Hi,
Basically what im trying to do is to split up a special 'test.exe' that contains secret messages added on to the end of the file, and extract the secret messages from the file. The 'secret messages' are strings added on to the binary data after compilation by another program.
Ex:
Binary View of file:
Delimiter '--CB--' is used in this example
Code:
aksjpgewoagjreaperiasdgaerwgerjapojaweybeyneeyna
ayueune5nueuaaketperovuerpvieruphvriuphvuraipheriv
asgwaeggggggggggggggggggggggggggggggggggggggg
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahaer
ahuvpehroihaeruhpevampeaherpa--CB--SECRET MSG 1--CB--
SECRETMSG 2--CB--SECRET MSG 3--CB--SECRET MSG 4
The only way I can think of achieving something like this in C is by reading each character one by one through the binary file and using IF statements to determine when it reaches a delimmiter. Unfrotunately, as you can see below this gets kind of messy and ugly and preferably not the way I want to go.
Code:
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[]) {
const char * delimit = "--CB--";
FILE * testFile;
testFile = fopen ("text.exe", "rb");
if (testFile==NULL) perror ("Error opening file");
else {
char c;
do {
/*If Maddness... Would it be possible for me to use a switch for these?*/
c = fgetc (testFile);
if (c == '-') {
c = fgetc (testFile);
if (c == '-') {
c = fgetc (testFile);
if (c == 'C') {
c = fgetc (testFile);
if (c == 'B') {
c = fgetc (testFile);
if (c == '-') {
c = fgetc (testFile);
if (c == '-') {
do
/*How would I create a string array here?*/
while (c != EOF && c != '-')
}
}
}
}
}
}
} while (c != EOF);
fclose (pFile);
}
return 0;
}
Is there any other way of acheving what im trying to do without reading the file one character at a time?
thanks, Zeph.