Last active
March 6, 2020 04:47
-
-
Save mlabbe/9a9c9a4515c51291b09ec8e4eda6db6d to your computer and use it in GitHub Desktop.
Redefine a symbol in a compiled elf object file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -x | |
rm -f *.o redefine | |
CC=clang-9 | |
LD=$CC | |
CFLAGS="-fno-inline-functions -O0" | |
$CC -c redefine.c -o redefine.o $CFLAGS | |
$CC -c redefine_b.c -o redefine_b.o $CFLAGS | |
$CC -c redefine_c.c -o redefine_c.o $CFLAGS | |
# rename the moveme function(symbol) to setaside | |
llvm-objcopy-9 --redefine-sym moveme=setaside redefine_c.o redefine_c.o | |
$LD redefine.o redefine_b.o redefine_c.o -o redefine && \ | |
./redefine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./redefine | |
success! | |
this function is called setaside() by the time linking happens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void moveme(void); | |
void setaside(void); | |
int main(void) { | |
moveme(); | |
setaside(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void moveme(void) { | |
puts("success!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void moveme(void) { | |
puts("this function is called setaside() by the time linking happens"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment