Swap out an ELF executable's main function with another function from its symbol table, without touching its code at all.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
574 B

.PHONY: default all clean
MUSLCC ?= x86_64-linux-musl-gcc
default: all
manip-exe: manip-exe.c manip-exe.h
$(CC) -o "$@" $< -Og -g
# 'export-dynamic' so that functions defined in the exe actually end up in .dynsym
hello.glibc: hello.c
$(GLIBCC) -o "$@" $< -Wl,--export-dynamic -Og -g
hello.musl: hello.c
$(MUSLCC) -o "$@" $< -Wl,--export-dynamic -Og -g
hello.%.manip: ./manip-exe hello.%
./$^ "$@" main2
@chmod +x "$@"
all: hello.glibc.manip hello.musl.manip
@$(RM) -v hello.glibc hello.glibc.manip manip-exe hello.musl hello.musl.manip