GetLastError
GetLastError() in the Win32 API retrieves the error code for the last operation, aiding in diagnosing and handling errors in Windows programming.
call_getprocaddress_getlasterror:
mov [rbp-0x28], rbx ; [RBP-0x28] = Kernel32 base address
mov rcx, [rbp-0x28] ; RCX = hModule = Kernel32 base address
mov rax, 0x726f7272 ;
push rax ;
mov rax, 0x457473614c746547 ;
push rax ;
mov rdx, rsp ; RDX = lpProcName = GetLastError
sub rsp, 0x2c ; Allocate stack space for the function call
; (+ alignment)
call [rbp-0x18] ; CALL GetProcAddress
add rsp, 0x2c ; Clean up allocated space
add rsp, 0x10 ; Clean up GetLastError on stack
mov [rbp-0x8], rax ; [RBP-0x8] = *GetLastErrorsub rsp, 0x2c ; Allocate stack space for the function call (+
; alignment)
call [rbp-0x8] ; Call GetLastError
int3 ; Break to examine error in raxExample

Last updated