rename할때 {0.pykemon}을 넣는다
python의 format함수를 이용해서 return을 해줄때 입력에 formatstring을 주입할 수 있다.
{0.__class__}를 하면 format의 class정보를 릭할 수 있는데
{0.pykemon}을 넣으면 아래와 같이 format에 Pykemon클래스가 들어있었기 때문에 있는 Pykemon.pykemon의 정보가 쭈루룩 나온다.
소스코드를보면
(p 는 Pykemon class변수)
if not p:
return "Error: trying to name a pykemon you haven't caught!"
r = session.get('room')
s = session.get('caught')
for pykemon in s['pykemon']:
if pykemon['pid'] == name:
pykemon['nickname'] = new_name
session['caught'] = s
print session['caught']
return "Successfully renamed to:\n" + new_name.format(p)
Class Pykemon(object):
pykemon = [
[100, 'Pydiot', 'Pydiot','images/pydiot.png', 'Pydiot is an avian Pykamon with large wings, sharp talons, and a short, hooked beak'],
[90, 'Pytata', 'Pytata', 'images/pytata.png', 'Pytata is cautious in the extreme. Even while it is asleep, it constantly listens by moving its ears around.'],
[80, 'Pyliwag', 'Pyliwag', 'images/pyliwag.png', 'Pyliwag resembles a blue, spherical tadpole. It has large eyes and pink lips.'],
[70, 'Pyrasect', 'Pyrasect', 'images/pyrasect.png','Pyrasect is known to infest large trees en masse and drain nutrients from the lower trunk and roots.'],
[60, 'Pyduck', 'Pyduck', 'images/pyduck.png','Pyduck is a yellow Pykamon that resembles a duck or bipedal platypus'],
[50, 'Pygglipuff', 'Pygglipuff', 'images/pygglipuff.png','When this Pykamon sings, it never pauses to breathe.'],
[40, 'Pykachu', 'Pykachu', 'images/pykachu.png','This Pykamon has electricity-storing pouches on its cheeks. These appear to become electrically charged during the night while Pykachu sleeps.'],
[30, 'Pyrigon', 'Pyrigon', 'images/pyrigon.png','Pyrigon is capable of reverting itself entirely back to program data and entering cyberspace.'],
[20, 'Pyrodactyl', 'Pyrodactyl', 'images/pyrodactyl.png','Pyrodactyl is a Pykamon from the age of dinosaurs'],
[10, 'Pytwo', 'Pytwo', 'images/pytwo.png','Pytwo is a Pykamon created by genetic manipulation'],
[0, 'FLAG', 'FLAG','images/flag.png', 'PCTF{XXXXX}']
]
def __init__(self, name=None, hp=None):
pykemon = Pykemon.pykemon
if not name:
i = randint(0,10)
else:
count = 0
for p in pykemon:
if name in p:
i = count
count += 1
self.name = pykemon[i][1]
self.nickname = pykemon[i][2]
self.sprite = pykemon[i][3]
self.description = pykemon[i][4]
self.hp = hp
if not hp:
self.hp = randint(1,100)
self.rarity = pykemon[i][0]
self.pid = self.name + str(self.hp)
http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
'CTF' 카테고리의 다른 글
[codegate 2017 prequal]meow (0) | 2017.05.09 |
---|---|
[codegate17 prequal]Goversing (0) | 2017.05.08 |
[codegate final]owner (0) | 2017.04.19 |
[ASISctf] DLP (2) | 2017.04.13 |
asis secured portal (0) | 2017.04.13 |