How to extend a file resource embedded in a C program

On GCC Linux, is there a way to add a file resource that will be embedded in the static C program, and then how can I extend it to / tmp from main ()?

+4
source share
3 answers

You can use objcopy to embed a resource, and then into regular file operations to create a file in / tmp.

If you compile this program:

#include <stdio.h> extern char _binary_resource_bin_start, _binary_resource_bin_end; int main() { FILE*out = fopen("/tmp/rsrc.bin","wb"); fwrite(&_binary_resource_bin_start, &_binary_resource_bin_end - &_binary_resource_bin_start, 1, out); fclose(out); } 

with this make file:

 program: program.o resource.o $(CC) -o program program.o resource.o resource.o: resource.bin objcopy -I binary -O elf32-i386 -B i386 resource.bin resource.o resource.bin: echo resource-file-contents > resource.bin 

I believe that you will get what you want.

+3
source

Just save it as a string (char *). If it has built-in zeros, or you don’t want to worry about screens for quotes, backslashes, etc., Uuencode-, hex, or base64-encode, and either put the decoding procedure in your C program or call it from the outside . Just use regular file operations to write data to the / tmp file.

+2
source

Perhaps you are trying to hide your PHP code. If so, note that it is trivial to extract the PHP code from the generated executable without even starting it. If the goal is to hide / obfuscate, you might want to use a PHP encoder.

0
source

All Articles