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.
 
 

27 lines
574 B

  1. .PHONY: default all clean
  2. GLIBCC ?= $(CC)
  3. MUSLCC ?= x86_64-linux-musl-gcc
  4. default: all
  5. manip-exe: manip-exe.c manip-exe.h
  6. $(CC) -o "$@" $< -Og -g
  7. # 'export-dynamic' so that functions defined in the exe actually end up in .dynsym
  8. hello.glibc: hello.c
  9. $(GLIBCC) -o "$@" $< -Wl,--export-dynamic -Og -g
  10. hello.musl: hello.c
  11. $(MUSLCC) -o "$@" $< -Wl,--export-dynamic -Og -g
  12. hello.%.manip: ./manip-exe hello.%
  13. ./$^ "$@" main2
  14. @chmod +x "$@"
  15. all: hello.glibc.manip hello.musl.manip
  16. clean:
  17. @$(RM) -v hello.glibc hello.glibc.manip manip-exe hello.musl hello.musl.manip