关于生成EXE文件的问题!(100分)

  • 主题发起人 主题发起人 zengzwz
  • 开始时间 开始时间
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.
 
大家有谁知道的吗?
 
100分没人来拿吗?
 
取出资源流直接保存为EXE文件就可以了。但是资源里必须是EXE的
 
我来了....不过代码太多看不了
 
再顶一下 哪位牛人帮我解决一下问题~!有人知道的吗
 
都等了一天了!
 
EXE存到另外一个程序里,然后用流式转存也行啊。
 
给你看段主要的源码吧,我的生成器里的
procedure TConfigServer.BitBtn3Click(Sender: TObject);

var
WriteBuff, ResultFilePath, ResourcePointer: PChar;
ResourceLocation: HRSRC;
ResourceSize, BytesWritten: Longword;
ResDataHandle: THandle;
FileHandle: THandle;
sf: TSaveDialog;
file4: string;
begin
if trim(Edit1.Text) = '' then
begin
MessageBox(0, '输入后门地址', '提示信息', mb_iconinformation);
exit;
end;

begin

sf := TSaveDialog.Create(Application);
sf.InitialDir := Application.ExeName;
sf.FileName := 'bear.exe';
sf.DefaultExt := 'exe';
sf.Title := '生成';
if not sf.Execute then exit;
file4:=trim(edit1.Text);
Filenupx := sf.FileName;
ResultFilePath := pchar(sf.FileName);
ResourceLocation := FindResource(HInstance, 'HOOKMM', 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);
SetFilePointer(FileHandle, OFFSET_EXE, nil, FILE_BEGIN)
//EXE名称
WriteBuff := PChar(file4 + StringOfChar(#0, 62 - Length(file4)));
WriteFile(FileHandle, WriteBuff^, 63, BytesWritten, nil);
SetFilePointer(FileHandle, OFFSET_EXE1, nil, FILE_BEGIN);







CloseHandle(FileHandle);

MessageBox(0, '配置文件成功', '提示', mb_iconinformation);

if CheckBox1.Checked then
begin
if ExtractRes('RCDUPX', 'UPXKMM', 'UPX.EXE') then
begin
ShellExecute(0, nil, 'upx.exe', PChar('&quot;' + Filenupx + '&quot;'), nil, SW_HIDE);
end;
end
end;
end;
end;
end;
end;
end;
end;

end.
 
问题我已经自己解决了! 谢谢大家
 

Similar threads

S
回复
0
查看
896
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
I
回复
0
查看
528
import
I
后退
顶部