Posts Tagged ‘mcu code discover’
Black-Box Discovery: Reading Pin Behaviour to Prove Code Exists
A board arrives with an unmarked chip, no documentation, and a question: can the code inside it be recovered. Before that question can be answered, a prior one has to be settled, and it is answerable without opening anything: is there code in it at all.
The distinction matters because a device with code has a route and a device without code does not. A fixed-function part, a mask-programmed logic array, an analog ASIC: none of them contain a program, and a quotation for extracting one is a quotation for a delivery that cannot happen.
Four observations settle it, and all four are made with the device powered and the pins visible.
Observation one: the supply current at power-up
A device executing code has a startup sequence, and a startup sequence has structure. The current rises as the core comes out of reset, steps as the clocks are enabled, steps again as peripherals are turned on, and settles into a pattern that reflects the workload.
A device without code has a current that rises to a level and stays there, with variation only from analog blocks warming up.
| Phase | Device with code | Device without code |
|---|---|---|
| 0–1 ms | Current ramps as the core starts | Current ramps as bias settles |
| 1–10 ms | Step as PLL locks | Flat |
| 10–100 ms | Steps as peripherals enable | Flat |
| Steady state | Ripple at the workload rate | Ripple at the clock rate |
The measurement is a current probe on the supply, or a small series resistor with a differential probe, at a bandwidth of at least a megahertz. The steps are large — tens of milliamps on a device that draws a hundred — and they are unambiguous.
The steady-state ripple is the second piece of evidence. Code that polls a loop produces a periodic ripple at the loop rate; code that sleeps produces bursts at wake-up; code that idles in an interrupt-driven design produces a ripple at the tick rate. A flat steady state suggests either a very tight loop or no code.
Observation two: the clock output
Many microcontrollers can be configured to output a divided system clock on a pin. It is a debugging convenience that survives into production more often than designers expect, because it is useful for board bring-up and nobody removes it.
A clock output is a square wave at a frequency related to the system clock, usually by a power of two. Its presence is strong evidence of a programmable device, because a fixed-function part has no reason to bring a clock out.
| Observation | Inference |
|---|---|
| Square wave at a suspiciously round frequency | Divided system clock |
| Square wave at a non-round frequency | Crystal or oscillator divided |
| No output on any pin | Either no clock output or no code |
| Clock present but stopped after a few ms | Firmware disabled it after startup |
The fourth row is the interesting one and it is not a contradiction. A device that outputs a clock for ten milliseconds and then stops is a device whose firmware reconfigured the pin, which is itself proof of code.
Observation three: bus activity
A device running code from an external memory generates bus traffic at startup, and the traffic has a signature.
On an SPI bus the signature is a read command followed by a burst of addresses, appearing within a few milliseconds of power-up and before any other activity. On an I2C bus it is an address followed by a register read. On a parallel bus it is a stream of addresses with a regular stride.
| Bus | Startup signature | What it proves |
|---|---|---|
| SPI | Read command plus address burst | A processor fetching an image |
| I2C | Device address plus register reads | A processor initialising peripherals |
| UART | A byte at a specific baud rate | Firmware announcing itself |
| Parallel | Sequential addresses | A fetch from external memory |
The SPI signature is the most informative, because it proves not only that code exists but where it is. A capture of the first millisecond of that bus is the single most useful measurement in a black-box investigation, and it takes ten minutes with a logic analyser.
Observation four: pin sequencing
A processor initialising its GPIOs produces a characteristic pattern: pins that were floating or pulled become driven, one after another, in an order that reflects the initialisation code.
A fixed-function device drives its outputs as soon as its supply is valid, all at once, because there is no code to sequence them.
| Pattern | Inference |
|---|---|
| Pins become driven in a staggered order | GPIO initialisation by code |
| All outputs valid within microseconds | Hardware-only device |
| A pin toggles once then stays | A reset or handshake sequence in code |
| A pin pulses periodically | A timer or a heartbeat in code |
The fourth row is a gift when it appears. A periodic pulse on an otherwise unexplained pin is almost always a firmware heartbeat, and its period is a direct readout of the tick rate. That number identifies the clock configuration, which in turn narrows the part family considerably.
Putting the four together
Each observation is suggestive on its own. Together they are conclusive, and the combination is what makes the conclusion defensible in a report.
| Evidence | Code present | Code absent |
|---|---|---|
| Current steps at startup | Yes | No |
| Clock output present | Likely | Unlikely |
| Bus traffic at boot | Yes | No |
| Staggered pin initialisation | Yes | No |
Three of four is enough for a confident statement. One of four is not, and the report should say which observations were made and which were not possible on the board in question — a board that is potted may not allow probing, and a board whose bus is not accessible may not allow a capture.
What follows from the answer
If code is present, the investigation continues into the part identification described in attacking a custom IC, and from there into the surface map in MCU attack surfaces.
If code is absent but the device has non-volatile storage, the contents are data rather than program, and the useful question becomes what the data means rather than how to run it. That is a different engagement with a different deliverable.
If the evidence is ambiguous — a device with a clock output but no bus activity and a flat current profile — the most likely explanation is a masked microcontroller running entirely from internal memory. That is still code, and the route is the one for a protected MCU whose storage is on the die.
| Conclusion | Next step |
|---|---|
| Code present, external memory | Read the memory |
| Code present, internal memory | Surface map, then the appropriate route |
| Data only | Interpret the data |
| Ambiguous | Probe more pins, capture longer |
Where the service fits
The deliverable at this layer is a one-page finding: whether the device executes code, the evidence for each observation, and the recommended next step. It is produced in an afternoon with a current probe and a logic analyser, and it costs a fraction of any subsequent work.
What it prevents is the most expensive category of wasted engagement: a decapsulation and a physical read performed on a part that had no program in it, which happens more often than the industry admits and is discovered only when the image turns out to be a wiring pattern.
The interpretation of what the code does, once its existence is established, is the analysis in MCU break. The question of where it is stored, once it is known to exist, is the subject of extracting MCU code.