News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

HexAsciiDump

Started by six_L, July 03, 2015, 05:18:09 PM

Previous topic - Next topic

six_L

the codes only worked the buffer of Ascii.
HexAsciiDump proc uses ebx esi edi inAddr:DWORD,nparagraphs:DWORD,fZeroBase:DWORD,outAddr:dword
LOCAL temp[4]:byte

invoke RtlZeroMemory,addr temp,4

mov esi, inAddr
mov ecx, nparagraphs
test ecx, ecx
jnz  rowLoop
ret

align 16

hex_table:

db "000102030405060708090A0B0C0D0E0F"
db "101112131415161718191A1B1C1D1E1F"
db "202122232425262728292A2B2C2D2E2F"
db "303132333435363738393A3B3C3D3E3F"
db "404142434445464748494A4B4C4D4E4F"
db "505152535455565758595A5B5C5D5E5F"
db "606162636465666768696A6B6C6D6E6F"
db "707172737475767778797A7B7C7D7E7F"
db "808182838485868788898A8B8C8D8E8F"
db "909192939495969798999A9B9C9D9E9F"
db "A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"
db "B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"
db "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"
db "D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF"
db "E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"
db "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"

ascii_table:

db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
db "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
db "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
db "P","Q","R","S","T","U","V","W","X","Y","Z","[","\","]","^","_"
db "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
db "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."

rowLoop:

push ecx

.IF fZeroBase
mov eax, esi
sub eax, inAddr
invoke lstrcat,outAddr,uhex$(eax)
invoke lstrcat,outAddr,CTXT(" ")
.ELSE                     
invoke lstrcat,outAddr,uhex$(esi)
invoke lstrcat,outAddr,CTXT(" ")
.ENDIF

lea edi, hex_table
push esi
REPEAT 8
invoke lstrcat,outAddr,CTXT(" ")
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx*2]

lea ecx,temp
mov [ecx], eax
invoke lstrcat,outAddr,addr temp

movzx eax, BYTE PTR [edi+ebx*2+1]
lea ecx,temp
mov [ecx], eax
invoke lstrcat,outAddr,addr temp
inc esi
ENDM

invoke lstrcat,outAddr,CTXT(" - ")

REPEAT 8
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx*2]
lea ecx,temp
mov [ecx], eax
invoke lstrcat,outAddr,addr temp
movzx eax, BYTE PTR [edi+ebx*2+1]
lea ecx,temp
mov [ecx], eax
invoke lstrcat,outAddr,addr temp
invoke lstrcat,outAddr,CTXT(" ")
inc esi
ENDM
pop esi

lea edi, ascii_table
invoke lstrcat,outAddr,CTXT(" ")
REPEAT 16
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx]
lea ecx,temp
mov [ecx], eax
invoke lstrcat,outAddr,addr temp
inc esi
ENDM
invoke lstrcat,outAddr,CTXT(13,10)

pop ecx
dec ecx
jnz rowLoop

ret

HexAsciiDump endp
Say you, Say me, Say the codes together for ever.

herge

Hi six_l:

Look at \masm32\m32lib\dw2ah.asm

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

six_L

thanks all who respondid my question.
here is a code of HexAsciiDump. and works fine.
HexAsciiDump_1 proc uses esi edi ebx pData:DWORD, dwOffset:DWORD, dwSize:DWORD
local dwCurrentOffset:DWORD
local AsciiBuffer:DWORD
local BufferSize:DWORD

.data
szFmt db "%08X  %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X  ", 0

.code

xor edx,edx
mov eax,dwSize
mov ecx,6
mul ecx
mov BufferSize,eax
invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_NO_SERIALIZE + HEAP_ZERO_MEMORY, BufferSize
.if eax != NULL

mov AsciiBuffer, eax
mov edi, eax

invoke RtlZeroMemory, edi, BufferSize
mov esi, pData
push dwOffset
pop dwCurrentOffset
mov ebx, dwSize
.if ( esi != NULL ) && ( ebx != 0 )

shr ebx, 4 ; / 16 - number of 16-byte lines to print
inc ebx

.while ebx
mov ecx, 16
xor eax, eax
.while ecx
dec ecx
mov al, [esi][ecx]
push eax
.endw
push dwCurrentOffset
push offset szFmt
push edi ; current pointer to text buffer
call wsprintf
add esp, 04Ch

add edi, eax ; shift current pointer to next free place

xor ecx, ecx
.while ecx < 16
mov al, [esi][ecx]
.if al < ' '
mov al, '.'
.elseif al > '~'
mov al, '.'
.endif
stosb
inc ecx
.endw

; New line
mov al, 0Dh
stosb
mov al, 0Ah
stosb

add esi, 16 ; next 16 bytes
add dwCurrentOffset, 16 ; next 16 bytes
dec ebx ; next line
.endw

invoke SetDlgItemText,XMAIN_hWnd,IDC_SHOWEDIT,NULL
invoke SetDlgItemText,XMAIN_hWnd,IDC_SHOWEDIT,AsciiBuffer

.endif

invoke GetProcessHeap
invoke HeapFree, eax, HEAP_NO_SERIALIZE, AsciiBuffer
.endif

ret

HexAsciiDump_1 endp


but i think the method of table searching better than the method of wsprintf.
Say you, Say me, Say the codes together for ever.

six_L

sorry for updating the old subject.
HexAsciiDump proc uses ebx esi edi pDataBuf:DWORD,dwSize:DWORD,p6xDataBuf_out:DWORD
LOCAL temp[4]:byte
LOCAL _EndAddr:DWORD
LOCAL rmData:DWORD

mov eax,pDataBuf
mov ecx,dwSize
add eax,ecx
mov _EndAddr,eax

invoke RtlZeroMemory, addr temp, sizeof temp
mov esi, pDataBuf
mov ecx, dwSize
test ecx, ecx
jnz  rowLoop
ret

align 16

hex_table:

db "000102030405060708090A0B0C0D0E0F"
db "101112131415161718191A1B1C1D1E1F"
db "202122232425262728292A2B2C2D2E2F"
db "303132333435363738393A3B3C3D3E3F"
db "404142434445464748494A4B4C4D4E4F"
db "505152535455565758595A5B5C5D5E5F"
db "606162636465666768696A6B6C6D6E6F"
db "707172737475767778797A7B7C7D7E7F"
db "808182838485868788898A8B8C8D8E8F"
db "909192939495969798999A9B9C9D9E9F"
db "A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"
db "B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"
db "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"
db "D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF"
db "E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"
db "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"

ascii_table:

db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db " ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/"
db "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"
db "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
db "P","Q","R","S","T","U","V","W","X","Y","Z","[","\","]","^","_"
db "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"
db "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."
db ".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."

rowLoop:
xor edx,edx
mov eax,dwSize
mov ecx,16
idiv ecx
inc eax
mov ecx,eax
mov rmData,edx

mov eax, p6xDataBuf_out
test eax, eax
jnz  rowLoop1
ret

rowLoop1:

mov eax, esi
sub eax, pDataBuf
invoke lstrcat,p6xDataBuf_out,uhex$(eax)
invoke lstrcat,p6xDataBuf_out,CTXT(":")
invoke lstrcat,p6xDataBuf_out,CTXT(" ")


lea edi, hex_table
push esi
REPEAT 8
invoke lstrcat,p6xDataBuf_out,CTXT(" ")
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx*2]
lea ecx,temp
mov [ecx], al
invoke lstrcat,p6xDataBuf_out,addr temp
movzx eax, BYTE PTR [edi+ebx*2+1]
lea ecx,temp
mov [ecx], al
invoke lstrcat,p6xDataBuf_out,addr temp
inc esi

cmp esi,_EndAddr
jz @exit_1

ENDM

invoke lstrcat,p6xDataBuf_out,CTXT(" - ")

REPEAT 8
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx*2]
lea ecx,temp
mov [ecx], eax
invoke lstrcat,p6xDataBuf_out,addr temp
movzx eax, BYTE PTR [edi+ebx*2+1]
lea ecx,temp
mov [ecx], al
invoke lstrcat,p6xDataBuf_out,addr temp
invoke lstrcat,p6xDataBuf_out,CTXT(" ")
inc esi

cmp esi,_EndAddr
jz @exit_1

ENDM
jmp _next
@exit_1:
mov esi,51
mov eax,rmData
xor edx,edx
mov ecx,3
imul ecx
sub esi,eax
.if rmData > 8
sub esi,3
.endif
.repeat
.if rmData==0
.break
.endif
invoke lstrcat,p6xDataBuf_out,CTXT(" ")
dec esi
.until esi==0
_next:
pop esi

lea edi, ascii_table
invoke lstrcat,p6xDataBuf_out,CTXT(" ")
REPEAT 16
movzx ebx, BYTE PTR [esi]
movzx eax, BYTE PTR [edi+ebx]
lea ecx,temp
mov [ecx], al
invoke lstrcat,p6xDataBuf_out,addr temp
inc esi

cmp esi,_EndAddr
jz @exit_2

ENDM
invoke lstrcat,p6xDataBuf_out,CTXT(13,10)
jmp rowLoop1

@exit_2:
ret

HexAsciiDump endp
Say you, Say me, Say the codes together for ever.