If your question is, if you can add a resource to a existing exe file, yes it is possible. To do this you must use the UpdateResource
function which can add, delete, or replace a resource in a portable executable (PE) file
.
update
Here you have a sample code
{$APPTYPE CONSOLE}
uses
Classes,
Windows,
SysUtils;
procedure UpdateExeResource(Const Source,Dest:string);
var
Stream : TFileStream;
hDestRes : THANDLE;
lpData : Pointer;
cbData : DWORD;
begin
Stream := TFileStream.Create(Source,fmOpenRead or fmShareDenyNone);
try
Stream.Seek(0, soFromBeginning);
cbData:=Stream.Size;
if cbData>0 then
begin
GetMem(lpData,cbData);
try
Stream.Read(lpData^, cbData);
hDestRes:= BeginUpdateResource(PChar(Dest), False);
if hDestRes <> 0 then
if UpdateResource(hDestRes, RT_RCDATA,'DATA',0,lpData,cbData) then
begin
if not EndUpdateResource(hDestRes,FALSE) then RaiseLastOSError
end
else
RaiseLastOSError
else
RaiseLastOSError;
finally
FreeMem(lpData);
end;
end;
finally
Stream.Free;
end;
end;
begin
try
UpdateExeResource('C:UsersDexterDocumentsRAD StudioProjectsDebugWin32Data.txt','C:UsersDexterDocumentsRAD StudioProjectsDebugWin32project86.exe');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…