新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 程序运行之后如何实现把自己删除

程序运行之后如何实现把自己删除

作者:时间:2012-06-26来源:网络收藏

近日看到网友询问的方法,不知大家对木马甚么的兴趣实在太浓,还是想要这样的效果:用户只要一,可执行文件就没有了,可是还是在跑,胆小的只怕要喊鬼呀!,老婆,快出来看上帝甚么的

本文引用地址:http://www.eepw.com.cn/article/148855.htm

  。其实最典型的用法是写反安装程序. 闲来无事,Bear掰到一种还算巧妙的“”的方法。

  大家都知道,一般的程序的时候,可执行文件本身是被操作系统保护的,不能用改写的方式访问,更别提在本身还在运行的时侯了。在Lu0的主页上看到一种UNDOCUMENT的方法,通过改变系统底层的文件访问模式删除自己,那是实在功夫。我看了很是佩服。但是有没有一种用在MSDN上就能查到的函数呢?有!Jeffrey Richter给我们做了一个范例:

  DeleteMe.CPP

  Module name: DeleteMe.cpp

  Written by: Jeffrey Richter

  Description: Allows an EXEcutable file to delete itself

  **************************************************/

  #include

  #include

  #include

  /////////////////////////////////////////////////

  int WINAPI WinMain(HINSTANCE h, HINSTANCE b, LPSTR psz, int n) {

  // Is this the Original EXE or the clone EXE?

  // If the command-line 1 argument, this is the Original EXE

  // If the command-line >1 argument, this is the clone EXE

  if (__argc == 1) {

  // Original EXE: Spawn clone EXE to delete this EXE

  // Copy this EXEcutable image into the user's temp directory

  TCHAR szPathOrig[_MAX_PATH], szPathClone[_MAX_PATH];

  GetModuleFileName(NULL, szPathOrig, _MAX_PATH);

  GetTempPath(_MAX_PATH, szPathClone);

  GetTempFileName(szPathClone, __TEXT(Del), 0, szPathClone);

  CopyFile(szPathOrig, szPathClone, FALSE);

  //***注意了***:

  // Open the clone EXE using FILE_FLAG_DELETE_ON_CLOSE

  HANDLE hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, NULL, OPEN_EXISTI

  NG, FILE_FLAG_DELETE_ON_CLOSE, NULL);

  // Spawn the clone EXE passing it our EXE's process handle

  // and the full path name to the Original EXE file.

  TCHAR szCmdLine[512];

  HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭