eXec0d3 Posted March 28, 2010 Posted March 28, 2010 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
BoB Posted March 28, 2010 Posted March 28, 2010 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 .. 1
Nacho_dj Posted March 28, 2010 Posted March 28, 2010 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; 1
eXec0d3 Posted March 28, 2010 Author Posted March 28, 2010 thanks it works !! but, PathToMyFile := 'C:\Program Files\MyExe.exe' <-- here must be ";" thisPathToMyFile := 'C:\Program Files\MyExe.exe';
Nacho_dj Posted March 28, 2010 Posted March 28, 2010 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now