Search code examples
windowsassemblyhexmasm32

Print hexa value in masm


I do a MapViewOfFile to get a pointer on the begin of my file, after that I want to print the value of it in hexa.

When I print it as string I get "MZ" which is the good value (the magic number) but I want it in hexa (5A4D).

I tried to format with %x in wsprintf but it doesn't work, I got 230000 as value..

EDIT the tried for %x:

.data
    header_format   db "The header is: %x",0 
    buffer          db 256 dup(?) ; File data
.data?
    pMemory DWORD ? ; Pointer to the data in the source file

getData:
    ;pMemory is the ptr which is correctly printed with %s
    invoke wsprintf, ADDR buffer, ADDR header_format, [pMemory] ; 
    invoke MessageBox, NULL, Addr buffer, Addr header_test, MB_OK

Have you any suggestions ?

Thanks.


Solution

  • It finally works by using this solution :

    push STD_OUTPUT_HANDLE
    call GetStdHandle
    
    mov eax, pMemory
    push eax
    print   right$(uhex$(eax),2),13,10
    pop eax
    mov eax, pMemory
    push eax
    print   right$(uhex$([eax]),2),13,10
    pop eax