PostHeaderIcon PIC18F65K22: What a Disassembly Predicts, and What It Only Suggests

An image read from a device is a sequence of instructions, and instructions are facts. What those facts imply about the product — its function, its operating conditions, its failure behaviour — is inference, and inference of varying quality.

The distinction matters because a disassembly feels authoritative. Every line is correct; the conclusions drawn from it are not automatically so, and the errors that result are hard to see because the underlying listing is accurate.

Facts

These are read directly and are not in doubt:

  • which addresses contain which instructions;
  • which addresses are called and from where;
  • which peripheral registers are written, and in what order;
  • which constant tables exist, their stride and their values;
  • where the code branches to, and under what condition.

That is a complete description of the instruction stream. It is what a disassembler produces, and it is reliable.

Inference of the first kind: strong

Some conclusions follow so directly that they are effectively facts:

Observation Conclusion
Write to clock registers early in start-up The device configures its own clock
Table read in a loop with accumulate A filter or a scaling operation
Periodic timer interrupt with a counter A scheduler tick
Branch on a status bit from a peripheral Polled I/O on that peripheral

Each of these is a pattern that appears for one reason. A reader who has seen a hundred firmware images will read them correctly.

Inference of the second kind: plausible

These are likely and sometimes wrong:

  • A block of coefficients is a filter. It might be a calibration curve, a gain schedule, or a protocol table. Its shape suggests one; its use confirms which.
  • A long delay loop is a timing requirement. It might be a workaround for a hardware erratum, or leftover code never removed.
  • An unused routine is dead code. It might be called through a computed jump, or from a region that is protected.
  • The largest table is the most important data. It might be a lookup that is rarely used.

Each of those is a hypothesis that a single measurement can confirm or refute, and treating it as established is how analysis goes wrong.

Inference of the third kind: unsupported

These appear in reports and should not:

  • “The device implements X algorithm.” Only if the table values match the algorithm’s constants, or the outputs match its characteristic.
  • “The protection was defeated.” Only if data that was previously inaccessible is now readable.
  • “The firmware is a modified version of the vendor’s reference.” Similarity requires a reference to compare against.
  • “The device was configured for conditions Y.” Configuration says what is possible, not what was done.

The third kind is where technical work becomes speculation, and the fix is always the same: identify the measurement that would settle it, and take it.

Using the device to confirm

The confirmation loop is short:

  1. Form a hypothesis from the disassembly.
  2. Predict an observable consequence.
  3. Measure the device.
  4. Compare.

For example: a coefficient block suggests a second-order filter. The prediction is that a step input produces a specific response shape. The measurement takes a minute with a signal generator and a scope. Either it matches, in which case the hypothesis is confirmed and the coefficients are explained, or it does not, in which case the block is something else.

That loop is what separates an analysis from a reading. It costs little and it converts hypotheses into statements.

The configuration’s role

Configuration is readable and states the device’s operating envelope: oscillator, watchdog, brown-out, programming interface, protection. It does not state what the firmware does, and it constrains inference usefully — a device configured for an external crystal did not derive its timing from the internal oscillator, whatever the code appears to assume.

Reading configuration first is the habit that keeps inference honest, because it removes a class of hypotheses before they are formed.

Reporting

A report that distinguishes its three kinds of statement is more useful than one that does not, even when the second kind outnumbers the first. The distinction tells the reader which parts to trust and which to test.

The discipline is simple to state: every claim that is not a direct reading should name the measurement that would confirm it, and say whether that measurement was taken.

Related reading

FAQ

Is a disassembly reliable? As a description of instructions, yes. As a description of the product, only where its implications are confirmed.

How do I confirm a hypothesis? Predict an observable consequence and measure it. If it does not appear, the hypothesis was wrong.

Why are coefficient tables ambiguous? Because encoding is a convention. Their use in code and the device’s response resolve them.

Does configuration tell me what the firmware does? No. It states the envelope the firmware operates within.

What makes a report useful? Separating what was read from what was inferred, and naming the measurement for each inference.

Conclusion

A disassembly is a set of facts and a generator of hypotheses. Treating the two as one produces confident, accurate listings attached to wrong conclusions. The confirmation loop — predict, measure, compare — is cheap, and it is what turns a reading into an understanding.

Comments are closed.