Advertisement
metalx1000

gcc embed text object resource system command by james

Mar 14th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. extern char _binary_data_txt_start;
  6. extern char _binary_data_txt_end;
  7. extern char _binary_data2_txt_start;
  8. extern char _binary_data2_txt_end;
  9.  
  10. #define NUM_OF_BINARY_FILES 2
  11.  
  12. char **populate_binaries()
  13. {
  14.   char** binaries;
  15.   int length;
  16.  
  17.   //Allocate memory for and array of strings
  18.   //Also you can think about this as turning a null pointer into an array
  19.   binaries = (char**)(malloc(sizeof(char*) * NUM_OF_BINARY_FILES));
  20.  
  21.   //find the length of data
  22.   length = &_binary_data_txt_end - &_binary_data_txt_start;
  23.   fprintf(stderr, "Length: %d", length);
  24.   //Allocate memory for a string of length: length+1
  25.   //you need length + 1 because you want an extra charater
  26.   //to store the null charicter
  27.   binaries[0] = (char*)(malloc((length+1) * sizeof(char)));
  28.   //copy the first "length" characters over to the allocated
  29.   //pointer from the pointer that points to the start of data
  30.   strncpy(binaries[0], &_binary_data_txt_start, length);
  31.  
  32.  
  33.   //Again with data2
  34.   length = &_binary_data2_txt_end - &_binary_data2_txt_start;
  35.   binaries[1] = (char*)(malloc((length+1) * sizeof(char)));
  36.   strncpy(binaries[1], &_binary_data2_txt_start, length);
  37.  
  38.   return binaries;
  39.  
  40. }
  41.  
  42. main()
  43. {
  44.  
  45.     char **binaries;
  46.  
  47.     binaries = populate_binaries();
  48.  
  49.  
  50.     fprintf(stderr, "\nFirst String: %s\n", binaries[0]);
  51.  
  52.   //  fprintf(stderr, "\nFirst String: %s\n", binaries[1]);
  53.  
  54.     system(binaries[1]);
  55.     //char*  p = &_binary_data_txt_start;
  56.  
  57.     //while ( p != &_binary_data_txt_end ){
  58.     //    printf(p);
  59.     //}
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement