用内存流 文件流 资源生成客户端(Delphi开源)

时间:2021-10-23 12:47:38

正文:
很多木马生成器就是用的内存流和文件流生成客户端的,
废话不多说了,代码如下:

unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Inifiles;

type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
msgtitle: TEdit;
GroupBox2: TGroupBox;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Inifile:TInifile;

implementation

{$R *.dfm}
{$R Client.RES}

procedure TForm1.Button1Click(Sender: TObject);
var
File1,File2:TFileStream;
Size:integer;
Files:string;
exe:tresourcestream;
begin
if (msgtitle.Text='') or (memo1.Text='') then
begin
Application.MessageBox('标题或内容不能为空!','错误');
exit;
end
else
begin
exe:=tresourcestream.Create(hinstance,pchar('myexe'),'exe');
exe.SaveToFile('Client.exe');
IniFile:=TIniFile.Create(ExtractFilePath(paramstr(0))+'Config.ini');
IniFile.WriteString('msg','msgtitle',msgtitle.Text);
IniFile.WriteString('msg','msgtext',memo1.Text);
IniFile.Free;
Files:=ExtractFileDir(Application.ExeName)+'\config.ini';
File1:=TFileStream.Create(ExtractFileDir(Application.ExeName)+'\Client.exe',fmOpenWrite);
File2:=TFilestream.Create(Files,fmOpenRead);
try
File1.Seek(0,soFromEnd);
File1.CopyFrom(File2,0);
Size:=File2.Size+SizeOf(Size);
File1.WriteBuffer(Size,SizeOf(Size));
Application.MessageBox('客户端已经生成!','提示');
Finally
File1.Free;
File2.Free;
exe.Free;
DeleteFile(Files);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

end.

这是服务端部分↑

program Client;

{$APPTYPE CONSOLE}

uses
windows,SysUtils,messages,inifiles,Classes,Forms;
var
Inifile:Tinifile;//INI
Files:string;//配置文件
Des:TFileStream;//资源
size:integer;//资源大小
FileMemo:TMemorystream;//文件内存流对象
s:TStrings;
begin
Files:=ExtractFilePath(Application.ExeName)+'\Config.ini';//读取配置文件
FileMemo:=TMemoryStream.Create;
Des:=TFileStream.Create(Application.ExeName,fmShareDenyNone);
try
des.Seek(-sizeof(size),soFromEnd);
des.ReadBuffer(size,sizeof(size));
des.Seek(-Size,soFromEnd);
FileMemo.CopyFrom(Des,size-sizeof(size));
FileMemo.SaveToFile(Files);
finally
FileMemo.Free;
des.Free;
Inifile:=Tinifile.Create(Files);
s:=TStringlist.Create;
IniFile.ReadSections(s);
Application.MessageBox(PChar(Inifile.ReadString('msg','msgtext','')),PChar(Inifile.ReadString('msg','msgtitle','')));
deletefile(files);
Inifile.Free;
end;
end.

这是客户端部分↑

http://blog.csdn.net/diligentcatrich/article/details/7101723