cybersecurity · intermediate · ~15 min · safe pentest lab
Strided binary walk with a bitwise nibble extraction.
Count the global symbols in an ELF .symtab buffer — a one-glance signal of how stripped a binary is, and the first thing a reverse-engineer looks at.
Implement int count_global_symbols(const uint8_t *buf, size_t n) that returns how many symbol-table entries have GLOBAL binding.
buf, n: a fixture byte buffer shaped like a .symtab, and its length, baked into the harness. Each Elf64_Sym entry is 24 bytes; the binding is the top 4 bits of st_info, which sits at offset 4 within each entry. Binding 1 = GLOBAL.Returns int:
(st_info >> 4) == 1 on success;0 if buf == NULL and n == 0 (empty);-1 if buf == NULL and n > 0 (corrupt);-1 if n % 24 != 0 (corrupt).3 entries, two with binding nibble 1 -> 2
NULL, n = 0 -> 0
n = 25 (not a multiple of 24) -> -1
n must be a multiple of 24.buf[i*24 + 4] directly (alignment-safe).The symbol table is the first place a reverse-engineer looks. A counter of global symbols is a one-glance signal of how stripped a binary is.
A const byte buffer + its length in bytes.
Non-negative count, or -1 on corruption / invalid input.
No alignment-unsafe casts. n must be a multiple of 24.
#include <stdint.h>
#include <stddef.h>
int count_global_symbols(const uint8_t *buf, size_t n) {
/* TODO */
(void)buf; (void)n;
return -1;
}
Confusing binding and type. Forgetting the n % 24 check. Casting (Elf64_Sym *)buf and tripping on alignment.
Empty input. Single entry. All entries WEAK.
O(n) per byte; O(n/24) per entry.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.