Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract the resource file

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. 
like image 311
Kermia Avatar asked Dec 27 '22 20:12

Kermia


1 Answers

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.

like image 197
David Heffernan Avatar answered Jan 19 '23 21:01

David Heffernan