radare2-r2pipe icon indicating copy to clipboard operation
radare2-r2pipe copied to clipboard

Handle JSON parse to work with iterator("@@")

Open n4r1b opened this issue 6 years ago • 1 comments

Now it should work when parsing JSON object returned from an iterator for ex.

r2.cmdj("pdj 1@@hit0");

This should be done in other bindings too (maybe I should open an issue). I tried to write some test cases, but I'm more used to mocha and I couldn't make it work with the testsuite, anyways I'll try to add some test as soon as possible

n4r1b avatar Mar 13 '18 00:03 n4r1b

The problem is that when parsing this json stream the delimiter between each result is a new line instead of a comma and every result is inside is own array. So right now when trying to execute a command like r2.cmdj("aoj @@=$$ $$+2") we'll get this error

{ SyntaxError: Unexpected token [ in JSON at position 368
    at Object.parse [as jsonParse] (<anonymous>)
    at Object.cb (/home/narib/test/node_modules/r2pipe/index.js:140:29)
    at Object.pipeCmdOutput (/home/narib/test/node_modules/r2pipe/index.js:118:21)
    at Socket.ls.stdout.on.data (/home/narib/test/node_modules/r2pipe/index.js:251:33)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:266:12)
    at readableAddChunk (_stream_readable.js:253:11)
    at Socket.Readable.push (_stream_readable.js:211:10)
    at Pipe.onread (net.js:587:20)
  res: '[{"opcode":"xor ebp, ebp","mnemonic":"xor","prefix":0,"id":334,"opex":{"operands":[{"size":4,"rw":3,"type":"reg","value":"ebp"},{"size":4,"rw":1,"type":"reg","value":"ebp"}],"modrm":true},"addr":22016,"bytes":"31ed","size": 2,"type": "xor","esil": "ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=","refptr":0,"cycles":1,"delay":0,"family":"cpu"}]\n[{"opcode":"mov r9, rdx","mnemonic":"mov","prefix":0,"id":449,"opex":{"operands":[{"size":8,"rw":2,"type":"reg","value":"r9"},{"size":8,"rw":1,"type":"reg","value":"rdx"}],"rex":true,"modrm":true},"addr":22018,"bytes":"4989d1","size": 3,"type": "mov","esil": "rdx,r9,=","refptr":0,"cycles":1,"delay":0,"family":"cpu"}]',
  cmd: 'aoj @@=$$ $$+2' }

I dont know if maybe I'm missing something, if its the case just cancel the pull request no prob :)

n4r1b avatar Mar 13 '18 09:03 n4r1b