HEX2ASCII && ASCII2HEX

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
; Author: Jake Commander
; Copyright The GeneSys Development System
 
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
; Author: Jake Commander
; Copyright The GeneSys Development System
 
HexDecode proc uses esi edi ebx pHexStr:dword,pOutBuffer:dword
;---------------------------------------
    mov    esi, pHexStr
    mov    edi, pOutBuffer
    jmp    @1
@@: and    ebx, 0Fh
    add    eax, ebx
    mov    [edi], al
    inc    edi
@1: movzx  edx, byte ptr[esi]
    cmp    edx, 40h
    sbb    ebx, ebx
    sub    edx, 37h
    and    ebx, 7
    inc    esi
    add    ebx, edx
    js      @F
    mov    eax, ebx
    shl    eax, 4
    mov    [edi], al
    movzx  edx, byte ptr [esi]
    cmp    edx, 40h
    sbb    ebx, ebx
    sub    edx, 37h
    and    ebx, 7
    inc    esi
    add    ebx, edx
    jns    @B
@@: ret
;---------------------------------------
HexDecode endp

Link:http://www.winasm.net/forum/index.php?showtopic=2618

原创文章,转载请注明: 转载自 obaby@mars

本文标题: 《HEX2ASCII && ASCII2HEX》

本文链接地址: http://www.h4ck.org.cn/2011/10/hex2ascii-ascii2hex/

You may also like

发表评论

电子邮件地址不会被公开。 必填项已用*标注