-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize_binary.py
More file actions
executable file
·39 lines (29 loc) · 870 Bytes
/
optimize_binary.py
File metadata and controls
executable file
·39 lines (29 loc) · 870 Bytes
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
#!/usr/bin/python
from pwn import *
from capstone import *
context.arch = 'amd64'
md = Cs(CS_ARCH_X86, CS_MODE_64)
r = open(sys.argv[1]).read()[:]
new_r2 = ''
new_r1 = ''
super_r = ''
for i in md.disasm(r, 0):
if i.mnemonic.startswith('nop'):
continue
new_r1 += str(i.bytes)
count = 0
for i in md.disasm(new_r1, 0):
if i.mnemonic.startswith('mov') and i.op_str.split(',')[0] == "rcx":
count = 0
continue
if count == 1 and i.mnemonic.startswith('mov') and i.op_str.split(',')[0] == "rax":
new_r2 = new_r2[:-10]
else:
count = 0
if i.mnemonic.startswith('mov') and i.op_str.split(',')[0] == "rax":
count = 1
if i.mnemonic.startswith('ro') and i.op_str.split(',')[1] == ' 0':
continue
new_r2 += str(i.bytes)
x = make_elf(new_r2)
open(sys.argv[1] + '_optimized', 'w').write(x)