HEX2ASCII && ASCII2HEX

; 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

; 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
* 网址:https://lang.ma/
* 个性:https://oba.by/
* 本文标题: 《HEX2ASCII && ASCII2HEX》
* 本文链接:https://nai.dog/2011/10/3189
* 短链接:https://oba.by/?p=3189
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

发表回复

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