Posted March 28, 201015 yr I need to Read data from .exe file for example this is OEP (virtual address) 00000023 I've converted it to physical and now I need to check if data on this address = $55 then WriteFile(H, buf, SizeOf(buf), written, nil); How to do that? Sorry for my bad English language
March 28, 201015 yr I need to Read data from .exe file for example this is OEP (virtual address) 00000023 I've converted it to physical and now I need to check if data on this address = $55 then WriteFile(H, buf, SizeOf(buf), written, nil); How to do that? Sorry for my bad English language Use ReadFile Api, has the same params as WriteFile. You can read file into memory all at once, or use SetFilePointer api to choose where to read from .. Also you can use FileStream / MemoryStream Delphi classes, but they are lame and you get much smaller code using apis ..
March 28, 201015 yr Check if this works for you. Of course, you can modify it to add checks and everything you need...type BufferByte = array of Byte;procedure ReadBufferFromFile(PathToMyFile : AnsiString; Offset : Integer; var buf : BufferByte);var MyFile : TFileStream; begin try MyFile := TFileStream.Create(PathToMyFile,fmOpenRead); MyFile.Seek(Offset,SoFromBeginning); MyFile.Read(buf[0],Length(buf)); finally MyFile.Free; end;end;procedure WriteBufferToFile(PathToMyFile : AnsiString; Offset : Integer; var buf : BufferByte);var MyFile : TFileStream; begin try MyFile := TFileStream.Create(PathToMyFile,fmOpenWrite); MyFile.Seek(Offset,SoFromBeginning); MyFile.Write(buf[0],Length(buf)); finally MyFile.Free; end;end;procedure CheckOEPAndFix;var Offset : Integer; PathToMyFile : AnsiString; bufRead, bufWrite : BufferByte;begin Offset := $1523; // Example of address of your OEP, it must be offset of a file, not Virtual Address PathToMyFile := 'C:\Program Files\MyExe.exe' SetLength(bufRead,1); ReadBufferFromFile(PathToMyFile,Offset,bufRead); if bufRead[0] = $55 then begin ........ // Treatment of your buffer to be written ........ WriteBufferToFile(PathToMyFile,Offset,bufWrite); end;end;
March 28, 201015 yr Author thanks it works !! but, PathToMyFile := 'C:\Program Files\MyExe.exe' <-- here must be ";" thisPathToMyFile := 'C:\Program Files\MyExe.exe';
March 28, 201015 yr Nice! Now you can try to find how to improve your techniques, by modifying that code for your needings. About the missing ';', hehe, when you code this happens for sure! Luckily there are good coompilers warning you about things like that... Best regards Nacho_dj
Create an account or sign in to comment