开发者

Extract the resource file

开发者 https://www.devze.com 2023-03-07 05:31 出处:网络
I have attached a resource file to an existing exe file using UpdateResource function. How can I extract it?

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 : T开发者_如何转开发Handle;
  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.


there are several tools you can use:

XN Resource Explorer

Resource Hacker

Resource-Grabber

from code by using DelphiDabbler.

or by using TResourceStream class. this question explain you how to use it: How can I extract a resource into a file at runtime?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号