Case Study: TH-D74 Firmware in Ghidra
- Why this matters
- The target
- Extracting the sections
- Resolving the load address
- Loading it into Ghidra
- Naming what the image already tells you
- What you end up with
- Limits of what this gets you
- Key takeaways
- References
Why this matters
Software Reverse Engineering gives you the procedure for a raw firmware image: resolve the architecture, resolve the load address, find the entry point, then work outward from strings. This page is that procedure carried out end to end on a real target — a Kenwood TH-D74 handheld, 2.5 MB of ARM code with no symbols, no headers, and no debug information.
The point is not the radio. The point is that “no symbols” does not mean “no
names.” Every name in the finished project came from evidence that was already
in the image: an exception vector table, a string table with a computable
stride, two command dispatch tables, and the error messages of a statically
linked copy of libpng. None of it required hardware, and all of it is
scriptable, which is why the four scripts are published next to this page:
srec2bin.py, build_project.py,
png_msgmap.py, and
project_stats.py.
⚠️ Everything below is static analysis of a vendor firmware image taken from Kenwood’s own publicly distributed updater, on a radio you own. Reading firmware is not the same as modifying a transmitter. Unlocking transmit outside the amateur allocations, or changing emission characteristics, makes the control operator answerable for whatever the radio then does on the air — an FCC question rather than a technical one, and firmly out of scope here.
The target
The TH-D74 is built around a Texas Instruments OMAP-L138 — an ARM926EJ-S paired with a C674x DSP. That one fact settles the first unknown before you open a disassembler, because the ARM926EJ-S implements ARMv5TE: 32-bit ARM plus original 16-bit Thumb, little-endian. Recessim’s teardown of the radio also documents the boot pins strapped for NOR flash and, usefully, that the image on that flash is not encrypted.
There are two ways to get the image, and they cost very differently:
| Route | What it takes | What you get |
|---|---|---|
| Desolder the NOR flash, read it in a programmer | hot air, a programmer, a steady hand, ~$330 of kit | one 32 MB image of everything, exactly as the CPU sees it |
| Decrypt the vendor’s Windows updater | thd74tool, no hardware at all |
the five sections the updater ships, each with its flash address |
We take the second route. It is the one students can do from a laptop, and the sections it produces carry their own addresses, which turns out to matter.
Extracting the sections
thd74tool decrypts the payload inside the
Kenwood updater .exe and writes each section as Motorola S-records:
$ thd74tool extract --help
usage: thd74tool extract [-h] -e EXE [-p PATH] [-s SECTION]
options:
-h, --help show this help message and exit
-e EXE, --exe EXE path to firmware updater .exe file
-p PATH, --path PATH export firmware sections to path in SREC format
-s SECTION, --section SECTION
select firmware section for export
$ thd74tool extract -e TH-D74_V110_e.exe -p fw/
$ file fw/*.srec
fw/DATA 00E0.srec: Motorola S-Record; binary data in text format
fw/DATA 0100.srec: Motorola S-Record; binary data in text format
fw/FIRMWARE.srec: Motorola S-Record; binary data in text format
fw/FONT DATA.srec: Motorola S-Record; binary data in text format
fw/IMAGE DATA.srec: Motorola S-Record; binary data in text format
The S0 header record names both the section and the tool that wrote it, which is worth knowing when you find one of these files later with no context:
$ head -1 "fw/FIRMWARE.srec"
S02400004649524d57415245000000000000000000000000000100017468643734746f6f6c13
$ head -1 "fw/FIRMWARE.srec" | cut -c9-80 | xxd -r -p | strings
FIRMWARE
thd74tool
⚠️ Upstream
thd74tooldoesfrom pkg_resources import requireto read its own version.pkg_resourceswas deprecated in setuptools 81 and is gone in current releases, so the tool dies at import on a modern system. Replace it withimportlib.metadata.version(), which has been in the standard library since Python 3.8.
Worked example: flattening the S-records
S-records are addressed text. Before Ghidra can load one you need a flat binary
plus the address it belongs at — and you want to know whether the records
actually cover the whole range or leave holes. srec2bin.py
reports both:
$ python3 srec2bin.py "fw/FIRMWARE.srec" ghidra/firmware.bin
fw/FIRMWARE.srec
header : b'FIRMWARE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01thd74tool'
range : 0x00200000 - 0x0047ffff (2621440 bytes)
covered : 2621440 bytes gaps: 0
wrote : ghidra/firmware.bin
covered equal to the range size and gaps: 0 is the check that matters: the
records tile the whole section, so nothing in the middle is missing. Run the
same command over the other four and the flash layout the updater knows about
comes out as:
| Section | Flash range | Size | Contents |
|---|---|---|---|
FIRMWARE |
0x00200000–0x0047FFFF |
2.5 MiB | the ARM code — the only section with instructions |
IMAGE DATA |
0x00600000–0x0065FFFF |
384 KiB | 848 PNG files — the UI artwork |
DATA 00E0 |
0x00E00000–0x00EFFFFF |
1 MiB | opaque blobs, no recognisable structure |
DATA 0100 |
0x01000000–0x011FFFFF |
2 MiB | opaque blobs behind an ascending 32-bit offset table |
FONT DATA |
0x01500000–0x015BFFFF |
768 KiB | glyphs, with its own 4409 FONT DATA header |
Only FIRMWARE goes into the disassembler. The other four hold no
instructions, but note what is in IMAGE DATA — it will matter later:
$ python3 srec2bin.py "fw/IMAGE DATA.srec" ghidra/image_data.bin | tail -2
covered : 393216 bytes gaps: 0
wrote : ghidra/image_data.bin
$ python3 - <<'EOF'
b = open("ghidra/image_data.bin", "rb").read()
print(b.count(b"\x89PNG"), "PNG signatures")
EOF
848 PNG signatures
Resolving the load address
The flash address is not the load address. FIRMWARE lives at flash
0x00200000, but the CPU does not execute it there — a NOR-booted OMAP-L138
copies it into DDR and runs it from there. If you load the image at
0x00200000, every absolute pointer in it misses, nothing cross-references, and
the listing is unreadable.
The image answers the question itself. Its first eight words are ARM
ldr pc, [pc, #imm] instructions reading a constant pool just past them, and
the pool contains the real addresses:
$ python3 - <<'EOF'
import struct
b = open("ghidra/firmware.bin", "rb").read()
for off in range(0, 0x40, 4):
print(f" +0x{off:04x}: 0x{struct.unpack_from('<I', b, off)[0]:08x}")
EOF
+0x0000: 0xe59ff01c
+0x0004: 0xe59ff01c
+0x0008: 0xe59ff01c
+0x000c: 0xe59ff01c
+0x0010: 0xe59ff01c
+0x0014: 0x00000000
+0x0018: 0xe59ff018
+0x001c: 0xe59ff018
+0x0020: 0x00ffffff
+0x0024: 0xc0153974
+0x0028: 0xc0153bac
+0x002c: 0xc0095a68
+0x0030: 0xc0153bd4
+0x0034: 0xc0153bfc
+0x0038: 0xc0095b3c
+0x003c: 0xc0153b70
Three things fall out of those twelve lines:
0xe59ff01cdecoding asldr pc, [pc, #0x1c]confirms little-endian 32-bit ARM. Read big-endian it is nonsense, which is the usual way to get a confident wrong answer here.- The pool entries are all
0xc01xxxxx, so the image is linked for0xC0000000— the OMAP-L138 DDR window. The image is 2.5 MB, the handlers are inside it, and the arithmetic closes: flash0x00200000maps to0xC0000000, a constant offset of0xBFE00000. - The word at
+0x14is zero, which is the architecturally reserved fifth vector. The table is the standard ARM seven-handler layout, not something custom.
Confirm by looking at where the reset vector points. A reset handler has a recognisable shape — it sets up a stack for each processor mode before it touches anything else:
$ arm-none-eabi-objdump -D -b binary -m arm --adjust-vma=0xc0000000 \
--start-address=0xc0153974 --stop-address=0xc01539c0 ghidra/firmware.bin | tail -12
c0153988: e10f0000 mrs r0, CPSR
c015398c: e3c0001f bic r0, r0, #31
c0153990: e3800017 orr r0, r0, #23
c0153994: e121f000 msr CPSR_c, r0
c0153998: e59fd0e0 ldr sp, [pc, #224] @ 0xc0153a80
c015399c: e10f0000 mrs r0, CPSR
c01539a0: e3c0001f bic r0, r0, #31
c01539a4: e3800012 orr r0, r0, #18
c01539a8: e121f000 msr CPSR_c, r0
c01539ac: e59fd0d0 ldr sp, [pc, #208] @ 0xc0153a84
Mode 0x17 is Abort, 0x12 is IRQ, 0x11 is FIQ, 0x1b is Undefined: the
handler walks the modes installing a stack pointer in each. That is a reset
handler at a correct load address, and the second unknown is now closed.
The vector-pool route works here because an ARMv5 image starts with a vector table whose entries are instructions. It is not the Cortex-M two-word trick from the Week 9 activity and it is not the pointer histogram either — but all three end at the same test, the one HW #5 Task 1 grades: load the image, and check that cross-references resolve.
Loading it into Ghidra
With the architecture and base address known, the import is mechanical. In the
GUI: File → Import File, format Raw Binary, language
ARM:LE:32:v5t, then Options… and set Base Address to c0000000.
Doing it from a script is better, because the markup that follows has to be
scripted anyway. build_project.py drives Ghidra
through PyGhidra:
$ GHIDRA_INSTALL_DIR=/opt/ghidra python3 build_project.py \
--firmware ~/clones/tools/thd74/ghidra/firmware.bin \
--project-dir ~/clones/tools/thd74/ghidra
[thd74] importing .../firmware.bin as ARM:LE:32:v5t at 0xC0000000
[thd74] FIRMWARE block 0xC0000000-0xC027FFFF
[thd74] RAM block 0xC0280000-0xC3FFFFFF
[thd74] PERIPH block 0x01C00000-0x01FFFFFF
[thd74] vector table: 7 handlers
[thd74] localize_string: 377 entries at 0xC000026C
[thd74] localize_string_1: 603 entries at 0xC0003D88
[thd74] localize_string_2: 134 entries at 0xC000B938
[thd74] localize_string_3: 10 entries at 0xC00C6E58
[thd74] cat_command_table: 53 handlers at 0xC002A828
[thd74] cat_service_command_table: 32 handlers at 0xC0064EDC
[thd74] helpers named: 2
[thd74] libpng_version_string: 2 copies
[thd74] zlib_version_string: 1 copies
[thd74] running auto-analysis (several minutes on 2.5 MB of ARM code)
[thd74] analysis finished
[thd74] vendor source-file strings bookmarked: 4
[thd74] libpng functions named: 23
[thd74] saved THD74 in /home/dmcgrath/clones/tools/thd74/ghidra
Three decisions in that output are worth justifying.
ARM:LE:32:v5t, not v7. The ARM926EJ-S is ARMv5TE and cannot execute
Thumb-2 at all, so the v5T Thumb decoder is the hardware-accurate choice. You
will see the TH-D74 firmware described elsewhere as Thumb-2; if you load it as
v7 the 16-bit Thumb in it still decodes, because Thumb-2 is a superset, but a
v7 decoder will also happily turn pairs of 16-bit instructions into one
32-bit instruction that this CPU could never run. The script takes
--language ARM:LE:32:v7 if you want to compare the two listings — that
comparison is a good exercise, and the answer is in the silicon, not the
disassembler.
A RAM block past the end of the image. The image stops at 0xC027FFFF,
but .bss, the heap, and the stacks are above it in the same DDR window.
Without a block there, every reference to a global lands outside defined memory
and Ghidra shows nothing. The size is a working assumption, not a datasheet
fact.
A PERIPH block at 0x01C00000. MMIO accesses need somewhere to point
too. TI’s datasheet puts the SYSCFG registers at 0x01C14000, which places the
peripheral region; the script labels that one register so the block has an
anchor.
Naming what the image already tells you
Auto-analysis found 8853 functions and could name none of them. Everything below is the script putting names on a fraction of them from internal evidence.
The exception vectors
Seven of those 8853 are reachable by definition: the vector table points at
them. The script types the constant pool as pointers, creates a function at
each target, and names it after the vector that reaches it — reset_handler,
svc_handler, irq_handler, and so on. Vector handlers here are ARM, not
Thumb: their addresses are even, and on ARM the low bit of a branch target is
the instruction set.
That last detail is the whole Thumb problem in one sentence, and it is why the CAT tables below are handled differently.
Worked example: the localized string tables
The string tables are the best anchor in the image, because a single function
reads them and its arithmetic tells you the layout. At 0xC0000238:
$ arm-none-eabi-objdump -D -b binary -m arm -M force-thumb \
--adjust-vma=0xc0000000 --start-address=0xc0000238 \
--stop-address=0xc000026c ghidra/firmware.bin | tail -16
c0000238: b538 push {r3, r4, r5, lr}
c000023a: 0004 movs r4, r0
c000023c: 000d movs r5, r1
c000023e: f00f fd8b bl 0xc000fd58
c0000242: 2801 cmp r0, #1
c0000244: d101 bne.n 0xc000024a
c0000246: 2001 movs r0, #1
c0000248: e000 b.n 0xc000024c
c000024a: 2000 movs r0, #0
c000024c: 2214 movs r2, #20
c0000250: a106 add r1, pc, #24 @ (adr r1, 0xc000026c)
c0000252: 00ab lsls r3, r5, #2
c0000254: 195b adds r3, r3, r5
c0000256: 00db lsls r3, r3, #3
c0000258: 18c9 adds r1, r1, r3
c0000264: f010 f9bb bl 0xc00105de
c0000268: bd31 pop {r0, r4, r5, pc}
Read it as arithmetic and the table defines itself:
adr r1, 0xc000026c— the table base.r5 * 4 + r5, then<< 3— the index times 40 (0x28), the entry stride.movs r2, #20— 0x14 bytes copied, so each entry holds two 0x14-byte columns.- The call at
0xC000FD58returns 0 or 1 and that result scales by 0x14, which picks the column. Entry 2 readsTX/RXin column 0 and Shift-JIS Japanese in column 1, so column 0 is English.
So: 0x28-byte entries, English at +0, Japanese at +0x14, base 0xC000026C. The
script walks entries while both halves stay plausible text and finds 377 —
which matches the entry count Travis Goodspeed reported from the hardware dump,
a good independent check that the two of us are looking at the same table.
It then types the table as an array of localized_string { char en[0x14];
char ja[0x14]; }, labels every entry with its own text, and repeats the trick
for the three other copies of the same helper found elsewhere in the image
(603, 134, and 10 entries). That is 1124 labelled strings, each of which becomes
a cross-reference the moment some UI function loads it.
⚠️ The counts for the second, third, and fourth tables are heuristic: the script stops where the bytes stop looking like paired text. Treat 377 as solid and the rest as a starting point.
Worked example: the CAT command tables
The TH-D74 speaks CAT, Kenwood’s serial control protocol — two-letter commands
over USB or Bluetooth. Both dispatch tables are plain arrays of
{ handler pointer, 4-byte name }:
$ python3 - <<'EOF'
import struct
b = open("ghidra/firmware.bin", "rb").read()
for i in range(4):
o = 0x2a828 + i * 8
print(f" 0x{struct.unpack_from('<I', b, o)[0]:08x} {b[o+4:o+8]!r}")
EOF
0xc0065041 b'0G\x00\x00'
0xc00650a5 b'0E\x00\x00'
0xc002a9d1 b'AI\x00\x00'
0xc002aa69 b'AG\x00\x00'
Note the handler addresses are odd. 0xC0065041 is not an instruction
boundary — it is 0xC0065040 with the Thumb bit set, which is how ARM encodes
“switch to Thumb” in a branch target. The script masks the bit off to place the
function and uses it to decide the decoder, which in Ghidra means setting the
TMode register for that address before disassembling (ArmDisassembleCommand
with thumbMode=true does both). Get this wrong and you get a page of
plausible garbage instead of a handler.
Walking outward from the two addresses while entries stay valid gives 53 standard commands and 32 service-mode commands, and every one of them names a function:
$ python3 project_stats.py --project-dir ~/clones/tools/thd74/ghidra --prefix cat_
cat_* (70):
cat_0E
cat_0G
cat_AE
...
cat_svc_1V
cat_svc_2V
cat_svc_9E
cat_svc_9R
85 table entries, 70 distinct functions: fifteen commands are served by a
handler that also appears in the other table, which is itself a finding. The
service table’s 0G and 0E handlers are the standard table’s — the
service-mode entry points are reachable from the normal command parser, and
whether you can reach them from a stock radio over USB is exactly the kind of
question this project exists to answer.
Worked example: libpng by error message
Those 848 PNGs in IMAGE DATA have to be decoded by something, and that
something is a statically linked libpng. Two version strings date it precisely:
$ python3 - <<'EOF'
b = open("ghidra/firmware.bin", "rb").read()
for s in (b"1.6.8", b"1.2.8"):
print(f"0x{0xc0000000 + b.find(s):08x} {s.decode()}")
EOF
0xc00b3040 1.6.8
0xc00f98c0 1.2.8
libpng 1.6.8 and zlib 1.2.8, both from late 2013. That is the lever: libpng
calls png_error() and png_warning() with string literals, and most of those
literals appear in exactly one function in the upstream source. Download the
matching release, build a message → function map, and any message that survives
as unique in both the source and the image names a function for free.
png_msgmap.py builds the map:
$ curl -sSLO https://downloads.sourceforge.net/project/libpng/libpng16/older-releases/1.6.8/libpng-1.6.8.tar.gz
$ tar xzf libpng-1.6.8.tar.gz
$ python3 png_msgmap.py libpng-1.6.8 png_msgmap.json
563 literals, 520 unique to one function -> png_msgmap.json
Of those 520, 48 appear exactly once in the firmware, between them identifying
26 functions. build_project.py then finds each message’s address, follows the
references back to the function that prints it, and renames it — following
references through one level of literal pool, because Thumb code loads a string
address with ldr rN, [pc, #imm] and Ghidra attributes the reference to the
pool word rather than the instruction. 23 survive to be named:
$ python3 project_stats.py --project-dir ~/clones/tools/thd74/ghidra --prefix png_
png_* (23):
png_cache_unknown_chunk
png_check_chunk_name
png_combine_row
png_handle_PLTE
png_handle_unknown
png_read_IDAT_data
png_read_row
png_read_update_info
png_set_PLTE
png_set_longjmp_fn
png_user_version_check
...
Each gets a plate comment recording why it has that name, which matters when you come back in a month: these are inferences from a message, not symbols.
Why 23 and not 26? Because the inference is not always clean. Two messages can land in one function if the compiler inlined a helper, and a message’s reference can sit outside any function the analyzer found. The script detects the first case, leaves a comment naming both candidates instead of guessing, and moves on.
The same trick applied to zlib pays much worse, and the reason is instructive.
zlib sets strm->msg from inside inflate() itself rather than from the
function that failed, so its messages identify one enormous function rather
than twenty small ones. Worse, they are not unique:
$ python3 - <<'EOF'
b = open("ghidra/firmware.bin", "rb").read()
s = b"invalid distance too far back"
i, out = b.find(s), []
while i >= 0:
out.append(0xc0000000 + i)
i = b.find(s, i + 1)
print([hex(a) for a in out])
EOF
['0xc00fc7b8', '0xc010c65c']
Two copies of that message means two copies of the inflate code in the image — probably libpng’s and one linked separately — and a message that matches twice identifies nothing. The script skips any message it cannot place uniquely, which is the only honest thing to do with it.
What you end up with
$ python3 project_stats.py --project-dir ~/clones/tools/thd74/ghidra
program : FIRMWARE_V1.10.000 (ARM:LE:32:v5t)
FIRMWARE : c0000000 - c027ffff (2621440 bytes)
disassembled : 788512 bytes (30.1% of FIRMWARE)
functions : 8853 of which named: 109
defined data : 29614 items
symbols : 22320
109 named functions out of 8853 is 1.2%, and that is a perfectly good result. The named ones are the ones that reach the outside world — the serial command handlers, the string layer the UI reads, the image decoder that parses attacker- supplied PNG data — and they are the entry points for every question worth asking next. The other 8744 become reachable by reading outward from these, which is the technique on Software Reverse Engineering under “orienting without symbols.”
Open it in the GUI from the directory you built it in:
$ ghidra ~/clones/tools/thd74/ghidra/THD74.gpr
Limits of what this gets you
- 30% disassembled, not 100%. The rest is data, DSP payloads, and code nothing reached from our entry points. Ghidra’s ARM Aggressive Instruction Finder will raise the number and also invent functions out of data — turn it on deliberately, not by default.
- No vendor symbols exist anywhere in this image. Four source file names
(
Fmc_msg.c,FrtcCalib.c,mc_searchengine.c,rtcCalib.c) survive as strings, bookmarked by the script, and that is the entire debug legacy. - Static only. There is no stack, no heap, no peripheral state. Questions about what the radio actually does with a malformed CAT command need either the JTAG route from JTAG and SWD or an emulator.
- The DSP is not here.
FIRMWAREis ARM code. Whatever runs on the C674x arrives from somewhere else, and finding out where is an open question.
Key takeaways
- Identify the SoC first. “OMAP-L138” settles architecture, instruction sets and endianness before you open a disassembler, and it tells you which Thumb you have — ARMv5TE, not Thumb-2.
- The flash address and the load address are different numbers. A NOR-booted image is copied to RAM; the vector table’s constant pool tells you where.
- Eight words of vector table resolve endianness, load address, and entry point at once. Read them before anything else.
- On ARM, bit 0 of a code pointer selects the instruction set. Table-driven handlers with odd addresses are Thumb, and loading them as ARM produces confident nonsense.
- Dispatch tables are the highest-value anchor in an embedded image: one array gives you dozens of named, externally reachable functions.
- A function that computes an index into a table publishes that table’s layout. Read the shifts and adds as arithmetic — stride, width, and column offset are all there.
- Statically linked open-source libraries carry their own symbols in the form of error messages. Match them against the exact upstream release and you get real function names for free.
- Record the evidence for every name you apply. A plate comment saying “named from an error message only this function prints” is the difference between a finding and a guess you will trust too much later.
References
- Travis Goodspeed (KK4VCZ), “Kenwood TH-D74 Firmware” — https://kk4vcz.com/posts/th-d74-firmware/
- Recessim wiki, Kenwood TH-D74A teardown and flash dump — https://wiki.recessim.com/view/Kenwood_TH-D74A
thd74tool, updater decryption and section export — https://github.com/cr/thd74- TI OMAP-L138 datasheet (SPRS586) — https://www.ti.com/lit/ds/symlink/omap-l138.pdf
- Arm ARM926EJ-S technical reference manual — https://developer.arm.com/documentation/ddi0198/latest/
- ARMv5 architecture reference manual (Thumb and interworking) — https://developer.arm.com/documentation/ddi0100/latest/
- Ghidra — https://ghidra-sre.org/
- PyGhidra scripting — https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Features/PyGhidra
- libpng 1.6.8 source — https://sourceforge.net/projects/libpng/files/libpng16/older-releases/1.6.8/
- zlib — https://zlib.net/
- setuptools,
pkg_resourcesdeprecation — https://setuptools.pypa.io/en/latest/pkg_resources.html - Motorola S-record format — https://en.wikipedia.org/wiki/SREC_(file_format)
Related course pages: Software Reverse Engineering · Dumping flash · JTAG and SWD · Other IoT radios · Attacks · Schedule
🛠️ Maintenance note: the PyGhidra API is the fastest-moving piece here —
open_program()is already deprecated in favour ofopen_project()plusprogram_loader(), which is whatbuild_project.pyuses, and Ghidra 13 may move it again. The addresses and table layouts are tied to firmware V1.10.000; a different release shifts every one of them, so re-run the anchor checks rather than trusting the constants at the top of the script.thd74toolitself is unmaintained upstream (last release 0.0.1a2) and will keep breaking against new setuptools and Python releases.