Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dnakov opened this issue May 27, 2024 · 5 comments
Closed

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

dnakov opened this issue May 27, 2024 · 5 comments

Comments

@dnakov
Copy link
Collaborator

dnakov commented May 27, 2024

We talked briefly about this here

Unfortunately, option 2 has a few pitfalls:

  • Lost ANSI coloring
  • doesn't work in some cases, example axt @ jksdhfdskjf 2>foo prints ERROR: Invalid command 'axt @ klasjdlkasjd' (0x61) but not in the foo file

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
Copy link
Contributor

trufae commented May 27, 2024

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
Copy link
Collaborator Author

dnakov commented May 27, 2024

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
Copy link
Contributor

trufae commented May 27, 2024

should bef ixed in radareorg/radare2#22975 . thanks for reporting!

@dnakov
Copy link
Collaborator Author

dnakov commented May 27, 2024

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
Copy link
Contributor

trufae commented May 27, 2024

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

@dnakov dnakov closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants