Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- extern char _binary_data_txt_start;
- extern char _binary_data_txt_end;
- extern char _binary_data2_txt_start;
- extern char _binary_data2_txt_end;
- #define NUM_OF_BINARY_FILES 2
- char **populate_binaries()
- {
- char** binaries;
- int length;
- //Allocate memory for and array of strings
- //Also you can think about this as turning a null pointer into an array
- binaries = (char**)(malloc(sizeof(char*) * NUM_OF_BINARY_FILES));
- //find the length of data
- length = &_binary_data_txt_end - &_binary_data_txt_start;
- fprintf(stderr, "Length: %d", length);
- //Allocate memory for a string of length: length+1
- //you need length + 1 because you want an extra charater
- //to store the null charicter
- binaries[0] = (char*)(malloc((length+1) * sizeof(char)));
- //copy the first "length" characters over to the allocated
- //pointer from the pointer that points to the start of data
- strncpy(binaries[0], &_binary_data_txt_start, length);
- //Again with data2
- length = &_binary_data2_txt_end - &_binary_data2_txt_start;
- binaries[1] = (char*)(malloc((length+1) * sizeof(char)));
- strncpy(binaries[1], &_binary_data2_txt_start, length);
- return binaries;
- }
- main()
- {
- char **binaries;
- binaries = populate_binaries();
- fprintf(stderr, "\nFirst String: %s\n", binaries[0]);
- // fprintf(stderr, "\nFirst String: %s\n", binaries[1]);
- system(binaries[1]);
- //char* p = &_binary_data_txt_start;
- //while ( p != &_binary_data_txt_end ){
- // printf(p);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement