Hi everyone
I have a text file which contains a memory dump as shown below
Code:
Memory Address 1FD7C000 49A0 Bytes
1FD7C000: 4D 5A 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *MZ..............*
1FD7C010: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C020: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C030: 00 00 00 00 00 00 00 00-00 00 00 00 B8 00 00 00 *................*
1FD7C040: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C050: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C060: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C070: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C080: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C090: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C0A0: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 *................*
1FD7C0B0: 00 00 00 00 00 00 00 00-50 45 00 00 4C 01 04 00 *........PE..L...*
what i want to do is have my program read the above text file and output it into another processed file which will look like this
Code:
4D 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 B8 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
and so on
A friend at my previous work gave me a hand and we came up with this
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
int main()
{
char instring[200];
int charpos; // position of ":" in the string
FILE *textfile,*outtxtfile ;
charpos=10;
// Process file
textfile=fopen("dump.txt","r");
// open the destination file
outtxtfile=fopen("outtext.txt","w");
// process file
while (!feof(textfile))
{
fgets(instring,200,textfile); /* if ":" found in the string will confirm valid string &
extract it to new file */
if(instring[10]==':')
{
// fwrite(void *buffer, size_t size, size_t num, FILE *fp);
fwrite(instring+charpos+2,1,30,outtxtfile); // first lot of data ie "45 5A 00 00 00 00 00 00"
fwrite(instring+charpos+2+31,1,30,outtxtfile); // second lot of 30 characters from "-" onwards
}
}
fclose(textfile);
fclose(outtxtfile);
return 0;
}
This program doesnt work how i would like it and returns the following
Code:
4D 5A 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *MZ.........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 B8 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........00 00 00 00 00 00 00 00-00 00 0 00 00 00 00 00 *...........
can anyone see where i am going wrong? and maybe come up with a way to fix it? sorry for the long post