标题:不定超长16进制ASCII码字符窜,按表达值压存汇编子程序
只看楼主
win_pig
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-11-14
 问题点数:0 回复次数:3 
不定超长16进制ASCII码字符窜,按表达值压存汇编子程序
送有特殊要求的人使用.
比如:
'13FDDC457F456DFCC4554',0  要按其表达的16进制值存入内存,没有相应的API.用汇编十分方便.注意高低位倒序
54 45 cc df 56 f4 57 c4 dd 3f 01 00


原码送上.
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;16进制ASCII字符窜压转16进制数值子程序
; lpAsciiBuffer 16进制ASCII字符窜缓冲区指针.低址为字首"8 D 5 7 8 8 9 2 F D"
; lpHexBuffer    压转后16进制数值缓冲区指针.低址为低位值 FD 92 88 57 8D
; 注意:函数转换成功则EAX返回转换后16进制的数值所占字节数
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcAsciiToHex    proc    uses  ebx ecx edi esi lpAsciiBuffer,lpHexBuffer
        local @buffer[24]:byte

        ;提示语句中文显示码
        mov dword ptr [@buffer+00],0dcb4d6d7h
        mov dword ptr [@buffer+04],0d5bfaaceh
        mov dword ptr [@buffer+08],0d0d3f2bbh
        mov dword ptr [@buffer+12],0fdcac7b7h
        mov dword ptr [@buffer+16],0d6d7b5d6h
        mov dword ptr [@buffer+20],00000fbb7h

        mov esi,lpHexBuffer
        mov edi,lpAsciiBuffer

;******  参数lpAsciiBuffer指向的ASCII窜改大写及合法判断  **********
        .while TRUE
            mov al,byte ptr [edi]
            .if al == 0
                .break
            .elseif    al>= 61h && al<=66H
                    and al,not 20H
                    mov byte ptr [edi],al
            .elseif al>=30h && al<=39h
            .elseif al>=41h && al<=46h
            .else
                invoke MessageBox ,hDlowin,addr @buffer,null,MB_OK
                xor eax,eax
                ret
            .endif
            inc edi
        .endw
        mov edi,lpAsciiBuffer             ;恢复EDI指针

;***************  确定ASCII窜字符长度  *******************
        mov ecx,0FFFFFFFFH
        xor eax,eax
        repnz scasb

        mov edi,lpAsciiBuffer             ;恢复EDI指针
        not ecx
        dec ecx

        .if ecx == 0                ;空窜提示
            invoke MessageBox ,hDlowin,addr @buffer,null,MB_OK
            xor eax,eax
            ret
        .endif
                     ;子程结束前 POP EAX 返回字窜长度

;**************  确定ASCII字符窜奇数时首字符前补0的处理 *********

        test ecx,1
        .if ! ZERO?                            ;奇

            inc ecx                        ;增1补0,字符数变偶
            shr ecx,1            ;取欲存字节数ECX/2,ESI+ECX即指向高字节单元

;            mov ah,0h                       ;AH补0 压为欲存字存高位
;            .if ah<=39h
;                sub ah,30h
;            .else
;                sub ah,37h
;            .endif
;            shl ah,4

            mov al,byte ptr [edi]          ;al字符压为欲存低位
            inc edi
            .if al<=39h
                sub al,30h
            .else
                sub al,37h
            .endif

;            or al,ah
            mov byte ptr [esi+ecx],0h    ;置结束字节00H
            push ecx
            dec ecx
            mov byte ptr [esi+ecx],al


        .else                                   ;偶
            shr ecx,1            ;取欲存字节数ECX/2,ESI+ECX即指向高字节单元

            mov ah,byte ptr [edi]        ;AH字符压为高位
            inc edi
            .if ah<=39h
                sub ah,30h
            .else
                sub ah,37h
            .endif
            shl ah,4            ;AH值移值高4位,低位补0

            mov al,byte ptr [edi]        ;AL字符压为低位
            inc edi
            .if al<=39h
                sub al,30h
            .else
                sub al,37h
            .endif

            add al,ah            ;整合为8位字节

            mov byte ptr [esi+ecx],0h    ;置结束字节00H
            push ecx
            dec ecx
            mov byte ptr [esi+ecx],al

        .endif

;**************** 字窜后续字符处理  ****************
        .while ecx

            mov ah,byte ptr [edi]        ;AH字符压为高位
            inc edi
            .if ah<=39h
                sub ah,30h
            .else
                sub ah,37h
            .endif
            shl ah,4

            mov al,byte ptr [edi]        ;AL字符压为低位
            inc edi
            .if al<=39h
                sub al,30h
            .else
                sub al,37h
            .endif

            add al,ah
            dec ecx
            mov byte ptr [esi+ecx],al

        .endw
        pop eax                    ;返回16进值所点字节数
        ret
_ProcAsciiToHex    endp

;mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
;       源码谨供MASM32研学,请忽它用
;mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
;Programming: sandejin      Date: 2008/12/15
;Email: sandejin@      QQ:  502790698
;mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
收到的鲜花
  • zklhp2008-12-26 16:44 送鲜花  50朵   附言:我很赞同
搜索更多相关主题的帖子: 进制 ASCII 
2008-12-15 18:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-249471-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054460 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved