so basically what I want is to send a byte array to a richedit control, currently I send a string by using EM_REPLACESEL message but the SendMessage function takes a null-terminated string, I want this control to show me a dump of a file.
Does anyone know a way to do this? Thanks.
You need to translate the byte array to a string of hex values:
include \masm32\include\masm32rt.inc
.data?
buffer db 1000 dup(?)
.code
txBytes db "Just a test", 0, "with an embedded nullbyte", 0
start:
; method A:
invoke bin2hex, addr txBytes, sizeof txBytes, addr buffer ; use somefiletobuffermacro here
print offset buffer, 13, 10, 10
; method B:
mov ebx, sizeof txBytes
mov esi, offset txBytes
mov edi, offset buffer
push edi
.Repeat
lodsb
movsx eax, al
push uhex$(eax) ; Masm32 macro
pop edx
mov eax, [edx+6]
stosb
xchg al, ah
stosb
mov al, " " ; for readability
stosb
dec ebx
.Until Sign?
pop edi
print edi, 13, 10
exit
end start
Output:
4A 75 73 74 20 61 20 74 - 65 73 74 00 77 69 74 68
20 61 6E 20 65 6D 62 65 - 64 64 65 64 20 6E 75 6C
6C 62 79 74 65 00
4A 75 73 74 20 61 20 74 65 73 74 00 77 69 74 68 20 61 6E 20 65 6D 62 65 64 64 65 64 20 6E 75 6C 6C 62 79 74 65 00 68 00
Hello jj2007, Thanks for your reply but I would like to see the result in characters, I think it's more readable.
OK. Technically speaking, a zero-delimited string finishes where there is a zero byte. Logical, right? So just go through the byte array and replace all zeroes with "." or "_".
that seems like a good idea, thank you. :biggrin:
It may be worth 'sanitising' any bytes below 20h -- there are control characters and shouldn't be printed, especially BEL, TAB, LF, CR.