radareorg / radeco

radare2-based decompiler and symbol executor
371 stars 52 forks source link

parsing json fails on 'tachikoma' #14

Closed crowell closed 9 years ago

crowell commented 9 years ago
[12:36:45] <mom> minishwoods tools/radeco ‹master*› » ./target/debug/cfg_ssa ../../dc23/ctf-services/services/defcon_finals_2015/tachikoma/tachikoma 
[12:36:45] <mom> Cannot find function at 0x0002b3f0
[12:36:45] <mom> thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: ParseError(SyntaxError("EOF While parsing value", 1, 1))', ../src/libcore/result.rs:731

http://toonces.cat/tachikoma

radare commented 9 years ago

isnt this a bug in r2?

On 08 Aug 2015, at 18:52, Jeffrey Crowell notifications@github.com wrote:

[12:36:45] minishwoods tools/radeco ‹master*› » ./target/debug/cfg_ssa ../../dc23/ctf-services/services/defcon_finals_2015/tachikoma/tachikoma [12:36:45] Cannot find function at 0x0002b3f0 [12:36:45] thread '

' panicked at 'called Result::unwrap() on an Err value: ParseError(SyntaxError("EOF While parsing value", 1, 1))', ../src/libcore/result.rs:731 http://toonces.cat/tachikoma http://toonces.cat/tachikoma — Reply to this email directly or view it on GitHub https://github.com/radare/radeco/issues/14.

radare commented 9 years ago

also, that eof susggest me that the bug is in r2pipe.rs

sushant94 commented 9 years ago

@radare @crowell , This has something to do with r2, not with the pipe. Though sym.main is identified, running pdfj @ sym.main says "Cannot find function at 0x0002b3f0"

radare commented 9 years ago

I would suggest handling “” as valid JSON from r2pipe.rs, this way commands like this, that doesnt display anything to stdout will not fail that hard, i think that we should handle better error cases like this from there. anyway, if there’s no function at sym.main is because the analysis hasnt been done properly, i see that you guys are doing “aa” for analysis, which is not the best way to get full analysis of the binary. what about af @ sym.main before running this? (just for testing)

On 10 Aug 2015, at 10:21, Sushant Dinesh notifications@github.com wrote:

@radare https://github.com/radare @crowell https://github.com/crowell , This has something to do with r2, not with the pipe. Though sym.main is identified, running pdfj @ sym.main says "Cannot find function at 0x0002b3f0"

— Reply to this email directly or view it on GitHub https://github.com/radare/radeco-lib/issues/14#issuecomment-129359933.

sushant94 commented 9 years ago

Yup. af @ sym.main followed by pdfj @ sym.main seems to work correctly.

sushant94 commented 9 years ago

@radare Actually, the correct fix would be that r2 returns an empty array in these cases i.e. "[]" This way, it'll still be a valid JSON.

radare commented 9 years ago

Thats not the same case. When the output is not json like an empty string it means that an error happened. We should handle this without a fatal exception. Maybe with Option or so

On 10 Aug 2015, at 21:23, Sushant Dinesh notifications@github.com wrote:

@radare Actually, the correct fix would be that r2 returns an empty array in these cases i.e. "[]" This way, it'll still be a valid JSON.

— Reply to this email directly or view it on GitHub.

sushant94 commented 9 years ago

@radare The ideal way would be to have the json be something like this:

{
    "status": "ok",
    "contents": [
        { "foo": "bar" }, 
        {"apple": "mango"}
    ]
}

This way the error can be displayed to the user too.

radare commented 9 years ago

i think that we should assume that it is nearly impossible to handle all cases where the json is printed to extend that “status” field, because is a manual change. i would prefer to just handle non-json or empty output as error cases

On 12 Aug 2015, at 10:30, Sushant Dinesh notifications@github.com wrote:

@radare https://github.com/radare The idea thing would be to have the json be something like this:

{ "status": "ok", "contents": [ { "foo": "bar" }, {"apple": "mango"} ] } This way the error can be displayed to the user too.

— Reply to this email directly or view it on GitHub https://github.com/radare/radeco-lib/issues/14#issuecomment-130215851.

sushant94 commented 9 years ago

Fixed in radare/r2pipe.rs@a8831ddb99b2e61c941b4032987397e233ea717d

radare commented 9 years ago

😃

On 07 Sep 2015, at 22:11, Sushant Dinesh notifications@github.com wrote:

Fixed in radare/r2pipe.rs@a8831dd

— Reply to this email directly or view it on GitHub.