cybersecurity · beginner · ~15 min · safe pentest lab

Recover the first character

Restore the overwritten first byte.

Challenge

Restore the filename byte that FAT overwrites on deletion, substituting a guessed character only when the entry is actually deleted.

Task

Implement unsigned char recover_first(unsigned char first, unsigned char hint) that returns hint when the entry is deleted (first == 0xE5), and otherwise returns first unchanged.

Input

  • first: the entry's current first byte.
  • hint: the character to substitute when the entry is deleted.

Output

Returns the recovered first byte: hint if first == 0xE5, else first.

Example

recover_first(0xE5, 'R')   ->   'R'   (deleted: use the hint)
recover_first('A', 'R')    ->   'A'   (live: keep it)

Edge cases

  • Substitution happens only for first == 0xE5; any other value is returned as-is.

Input format

The entry's first byte first and a replacement character hint.

Output format

hint if first == 0xE5; otherwise first unchanged.

Constraints

Substitute only when first == 0xE5.

Starter code

unsigned char recover_first(unsigned char first, unsigned char hint) {
    /* TODO */
    return first;
}

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