I have a closed-source binary (minecraft-pi). For a given section of the assembly like so:

   a2ed4:       e92d45f8        push    {r3, r4, r5, r6, r7, r8, sl, lr}
   a2ed8:       e1a04000        mov     r4, r0
   a2edc:       e59d0024        ldr     r0, [sp, #36]   ; 0x24
   a2ee0:       e352007f        cmp     r2, #127        ; 0x7f
   a2ee4:       d3a02000        movle   r2, #0
   a2ee8:       c3a02001        movgt   r2, #1
   a2eec:       e1922fa0        orrs    r2, r2, r0, lsr #31
   a2ef0:       1a000015        bne     a2f4c

conveniently there's another binary libminecraftpe.so that has code with symbols while containing similar disassembled instructions, and similar relative placement among functions e.g.:

0013a3ac <_ZN5Level11hasChunksAtEiiiiii>:
  13a3ac:       e92d 43f8       stmdb   sp!, {r3, r4, r5, r6, r7, r8, r9, lr}
  13a3b0:       2a7f            cmp     r2, #127        ; 0x7f
  13a3b2:       4604            mov     r4, r0
  13a3b4:       9809            ldr     r0, [sp, #36]   ; 0x24
  13a3b6:       bfd4            ite     le
  13a3b8:       2200            movle   r2, #0
  13a3ba:       2201            movgt   r2, #1
  13a3bc:       ea52 72d0       orrs.w  r2, r2, r0, lsr #31
  13a3c0:       d119            bne.n   13a3f6 <_ZN5Level11hasChunksAtEiiiiii+0x4a>

(_ZN5Level11hasChunksAtEiiiiii ~ Level::hasChunksAt(int, int, int, int, int, int) according to c++filt).

This matches up because despite one being ARM + Linux and the other ARM/Thumb + Android, they come from roughly the same codebase.

It's thus appealing to build a symbol file for minecraft-pi by hand and use it in gdb. Even when primarily stepping through assembly it would be very helpful if I could set breakpoints on function names and see informative backtraces.

So if I have written up a map of addresses to symbol names, how can I generate a corresponding symbol file binary (to be loaded in gdb via the symbol-file command, or even embedded into the executable)?

I'm familiar with human-readable debug symbol formats like Breakpad syms, but are there tools for generating a DWARF binary in this manner?

I found other questions on Stack Exchange related to IDA integration, dwarfexport, pwndebug, and unstrip (included in links below). florisschabert/unstrip has ARM support but seems to be geared toward inserting symbols based on Objective-C standard libraries, which isn't applicable here. Using IDA with dwarfexport could be an option, but I'd prefer a command-line solution that I could script. I'm basically looking for advice on generally recommended practices before I try out these various tools with limited documentation.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.