How telepath9000/elf-packer works
Project type and purpose
• This is a native CLI tool (elf-packer) written in C and x86_64 assembly.
• Its purpose is to read an existing ELF64 binary, encrypt the .text section, inject a self-decrypting stub, and produce a packed ELF64 executable.
File structure
• Top level:
• Makefile: build and test targets
• README.md, LICENSE, .gitignore
• /packer.h: public header defining interfaces
• src/: implementation modules
• encrypt.c – routines to encrypt/decrypt data
• inject.asm – assembly stub that will be prepended for runtime decryption
• packer.c – orchestrates the packing workflow, CLI entry point
• prepare_elf.c – reads/parses the input ELF64, sets up new segments/sections
• util.c – helper functions (file I/O, error handling, ELF metadata)
README for additional insights
• Workflow: packer [elf64_filepath]
• Read and parse ELF64 file
• Encrypt .text section
• Inject the decryptor stub (inject.asm)
• Write out a new ELF64 binary
• It warns it only works on older kernels (implying no dynamic loader compatibility logic in source).
a. Main components:
1. CLI Interface (packer.c – main)
2. ELF Parser & Modifier (prepare_elf.c + packer.h)
3. Encryptor Module (encrypt.c)
4. Stub Injector (inject.asm + inject routines in util.c)
5. Utilities (util.c: file operations, logging, error management)
6. Build System (Makefile)
b. Relationships & data flow:
– User invokes CLI → packer.c
– packer.c calls ELF Parser to load input binary
– Parser returns in-memory structures → passed to Encryptor
– Encryptor encrypts .text, updates in-memory image
– Injector attaches the decrypt stub at ELF entry point
– Final image passed to Utilities for writing to disk
c. Architectural patterns / principles:
– Modular separation of concerns: parsing, encryption, injection, utilities
– Linear data pipeline: file input → transformation → file output
– Single-pass packing workflow
d. Key technologies / libraries:
– C language, x86_64 assembly
– ELF64 file format (manual parsing, no external ELF lib)
– Makefile-driven build & test targets