radareorg / r2ai

local language model for radare2
https://www.radare.org
MIT License
104 stars 17 forks source link

Figure out how to get errors reliably from r2.cmd(j) #28

Closed dnakov closed 6 months ago

dnakov commented 6 months ago

We talked briefly about this here

Unfortunately, option 2 has a few pitfalls:

Option 1 only works in some of the r2langs Can you help me understand this issue and why it'd be hard to do it for, say r2lang-python? It's a pretty big issue for auto-mode.

trufae commented 6 months ago

Ok did some thoughs about this long standing issue and finally implemented r2pipe2 in r2. Check the new { command which takes cmd as a json object and returns a json with the output, error code , return value and log messages associated.

The next step will be to try every single command (about 8000) and ensure the return code and errors are consistent with what’s expected. Which is not good it is right now but it was about the time to tackle this

dnakov commented 6 months ago

Amazing! This looks great so far!! Getting some random segfaults, though

[0x00001c10]> {"cmd": "aaa" }
{"res":"","error":false,"value":0,"code":0,"logs":[{"type":"WARN","origin":"logline","message":"Analyze all flags starting with sym. and entry0 (aa)"}{"type":"WARN","origin":"logline","message":"Analyze imports (af@@@i)"}{"type":"WARN","origin":"logline","message":"Analyze entrypoint (af@ entry0)"}{"type":"WARN","origin":"logline","message":"Analyze symbols (af@@@s)"}{"type":"WARN","origin":"logline","message":"Recovering variables"}{"type":"WARN","origin":"logline","message":"Analyze all functions arguments/locals (afva@@@F)"}{"type":"WARN","origin":"logline","message":"Analyze function calls (aac)"}{"type":"WARN","origin":"logline","message":"Analyze len bytes of instructions for references (aar)"}{"type":"WARN","origin":"logline","message":"Finding and parsing C++ vtables (avrr)"}{"type":"WARN","origin":"logline","message":"Analyzing methods"}{"type":"WARN","origin":"logline","message":"Recovering local variables (afva)"}{"type":"WARN","origin":"logline","message":"Type matching analysis for all functions (aaft)"}{"type":"WARN","origin":"logline","message":"Propagate noreturn information (aanr)"}{"type":"WARN","origin":"cmd_anal_all","message":"Use -AA or aaaa to perform additional experimental analysis"}],"code":0}
[0x00001c10]> {"cmd": "aaaa" }
{"res":"","error":false,"value":0,"code":0,"logs":[{"type":"WARN","origin":"logline","message":"Analyze all flags starting with sym. and entry0 (aa)"}{"type":"WARN","origin":"logline","message":"Analyze imports (af@@@i)"}{"type":"WARN","origin":"logline","message":"Analyze entrypoint (af@ entry0)"}{"type":"WARN","origin":"logline","message":"Analyze symbols (af@@@s)"}{"type":"WARN","origin":"logline","message":"Recovering variables"}{"type":"WARN","origin":"logline","message":"Analyze all functions arguments/locals (afva@@@F)"}{"type":"WARN","origin":"logline","message":"Analyze function calls (aac)"}{"type":"WARN","origin":"logline","message":"Analyze len bytes of instructions for references (aar)"}{"type":"WARN","origin":"logline","message":"Finding and parsing C++ vtables (avrr)"}{"type":"WARN","origin":"logline","message":"Analyzing methods"}{"type":"WARN","origin":"logline","message":"Recovering local variables (afva)"}{"type":"WARN","origin":"logline","message":"Type matching analysis for all functions (aaft)"}{"type":"WARN","origin":"logline","message":"Propagate noreturn information (aanr)"}{"type":"WARN","origin":"logline","message":"Scanning for strings constructed in code (/azs)"}{"type":"WARN","origin":"logline","message":"Finding function preludes (aap)"}{"type":"WARN","origin":"logline","message":"Enable anal.types.constraint for experimental type propagation"}],"code":0}
[0x00001c10]> { "cmd": "aaaa" }
{"res":"","error":false,"value":0,"code":0,"logs":[{"type":"WARN","origin":"logline","message":"Analyze all flags starting with sym. and entry0 (aa)"}{"type":"WARN","origin":"logline","message":"Analyze imports (af@@@i)"}{"type":"WARN","origin":"logline","message":"Analyze entrypoint (af@ entry0)"}{"type":"WARN","origin":"logline","message":"Analyze symbols (af@@@s)"}{"type":"WARN","origin":"logline","message":"Recovering variables"}{"type":"WARN","origin":"logline","message":"Analyze all functions arguments/locals (afva@@@F)"}{"type":"WARN","origin":"logline","message":"Analyze function calls (aac)"}{"type":"WARN","origin":"logline","message":"Analyze len bytes of instructions for references (aar)"}{"type":"WARN","origin":"logline","message":"Finding and parsing C++ vtables (avrr)"}{"type":"WARN","origin":"logline","message":"Analyzing methods"}{"type":"WARN","origin":"logline","message":"Recovering local variables (afva)"}{"type":"WARN","origin":"logline","message":"Type matching analysis for all functions (aaft)"}{"type":"WARN","origin":"logline","message":"Propagate noreturn information (aanr)"}{"type":"WARN","origin":"logline","message":"Scanning for strings constructed in code (/azs)"}{"type":"WARN","origin":"logline","message":"Finding function preludes (aap)"}{"type":"WARN","origin":"logline","message":"Enable anal.types.constraint for experimental type propagation"}],"code":0}
[0x00001c10]> { "cmd": "aaaa" }
[1]    4832 segmentation fault  r2 -A -i r2ai/main.py ~/Downloads/svchost.exe
trufae commented 6 months ago

should bef ixed in https://github.com/radareorg/radare2/pull/22975 . thanks for reporting!

dnakov commented 6 months ago

works great with that patch! in the future, should i open issues in radare2 for anything else i find related to this or do you prefer I keep here?

trufae commented 6 months ago

Yeah better fill the r2 tickets in the r2 repo :)