PostHeaderIcon ST72F325J6 Program Code Extraction: Telling Tables From Instructions

A ST72F325J6 program code extraction begins with a file and a question the file does not answer: which bytes are instructions. The architecture gives no help. Instructions and data share one address space, one bus and one byte ordering, and a disassembler asked to render the whole image as code will render the tables as code too, with results that look like a program and are not.

The four signals that separate them are structural rather than visual. None requires knowing the product. Together they resolve almost every byte in a 64 KB image, and the residue is small enough to review by hand.

One address space, two kinds of content

A Harvard machine keeps instructions and data in separate memories, and a reader knows which is which from the address. A von Neumann machine, which is what this device is, has one memory and one address space, and the distinction is a convention of the program rather than a property of the hardware.

property consequence
single address space a table address and a code address look identical
single bus fetching a table and executing it use the same path
no execute permission bit the hardware cannot mark a region non-executable
no alignment requirement on data tables start wherever the linker put them

The last row is the one that makes the problem hard. On an architecture that aligns data, a table’s start address is a hint. Here it is not.

Why the disassembler cannot decide

A linear disassembler decodes every byte from a start address and produces a listing. Where the byte is genuine code, the listing is right. Where the byte is table data, the decoder produces instructions that are syntactically valid and semantically meaningless, and it then continues from a position that no longer corresponds to any instruction boundary.

The damage propagates. A single misidentified table shifts the decode phase, and everything after it is decoded from the wrong offsets. The output becomes progressively less plausible, which is why long stretches of a naive disassembly often look like nonsense towards the end.

The correct approach is to decode from known entry points outward, never linearly, and to stop at boundaries that the evidence supports.

Entry points: the only hard evidence

The hardware provides entry points, and they are the only facts in the image that cannot be wrong.

source number reliability
interrupt vector table at the top of the map sixteen entries exact, it is what the hardware uses
reset vector, the last two bytes one exact
direct call and jump targets many exact, the instruction names the target
computed jumps through a register unknown the analysis has to find them

Decoding outward from the vector table alone usually accounts for the majority of the code, because 8-bit products are interrupt-driven and most functions are reachable from a handler or from the main loop that the reset vector enters.

The table signature

A table has three properties that code does not, and each is checkable.

The first is stride. Tables are read at a fixed element size, so their content becomes regular when viewed at that width: sixteen-bit values that form a curve, eight-bit values that fall in a narrow range, four-byte records with a repeated internal structure.

viewed as code region table region
bytes varied, with frequent small values clustered in a range
16-bit words decoded instructions become nonsense smooth curve or monotonic sequence
16-bit with stride 4 irregular repeated record pattern

The second is that a table is referenced from code. Somewhere there is an instruction that loads its address, and that instruction is a direct pointer to the table’s base. Finding those pointers is a matter of scanning the decoded code for address loads that land outside any function.

The third is the absence of internal control flow. A table contains no branches. If a candidate region decodes as a sequence of branches, it is code, however implausible the branches look.

The index register as a discriminator

The strongest single signal is which register touches the memory.

Code accesses memory through direct addressing for globals and through the frame for locals. Tables are accessed through an index register, because that is what an index register is for: the program computes an offset, loads it, and reads through it.

That produces a distinctive pattern in the code around a table: a load of an offset, a load of a base address, an access through the index, and a store of the result. The section of memory addressed by that base is a table, and its length is bounded by the highest offset the code can generate.

observation in the code what it identifies
base address loaded, then indexed access the start of a table
comparison against an offset before indexing the table’s length
two tables indexed with the same register in sequence paired tables, often a lookup and its inverse
indexed write as well as read a buffer in RAM, not a table in flash

The last row catches a common misclassification. An indexed access that writes is addressing RAM, so the pattern identifies a data structure rather than a constant table, and the region it points at is not in flash at all.

A practical sweep

The work proceeds in passes, and each pass adds entry points rather than refining the previous guess.

Start from the vector table and the reset vector. Decode outward, following direct calls and jumps, and record every target. Mark each target as a function start. Then scan the decoded code for address loads that land outside the marked regions: each one points at a table or at a string. Mark those regions as data. Then re-scan the remaining unmarked bytes for instructions that decode into valid code with a plausible boundary: any cluster that survives becomes a candidate function, to be confirmed by a call reference or discarded.

pass input output
one vector table, reset vector function starts, initial code regions
two decoded instructions table and string regions
three unmarked bytes candidate functions
four candidates confirmed functions or discarded regions

Three passes usually resolve a 64 KB image, because the code is small and the call graph is shallow.

Where the judgement calls remain

Two categories resist resolution, and both should be reported rather than guessed.

The first is padding. A linker fills unused space with a pattern, and that pattern may decode as instructions. It is identifiable by its uniformity and by the absence of any reference to it, and it should be marked as padding rather than as code.

The second is code reachable only through a computed jump. A state machine implemented as a jump table has no direct call to its states, so they appear as unmarked regions until the jump table itself is found. The table is the entry point, and finding it is the same indexed-access pattern described above.

unresolved region likely content how to report it
uniform repeated pattern padding marked, not analysed
plausible code with no references jump table target marked as state handler
high-variety data with no references unreferenced table marked as data, flagged
decodes cleanly but contradicts the call graph overlapping code and data flagged for review

What the extraction delivers

The output is a map, not a decompilation: address ranges with their classification, function entry points, the tables with their strides and element types, and a list of regions where the classification is uncertain.

That map is what makes everything downstream possible. A reconstruction of the source needs it, as described in ST72F321BAR9T6 source code extraction. A decision about whether a region is encrypted rather than tabular needs it, as described in ST72F321BK flash memory decrypt. And loading the image so that any of this is meaningful requires the base-address discipline in ST72F32AJ1 flash memory binary.

The measure of a good extraction is not how much it decodes but how little of the image remains unclassified, and whether the classification is stated in a way that a second engineer can check.

Comments are closed.