cybersecurity · intermediate · ~15 min · safe pentest lab
Strided binary walk with a bitwise nibble extraction.
Implement:
#include <stdint.h>
#include <stddef.h>
int count_global_symbols(const uint8_t *buf, size_t n);
Each Elf64_Sym is 24 bytes. The binding lives in the top 4 bits of
st_info, which is at offset 4 inside each entry. Binding 1 = GLOBAL.
Return:
(st_info >> 4) == 1 on success0 if buf == NULL && n == 0 (empty)-1 if buf == NULL && n > 0 (corrupt)-1 if n % 24 != 0 (corrupt)buf[i*24 + 4] directly.for (i = 0; i < n / 24; ++i).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.