Last active
October 14, 2016 13:40
-
-
Save Leandros/3a7fa4a415fd3e630ff407d4ba02a88e to your computer and use it in GitHub Desktop.
Define function by objectcode
This file contains hidden or 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
/* | |
* !!! Linux Version !!! | |
* | |
* Compile with: gcc -o foo foo_linux.c | |
* | |
* $ ./foo | |
* foo(5) = 10 | |
*/ | |
#include <stdio.h> | |
unsigned char __foo[] __attribute__((section(".text"))) = { | |
0x8d, 0x04, 0x3f, 0xc3 | |
}; | |
int (*foo)(int) = (int (*)(int))__foo; | |
int main(void) | |
{ | |
printf("foo(5) = %d\n", foo(5)); | |
return 0; | |
} |
This file contains hidden or 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
/* | |
* !!! macOS Version !!! | |
* | |
* Compile with: gcc -o foo foo_mac.c | |
* | |
* $ ./foo | |
* foo(5) = 10 | |
*/ | |
#include <stdio.h> | |
unsigned char __foo[] __attribute__((section("__TEXT,__text"))) = { | |
0x55, 0x48, 0x89, 0xe5, 0x8d, 0x04, 0x3f, 0x5d, 0xc3 | |
}; | |
int (*foo)(int) = (int (*)(int))__foo; | |
int main(void) | |
{ | |
printf("foo(5) = %d\n", foo(5)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment