Programming/Python
[unpack] little endian으로 문자열 unpack
Tribal
2019. 7. 8. 15:31
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
from struct import unpack
ul32 = lambda x: unpack("<L", x)[0]
ul64 = lambda x: unpack("<Q", x)[0]
def padding(s, bit=32):
s_len = len(s)
align = bit/8
pad_len = align - (s_len % align)
return s + '\x00'*pad_len
def print_x86(s):
for i in xrange(0, len(s), 4):
print '0x%08x' % ul32(s[i:i+4])
def print_x64(s):
for i in xrange(0, len(s), 8):
print '0x%016x' % ul64(s[i:i+8])
if __name__ == '__main__':
BIT = 32 # 64
a = 'urlmon.dll'
a = padding(a, BIT)
if BIT == 32:
print_x86(a)
else:
print_x64(a)
|
cs |