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.39k stars 524 forks source link

is it possible to recognize basic block by triton itself? #1339

Closed vxcall closed 4 days ago

vxcall commented 4 days ago

Hi, thanks for creating / maintening cool project!

I'm sorry if this question is irrelevant as I am not fully familiar to these tools yet. but is it possible to recognize basic block of let's say a function using only triton? for example if u use IDA python u can get basic blocks by something like this I guess:

func = idaapi.get_func(func_addr)
flow_chart = idaapi.FlowChart(func)
# or bb   = ida_gdl.FlowChart(func)[0]

Am I able to perform same thing using triton? so that code will be simpler. I know it's fine just to use IDA python in conjunction with triton when I desperately need basic blocks, but I just wonder if i can do that without IDA python.

Thanks!

JonathanSalwan commented 4 days ago

Unfortunately not.

Triton's input is only one instruction. There is no notion of CFG/function in Triton. As it's designed to perform dynamic analysis, the highest granularity is one instruction and lowest is a node into the instruction semantic.

So if you are working within IDA, you have to forward instructions from IDA to Triton. I can share with an example where I detect opaque predicates in IDA function.

https://github.com/JonathanSalwan/X-Tunnel-Opaque-Predicates/blob/master/detect-opaque-predicates-in-function.py#L96-L110

I hope it can help

vxcall commented 4 days ago

Thanks for your quick response!

Your answer is mostly what I expected, so it's no problem I just wanted to confirm it in case I was wrong.

And also appreciate giving me a sample code. I read one of your blog and knew it's feasible too! ( The number of resources in wiki and examples are amazing btw haha )

I'm one of those users that feels great potential on this tool. Thank you so much. I'm glad that you are so supportive!