PostHeaderIcon ST72F321BAR9T6 Source Code Extraction: What Comes Back and What Never Will

The request for ST72F321BAR9T6 flash memory source code is the most common way to ask for something that does not exist. Not because the work is impossible, but because “source code” names one specific artefact — the text the original programmer typed — and that artefact was destroyed by the compiler, deliberately and permanently, before the first device was ever programmed.

What can be recovered is a great deal. What cannot be recovered is a specific and predictable list. The work goes badly when the customer expects the second list to be part of the first, and it goes well when the difference is explained before anyone quotes a price.

The word “source” in the request

Three different things get called source code by customers, and they have different feasibility.

The first is the actual C or assembly file, with the original identifiers and comments. This does not exist in the device and cannot be produced from it. Anyone who claims otherwise is either misunderstanding the request or selling something else.

The second is a compilable reconstruction: a set of files that can be built, flashed, and produces a device that behaves identically. This is achievable for many 8-bit products, takes substantial work, and is what a serious recovery aims at.

The third is a readable functional account: what the firmware does, in what order, with which constants, in enough detail to reimplement or to verify. This is almost always achievable and is what most customers actually need once they understand the options.

what was asked for achievable realistic form
the original source files no never
a rebuild that behaves identically usually reconstructed sources plus a build
a functional description with constants yes annotated disassembly plus notes
a list of what the device does at startup yes mapped call sequence

What a compiler destroys

Compilation is a one-way function with respect to several kinds of information, and each one is destroyed for a reason.

destroyed why the compiler removed it any trace left
variable and function names they have no meaning to the machine none, unless debug symbols were stored
comments never reach the compiler at all none
macros and constants-by-name expanded before code generation the expanded values, not the names
type information irrelevant after code generation implied by the operations used
original function boundaries inlining merges small functions partially, via call targets
code compiled out by conditionals not compiled none, by definition
the order of source statements the optimiser reorders freely a partial ordering

The fourth row is more recoverable than it looks. A variable’s type can often be inferred from the instructions that touch it: an 8-bit quantity uses byte operations, a 16-bit quantity uses pairs, a pointer uses indirect addressing through the index registers. That inference is how a reconstruction gets its declarations back, and it is reliable enough that reconstructed code usually compiles cleanly.

What survives, and why

Everything that has to be present for the device to run survives, because the device does run.

The constants survive exactly, because they are data. The strings survive exactly, in whatever character encoding the original used. The peripheral configuration survives exactly, as a sequence of register writes. The control flow survives structurally, even when statements were reordered. And the arithmetic survives in a form that can be read back, because the operations are what the machine performed.

The consequence is that behaviour is recoverable in full and presentation is not recoverable at all. That distinction is the whole of the expectation-setting conversation.

Four grades of recovery

It is useful to put a grade on the deliverable, because it lets a customer choose a stopping point and lets a supplier scope honestly.

grade content effort what it supports
behavioural what the device does, in what order low fault diagnosis, specification writing
structural functions, call graph, data layout medium targeted patching, feature comparison
compilable reconstruction that builds and runs high repair of the production flow
bit-exact identical bytes, matching the original build highest, sometimes impossible proving equivalence

The fourth grade is achievable only when the original compiler, its version, its options and its libraries are all available and reproducible. Without them, a rebuild can be functionally identical and byte-different, and no amount of effort closes that gap.

The tables and strings that carry meaning

Two categories of data give a reconstruction most of its semantic content, and both are easy to extract once the image is loaded.

The first is text. Product names, version strings, error messages, menu labels. On a device built for a display or a serial interface, these strings usually appear in the same encoding the display or the terminal expects, which means they are readable directly from the image.

data type how to find it what it gives you
ASCII or Latin-1 text run-length scanning for printable bytes product identity, messages, version
segment code table stride of the display digit width the display mapping
calibration constants small clusters near startup code the physical units the firmware works in
conversion tables fixed stride with monotonic values the sensor or output scaling

The second is calibration. A device that measures something has constants that convert an ADC reading into a physical quantity, and those constants cluster near the code that uses them. Finding them is usually a matter of following the routine that reads the ADC and looking at what it multiplies by.

State machines: the most recoverable structure

Most 8-bit products of this class are one state machine wrapped around a main loop. That structure is highly recoverable, because the compiler cannot easily destroy it: the states become constants, the transitions become comparisons and jumps, and the actions become blocks of code reached from a switch.

Recovering a state machine from the image means identifying the state variable, enumerating its values, and following each comparison to the block it selects. The result is a diagram that is very close to what the original designer drew, usually closer than the reconstructed C would suggest.

That diagram is often more valuable to a customer than compilable code, because it answers the question they actually have — what does this thing do, and what would break if I changed it.

Setting expectations before the work starts

Three sentences, delivered before the quote is accepted, prevent most disputes.

The image contains behaviour, not naming. We can rebuild something that runs identically; we cannot tell you what the original author called the variables.

The constants are exact. If the product measures something, the numbers it measures with are recoverable precisely, which is usually enough to repair or to verify a design.

The build will not be byte-identical unless the original toolchain is available. If bit-exactness matters, it has to be established as a requirement at the start, because it changes what is possible.

What the delivery contains

A code recovery on this device produces an annotated disassembly with recovered function boundaries, a data map covering tables and calibration, a state diagram where a state machine was found, and — when the compilable grade was purchased — reconstructed sources with a build that produces a working device.

The instruction-versus-data separation that makes the annotated disassembly possible is the subject of ST72F325J6 program code extraction. Where a region of the image is not code at all but encrypted records, the classification work in ST72F321BK flash memory decrypt comes first. And where the recovered code has to be loaded back for any of this to happen, the base-address discipline in ST72F32AJ1 flash memory binary is the prerequisite.

Comments are closed.