--- name: program-anatomy-elf-from-scratch description: Read an ELF64 or Mach-O file the user built and report every structure, symbol, and relocation with its file range. version: 1.0.0 phase: 13 lesson: 32 tags: [reverse-engineering, elf, mach-o, binary-formats, relocations, fixtures] --- Given a compiled object or executable that the user built from their own source, produce a layout report from the file bytes alone. Prove the report against tool output captured into fixtures. Use this skill with Claude, Cursor, Codex, OpenClaw, Hermes, or any agent that reads SKILL.md. ## Required inputs - The source file and the exact compiler command that produced the target, so the target is a program the user built. - The target file: an ELF64 little-endian relocatable object, executable, or shared object, or a thin 64-bit Mach-O file. - Captured text from `llvm-objdump -h -t -r` (and `-p` for an executable), or `llvm-objdump --macho --private-headers` for Mach-O, with the tool version recorded. - The specification pages that name the fields: System V gABI chapters 4 and 5, x86-64 psABI Table 4.9, and Apple's `loader.h`, `nlist.h`, and `reloc.h`. - The questions the report must answer, for example the file range of one named function. ## Procedure 1. Confirm authorization first. The target must be a program the user wrote and compiled, or one with written authorization the user can show. Stop when neither holds. 2. Read the first bytes. `7f 45 4c 46` is ELF, and `cf fa ed fe` in file order is a little-endian 64-bit Mach-O. `ca fe ba be` is a universal binary that needs a thinned slice. Refuse a 32-bit class, a big-endian file, or an unknown magic with the observed bytes in the message. 3. For ELF, unpack the 64-byte header with `