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;   

相关阅读 >>

Delphi与正则表达式

Delphi下调用有返回值的存储过程

Delphi tfdquery提交tfdmemtable修改的数据

Delphi 如何快速读写文件中的字符串

Delphi tdictionary保存到文件

Delphi tscreen 类 - 通过 screen 更换光标

Delphi中break,exit,abort跳出循环的比较

Delphi 老外分享的textfile高速遍历大数据文本

Delphi 2010 复制整个文件夹(当然包括嵌套文件夹)

Delphi 替换指定字符串的函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...