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?
精彩评论