delphi Self-Delete程序  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi Self-Delete程序


 //转贴者:以前看过陆麟先生翻译过一篇这样的文章,是c版本的,我用delphi改写了没成功,今天去清华bbs转悠看见了这篇delphi版本的,特贴出来
发信人: Litoad (Rick), 信区: Delphi
标  题: Self-Delete程序之Delphi版本,终于搞定了。 (转载)
发信站: BBS 水木清华站 (Mon Jun  4 20:51:55 2001)
【 以下文字转载自 Programming 讨论区 】
发信人: Litoad (Rick), 信区: Programming
标  题: Self-Delete程序之Delphi版本,终于搞定了。
发信站: BBS 水木清华站 (Mon Jun  4 20:50:42 2001)

到Borland的论坛去问了问,确实跟laoduan说得一样,要自己GetProcAddress。代码如下:

 program Project1;    
uses   
  windows;    
   
procedure DeleteSelf;    
var   
   module : HMODULE;    
   buf : array [ 0 .. MAX_PATH - 1 ] of char;    
   p : ULONG;    
   hKrnl32 : HMODULE;    
   pExitProcess, pDeleteFile, pFreeLibrary : pointer;    
begin   
  module := GetModuleHandle ( nil );    
  GetModuleFileName ( module, buf, sizeof ( buf ) );    
  CloseHandle ( THandle ( 4 ) );    
   
  p := ULONG ( module ) + 1;    
  //上面这一句什么意思?    
   
  hKrnl32 := GetModuleHandle ( 'kernel32' );    
  pExitProcess := GetProcAddress ( hKrnl32, 'ExitProcess' );    
  pDeleteFile := GetProcAddress  ( hKrnl32, 'DeleteFileA' );    
  pFreeLibrary := GetProcAddress ( hKrnl32, 'FreeLibrary' );    
   
  asm   
    lea eax, buf    
    push 0   
    push 0   
    push eax    
    push pExitProcess    
    push p    
    push pDeleteFile    
    push pFreeLibrary    
    ret    
  end;    
end;   


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.041234016418457 seconds