ELFTOC(1)

✨ ELFTOC(1) β€” the elf-to-C glow-up ✨

okay bestie, so you found the elftoc page in the General Commands Manual section and you're like "what is this little guy" β€” let me tell you everything πŸ’–


🌸 NAME 🌸

elftoc β€” translate an ELF file into a C struct

like literally it takes your ELF and turns it into C source. iconic behavior honestly.


πŸ¦‹ SYNOPSIS πŸ¦‹

elftoc [OPTIONS] FILE

✨ DESCRIPTION ✨

elftoc takes as input an ELF file, and translates its content into a C source file describing a struct with an initialized value that matches the ELF file's memory image. no cap, it's giving "here's your binary as a vibe, but in C" πŸ’…

Where possible, literal values are replaced with preprocessor symbols and sizeof-based calculations. so it's smart about it, not just dumping raw numbers everywhere 🧚


πŸ‘‘ OPTIONS πŸ‘‘

  • -e, --force-end β€” force inclusion of a final _end field in the C struct. By default, an _end field is only included if the padding causes the struct to be larger than the original ELF file. With this option, a struct with no extra padding will provide an _end field defined as a zero-length array. (yes bestie, zero-length array, we love a technicality 🌈)
  • -E, --exclude-end β€” do NOT include a final _end field, even if padding is present at the end of the C struct. like, no thank you, we're done here πŸ™ˆ
  • -w, --width=N β€” set the maximum line width in the output to N. The default maximum line width is 80.
  • -i, --indent=N β€” set the number of spaces to indent to N. The default indentation amount is 2.
  • -s, --structname=NAME β€” set the name of the C struct in the generated source code to NAME. By default the struct's name is "elf".
  • -v, --varname=NAME β€” set the name of the variable in the generated source code to NAME. By default the variable's name is "foo". (yes, foo. it said what it said πŸŽ€)
  • -m, --allow-misaligned β€” a misaligned section in the ELF file would cause padding bytes to be inserted in the C struct. To avoid this, elftoc represents misaligned sections as uninterpreted byte arrays, regardless of their original type. This option suppresses this behavior, so that misaligned sections retain their actual type, even when this creates an incorrect image in the C struct.
⚠️ okay so heads up: that last one means the C struct image will be incorrect. like, you asked for it, and you got it, but it's wrong on purpose. not me being dramatic, that's just what the page says 😭
  • -q, --quiet β€” suppress warning messages regarding invalid and contradictory values in the ELF file. shhh 🀫
  • -o, --output=FILENAME β€” write the C source code to FILENAME instead of to standard output.
  • --help β€” display help and exit. 🫢
  • --version β€” display version information and exit.

Copyright Β© 1999, 2001, 2011 Brian Raiter <breadbox@muppetlabs.com>.

License GPLv2+: GNU GPL version 2 or later. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


okay that's the whole thing, bestie β€” go forth and struct-ify some ELF files πŸ’–

this page came to you from ELF kickers 3.0, dated May 2011 β€” slay, we stan a maintained classic πŸ‘‘βœ¨

πŸ“¦ where this page comes from