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_endfield in the C struct. By default, an_endfield 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_endfield defined as a zero-length array. (yes bestie, zero-length array, we love a technicality π)-E,--exclude-endβ do NOT include a final_endfield, 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 is80.-i,--indent=Nβ set the number of spaces to indent to N. The default indentation amount is2.-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,elftocrepresents 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 π
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
- arch rolling: elfkickers 3.2-6 Β· GPL-2.0-or-later
- debian trixie: elfkickers 0+git20240221+ds-5
- nixos 26.05: elfkickers 3.2
- nixpkgs unstable: elfkickers 3.2
- ubuntu resolute: elfkickers 3.2+ds-1
- ubuntu stonking: elfkickers 3.2+ds-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms