能力值:
( LV12,RANK:450 )
8 楼
WinRAR 3.62注册算法 - 黑名单 [声明] 本文为逆向学习参考文章, 若使用 winrar 请向作者注册.
2. 注册码黑名单
回到上回跳过的黑名单部分:
.text:0040E7D8 loc_40E7D8: ; CODE XREF: check_regdata+10Bj
.text:0040E7D8 xor ebx, ebx
.text:0040E7DA NEXT_BLACK: ; CODE XREF: check_regdata+159j
.text:0040E7DA mov eax, ebx
.text:0040E7DC lea edx, [esp+0E88h+black_string]
.text:0040E7E3 shl eax, 3
.text:0040E7E6 mov ecx, 8 ; 单个black的长度
.text:0040E7EB add eax, offset g_blacklist ; 一个全局的黑名单列表
.text:0040E7F1 call getOneBlack ; 从黑名单中取8个字节, 按16进制转化为字符串black_string
.text:0040E7F1
.text:0040E7F6 lea edx, [esp+0E88h+black_string] ; lpString2
.text:0040E7FD lea eax, [esp+0E88h+strTemp+0Ah] ; lpString1
.text:0040E801 mov ecx, 8 ; cchCount2
.text:0040E806 call rar_strncmp
.text:0040E80B test eax, eax ; [Check3] 检查 snCode1[注册字符串1] 前8位是否在黑名
; 单中,在黑名单注册失败!
.text:0040E80D jnz short NO_BLACK
.text:0040E80F xor eax, eax
.text:0040E811 jmp REG_FAIL_EXIT
.text:0040E816 NO_BLACK: ; CODE XREF: check_regdata+149j
.text:0040E816 inc ebx
.text:0040E817 cmp ebx, 9Dh ; 157(0x9D)个黑名单, 每个黑名单占8个字节,那么
; g_blacklist总共占157*8=1256个字节
.text:0040E81D jl short NEXT_BLACK void __fastcall getOneBlack(BYTE *black,char *black_string,int len=8)
{
for (; len>0; len--)
{
sprintf(black_string, "%02x", *black++);
black_string += 2;
}
}
int __fastcall rar_strncmp(LPCSTR lpString1,LPCSTR lpString2,int cCount)
{
return CompareString(LOCALE_USER_DEFAULT,
NORM_IGNORECASE|SORT_STRINGSORT,
lpString1,
cCount,
lpString2,
cCount) - CSTR_EQUAL;
}
getOneBlack 函数很简单在这里就是每次取8个字节, 按16进制转化为字符串black_string,
然后又调用 rar_strncmp对字符串进行比较, 这里用到了strTemp+10, 看上一篇可知
strTemp存储的是:
6412212250eb294bd5b605e535f7334b6e2e56a9e405a044f60225
c843a161a156aa01684c6035c6ab9048e2c5c62f0238f183d28519
aa87488bf38f5b634cf28190bdf438ac593b1857cdb55a7fcb0eb0
c3e4c2736090b3dfa45384e08e9de05c5860ae8049eaa9443b44f9
faac06b7ced5f95ab06b40a99e850616dc92fc5301fe63c674ea55
3971fefd9e10f300d2a515c74b02f673b7fe5a89fa92f51260a5af
78a306093f5763d6acc779488f5d42e9b044836a837c0424153795
那么跳过10个字节后就是snCode1, 然后调用rar_strncmp比较snCode1的前8位和黑名单返回
16位字符串的前8位, 返回0表示相等也就注册失败了.
看一下黑名单都有那些:
.data:004A012C g_blacklist db 6Ch, 4, 0Ch, 9Dh, 3Bh, 41h, 9Ah, 18h; 0
.data:004A012C db 1Dh, 29h, 3Eh,0D1h, 42h,0AFh, 12h, 2Bh; 8
.data:004A012C db 9,0B6h,0C1h,0A2h,0F4h, 7,0C7h, 75h; 16
.data:004A012C db 0C4h, 7Fh,0A7h,0D1h, 85h,0A5h,0DAh,0FCh; 24
.data:004A012C db 0A2h,0BAh, 6Ch,0FDh, 60h,0D8h, 69h, 0Eh; 32
.data:004A012C db 89h, 14h,0D2h,0EAh, 34h, 56h, 8Bh, 68h; 40
.data:004A012C db 30h,0FEh,0C8h, 17h, 6,0E2h, 5Ch,0B1h; 48
.data:004A012C db 39h, 74h, 75h, 40h, 4Bh, 56h, 6Bh,0C2h; 56
.data:004A012C db 71h, 26h,0B3h, 24h, 0Fh,0D7h, 5,0ACh; 64
.data:004A012C db 0F8h,0EFh, 97h, 1Ch,0D3h,0A6h, 8Eh,0BDh; 72
.data:004A012C db 10h, 56h,0F5h, 60h, 6, 53h, 4Bh,0C8h; 80
.data:004A012C db 68h, 26h, 54h, 92h, 31h, 68h, 18h, 85h; 88
.data:004A012C db 6Dh, 1, 5Dh, 59h, 82h,0D4h,0E1h,0B6h; 96
.data:004A012C db 0F9h,0C2h,0AAh, 70h, 17h, 24h, 82h, 9Ah; 104
.data:004A012C db 48h, 6Ch, 45h,0ABh, 74h, 3Dh, 84h,0E0h; 112
.data:004A012C db 7, 47h, 65h,0F3h,0F7h, 37h,0AFh,0B1h; 120
.data:004A012C db 0ABh,0FDh, 70h, 24h, 64h,0FEh, 55h, 22h; 128
.data:004A012C db 33h,0D0h,0FAh, 0Eh, 3Fh, 3Dh,0A1h, 74h; 136
.data:004A012C db 25h, 96h, 8Fh, 67h,0A2h, 6Dh, 9Dh, 4Ah; 144
.data:004A012C db 62h, 2Ah, 23h, 47h, 78h, 5Bh, 1Ch, 71h; 152
.data:004A012C db 51h, 0Ah,0FCh, 94h,0E2h, 6Dh, 74h,0EAh; 160
.data:004A012C db 0C6h, 4, 8Ah, 7Ah, 32h, 8Eh, 3Eh, 67h; 168
.data:004A012C db 0Fh, 3Eh, 35h,0CAh,0DEh,0B1h, 4Eh,0D6h; 176
.data:004A012C db 0E1h, 76h,0D4h,0B2h,0BBh, 99h, 69h,0AAh; 184
.data:004A012C db 99h, 8Eh, 5Fh,0B5h, 5, 2Eh,0A4h, 55h; 192
.data:004A012C db 6Fh,0C6h, 58h, 39h, 34h,0A1h,0FDh,0EAh; 200
.data:004A012C db 34h, 99h, 0Bh,0F0h, 3Eh, 2Ch, 1Eh, 7; 208
.data:004A012C db 1Dh, 89h, 82h,0BAh,0F0h,0DDh, 2Bh,0BBh; 216
.data:004A012C db 0ADh, 0Dh, 2Bh, 61h, 9Eh, 40h, 28h, 95h; 224
.data:004A012C db 95h, 51h, 20h,0F3h,0F5h, 39h, 40h,0D8h; 232
.data:004A012C db 0D1h,0A1h, 18h,0E3h, 84h,0AEh, 19h, 96h; 240
.data:004A012C db 0F1h, 17h, 3Eh,0EAh, 71h, 5Ah, 4,0D1h; 248
.data:004A012C db 7Ah, 2, 7Dh,0AAh, 8Eh,0EAh, 3Dh,0EEh; 256
.data:004A012C db 0A8h, 0, 3Ah, 7Dh,0F5h, 30h, 99h,0B9h; 264
.data:004A012C db 0AFh, 67h, 46h,0CEh, 78h, 0Eh, 38h, 1Eh; 272
.data:004A012C db 0C5h,0CDh, 3Ch, 5Fh, 65h, 96h, 96h,0F8h; 280
.data:004A012C db 46h, 30h, 23h, 79h,0AFh, 0, 29h, 4Ch; 288
.data:004A012C db 9Dh,0D5h,0A1h, 81h, 26h,0FAh, 74h, 27h; 296
.data:004A012C db 71h,0FAh,0A9h,0A9h,0A3h, 64h,0A1h, 66h; 304
.data:004A012C db 62h,0D4h, 96h, 95h, 13h, 36h,0D3h, 37h; 312
.data:004A012C db 2Ah, 8Bh, 50h, 7Ah, 41h,0B9h,0A8h,0A5h; 320
.data:004A012C db 0E3h, 40h,0AAh,0EDh,0FBh,0B2h,0ABh, 68h; 328
.data:004A012C db 0BEh, 80h, 9Fh, 38h, 4, 9Eh,0D3h,0BFh; 336
.data:004A012C db 86h, 78h, 9Ch, 3Ah, 9Eh,0E7h,0C7h,0F2h; 344
.data:004A012C db 6Ch, 99h,0F6h, 90h,0A7h,0F4h, 0,0B2h; 352
.data:004A012C db 57h, 70h,0AEh, 56h, 8Ch,0B9h,0C6h, 5Eh; 360
.data:004A012C db 0D4h, 29h, 63h, 39h, 2, 0Fh, 5Ch,0DAh; 368
.data:004A012C db 0AEh, 3Dh, 2Ah, 72h,0F9h,0EDh,0E8h,0B1h; 376
.data:004A012C db 0B8h,0C4h,0CCh,0FAh, 89h,0EEh, 80h,0D7h; 384
.data:004A012C db 0BEh, 2Dh,0E6h, 78h, 3Ch,0CDh, 64h, 28h; 392
.data:004A012C db 9Fh, 1Ch, 69h,0E8h, 62h, 6Dh, 32h, 2Bh; 400
.data:004A012C db 0B0h, 20h, 80h, 6Fh,0D3h, 16h, 51h, 87h; 408
.data:004A012C db 12h, 8Ah,0EBh, 39h,0FFh,0C5h, 30h, 9Bh; 416
.data:004A012C db 0Eh, 50h, 40h,0C2h,0CFh,0EDh,0DDh,0F4h; 424
.data:004A012C db 0D9h, 83h, 32h, 45h, 0Ch,0CAh,0D8h,0F7h; 432
.data:004A012C db 0CEh,0D0h, 9, 79h, 33h,0B6h, 26h, 7Ch; 440
.data:004A012C db 0DCh,0C0h, 1Eh, 50h, 67h, 83h, 33h,0FDh; 448
.data:004A012C db 0B8h, 2, 84h, 8Bh, 5Fh, 9,0B0h, 33h; 456
.data:004A012C db 0D2h, 8,0D0h, 5, 6, 90h, 3, 5Fh; 464
.data:004A012C db 48h, 60h,0A4h, 8Dh, 73h,0F3h,0A8h, 8Fh; 472
.data:004A012C db 0ACh, 4Ch,0FEh, 7Eh, 29h,0A9h, 44h,0E0h; 480
.data:004A012C db 0B4h, 9Dh, 3Eh, 65h,0DBh,0B7h,0F4h,0C9h; 488
.data:004A012C db 26h, 1Ah, 96h,0A0h,0C0h, 0Eh,0D3h,0B7h; 496
.data:004A012C db 57h, 6Dh,0B0h, 3Ch, 64h, 9Ah,0C9h,0E6h; 504
.data:004A012C db 0EDh, 90h, 97h, 8Eh,0DEh, 78h, 43h,0E9h; 512
.data:004A012C db 0ABh,0E5h,0D1h,0BDh,0D1h, 5Ch, 68h,0A4h; 520
.data:004A012C db 0B5h,0F9h, 65h, 4Eh,0DDh,0A8h, 70h,0CDh; 528
.data:004A012C db 0CFh, 10h, 2Bh,0E6h,0F4h, 3Dh, 0Dh, 3Ah; 536
.data:004A012C db 3Fh,0C8h, 3Dh, 7Ah, 5Dh,0FBh,0EDh, 3Ah; 544
.data:004A012C db 0D3h,0BAh,0DDh, 9, 1Ah,0F6h, 1Ah, 8Bh; 552
.data:004A012C db 6Eh,0DBh,0D7h, 9,0EFh, 34h,0EBh, 50h; 560
.data:004A012C db 0E0h,0EEh, 2Eh,0A8h,0A2h, 28h, 10h,0ABh; 568
.data:004A012C db 2Fh, 6Bh,0D1h,0EBh, 53h, 5, 87h,0DEh; 576
.data:004A012C db 41h,0FCh, 1Eh, 11h, 0Fh, 42h, 6, 26h; 584
.data:004A012C db 89h, 0Ah,0FDh,0BBh, 5Ah, 52h, 41h,0F7h; 592
.data:004A012C db 3Eh, 10h, 7Dh, 70h, 5Ah, 40h, 87h,0C2h; 600
.data:004A012C db 0BFh, 7Ch, 7Eh,0A6h, 7Ah, 1Eh,0B1h, 3Dh; 608
.data:004A012C db 0FBh,0C5h, 2Dh,0F7h, 5Fh, 86h,0C8h, 0Ah; 616
.data:004A012C db 0FBh, 2Ah, 1,0C2h,0E5h, 10h,0F7h,0F2h; 624
.data:004A012C db 0B4h, 62h,0F9h,0FCh,0A3h,0FDh,0BBh, 0Eh; 632
.data:004A012C db 9Fh,0C9h,0BFh,0E9h,0C5h,0AAh, 3Dh,0EDh; 640
.data:004A012C db 2Ah,0C8h,0C2h, 62h,0F0h, 3Dh, 73h,0A0h; 648
.data:004A012C db 0D3h, 23h, 1Bh,0BDh, 75h,0E7h, 9,0E1h; 656
.data:004A012C db 0EBh, 29h, 4Bh,0D5h,0B6h, 5,0E5h, 35h; 664
.data:004A012C db 19h, 29h, 28h,0EBh,0A6h,0DCh,0ADh, 50h; 672
.data:004A012C db 2Fh, 1Dh, 6, 84h, 42h, 52h,0D9h, 9Eh; 680
.data:004A012C db 93h,0DBh, 47h, 15h, 41h,0A6h, 0, 83h; 688
.data:004A012C db 23h, 8Ah, 8, 3Ch,0CEh, 1, 81h, 85h; 696
.data:004A012C db 0C3h,0B2h, 63h,0A4h, 7Dh,0ABh,0CDh, 7Ah; 704
.data:004A012C db 4Fh, 16h, 9Ah, 6Eh, 4Dh,0F0h,0CAh,0FEh; 712
.data:004A012C db 85h, 48h, 4Bh, 1Dh,0BFh, 76h, 9Ch, 5Ch; 720
.data:004A012C db 9Bh, 54h,0A6h,0B0h,0B7h,0F9h, 64h, 89h; 728
.data:004A012C db 1,0C2h, 21h,0A2h,0DDh, 6Ah,0F1h, 61h; 736
.data:004A012C db 0A2h, 5, 95h,0FCh,0B5h, 5,0A9h, 10h; 744
.data:004A012C db 66h, 62h,0ADh,0EEh, 1Eh,0A0h, 2Dh, 7Eh; 752
.data:004A012C db 0ECh,0D4h, 5Dh, 27h,0F6h, 88h,0A2h, 79h; 760
.data:004A012C db 0F2h,0FCh, 56h, 79h, 89h, 4Fh,0C4h,0E9h; 768
.data:004A012C db 28h, 32h,0F1h, 4Ch, 8,0E5h,0D3h, 8Ah; 776
.data:004A012C db 0C3h, 0Fh, 7,0FBh, 7Bh, 2Ch,0E5h, 9; 784
.data:004A012C db 59h, 69h,0EBh,0F2h, 23h, 4Bh,0F5h,0FEh; 792
.data:004A012C db 17h,0F7h, 47h,0C0h, 2Fh,0A1h, 56h, 74h; 800
.data:004A012C db 88h, 76h, 90h, 58h,0BBh, 5Ah,0D1h,0F0h; 808
.data:004A012C db 1Bh, 65h, 80h,0A4h,0E4h, 12h,0EBh, 32h; 816
.data:004A012C db 3Ah,0ECh, 99h,0E6h, 3Ah, 8Eh, 8Ch,0E0h; 824
.data:004A012C db 0C0h, 2Bh,0C6h, 6Bh, 62h, 52h, 0Ch,0AAh; 832
.data:004A012C db 0ECh,0CDh, 6Bh,0E3h,0B2h,0CFh, 57h, 26h; 840
.data:004A012C db 8Fh, 77h,0E4h,0C7h, 29h, 35h, 55h,0ECh; 848
.data:004A012C db 68h, 26h,0AEh, 8Fh,0D2h, 67h, 3Ah,0F1h; 856
.data:004A012C db 8Fh, 3Dh, 0Ah,0E0h, 9Ch, 83h, 41h, 2Dh; 864
.data:004A012C db 0E9h,0A8h, 60h, 67h, 5Fh,0CFh, 80h, 51h; 872
.data:004A012C db 33h,0B0h, 57h, 11h,0CEh, 1Fh,0EFh, 19h; 880
.data:004A012C db 0, 79h,0A8h, 72h, 57h, 5Ch, 90h, 6; 888
.data:004A012C db 0BDh, 6,0E6h,0F4h, 7, 6Ah,0DCh, 1Dh; 896
.data:004A012C db 69h, 95h, 0Eh, 52h,0E1h, 4,0D7h, 1Bh; 904
.data:004A012C db 0D4h, 38h,0CDh,0DFh, 1,0CFh,0F3h, 68h; 912
.data:004A012C db 0C9h, 13h, 40h, 8Ch, 8Eh, 6,0FEh,0D3h; 920
.data:004A012C db 7Bh,0ADh, 2Ah, 97h, 56h,0ADh, 8, 53h; 928
.data:004A012C db 0C2h,0B7h, 81h, 7Bh, 26h, 23h, 9Dh, 54h; 936
.data:004A012C db 0A1h,0A3h,0E5h,0C6h, 8Eh, 67h,0F1h, 96h; 944
.data:004A012C db 81h, 0Bh, 68h,0E8h, 54h, 66h, 0Bh, 7Ah; 952
.data:004A012C db 32h, 57h, 8Eh, 7Eh,0E8h, 0Eh, 8Ah, 7Ch; 960
.data:004A012C db 3, 53h,0D5h,0CEh,0F4h, 3, 8Bh, 91h; 968
.data:004A012C db 0FEh,0DFh, 1Ah, 8Eh, 7Fh, 1Eh,0F0h, 75h; 976
.data:004A012C db 11h, 8,0E2h, 23h, 74h, 97h, 3, 9Ch; 984
.data:004A012C db 80h,0DEh, 79h,0D5h,0B0h, 2Ch, 5Ch, 0Eh; 992
.data:004A012C db 15h, 5Bh, 33h,0D5h,0F4h,0ADh, 70h,0C2h; 1000
.data:004A012C db 9Bh,0C1h, 86h,0F1h, 4Eh,0EFh, 3Dh, 65h; 1008
.data:004A012C db 2, 81h,0ACh,0B4h,0E9h, 25h,0B6h, 35h; 1016
.data:004A012C db 1Dh, 7Eh, 16h,0C4h, 5,0F0h, 0Bh,0D2h; 1024
.data:004A012C db 0F8h, 3Eh, 9Fh, 2Dh, 43h, 9Ch, 66h,0C5h; 1032
.data:004A012C db 2Bh,0FDh, 23h,0FEh,0C7h, 72h,0F7h,0E0h; 1040
.data:004A012C db 64h, 10h, 34h, 8Ch,0B3h,0FFh, 4Dh, 3Dh; 1048
.data:004A012C db 52h,0C8h, 4Ah, 82h,0E5h,0B0h, 7Fh, 93h; 1056
.data:004A012C db 0F2h,0EEh,0CEh,0B0h, 67h,0CBh, 6Fh,0D1h; 1064
.data:004A012C db 0Eh,0AAh, 43h,0C4h, 19h, 56h, 9Dh, 15h; 1072
.data:004A012C db 0B8h,0BFh,0ACh, 1, 80h, 8Ch, 30h, 2Bh; 1080
.data:004A012C db 95h,0D8h, 6Ah,0A5h, 5Dh, 9Ah,0BEh, 48h; 1088
.data:004A012C db 6Bh,0CDh,0C6h, 6Bh,0D0h,0C3h,0DDh,0FAh; 1096
.data:004A012C db 6Fh, 47h,0AFh,0A0h,0F5h, 25h,0DFh, 98h; 1104
.data:004A012C db 0D3h, 17h,0D5h,0EAh, 5Ah, 69h,0EAh, 59h; 1112
.data:004A012C db 0CCh,0FAh,0D0h,0FBh,0F1h, 3Eh,0ACh, 1Eh; 1120
.data:004A012C db 3Ah, 53h, 59h, 18h,0E0h,0A7h, 5Fh,0ACh; 1128
.data:004A012C db 0FEh, 26h,0DEh,0B2h, 42h,0B1h,0E6h, 33h; 1136
.data:004A012C db 31h,0DEh, 21h, 69h, 6Fh,0F9h, 34h, 5Dh; 1144
.data:004A012C db 33h,0CEh, 79h,0E8h, 0Dh, 32h, 4, 24h; 1152
.data:004A012C db 98h,0D5h,0B8h, 91h, 5Bh,0F6h, 20h,0B2h; 1160
.data:004A012C db 0C7h,0AFh,0CFh,0E4h,0DAh, 9Ah, 3Ah, 6Dh; 1168
.data:004A012C db 0DBh, 1Fh, 16h,0C8h, 8Ah, 5Ah, 28h,0C6h; 1176
.data:004A012C db 0FFh, 5, 38h, 0Eh, 7Bh, 91h, 1Ch, 82h; 1184
.data:004A012C db 69h, 77h, 27h,0F1h, 68h, 83h, 9Eh, 9Eh; 1192
.data:004A012C db 0A3h,0E5h, 40h, 3Dh, 63h, 9Bh, 47h, 82h; 1200
.data:004A012C db 83h,0F6h,0D3h, 1Dh, 50h,0B6h, 97h,0DDh; 1208
.data:004A012C db 8Ah,0E6h, 6Ah, 16h, 0Dh, 0Bh,0DFh, 6Fh; 1216
.data:004A012C db 48h, 10h,0ABh, 62h,0F6h,0B1h,0E8h,0C9h; 1224
.data:004A012C db 8Ah, 6Eh, 49h, 9Fh,0E1h,0CCh, 1Eh,0C1h; 1232
.data:004A012C db 24h, 20h,0A9h, 0Ch, 8Ah,0D4h, 31h,0EAh; 1240
.data:004A012C db 0D8h,0C2h, 91h, 8Ch, 90h, 91h, 0Fh, 67h; 1248 这里写一个idc脚本把g_blacklist输出到文件blacklist.txt
#include <idc.idc>
static print_blacklist()
{
auto blacklist_addr;
auto i, p;
auto fl;
blacklist_addr = 0x4a012c;
p = blacklist_addr;
fl = fopen("blacklist.txt", "w");
if ( fl == 0)
{
Message("打开文件失败!\n");
return;
}
for (i=0; i<1256; i++)
{
if ( (i!=0) && (i%8 == 0))
{
Message("\n");
fprintf(fl,"\n");
}
Message("%02x", Byte(p) );
fprintf(fl, "%02x", Byte(p) );
p++;
}
fclose(fl);
} 3. 用户名黑名单 紧跟着下面有一个用户名黑名单user_blacklist, 存储的是用户名的sha1值的前64bit, 不过
这里的sha1好像作了一些手脚, 最后的HASH摘要并没有处理字节序问题(按DWORD存储了, 不
过下面比较的时候也用的是DWORD比较所以比较结果也是正确的), 发现sha1_update,
sha1_final都有一个参数1, 下一篇跟踪一下sha1算法.
有人可能要问我怎么知道是sha1的, 其实俺也是老菜的方法, 在跟进sha1_init函数是看到了
只是简单的赋值 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0x0c3d2e1f0, 俺猜
想可能是遇到hash算法了(如:md5, sha), 就计算username的各种hash值和内存对比就判断它
是sha1了. .text:0040E81F xor ebx, ebx
.text:0040E821 NEXT_UBLACK: ; CODE XREF: check_regdata+1C2j
.text:0040E821 lea eax, [esp+0E88h+sha1_ctx] ; ctx
.text:0040E828 call sha1_init
.text:0040E82D push 1
.text:0040E82F push regData ; username
.text:0040E830 call _strlen
.text:0040E835 pop ecx
.text:0040E836 mov ecx, eax ; len
.text:0040E838 mov edx, regData ; data
.text:0040E83A lea eax, [esp+0E8Ch+sha1_ctx] ; ctx
.text:0040E841 call sha1_update
.text:0040E846 lea edx, [esp+0E88h+sha1_digest] ; digest
.text:0040E84D lea eax, [esp+0E88h+sha1_ctx] ; ctx
.text:0040E854 mov cl, 1 ; endian
.text:0040E856 call sha1_final
.text:0040E85B mov edx, user_blacklist.sha_0[ebx*8] ;
.text:0040E862 cmp edx, dword ptr [esp+0E88h+sha1_digest] ; [Check4]
.text:0040E869 jnz short loc_40E882
.text:0040E86B mov eax, user_blacklist.sha_1[ebx*8] ;
.text:0040E872 cmp eax, dword ptr [esp+0E88h+sha1_digest+4] ; [Check4]
.text:0040E879 jnz short loc_40E882
.text:0040E87B xor eax, eax ; [Check4] 检查注册用户名的 SHA1值的前 8字节是否在
; user_blacklist里, 在则注册失败!
.text:0040E87D jmp REG_FAIL_EXIT
.text:0040E882 loc_40E882: ; CODE XREF: check_regdata+1A5j
.text:0040E882 ; check_regdata+1B5j
.text:0040E882 inc ebx
.text:0040E883 cmp ebx, 6
.text:0040E886 jl short NEXT_UBLACK
有6个用户黑名单, 也idc脚本打印出来
.data:004A0614 user_blacklist _SHA_ <539D5CC7h, 1C48938Ch>; 0
.data:004A0614 _SHA_ <0AEE5DA2Fh, 83182A3Ch>; 1
.data:004A0614 _SHA_ <0EF15C666h, 0BB1FDF30h>; 2
.data:004A0614 _SHA_ <2B2CB836h, 1589154Ah>; 3
.data:004A0614 _SHA_ <0C16C2007h, 4EC9F4CEh>; 4
.data:004A0614 _SHA_ <37A1C984h, 20A6A0D5h>; 5
#include <idc.idc>
static print_user_blacklist()
{
auto user_blacklist_addr;
auto i, j, p;
auto fl;
user_blacklist_addr = 0x4a0614;
p = user_blacklist_addr;
fl = fopen("user_blacklist.txt", "w");
if ( fl == 0 )
{
Message("打开文件失败!\n");
return;
}
for (i=0; i<6*2; i++)
{
if ( (i!=0) && (i%2 == 0))
{
Message("\n");
fprintf(fl,"\n");
}
Message("%08x", Dword(p) );
fprintf(fl, "%08x", Dword(p) );
p = p+4;
}
fclose(fl);
}
到此已经有5处检查, 1). g_HCode0的CRC32校验; 2). 从snHead中取出的snCode2, snCode3
的长度不大于256; 3). snCode1的前8位是否在黑名单; 4). username的sha1前8字节是否在
用户黑名单; 5).regData.licType + username + regData.snCode1/2/3/4的~CRC32值是否等
于regData.crc32
能力值:
( LV12,RANK:450 )
12 楼
WinRAR 3.62注册算法 - SHA1 hash算法 [声明] 本文为逆向学习参考文章, 若使用 winrar 请向作者注册.
4. SHA1 算法
上回讲用户黑名单是遇到了SHA1算法, 这回就看看这个算法.
首先用到一个结构:
typedef unsigned int u_int32_t;
typedef unsigned char u_int8_t;
typedef struct _sha1_ctx
{
u_int32_t state[5];
u_int32_t count[2];
u_int8_t buffer[64];
} SHA1_CTX; 在这里我都是先把结构给出来了, 然后再分析相关函数的, 其实逆向分析正好是相反的过程,
个人认为数据结构的确定是逆向过程的一个很重要的部分, 而数据结构的确定可能需要查看
基于某地址不同偏移的内存访问的所有函数.
首先是初始化函数, 非常简单:
.text:0042FFB0 ; void __fastcall sha1_init(SHA1_CTX *ctx)
.text:0042FFB0 sha1_init proc near
.text:0042FFB0 _ctx = eax
.text:0042FFB0 mov [_ctx+SHA1_CTX.sha_0], 67452301h
.text:0042FFB6 xor edx, edx
.text:0042FFB8 mov [_ctx+SHA1_CTX.sha_1], 0EFCDAB89h
.text:0042FFBF mov [_ctx+SHA1_CTX.sha_2], 98BADCFEh
.text:0042FFC6 mov [_ctx+SHA1_CTX.sha_3], 10325476h
.text:0042FFCD mov [_ctx+SHA1_CTX.sha_4], 0C3D2E1F0h
.text:0042FFD4 mov [_ctx+SHA1_CTX.count1], edx
.text:0042FFD7 mov [_ctx+SHA1_CTX.count0], edx
.text:0042FFDA retn
.text:0042FFDA sha1_init endp sha1_init C实现:
void
sha1_init(SHA1_CTX *ctx)
{
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
ctx->state[4] = 0xC3D2E1F0;
ctx->count[0] = 0;
ctx->count[1] = 0;
}
看下一个函数:
.text:0040E82D push 1
.text:0040E82F push regData ; username
.text:0040E830 call _strlen
.text:0040E830
.text:0040E835 pop ecx
.text:0040E836 mov ecx, eax ; len
.text:0040E838 mov edx, regData ; data
.text:0040E83A lea eax, [esp+0E8Ch+sha1_ctx] ; ctx
.text:0040E841 call sha1_update
函数有3个参数, eax指向sha1_ctx结构, edx指向一个buffer, 这里指向regData.username
ecx是buffer的长度, 还有一个参数1(push 1), 跟进去往后看这个参数干什么用的.
.text:0042FFDC ; void __fastcall sha1_update(SHA1_CTX *ctx,BYTE *data,DWORD len,BYTE trans_copies)
.text:0042FFDC sha1_update proc near ; CODE XREF: sub_407D7C+88p
.text:0042FFDC
.text:0042FFDC var_10 = dword ptr -10h
.text:0042FFDC _data = dword ptr -4
.text:0042FFDC trans_copies = byte ptr 8
.text:0042FFDC
.text:0042FFDC _len = edi
.text:0042FFDC _ctx = esi
.text:0042FFDC push ebp
.text:0042FFDD mov ebp, esp
.text:0042FFDF push ecx
.text:0042FFE0 push ebx
.text:0042FFE1 push _ctx
.text:0042FFE2 push _len
.text:0042FFE3 mov _len, ecx
.text:0042FFE5 mov [ebp+_data], edx
.text:0042FFE8 mov _ctx, eax
.text:0042FFEA mov edx, _len
.text:0042FFEC shl edx, 3 ; 把长度*8, 把字节数转换成bit位
.text:0042FFEF mov eax, [_ctx+SHA1_CTX.count0]
.text:0042FFF2 shr eax, 3 ; 把bit位数转换成字节数
.text:0042FFF5 and eax, 3Fh ; 是否是64字节的倍数, 因为低于64字节部分还没有处理
.text:0042FFF8 add [_ctx+SHA1_CTX.count0], edx ; 计数相加, 这里应该知道 count0存储的是buffer的bit数
.text:0042FFFB mov ecx, [_ctx+SHA1_CTX.count0]
.text:0042FFFE cmp edx, ecx
.text:00430000 jbe short loc_430005
.text:00430002 inc [_ctx+SHA1_CTX.count1] ; 处理加法运算发生的进位, 看来count0, connt1
.text:00430002 ; 应该是一个64bit 整数.
.text:00430005
.text:00430005 loc_430005: ; CODE XREF: sha1_update+24j
.text:00430005 mov edx, _len
.text:00430007 shr edx, 1Dh
.text:0043000A add [_ctx+SHA1_CTX.count1], edx ; 处理左移发生的进位
.text:0043000D lea ecx, [_len+eax]
.text:00430010 cmp ecx, 3Fh
.text:00430013 jbe short LESS_64
.text:00430015 mov ebx, 40h
.text:0043001A sub ebx, eax
.text:0043001C add eax, _ctx
.text:0043001E push ebx ; n
.text:0043001F add eax, 1Ch
.text:00430022 push [ebp+_data] ; src
.text:00430025 push eax ; dest
.text:00430026 call _memcpy ; 拷贝64个字节到sha1_ctx.buffer中
.text:0043002B add esp, 0Ch
.text:0043002E lea edx, [_ctx+SHA1_CTX.buffer] ; data
.text:00430031 mov cl, [ebp+trans_copies] ; trans_copies
.text:00430034 mov eax, _ctx ; ctx_state
.text:00430036 call sha1_transform ; 处理sha1_ctx.buffer, sha1_transform是sha的核心运算.
.text:00430036
.text:0043003B jmp short loc_43004F
.text:0043003D ; ---------------------------------------------------------------------------
.text:0043003D NEXT_64B: ; CODE XREF: sha1_update+78j
.text:0043003D mov edx, [ebp+_data]
.text:00430040 add edx, ebx ; data
.text:00430042 mov cl, [ebp+trans_copies] ; trans_copies
.text:00430045 mov eax, _ctx ; ctx_state
.text:00430047 call sha1_transform
.text:0043004C loc_43004C: ; DATA XREF: .data:004A5BC0o
.text:0043004C add ebx, 40h
.text:0043004F loc_43004F: ; CODE XREF: sha1_update+5Fj
.text:0043004F lea eax, [ebx+3Fh]
.text:00430052 cmp _len, eax
.text:00430054 ja short NEXT_64B
.text:00430056 xor eax, eax
.text:00430058 jmp short loc_43005C
.text:0043005A ; ---------------------------------------------------------------------------
.text:0043005A LESS_64: ; CODE XREF: sha1_update+37j
.text:0043005A xor ebx, ebx
.text:0043005C loc_43005C: ; CODE XREF: sha1_update+7Cj
.text:0043005C cmp ebx, _len
.text:0043005E jnb short EXIT
.text:00430060 sub _len, ebx
.text:00430062 add _ctx, eax
.text:00430064 push _len ; n
.text:00430065 mov edx, [ebp+_data]
.text:00430068 add edx, ebx
.text:0043006A add _ctx, 1Ch
.text:0043006D push edx ; src
.text:0043006E push _ctx ; dest
.text:0043006F call _memcpy ; 不到64字节的部分拷贝到sha1_ctx.buffer中下次处理.
.text:00430074 add esp, 0Ch
.text:00430077 EXIT: ; CODE XREF: sha1_update+82j
.text:00430077 pop _len
.text:00430078 pop _ctx
.text:00430079 pop ebx
.text:0043007A pop ecx
.text:0043007B pop ebp
.text:0043007C retn 4
.text:0043007C sha1_update endp sha1_update C实现:
void __fastcall
sha1_update(SHA1_CTX *ctx, u_int8_t *data, u_int32_t len, u_int8_t trans_copies)
{
u_int32_t remain;
u_int32_t count;
remain = ctx->count[0] >> 3 & 0x3F; /* 未处理的剩余字节数 */
count = len << 3;
ctx->count[0] += count;
if (count > ctx->count[0]) /* 进位处理 */
ctx->count[1]++;
ctx->count[1] += len >> 29;
if (len + remain > 63)
{
count = 64 - remain;
memcpy(ctx->buffer+remain, data, count);
sha1_transform(ctx->state, ctx->buffer, trans_copies);
for (; len > count+63 ; count += 64) /* 循环每次计算64字节 */
{
sha1_transform(ctx->state, data+count, trans_copies);
}
}
else
count = 0;
if (count < len) /* 把不到64字节的部分拷贝到ctx->buffer */
memcpy(ctx->buffer+remain, data+count, len-count);
} 核心运算sha1_transform:
.text:0042E374 ; void __fastcall sha1_transform(DWORD *ctx_state,BYTE *data,BYTE trans_copies)
.text:0042E374 sha1_transform proc near ; CODE XREF: sha1_update+5Ap
.text:0042E374 ; sha1_update+6Bp
.text:0042E374 ; sha1_final+119p
.text:0042E374
.text:0042E374 _state = dword ptr -14h
.text:0042E374 _buffer = dword ptr -10h
.text:0042E374 _trans_copies = byte ptr -0Ch
.text:0042E374 A = dword ptr -8
.text:0042E374 E = dword ptr -4
.text:0042E374
.text:0042E374 eax_B = eax
.text:0042E374 edx_C = edx
.text:0042E374 ecx_D = ecx
.text:0042E374 push ebx
.text:0042E375 push esi
.text:0042E376 push edi
.text:0042E377 push ebp
.text:0042E378 add esp, 0FFFFFFECh
.text:0042E37B mov [esp+14h+_trans_copies], cl
.text:0042E37F mov [esp+14h+_buffer], edx_C
.text:0042E383 mov [esp+14h+_state], eax_B
.text:0042E386 cmp [esp+14h+_trans_copies], 0
.text:0042E38B jz short IF1_ELSE
.text:0042E38B
.text:0042E38D mov ebx, offset g_Buffer64
.text:0042E392 push 40h ; n
.text:0042E394 push [esp+18h+_buffer] ; src
.text:0042E398 push ebx ; dest
.text:0042E399 call _memcpy
.text:0042E399
.text:0042E39E add esp, 0Ch
.text:0042E3A1 jmp short loc_42E3A7
.text:0042E3A1
.text:0042E3A3 ; ---------------------------------------------------------------------------
.text:0042E3A3
.text:0042E3A3 IF1_ELSE: ; CODE XREF: sha1_transform+17j
.text:0042E3A3 mov ebx, [esp+14h+_buffer]
.text:0042E3A3
.text:0042E3A7
.text:0042E3A7 loc_42E3A7: ; CODE XREF: sha1_transform+2Dj
.text:0042E3A7 mov eax_B, [esp+14h+_state]
.text:0042E3AA mov edx_C, [eax_B]
.text:0042E3AC mov [esp+14h+A], edx_C
.text:0042E3B0 mov ecx_D, [esp+14h+_state]
.text:0042E3B3 mov edx_C, [esp+14h+_state]
.text:0042E3B6 mov esi, [esp+14h+_state]
.text:0042E3B9 mov eax_B, [ecx_D+4]
.text:0042E3BC mov ecx_D, [esp+14h+_state]
.text:0042E3BF mov edx_C, [edx_C+8]
.text:0042E3C2 mov esi, [esi+10h]
.text:0042E3C5 mov ecx_D, [ecx_D+0Ch]
.text:0042E3C8 mov [esp+14h+E], esi ; 这里我们把ctx->state[5]数组中的值分别赋值给A, eax, edx, ecx,
.text:0042E3C8 ; E, 变量A,E是内存分配的局域变量, 其它几个值用的寄存器,
.text:0042E3C8 ; 我在这里分别把eax, edx, ecx重新命名位, eax_B, edx_C,
.text:0042E3C8 ; ecx_D(以下分别称其B, C, D), ebx指向输入64字节的数据
.text:0042E3C8 ; (以下都称其buf); 因为buf是按DWORD取值的, 故我把ebx定
.text:0042E3C8 ; 义为一个指向UI32[16]的数组:
.text:0042E3C8 ; 00000000 UI32 struc ; (sizeof=0x40)
.text:0042E3C8 ; 00000000 _0 dd ?
.text:0042E3C8 ; 00000004 _1 dd ?
.text:0042E3C8 ; 00000008 _2 dd ?
.text:0042E3C8 ; 0000000C _3 dd ?
.text:0042E3C8 ; 00000010 _4 dd ?
.text:0042E3C8 ; 00000014 _5 dd ?
.text:0042E3C8 ; 00000018 _6 dd ?
.text:0042E3C8 ; 0000001C _7 dd ?
.text:0042E3C8 ; 00000020 _8 dd ?
.text:0042E3C8 ; 00000024 _9 dd ?
.text:0042E3C8 ; 00000028 _10 dd ?
.text:0042E3C8 ; 0000002C _11 dd ?
.text:0042E3C8 ; 00000030 _12 dd ?
.text:0042E3C8 ; 00000034 _13 dd ?
.text:0042E3C8 ; 00000038 _14 dd ?
.text:0042E3C8 ; 0000003C _15 dd ?
.text:0042E3C8 ; 00000040 UI32 ends
.text:0042E3C8 ;
.text:0042E3C8 ;
.text:0042E3C8 ;
.text:0042E3CC mov esi, [ebx+UI32._0] ; ***********************第1次运算开始****
.text:0042E3CE mov edi, [ebx] ; 取buf中第一个DWORD, 称其buf[0], 本函数此行以下,
.text:0042E3CE ; 若未另声明则buf为一DWORD数组, 数组大小64字节.
.text:0042E3CE ;
.text:0042E3CE ;
.text:0042E3D0 shr edi, 8 ; buf[0]右移8bit
.text:0042E3D3 mov ebp, [ebx+UI32._0]
.text:0042E3D5 shl esi, 18h ; buf[0]左移24bit(32-8)
.text:0042E3D8 or esi, edi ; 左移和右移的结果按位或, (buf[0]>>8) | (buf[0]<<24)
.text:0042E3DA mov edi, [ebx+UI32._0]
.text:0042E3DC shl edi, 8 ; buf[0]左移8bit
.text:0042E3DF and esi, 0FF00FF00h ; (buf[0]>>8) | (buf[0]<<24) & 0xFF00FF00
.text:0042E3E5 shr ebp, 18h ; buf[0]右移24bit
.text:0042E3E8 or edi, ebp ; (buf[0]<<8) | (buf[0]>>24)
.text:0042E3EA and edi, 0FF00FFh ; (buf[0]<<8) | (buf[0]>>24) & 0x0FF00FF
.text:0042E3F0 or esi, edi ; ((buf[0]>>8) | (buf[0]<<24) & 0xFF00FF00) |
.text:0042E3F0 ; ((buf[0]<<8) | (buf[0]>>24) & 0x0FF00FF)
.text:0042E3F0 ;
.text:0042E3F0 ; buf[0]>>8 求或 buf[0]<<24 求与0xFF00FF00, 也就是只留
.text:0042E3F0 ; 最高字节和第2个字节, 而计算后最高字节是buf[0]的最低字
.text:0042E3F0 ; 节, 第2个字节是buf[0]的第3个字节.
.text:0042E3F0 ;
.text:0042E3F0 ; buf[0]<<8 求或 buf[0]>>24 求与 0x0FF00FF, 就是只留最
.text:0042E3F0 ; 低字节和第3个字节, 而计算后最低字节就是buf[0]的最高字
.text:0042E3F0 ; 节, 第3个字节就是buf[0]的第2个字节
.text:0042E3F0 ;
.text:0042E3F0 ; 两者再按位或以后, 就是把原来的字节序反了一下,
.text:0042E3F0 ; 以后称这种反序运算为RE(v), 如: RE(buf[0])
.text:0042E3F0 ;
.text:0042E3F2 mov edi, ecx_D
.text:0042E3F4 xor edi, edx_C ; D异或C, D^C
.text:0042E3F6 mov [ebx+UI32._0], esi ; 把buf[0]反序后的的值重新复制给buf[0]
.text:0042E3F6 ; buf[0] = RE(buf[0])
.text:0042E3F8 and edi, eax_B ; (D^C)&B
.text:0042E3FA mov ebp, [esp+14h+A]
.text:0042E3FE xor edi, ecx_D ; ((D^C)&B)^D
.text:0042E400 add esi, edi ; RE(buf[0]) & (((D^C)&B)^D)
.text:0042E402 mov edi, [esp+14h+A]
.text:0042E406 shl edi, 5 ; A<<5
.text:0042E409 shr ebp, 1Bh ; A>>27; // 27=32-5
.text:0042E40C or edi, ebp ; (A>>27) | (A<<5)
.text:0042E40C ; 这种运算下面统一叫做 RL(value, n) = (value<<n) | (value>>(32-n))
.text:0042E40C ; 如: 此处RL(A,5)
.text:0042E40C ; 同时: RE(v) =(RL(v,24)&0xFF00FF00) | (RL(v,8)&0x0FF00FF)
.text:0042E40C ;
.text:0042E40E add esi, edi ; RE(buf[0]) + (((D^C)&B)^D) + RL(A,5)
.text:0042E40E ; 从下面得知RX运算以后, 整个表达式变成了:
.text:0042E40E ; RE(buf[0]) + RX(B,C,D) + RL(A,5)
.text:0042E40E ;
.text:0042E40E ;
.text:0042E410 add esi, 5A827999h ; <suspicious> ; (RE(buf[0]) + RX(B,C,D) + RL(A,5)) + 0x5A827999
.text:0042E416 add [esp+14h+E], esi ; E += (RE(buf[0]) + RX(B,C,D) + RL(A,5)) + 0x5A827999
.text:0042E41A mov esi, eax_B
.text:0042E41C shr eax_B, 2 ; B>>2
.text:0042E41F mov edi, [ebx+UI32._1] ; edi = buf[1]
.text:0042E422 shl esi, 1Eh ; B<<(32-2)
.text:0042E425 mov ebp, [ebx+UI32._1] ; ebp = buf[1]
.text:0042E428 or esi, eax_B ; (B>>2) | (B<<(32-2))
.text:0042E428 ; 即RL(B,30)
.text:0042E42A mov eax_B, esi ; B = RL(B,30)
.text:0042E42A ; ***********************第1次运算结束****
.text:0042E42A ;
.text:0042E42A ;
.text:0042E42C mov esi, [ebx+UI32._1] ; ***********************第2次运算开始****
.text:0042E42C ; buf[1]
.text:0042E42F shl esi, 18h ; buf[1]<<24
.text:0042E432 shr edi, 8 ; buf[1]>>8
.text:0042E435 or esi, edi ; RL(buf[1],24) = (buff[1]>>8) | (buff[1]<<24)
.text:0042E437 mov edi, [ebx+UI32._1]
.text:0042E43A shl edi, 8 ; buf[1]<<8
.text:0042E43D and esi, 0FF00FF00h ; RL(buf[1],24)&0xFF00FF00
.text:0042E443 shr ebp, 18h ; buf[1]>>24
.text:0042E446 or edi, ebp ; RL(buf[1],8) = (buf[1]>>24) | (buf[1]<<8)
.text:0042E448 and edi, 0FF00FFh ; RL(buf[1],8)&0xFF00FF
.text:0042E44E or esi, edi ; RE(buf[1]) = (RL(buf[1],24) & 0xFF00FF00)| (RL(buf[1],8)&0x0FF00FF)
.text:0042E44E ; 反序buf[1]
.text:0042E450 mov edi, edx_C
.text:0042E452 mov [ebx+UI32._1], esi ; buf[1] = RE(buf[1])
.text:0042E455 xor edi, eax_B ; C^B
.text:0042E457 and edi, [esp+14h+A] ; (C^B)&A
.text:0042E45B mov ebp, [esp+14h+E]
.text:0042E45F xor edi, edx_C ; ((C^B)&A)^C
.text:0042E45F ; 这个运算是不是很面熟? 对前面出现过((D^C)&B)^D
.text:0042E45F ; 定义一个运算: RX(w,x,y) = ((x^y)&w)^y
.text:0042E45F ; 这里RX(A,B,C) = ((B^C)&A)^C
.text:0042E45F ;
.text:0042E461 add esi, edi ; RE(buf[1])+RX(A,B,C)
.text:0042E463 mov edi, [esp+14h+E]
.text:0042E467 shl edi, 5 ; E<<5
.text:0042E46A shr ebp, 1Bh ; E>>27
.text:0042E46D or edi, ebp ; RL(E,5) = (E<<5) | (E>>(32-5))
.text:0042E46F add esi, edi ; RE(buf[1]) + RX(A,B,C) + RL(E,5)
.text:0042E471 mov edi, [esp+14h+A]
.text:0042E475 add esi, 5A827999h ; <suspicious> ; RE(buf[1]) + RX(A,B,C) + RL(E,5) + 0x5a827999
.text:0042E47B add ecx_D, esi ; D += RE(buf[1]) + RX(A,B,C) + RL(E,5) + 0x5a827999
.text:0042E47D mov esi, [esp+14h+A]
.text:0042E481 shl esi, 1Eh ; A<<30
.text:0042E484 shr edi, 2 ; A>>2
.text:0042E487 or esi, edi ; RL(A,30) = (A<<30) | (A>>(32-30))
.text:0042E489 mov [esp+14h+A], esi ; A = RL(A,30)
.text:0042E489 ; ***********************第2次运算结束****
.text:0042E489 ;
.text:0042E489 ;
.text:0042E48D mov esi, [ebx+UI32._2] ; ***********************第3次运算开始****
.text:0042E490 mov edi, [ebx+UI32._2] ; buf[2]
.text:0042E493 shr edi, 8 ; buf[2]>>8
.text:0042E496 mov ebp, [ebx+UI32._2]
.text:0042E499 shl esi, 18h ; buf[2]<<24
.text:0042E49C or esi, edi ; RL(buf[2],24)
.text:0042E49E mov edi, [ebx+UI32._2]
.text:0042E4A1 shl edi, 8 ; buf[2]<<8
.text:0042E4A4 and esi, 0FF00FF00h ; RL(buf[2],24)&0xff00ff00
.text:0042E4AA shr ebp, 18h ; buf[2]>>24
.text:0042E4AD or edi, ebp ; RL(buf[2],8)
.text:0042E4AF mov ebp, ecx_D
.text:0042E4B1 and edi, 0FF00FFh ; RL(buf[2],8)&0x0ff00ff
.text:0042E4B7 or esi, edi ; RE(buf[2]) = (RL(buf[2],24)&0xff00ff00) | (RL(buf[2],8)&0x0ff00ff)
.text:0042E4B9 mov [ebx+UI32._2], esi ; buf[2] = RE(buf[2])
.text:0042E4BC mov edi, [esp+14h+A]
.text:0042E4C0 xor edi, eax_B ; A^B
.text:0042E4C2 and edi, [esp+14h+E] ; (B^A)&E
.text:0042E4C6 xor edi, eax_B ; RX(E,A,B) = ((B^A)&E)^B
.text:0042E4C8 add esi, edi ; RE(buf[2]) + RX(E,A,B)
.text:0042E4CA mov edi, ecx_D
.text:0042E4CC shl edi, 5 ; D<<5
.text:0042E4CF shr ebp, 1Bh ; D>>27
.text:0042E4D2 or edi, ebp ; RL(D,5) = (D<<5) | (D>>(32-5))
.text:0042E4D4 add esi, edi ; RE(buf[2]) + RX(E,A,B) + RL(D,5)
.text:0042E4D6 mov edi, [esp+14h+E]
.text:0042E4DA add esi, 5A827999h ; <suspicious> ; RE(buf[2]) + RX(E,A,B) + RL(D,5) + 0x5a827999
.text:0042E4E0 add edx_C, esi ; C += RE(buf[2]) + RX(E,A,B) + RL(D,5) + 0x5a827999
.text:0042E4E2 mov esi, [esp+14h+E]
.text:0042E4E6 shl esi, 1Eh ; E<<30
.text:0042E4E9 shr edi, 2 ; E>>2
.text:0042E4EC or esi, edi ; RL(E,30) = (E<<30) | (E>>(32-30))
.text:0042E4EE mov [esp+14h+E], esi ; E = RL(E,30)
.text:0042E4EE ; ***********************第3次运算结束****
.text:0042E4EE ; 观察前3次运算总结:
.text:0042E4EE ; 1. 从buf中取一个DWORD, 反序后保存.
.text:0042E4EE ; 2. 每次运算都用到了A,B,C,D,E, 只是用的顺序不同.
.text:0042E4EE ; 3. 每次运算除了修改了buf[i]的内容, 还修改了A-E中
.text:0042E4EE ; 两个'变量'
.text:0042E4EE ;
.text:0042E4EE ; 定义一个函数:
.text:0042E4EE ; void inline R0(u_int32_t a,
.text:0042E4EE ; u_int32_t b,
.text:0042E4EE ; u_int32_t c,
.text:0042E4EE ; u_int32_t d,
.text:0042E4EE ; u_int32_t e,
.text:0042E4EE ; u_int32_t &n)
.text:0042E4EE ; {
.text:0042E4EE ; *n = RE(*n);
.text:0042E4EE ; e += *n + RX(b,c,d) + 0x5a827999;
.text:0042E4EE ; b = RL(b,30);
.text:0042E4EE ; }
.text:0042E4EE ;
.text:0042E4EE ; 那么前3次调用此函数分别为:
.text:0042E4EE ; R_0(A,B,C,D,E,&buf[0]);
.text:0042E4EE ; R_0(E,A,B,C,D,&buf[1]);
.text:0042E4EE ; R_0(D,E,A,B,C,&buf[2]);
.text:0042E4EE ;
.text:0042E4EE ;
.text:0042E4EE ;
.text:0042E4F2 mov esi, [ebx+UI32._3] ; ***********************第4次运算开始****
.text:0042E4F5 mov edi, [ebx+UI32._3] ; buf[3]
.text:0042E4F8 shr edi, 8 ; buf[3]>>8
.text:0042E4FB mov ebp, [ebx+UI32._3]
.text:0042E4FE shl esi, 18h ; buf[3]<<24
.text:0042E501 or esi, edi ; RL(buf[3],24) = (buf[3]<<24) | (buf[3]>>(32-24))
.text:0042E503 mov edi, [ebx+UI32._3]
.text:0042E506 shl edi, 8 ; buf[3]<<8
.text:0042E509 and esi, 0FF00FF00h ; RL(buf[3],24) & 0xff00ff00
.text:0042E50F shr ebp, 18h ; buf[3]>>24
.text:0042E512 or edi, ebp ; RL(buf[3],8) = (buf[3]<<8) | (buf[3]>>(32-8))
.text:0042E514 mov ebp, edx_C
.text:0042E516 and edi, 0FF00FFh ; RL(buf[3],8) &0x0ff00ff
.text:0042E51C or esi, edi ; RE(buf[3]) = (RL(buf[3],24)&0xff00ff00) | (RL(buf[3],8)&0xff00ff)
.text:0042E51E mov [ebx+UI32._3], esi ; buf[3] = RE(buf[3])
.text:0042E521 mov edi, [esp+14h+E]
.text:0042E525 xor edi, [esp+14h+A] ; (E^A)
.text:0042E529 and edi, ecx_D ; (E^A)&D
.text:0042E52B xor edi, [esp+14h+A] ; RX(D,E,A) = (E^A)&D^A
.text:0042E52F add esi, edi ; RE(buf[3]) + RX(D,E,A)
.text:0042E531 mov edi, edx_C
.text:0042E533 shl edi, 5 ; C<<5
.text:0042E536 shr ebp, 1Bh ; C>>27
.text:0042E539 or edi, ebp ; RL(C,5) = (C<<5) | (C>>(32-5))
.text:0042E53B mov ebp, [ebx+UI32._4] ; buf[4]
.text:0042E53E add esi, edi ; RE(buf[3]) + RX(D,E,A) + RL(C,5)
.text:0042E540 mov edi, [ebx+UI32._4]
.text:0042E543 add esi, 5A827999h ; <suspicious>
.text:0042E549 add eax_B, esi ; B += RE(buf[3]) + RX(D,E,A) + RL(C,5) + 0x5a827999
.text:0042E54B mov esi, ecx_D
.text:0042E54D shr ecx_D, 2 ; D>>2
.text:0042E550 shl esi, 1Eh ; D<<30
.text:0042E553 or esi, ecx_D ; RL(D,30) = (D<<30) | (D>>(32-30))
.text:0042E555 mov ecx_D, esi ; D = RL(D,30)
.text:0042E555 ;
.text:0042E555 ; 整个第4次运算用函数R0表示: R0(C,D,E,A,B, &buf[3])
.text:0042E555 ;
.text:0042E555 ; ***********************第4次运算结束****
.text:0042E555 ;
.text:0042E555 ;
.text:0042E557 mov esi, [ebx+UI32._4] ; ***********************第5次运算开始****
.text:0042E557 ; buf[4]
.text:0042E55A shl esi, 18h ; buf[4]<<24
.text:0042E55D shr edi, 8 ; buf[4]>>8
.text:0042E560 or esi, edi ; RL(buf[4],24)
.text:0042E562 mov edi, [ebx+UI32._4]
.text:0042E565 shl edi, 8 ; buf[4]<<8
.text:0042E568 and esi, 0FF00FF00h ; RL(buf[4],24) &0xff00ff00
.text:0042E56E shr ebp, 18h ; buf[4]>>24
.text:0042E571 or edi, ebp ; RL(buf[4],8)
.text:0042E573 mov ebp, eax_B
.text:0042E575 and edi, 0FF00FFh ; RL(buf[4],8)&0x0ff00ff
.text:0042E57B or esi, edi ; RE(buf[4])
.text:0042E57D mov [ebx+UI32._4], esi ; buf[4] = RE(buf[4])
.text:0042E580 mov edi, [esp+14h+E]
.text:0042E584 xor edi, ecx_D ; (E^D)
.text:0042E586 and edi, edx_C ; (E^D)&C
.text:0042E588 xor edi, [esp+14h+E] ; RX(C,D,E) = ((D^E)&C)^E
.text:0042E58C add esi, edi ; RE(buf[4]) + RX(C,D,E)
.text:0042E58E mov edi, eax_B
.text:0042E590 shl edi, 5 ; B<<5
.text:0042E593 shr ebp, 1Bh ; B>>27
.text:0042E596 or edi, ebp ; RL(B,5)
.text:0042E598 add esi, edi ; RE(buf[4]) + RX(C,D,E) + RL(B,5)
.text:0042E59A add esi, 5A827999h ; <suspicious>
.text:0042E5A0 add [esp+14h+A], esi ; A += RE(buf[4]) + RX(C,D,E) + RL(B,5) + 0x5a827999;
.text:0042E5A4 mov esi, edx_C
.text:0042E5A6 shr edx_C, 2 ; C>>2
.text:0042E5A9 mov edi, [ebx+UI32._5] ; buf[5]
.text:0042E5AC shl esi, 1Eh ; C<<30
.text:0042E5AF mov ebp, [ebx+UI32._5] ; buf[5]
.text:0042E5B2 or esi, edx_C ; RL(C,30)
.text:0042E5B4 mov edx_C, esi ; C = RL(C,30);
.text:0042E5B4 ;
.text:0042E5B4 ; (5) R0(B,C,D,E,A, &buf[4]);
.text:0042E5B4 ; ***********************第5次运算结束****
.text:0042E5B4 ;
.text:0042E5B4 ;
.text:0042E5B6 mov esi, [ebx+UI32._5] ; ***********************第6次运算开始****
.text:0042E5B9 shl esi, 18h ; buf[5]<<24
.text:0042E5BC shr edi, 8 ; buf[5]>>8
.text:0042E5BF or esi, edi ; RL(buf[5],24)
.text:0042E5C1 mov edi, [ebx+UI32._5] ; buf[5]
.text:0042E5C4 shl edi, 8 ; buf[5]<<8
.text:0042E5C7 and esi, 0FF00FF00h ; RL(buf[5],24)&0xff00ff00
.text:0042E5CD shr ebp, 18h ; buf[5]>>24
.text:0042E5D0 or edi, ebp ; RL(buf[5],8)
.text:0042E5D2 and edi, 0FF00FFh ; RL(buf[5],8) & 0x0ff00ff
.text:0042E5D8 or esi, edi ; RE(buf[5])
.text:0042E5DA mov edi, ecx_D
.text:0042E5DC xor edi, edx_C ; (C^D)
.text:0042E5DE mov [ebx+UI32._5], esi ; buf[5] = RE(buf[5])
.text:0042E5E1 and edi, eax_B ; (C^D)&B
.text:0042E5E3 mov ebp, [esp+14h+A]
.text:0042E5E7 xor edi, ecx_D ; RX(B,C,D) = ((C^D)&B)^D
.text:0042E5E9 add esi, edi ; RE(buf[5]) + RX(B,C,D)
.text:0042E5EB mov edi, [esp+14h+A]
.text:0042E5EF shl edi, 5 ; A<<5
.text:0042E5F2 shr ebp, 1Bh ; A>>27
.text:0042E5F5 or edi, ebp ; RL(A,5)
.text:0042E5F7 add esi, edi ; RE(buf[5]) + RX(B,C,D) + RL(A,5)
.text:0042E5F9 add esi, 5A827999h ; <suspicious>
.text:0042E5FF add [esp+14h+E], esi ; E += RE(buf[5]) + RX(B,C,D) + RL(A,5) + 0x5a827999;
.text:0042E603 mov esi, eax_B
.text:0042E605 shr eax_B, 2 ; B>>2
.text:0042E608 mov edi, [ebx+UI32._6]
.text:0042E60B shl esi, 1Eh ; B<<30
.text:0042E60E mov ebp, [ebx+UI32._6]
.text:0042E611 or esi, eax_B ; RL(B,30)
.text:0042E613 mov eax_B, esi ; B = RL(B,30);
.text:0042E613 ; (6). R0(A,B,C,D,E, &buf[5])
.text:0042E613 ; ***********************第6次运算结束****
.text:0042E613 ;
.text:0042E613 ;
.text:0042E615 mov esi, [ebx+UI32._6] ; ***********************第7次运算开始****
.text:0042E618 shl esi, 18h
.text:0042E61B shr edi, 8
.text:0042E61E or esi, edi
.text:0042E620 mov edi, [ebx+UI32._6]
.text:0042E623 shl edi, 8
.text:0042E626 and esi, 0FF00FF00h
.text:0042E62C shr ebp, 18h
.text:0042E62F or edi, ebp
.text:0042E631 and edi, 0FF00FFh
.text:0042E637 or esi, edi
.text:0042E639 mov edi, edx_C
.text:0042E63B mov [ebx+UI32._6], esi
.text:0042E63E xor edi, eax_B
.text:0042E640 and edi, [esp+14h+A]
.text:0042E644 mov ebp, [esp+14h+E]
.text:0042E648 xor edi, edx_C
.text:0042E64A add esi, edi
.text:0042E64C mov edi, [esp+14h+E]
.text:0042E650 shl edi, 5
.text:0042E653 shr ebp, 1Bh
.text:0042E656 or edi, ebp
.text:0042E658 add esi, edi
.text:0042E65A mov edi, [esp+14h+A]
.text:0042E65E add esi, 5A827999h ; <suspicious>
.text:0042E664 add ecx_D, esi
.text:0042E666 mov esi, [esp+14h+A]
.text:0042E66A shl esi, 1Eh
.text:0042E66D shr edi, 2
.text:0042E670 or esi, edi
.text:0042E672 mov [esp+14h+A], esi ; (7). R0(E,A,B,C,D, &buf[6])
.text:0042E672 ; ***********************第7次运算结束****
.text:0042E672 ;
.text:0042E672 ;
.text:0042E676 mov esi, [ebx+UI32._7] ; ***********************第8次运算开始****
.text:0042E679 mov edi, [ebx+UI32._7]
.text:0042E67C shr edi, 8
.text:0042E67F mov ebp, [ebx+UI32._7]
.text:0042E682 shl esi, 18h
.text:0042E685 or esi, edi
.text:0042E687 mov edi, [ebx+UI32._7]
.text:0042E68A shr ebp, 18h
.text:0042E68D and esi, 0FF00FF00h
.text:0042E693 shl edi, 8
.text:0042E696 or edi, ebp
.text:0042E698 and edi, 0FF00FFh
.text:0042E69E or esi, edi
.text:0042E6A0 mov [ebx+UI32._7], esi
.text:0042E6A3 mov edi, [esp+14h+A]
.text:0042E6A7 xor edi, eax_B
.text:0042E6A9 and edi, [esp+14h+E]
.text:0042E6AD mov ebp, ecx_D
.text:0042E6AF xor edi, eax_B
.text:0042E6B1 add esi, edi
.text:0042E6B3 mov edi, ecx_D
.text:0042E6B5 shl edi, 5
.text:0042E6B8 shr ebp, 1Bh
.text:0042E6BB or edi, ebp
.text:0042E6BD add esi, edi
.text:0042E6BF mov edi, [esp+14h+E]
.text:0042E6C3 add esi, 5A827999h ; <suspicious>
.text:0042E6C9 add edx_C, esi
.text:0042E6CB mov esi, [esp+14h+E]
.text:0042E6CF shl esi, 1Eh
.text:0042E6D2 shr edi, 2
.text:0042E6D5 or esi, edi
.text:0042E6D7 mov [esp+14h+E], esi ; (8). R0(D,E,A,B,C, &buf[7])
.text:0042E6D7 ; ***********************第8次运算结束****
.text:0042E6D7 ;
.text:0042E6D7 ;
.text:0042E6DB mov esi, [ebx+UI32._8] ; ***********************第9次运算开始****
.text:0042E6DE mov edi, [ebx+UI32._8]
.text:0042E6E1 shr edi, 8
.text:0042E6E4 mov ebp, [ebx+UI32._8]
.text:0042E6E7 shl esi, 18h
.text:0042E6EA or esi, edi
.text:0042E6EC mov edi, [ebx+UI32._8]
.text:0042E6EF shl edi, 8
.text:0042E6F2 and esi, 0FF00FF00h
.text:0042E6F8 shr ebp, 18h
.text:0042E6FB or edi, ebp
.text:0042E6FD mov ebp, edx_C
.text:0042E6FF and edi, 0FF00FFh
.text:0042E705 or esi, edi
.text:0042E707 mov [ebx+UI32._8], esi
.text:0042E70A mov edi, [esp+14h+E]
.text:0042E70E xor edi, [esp+14h+A]
.text:0042E712 and edi, ecx_D
.text:0042E714 xor edi, [esp+14h+A]
.text:0042E718 add esi, edi
.text:0042E71A mov edi, edx_C
.text:0042E71C shl edi, 5
.text:0042E71F shr ebp, 1Bh
.text:0042E722 or edi, ebp
.text:0042E724 mov ebp, [ebx+UI32._9]
.text:0042E727 add esi, edi
.text:0042E729 mov edi, [ebx+UI32._9]
.text:0042E72C add esi, 5A827999h ; <suspicious>
.text:0042E732 add eax_B, esi
.text:0042E734 mov esi, ecx_D
.text:0042E736 shr ecx_D, 2
.text:0042E739 shl esi, 1Eh
.text:0042E73C or esi, ecx_D
.text:0042E73E mov ecx_D, esi ; (9). R0(C,D,E,A,B, &buf[8])
.text:0042E73E ; ***********************第9次运算结束****
.text:0042E73E ;
.text:0042E73E ;
.text:0042E740 mov esi, [ebx+UI32._9] ; ***********************第10次运算开始****
.text:0042E743 shl esi, 18h
.text:0042E746 shr edi, 8
.text:0042E749 or esi, edi
.text:0042E74B mov edi, [ebx+UI32._9]
.text:0042E74E shl edi, 8
.text:0042E751 and esi, 0FF00FF00h
.text:0042E757 shr ebp, 18h
.text:0042E75A or edi, ebp
.text:0042E75C mov ebp, eax_B
.text:0042E75E and edi, 0FF00FFh
.text:0042E764 or esi, edi
.text:0042E766 mov [ebx+UI32._9], esi
.text:0042E769 mov edi, [esp+14h+E]
.text:0042E76D xor edi, ecx_D
.text:0042E76F and edi, edx_C
.text:0042E771 xor edi, [esp+14h+E]
.text:0042E775 add esi, edi
.text:0042E777 mov edi, eax_B
.text:0042E779 shl edi, 5
.text:0042E77C shr ebp, 1Bh
.text:0042E77F or edi, ebp
.text:0042E781 add esi, edi
.text:0042E783 add esi, 5A827999h ; <suspicious>
.text:0042E789 add [esp+14h+A], esi
.text:0042E78D mov esi, edx_C
.text:0042E78F shr edx_C, 2
.text:0042E792 mov edi, [ebx+UI32._10]
.text:0042E795 shl esi, 1Eh
.text:0042E798 mov ebp, [ebx+UI32._10]
.text:0042E79B or esi, edx_C
.text:0042E79D mov edx_C, esi ; (10). R0(B,C,D,E,A, &buf[9])
.text:0042E79D ; ***********************第10次运算end****
.text:0042E79D ;
.text:0042E79D ;
.text:0042E79F mov esi, [ebx+UI32._10] ; ***********************第11次运算开始****
.text:0042E7A2 shl esi, 18h
.text:0042E7A5 shr edi, 8
.text:0042E7A8 or esi, edi
.text:0042E7AA mov edi, [ebx+UI32._10]
.text:0042E7AD shl edi, 8
.text:0042E7B0 and esi, 0FF00FF00h
.text:0042E7B6 shr ebp, 18h
.text:0042E7B9 or edi, ebp
.text:0042E7BB and edi, 0FF00FFh
.text:0042E7C1 or esi, edi
.text:0042E7C3 mov edi, ecx_D
.text:0042E7C5 xor edi, edx_C
.text:0042E7C7 mov [ebx+UI32._10], esi
.text:0042E7CA and edi, eax_B
.text:0042E7CC mov ebp, [esp+14h+A]
.text:0042E7D0 xor edi, ecx_D
.text:0042E7D2 add esi, edi
.text:0042E7D4 mov edi, [esp+14h+A]
.text:0042E7D8 shl edi, 5
.text:0042E7DB shr ebp, 1Bh
.text:0042E7DE or edi, ebp
.text:0042E7E0 add esi, edi
.text:0042E7E2 add esi, 5A827999h ; <suspicious>
.text:0042E7E8 add [esp+14h+E], esi
.text:0042E7EC mov esi, eax_B
.text:0042E7EE shr eax_B, 2
.text:0042E7F1 mov edi, [ebx+UI32._11]
.text:0042E7F4 shl esi, 1Eh
.text:0042E7F7 mov ebp, [ebx+UI32._11]
.text:0042E7FA or esi, eax_B
.text:0042E7FC mov eax_B, esi ; (11). R0(A,B,C,D,E, &buf[10])
.text:0042E7FC ; ***********************第11次运算end****
.text:0042E7FC ;
.text:0042E7FC ;
.text:0042E7FE mov esi, [ebx+UI32._11] ; ***********************第12次运算开始****
.text:0042E801 shl esi, 18h
.text:0042E804 shr edi, 8
.text:0042E807 or esi, edi
.text:0042E809 mov edi, [ebx+UI32._11]
.text:0042E80C shl edi, 8
.text:0042E80F and esi, 0FF00FF00h
.text:0042E815 shr ebp, 18h
.text:0042E818 or edi, ebp
.text:0042E81A and edi, 0FF00FFh
.text:0042E820 or esi, edi
.text:0042E822 mov edi, edx_C
.text:0042E824 mov [ebx+UI32._11], esi
.text:0042E827 xor edi, eax_B
.text:0042E829 and edi, [esp+14h+A]
.text:0042E82D mov ebp, [esp+14h+E]
.text:0042E831 xor edi, edx_C
.text:0042E833 add esi, edi
.text:0042E835 mov edi, [esp+14h+E]
.text:0042E839 shl edi, 5
.text:0042E83C shr ebp, 1Bh
.text:0042E83F or edi, ebp
.text:0042E841 add esi, edi
.text:0042E843 mov edi, [esp+14h+A]
.text:0042E847 add esi, 5A827999h ; <suspicious>
.text:0042E84D add ecx_D, esi
.text:0042E84F mov esi, [esp+14h+A]
.text:0042E853 shl esi, 1Eh
.text:0042E856 shr edi, 2
.text:0042E859 or esi, edi
.text:0042E85B mov [esp+14h+A], esi ; (12). R0(E,A,B,C,D, &buf[11])
.text:0042E85B ; ***********************第12次运算end****
.text:0042E85B ;
.text:0042E85B ;
.text:0042E85F mov esi, [ebx+UI32._12] ; ***********************第13次运算开始****
.text:0042E862 mov edi, [ebx+UI32._12]
.text:0042E865 shr edi, 8
.text:0042E868 mov ebp, [ebx+UI32._12]
.text:0042E86B shl esi, 18h
.text:0042E86E or esi, edi
.text:0042E870 mov edi, [ebx+UI32._12]
.text:0042E873 shl edi, 8
.text:0042E876 and esi, 0FF00FF00h
.text:0042E87C shr ebp, 18h
.text:0042E87F or edi, ebp
.text:0042E881 mov ebp, ecx_D
.text:0042E883 and edi, 0FF00FFh
.text:0042E889 or esi, edi
.text:0042E88B mov [ebx+UI32._12], esi
.text:0042E88E mov edi, [esp+14h+A]
.text:0042E892 xor edi, eax_B
.text:0042E894 and edi, [esp+14h+E]
.text:0042E898 xor edi, eax_B
.text:0042E89A add esi, edi
.text:0042E89C mov edi, ecx_D
.text:0042E89E shl edi, 5
.text:0042E8A1 shr ebp, 1Bh
.text:0042E8A4 or edi, ebp
.text:0042E8A6 add esi, edi
.text:0042E8A8 mov edi, [esp+14h+E]
.text:0042E8AC add esi, 5A827999h ; <suspicious>
.text:0042E8B2 add edx_C, esi
.text:0042E8B4 mov esi, [esp+14h+E]
.text:0042E8B8 shl esi, 1Eh
.text:0042E8BB shr edi, 2
.text:0042E8BE or esi, edi
.text:0042E8C0 mov [esp+14h+E], esi ; (13). R0(D,E,A,B,C, &buf[12])
.text:0042E8C0 ; ***********************第13次运算end****
.text:0042E8C0 ;
.text:0042E8C0 ;
.text:0042E8C4 mov esi, [ebx+UI32._13] ; ***********************第14次运算开始****
.text:0042E8C7 mov edi, [ebx+UI32._13]
.text:0042E8CA shr edi, 8
.text:0042E8CD mov ebp, [ebx+UI32._13]
.text:0042E8D0 shl esi, 18h
.text:0042E8D3 or esi, edi
.text:0042E8D5 mov edi, [ebx+UI32._13]
.text:0042E8D8 shl edi, 8
.text:0042E8DB and esi, 0FF00FF00h
.text:0042E8E1 shr ebp, 18h
.text:0042E8E4 or edi, ebp
.text:0042E8E6 mov ebp, edx_C
.text:0042E8E8 and edi, 0FF00FFh
.text:0042E8EE or esi, edi
.text:0042E8F0 mov [ebx+UI32._13], esi
.text:0042E8F3 mov edi, [esp+14h+E]
.text:0042E8F7 xor edi, [esp+14h+A]
.text:0042E8FB and edi, ecx_D
.text:0042E8FD xor edi, [esp+14h+A]
.text:0042E901 add esi, edi
.text:0042E903 mov edi, edx_C
.text:0042E905 shl edi, 5
.text:0042E908 shr ebp, 1Bh
.text:0042E90B or edi, ebp
.text:0042E90D mov ebp, [ebx+UI32._14]
.text:0042E910 add esi, edi
.text:0042E912 mov edi, [ebx+UI32._14]
.text:0042E915 add esi, 5A827999h ; <suspicious>
.text:0042E91B add eax_B, esi
.text:0042E91D mov esi, ecx_D
.text:0042E91F shr ecx_D, 2
.text:0042E922 shl esi, 1Eh
.text:0042E925 or esi, ecx_D
.text:0042E927 mov ecx_D, esi ; (14). R0(C,D,E,A,B, &buf[13])
.text:0042E927 ; ***********************第14次运算end****
.text:0042E927 ;
.text:0042E927 ;
.text:0042E929 mov esi, [ebx+UI32._14] ; ***********************第15次运算开始****
.text:0042E92C shl esi, 18h
.text:0042E92F shr edi, 8
.text:0042E932 or esi, edi
.text:0042E934 mov edi, [ebx+UI32._14]
.text:0042E937 shl edi, 8
.text:0042E93A and esi, 0FF00FF00h
.text:0042E940 shr ebp, 18h
.text:0042E943 or edi, ebp
.text:0042E945 mov ebp, eax_B
.text:0042E947 and edi, 0FF00FFh
.text:0042E94D or esi, edi
.text:0042E94F mov [ebx+UI32._14], esi
.text:0042E952 mov edi, [esp+14h+E]
.text:0042E956 xor edi, ecx_D
.text:0042E958 and edi, edx_C
.text:0042E95A xor edi, [esp+14h+E]
.text:0042E95E add esi, edi
.text:0042E960 mov edi, eax_B
.text:0042E962 shl edi, 5
.text:0042E965 shr ebp, 1Bh
.text:0042E968 or edi, ebp
.text:0042E96A add esi, edi
.text:0042E96C add esi, 5A827999h ; <suspicious>
.text:0042E972 add [esp+14h+A], esi
.text:0042E976 mov esi, edx_C
.text:0042E978 shr edx_C, 2
.text:0042E97B mov edi, [ebx+UI32._15]
.text:0042E97E shl esi, 1Eh
.text:0042E981 mov ebp, [ebx+UI32._15]
.text:0042E984 or esi, edx_C
.text:0042E986 mov edx_C, esi ; (15). R0(B,C,D,E,A, &buf[14])
.text:0042E986 ; ***********************第15次运算end****
.text:0042E986 ;
.text:0042E986 ;
.text:0042E988 mov esi, [ebx+UI32._15] ; ***********************第16次运算开始****
.text:0042E98B shl esi, 18h ; buf[15]<<24
.text:0042E98E shr edi, 8 ; buf[15]>>8
.text:0042E991 or esi, edi ; RL(buf[15],24)
.text:0042E993 mov edi, [ebx+UI32._15]
.text:0042E996 shr ebp, 18h ; buf[15]>>24
.text:0042E999 and esi, 0FF00FF00h ; RL(buf[15],24)&0xff00ff00
.text:0042E99F shl edi, 8 ; buf[15]<<8
.text:0042E9A2 or edi, ebp ; RL(buf[15],8)
.text:0042E9A4 and edi, 0FF00FFh ; RL(buf[15],8)&0xff00ff
.text:0042E9AA or esi, edi ; RE(buf[15])
.text:0042E9AC mov edi, ecx_D
.text:0042E9AE xor edi, edx_C ; (C^D)
.text:0042E9B0 mov [ebx+UI32._15], esi ; buf[15] = RE(buf[15])
.text:0042E9B3 and edi, eax_B ; (C^D)&B
.text:0042E9B5 mov ebp, [esp+14h+A]
.text:0042E9B9 xor edi, ecx_D ; RX(B,C,D) = ((C^D)&B)^D
.text:0042E9BB add esi, edi ; RE(buf[15]) + RX(B,C,D)
.text:0042E9BD mov edi, [esp+14h+A]
.text:0042E9C1 shl edi, 5 ; A<<5
.text:0042E9C4 shr ebp, 1Bh ; A>>30
.text:0042E9C7 or edi, ebp ; RL(A,5)
.text:0042E9C9 add esi, edi ; RE(buf[15]) + RX(B,C,D) + RL(A,5)
.text:0042E9CB add esi, 5A827999h ; <suspicious>
.text:0042E9D1 add [esp+14h+E], esi ; E += RE(buf[15]) + RX(B,C,D) + RL(A,5) + 0x5a827999;
.text:0042E9D5 mov esi, eax_B
.text:0042E9D7 shr eax_B, 2 ; B>>2
.text:0042E9DA mov edi, [ebx+UI32._13]
.text:0042E9DD shl esi, 1Eh ; B<<30
.text:0042E9E0 xor edi, [ebx+UI32._8] ; buf[13] ^ buf[8]
.text:0042E9E3 or esi, eax_B ; RL(B,30)
.text:0042E9E5 xor edi, [ebx+UI32._2] ; buf[13] ^ buf[8] ^ buf[2]
.text:0042E9E8 mov eax_B, esi ; B = RL(B,30)
.text:0042E9E8 ; (16). R0(A,B,C,D,E, &buf[15])
.text:0042E9E8 ; ***********************第16次运算end****
.text:0042E9E8 ;
.text:0042E9E8 ;
.text:0042E9EA mov esi, [ebx+UI32._13] ; ***********************第17次运算开始****
.text:0042E9ED xor esi, [ebx+UI32._8] ; buf[13]^buf[8]
.text:0042E9F0 xor edi, [ebx+UI32._0] ; buf[13] ^ buf[8] ^ buf[2] ^ buf[0]
.text:0042E9F2 xor esi, [ebx+UI32._2] ; buf[13] ^ buf[8] ^ buf[2]
.text:0042E9F5 xor esi, [ebx+UI32._0] ; buf[13] ^ buf[8] ^ buf[2] ^ buf[0]
.text:0042E9F7 shr edi, 1Fh ; (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]) >> 31
.text:0042E9FA add esi, esi ; (buf[13] ^ buf[8] ^ buf[2] ^ buf[0])<<1
.text:0042E9FA ; 这里把++转换成左移1bit是为了下面用RL运算
.text:0042E9FC or esi, edi ; RL((buf[13] ^ buf[8] ^ buf[2] ^ buf[0]),1) =
.text:0042E9FC ; ((buf[13] ^ buf[8] ^ buf[2] ^ buf[0])<<1) |
.text:0042E9FC ; ((buf[13] ^ buf[8] ^ buf[2] ^ buf[0])>>(32-1))
.text:0042E9FE mov edi, edx_C
.text:0042EA00 mov [ebx+UI32._0], esi ; buf[0] = RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]), 1)
.text:0042EA00 ; buf又从[0]开始参与运算
.text:0042EA02 xor edi, eax_B ; (B^C)
.text:0042EA04 and edi, [esp+14h+A] ; (B^C)&A
.text:0042EA08 mov ebp, [esp+14h+E]
.text:0042EA0C xor edi, edx_C ; RX(A,B,C) = ((B^C)&A)^C
.text:0042EA0E add esi, edi ; RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]),1) + RX(A,B,C)
.text:0042EA10 mov edi, [esp+14h+E]
.text:0042EA14 shl edi, 5 ; E<<5
.text:0042EA17 shr ebp, 1Bh ; E>>27
.text:0042EA1A or edi, ebp ; RL(E,5)
.text:0042EA1C add esi, edi ; RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]),1) + RX(A,B,C) + RL(E,5)
.text:0042EA1E mov edi, [esp+14h+A]
.text:0042EA22 add esi, 5A827999h ; <suspicious>
.text:0042EA28 add ecx_D, esi ; D += RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]),1) + RX(A,B,C) + RL(E,5) + 0x5a827999
.text:0042EA2A mov esi, [esp+14h+A]
.text:0042EA2E shl esi, 1Eh ; A<<30
.text:0042EA31 mov ebp, ecx_D
.text:0042EA33 shr edi, 2 ; A>>2
.text:0042EA36 or esi, edi ; RL(A,30)
.text:0042EA38 mov [esp+14h+A], esi ; A = RL(A,30)
.text:0042EA38 ; 观察第17-20次运算不难得到如下数据:
.text:0042EA38 ; 17
.text:0042EA38 ; buf[0] = RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]), 1)
.text:0042EA38 ; D += RL( (buf[13] ^ buf[8] ^ buf[2] ^ buf[0]),1) + RX(A,B,C) + RL(E,5) + 0x5a827999
.text:0042EA38 ; A = RL(A,30)
.text:0042EA38 ;
.text:0042EA38 ; 18
.text:0042EA38 ; buf[1] = RL( (buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1)
.text:0042EA38 ; C += RL((buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1) + RX(E,A,B) + RL(D,5) + 0x5a827999;
.text:0042EA38 ; E = RL(E,30)
.text:0042EA38 ;
.text:0042EA38 ; 19
.text:0042EA38 ; buf[2] = RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1)
.text:0042EA38 ; B += RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1) + RX(D,E,A) + 0x5a827999
.text:0042EA38 ; D = RL(D,30)
.text:0042EA38 ;
.text:0042EA38 ; 20
.text:0042EA38 ; buf[3] = RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1)
.text:0042EA38 ; A += RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1) + RX(C,D,E) + RL(B,5) + 0x5a827999
.text:0042EA38 ; C = RL(C,30)
.text:0042EA38 ;
.text:0042EA38 ; (宏定义参考了Steve Reid的SHA1代码)
.text:0042EA38 ; 总结定义宏RXL:
.text:0042EA38 ; #define RXL(i)
.text:0042EA38 ; ( buf[i&15] = RL( (buf[(i+13)&15] ^ buf[(i+8)&15] ^ buf[(i+2)&15] ^ buf[i&15]), 1) )
.text:0042EA38 ;
.text:0042EA38 ; 定义宏R1:
.text:0042EA38 ; #define R1(a,b,c,d,e, i)
.text:0042EA38 ; ( e+=RXL(i)+RX(b,c,d)+RL(a,5)+0x5a827999;b=RL(b,30); )
.text:0042EA38 ;
.text:0042EA38 ; 那么第17次运算表示为:
.text:0042EA38 ; R1(E,A,B,C,D, 16)
.text:0042EA38 ; ***********************第17次运算end****
.text:0042EA38 ;
.text:0042EA38 ;
.text:0042EA3C mov edi, [ebx+UI32._14] ; 根据R1,RXL宏, 修改RE,R0:
.text:0042EA3C ;
.text:0042EA3C ; #define RE(i) ( buf[i] = (RL(buf[i],24)&0xff00ff00) | (RL(buf[i],8)&0x0ff00ff) )
.text:0042EA3C ;
.text:0042EA3C ; #define R0(a,b,c,d,e,i) ( e+=RE(i)+RX(b,c,d)+RL(a,5)+0x5a827999; b=RL(b,30); )
.text:0042EA3C ;
.text:0042EA3C ; 那前16次就要改为:
.text:0042EA3C ; R0(A,B,C,D,E,0);
.text:0042EA3C ; R0(E,A,B,C,D,1);
.text:0042EA3C ; R0(D,E,A,B,C,2);
.text:0042EA3C ; R0(C,D,E,A,B,3);
.text:0042EA3C ; R0(B,C,D,E,A,4);
.text:0042EA3C ; R0(A,B,C,D,E,5);
.text:0042EA3C ; ....
.text:0042EA3C ; R0(A,B,C,D,E,15)
.text:0042EA3C ; ***********************第18次运算开始****
.text:0042EA3F mov esi, [ebx+UI32._14]
.text:0042EA42 xor edi, [ebx+UI32._9] ; buf[14] ^ buf[9]
.text:0042EA45 xor esi, [ebx+UI32._9] ; buf[14] ^ buf[9]
.text:0042EA48 xor edi, [ebx+UI32._3] ; buf[14] ^ buf[9] ^ buf[3]
.text:0042EA4B xor esi, [ebx+UI32._3] ; buf[14] ^ buf[9] ^ buf[3]
.text:0042EA4E xor edi, [ebx+UI32._1] ; buf[14] ^ buf[9] ^ buf[3] ^ buf[1]
.text:0042EA51 xor esi, [ebx+UI32._1] ; buf[14] ^ buf[9] ^ buf[3] ^ buf[1]
.text:0042EA54 shr edi, 1Fh ; (buf[14] ^ buf[9] ^ buf[3] ^ buf[1])>>31
.text:0042EA57 add esi, esi ; (buf[14] ^ buf[9] ^ buf[3] ^ buf[1])<<1
.text:0042EA59 or esi, edi ; RL((buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1)
.text:0042EA5B mov [ebx+UI32._1], esi ; buf[1] = RL( (buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1)
.text:0042EA5E mov edi, [esp+14h+A]
.text:0042EA62 xor edi, eax_B ; A^B
.text:0042EA64 and edi, [esp+14h+E] ; (A^B)&E
.text:0042EA68 xor edi, eax_B ; RX(E,A,B) = ((A^B)&E)^B
.text:0042EA6A add esi, edi ; RL((buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1) + RX(E,A,B)
.text:0042EA6C mov edi, ecx_D
.text:0042EA6E shl edi, 5 ; D<<5
.text:0042EA71 shr ebp, 1Bh ; D>>27
.text:0042EA74 or edi, ebp ; RL(D,5)
.text:0042EA76 add esi, edi ; RL((buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1) + RX(E,A,B) + RL(D,5)
.text:0042EA78 mov edi, [esp+14h+E]
.text:0042EA7C add esi, 5A827999h ; <suspicious>
.text:0042EA82 add edx_C, esi ; C += RL((buf[14] ^ buf[9] ^ buf[3] ^ buf[1]),1) + RX(E,A,B) + RL(D,5)+ 0x5a827999;
.text:0042EA84 mov esi, [esp+14h+E]
.text:0042EA88 shl esi, 1Eh ; E<<30
.text:0042EA8B mov ebp, edx_C
.text:0042EA8D shr edi, 2 ; E>>2
.text:0042EA90 or esi, edi ; RL(E,30)
.text:0042EA92 mov [esp+14h+E], esi ; E = RL(E,30);
.text:0042EA92 ;
.text:0042EA92 ; R1(D,E,A,B,C,17)
.text:0042EA92 ; ***********************第18次运算end****
.text:0042EA92 ;
.text:0042EA92 ;
.text:0042EA96 mov edi, [ebx+UI32._15] ; ***********************第19次运算开始****
.text:0042EA99 mov esi, [ebx+UI32._15]
.text:0042EA9C xor edi, [ebx+UI32._10] ; buf[15] ^ buf[10]
.text:0042EA9F xor esi, [ebx+UI32._10]
.text:0042EAA2 xor edi, [ebx+UI32._4] ; buf[15] ^ buf[10] ^ buf[4]
.text:0042EAA5 xor esi, [ebx+UI32._4]
.text:0042EAA8 xor edi, [ebx+UI32._2] ; buf[15] ^ buf[10] ^ buf[4] ^ buf[2]
.text:0042EAAB xor esi, [ebx+UI32._2]
.text:0042EAAE shr edi, 1Fh ; (buf[15] ^ buf[10] ^ buf[4] ^ buf[2])>>31
.text:0042EAB1 add esi, esi ; (buf[15] ^ buf[10] ^ buf[4] ^ buf[2])<<1
.text:0042EAB3 or esi, edi ; RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1)
.text:0042EAB5 mov [ebx+UI32._2], esi ; buf[2] = RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1)
.text:0042EAB8 mov edi, [esp+14h+E]
.text:0042EABC xor edi, [esp+14h+A] ; E^A
.text:0042EAC0 and edi, ecx_D ; (E^A)&D
.text:0042EAC2 xor edi, [esp+14h+A] ; RX(D,E,A) = ((E^A)&D)^A
.text:0042EAC6 add esi, edi ; RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1) + RX(D,E,A)
.text:0042EAC8 mov edi, edx_C
.text:0042EACA shl edi, 5 ; C<<5
.text:0042EACD shr ebp, 1Bh ; C>>27
.text:0042EAD0 or edi, ebp ; RL(C,5)
.text:0042EAD2 add esi, edi ; RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1) + RX(D,E,A) + RL(C,5)
.text:0042EAD4 mov edi, [ebx+UI32._0]
.text:0042EAD6 add esi, 5A827999h ; <suspicious>
.text:0042EADC xor edi, [ebx+UI32._11]
.text:0042EADF add eax_B, esi ; B += RL( (buf[15] ^ buf[10] ^ buf[4] ^ buf[2]),1) + RX(D,E,A) + 0x5a827999
.text:0042EAE1 mov esi, ecx_D
.text:0042EAE3 shr ecx_D, 2 ; D>>2
.text:0042EAE6 mov ebp, eax_B
.text:0042EAE8 shl esi, 1Eh ; D<<30
.text:0042EAEB xor edi, [ebx+UI32._5]
.text:0042EAEE or esi, ecx_D ; RL(D,30)
.text:0042EAF0 xor edi, [ebx+UI32._3] ; buf[0] ^ buf[11] ^ buf[5] ^ buf[3]
.text:0042EAF3 mov ecx_D, esi ; D = RL(D,30)
.text:0042EAF3 ;
.text:0042EAF3 ; 19). R1(C,D,E,A,B,18)
.text:0042EAF3 ; ***********************第19次运算end****
.text:0042EAF3 ;
.text:0042EAF3 ;
.text:0042EAF5 mov esi, [ebx+UI32._0] ; ***********************第20次运算开始****
.text:0042EAF7 xor esi, [ebx+UI32._11] ; buf[0] ^ buf[11]
.text:0042EAFA xor esi, [ebx+UI32._5] ; buf[0] ^ buf[11] ^ buf[5]
.text:0042EAFD xor esi, [ebx+UI32._3] ; buf[0] ^ buf[11] ^ buf[5] ^ buf[3]
.text:0042EB00 shr edi, 1Fh ; (buf[0] ^ buf[11] ^ buf[5] ^ buf[3]) >>31
.text:0042EB03 add esi, esi ; (buf[0] ^ buf[11] ^ buf[5] ^ buf[3])<<1
.text:0042EB05 or esi, edi ; RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1)
.text:0042EB07 mov [ebx+UI32._3], esi ; buf[3] = RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1)
.text:0042EB0A mov edi, [esp+14h+E]
.text:0042EB0E xor edi, ecx_D ; D^E
.text:0042EB10 and edi, edx_C ; (D^E)&C
.text:0042EB12 xor edi, [esp+14h+E] ; RX(C,D,E) = ((D^E)&C)^E
.text:0042EB16 add esi, edi ; RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1) + RX(C,D,E)
.text:0042EB18 mov edi, eax_B
.text:0042EB1A shl edi, 5 ; B<<5
.text:0042EB1D shr ebp, 1Bh ; B>>27
.text:0042EB20 or edi, ebp ; RL(B,5)
.text:0042EB22 add esi, edi ; RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1) + RX(C,D,E) + RL(B,5)
.text:0042EB24 add esi, 5A827999h ; <suspicious>
.text:0042EB2A add [esp+14h+A], esi ; A += RL((buf[0] ^ buf[11] ^ buf[5] ^ buf[3]),1) + RX(C,D,E) + RL(B,5) + 0x5a827999
.text:0042EB2E mov esi, edx_C
.text:0042EB30 shr edx_C, 2 ; C>>2
.text:0042EB33 mov edi, [ebx+UI32._1]
.text:0042EB36 shl esi, 1Eh ; C<<30
.text:0042EB39 xor edi, [ebx+UI32._12]
.text:0042EB3C or esi, edx_C ; RL(C,30)
.text:0042EB3E xor edi, [ebx+UI32._6]
.text:0042EB41 mov edx_C, esi ; C = RL(C,30)
.text:0042EB41 ;
.text:0042EB41 ; 20). R1(B,C,D,E,A,19)
.text:0042EB41 ; ***********************第20次运算end****
.text:0042EB41 ; ***********************第1轮计算结束****