JonathanSalwan / Triton

Triton is a dynamic binary analysis library. Build your own program analysis tools, automate your reverse engineering, perform software verification or just emulate code.
https://triton-library.github.io
Apache License 2.0
3.4k stars 524 forks source link

Simplify basic block with padding = True does not work #1253

Closed thanh122 closed 1 year ago

thanh122 commented 1 year ago

I used example here with changed padding = True

https://github.com/JonathanSalwan/Triton/blob/master/src/examples/python/dead_store_elimination.py

print('[Simplified basic block] --------------------------------------------- ')
sblock = ctx.simplify(block,True) <---- used pading =True
ctx.disassembly(sblock, 0x140004149)
print(sblock)
print('[End of simplified basic block] -------------------------------------- ')

The result is the same as padding = False which is

[Simplified basic block] --------------------------------------------- 0x140004149: pop rax 0x14000414a: pop r11 0x14000414c: pop rdi 0x14000414d: pop r8 0x14000414f: pop rdx 0x140004150: pop r9 0x140004152: pop r10 0x140004154: pop r12 0x140004156: pop rbp 0x140004157: popfq 0x140004158: pop rcx 0x140004159: pop rcx 0x14000415a: pop r14 0x14000415c: pop rsi 0x14000415d: pop r13 0x14000415f: ret [End of simplified basic block] --------------------------------------

pop rax should be 0x14000414c

thanh122 commented 1 year ago

I found the problem. I've been looking at the doc here. Only after looking at the c++ source here I realized the function ctx.simplify received 4 arguments padding is the last one and should be called.

sblock = ctx.simplify(block,True,True,True)

The docs is obviously deprecated

JonathanSalwan commented 1 year ago

This is keywords, so you have to provide padding=True.

sblock = ctx.simplify(block, padding=True)