Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to modify an already loaded resource?

I'm using the TResourceStream class to read a resource, know I want to modify the resource in memory, but the documentation of the Write method of the above class says:

Applications should not use a TResourceStream to write the resources of the running application. Write overrides the inherited method to raise an EStreamError exception when an application tries to write to the application's resources.

As all other data-writing methods of TResourceStream (WriteBuffer, WriteComponent) call Write to do the actual writing, calling any of the data-writing methods of TResourceStream will raise an exception.

The question is, is there a way to modify a resource in my running application using any WinApi funcion? or are the resources stictly read-only?

like image 829
Salvador Avatar asked Feb 23 '23 02:02

Salvador


1 Answers

Resources are just pointers to some executable part mapped in memory.

So you may be able to change this memory by using VirtualProtectEx, just as you can patch any part of the code.

See Ok to use VirtualProtect to change resource in Delphi? about this technique (here about resourcestring, but the same API can be used over any locked resource).

like image 82
Arnaud Bouchez Avatar answered Feb 24 '23 23:02

Arnaud Bouchez