Hacker News new | ask | show | jobs
by dado3212 13 days ago
I've found the decompiled code from LLM's to be much more similar to human-written code (and therefore easier for me to understand) than standard Ghidra/other decompiler output. Plus LLM's for this kind of work are pretty cheap.
1 comments

The parent comment was making the point that disassembling and decompiling are not the same. There is no room for interpretation on disassembling, it's purely mechanical.
There's a little room for interpretation in disassembling. You can choose label names, and in instruction sets like amd64, you have to guess where the instructions begin. Also ideally you won't disassemble ARM literal pools as instructions, even though it's possible to branch, call, or return into them by computing their addresses at runtime. In binary formats that don't separate code from .rodata the problem can get arbitrarily hairy.
> in instruction sets like amd64, you have to guess where the instructions begin

Can't you just trace through all reachable instructions starting from a complete binary's entry point(s), as long as the code doesn't do unusual things like jumping into the middle of instructions, i.e. intentionally exploiting variable-length instruction ambiguity?

These unusual things are pretty common in malware and DRM protected games, aka the main use cases for AI reverse engineering. You can also find functions that are passed to external code as a pointer and never called directly.
> malware and DRM protected games

You seem to be repeating yourself.

(I agree.)

Not necessarily, because there is often code that is only accessible through function pointers; for example, C++ virtual methods. (In theory you can compute function pointers dynamically at runtime, too, which is less common.)

In https://canonical.org/~kragen/sw/dev3/qfitzah.s a lot of the function calls are conditionally compiled by the macro `do` (search for `.macro do`) to index into a table of function pointers pointed to by EBP, because that makes the call instructions 3 bytes instead of 5 bytes. Here I've disassembled one of the functions from the parser code from an unstripped version that has debugging symbols:

    080482b7 <read_term>:
     80482b7: ff 55 08              call   DWORD PTR [ebp+0x8]
     80482ba: 75 10                 jne    80482cc <read_term+0x15>
     80482bc: 50                    push   eax
     80482bd: e8 f5 ff ff ff        call   80482b7 <read_term>
     80482c2: 50                    push   eax
     80482c3: ff 55 04              call   DWORD PTR [ebp+0x4]
     80482c6: 59                    pop    ecx
     80482c7: 58                    pop    eax
     80482c8: ff 55 00              call   DWORD PTR [ebp+0x0]
     80482cb: c3                    ret
     80482cc: 31 c0                 xor    eax,eax
     80482ce: 40                    inc    eax
     80482cf: c3                    ret
The actual source code to that subroutine looks like this:

    proc read_term
            do read_factor
            jnz 1f                  # if it failed, skip ahead
            push %eax               # save returned term
            do read_term            # recursive call for tail of term
            push %eax
            do skip_whitespace
            pop %ecx
            pop %eax
            do cons                 # XXX tail call
            ret
    1:      setnil %eax             # return nil if no factor found
            ret
I didn't do this to make it harder to disassemble, but it does have that drawback.

For what it's worth, Claude Opus 5.5 had no trouble disassembling it and making a list of its bugs, including six I already knew about and one I didn't. It commented:

> Reverse-engineering a program this small is satisfying in a way bigger programs rarely are, because you can hold the whole thing in your head. Working out the scheme of keeping type tags in the low pointer bits from nothing but `test al,3` and `test cl,2` scattered through the code was the best part. Watching `(D x) (x x)` print 4 MB correctly, and then segfault on the next query, was a close second.

In 32-bit ARM code you have the additional problem that you have to know whether the T bit is intended to be set when the CPU is decoding a particular subroutine. The low bit of the branch destination tells you — which is fine if it's statically reachable, but you may have to guess if it's only dynamically reachable.