Posts Tagged ‘saldırmak mikrodenetleyici dump’

PostHeaderIcon Attacking the PIC16C710: Code Protection on a 512-Word EPROM Part

The PIC16C710 is the smallest member of Microchip’s PIC16C71X family, and that single fact reshapes everything about attacking it. Most protection discussions assume a large firmware image where the difficulty is extracting megabytes without error. Here the entire program is 512 instruction words. The difficulty is not volume. It is that the part is EPROM, that the code-protect bit lives in the same array as the code, and that the documented way to clear the bit destroys what it protects.

The part in context

Before going further, one correction worth making explicitly, because it propagates widely: the PIC16C71X datasheet header advertises “up to 2K × 14 words of program memory, up to 128 × 8 bytes of data memory.” Those are the family maximums, reached by the PIC16C715. They are not the PIC16C710’s specifications.

Property PIC16C710
Program memory 512 × 14 words EPROM
Address range 0000h–01FFh
Data memory (RAM) 36 bytes
I/O pins 13
Timer modules 1 (Timer0)
A/D converter 4 channels, 8-bit
Package 18-pin PDIP/SOIC, 20-pin SSOP
Supply 2.5 V – 6.0 V
Brown-out reset Yes
In-circuit serial programming Yes

The family’s 13-bit program counter can address 8K × 14, but only the first 512 words are implemented here. Accessing an address above 01FFh causes a wraparound, not a fault — a behaviour that matters when reading a dumped image, because a wraparound can make a truncated read look complete.

Memory organisation

The reset vector is at 0000h and the interrupt vector at 0004h, so the first eight words are effectively fixed: a jump to the main routine, and a jump to the interrupt handler. Everything the device does is reachable from those two addresses.

Data memory is organised in banks of 128 bytes, with the Special Function Registers occupying the low addresses of each bank and General Purpose Registers — implemented as static RAM — above them. With only 36 bytes of GPR available, the firmware cannot afford abstraction. State is held in SFRs and a handful of bytes, which has a useful side effect for anyone reading a recovered image: there is nowhere for the code to hide. A 512-word program using 36 bytes of RAM is close to self-documenting once the SFR accesses are annotated.

The A/D converter is the other fixed point. Four channels of 8-bit conversion implies reference and scaling constants, and on a part this small those constants are typically sitting in the last few words of the array as a look-up table or as inline literals.

How code protection works here

Configuration bits on this family are programmed at address 2007h, which is part of the same EPROM array as the program. The code-protect bit, when programmed, prevents the program memory from being read out over the programming interface — including in-circuit serial programming.

The consequence is structural rather than procedural. Because the configuration word and the program live in one array, there is no operation that clears the code-protect bit while leaving the program intact. On a windowed CERDIP part, ultraviolet erase clears both together. On an OTP part, there is no erase path at all, so the barrier is permanent for that device.

This is the same design pattern found across the microcontroller world — the mechanism differs, the asymmetry does not. PIC16C711 code protection shows the identical arrangement on the next part up, and PIC16C71 program recovery covers the original variant.

What attacking it can mean

Four routes exist, in increasing order of cost.

Read over the programming interface. With the bit clear this is trivial: the programmer reads 512 words plus the configuration word and emits a hex file. With the bit set, the device returns nothing useful. Note that the protection does not necessarily announce itself — a protected read may return zeros or all-ones rather than an error, so a “successful” dump must be validated before it is believed.

Manipulate the configuration word. Attempting to reprogram 2007h to clear the bit initiates the erase sequence, and the program goes with it. This is the trap, not the solution.

Fault injection at the protection check. The code-protect condition is evaluated by on-chip logic when a read is requested. A precisely timed supply or clock disturbance during that evaluation can cause the check to be mis-evaluated for a cycle, allowing a read before protection reasserts. It is non-invasive and preserves the die, but it is timing-critical, and results vary with silicon revision.

Physical read. After decapsulation, EPROM cells can be examined directly: floating-gate cells holding charge are distinguishable from erased ones. On a 512-word array this is unusually tractable, because the array is small enough to image at high magnification in a small number of passes.

Why a part this small still matters

The PIC16C710 appears in enormous volumes of appliance control, thermostats, pressure sensing, and small motor drives designed through the late 1990s and 2000s. Those products are still manufactured and still repaired. The datasheet describes the A/D converter as suited to “low-cost analog interface, e.g. thermostat control, pressure sensing” — and that is exactly where the part ended up.

When such a product’s firmware is lost, the consequences are disproportionate to the chip’s size: a 512-word program is the entire control law of the appliance, and no schematic contains it. Related parts in the same family show identical constraints at slightly larger sizes — PIC16C712 protection and PIC16C715 firmware.

Limits worth stating upfront

  • OTP parts cannot be reused. There is no erase, so any invasive route ends the device.
  • The family header misleads. Reading “2K × 14” as this part’s capacity leads to expecting twice the image that exists.
  • Wraparound hides truncation. A read that stops early can alias and appear complete.
  • 36 bytes of RAM constrains nothing about difficulty. Small firmware is not simple firmware; the control law can still be dense.

FAQ

How much program memory does the PIC16C710 really have? 512 × 14 words, addressed 0000h–01FFh. The 2K × 14 figure in the datasheet features list is the family maximum, belonging to the PIC16C715.

Does in-circuit serial programming bypass code protection? No. ICSP is the interface the protection is enforced on. It allows programming and, with the bit clear, reading; with the bit set it allows neither read-out nor a partial unprotect.

Why does a protected read sometimes look like a valid dump? Because the interface may return zeros or ones rather than reporting a failure. Validation against known vectors — reset behaviour, a handful of A/D conversions — is what separates a real image from a flat one.

Is the 8-bit A/D relevant to recovery? Yes. Reference and scaling constants for the converter are usually embedded in the image, and a recovered program without them can run correctly and still produce wrong measurements.

Conclusion

Attacking a PIC16C710 is a small-array problem with a large structural obstacle: the code-protect bit shares its EPROM array with the code, so clearing it clears the program. What makes this part workable is its scale — 512 words of image, 36 bytes of state, one timer, four A/D channels. There is very little surface for a firmware to hide in, which means a successful read is usually followed by comprehension rather than by months of analysis.

Related reading