Skip to the content ForoHackers
Log inJoin

Finding the load address of a raw Cortex-M firmware dump

Binary analysisFirmwareMicrocontrollers
#1052 · hexdump_hermit · · Report

You dumped the flash of your own board and got a raw .bin with no ELF header, no symbols, no load address. Where do you start? With the vector table, which sits at the beginning of the image on a Cortex-M.

First bytes:

00000000: 00 80 00 20  c1 01 00 08  5d 02 00 08  5f 02 00 08

Little-endian words:

  • word 0: 0x20008000, the initial stack pointer. It points to the end of RAM, so RAM starts below it (0x20000000 region).
  • word 1: 0x080001C1, the reset handler. The lowest bit is the Thumb bit (always 1 on these cores), so the real code address is 0x080001C0.
  • word 2: 0x0800025D, NMI handler (code at 0x0800025C).
  • word 3: 0x0800025F, HardFault (code at 0x0800025E).

Every handler address points into 0x0800xxxx. That tells you the image is mapped at 0x08000000, so file offset 0x1C0 is address 0x080001C0. Load the binary at that base in your disassembler, mark 0x080001C0 as a function in Thumb mode, and the rest unravels from there.

Sanity checks: all code pointers odd and in a consistent range; the stack pointer in a plausible RAM range; many vectors pointing to the same default handler. If instead the first word looks like code, the image probably has a bootloader or header in front, and the table sits at a later offset.

Shape, not offsets, as I say every time.

#1577 · null_terminated_hopes · · Report

Also remember that the vector table can be relocated at runtime (the VTOR register on parts that have it), so the table in the image is the boot-time one. A bootloader may point it somewhere else for the application.

#1578 · n0p_sl3d · · Report

Great for CTF firmware tasks too. If a challenge gives you a raw blob, the first thing I check is whether word 0 and word 1 look like a stack pointer and an odd code address. Takes ten seconds and saves a wrong base address and an hour.

#1579 · cr4ckm3_c4t · · Report

My cat sat on the keyboard while I read this and typed 0xdeadbeef. Seemed relevant.

#1580 · c0ld_b00t · · Report

For the record-keeping crowd: hash the dump before you start, note which board and which firmware version, and write down how you extracted it. Six months from now, "a .bin I found" is not a reproducible analysis.

Log in or join to reply.