The first portion of any ELF file is the ELF header. This generally provides offsets to other headers (program headers and section headers) within an ELF.
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
> set PATH=C:\MinGW\bin;%PATH% | |
C:\Tools\zlib\zlib-1.2.8> C:\MinGW\bin\mingw32-make.exe -fwin32/Makefile.gcc | |
gcc -O3 -Wall -c -o adler32.o adler32.c | |
gcc -O3 -Wall -c -o compress.o compress.c | |
gcc -O3 -Wall -c -o crc32.o crc32.c | |
gcc -O3 -Wall -c -o deflate.o deflate.c | |
gcc -O3 -Wall -c -o gzclose.o gzclose.c | |
gcc -O3 -Wall -c -o gzlib.o gzlib.c | |
gcc -O3 -Wall -c -o gzread.o gzread.c |
Suppose you need to add a section to an ELF binary to contain information gathered at compile time, but to be used at link time or run time. Here's how to add a section named .okdata
and either populate it with data either after or before emitting the ELF binary.
In this case, you'll add file’s contents to an already existing binary. objcopy
copies and translates object files, such that adding a new section is a matter of writing that new section’s contents into the ELF file.
(Optional) Create a simple program’s object file.
#include <stdio.h> | |
int ft_atoi(char *str) | |
{ | |
long long to_dec = 0; | |
int neg = 1; | |
while (!(*str ^ ' ') || (*str >= '\t' && *str <= '\r')) | |
str = (char *)-~(unsigned long long)str; // Wtff dude | |
while ((!(*str ^ '+') || !(*str ^ '-'))) |