; ----------------------------------------
;
;  (C) Alex Demchenko (alex@ritlabs.com)
;          http://www.cobans.net
;
; ----------------------------------------
; Doesn't work with FSG packer, works normally with UPX or w/o packer



; #########################################################################

.data
        szSDKernel32    db "KERNEL32",0
        szSDExitProcess db "ExitProcess",0
        szSDDeleteFile  db "DeleteFileA",0

.data?
        pExitProcess    dd ?
        pDeleteFile     dd ?

; #########################################################################

.code

; Ugly hack :)
DoSelfDelete proc
        invoke  GetModuleHandle, offset szSDKernel32
        mov     esi, eax
        invoke  GetProcAddress, esi, offset szSDExitProcess
        mov     [pExitProcess], eax
        invoke  GetProcAddress, esi, offset szSDDeleteFile
        mov     [pDeleteFile], eax

        sub     esp, 104h
        mov     edi, esp
        push    104h
        push    edi
        push    0
        call    GetModuleFileNameA
        push    0
        call    GetModuleHandleA
        push    0
        push    0
        push    edi
        push    [pExitProcess]
        push    eax
        push    [pDeleteFile]
        push    eax
        push    UnmapViewOfFile
        push    4
        push    FreeLibrary
        push    CloseHandle
        ret
DoSelfDelete endp
