anyone know of any interesting ELF binary patching tricks? like LD_PRELOAD but u got root access and wanna make things permanent
@SuricrasiaOnline wow twitter absolutely blew this one off the site, i had to switch over to here to see it
@SuricrasiaOnline i've never dug into these kinds of stuff, but isn't there stuff for doing it? my system has patchelf and elfedit, and i thought there was some other binary patching stuff in some less standard package i can't otherwise recall?
@SuricrasiaOnline Nix uses patchelf extensively, mostly for setting the RPATH and interpreter of elf files to custom things. It also uses a patched version of ld iirc.
@SuricrasiaOnline tl;dr, append your new code and change an unneeded program header to PT_LOAD to load the new code
@SuricrasiaOnline FreeBSD has elfctl(1) in base. it's for twiddling bits in a notes header that tell the kernel something about your binary.
a writup of what the bits do: https://github.com/golang/go/issues/48164
how it's twiddled: https://github.com/freebsd/freebsd-src/blob/main/usr.bin/elfctl/elfctl.c
@SuricrasiaOnline Not super interesting, but still useful: You can set a library lookup path within the ELFdynamic section in the "RUNPATH" string via -Wl,-rpath . It should also be possible to patch this in the header with medium effort.