cybersecurity · intermediate · ~15 min · safe pentest lab
Recognise the ELF magic number.
Recognise an ELF binary from its four magic bytes — step one of any Linux binary forensics.
Implement int is_elf(const unsigned char *b) that returns 1 if the buffer begins with the ELF magic, else 0.
b: a byte buffer (the start of a file) the grader passes; at least 4 bytes are readable.Returns int: 1 if b[0..3] are 0x7F, 'E', 'L', 'F'; else 0.
{0x7f,'E','L','F',2} -> 1
{'M','Z',0,0} -> 0 (PE, not ELF)
A byte buffer b with at least 4 readable bytes.
An int: 1 if b[0..3] is the ELF magic 0x7F 'E' 'L' 'F', else 0.
Check only the first four bytes.
int is_elf(const unsigned char *b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.