News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Memory to String

Started by Farabi, June 03, 2010, 02:28:56 AM

Previous topic - Next topic

Farabi

I wonder what was wrong with my code


fInetData struct
nSize dword 0
lpData dword 0
fInetData ends

.data
tbl db "0123456789ABCDEF",0

.code

fBin2String proc uses esi edi lpfInetData:dword,lpData:dword,nSize:dword
LOCAL data:dword
LOCAL off_p:Dword
LOCAL b:word
LOCAL buff[256]:dword

mov esi,lpData

mov ecx,nSize
shl ecx,1
invoke mAlloc,ecx
mov data,eax
mov edi,eax

xor ecx,ecx
mov off_p,ecx
loop_data:
push ecx
add edi,off_p
lea edx,tbl

movzx eax,byte ptr[esi+ecx]
shr eax,4
mov al,[edx+eax]
mov [edi+0],al

movzx eax,byte ptr[esi+ecx]
and al,1111b
mov al,[edx+eax]
mov [edi+1],al

add off_p,2
pop ecx
inc ecx
cmp ecx,nSize
jl loop_data

; invoke dw2a,ecx,addr buff
; invoke MessageBox,0,addr buff,0,0

mov esi,lpfInetData
mov eax,nSize
shl eax,1
push eax
pop [esi].fInetData.nSize
push data
pop [esi].fInetData.lpData

ret
fBin2String endp


It only convert 2 byte.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Never mind, I found it
Quote
fBin2String proc uses esi edi lpfInetData:dword,lpData:dword,nSize:dword
   LOCAL data:dword
   LOCAL off_p:Dword
   LOCAL b:word
   LOCAL buff[256]:dword
   
   mov esi,lpData
   
   mov ecx,nSize
   shl ecx,1
   invoke mAlloc,ecx
   mov data,eax
   mov edi,eax
   
   xor ecx,ecx
   mov off_p,ecx
   loop_data:
   push ecx
      mov edi,data
      add edi,off_p
      lea edx,tbl
      
      movzx eax,byte ptr[esi+ecx]
      shr eax,4
      mov al,[edx+eax]
      mov [edi+0],al
      
      movzx eax,byte ptr[esi+ecx]
      and al,1111b
      mov al,[edx+eax]
      mov [edi+1],al
      
      add off_p,2
   pop ecx
   inc ecx
   cmp ecx,nSize
   jl loop_data
   
;   invoke dw2a,ecx,addr buff
;   invoke MessageBox,0,addr buff,0,0
   
   mov esi,lpfInetData
   mov eax,nSize
   shl eax,1
   push eax
   inc dword ptr[esp]
   pop [esi].fInetData.nSize
   push data
   pop [esi].fInetData.lpData
   
   ret
fBin2String endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Anyway here is the string to bin function.

Quote
fString2Bin proc uses esi edi lpfInetData:dword,lpData:dword,nSize:dword
   LOCAL data:dword
   LOCAL off_data:dword
   
   mov esi,lpData
   mov ecx,nSize
   ;shr ecx,1
   invoke mAlloc,ecx
   mov data,eax
   
   xor ecx,ecx
   mov off_data,ecx
   loop_data:
   push ecx
      mov edi,data
      add edi,off_data
      
      mov al,[esi]
      mov ah,[esi+1]
      
      .if al>=30h
         .if al<=39h
            sub al,30h
         .else
            .if al>=41h
               .if al<=46h
                  sub al,37h
               .endif
            .endif
         .endif
      .endif

      .if ah>=30h
         .if ah<=39h
            sub ah,30h
         .else
            .if ah>=41h
               .if al<=46h
                  sub ah,37h
               .endif
            .endif
         .endif
      .endif
      
      mov ecx,0
      mov cl,al
      shl cl,4
      or cl,ah
      
      mov byte ptr[edi],cl
      
      add esi,2
      add off_data,1
   pop ecx
   inc ecx
   cmp ecx,nSize
   jl loop_data
   
   mov ecx,lpfInetData
   push nSize
   shr dword ptr[esp],1
   pop [ecx].fInetData.nSize
   push data
   pop [ecx].fInetData.lpData
   
   ret
fString2Bin endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"