| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 820 人关注过本帖
标题:精华区代码Revision-C版本[系列五]
只看楼主 加入收藏
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
结帖率:100%
收藏
已结贴  问题点数:100 回复次数:1 
精华区代码Revision-C版本[系列五]
程序代码:
;MASMPlus 代码模板 - 控制台程序
;********************************************************************************
;MD5 Hasher
;by zklhp    Email:zklhp@
;2008.8.4
;转载请保留完整
;********************************************************************************

;Revision Declare Modified by zaixuexi
;*/ --------------------------------------------------------------------------------------
;*/ source:http://www.
;*/ author:zaixuexi
;*/ date:  2011-11-29
;*/ email: asmedu@
;*/ revision declare:
;*/ 1.add self-estimated c source code.
;*/ 2.adjust all asm source code lower-case style.
;*/ 3.keep all original code designment.
;*/ 4.using tab alignment source code text.
;*/ --------------------------------------------------------------------------------------

;#define PRJ_TITLE        L"MD5 hasher\r\n"
;#define CONTACT_US       L"by zklhp   Email:zklhp@\r\n"
;#define ENCRYPT_STR      L"Usage:%s 待加密字符串\r\n"
;#define MD5_STR          L"MD5("%s")="
;#define MD5_FORMAT       L"%08x%08x%08x%08x"
;#define wputs(str)       printf("%ws", str)
;#ifdef  UNICODE
;#define lstrlen          wcslen
;#else
;#define lstrlen          strlen
;#endif
;#ifdef  WIN32
;#define c_malloc(size)   GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, size)
;#define c_free(buf)      GlobalFree(buf)
;#else
;#define c_malloc(size)   malloc(size)
;#define c_free(buf)      free(buf)
;#endif
;#define ROL(a, N, n)     a = (a>>(N-n))|(a<<n)));
;#define ALIGN_2N(n)      (n-1)

;typedef unsigned char    uint8_t;
;typedef unsigned short   uint16_t;
;typedef unsigned int     uint32_t;
;typedef signed int       int32_t;
;typedef void*            lpvoid;

.386
.model flat, stdcall
option casemap :none

include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
;include gdi32.inc

;includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm
.data
    lpszDigest db 17d dup(0)    ;uint8_t  lpszDigest[17]; better 4-bytes alignment: uint32_t lpszDigest[5];
    lpszBuffer db 512d dup(0)   ;uint16_t lpszBuffer[256];
    lpszOut db 128d dup(0)      ;uint16_t lpszOut[64];

_MD5hash            proto    :DWORD,:DWORD,:DWORD         ;int32_t __stdcall _MD5hash(uint32_t, uint32_t, uint32_t);

.CODE
    include md5.asm  ;参考多个版本的源代码编写 有一个不知道作者 在此一并表示感谢
START:                                                    ;int32_t __stdcall main(int32_t argc, uint16_t *argv[]);

    invoke StdOut,CTXT('MD5 hasher',0dh,0ah)                         ;wputs(PRJ_TITLE);
    invoke StdOut,CTXT('by zklhp   Email:zklhp@',0dh,0ah)    ;wputs(CONTACT_US);
    invoke GetCL,0,  offset lpszBuffer                    ;lpszBuffer = argv[0];
    invoke wsprintf, offset lpszOut,CTXT('Usage:%s 待加密字符串',0dh,0ah),offset lpszBuffer   
                                                          ;wsprintf(lpszOut, ENCRYPT_STR, lpszBuffer);
    invoke StdOut,   offset lpszOut                       ;wputs(lpszOut);
    invoke GetCL,1,  offset lpszBuffer                    ;lpszBuffer = argv[1];
    invoke wsprintf, offset lpszOut,CTXT('MD5("%s")='),offset lpszBuffer
                                                          ;wsprintf(lpszOut, MD5_STR, lpszBuffer);
    invoke StdOut,   offset lpszOut                       ;wputs(lpszOut);
    invoke lstrlen,  offset lpszBuffer
    invoke _MD5hash, offset lpszBuffer,eax,offset lpszDigest       
                                                          ;_MD5hash(lpszBuffer, lstrlen(lpszBuffer), lpszDigest);
    lea esi,lpszDigest                                    ;uint32_t *lp = (uint32_t)lpszDigest;
    xor ecx,ecx                                           ;int32_t i = 0;
    ;改变顺序 方便输出
    .while ecx < 4                                        ;while (i < 4)
    mov eax,[esi+ecx*4]                                   ;uint32_t t = lp[i];
    xchg ah,al                                ;t = HIWORD(t) | (HIBYTE((uint16_t)t)>>8) | (LOBYTE((uint16_t)t)<<8);
    rol eax,16d                                           ;ROL(t, sizeof(t), 16);
    xchg al,ah                                ;t = HIWORD(t) | (HIBYTE((uint16_t)t)>>8) | (LOBYTE((uint16_t)t)<<8);
    mov [esi+ecx*4],eax                                   ;lp[i] = t;
    ;int 3h                                               ;assert(0);
    inc ecx                                               ;i++;
    .endw

    invoke wsprintf,offset lpszBuffer,CTXT('%08x%08x%08x%08x'),\
        DWORD ptr [esi],DWORD ptr [esi+4h],DWORD ptr [esi+8h],DWORD ptr [esi+0ch]
                                                       ;wsprintf(lpszBuffer, MD5_FORMAT, lp[0], lp[4], lp[8], lp[12]);
    invoke StdOut,offset lpszBuffer                       ;wputs(lpszBuffer);

    ;暂停显示,回车键关闭
    invoke StdIn,offset lpszBuffer,sizeof lpszBuffer      ;fread(lpszBuffer, sizeof(uint16_t), lstrlen(lpszBuffer), stdin);
    invoke ExitProcess,0                                  ;exit(0);
   
end START

md5.asm

.code

_MD5hash proc    uses ebx edi esi,_lpBuffer:DWORD,_dwBufferLength:DWORD,_lpMD5Result:DWORD
;int32_t __stdcall _MD5hash(lpvoid _lpBuffer, int32_t _dwBufferLength, lpvoid _lpMD5Result);
    local @dwA:DWORD,@dwB:DWORD,@dwC:DWORD,@dwD:DWORD     ;uint32_t dwArray[4];
    local @lpBuf:DWORD                                    ;lpvoid lpBuf;

    mov    ecx, _dwBufferLength                           ;int32_t size = _dwBufferLength;
    add    ecx, 128d    ;分配足够大的  保证够用           ;size += 0x80;
    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,ecx    ;貌似这样和平台相关
    .if    eax
        mov    @lpBuf, eax                       ;if (lpBuf = c_malloc(size)); c_malloc is ARCHLESS.
    .else
        dec    eax    ;出错返回 -1
        ret                                      ;else return (uint32_t)(-1);
    .endif
    ;int   3h                                    ;assert(0);
    mov    edi, eax
    mov    esi, _lpBuffer
    mov    ecx, _dwBufferLength
    shr    ecx, 2
    rep    movsd                                 ;memcpy_d((uint32_t*)lpBuf, (uint32_t*)_lpBuffer,
                                                 ;_dwBufferLength / sizeof(uint32_t)); 
    mov    ecx, _dwBufferLength
    and    ecx, 11b
    rep    movsb                                 ;memcpy((lpvoid)(lpBuf + len), (lpvoid) 
                                                 ;(_lpBuffer + _dwBufferLength), ALIGN_2N(sizeof(uint32_t)));
    mov    edi, eax
    mov    eax, _dwBufferLength
    inc    eax
    add    edi, eax                               ;uint8_t *lp = lpBuf + _dwBufferLength + 1;
    mov    BYTE ptr [edi-1], 080h                 ;lp[-1] = 0x80;
    mov    edx, eax
    and    edx, 111111b                           ;size = (_dwBufferLength + 1) & ALIGN_2N(2^6);
    neg    edx                                    ;size = (~offset + 1) | (offset >> (8*sizeof(int32_t) - 1));
    add    edx, 40h                               ;size += 0x40;
    cmp    edx, 8h
    jae    @f                                     ;if (size >= 8) goto @@; better instruction: jge @f
    add    edx, 40h                               ;else size += 0x40;
@@:
    mov    ecx, edx
    shr    ecx, 2
    xor    eax, eax
    rep    stosd                                  ;memset_d((uint32_t*)lp, 0, (size / sizeof(uint32_t)));
    mov    ecx, edx                           
    and    ecx, 11b
    rep    stosb                                  ;memset((lpvoid)(lp + size), 0, ALIGN_2N(sizeof(uint32_t)));
    mov    eax, _dwBufferLength
    inc    edx               
    add    _dwBufferLength, edx                   ;_dwBufferLength += (++size);
    xor    edx, edx
    shl    eax,3
    mov    DWORD  ptr [edi-8], eax                ;(uint32_t)lp[-8] = _dwBufferLength / 8;
    mov    DWORD  ptr [edi-4], edx                ;(uint32_t)lp[-4] = 0;
    mov    edi, @lpBuf                            ;lpvoid plp = lpBuf;
    mov    eax, 067452301h                        ;const uint32_t MD5_A = 0x67452301;
    mov    ebx, 0efcdab89h                        ;const uint32_t MD5_B = 0xefcdab89;
    mov    ecx, 098badcfeh                        ;const uint32_t MD5_C = 0x98badcfe;
    mov    edx, 010325476h                        ;const uint32_t MD5_D = 0x10325476;

hashloop:                                                     ;Iterative calculation

    mov    @dwA, eax                                          ;dwArray[0] = MD5_A;
    mov    @dwB, ebx                                          ;dwArray[1] = MD5_B;
    mov    @dwC, ecx                                          ;dwArray[2] = MD5_C;
    mov    @dwD, edx                                          ;dwArray[3] = MD5_D;

    push   ebp                                                ;uint32_t s;
    mov    esi, ebx                           
    and    esi, ecx                                           ;uint32_t t = dwArray[1] & dwArray[2];
    mov    ebp, ebx                                           ;s = dwArray[1];
    not    ebp                                                ;s = ~s;
    and    ebp, edx                                           ;s &= dwArray[3];
    or     esi, ebp                                           ;t |= s;
    lea    esi, DWORD ptr ds:[eax+esi+0D76AA478H]             ;t = dwArray[0] + t + 0xd76aa478;
    add    esi, DWORD ptr ds:[edi]                            ;t += *(uint32_t*)plp;
    rol    esi, 7                                             ;ROL(t, sizeof(uint32_t), 7);
    add    esi, ebx                                           ;t += dwArray[1];
    mov    eax, esi                                           ;uint32_t t1 = t;
    mov    esi, eax                                           ;t = dwArray[0];
    and    esi, ebx                                           ;t &= dwArray[1];
    mov    ebp, eax                                           ;s = t1;
    not    ebp                                                ;s = ~s;
    and    ebp, ecx                                           ;s &= dwArray[2];
    or     esi, ebp                                           ;t |= s;
    lea    esi, DWORD ptr ds:[edx+esi+0E8C7B756H]
    add    esi, DWORD ptr ds:[edi+4H]
    rol    esi, 0CH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, eax
    mov    ebp, edx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0242070DBH]
    add    esi, DWORD ptr ds:[edi+8H]
    rol    esi, 11H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, edx
    mov    ebp, ecx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+0C1BDCEEEH]
    add    esi, DWORD ptr ds:[edi+0CH]
    rol    esi, 16H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, ecx
    mov    ebp, ebx
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+0F57C0FAFH]
    add    esi, DWORD ptr ds:[edi+10H]
    rol    esi, 7H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ebx
    mov    ebp, eax
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+04787C62AH]
    add    esi, DWORD ptr ds:[edi+14H]
    rol    esi, 0CH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, eax
    mov    ebp, edx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0A8304613H]
    add    esi, DWORD ptr ds:[edi+18H]
    rol    esi, 11H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, edx
    mov    ebp, ecx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+0FD469501H]
    add    esi, DWORD ptr ds:[edi+1CH]
    rol    esi, 16H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, ecx
    mov    ebp, ebx
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+0698098D8H]
    add    esi, DWORD ptr ds:[edi+20H]
    rol    esi, 7
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ebx
    mov    ebp, eax
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+8B44F7AFH]
    add    esi, DWORD ptr ds:[edi+24H]
    rol    esi, 0CH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, eax
    mov    ebp, edx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0FFFF5BB1H]
    add    esi, DWORD ptr ds:[edi+28H]
    rol    esi, 11H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, edx
    mov    ebp, ecx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+895CD7BEH]
    add    esi, DWORD ptr ds:[edi+2CH]
    rol    esi, 16H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, ecx
    mov    ebp, ebx
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+06B901122H]
    add    esi, DWORD ptr ds:[edi+30H]
    rol    esi, 7H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ebx
    mov    ebp, eax
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+0FD987193H]
    add    esi, DWORD ptr ds:[edi+34H]
    rol    esi, 0CH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, eax
    mov    ebp, edx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0A679438EH]
    add    esi, DWORD ptr ds:[edi+38H]
    rol    esi, 11H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, edx
    mov    ebp, ecx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+049B40821H]
    add    esi, DWORD ptr ds:[edi+3CH]
    rol    esi, 16H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, edx
    mov    ebp, edx
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+0F61E2562H]
    add    esi, DWORD ptr ds:[edi+4H]
    rol    esi, 5H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ecx
    mov    ebp, ecx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+0C040B340H]
    add    esi, DWORD ptr ds:[edi+18H]
    rol    esi, 9H
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, ebx
    mov    ebp, ebx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0265E5A51H]
    add    esi, DWORD ptr ds:[edi+2CH]
    rol    esi, 0EH
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, eax
    mov    ebp, eax
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+0E9B6C7AAH]
    add    esi, DWORD ptr ds:[edi]
    rol    esi, 14H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, edx
    mov    ebp, edx
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+0D62F105DH]
    add    esi, DWORD ptr ds:[edi+14H]
    rol    esi, 5
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ecx
    mov    ebp, ecx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+02441453H]
    add    esi, DWORD ptr ds:[edi+28H]
    rol    esi, 9H
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, ebx
    mov    ebp, ebx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0D8A1E681H]
    add    esi, DWORD ptr ds:[edi+3CH]
    rol    esi, 0EH
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, eax
    mov    ebp, eax
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+0E7D3FBC8H]
    add    esi, DWORD ptr ds:[edi+10H]
    rol    esi, 14H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, edx
    mov    ebp, edx
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+21E1CDE6H]
    add    esi, DWORD ptr ds:[edi+24H]
    rol    esi, 5H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ecx
    mov    ebp, ecx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+0C33707D6H]
    add    esi, DWORD ptr ds:[edi+38H]
    rol    esi, 9H
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, ebx
    mov    ebp, ebx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+0F4D50D87H]
    add    esi, DWORD ptr ds:[edi+0CH]
    rol    esi, 0EH
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, eax
    mov    ebp, eax
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+455A14EDH]
    add    esi, DWORD ptr ds:[edi+20H]
    rol    esi, 14H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    and    esi, edx
    mov    ebp, edx
    not    ebp
    and    ebp, ecx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[eax+esi+0A9E3E905H]
    add    esi, DWORD ptr ds:[edi+34H]
    rol    esi, 5H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    and    esi, ecx
    mov    ebp, ecx
    not    ebp
    and    ebp, ebx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[edx+esi+0FCEFA3F8H]
    add    esi, DWORD ptr ds:[edi+8H]
    rol    esi, 9H
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    and    esi, ebx
    mov    ebp, ebx
    not    ebp
    and    ebp, eax
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ecx+esi+676F02D9H]
    add    esi, DWORD ptr ds:[edi+1CH]
    rol    esi, 0EH
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    and    esi, eax
    mov    ebp, eax
    not    ebp
    and    ebp, edx
    or     esi, ebp
    lea    esi, DWORD ptr ds:[ebx+esi+8D2A4C8AH]
    add    esi, DWORD ptr ds:[edi+30H]
    rol    esi, 14H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    xor    esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[eax+esi+0FFFA3942H]
    add    esi, DWORD ptr ds:[edi+14H]
    rol    esi, 4
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    xor    esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[edx+esi+8771F681H]
    add    esi, DWORD ptr ds:[edi+20H]
    rol    esi, 0BH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    xor    esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[ecx+esi+6D9D6122H]
    add    esi, DWORD ptr ds:[edi+2CH]
    rol    esi, 10H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    xor    esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ebx+esi+0FDE5380CH]
    add    esi, DWORD ptr ds:[edi+38H]
    rol    esi, 17H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    xor    esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[eax+esi+0A4BEEA44H]
    add    esi, DWORD ptr ds:[edi+4H]
    rol    esi, 4
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    xor    esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[edx+esi+04BDECFA9H]
    add    esi, DWORD ptr ds:[edi+10H]
    rol    esi, 0BH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    xor    esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[ecx+esi+0F6BB4B60H]
    add    esi, DWORD ptr ds:[edi+1CH]
    rol    esi, 10H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    xor    esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ebx+esi+0BEBFBC70H]
    add    esi, DWORD ptr ds:[edi+28H]
    rol    esi, 17H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    xor    esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[eax+esi+289B7EC6H]
    add    esi, DWORD ptr ds:[edi+34H]
    rol    esi, 4H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    xor    esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[edx+esi+0EAA127FAH]
    add    esi, DWORD ptr ds:[edi]
    rol    esi, 0BH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    xor    esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[ecx+esi+0D4EF3085H]
    add    esi, DWORD ptr ds:[edi+0CH]
    rol    esi, 10H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    xor    esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ebx+esi+4881D05H]
    add    esi, DWORD ptr ds:[edi+18H]
    rol    esi, 17H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, ebx
    xor    esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[eax+esi+0D9D4D039H]
    add    esi, DWORD ptr ds:[edi+24H]
    rol    esi, 4H
    add    esi, ebx
    mov    eax, esi
    mov    esi, eax
    xor    esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[edx+esi+0E6DB99E5H]
    add    esi, DWORD ptr ds:[edi+30H]
    rol    esi, 0BH
    add    esi, eax
    mov    edx, esi
    mov    esi, edx
    xor    esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[ecx+esi+1FA27CF8H]
    add    esi, DWORD ptr ds:[edi+3CH]
    rol    esi, 10H
    add    esi, edx
    mov    ecx, esi
    mov    esi, ecx
    xor    esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ebx+esi+0C4AC5665H]
    add    esi, DWORD ptr ds:[edi+8]
    rol    esi, 17H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, edx
    not    esi
    or     esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[eax+esi+0F4292244H]
    add    esi, DWORD ptr ds:[edi]
    rol    esi, 6H
    add    esi, ebx
    mov    eax, esi
    mov    esi, ecx
    not    esi
    or     esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[edx+esi+432AFF97H]
    add    esi, DWORD ptr ds:[edi+1CH]
    rol    esi, 0AH
    add    esi, eax
    mov    edx, esi
    mov    esi, ebx
    not    esi
    or     esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ecx+esi+0AB9423A7H]
    add    esi, DWORD ptr ds:[edi+38H]
    rol    esi, 0FH
    add    esi, edx
    mov    ecx, esi
    mov    esi, eax
    not    esi
    or     esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[ebx+esi+0FC93A039H]
    add    esi, DWORD ptr ds:[edi+14H]
    rol    esi, 15H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, edx
    not    esi
    or     esi, ebx
    xor    esi, ecx
    lea    esi, DWORD    ptr ds:[eax+esi+655B59C3H]
    add    esi, DWORD    ptr ds:[edi+30H]
    rol    esi, 6H
    add    esi, ebx
    mov    eax, esi
    mov    esi, ecx
    not    esi
    or     esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[edx+esi+8F0CCC92H]
    add    esi, DWORD ptr ds:[edi+0CH]
    rol    esi, 0AH
    add    esi, eax
    mov    edx, esi
    mov    esi, ebx
    not    esi
    or     esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ecx+esi+0FFEFF47DH]
    add    esi, DWORD ptr ds:[edi+28H]
    rol    esi, 0FH
    add    esi, edx
    mov    ecx, esi
    mov    esi, eax
    not    esi
    or     esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[ebx+esi+85845DD1H]
    add    esi, DWORD ptr ds:[edi+4H]
    rol    esi, 15H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, edx
    not    esi
    or     esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[eax+esi+6FA87E4FH]
    add    esi, DWORD ptr ds:[edi+20H]
    rol    esi, 6H
    add    esi, ebx
    mov    eax, esi
    mov    esi, ecx
    not    esi
    or     esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[edx+esi+0FE2CE6E0H]
    add    esi, DWORD ptr ds:[edi+3CH]
    rol    esi, 0AH
    add    esi, eax
    mov    edx, esi
    mov    esi, ebx
    not    esi
    or     esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ecx+esi+0A3014314H]
    add    esi, DWORD ptr ds:[edi+18H]
    rol    esi, 0FH
    add    esi, edx
    mov    ecx, esi
    mov    esi, eax
    not    esi
    or     esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[ebx+esi+4E0811A1H]
    add    esi, DWORD ptr ds:[edi+34H]
    rol    esi, 15H
    add    esi, ecx
    mov    ebx, esi
    mov    esi, edx
    not    esi
    or     esi, ebx
    xor    esi, ecx
    lea    esi, DWORD ptr ds:[eax+esi+0F7537E82H]
    add    esi, DWORD ptr ds:[edi+10H]
    rol    esi, 6H
    add    esi, ebx
    mov    eax, esi
    mov    esi, ecx
    not    esi
    or     esi, eax
    xor    esi, ebx
    lea    esi, DWORD ptr ds:[edx+esi+0BD3AF235H]
    add    esi, DWORD ptr ds:[edi+2CH]
    rol    esi, 0AH
    add    esi, eax
    mov    edx, esi
    mov    esi, ebx
    not    esi
    or     esi, edx
    xor    esi, eax
    lea    esi, DWORD ptr ds:[ecx+esi+02AD7D2BBH]
    add    esi, DWORD ptr ds:[edi+8H]
    rol    esi, 0FH
    add    esi, edx
    mov    ecx, esi
    mov    esi, eax
    not    esi
    or     esi, ecx
    xor    esi, edx
    lea    esi, DWORD ptr ds:[ebx+esi+0EB86D391H]
    add    esi, DWORD ptr ds:[edi+24H]
    rol    esi, 15H
    add    esi, ecx
    mov    ebx, esi
    pop    ebp

    add    eax, @dwA
    add    ebx, @dwB
    add    ecx, @dwC
    add    edx, @dwD

    add    edi,40h                           
    sub    _dwBufferLength,40h                    ;_dwBufferLength -= 0x40;                       
    jnz    hashloop                               ;if (_dwBufferLength) goto hashloop
    ;int    3h                                    ;assert(0);
    mov    esi, _lpMD5Result
    mov    [esi], eax                             ;*(uint32_t*)_lpMD5Result = EAX;
    mov    [esi+4h], ebx                          ;*(uint32_t*)(_lpMD5Result+4)  = EBX;
    mov    [esi+8h], ecx                          ;*(uint32_t*)(_lpMD5Result+8)  = ECX;
    mov    [esi+0Ch], edx                         ;*(uint32_t*)(_lpMD5Result+12) = EDX;
    invoke GlobalFree, @lpBuf                     ;c_free(lpBuf);
    ret                                           ;return;
_MD5hash   endp

简单评论:MD5迭代计算的重复代码就不写了,感兴趣的童鞋可以网上找MD5的spec来看,挺好的win32学习代码
搜索更多相关主题的帖子: 精华 
2011-11-29 11:21
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:100 
nice

经验积累中............
2011-11-29 13:28
快速回复:精华区代码Revision-C版本[系列五]
数据加载中...
 
   



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

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