cybersecurity · intermediate · ~15 min · safe pentest lab

ELF symbol type

Extract the type nibble.

Challenge

Extract the type from an ELF symbol's st_info byte — the low nibble that says whether a symbol names a function, an object, etc.

Task

Implement int symbol_type(unsigned char info) that returns the low nibble, info & 0xF.

Input

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

Output

Returns int: the type, info & 0xF (0=NOTYPE, 1=OBJECT, 2=FUNC).

Example

symbol_type(0x12)   ->   2   (FUNC)
symbol_type(0x11)   ->   1   (OBJECT)

Edge cases

  • The high nibble (the binding) is masked out.

Input format

An st_info byte info.

Output format

An int: the type nibble info & 0xF.

Constraints

Type is the low nibble (info & 0xF).

Starter code

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

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