本文共 2922 字,大约阅读时间需要 9 分钟。
//1提取出资源
procedure TForm1.Button1Click(Sender: TObject);begin with TResourceStream.Create(HInstance, 'SnapShot_EXE', RT_RCDATA) do begin SavetoFile('SnapShot.exe'); Free; end;end;
TResourceStream = class(TCustomMemoryStream)
procedure Initialize(Instance: THandle; Name, ResType: PChar; FromID: Boolean);
constructor Create(Instance: THandle; const ResName: string; ResType: PChar);
constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar);
destructor Destroy; override;
function Write(const Buffer; Count: Longint): Longint; override;
const { Predefined Resource Types } {$EXTERNALSYM RT_CURSOR} RT_CURSOR = MakeIntResource(1); //光标文件 {$EXTERNALSYM RT_BITMAP} RT_BITMAP = MakeIntResource(2);//位图 {$EXTERNALSYM RT_ICON} RT_ICON = MakeIntResource(3);//图标 {$EXTERNALSYM RT_MENU} RT_MENU = MakeIntResource(4); {$EXTERNALSYM RT_DIALOG} RT_DIALOG = MakeIntResource(5); {$EXTERNALSYM RT_STRING} RT_STRING = MakeIntResource(6); {$EXTERNALSYM RT_FONTDIR} RT_FONTDIR = MakeIntResource(7); {$EXTERNALSYM RT_FONT} RT_FONT = MakeIntResource(8); {$EXTERNALSYM RT_ACCELERATOR} RT_ACCELERATOR = MakeIntResource(9); {$EXTERNALSYM RT_RCDATA} RT_RCDATA = Types.RT_RCDATA; //MakeIntResource(10); {$EXTERNALSYM RT_MESSAGETABLE} RT_MESSAGETABLE = MakeIntResource(11); DIFFERENCE = 11; {$EXTERNALSYM DIFFERENCE} RT_GROUP_CURSOR = MakeIntResource(DWORD(RT_CURSOR) + DIFFERENCE); {$EXTERNALSYM RT_GROUP_CURSOR} RT_GROUP_ICON = MakeIntResource(DWORD(RT_ICON) + DIFFERENCE); {$EXTERNALSYM RT_GROUP_ICON} RT_VERSION = MakeIntResource(16); {$EXTERNALSYM RT_VERSION} RT_DLGINCLUDE = MakeIntResource(17); {$EXTERNALSYM RT_DLGINCLUDE} RT_PLUGPLAY = MakeIntResource(19); {$EXTERNALSYM RT_PLUGPLAY} RT_VXD = MakeIntResource(20); {$EXTERNALSYM RT_VXD} RT_ANICURSOR = MakeIntResource(21); {$EXTERNALSYM RT_ANICURSOR} RT_ANIICON = MakeIntResource(22); {$EXTERNALSYM RT_ANIICON} RT_HTML = MakeIntResource(23); {$EXTERNALSYM RT_HTML} RT_MANIFEST = MakeIntResource(24);
{取出现Wav资源} with TResourceStream.Create(HInstance, 'warning', RT_RCDATA) do begin SaveToFile('warning.wav'); Free; end; //把EXE文件打包到资源文件中一.编写rc脚本文本新建一个记事本,输入 ExeFile1 ExeFile "myExeFile.exe" 保存文件为 ExeRes.rc二.将rc文件编译成res资源文件 在dos中输入brcc32 C:\Users\Administrator\Desktop\ExeRes.rc//brcc32.exe在DelphiX\Bin目录中 将其复制到 C:\Windows目录下面 三.在Delphi单元中加入资源文件新建一个项目,把ExeRes.RES文件复制到 项目目录下,在 implementation 的{$R *.dfm}的下面输入:{$R ExeRes.RES} 四.把资源文件中exe文件提取出来
uses classes;procedure ExtractRes( ResType, ResName, ResNewName : String );var Res : TResourceStream;begin Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType)); Res.SavetoFile(ResNewName); Res.Free;end; //把资源文件中exe文件提取出来procedure TForm1.Button1Click(Sender: TObject);begin ExtractRes('exefile','ExeFile1','C:\Users\Administrator\Desktop\aaa.exe');end;
转载于:https://www.cnblogs.com/xe2011/p/3876377.html