0

For example we have chars buffer with hex value:

char * buff = {"e000"}; //this is our hex value in eax - input for Get_Val().

Then there is function Get_Val() - converts hex (string) to decimal (numbers):

cseg01:0004DC00 Get_Val         proc near               ; CODE XREF: Get_DeviceID_Value+97p
cseg01:0004DC00                 push    ebx
cseg01:0004DC01                 push    ecx
cseg01:0004DC02                 push    edx
cseg01:0004DC03                 push    esi
cseg01:0004DC04                 push    edi
cseg01:0004DC05                 push    ebp
cseg01:0004DC06                 mov     ebp, eax        ; ebp = eax = pointer to chars buff
cseg01:0004DC08                 mov     edi, eax        ; edi = eax = pointer to chars buff
cseg01:0004DC0A                 sub     ecx, ecx
cseg01:0004DC0C                 dec     ecx
cseg01:0004DC0D                 xor     eax, eax
cseg01:0004DC0F                 repne scasb
cseg01:0004DC11                 not     ecx
cseg01:0004DC13                 dec     ecx
cseg01:0004DC14                 xor     ebx, ebx
cseg01:0004DC16                 xor     esi, esi
cseg01:0004DC18                 lea     edx, ds:0[ecx*4]
cseg01:0004DC1F
cseg01:0004DC1F next_loop:                              ; CODE XREF: Get_Val+3Ej
cseg01:0004DC1F                 mov     eax, ebx
cseg01:0004DC21                 inc     ebx
cseg01:0004DC22                 mov     al, [eax+ebp]
cseg01:0004DC25                 and     eax, 0FFh
cseg01:0004DC2A                 call    Get_Digit
cseg01:0004DC2F                 imul    eax, off_C6D28[edx]
cseg01:0004DC36                 sub     edx, 4
cseg01:0004DC39                 dec     ecx
cseg01:0004DC3A                 add     esi, eax
cseg01:0004DC3C                 test    ecx, ecx
cseg01:0004DC3E                 ja      short next_loop
cseg01:0004DC40                 mov     eax, esi
cseg01:0004DC42                 pop     ebp
cseg01:0004DC43                 pop     edi
cseg01:0004DC44                 pop     esi
cseg01:0004DC45                 pop     edx
cseg01:0004DC46                 pop     ecx
cseg01:0004DC47                 pop     ebx
cseg01:0004DC48                 retn
cseg01:0004DC48 Get_Val         endp

Function Get_Digit returns one digit - corresponds to chars buffer, one digit from 0 to 15, for example our hex 'e' has numeric value 14 decimal, and Get_Digit returns for our example 14 decimal.

cseg01:0004DC4C Get_Digit       proc near               ; CODE XREF: Get_Val+2Ap
cseg01:0004DC4C                 push    ebx
cseg01:0004DC4D                 push    ecx
cseg01:0004DC4E                 push    edx
cseg01:0004DC4F                 mov     ecx, off_C6D28
cseg01:0004DC55                 mov     bl, al
cseg01:0004DC57                 xor     eax, eax
cseg01:0004DC59
cseg01:0004DC59 next_loop:                              ; CODE XREF: Get_Digit+1Dj
cseg01:0004DC59                 lea     edx, [ecx+eax]
cseg01:0004DC5C                 cmp     bl, [edx]
cseg01:0004DC5E                 jz      short on_exit
cseg01:0004DC60                 cmp     bl, [edx+10h]
cseg01:0004DC63                 jz      short on_exit
cseg01:0004DC65                 inc     eax
cseg01:0004DC66                 cmp     eax, 10h
cseg01:0004DC69                 jb      short next_loop
cseg01:0004DC6B                 mov     eax, 0FFFFFFFFh
cseg01:0004DC70
cseg01:0004DC70 on_exit:                                ; CODE XREF: Get_Digit+12j
cseg01:0004DC70                                         ; Get_Digit+17j
cseg01:0004DC70                 mov     off_C6D28, ecx
cseg01:0004DC76                 pop     edx
cseg01:0004DC77                 pop     ecx
cseg01:0004DC78                 pop     ebx
cseg01:0004DC79                 retn
cseg01:0004DC79 Get_Digit       endp

Where off_C6D28 is:

dseg05:000C6D28 off_C6D28       dd offset a0123456789abcd
dseg05:000C11BC a0123456789abcd db '0123456789ABCDEF0123456789abcdef',0

My question is - what is this means in func Get_Val():

imul    eax, off_C6D28[edx]

What is value of edx:

lea     edx, ds:0[ecx*4]

And how arranged exit from loop (I dont understand what happens with ecx inside loop):

cseg01:0004DC1F next_loop:                              ; CODE XREF: Get_Val+3Ej
cseg01:0004DC1F                 mov     eax, ebx
cseg01:0004DC21                 inc     ebx
cseg01:0004DC22                 mov     al, [eax+ebp]
cseg01:0004DC25                 and     eax, 0FFh
cseg01:0004DC2A                 call    Get_Digit
cseg01:0004DC2F                 imul    eax, off_C6D28[edx]
cseg01:0004DC36                 sub     edx, 4
cseg01:0004DC39                 dec     ecx
cseg01:0004DC3A                 add     esi, eax
cseg01:0004DC3C                 test    ecx, ecx
cseg01:0004DC3E                 ja      short next_loop

Thanks in advance.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.