Skip to content

Instantly share code, notes, and snippets.

@alexeiz
Last active June 9, 2017 05:43
Show Gist options
  • Save alexeiz/bf48692a34fc8964715ffb664128c7fa to your computer and use it in GitHub Desktop.
Save alexeiz/bf48692a34fc8964715ffb664128c7fa to your computer and use it in GitHub Desktop.
Add a file content to a compiled binary to read at runtime.
$ 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