Hi,
i have managed to create a lib wich uses no lib funcs and imports everything runtime so my exe is only 4KB ;-)
I have a compression routine but for some reason i can`t seem to get hex/ascii thing working.
for example:
buffer db 256 dup(0)
nasty2 db 00h, 40h, 0C0h, 80h, 4Ch, 00h, 00h, 00h, 0B4h, 0BDh, 59h, 0ADh, 1Ch, 0B4h, 0BDh, 59h,0ADh, 1Ch, 64h, 0E3h
; doesn f***ing work
do_it proc x_nasty,i_size
local abuf:byte
;NastyToHex:
push offset nasty
push edi
;mov eax,OFFSET nasty ; input
;mov edx,OFFSET buffer ; output
;mov edi,8 ; number of bytes to convert
;assume eax:byte
mov eax, x_nasty ; input
mov edx, OFFSET buffer ; output
mov edi,i_size ;8 ; number of bytes to convert
_ntx_loop:
mov cl,byte ptr [eax] ; convert top half
and cl,0F0h
shr cl,4
cmp cl,9
jle no_xtra_add
add cl,7
no_xtra_add:
add cl,30h
mov byte ptr [edx],cl
mov cl,byte ptr [eax] ; convert low half
and cl,0Fh
cmp cl,9
jle no_xtra_add2
add cl,7
no_xtra_add2:
add cl,30h
mov byte ptr [edx+1],cl
inc eax
add edx,2
dec edi
jnz _ntx_loop
pop eax
mov eax,OFFSET buffer
ret
do_it endp
invoke do_it, offset nasty2 ,n2len
invoke MessageBox, NULL,addr nasty2, addr buffer, MB_OK
it outputs: 0101deeh11h and not ( Life is Wonderfull for example).
I am planning compressing API-names(strings) and storing them as hex DB and making the smallest exe possible.
I already try`d the masmlib but to be honnest it does not work for me.
When i was searching the forum i did download everything related to HEX_TO_ASCII but i still didn`t see any good routine.
maybe someone can shine some light on it.
Thnx
marco,
The routines in the masm32 library for byte data to hex string were designed for speed rather than being compact.
bin2hex proc lpString:DWORD,lnString:DWORD,lpbuffer:DWORD
hex2bin proc src:DWORD,dst:DWORD
They both use tables for the conversions which brings their size up.
hmm this seems tobe hard, converting:
nasty2 dw 00h, 40h, 0C0h, 80h, 4Ch, 00h, 00h, 00h, 0B4h, 0BDh, 59h, 0ADh, 1Ch, 0B4h, 0BDh, 59h,0ADh, 1Ch, 64h, 0E3h
n2len equ 20
to Ascii_string.
The
;bin2hex proc lpString:DWORD,lnString:DWORD,lpbuffer:DWORD
;hex2bin proc src:DWORD,dst:DWORD
invoke hex2bin, offset nasty2,offset buffer
;invoke HexDump,offset nasty2,n2len,offset buffer
;invoke dw2a,offset nasty2,offset buffer
functions all fill the buffer with HEX or bin not ascii`s.
can somebody give me a sample like
myhex 0h,1h,2e
text_converted db 256 dup(0)
invoke convert,myhex,buffer
please?
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
buffer db 256 dup(0)
nnnnnn db 00h, 40h, 0C0h, 80h, 4Ch, 00h, 00h, 00h, 0B4h, 0BDh, 59h, 0ADh, 1Ch, 0B4h, 0BDh, 59h,0ADh, 1Ch, 64h, 0E3h
.code
start:
mov esi, sizeof nnnnnn - 1
mov edi, 0
.while (edi <= esi)
mov dl, [nnnnnn+edi]
mov al, dl
shr al, 4
and al, 0Fh
add al, 30h
.if (al > 39h)
add al, 7 ; uppercase or 7+32 for lowercase
.endif
mov [buffer+edi*2], al
mov al, dl
and al, 0Fh
add al, 30h
.if (al > 39h)
add al, 7 ; uppercase or 7+32 for lowercase
.endif
mov [buffer+edi*2+1], al
inc edi
.endw
invoke MessageBox, NULL,addr nnnnnn, addr buffer, MB_OK ; nnnnnn has a leading zero byte so no message shows, just caption
invoke ExitProcess,eax
end start
[attachment deleted by admin]
An array of bytes used as an ascii string is treated as an zero (byte) terminated string,
so if the first byte value is 0 ( 00h as shown in the listing) the string will terminate right there,
ie an empty string so nothing is shown in the messagebox output.
Instead of this
and al, 0Fh
add al, 30h
.if (al > 39h)
add al, 7 ; uppercase or 7+32 for lowercase
.endif
try this
and al,15
cmp al,10
sbb al,105
das
Thanx.
I am sorry maybe i didn`t explain it well enough.
I feel so ...... n00b :p
okay another try.
lets asume i have encoded the word 'test' using hexdump.exe
.data
encoded_txt db 74h, 65h, 73h, 74h ; =test
is it then possible to take the encoded_text and CONVERT it to a string
wich MessageBox can display?
for example:
invoke HexToAscii,encoded_text,outbuffer
invoke messagebox,0,some_title,outbuffer,0
Thanx for helping me.
I really apreciate all the help
Marco
Sure just have a zero byte after it.
.data
encoded_txt db 74h, 65h, 73h, 74h ; =test
zterm db 0
.code
invoke MessageBox, NULL,addr encoded_txt, addr encoded_txt, MB_OK
Thank your verry much,
it worked PERFECTLY
It works, but not in the way you've tried in your first attempt.
Your first attempt requires hex notation in character or text format.
encoded_text db '74657374'
After conversion, you still need to add a zero byte if you don't want MessageBox to print garbage after the first four characters.