PostHeaderIcon PIC18F44K22: The Vector Table Is the Cheapest Thing to Protect

At the bottom of the program memory sit the reset vector and the interrupt vectors: a handful of instructions that point at every routine the hardware can enter. They occupy perhaps thirty bytes. They are also the single most useful thing in an image for anyone trying to understand it.

A vendor who protects only the block containing them has protected almost nothing of value to a copier and a great deal of value to a reader. That is not always deliberate — protection is applied per block, and the first block happens to contain the vectors — but the effect is the same.

What the vectors give a reader

Every decoded image starts somewhere. With the vectors available, it starts in a dozen places simultaneously, each of them a known entry point, each with a known trigger.

Vector available Consequence
Yes Entry points known; decode outward from each
No Entry points inferred from call targets and handler shapes

The difference is not a matter of convenience. Decoding outward from known entry points produces regions that are correct where they exist, and honest gaps between them. Decoding by scanning produces a listing with no anchors, where every inference depends on the previous one.

What the vectors give a copyist

Almost nothing. An address points at a routine; it does not contain it. A copyist with the vectors and not the code has a table of addresses into memory they cannot read.

This is why the protection pattern appears: blocking the first block removes the diagnostic value without any cost to whoever is copying, because copying was never the threat the block was aimed at.

Reading without vectors

If the first block is closed and the rest is open, the image lacks anchors, and four techniques substitute:

  1. Collect call targets. Every call instruction carries a destination. Frequent destinations are functions; unique ones are often main or a dispatcher.
  2. Find handler shapes. Save context, do work, restore, return. Handlers are recognisable by their prologue even without a vector pointing at them.
  3. Follow the tables. A jump table’s targets are a set of nearby addresses, and the table itself identifies the dispatcher that reads it.
  4. Use entry-like sequences. Start-up code initialises the clock in a recognisable order; finding it identifies the reset path even if the reset vector is unavailable.

None of these is as clean as the vector table, and all of them together are usually enough for a 16K image.

The block arithmetic

On this part the array divides into four blocks. The vectors are in the first, along with start-up code and whatever small routines the compiler placed early.

So a device with the first block closed loses: the reset vector, the interrupt vectors, the clock initialisation, and the routines that happen to live nearby. That is a coherent loss, not a random one, and its consequence is that the image begins in the middle of the application with no way to know what came before.

The practical response is to decode the readable region first and treat the missing block as a hypothesis to be tested by behaviour — the clock is measurable, the interrupt map is inferable from which peripherals respond, and the entry point is findable from the loader if one exists.

Protection as an economic decision

Vendors choose protection settings under constraints: what the tooling supports, what the update path requires, what a distributor needs to be able to read for verification.

The result is often a compromise that looks arbitrary from outside and is entirely rational from inside. A first block protected and the rest open is a pattern that says: updates are supported, verification is done by the vendor, and nobody thought about disassembly.

That reading is more useful than a judgement about intent. It predicts what else exists — an update path, a service tool, a production record — and those are often where the answer actually lies.

Related reading

FAQ

How large is the vector table? A few dozen bytes — an insignificant fraction of the array and the most informative content in it.

Can entry points be recovered without it? Yes, from call targets and handler shapes, with less certainty.

Why would a vendor protect only the first block? Because protection is per block and the vectors happen to live there, or because the loader below them must be protected for other reasons.

Does protecting the vectors stop copying? No. Addresses are not code.

What else is in the first block? Start-up code, clock configuration and small routines the compiler placed early.

Conclusion

The vector table is a few dozen bytes that cost nothing to protect and remove the best anchor an image has. When it is missing, the work is inference rather than lookup, and the compensation is behavioural: the clock, the interrupt map and the entry point are all measurable. Recognising the pattern also predicts what else the device has — usually an update path worth more than the code.

Comments are closed.