MSP430G2444: The Eighty Percent That Comes After Extraction
Extraction occupies the imagination and a small share of the calendar. Once the array is read, the deliverable does not exist yet. What exists is a file of words with addresses, and turning it into something a person can act on is the larger part of the work.
This is the part that is hard to quote, because its difficulty is not in any single step. It is in the accumulation: every routine understood contributes a little, and the total only becomes useful near the end.
Step one: which toolchain
The compiler influences everything downstream. Its startup code has a characteristic shape, its library routines have recognisable implementations, and its calling conventions determine how parameters appear at a call site.
Two observations usually settle it. The startup sequence — the order in which the stack pointer, the watchdog and the clock are configured — is diagnostic, because each vendor’s startup file has a different order and different comments compiled away. The library routines are the second, since division, multiplication and memory copy are implemented differently and can be matched against known builds.
Why it matters: knowing the compiler tells you how variadic functions pass arguments, how structures are aligned, and whether the code you are looking at was optimised. Each of those changes how much of the image you can read confidently.
Step two: function boundaries
On this architecture function boundaries are easier than on most. Calls are explicit instructions with a target, returns are explicit instructions, and the vector table points at entry points.
| Source of boundary information | What it gives |
|---|---|
| Call instructions | Targets that are certainly functions |
| Vector table | Interrupt handlers, named by source |
| Return instructions | Ends of functions, once the start is known |
| Startup code | The call to main, which anchors the top of the graph |
The remaining ambiguity is the leaf function reached only by pointer. Those have to be found by scanning for the prologue pattern or by noticing that a table contains an address that is not otherwise referenced.
Step three: names before understanding
A naming discipline that works: name by the peripherals touched, not by the guess at intent.
A routine that writes the serial transmit buffer, waits on a flag and returns is uart_tx_byte. A routine that reads an analog channel, subtracts a constant and writes another register is adc_read_scaled. Those names are defensible from the code alone, and they make the rest of the analysis navigable.
Guessing intent too early — calling something compute_pid on the basis of two multiplies — produces names that have to be revised and a graph that has to be redrawn. The discipline is to name what is observable and leave the intent until the call graph is complete.
Step four: structures
A structure appears in the image as a base register plus literal offsets. The evidence is a routine that loads an address once and then accesses many displaced locations through it.
Recovering the layout is mechanical once the routine is identified: list every offset, note the width of each access, and infer the fields. Byte at offset zero used as a flag, word at offset two used as a counter, six bytes at offset four copied in bulk — that is a structure description, and it is usually enough.
The payoff is large: once two routines are seen to operate on the same structure, their relationship is established, and the program starts to look like a design rather than a sequence.
Step five: the protocol
If the product communicates, the protocol is the most valuable thing in the image. It is also the most tractable, because protocol code is repetitive by nature.
The signature to look for is a buffer, a length, a loop that moves bytes, and an arithmetic combination over them. That combination is the checksum, and it is the part that has to be reproduced exactly.
- Find the transmit routine and note the buffer it fills.
- Find the checksum computation that runs over the buffer before transmission.
- Extract the polynomial or the additive constant, and the byte order.
- Find the receive path and the length framing.
- Write the protocol down as a document, not as a comment in the listing.
Step five is the deliverable. A protocol document lets someone else build a compatible device; a comment in a listing does not.
Step six: the state machine
Most of these programs are built around a state variable. Finding it is the same exercise described for smaller images, with one difference: at this size there may be several state machines, one per subsystem.
The way to tell them apart is scope. A state variable that is only tested inside one cluster of routines governs that cluster. A variable tested across clusters is the top-level mode, and the clusters hang off it.
What the deliverable looks like
The output of all six steps is a document with five parts: the memory map, the function inventory with names and one-line descriptions, the structure definitions, the protocol specification, and the state machines.
That document, plus the disassembly with the annotation applied, is what a client can actually use. It is also what makes the work repeatable, because the next person to look at the image starts from an inventory rather than from an address zero.
Related reading
- MSP430G2252 and how the deliverable is scoped — the commercial framing of this work.
- MSP430G2544 and why a full array changes the analysis — the size at which these steps stop being optional.
- MSP430G2121 and the instruction set this depends on — why the boundaries are recoverable at all.
FAQ
Can a decompiler skip these steps? It produces readable-looking output that is frequently wrong about types and never rebuilds. It is an aid, not a result.
Which step takes longest? Structures. The offsets are tedious and the confirmation requires reading several routines.
Is the protocol always recoverable? Only if it is implemented in software. A hardware-assisted interface may not be visible in the image at all.
How much of the image remains unanalysed? In practice a third. It is usually library code and unexercised error paths.
Conclusion
Extraction is a day and the analysis is a fortnight. Identify the toolchain, recover the boundaries, name by behaviour, rebuild the structures, document the protocol, and draw the state machines. The file is not the deliverable; the document is.