assembly - Nasm kernel32.dll DeleteFile -


alright, tried use deletefile method kernel32.dll (using nasm assembler), doesn't deletes file, , exits error.

extern _getstdhandle@4 extern _writeconsolea@20 extern _deletefilea@4 extern _exitprocess@4  section .data     msg: db "could not delete file", 10, 0     len: equ $- msg  section .bss     numcharswritten resb 1  section .text     global _start      _start:         mov edx, [esp+8]         push dword [edx]            ; pushes argument.         call _deletefilea@4         ; deletes file          add esp, 8                  ; removes 2 arguments          cmp eax, 0                  ; <cmp> = (eax == 0)         je _error                   ; if(<cmp>) jump _error          push dword 0x0a             ; exit value         call _exitprocess@4         ; exit      _error:         push dword -0x0b         call _getstdhandle@4          push dword 0                ; arg4, unused         push numcharswritten        ; arg3, pointer numcharswritten         push dword len              ; arg2, length of string         push msg                    ; arg1, string         push eax                    ; arg0, _getstdhandle@4         call _writeconsolea@20      ; writes string          push dword 0x0a             ; exit code         call _exitprocess@4         ; exit 

it prints not delete file, , exits. code has error?

unless linking against c library (using gcc or similar), windows programs not have argc or argv trying access params esp not work. instead, need use getcommandlinew return pointer command line string current process. turn argc , argv, use commandlinetoargvw. yes, unicode versions. here example, use printf make displaying bit easier.

%define     std_output_handle -11  ; shell32.dll extern  commandlinetoargvw  ; kernel32.dll extern exitprocess, writeconsolew, localfree extern getstdhandle, getcommandlinew %define getcommandline getcommandlinew  ;  msvcrt.dll extern _printf  section .bss stdout          resd 1 szarglist       resd 1 nargs           resd 1  section .data fmtst     db  "%ws", 13, 10, 0  section .text global _start  _start:     push    std_output_handle     call    getstdhandle     mov     dword [stdout], eax      call    getcommandline      push    nargs     push    eax     call    commandlinetoargvw     mov     dword [szarglist], eax     mov     esi, eax     xor     ebx, ebx     sub     dword [nargs], 1  .displayargs:     push    dword [esi + 4 * ebx]     push    fmtst     call    _printf     add     esp, 4 * 2      inc     ebx     cmp     ebx, dword [nargs]     jle     .displayargs      push    dword [szarglist]     call    localfree      push    0     call    exitprocess 

and output:

enter image description here


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -