I'm trying to embed an executable binary inside an other one and then write the first binary to a file.
I successfully achieved this with a plain text file but when it comes to writing an executable I cant make it work.
So for example I want to copy /usr/bin/ls
to ls2
, so here what I tried
First:
objcopy --input binary --output elf64-x86-64 --binary-architecture i386 /usr/bin/ls lss.o
the C code:
#include <stdio.h> FILE *f; extern char _binary_lss_start; extern char _binary_lss_end; main() { f = fopen("lss", "w"); fprintf(f, &_binary_lss_start); fclose(f); return 0; }
Compilation:
gcc main.c lss.o
The Code successfully compiled but when i'm trying ./a.out
nothing is written to lss.
(I'm using Arch Linux 4.18.5 and gcc 8.2.0.)
Can I achieve this?