ThoughtGang / opdis

libopcodes-based disassembler
GNU General Public License v2.0
35 stars 10 forks source link

Invalid XML produced when using section disassembly #15

Closed natinusala closed 8 years ago

natinusala commented 8 years ago

Hello,

When I run this command : opdis -f xml -S .text executable

The resulting XML starts with :

Linear disassembly of section .text
<?xml version="1.0"?>
<!DOCTYPE disassembly [
<!ELEMENT disassembly (instruction*)>
<.........>

Which first line is obviously not valid XML. Could you fix this ?

natinusala commented 8 years ago

And the --quiet option doesn't work either, the debug line is still there.

natinusala commented 8 years ago

I found a workaround, using the --debug option somehow disables this message.

mkfs commented 8 years ago

Fix committed:

bash$ dist/opdis -f xml -S .text /bin/cat |head<?xml version="1.0"?>
<!DOCTYPE disassembly [
<!ELEMENT disassembly (instruction*)>
<!ELEMENT instruction (offset,vma,bytes,ascii?,mnemonic?,prefix?,isa?,category?,flags?,operands?,invalid?)>

The fix is to set job_options.quiet if output format is 'XML'. I'll do a second pass to see if other output formats need to be supported. I admit that job_list was a bit of a hack to get around the limitations of command-line disassembly; it was not properly thought-through.

Hmm, I should add JSON support if I ever expect to use this software again. XML is so ... 1999/2000.

I cannot see anything in the code that would cause --debug to work (and --quiet NOT to). Might have to spend some time on that one. Main bug fixed, though.

mkfs commented 8 years ago

Updated to only print job headers when output format is 'dump'.

Could not replicate the '--debug works and --quiet does not' workaround. Backing out the change, --quiet works (as it should) and --debug does not:

bash$ dist/opdis -f xml -q -S .text /bin/cat |head <?xml version="1.0"?> <!DOCTYPE disassembly [ <!ELEMENT disassembly (instruction*)> ...

bash$ dist/opdis -f xml -d -S .text /bin/cat |head
[DEBUG] Start linear from 0x401a40 max 0x40898a
[DEBUG] End linear 0x401a40 (count 6730)
Linear disassembly of section .text
<?xml version="1.0"?>
<!DOCTYPE disassembly [
<!ELEMENT disassembly (instruction*)>

Maybe the version you are building from is old? Try a fresh checkout.

natinusala commented 8 years ago

Thanks ! I think too that a JSON support would be interesting.

The debug option did add some more messages to stderr, but it also made the XML message to disappear. I don't really know why, but I'm quite sure that the quiet option didn't do anything.