flat assembler
Message board for the users of flat assembler.

Index > Windows > Yet another hexdump program

Author
Thread Post new topic Reply to topic
Mat Quasar 1



Joined: 08 Nov 2026
Posts: 7
Mat Quasar 1 08 Nov 2026, 14:15
My last hobby project was scanexe.asm in December 2025, so it has been 10 months I didn't do anything. This time is a hexdump CLI program for Windows, but I use different approach, a library function in CRYPT32.DLL. I am not sure whether it support bytes array larger than 64KB, because the address output is only 16-bit.

However, it is sad today I have to make the following note:

Note: This program was 100% hand written. No AI.

Code:
; hexview , by fliermate (aka Mat Quasar), 2026/10
; License: CC0
;
; Dedicated to SherpaSec
;
; Version history: v0.01 - Initial release
;
; Reference:
; - https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptbinarytostringa
;
; API function calls:
;invoke GetCommandLine
;invoke CreateFileA,......
;invoke ReadFile,....
;invoke CryptBinaryToStringA,......
;invoke GetStdHandle,.......
;invoke WriteFile,........
;invoke ExitProcess,......
;

format PE console
include 'win32a.inc'

CRYPT_STRING_HEXASCIIADDR = 0x0000000b
BUFFER_SIZE=64*1024  ;Supports up to 64KB file size
STRING_SIZE=64*1024*100

section '.data' readable writeable

_err0     db 'Usage:  hexview <filename>',13,10,0
_len0     = $ - _err0
_err1     db 'Error opening file.',13,10,0
_len1     = $ - _err1
_err2     db 'Error reading file.',13,10,0
_len2     = $ - _err2
_err3     db 'Error displaying the output.',13,10,0
_len3     = $ - _err3

_dummy    dd ?
_fnlen    dd ?
_hfile    dd ?
_hout     dd ?
_len      dd ?
_count    dd STRING_SIZE
_filename rb MAX_PATH
_buffer   rb BUFFER_SIZE
_string   rb STRING_SIZE

section '.code' code readable executable

entry $
    invoke  GetStdHandle, STD_OUTPUT_HANDLE ;-11
    mov     dword [_hout],eax

    call    [GetCommandLine]
    push    eax
    cld
    mov     edi, eax
    or      ecx, -1
    xor     eax, eax
    repnz   scasb           ; Calculate total length of command line arguments
    not     ecx
    pop     eax
    push    eax
    mov     dword [_fnlen], ecx
    mov     edi, eax
    or      ecx, -1
    mov     eax, 32
    repnz   scasb           ; Find the first white space after first argument
    repz    scasb           ; Scan for extra white spacing between first argument and second argument
    not     ecx
    mov     dword [_dummy], ecx
    sub     dword [_fnlen], ecx
    cmp     dword [_fnlen], 0    ; Check if no argument is supplied
    jle     .err0
    mov     ecx, dword [_fnlen]
    pop     eax
    add     eax, dword [_dummy]
    dec     eax
    xor     ebx, ebx
    cmp     byte [eax], '"'      ; Check if path is enclosed in quotes
    setz    bl
    sub     ecx, ebx
    sub     ecx, ebx
    mov     esi, eax
    add     esi, ebx
    lea     edi, [_filename]
    rep     movsb

    invoke  CreateFile, _filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
    mov     dword [_hfile], eax
    cmp     eax, INVALID_HANDLE_VALUE
    je      .err1

    invoke  ReadFile, dword [_hfile], _buffer, BUFFER_SIZE, _len, 0
    test    eax, eax
    jz      .err2
    mov     ecx, dword [_len]
    test    ecx, ecx
    jz      .close

    invoke  CryptBinaryToStringA, _buffer, dword [_len], CRYPT_STRING_HEXASCIIADDR, _string, _count
    or      eax,eax
    jz      .err3
    inc     dword [_count]
    invoke  WriteFile, dword [_hout], _string, dword [_count], _dummy, 0 ;Output can be redirected to text file using ">" or ">>" in command line

.close:
    invoke  CloseHandle, [_hfile]
    jmp     .done

.err0:
    lea     edx, [_err0]
    mov     ecx, _len0
    jmp     .error
.err1:
    lea     edx, [_err1]
    mov     ecx, _len1
    jmp     .error
.err2:
    lea     edx, [_err2]
    mov     ecx, _len2
    jmp     .error
.err3:
    lea     edx, [_err3]
    mov     ecx, _len3
.error:
    invoke  WriteConsole, dword [_hout], edx, ecx, _dummy, 0

.done:
    invoke  ExitProcess,0

section '.idata' import readable writable

  library kernel32, 'KERNEL32.DLL' ,\
          crypt32, 'CRYPT32.DLL'

  import kernel32,\
         GetStdHandle, 'GetStdHandle', \
         WriteConsole, 'WriteConsoleA', \
         CreateFile, 'CreateFileA', \
         ReadFile, 'ReadFile', \
         WriteFile, 'WriteFile', \
         CloseHandle, 'CloseHandle', \
         GetCommandLine, 'GetCommandLineA', \
         ExitProcess,'ExitProcess'

  import crypt32,\
         CryptBinaryToStringA,'CryptBinaryToStringA'    
Post 08 Nov 2026, 14:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21203
Location: In your JS exploiting you and your system
revolution 08 Nov 2026, 20:05
Mat Quasar 1 wrote:
However, it is sad today I have to make the following note:

Note: This program was 100% hand written. No AI.
Not sure why that is sad.

Exercising the brain is a good thing. Adds 5-10 years to expected lifespan.
Post 08 Nov 2026, 20:05
View user's profile Send private message Visit poster's website Reply with quote
Mat Quasar 1



Joined: 08 Nov 2026
Posts: 7
Mat Quasar 1 08 Nov 2026, 21:28
revolution wrote:
Mat Quasar 1 wrote:
However, it is sad today I have to make the following note:

Note: This program was 100% hand written. No AI.
Not sure why that is sad.

Exercising the brain is a good thing. Adds 5-10 years to expected lifespan.


I meant it is sad I have to state it as non-AI created app or else readers would assume it is another vibe coded project.
Prior to 2025, it was less likely AI models could write good Assembly program, and I didn't have to say '100% hand-written' at the time to distinguish it from AI-assisted project.
Post 08 Nov 2026, 21:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.