-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlief_test.py
36 lines (34 loc) · 1.04 KB
/
lief_test.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
try:
import lief
except ImportError:
print("lief not installed, can not test comparison")
sys.exit()
from zangope import Binary
import time
lief.logging.enable()
lief.logging.set_level(lief.logging.LOGGING_LEVEL.TRACE)
lief.logging.set_path("lief.log.txt")
start_t = time.time()
SCTS = 88
SECTION_LENGHT = 512
pebinary = lief.PE.parse("calc.exe")
for i in range(SCTS):
section = lief.PE.Section(".test")
section.content = [41] * SECTION_LENGHT
section.characteristics = 0x60000020
pebinary.add_section(section)
builder = lief.PE.Builder(pebinary)
builder.build()
end_t = time.time()
builder.write("lief_calc.exe")
print(f"Created LIEF version, took {end_t - start_t}")
start_t = time.time()
with open("calc.exe", "rb") as f:
calc_bytes = bytearray(f.read())
calc = Binary(bytez=calc_bytes)
for i in range(SCTS):
calc_bytes = calc.add_section(".test", 0x60000020, b"\x41" * SECTION_LENGHT)
end_t = time.time()
with open("addsect_calc.exe", "wb") as f:
f.write(calc_bytes)
print(f"Created NATIVE version, took {end_t - start_t}")