andersch.dev

<2022-05-08 Sun>
[ os ]

The Executable & Linkable Format (ELF)

The Executable & Linkable Format (ELF) is a file format for executable images. Files of this format are called ELF executables, and can include executables, object code and shared libraries. It is the standard binary file format for Unix and Unix-like systems on x86 processors.

How to manually edit executables

  1. Get a plaintext hexdump of the executable, i.e. the hex values that make up the executable represented in ascii: xxd -plain /path/to/elf_file > elf_file.dump
  2. Edit hex values in a normal text editor vim elf_file.dump
  3. Write changes back to an executable file, i.e. revert an ascii hexdump into binary data xxd -plain -revert elf_file.dump > /path/to/elf_file

Script to turn hexdump-files (.dump) that contain comments (lines starting with '#') into executable files:

#!/bin/bash
for f in *.dump
do
    a=`basename $f .dump`
    cut -d'#' -f1 <$f | xxd -plain -revert > $a
    chmod +x $a
done

Resources