Z
zengzwz
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个EXE文件的生成器,
也参考了一些程序,
编译通过后却不能生成EXE文件。
大家帮忙看看是什么问题!
最好能有源码给我看一看
E-MAIL : zengzwz@163.com
下面是我写的源码
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
OFFSET_HOOK = 31412;
OFFSET_HOOK1 = 31496;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Filenupx: string;
implementation
{$R *.dfm}
{$R 'qq.RES'}
procedure TForm1.Button1Click(Sender: TObject);
var
WriteBuff, ResultFilePath, ResourcePointer: PChar;
ResourceLocation: HRSRC;
ResourceSize, BytesWritten: Longword;
ResDataHandle: THandle;
FileHandle: THandle;
sf: TSaveDialog;
LFile: string;
begin
if trim(Edit2.Text) = '' then
begin
MessageBox(0, '请输入名称', '提示信息', mb_iconinformation);
exit;
end;
begin
sf := TSaveDialog.Create(Application);
sf.InitialDir := Application.ExeName;
sf.FileName := 'aill.exe';
sf.DefaultExt := 'exe';
sf.Title := '生成文件';
if not sf.Execute then exit;
LFile := trim(edit2.Text)
//名称
Filenupx := sf.FileName;
ResultFilePath := pchar(sf.FileName);
ResourceLocation := FindResource(HInstance, 'HOKMM', RT_RCDATA);
if ResourceLocation <> 0 then
begin
ResourceSize := SizeofResource(HInstance, ResourceLocation);
if ResourceSize <> 0 then
begin
ResDataHandle := LoadResource(HInstance, ResourceLocation);
if ResDataHandle <> 0 then
begin
ResourcePointer := LockResource(ResDataHandle);
if ResourcePointer <> nil then
begin
FileHandle := CreateFile(ResultFilePath, GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if FileHandle <> INVALID_HANDLE_VALUE then
begin
WriteFile(FileHandle, ResourcePointer^, ResourceSize, BytesWritten, nil);
Sleep(10);
//设置文件指针位置 (PChar 指向一个字符串,用PChar 在很多场合可以当作String用的)
SetFilePointer(FileHandle, OFFSET_HOOK, nil, FILE_BEGIN);
WriteBuff := PChar(LFile + StringOfChar(#0, 64 - Length(LFile)));
//StringOfChar返回指定个数的字符组成的字符串 填充起来
WriteFile(FileHandle, WriteBuff^, 65, BytesWritten, nil)
//将数据写入一个文件
SetFilePointer(FileHandle, OFFSET_HOOK1, nil, FILE_BEGIN);
CloseHandle(FileHandle)
// 失败处理
MessageBox(0, '配置文件成功', '提示', mb_iconinformation);
end;
end;
end;
end;
end;
end;
end;
end.
也参考了一些程序,
编译通过后却不能生成EXE文件。
大家帮忙看看是什么问题!
最好能有源码给我看一看
E-MAIL : zengzwz@163.com
下面是我写的源码
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
OFFSET_HOOK = 31412;
OFFSET_HOOK1 = 31496;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Filenupx: string;
implementation
{$R *.dfm}
{$R 'qq.RES'}
procedure TForm1.Button1Click(Sender: TObject);
var
WriteBuff, ResultFilePath, ResourcePointer: PChar;
ResourceLocation: HRSRC;
ResourceSize, BytesWritten: Longword;
ResDataHandle: THandle;
FileHandle: THandle;
sf: TSaveDialog;
LFile: string;
begin
if trim(Edit2.Text) = '' then
begin
MessageBox(0, '请输入名称', '提示信息', mb_iconinformation);
exit;
end;
begin
sf := TSaveDialog.Create(Application);
sf.InitialDir := Application.ExeName;
sf.FileName := 'aill.exe';
sf.DefaultExt := 'exe';
sf.Title := '生成文件';
if not sf.Execute then exit;
LFile := trim(edit2.Text)
//名称
Filenupx := sf.FileName;
ResultFilePath := pchar(sf.FileName);
ResourceLocation := FindResource(HInstance, 'HOKMM', RT_RCDATA);
if ResourceLocation <> 0 then
begin
ResourceSize := SizeofResource(HInstance, ResourceLocation);
if ResourceSize <> 0 then
begin
ResDataHandle := LoadResource(HInstance, ResourceLocation);
if ResDataHandle <> 0 then
begin
ResourcePointer := LockResource(ResDataHandle);
if ResourcePointer <> nil then
begin
FileHandle := CreateFile(ResultFilePath, GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if FileHandle <> INVALID_HANDLE_VALUE then
begin
WriteFile(FileHandle, ResourcePointer^, ResourceSize, BytesWritten, nil);
Sleep(10);
//设置文件指针位置 (PChar 指向一个字符串,用PChar 在很多场合可以当作String用的)
SetFilePointer(FileHandle, OFFSET_HOOK, nil, FILE_BEGIN);
WriteBuff := PChar(LFile + StringOfChar(#0, 64 - Length(LFile)));
//StringOfChar返回指定个数的字符组成的字符串 填充起来
WriteFile(FileHandle, WriteBuff^, 65, BytesWritten, nil)
//将数据写入一个文件
SetFilePointer(FileHandle, OFFSET_HOOK1, nil, FILE_BEGIN);
CloseHandle(FileHandle)
// 失败处理
MessageBox(0, '配置文件成功', '提示', mb_iconinformation);
end;
end;
end;
end;
end;
end;
end;
end.