Printf or MessageBox in ASM for debugging

98 Views Asked by At

I try to debug in x32dbg how a MFC program works with IO ports and I want to add printf or MessageBoxA after in/out assembly commands before returning from the function and display some values. When I put printf:

push eax //eax contains the value
call printf
add esp,4
ret

I get exception C0000005 EXCEPTION_ACCESS_VIOLATION

If I use MessagrBoxA:

push 0 //OK
push eax // eax contains the value
push eax
push 0 // HWND
call dword ptr ds:[54352C] // linked user32.MessageBoxA
ret

I get the same exception into MessageBoxA. Why is this happens? How can I output some values another way?

Update:

If I use putchar here:

push eax
call putchar
add esp,4
ret

I get nothing because I didn't initialise console in my app. Is it possible to initialize it in ASM and run console parallel to main app?

0

There are 0 best solutions below