file
-
-
hi i want to open an exe as a file in my application. in my dialog box app there is a button when i click on that it will open a exe as a file and search for suppose "t". how can i open an exe as a file and how to replace a char or string in it. swarup
I think you use the
GetOpenFileName()
to open the exe file the you need an handle in order to open file usingCreateFileA
HANDLE hFile=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
at this point you should have an handle to your exe file, now we read it into memory using ReadFileADWORD BR=0; //numbers of bytes read by readfile char *tempbuff=(char*)calloc(dFileSize,sizeof(char)); ReadFile(hFile, tempbuff, dFileSize, &BR, NULL); if( BR < dFileSize){ //Process the error, since not all file could have been read }
now we search the string you're looking forchar *p=NULL; p=strstr(tempbuff,"TEXT_TO_BE_SEARCHED"); if( p==NULL) // no TEXT_TO_BE_SEARCHED found in tempbuff else you've the first occurrence
for writing you do the same using WriteFile, bye Paolo -
I think you use the
GetOpenFileName()
to open the exe file the you need an handle in order to open file usingCreateFileA
HANDLE hFile=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
at this point you should have an handle to your exe file, now we read it into memory using ReadFileADWORD BR=0; //numbers of bytes read by readfile char *tempbuff=(char*)calloc(dFileSize,sizeof(char)); ReadFile(hFile, tempbuff, dFileSize, &BR, NULL); if( BR < dFileSize){ //Process the error, since not all file could have been read }
now we search the string you're looking forchar *p=NULL; p=strstr(tempbuff,"TEXT_TO_BE_SEARCHED"); if( p==NULL) // no TEXT_TO_BE_SEARCHED found in tempbuff else you've the first occurrence
for writing you do the same using WriteFile, bye Paolo