Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 팁&트릭
Delphi Programming Tip&Tricks
[271] 자기 자신을 삭제하기
civilian [civilian] 6206 읽음    2010-01-26 13:05
program selfdelete;
uses
  windows,
  sysutils;
procedure DeleteExeAndDir;
var hModule:THandle;
   szModuleName,szDirName:array[0..MAX_PATH] of char;
   hKrnl32 : THandle;
   pExitProcess, pDeleteFile, pUnmapViewOfFile,pRemoveDir : pointer;
   ExitCode:UINT;
   var r:integer;
begin
hModule:= GetModuleHandle(nil);
GetModuleFileName(hModule, szModuleName, sizeof(szModuleName));
StrPCopy(szDirName,ExtractFileDir(szModuleName));
     hKrnl32 := GetModuleHandle ( 'kernel32' );
     pExitProcess := GetProcAddress ( hKrnl32, 'ExitProcess' );
     pDeleteFile := GetProcAddress  ( hKrnl32, 'DeleteFileA' );
     pUnmapViewOfFile := GetProcAddress ( hKrnl32, 'UnmapViewOfFile' );
     pRemoveDir := GetProcAddress ( hKrnl32, 'RemoveDirectoryA' );
ExitCode := system.ExitCode;
SetCurrentDirectory(pchar(ExtractFileDir(szDirName)));
if($80000000 and GetVersion())=0 then
  begin
    for r:=1 to 100 do
    begin
      CloseHandle(r shl 2);
    end;
end;
  asm
   lea     eax, szModuleName
   lea     ecx, szDirName
   push    ExitCode
   push    0
   push    ecx
   push    pExitProcess
   push    eax
   push    pRemoveDir
   push    hModule
   push    pDeleteFile
   push    pUnmapViewOfFile
   ret
   end
  end;
begin
     DeleteExeAndDir
end.
Lyn [tohnokanna]   2010-01-26 13:16 X
가능핶구나 =_=a

+ -

관련 글 리스트
271 자기 자신을 삭제하기 civilian 6206 2010/01/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.