cybersecurity · intermediate · ~15 min · safe pentest lab
Read the ELF class field.
Read the ELF class field to learn the word size before parsing the rest of the header.
Implement int elf_is_64bit(const unsigned char *b) that returns 1 if the ELF is 64-bit, else 0.
b: an ELF header buffer the grader passes; the EI_CLASS byte at offset 4 is 1 for 32-bit, 2 for 64-bit.Returns int: 1 if b[4] == 2, else 0.
{0x7f,'E','L','F',2} -> 1 (64-bit)
{0x7f,'E','L','F',1} -> 0 (32-bit)
An ELF header buffer b with at least 5 readable bytes.
An int: 1 if the EI_CLASS byte b[4] is 2 (64-bit), else 0.
EI_CLASS is at offset 4; 2 means 64-bit.
int elf_is_64bit(const unsigned char *b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.