-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack.py
executable file
·82 lines (64 loc) · 1.47 KB
/
stack.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
# 2020 - matth
#
# crappy stack string helper, just copy paste ghidra decomp...
#
# % cat | stack.py
# local_1d8 = 0x6b;
# local_1d6 = 0x65;
# local_1d4 = 0x72;
# local_1d2 = 0x6e;
# local_1d0 = 0x65;
# local_1ce = 0x6c;
# local_1cc = 0x33;
# local_1ca = 0x32;
# local_1c8 = 0x2e;
# local_1c6 = 100;
# local_1c4 = 0x6c;
# local_1c2 = 0x6c;
# local_1c0 = 0;
#size: 8
#b'kernel32.dll\x00'
import re
import struct
values = []
def guess_size(values):
sz = max([len(_) for _ in values])
if sz <= 2:
return 8
if sz > 2 and sz <= 8:
return 32
if sz > 8 and sz <= 16:
return 64
raise Exception("cant guess size")
def unpack(b, sz):
match sz:
case 8:
return int(b, 16).to_bytes(1, 'little')
case 32:
mod = "<I"
case 64:
mod = "<Q"
case _:
raise Exception("unsupported size")
return struct.pack(mod, int(b, 16))
def main():
values = []
while True:
try:
values += re.findall("= ((?:0x)?[0-9a-fA-F]+);", input())
except EOFError:
break
for n, v in enumerate(values):
if v.startswith('0x'):
values[n] = v[2:]
else:
values[n] = hex(int(v))[2:]
size = guess_size(values)
print(f"size: {size}")
out = b''
for v in values:
out += unpack(v, size)
print(out)
if __name__ == "__main__":
main()