Posts Tagged ‘fpga program recovery’
Behavioural Reconstruction: The Route When Reading Is Impossible
There are devices whose contents cannot be obtained at any price: a masked part with a coated die, a chip that was potted into a housing, a product whose only unit is also the only sample of a discontinued design. For those, the question stops being how to read it and becomes how to replace it.
Behavioural reconstruction answers that question. It does not recover the program; it produces something that behaves like the program at the interface, which is what a replacement needs.
What reconstruction substitutes for
Reading gives content. Reconstruction gives a model. The two are equivalent only in what they can support.
Content supports everything: modification, comparison, forensic claims, reimplementation. A model supports replacement and interoperability, and it supports nothing that requires knowing what is inside.
| Question | Content answers | Model answers |
|---|---|---|
| What does it do | Yes | Yes, at the pins |
| How does it do it | Yes | No |
| Can I change the behaviour | Yes | Only by changing the model |
| Is this code derived from that source | Yes | No |
| Can I build a replacement | Yes | Yes |
The last row is the one that justifies the work. A customer who needs to keep a product in production after a part becomes unavailable needs replacement, and replacement does not require content.
Step one: decide what is observable
The ceiling on reconstruction is set before any measurement, by the interface.
Observability has three dimensions: which signals are reachable, at what resolution, and with what controllability on the input side. A design with twenty digital inputs and ten digital outputs, all accessible on a connector, is a design that can be characterised exhaustively. A design with a single bidirectional pin and internal analog functions is one that can barely be characterised at all.
| Observability | Characterisation possible |
|---|---|
| All inputs and outputs on a connector | Exhaustive |
| Most signals on test pads | Near-exhaustive |
| Signals only on the die | Requires probing, limited |
| Analog behaviour inside the part | Only at the boundary |
The fourth row is the important limit. An analog function that is never exposed — a filter that operates on an internal signal — cannot be characterised, and a model of the part will be wrong for any input that exercises it.
Step two: design the stimulus
The stimulus has to cover the state space rather than the input space, and those are different sizes.
A combinational design has no state, so the input space is the whole space. A sequential design has state, and the number of reachable states is usually far smaller than the number of input sequences, which makes a state-oriented stimulus more efficient than a random one.
| Design type | Space to cover | Stimulus |
|---|---|---|
| Combinational | All input combinations | Exhaustive sweep |
| Small state machine | Reachable states times inputs | State-directed sequences |
| Protocol interface | Message types and orderings | Sequence generation |
| Data path | Value ranges and corner cases | Directed plus random |
The third row is the one that appears most often in practice. A device that speaks a protocol has states that only certain message sequences reach, and a random stimulus will not find them. The state machine has to be inferred incrementally: send a sequence, observe the response, extend the sequence.
Step three: fit the model
With stimulus and responses in hand, the model is fitted, and the fitting method depends on the design type.
| Design type | Model form | Fitting method |
|---|---|---|
| Combinational | Truth table or Boolean expression | Direct from the sweep |
| State machine | Transition table | From observed transitions |
| Data path | Arithmetic plus conditions | Regression on the observations |
| Protocol | Message formats plus states | From the capture analysis |
The second row is the one that produces a usable artefact. A transition table with states, inputs and next states is a specification, and it can be implemented directly. The work of deriving it is the state exploration described in protocol reverse engineering.
Where reconstruction fails
Three conditions make reconstruction unreliable, and they should be established before the work is quoted.
Hidden state is the first. A design that maintains internal state that never affects an output until a rare condition is met is a design whose model will be wrong for that condition, and the wrongness will appear in the field rather than on the bench.
| Failure condition | Symptom | Detectable before work |
|---|---|---|
| Hidden state | Intermittent divergence | No, until the condition occurs |
| Timing sensitivity | Works at one speed, fails at another | Yes, by varying the clock |
| Analog behaviour | Correct digitally, wrong in the system | Partly, by system test |
| Randomness | Non-repeatable outputs | Yes, by repetition |
The first row is the reason a reconstructed model is always delivered with a statement about what was tested. A model that has been exercised across the reachable state space is strong; a model that has been exercised across the states someone thought of is weak, and the difference is invisible to the customer unless it is stated.
The fourth row is a special case worth flagging. A device that produces random or pseudo-random output cannot be modelled exactly, only statistically, and a replacement must reproduce the distribution rather than the sequence.
What acceptance looks like
The acceptance criterion for a reconstruction is behavioural equivalence over a defined test set, and the definition of the test set is part of the deliverable.
| Criterion | What it means | Strength |
|---|---|---|
| Passes the recorded stimulus | Reproduces the observations | Weak; it is the training set |
| Passes a held-out stimulus | Generalises | Moderate |
| Passes the system test | Works in the product | Strong |
| Passes a specification test | Meets the documented requirement | Strongest |
The second row is the minimum acceptable standard. A model that reproduces only the observations used to build it has learned nothing, and a held-out test — stimulus recorded but not used in fitting — is the cheapest way to detect that.
The third row is what the customer actually cares about, and it is worth designing the characterisation so that a system test is possible: a harness that drives the real product through its real functions, comparing the original and the replacement.
When reconstruction is the wrong choice
Reconstruction is expensive and its ceiling is real, so it is worth saying when not to use it.
If the device can be read at all, reading is cheaper and gives more. The routes are in extracting MCU firmware, and a device that is merely protected rather than unreadable should be attacked rather than modelled.
| Situation | Better route |
|---|---|
| Device readable | Read it |
| Device protected but present | Attack surface analysis |
| Device unreadable, design simple | Reconstruct |
| Device unreadable, design complex | Redesign from product requirements |
The fourth row is the honest alternative and it is often better than reconstruction. If the product’s requirements are documented, a new design that meets them is a better outcome than a model of an old one, because the new design is maintainable and the model is not.
What the service delivers
A model, a characterisation report listing what was tested, and a conformance test that the customer can run against the replacement.
| Item | Content |
|---|---|
| Model | Transition table or equivalent |
| Characterisation report | Stimulus, coverage, gaps |
| Conformance test | Vectors and expected responses |
| Statement of limits | What was not observable |
The fourth item is the one that makes the deliverable honest, and it is the reason a customer can trust the model for the purpose it was built for without trusting it for anything else.
The equivalence claim for a programmable logic device is the narrower version of the same idea and is set out in FPGA pin-level equivalence. Where the device is a masked microcontroller whose contents are in ROM, the optical route in breaking a one-time device may still be available and is worth costing before reconstruction begins.