cybersecurity · intermediate · ~15 min · safe pentest lab

ELF symbol binding

Extract the binding nibble.

Challenge

Extract the binding from an ELF symbol's st_info byte, which packs binding in the high nibble and type in the low nibble.

Task

Implement int symbol_binding(unsigned char info) that returns the high nibble, info >> 4.

Input

  • info: one st_info byte from an ELF symbol-table entry. The grader passes fixed values.

Output

Returns int: the binding, info >> 4 (0=LOCAL, 1=GLOBAL, 2=WEAK).

Example

symbol_binding(0x12)   ->   1   (GLOBAL)
symbol_binding(0x02)   ->   0   (LOCAL)
symbol_binding(0x21)   ->   2   (WEAK)

Edge cases

  • The low nibble (the type) is discarded by the shift.

Input format

An st_info byte info.

Output format

An int: the binding nibble info >> 4.

Constraints

Binding is the high nibble (info >> 4).

Starter code

int symbol_binding(unsigned char info) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.