1 #include <libelfu/libelfu.h>
4 static void* subFindByAddr(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
6 GElf_Addr a = *(GElf_Addr*)aux1;
8 if (OVERLAPPING(ms->shdr.sh_addr, ms->shdr.sh_size, a, 1)) {
17 void elfu_mDetour(ElfuElf *me, GElf_Addr from, GElf_Addr to)
21 unsigned char detourcode[] = {0xe9, 0xfc, 0xff, 0xff, 0xff};
23 ms = elfu_mScnForall(me, subFindByAddr, &from, NULL);
26 ELFU_WARN("mDetour: Cannot find address %x in any section.\n",
31 if (ms->shdr.sh_type != SHT_PROGBITS) {
32 ELFU_WARN("mDetour: Cannot detour in non-PROGBITS section %s.\n",
33 elfu_mScnName(me, ms));
37 scnoffset = from - ms->shdr.sh_addr;
39 if (ms->shdr.sh_size - scnoffset < 5) {
40 ELFU_WARN("mDetour: Not enough space to insert a detour.\n");
44 ELFU_DEBUG("mDetour: Detouring at address %x in section %s to %x.\n",
46 elfu_mScnName(me, ms),
49 *(Elf32_Word*)(detourcode + 1) = to - from - 5;
50 memcpy((char*)ms->data.d_buf + scnoffset, detourcode, 5);