Advertisement
metalx1000

GCC C code to embed text files in a program

Oct 26th, 2017
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. //More examples - https://github.com/metalx1000/C-Code-with-embedded-files
  2. /*
  3.  * Copyright (c) 2017 Kris Occhipint.
  4.  * http://filmsbykris.com
  5.  *
  6.  * Embed text files in a C program
  7.  *
  8.  * This program is free software: you can redistribute it and/or modify  
  9.  * it under the terms of the GNU General Public License as published by  
  10.  * the Free Software Foundation, version 3.
  11.  *
  12.  * This program is distributed in the hope that it will be useful, but
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15.  * General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20. #include <stdio.h>
  21. //create object file -- architecture may very
  22. //objcopy --input binary --output elf64-x86-64 --binary-architecture i386 file.txt file.o
  23. //compile: gcc textfile_3_obj.c file.o -o textfile_3_obj
  24. //for windows/mingw remove underscores
  25.  
  26. extern char _binary_file_txt_start;
  27. extern char _binary_file_txt_end;
  28.  
  29. int main(){
  30.     char*  p = &_binary_file_txt_start;
  31.  
  32.     while ( p != &_binary_file_txt_end ) putchar(*p++);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement