Last active
June 9, 2017 05:43
-
-
Save alexeiz/bf48692a34fc8964715ffb664128c7fa to your computer and use it in GitHub Desktop.
Add a file content to a compiled binary to read at runtime.
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
$ cat myasmfile.S | |
.global MyAwesomeBinary, MyAwesomeBinaryEnd | |
.data | |
.align 8 | |
MyAwesomeBinary: | |
.incbin "file.txt" | |
MyAwesomeBinaryEnd: | |
.zero 1 | |
$ cat file.txt | |
Hello, world! | |
// myprogram.c | |
#include <stdio.h> | |
extern char MyAwesomeBinary, MyAwesomeBinaryEnd; | |
int main() { | |
puts(&MyAwesomeBinary); | |
printf("Binary length: %i\n", &MyAwesomeBinaryEnd - &MyAwesomeBinary); | |
} | |
$ gcc myprogram.c myasmfile.S -o myprogram | |
$ ./myprogram | |
Hello, world! | |
Binary length: 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment