I am working on the scripting program with Prolog, where they talk through the pipe and JSON-formatted data. Everything works fine except the json_read_dict/2
relation.
?- json_read_dict(F, "[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n").
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [11] get_code(_1324,_1326)
ERROR: [10] json:json_value(_1356,_1358,_1360,json_options(null,true,false,string,'')) at /usr/lib64/swipl-7.6.4/library/http/json.pl:260
ERROR: [9] json:json_read_dict(_1404,"[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n",[]) at /usr/lib64/swipl-7.6.4/library/http/json.pl:934
ERROR: [7] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
How it is possible to parse this output with SWI-Prolog?
The json_read_dict/2
predicate takes a stream or stream alias as first argument. You cannot call it with the first argument unbound, hence the instantiation error. Maybe you're looking for the functionality of the atom_json_dict/3
predicate?
?- atom_json_dict("[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n", D, []).
D = [_19642{bytes:"31ed", disasm:"xor ebp, ebp", esil:"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=", family:"cpu", fcn_addr:0, fcn_last:0, flags:["entry0", "rip"], offset:22784, opcode:"xor ebp, ebp", refptr:false, size:2, type:"xor", type2_num:0, type_num:28}].
Update
It seems that you get the json(illegal_json)
syntax error due to the presence of a starting quote in the output that we're trying to parse. Try instead:
read_result(Out, Json) :-
read_string(Out, "", "", _, String),
atom_json_dict(String, Json, []).
Using your sample call:
?- with_command("/bin/ls", "ij", O).
O = _5058{bin:_4930{arch:"x86", binsz:38688, bintype:"mach0", bits:64, canary:true, checksums:_4926{}, class:"MACH064", compiled:"", crypto:false, dbg_file:"", endian:"little", guid:"", havecode:true, intrp:"/usr/lib/dyld", lang:"c", linenum:false, lsyms:false, machine:"x86 64 all", maxopsz:16, minopsz:1, nx:false, os:"macos", pcalign:0, pic:true, relocs:false, retguard:false, rpath:"", static:false, stripped:true, subsys:"darwin", va:true}, core:_4498{block:256, fd:3, file:"/bin/ls", format:"mach064", humansz:"37.8K", iorw:false, mode:"r-x", obsz:0, size:38688, type:"Executable file"}}.
User contributions licensed under CC BY-SA 3.0