
Extremely Active Member
     
Group: Moderators
Posts: 873
Member No.: 5019
Joined: 13-May 07

|
Hi
This code convert a String "Encodeme"to hex "456E636F64656D65"
| CODE |
include \masm32\include\masm32rt.inc
; added a PROTOtype near the beginning of the source so we can use INVOKE
HexEncode PROTO :dword,:dword,:dword
.data HexWord db "Encodeme" ; we pass the length, so a null terminator is not required
.data? hOut db 260 dup (?)
.code start:
invoke HexEncode,offset HexWord,sizeof HexWord,offset hOut
invoke MessageBox,0,addr hOut ,0,MB_OK invoke ExitProcess,0
HexEncode proc uses edi esi ebx pBuff:dword,dwLen:dword,pOutBuff:dword ;--------------------------------------- mov ebx, dwLen mov edi, pOutBuff test ebx, ebx mov esi, pBuff jz @F .repeat movzx eax, byte ptr [esi] mov ecx, eax add edi, 2 shr ecx, 4 and eax, 1111b and ecx, 1111b cmp eax, 10 sbb edx, edx adc eax, 0 lea eax, [eax+edx*8+'7'] cmp ecx, 10 sbb edx, edx adc ecx, 0 shl eax, 8 lea ecx, [ecx+edx*8+'7'] or eax, ecx inc esi mov [edi-2], ax dec ebx .until ZERO? @@: mov eax, edi mov byte ptr [edi], 0 sub eax, pOutBuff ret ;--------------------------------------- HexEncode endp end start
|
Greets,
|