cybersecurity · intermediate · ~15 min · safe pentest lab
Branch on multiple magic numbers.
Identify a firmware container by branching on its magic bytes — the first step of any firmware-unpacking pipeline.
Implement const char *firmware_kind(const unsigned char *b) that returns a string naming the container type.
b: a byte buffer of at least 4 bytes. The grader passes a fixed buffer.Returns const char *:
"gzip" if the first two bytes are 0x1F 0x8B;"uimage" if the first four bytes are the U-Boot magic 0x27 0x05 0x19 0x56 (big-endian);"unknown" otherwise.b = 0x27 0x05 0x19 0x56 -> "uimage"
b = 0x1F 0x8B 0x00 0x00 -> "gzip"
b = 0x00 0x01 0x02 0x03 -> "unknown"
"unknown".A byte buffer b of at least 4 bytes.
A const char*: "gzip", "uimage", or "unknown".
gzip = 1F 8B; uimage = 27 05 19 56 (big-endian); else unknown.
const char *firmware_kind(const unsigned char *b) {
/* TODO */
return "unknown";
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.