Posts Tagged ‘copy chip source archive’

PostHeaderIcon Break Encrypted GD32F330K6U6 Source Code: QFN32 32 KB Recovery

The GD32F330K6U6 puts a Cortex-M4 core at 84 MHz, 32 KB of flash and 4 KB of SRAM into a QFN32 package with 27 GPIO — a part that ends up in products whose firmware was written years ago by a team that has since moved on. What owners usually ask for is not just the binary. They want the source code behind it, and the compiler is the only one who ever had it. To break encrypted GD32F330K6U6 source code out of a locked part is a two-stage job: first the image leaves the chip, then the image is turned back into something an engineer can edit.

Decapsulated microcontroller die under recovery

Why the source is gone

Source code is rarely lost in a dramatic way. A contractor delivered binaries only, a laptop was retired, a repository outlived its licence server. The chip keeps running either way, which hides the problem until a change is needed — a new sensor, a revised regulator setting, a production fix. At that point the locked QFN32 on the board is the sole, encrypted container of the only copy, and read protection stands between you and it.

Getting the binary out

The first stage is a read, and the read is guarded by the security-protection level in the option bytes. The debug port and the USART bootloader both refuse the main array at level 1, so the extraction runs a timed fault against the boot-time check and streams the 32 KB out with the flash untouched. We capture twice and checksum before trusting the image, because a silent half-read would poison everything downstream. The read method is the same one we document for protected flash recovery.

From disassembly toward C source

The binary that comes out is machine code: complete, but written for the core, not for a person. Recovery to source means running a disassembly against the Cortex-M4 instruction set and rebuilding structure on top of it — where functions start and end, which blocks are loops and which are switch tables, and above all the peripheral set-up, because initialising the timers, ADC and serial ports of the F330 correctly is what makes the reconstructed code behave like the original. Our dual probe and flying probe bench is where ambiguous pins and signals get confirmed against the running hardware.

What survives and what cannot

Recovered Not recoverable
Program flow and all logic Original variable names
Peripheral initialisation Comments the author wrote
Constants, strings, tables Build scripts and headers
Data pages stored in flash Version-control history

That split matters for expectations. The rebuilt source behaves like the original and can be edited, recompiled and maintained — but it reads like a reverse-engineered file, not like the code the original author typed. Where a customer only needs one value changed, editing the binary directly is often faster than a full rebuild.

Handover formats

A typical job returns three things: the verified binary, a documented disassembly, and where a rebuild was in scope, C source files that compile to an equivalent image. The same image also feeds a clone of the part if replacement hardware is the goal.

When a rebuild is overkill

Not every locked K6U6 needs a full source-code rebuild. Where the change is a single value — a baud rate, a threshold, a serial-number range — editing the verified binary directly is faster, cheaper and safer, because recompiled code can drift from the silicon it runs on if the toolchain differs from the original. A rebuild earns its cost when the firmware will be maintained for years, when several variants must be derived from one base, or when the author’s logic has to be audited. We scope that trade with you before opening the part, so the job matches the problem. The same image that feeds a rebuild also seeds a clone if replacement hardware is ever the goal, so nothing is wasted either way.

How the K6U6 relates to its neighbours

The 32 KB array makes this the mid-size member of the leadless F330 group, and the flow is shared with the QFN28 GD32F330G8U6TR flash reads, the GD32F330C6T6 memory decodes and the GD32F330R8T6 code recoveries on LQFP64. Send the chip, the board, or just the part number and we will scope what the 32 KB can give back.