The tests passed. The code was still wrong.
We compiled a CRC-32 routine into a stripped 32-bit Windows binary
(mingw-w64 GCC 16.2, -Os, 60 bytes of code) and decompiled it. Below is
the C recovered for it, and a version an analyst might write while tidying
up. They differ in one word.
/* recovered */
uint32_t crc32_update(uint32_t crc, const uint8_t *buf, size_t len)
/* tidied */
uint32_t crc32_update(uint32_t crc, const char *buf, size_t len)
The bodies are identical:
{
crc = ~crc;
while (len--) {
crc ^= *buf++;
for (int bit = 0; bit < 8; bit++)
crc = (crc >> 1) ^ (0xEDB88320u & -(crc & 1));
}
return ~crc;
}
Test it
The usual move is to run a known input. CRC-32 even has an official check
value: the string 123456789 must give cbf43926.
| Input | uint8_t version | char version | Agree |
|---|---|---|---|
123456789 | cbf43926 | cbf43926 | yes |
relumea | dcb1dc28 | dcb1dc28 | yes |
été (UTF-8) | 44d16cd4 | 9a2b6a25 | no |
Both pass the official check. Only the third row tells them apart, and you would have had to think of it.
char is signed on x86. The first byte of é is 0xc3, and loading it
into a 32-bit register goes one of two ways:
uint8_tcharThose ones go straight into the XOR. Every byte at or above 0x80 does the
same, which covers any non-ASCII text and nearly all binary data: the inputs a
checksum exists for. Plain ASCII never hits it, so the usual test vectors never
do either.
Why that is a problem
A wrong checksum raises no error. It returns eight plausible hex digits every time, and the failure shows up in whatever reads the value.
It is wrong exactly when the input holds a byte at or above 0x80. We ran
both versions over 100,000 random buffers of each size:
| Buffer | char version wrong |
|---|---|
| 1 byte | 50.1% |
| 4 bytes | 93.7% |
| 16 bytes | 99.996% |
| 64 bytes | 100% |
0xEDB88320 is also the polynomial PNG, ZIP and gzip use, so real files hit
the bug as well. This site's apple-touch-icon.png has 10 chunks, each carrying a stored
CRC-32. The recovered version accepts all 10. The tidied one rejects 4,
including the header (IHDR) and the pixel data (IDAT). On the share
image, og.png, it rejects 29 of 30.
A config extractor built on the tidied routine reports every embedded config as corrupt, and the analyst goes looking for an encryption layer that is not there. A C2 emulator frames its packets with bad checksums; if the protocol checks them, the implant drops every packet and the emulation fails with no error to read.
Review rarely catches it. Hand-written tests tend to use ASCII strings and the official check value. Both pass, so the code ships green. Whoever meets it later sees "checksum mismatch" in another component and starts debugging from the wrong end.
Recompile it
Now build the char version with the same compiler and flags and lay its
bytes over the original's.
const char *buf. Offset 0x17: 0f b6 (movzx) became 0f be (movsx).A single byte of the 60 changed, at offset 0x17. The original loads each input
byte with movzx (zero extend); the tidied C compiles to movsx (sign
extend). The comparison needed no test vector and no guess about which input would break it. It also
points at the instruction, which is where you would start looking anyway.
; 0x401016, original: 0f b6 0a
movzx ecx, byte [edx]
; 0x401016, rebuilt from the tidied C: 0f be 0a
movsx ecx, byte [edx]
What relumea does with it
relumea runs this check on every recovered function:
01
Stripped binaryMachine code with no symbols and no source.02
DecompileC, with names and types proposed for review.03
RecompileThe toolchain and flags the binary was built with.04
CompareThe rebuilt function against the original, byte for byte.
Each function ends up with one label:
- EXACT
- The recompiled bytes are identical to the original.
- RELOC
- Identical except for addresses the linker fills in.
- PROVEN
- Separate symbolic evidence, within stated assumptions and a checked scope.
- LIBRARY
- Attributed to a known library, not counted as recovered.
- no match
- The bytes differ. It stays failed until the source changes.
- not attempted
- Nobody has tried yet, and the report says so.
Similarity scores help pick candidates and never stand in for a verdict.
EXACT says the source builds into the code in the binary; it does not say that code is free of bugs. And a rewrite that behaves the same but compiles differently does not get EXACT, so the check errs toward asking a person to look.
Who it is for
If you reverse binaries for a living, the verdict shows which recovered
functions you can build on. A malware analyst
reimplementing a config decoder, or a researcher building a patch on recovered
code, inherits every char-for-uint8_t slip in it. relumea works
alongside IDA Pro, Ghidra and Binary Ninja: names, signatures and types export
to all three.
If you sign off on that work and do not read x86, you should not have to. A count of EXACT, no match and not attempted functions is something you can forward and defend, because each number comes from a byte comparison.
Try it
Sign-up is open at app.relumea.ai. Workspace and API access open after your account is approved.