cybersecurity · intermediate · ~15 min · safe pentest lab
Fixed-layout filename reconstruction with a sentinel-byte rule.
Implement:
#include <stdint.h>
int recover_8_3(const uint8_t *entry, char *out);
entry points to a 32-byte FAT directory entry. Bytes 0..10 are the
8.3 short name (8 base + 3 extension, space-padded ASCII).
Rules:
entry[0] == 0xE5, replace the first byte of the rendered name
with '_' (deleted-entry convention)...entry or out is NULL.HELLO.TXT → 9README → 6_ELLO.TXT → 9strncpy and trying to trim later. It's
simpler to walk byte-by-byte.The 0xE5 deletion convention is what every FAT recovery tool uses to list deleted files. Reproducing it in C makes the rule concrete.
A pointer to a 32-byte buffer and a >=13-byte output buffer.
Number of bytes written (excluding NUL), or -1 on NULL inputs.
Output up to 13 bytes (8 + 1 + 3 + 1). Uppercase ASCII. No reads past byte 11.
#include <stdint.h>
int recover_8_3(const uint8_t *entry, char *out) {
/* TODO */
(void)entry; (void)out;
return -1;
}
Forgetting trailing spaces. Including the dot when extension is empty. Mishandling the 0xE5 rule (it applies only to position 0).
No extension. Maximum-length 8 + 3 name. Deleted entry that's also lowercase before deletion.
O(1) — at most 12 bytes processed.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.