I have attached a resource file to an existing exe file using UpdateResource function.
How can I extract it?
Edit
This is my code to attach a resource file to an existing exe file :
Uses Classes, Windows, SysUtils, Dialogs;
Type
TBuffer = Array[0..0] of Byte;
PBuffer = ^TBuffer;
Var
FS : TFileStream;
ResourceHandle : THandle;
DataLength : DWord;
Data : PBuffer;
Ok : Boolean;
Begin
ResourceHandle := BeginUpdateResource(pChar('d:\someexefile.exe'), False);
IF (ResourceHandle <> 0) Then
Begin
FS := TFileStream.Create('d:\somebitmap.bmp', fmOpenRead);
FS.Seek(0, soFromBeginning);
DataLength := FS.Size;
GetMem(Data, DataLength);
FS.Read(Data^, DataLength);
FS.Free;
Ok := True;
IF (not UpdateResource(ResourceHandle, RT_RCDATA, pChar('MyNewResource'), LANG_SYSTEM_DEFAULT{MakeLangID(LANG_NEUTRAL, SUBLANG_NEUTRAL)}, Data, DataLength)) Then Ok := False;
IF (not EndUpdateResource(ResourceHandle, False)) Then Ok := False;
IF (Ok) Then ShowMessage('Update of resources successful!')
Else ShowMessage('Update of resources failed!');
FreeMem(Data);
End;
End.
Use LoadLibraryEx passing LOAD_LIBRARY_AS_IMAGE_
RESOURCE to load the module and then TResourceStream.SaveToFile to save the resource.
I am of course assuming that you don't want to extract the resource from the running executable. If that were the case you could go straight to TResourceStream.SaveToFile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With