XXX人力资源管理系统 算法分析+注册机源码
本软件加了穿山甲的壳,懒得脱壳了,就带壳调试,运行程序进行注册,输入注册码,确定,出现“注册失败”。ctrl+G “00401000”查找字符串。
地址=00550819 反汇编=PUSH 004169C8 文本字串=注册失败!
双击到下面。找到句首:
005503C1 55 PUSH EBP ; (初始 cpu 选择)
005503C2 8BEC MOV EBP,ESP
005503C4 81EC 18000000 SUB ESP,18
005503CA C745 FC 00000000 MOV DWORD PTR SS:,0
005503D1 6A FF PUSH -1
005503D3 6A 08 PUSH 8
005503D5 68 412D0116 PUSH 16012D41
005503DA 68 372D0152 PUSH 52012D37
005503DF E8 1F0D0B00 CALL 00601103 ; 取第一段注册假码
005503E4 83C4 10 ADD ESP,10
005503E7 8945 F8 MOV DWORD PTR SS:,EAX
005503EA 6A FF PUSH -1
005503EC 6A 08 PUSH 8
005503EE 68 402D0116 PUSH 16012D40
005503F3 68 372D0152 PUSH 52012D37
005503F8 E8 060D0B00 CALL 00601103 ; 取第二段注册假码
005503FD 83C4 10 ADD ESP,10
00550400 8945 F4 MOV DWORD PTR SS:,EAX
00550403 6A FF PUSH -1
00550405 6A 08 PUSH 8
00550407 68 3F2D0116 PUSH 16012D3F
0055040C 68 372D0152 PUSH 52012D37
00550411 E8 ED0C0B00 CALL 00601103 ; 取第三段注册假码
00550416 83C4 10 ADD ESP,10
00550419 8945 F0 MOV DWORD PTR SS:,EAX
0055041C 6A FF PUSH -1
0055041E 6A 08 PUSH 8
00550420 68 3E2D0116 PUSH 16012D3E
00550425 68 372D0152 PUSH 52012D37
0055042A E8 D40C0B00 CALL 00601103 ; 取第四段注册假码
0055042F 83C4 10 ADD ESP,10
00550432 8945 EC MOV DWORD PTR SS:,EAX
00550435 FF75 EC PUSH DWORD PTR SS:
00550438 68 115B4100 PUSH 00415B11 ; -
0055043D FF75 F0 PUSH DWORD PTR SS:
00550440 68 115B4100 PUSH 00415B11 ; -
00550445 FF75 F4 PUSH DWORD PTR SS:
00550448 68 115B4100 PUSH 00415B11 ; -
0055044D FF75 F8 PUSH DWORD PTR SS:
00550450 B9 07000000 MOV ECX,7
00550455 E8 CDD7FDFF CALL 0052DC27
0055045A 83C4 1C ADD ESP,1C
0055045D 8945 E8 MOV DWORD PTR SS:,EAX
00550460 8B5D F8 MOV EBX,DWORD PTR SS:
00550463 85DB TEST EBX,EBX
00550465 74 09 JE SHORT 00550470
00550467 53 PUSH EBX
00550468 E8 7E0C0B00 CALL 006010EB
0055046D 83C4 04 ADD ESP,4
00550470 8B5D F4 MOV EBX,DWORD PTR SS:
00550473 85DB TEST EBX,EBX
00550475 74 09 JE SHORT 00550480
00550477 53 PUSH EBX
00550478 E8 6E0C0B00 CALL 006010EB
0055047D 83C4 04 ADD ESP,4
00550480 8B5D F0 MOV EBX,DWORD PTR SS:
00550483 85DB TEST EBX,EBX
00550485 74 09 JE SHORT 00550490
00550487 53 PUSH EBX
00550488 E8 5E0C0B00 CALL 006010EB
0055048D 83C4 04 ADD ESP,4
00550490 8B5D EC MOV EBX,DWORD PTR SS:
00550493 85DB TEST EBX,EBX
00550495 74 09 JE SHORT 005504A0
00550497 53 PUSH EBX
00550498 E8 4E0C0B00 CALL 006010EB
0055049D 83C4 04 ADD ESP,4
005504A0 8B45 E8 MOV EAX,DWORD PTR SS:
005504A3 50 PUSH EAX
005504A4 8B5D FC MOV EBX,DWORD PTR SS:
005504A7 85DB TEST EBX,EBX
005504A9 74 09 JE SHORT 005504B4
005504AB 53 PUSH EBX
005504AC E8 3A0C0B00 CALL 006010EB
005504B1 83C4 04 ADD ESP,4
005504B4 58 POP EAX
005504B5 8945 FC MOV DWORD PTR SS:,EAX
005504B8 68 04000080 PUSH 80000004
005504BD 6A 00 PUSH 0
005504BF 8B45 FC MOV EAX,DWORD PTR SS:
005504C2 85C0 TEST EAX,EAX
005504C4 75 05 JNZ SHORT 005504CB
005504C6 B8 C8144100 MOV EAX,004114C8
005504CB 50 PUSH EAX
005504CC 68 01000000 PUSH 1
005504D1 BB 50010000 MOV EBX,150
005504D6 E8 2E0C0B00 CALL 00601109
005504DB 83C4 10 ADD ESP,10
005504DE 8945 F8 MOV DWORD PTR SS:,EAX
005504E1 8B45 F8 MOV EAX,DWORD PTR SS:
005504E4 50 PUSH EAX
005504E5 FF35 C84CDC01 PUSH DWORD PTR DS: ;真码出现 "17BE3-BCA66-CE9F6-0C7E1")
005504EB E8 41EDFDFF CALL 0052F231
005504F0 83C4 08 ADD ESP,8
005504F3 83F8 00 CMP EAX,0
005504F6 B8 00000000 MOV EAX,0
005504FB 0F94C0 SETE AL
005504FE 8945 F4 MOV DWORD PTR SS:,EAX
00550501 8B5D F8 MOV EBX,DWORD PTR SS:
00550504 85DB TEST EBX,EBX
00550506 74 09 JE SHORT 00550511
00550508 53 PUSH EBX
00550509 E8 DD0B0B00 CALL 006010EB
0055050E 83C4 04 ADD ESP,4
00550511 837D F4 00 CMP DWORD PTR SS:,0
00550515 0F84 0B010000 JE 00550626 //跳向失败
0055051B 68 04000080 PUSH 80000004
00550520 6A 00 PUSH 0
00550522 68 C8144100 PUSH 004114C8
00550527 68 04000080 PUSH 80000004
0055052C 6A 00 PUSH 0
0055052E 68 DF684100 PUSH 004168DF ; software\microsoft\windows\currentversion\policies\dt\rs
00550533 68 01030080 PUSH 80000301
00550538 6A 00 PUSH 0
0055053A 68 04000000 PUSH 4
0055053F 68 03000000 PUSH 3
00550544 BB A4060000 MOV EBX,6A4
00550549 E8 BB0B0B00 CALL 00601109 //修改注册表,添加注册标志,添加项,rs(字符串),rsmm(DWORD)
0055054E 83C4 28 ADD ESP,28
00550551 FF35 CC4CDC01 PUSH DWORD PTR DS:
00550557 68 18694100 PUSH 00416918 ; XX人力资源管理系统 >>
0055055C B9 02000000 MOV ECX,2
00550561 E8 C1D6FDFF CALL 0052DC27
00550566 83C4 08 ADD ESP,8
00550569 8945 F8 MOV DWORD PTR SS:,EAX
0055056C 6A 00 PUSH 0
0055056E FF75 F8 PUSH DWORD PTR SS:
00550571 6A FF PUSH -1
00550573 6A 08 PUSH 8
00550575 68 00000106 PUSH 6010000
0055057A 68 01000152 PUSH 52010001
0055057F E8 790B0B00 CALL 006010FD
00550584 83C4 18 ADD ESP,18
00550587 8B5D F8 MOV EBX,DWORD PTR SS:
0055058A 85DB TEST EBX,EBX
0055058C 74 09 JE SHORT 00550597
0055058E 53 PUSH EBX
0055058F E8 570B0B00 CALL 006010EB
00550594 83C4 04 ADD ESP,4
00550597 6A 00 PUSH 0
00550599 6A 00 PUSH 0
0055059B 6A 00 PUSH 0
0055059D 68 01030080 PUSH 80000301
005505A2 6A 00 PUSH 0
005505A4 68 00000000 PUSH 0
005505A9 68 04000080 PUSH 80000004
005505AE 6A 00 PUSH 0
005505B0 68 31694100 PUSH 00416931 ; 您现在可以继续使用本软件;谢谢您的注册!
005505B5 68 03000000 PUSH 3
005505BA BB 00030000 MOV EBX,300
005505BF E8 450B0B00 CALL 00601109
005505C4 83C4 28 ADD ESP,28
005505C7 833D D04CDC01 00 CMP DWORD PTR DS:,0
005505CE 0F85 2C000000 JNZ 00550600
005505D4 6A 00 PUSH 0
005505D6 68 01000000 PUSH 1
005505DB 6A FF PUSH -1
005505DD 6A 05 PUSH 5
005505DF 68 00000106 PUSH 6010000
005505E4 68 01000152 PUSH 52010001
005505E9 E8 0F0B0B00 CALL 006010FD
005505EE 83C4 18 ADD ESP,18
005505F1 C705 D04CDC01 01000000 MOV DWORD PTR DS:,1
005505FB E9 00000000 JMP 00550600
00550600 68 01000100 PUSH 10001
00550605 68 362D0106 PUSH 6012D36
0055060A 68 372D0152 PUSH 52012D37
0055060F 68 01000000 PUSH 1
00550614 BB 60030000 MOV EBX,360
00550619 E8 EB0A0B00 CALL 00601109
0055061E 83C4 10 ADD ESP,10
00550621 E9 0A020000 JMP 00550830
00550626 68 04000080 PUSH 80000004
0055062B 6A 00 PUSH 0
0055062D 8B45 FC MOV EAX,DWORD PTR SS:
00550630 85C0 TEST EAX,EAX
00550632 75 05 JNZ SHORT 00550639
00550634 B8 C8144100 MOV EAX,004114C8
00550639 50 PUSH EAX
0055063A 68 01000000 PUSH 1
0055063F BB 50010000 MOV EBX,150
00550644 E8 C00A0B00 CALL 00601109
00550649 83C4 10 ADD ESP,10
0055064C 8945 F8 MOV DWORD PTR SS:,EAX
0055064F 8B45 F8 MOV EAX,DWORD PTR SS:
00550652 50 PUSH EAX
00550653 FF35 D44CDC01 PUSH DWORD PTR DS:;真码2出现"88102-986BC-4A061-AC9EB"
00550659 E8 D3EBFDFF CALL 0052F231
0055065E 83C4 08 ADD ESP,8
00550661 83F8 00 CMP EAX,0
00550664 B8 00000000 MOV EAX,0
00550669 0F94C0 SETE AL
0055066C 8945 F4 MOV DWORD PTR SS:,EAX
0055066F 8B5D F8 MOV EBX,DWORD PTR SS:
00550672 85DB TEST EBX,EBX
00550674 74 09 JE SHORT 0055067F
00550676 53 PUSH EBX
00550677 E8 6F0A0B00 CALL 006010EB
0055067C 83C4 04 ADD ESP,4
0055067F 837D F4 00 CMP DWORD PTR SS:,0
00550683 0F84 77010000 JE 00550800 //跳向失败
00550689 68 04000080 PUSH 80000004
0055068E 6A 00 PUSH 0
00550690 68 5A694100 PUSH 0041695A ; software\microsoft\windows\currentversion\policies\dt\rsbt
00550695 68 01030080 PUSH 80000301
0055069A 6A 00 PUSH 0
0055069C 68 04000000 PUSH 4
005506A1 68 02000000 PUSH 2
005506A6 BB AC060000 MOV EBX,6AC
005506AB E8 590A0B00 CALL 00601109 //修改注册表,添加注册标志,添加项,rsbt(字符串)
005506B0 83C4 1C ADD ESP,1C
005506B3 8945 F4 MOV DWORD PTR SS:,EAX
005506B6 837D F4 01 CMP DWORD PTR SS:,1
005506BA 0F85 35000000 JNZ 005506F5
005506C0 6A 00 PUSH 0
005506C2 6A 00 PUSH 0
005506C4 6A 00 PUSH 0
005506C6 68 01030080 PUSH 80000301
005506CB 6A 00 PUSH 0
005506CD 68 40000000 PUSH 40
005506D2 68 04000080 PUSH 80000004
005506D7 6A 00 PUSH 0
005506D9 68 95694100 PUSH 00416995 ; 您的注册码不正确,请联系XX软件取的正确的注册码!
005506DE 68 03000000 PUSH 3
005506E3 BB 00030000 MOV EBX,300
005506E8 E8 1C0A0B00 CALL 00601109
005506ED 83C4 28 ADD ESP,28
005506F0 E9 06010000 JMP 005507FB
005506F5 68 04000080 PUSH 80000004
005506FA 6A 00 PUSH 0
005506FC 68 C8144100 PUSH 004114C8
00550701 68 04000080 PUSH 80000004
00550706 6A 00 PUSH 0
00550708 68 5A694100 PUSH 0041695A ; software\microsoft\windows\currentversion\policies\dt\rsbt
0055070D 68 01030080 PUSH 80000301
00550712 6A 00 PUSH 0
00550714 68 04000000 PUSH 4
00550719 68 03000000 PUSH 3
0055071E BB A4060000 MOV EBX,6A4
00550723 E8 E1090B00 CALL 00601109
00550728 83C4 28 ADD ESP,28
0055072B FF35 CC4CDC01 PUSH DWORD PTR DS:
00550731 68 18694100 PUSH 00416918 ; XX人力资源管理系统 >>
00550736 B9 02000000 MOV ECX,2
0055073B E8 E7D4FDFF CALL 0052DC27
00550740 83C4 08 ADD ESP,8
00550743 8945 F8 MOV DWORD PTR SS:,EAX
00550746 6A 00 PUSH 0
00550748 FF75 F8 PUSH DWORD PTR SS:
0055074B 6A FF PUSH -1
0055074D 6A 08 PUSH 8
0055074F 68 00000106 PUSH 6010000
00550754 68 01000152 PUSH 52010001
00550759 E8 9F090B00 CALL 006010FD
0055075E 83C4 18 ADD ESP,18
00550761 8B5D F8 MOV EBX,DWORD PTR SS:
00550764 85DB TEST EBX,EBX
00550766 74 09 JE SHORT 00550771
00550768 53 PUSH EBX
00550769 E8 7D090B00 CALL 006010EB
0055076E 83C4 04 ADD ESP,4
00550771 6A 00 PUSH 0
00550773 6A 00 PUSH 0
00550775 6A 00 PUSH 0
00550777 68 01030080 PUSH 80000301
0055077C 6A 00 PUSH 0
0055077E 68 00000000 PUSH 0
00550783 68 04000080 PUSH 80000004
00550788 6A 00 PUSH 0
0055078A 68 31694100 PUSH 00416931 ; 您现在可以继续使用本软件;谢谢您的注册!
0055078F 68 03000000 PUSH 3
00550794 BB 00030000 MOV EBX,300
00550799 E8 6B090B00 CALL 00601109
0055079E 83C4 28 ADD ESP,28
005507A1 833D D04CDC01 00 CMP DWORD PTR DS:,0
005507A8 0F85 2C000000 JNZ 005507DA
005507AE 6A 00 PUSH 0
005507B0 68 01000000 PUSH 1
005507B5 6A FF PUSH -1
005507B7 6A 05 PUSH 5
005507B9 68 00000106 PUSH 6010000
005507BE 68 01000152 PUSH 52010001
005507C3 E8 35090B00 CALL 006010FD
005507C8 83C4 18 ADD ESP,18
005507CB C705 D04CDC01 01000000 MOV DWORD PTR DS:,1
005507D5 E9 00000000 JMP 005507DA
005507DA 68 01000100 PUSH 10001
005507DF 68 362D0106 PUSH 6012D36
005507E4 68 372D0152 PUSH 52012D37
005507E9 68 01000000 PUSH 1
005507EE BB 60030000 MOV EBX,360
005507F3 E8 11090B00 CALL 00601109
005507F8 83C4 10 ADD ESP,10
005507FB E9 30000000 JMP 00550830
00550800 6A 00 PUSH 0
00550802 6A 00 PUSH 0
00550804 6A 00 PUSH 0
00550806 68 01030080 PUSH 80000301
0055080B 6A 00 PUSH 0
0055080D 68 40000000 PUSH 40
00550812 68 04000080 PUSH 80000004
00550817 6A 00 PUSH 0
00550819 68 C8694100 PUSH 004169C8 ; 注册失败!
0055081E 68 03000000 PUSH 3
00550823 BB 00030000 MOV EBX,300
00550828 E8 DC080B00 CALL 00601109
分析一下算法:
下面是关键位置:
00589A7E /.55 PUSH EBP
00589A7F |.8BEC MOV EBP,ESP
00589A81 |.81EC 08000000 SUB ESP,8
00589A87 |.6A 01 PUSH 1
00589A89 |.B8 CA9D4100 MOV EAX,00419DCA ;ASCII "4411"固定值用于算注册码
00589A8E |.8945 FC MOV DWORD PTR SS:,EAX
00589A91 |.8D45 FC LEA EAX,DWORD PTR SS:
00589A94 |.50 PUSH EAX
00589A95 |.E8 E2000000 CALL 00589B7C //取机器码
00589A9A |.8945 F8 MOV DWORD PTR SS:,EAX
00589A9D |.8B5D FC MOV EBX,DWORD PTR SS:
00589AA0 |.85DB TEST EBX,EBX
00589AA2 |.74 09 JE SHORT 00589AAD
00589AA4 |.53 PUSH EBX
00589AA5 |.E8 41760700 CALL 006010EB
00589AAA |.83C4 04 ADD ESP,4
00589AAD |>8B45 F8 MOV EAX,DWORD PTR SS: //硬件码赋值给eax
00589AB0 |.50 PUSH EAX
00589AB1 |.8B1D 304DDC01 MOV EBX,DWORD PTR DS:
00589AB7 |.85DB TEST EBX,EBX
00589AB9 |.74 09 JE SHORT 00589AC4
00589ABB |.53 PUSH EBX
00589ABC |.E8 2A760700 CALL 006010EB
00589AC1 |.83C4 04 ADD ESP,4
00589AC4 |>58 POP EAX
00589AC5 |.A3 304DDC01 MOV DWORD PTR DS:,EAX
00589ACA |.6A 01 PUSH 1 ; /Arg3 = 00000001
00589ACC |.B8 CA9D4100 MOV EAX,00419DCA ; |ASCII "4411"
00589AD1 |.8945 FC MOV DWORD PTR SS:,EAX ; |
00589AD4 |.8D45 FC LEA EAX,DWORD PTR SS: ; |
00589AD7 |.50 PUSH EAX ; |Arg2
00589AD8 |.68 304DDC01 PUSH 1DC4D30 ; |Arg1 = 01DC4D30
00589ADD |.E8 5D040000 CALL 00589F3F ; \XX人事.00589F3F注册算法CALL
00589AE2 |.8945 F8 MOV DWORD PTR SS:,EAX //返回真码1
00589AE5 |.8B5D FC MOV EBX,DWORD PTR SS:
00589AE8 |.85DB TEST EBX,EBX
00589AEA |.74 09 JE SHORT 00589AF5
00589AEC |.53 PUSH EBX
00589AED |.E8 F9750700 CALL 006010EB
00589AF2 |.83C4 04 ADD ESP,4
00589AF5 |>8B45 F8 MOV EAX,DWORD PTR SS:
00589AF8 |.50 PUSH EAX
00589AF9 |.8B1D C84CDC01 MOV EBX,DWORD PTR DS:
00589AFF |.85DB TEST EBX,EBX
00589B01 |.74 09 JE SHORT 00589B0C
00589B03 |.53 PUSH EBX
00589B04 |.E8 E2750700 CALL 006010EB
00589B09 |.83C4 04 ADD ESP,4
00589B0C |>58 POP EAX
00589B0D |.A3 C84CDC01 MOV DWORD PTR DS:,EAX
00589B12 |.6A 01 PUSH 1 ; /Arg3 = 00000001
00589B14 |.B8 CF9D4100 MOV EAX,00419DCF ; |ASCII "4444"
00589B19 |.8945 FC MOV DWORD PTR SS:,EAX ; |
00589B1C |.8D45 FC LEA EAX,DWORD PTR SS: ; |
00589B1F |.50 PUSH EAX ; |Arg2
00589B20 |.68 304DDC01 PUSH 1DC4D30 ; |Arg1 = 01DC4D30
00589B25 |.E8 15040000 CALL 00589F3F ; \XX人事.00589F3F注册算法CALL
00589B2A |.8945 F8 MOV DWORD PTR SS:,EAX //返回真码2
00589B2D |.8B5D FC MOV EBX,DWORD PTR SS:
00589B30 |.85DB TEST EBX,EBX
00589B32 |.74 09 JE SHORT 00589B3D
00589B34 |.53 PUSH EBX
00589B35 |.E8 B1750700 CALL 006010EB
00589B3A |.83C4 04 ADD ESP,4
00589B3D |>8B45 F8 MOV EAX,DWORD PTR SS:
00589B40 |.50 PUSH EAX
00589B41 |.8B1D D44CDC01 MOV EBX,DWORD PTR DS:
00589B47 |.85DB TEST EBX,EBX
00589B49 |.74 09 JE SHORT 00589B54
00589B4B |.53 PUSH EBX
00589B4C |.E8 9A750700 CALL 006010EB
00589B51 |.83C4 04 ADD ESP,4
00589B54 |>58 POP EAX
00589B55 |.A3 D44CDC01 MOV DWORD PTR DS:,EAX
00589B5A |.6A 00 PUSH 0
00589B5C |.FF35 304DDC01 PUSH DWORD PTR DS:
00589B62 |.6A FF PUSH -1
00589B64 |.6A 08 PUSH 8
00589B66 |.68 382D0116 PUSH 16012D38
00589B6B |.68 372D0152 PUSH 52012D37
00589B70 |.E8 88750700 CALL 006010FD
00589B75 |.83C4 18 ADD ESP,18
00589B78 |.8BE5 MOV ESP,EBP
00589B7A |.5D POP EBP
00589B7B \.C3 RETN
跟进算法CALL
00589F3F 55 PUSH EBP //调用两次,分别计算两个注册码。
00589F40 8BEC MOV EBP,ESP
00589F42 81EC 28000000 SUB ESP,28
00589F48 C745 FC 00000000 MOV DWORD PTR SS:,0
00589F4F 68 C8144100 PUSH 004114C8
00589F54 8B5D 0C MOV EBX,DWORD PTR SS:
00589F57 FF33 PUSH DWORD PTR DS:
00589F59 E8 D352FAFF CALL 0052F231
00589F5E 83C4 08 ADD ESP,8
00589F61 83F8 00 CMP EAX,0
00589F64 0F85 E7000000 JNZ 0058A051 //跳走。
00589F6A 68 D49D4100 PUSH 00419DD4
00589F6F 8B5D 08 MOV EBX,DWORD PTR SS:
00589F72 FF33 PUSH DWORD PTR DS:
00589F74 B9 02000000 MOV ECX,2
00589F79 E8 A93CFAFF CALL 0052DC27
00589F7E 83C4 08 ADD ESP,8
00589F81 8945 F8 MOV DWORD PTR SS:,EAX
00589F84 68 04000080 PUSH 80000004
00589F89 6A 00 PUSH 0
00589F8B 8B45 F8 MOV EAX,DWORD PTR SS:
00589F8E 85C0 TEST EAX,EAX
00589F90 75 05 JNZ SHORT 00589F97
00589F92 B8 C8144100 MOV EAX,004114C8
00589F97 50 PUSH EAX
00589F98 68 01000000 PUSH 1
00589F9D BB 98010000 MOV EBX,198
00589FA2 E8 62710700 CALL 00601109
00589FA7 83C4 10 ADD ESP,10
00589FAA 8945 F4 MOV DWORD PTR SS:,EAX
00589FAD 8B5D F8 MOV EBX,DWORD PTR SS:
00589FB0 85DB TEST EBX,EBX
00589FB2 74 09 JE SHORT 00589FBD
00589FB4 53 PUSH EBX
00589FB5 E8 31710700 CALL 006010EB
00589FBA 83C4 04 ADD ESP,4
00589FBD 68 05000080 PUSH 80000005
00589FC2 6A 00 PUSH 0
00589FC4 8B45 F4 MOV EAX,DWORD PTR SS:
00589FC7 85C0 TEST EAX,EAX
00589FC9 75 05 JNZ SHORT 00589FD0
00589FCB B8 D1144100 MOV EAX,004114D1
00589FD0 50 PUSH EAX
00589FD1 68 01000000 PUSH 1
00589FD6 BB 08000000 MOV EBX,8
00589FDB B8 0F000000 MOV EAX,0F
00589FE0 E8 0C710700 CALL 006010F1
00589FE5 83C4 10 ADD ESP,10
00589FE8 8945 F0 MOV DWORD PTR SS:,EAX
00589FEB 8B5D F4 MOV EBX,DWORD PTR SS:
00589FEE 85DB TEST EBX,EBX
00589FF0 74 09 JE SHORT 00589FFB
00589FF2 53 PUSH EBX
00589FF3 E8 F3700700 CALL 006010EB
00589FF8 83C4 04 ADD ESP,4
00589FFB 68 04000080 PUSH 80000004
0058A000 6A 00 PUSH 0
0058A002 8B45 F0 MOV EAX,DWORD PTR SS:
0058A005 85C0 TEST EAX,EAX
0058A007 75 05 JNZ SHORT 0058A00E
0058A009 B8 C8144100 MOV EAX,004114C8
0058A00E 50 PUSH EAX
0058A00F 68 01000000 PUSH 1
0058A014 BB 50010000 MOV EBX,150
0058A019 E8 EB700700 CALL 00601109
0058A01E 83C4 10 ADD ESP,10
0058A021 8945 EC MOV DWORD PTR SS:,EAX
0058A024 8B5D F0 MOV EBX,DWORD PTR SS:
0058A027 85DB TEST EBX,EBX
0058A029 74 09 JE SHORT 0058A034
0058A02B 53 PUSH EBX
0058A02C E8 BA700700 CALL 006010EB
0058A031 83C4 04 ADD ESP,4
0058A034 8B45 EC MOV EAX,DWORD PTR SS:
0058A037 50 PUSH EAX
0058A038 8B5D FC MOV EBX,DWORD PTR SS:
0058A03B 85DB TEST EBX,EBX
0058A03D 74 09 JE SHORT 0058A048
0058A03F 53 PUSH EBX
0058A040 E8 A6700700 CALL 006010EB
0058A045 83C4 04 ADD ESP,4
0058A048 58 POP EAX
0058A049 8945 FC MOV DWORD PTR SS:,EAX
0058A04C E9 E2000000 JMP 0058A133
0058A051 8B5D 0C MOV EBX,DWORD PTR SS://跳到这里
0058A054 FF33 PUSH DWORD PTR DS: //固定码4411/4444压栈
0058A056 8B5D 08 MOV EBX,DWORD PTR SS:
0058A059 FF33 PUSH DWORD PTR DS: //机器码“03010010311”压栈
0058A05B B9 02000000 MOV ECX,2
0058A060 E8 C23BFAFF CALL 0052DC27 //将机器码与固定码4444连接030100103114411/4444
0058A065 83C4 08 ADD ESP,8
0058A068 8945 F8 MOV DWORD PTR SS:,EAX
0058A06B 68 04000080 PUSH 80000004
0058A070 6A 00 PUSH 0
0058A072 8B45 F8 MOV EAX,DWORD PTR SS:
0058A075 85C0 TEST EAX,EAX
0058A077 75 05 JNZ SHORT 0058A07E
0058A079 B8 C8144100 MOV EAX,004114C8
0058A07E 50 PUSH EAX
0058A07F 68 01000000 PUSH 1
0058A084 BB 98010000 MOV EBX,198
0058A089 E8 7B700700 CALL 00601109
0058A08E 83C4 10 ADD ESP,10
0058A091 8945 F4 MOV DWORD PTR SS:,EAX
0058A094 8B5D F8 MOV EBX,DWORD PTR SS:
0058A097 85DB TEST EBX,EBX
0058A099 74 09 JE SHORT 0058A0A4
0058A09B 53 PUSH EBX
0058A09C E8 4A700700 CALL 006010EB
0058A0A1 83C4 04 ADD ESP,4
0058A0A4 68 05000080 PUSH 80000005
0058A0A9 6A 00 PUSH 0
0058A0AB 8B45 F4 MOV EAX,DWORD PTR SS:
0058A0AE 85C0 TEST EAX,EAX
0058A0B0 75 05 JNZ SHORT 0058A0B7
0058A0B2 B8 D1144100 MOV EAX,004114D1
0058A0B7 50 PUSH EAX
0058A0B8 68 01000000 PUSH 1
0058A0BD BB 08000000 MOV EBX,8
0058A0C2 B8 0F000000 MOV EAX,0F
0058A0C7 E8 25700700 CALL 006010F1 ; md5运算计算“030100103114411/4444”
0058A0CC 83C4 10 ADD ESP,10
0058A0CF 8945 F0 MOV DWORD PTR SS:,EAX //"e1b4534fd0e23eb7166acb6f9ec1e7c0"
0058A0D2 8B5D F4 MOV EBX,DWORD PTR SS:
0058A0D5 85DB TEST EBX,EBX
0058A0D7 74 09 JE SHORT 0058A0E2
0058A0D9 53 PUSH EBX
0058A0DA E8 0C700700 CALL 006010EB
0058A0DF 83C4 04 ADD ESP,4
0058A0E2 68 04000080 PUSH 80000004
0058A0E7 6A 00 PUSH 0
0058A0E9 8B45 F0 MOV EAX,DWORD PTR SS:
0058A0EC 85C0 TEST EAX,EAX
0058A0EE 75 05 JNZ SHORT 0058A0F5
0058A0F0 B8 C8144100 MOV EAX,004114C8
0058A0F5 50 PUSH EAX
0058A0F6 68 01000000 PUSH 1
0058A0FB BB 50010000 MOV EBX,150
0058A100 E8 04700700 CALL 00601109 ; 将字母转为大写
0058A105 83C4 10 ADD ESP,10
0058A108 8945 EC MOV DWORD PTR SS:,EAX
0058A10B 8B5D F0 MOV EBX,DWORD PTR SS:
0058A10E 85DB TEST EBX,EBX
0058A110 74 09 JE SHORT 0058A11B
0058A112 53 PUSH EBX
0058A113 E8 D36F0700 CALL 006010EB
0058A118 83C4 04 ADD ESP,4
0058A11B 8B45 EC MOV EAX,DWORD PTR SS:
0058A11E 50 PUSH EAX
0058A11F 8B5D FC MOV EBX,DWORD PTR SS:
0058A122 85DB TEST EBX,EBX
0058A124 74 09 JE SHORT 0058A12F
0058A126 53 PUSH EBX
0058A127 E8 BF6F0700 CALL 006010EB
0058A12C 83C4 04 ADD ESP,4
0058A12F 58 POP EAX
0058A130 8945 FC MOV DWORD PTR SS:,EAX
0058A133 8D45 FC LEA EAX,DWORD PTR SS:
0058A136 50 PUSH EAX
0058A137 E8 E1FCFFFF CALL 00589E1D ; //字符串转为倒序排列
0058A13C 8945 F8 MOV DWORD PTR SS:,EAX//"0C7E1CE9F6BCA6617BE32E0DF4354B1E"
0058A13F 8B45 F8 MOV EAX,DWORD PTR SS:
0058A142 50 PUSH EAX
0058A143 8B5D FC MOV EBX,DWORD PTR SS:
0058A146 85DB TEST EBX,EBX
0058A148 74 09 JE SHORT 0058A153
0058A14A 53 PUSH EBX
0058A14B E8 9B6F0700 CALL 006010EB
0058A150 83C4 04 ADD ESP,4
0058A153 58 POP EAX
0058A154 8945 FC MOV DWORD PTR SS:,EAX
0058A157 68 01030080 PUSH 80000301
0058A15C 6A 00 PUSH 0
0058A15E 68 05000000 PUSH 5
0058A163 68 04000080 PUSH 80000004
0058A168 6A 00 PUSH 0
0058A16A 8B45 FC MOV EAX,DWORD PTR SS:
0058A16D 85C0 TEST EAX,EAX
0058A16F 75 05 JNZ SHORT 0058A176
0058A171 B8 C8144100 MOV EAX,004114C8
0058A176 50 PUSH EAX
0058A177 68 02000000 PUSH 2
0058A17C BB 34010000 MOV EBX,134
0058A181 E8 836F0700 CALL 00601109 ; 取字倒顺后的MD5字串前五位为注册码最后五位0C7E1
0058A186 83C4 1C ADD ESP,1C
0058A189 8945 F8 MOV DWORD PTR SS:,EAX
0058A18C 8D45 F8 LEA EAX,DWORD PTR SS:
0058A18F 50 PUSH EAX
0058A190 E8 88FCFFFF CALL 00589E1D
0058A195 8945 F4 MOV DWORD PTR SS:,EAX
0058A198 8B5D F8 MOV EBX,DWORD PTR SS:
0058A19B 85DB TEST EBX,EBX
0058A19D 74 09 JE SHORT 0058A1A8
0058A19F 53 PUSH EBX
0058A1A0 E8 466F0700 CALL 006010EB
0058A1A5 83C4 04 ADD ESP,4
0058A1A8 68 01030080 PUSH 80000301
0058A1AD 6A 00 PUSH 0
0058A1AF 68 05000000 PUSH 5
0058A1B4 68 01030080 PUSH 80000301
0058A1B9 6A 00 PUSH 0
0058A1BB 68 06000000 PUSH 6
0058A1C0 68 04000080 PUSH 80000004
0058A1C5 6A 00 PUSH 0
0058A1C7 8B45 FC MOV EAX,DWORD PTR SS:
0058A1CA 85C0 TEST EAX,EAX
0058A1CC 75 05 JNZ SHORT 0058A1D3
0058A1CE B8 C8144100 MOV EAX,004114C8
0058A1D3 50 PUSH EAX
0058A1D4 68 03000000 PUSH 3
0058A1D9 BB 3C010000 MOV EBX,13C
0058A1DE E8 266F0700 CALL 00601109//取字倒顺后的MD5字串6-10位为注册码倒数第二段“CE9F6”
0058A1E3 83C4 28 ADD ESP,28
0058A1E6 8945 F0 MOV DWORD PTR SS:,EAX
0058A1E9 8D45 F0 LEA EAX,DWORD PTR SS:
0058A1EC 50 PUSH EAX
0058A1ED E8 2BFCFFFF CALL 00589E1D
0058A1F2 8945 EC MOV DWORD PTR SS:,EAX
0058A1F5 8B5D F0 MOV EBX,DWORD PTR SS:
0058A1F8 85DB TEST EBX,EBX
0058A1FA 74 09 JE SHORT 0058A205
0058A1FC 53 PUSH EBX
0058A1FD E8 E96E0700 CALL 006010EB
0058A202 83C4 04 ADD ESP,4
0058A205 68 01030080 PUSH 80000301
0058A20A 6A 00 PUSH 0
0058A20C 68 05000000 PUSH 5
0058A211 68 01030080 PUSH 80000301
0058A216 6A 00 PUSH 0
0058A218 68 0B000000 PUSH 0B
0058A21D 68 04000080 PUSH 80000004
0058A222 6A 00 PUSH 0
0058A224 8B45 FC MOV EAX,DWORD PTR SS:
0058A227 85C0 TEST EAX,EAX
0058A229 75 05 JNZ SHORT 0058A230
0058A22B B8 C8144100 MOV EAX,004114C8
0058A230 50 PUSH EAX
0058A231 68 03000000 PUSH 3
0058A236 BB 3C010000 MOV EBX,13C
0058A23B E8 C96E0700 CALL 00601109//取字倒顺后的MD5字串11-15位为注册码倒数第三段“BCA66”
0058A240 83C4 28 ADD ESP,28
0058A243 8945 E8 MOV DWORD PTR SS:,EAX
0058A246 8D45 E8 LEA EAX,DWORD PTR SS:
0058A249 50 PUSH EAX
0058A24A E8 CEFBFFFF CALL 00589E1D
0058A24F 8945 E4 MOV DWORD PTR SS:,EAX
0058A252 8B5D E8 MOV EBX,DWORD PTR SS:
0058A255 85DB TEST EBX,EBX
0058A257 74 09 JE SHORT 0058A262
0058A259 53 PUSH EBX
0058A25A E8 8C6E0700 CALL 006010EB
0058A25F 83C4 04 ADD ESP,4
0058A262 68 01030080 PUSH 80000301
0058A267 6A 00 PUSH 0
0058A269 68 05000000 PUSH 5
0058A26E 68 01030080 PUSH 80000301
0058A273 6A 00 PUSH 0
0058A275 68 10000000 PUSH 10
0058A27A 68 04000080 PUSH 80000004
0058A27F 6A 00 PUSH 0
0058A281 8B45 FC MOV EAX,DWORD PTR SS:
0058A284 85C0 TEST EAX,EAX
0058A286 75 05 JNZ SHORT 0058A28D
0058A288 B8 C8144100 MOV EAX,004114C8
0058A28D 50 PUSH EAX
0058A28E 68 03000000 PUSH 3
0058A293 BB 3C010000 MOV EBX,13C
0058A298 E8 6C6E0700 CALL 00601109 //取字倒顺后的MD5字串16-20位为注册码第一段“17BE3”
0058A29D 83C4 28 ADD ESP,28
0058A2A0 8945 E0 MOV DWORD PTR SS:,EAX
0058A2A3 8D45 E0 LEA EAX,DWORD PTR SS:
0058A2A6 50 PUSH EAX
0058A2A7 E8 71FBFFFF CALL 00589E1D
0058A2AC 8945 DC MOV DWORD PTR SS:,EAX
0058A2AF 8B5D E0 MOV EBX,DWORD PTR SS:
0058A2B2 85DB TEST EBX,EBX
0058A2B4 74 09 JE SHORT 0058A2BF
0058A2B6 53 PUSH EBX
0058A2B7 E8 2F6E0700 CALL 006010EB
0058A2BC 83C4 04 ADD ESP,4
0058A2BF FF75 DC PUSH DWORD PTR SS:
0058A2C2 68 115B4100 PUSH 00415B11
0058A2C7 FF75 E4 PUSH DWORD PTR SS:
0058A2CA 68 115B4100 PUSH 00415B11
0058A2CF FF75 EC PUSH DWORD PTR SS:
0058A2D2 68 115B4100 PUSH 00415B11
0058A2D7 FF75 F4 PUSH DWORD PTR SS:
0058A2DA B9 07000000 MOV ECX,7
0058A2DF E8 4339FAFF CALL 0052DC27 ; 把以上注册码用“-”连结生成注册码
0058A2E4 83C4 1C ADD ESP,1C
0058A2E7 8945 D8 MOV DWORD PTR SS:,EAX
0058A2EA 8B5D F4 MOV EBX,DWORD PTR SS:
0058A2ED 85DB TEST EBX,EBX
0058A2EF 74 09 JE SHORT 0058A2FA
0058A2F1 53 PUSH EBX
...........中间省略
0058A3C0 83C4 10 ADD ESP,10
0058A3C3 8BE5 MOV ESP,EBP
0058A3C5 5D POP EBP
0058A3C6 C3 RETN
==============================================================================================
DELPHI 算法注册机原码:
{计算注册码}
procedure TfmKey.sbtCalcClick(Sender: TObject);
var
n,m,name,str2,str1:string;
begin
name:= edName.Text;
str1:='4411';
str2:='4444';
if edName.Text='' then
begin
ShowMessage('请输入机器码!!!');
exit;
end
else
//处理注册码1
n:=name+str1;
n:=md5print(md5string(n)) ;
n:=ReverseString(n);
n:= uppercase (n);
//处理注册码2
m:=name+str2;
m:=md5print(md5string(m)) ;
m:=ReverseString(m);
m:= uppercase (m);
//输出注册码1
edCode.Text:=MidStr(n,16,5) +'-'+ MidStr(n,11,5) +'-'+ MidStr(n,6,5) +'-'+ MidStr(n,1,5);
//输出注册码2
edCode1.Text:=MidStr(m,16,5) +'-'+ MidStr(m,11,5) +'-'+ MidStr(m,6,5) +'-'+ MidStr(m,1,5);
end;
{MD5值算法单元}
unit md5;
interface
uses
Windows;
type
MD5Count = array of DWORD;
MD5State = array of DWORD;
MD5Block = array of DWORD;
MD5CBits = array of byte;
MD5Digest = array of byte;
MD5Buffer = array of byte;
MD5Context = record
State: MD5State;
Count: MD5Count;
Buffer: MD5Buffer;
end;
procedure MD5Init(var Context: MD5Context);
procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
function MD5String(M: string): MD5Digest;
function MD5File(N: string): MD5Digest;
function MD5Print(D: MD5Digest): string;
function MD5Match(D1, D2: MD5Digest): boolean;
// -----------------------------------------------------------------------------------------------
IMPLEMENTATION
// -----------------------------------------------------------------------------------------------
var
PADDING: MD5Buffer = (
$80, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00
);
function F(x, y, z: DWORD): DWORD;
begin
Result := (x and y) or ((not x) and z);
end;
function G(x, y, z: DWORD): DWORD;
begin
Result := (x and z) or (y and (not z));
end;
function H(x, y, z: DWORD): DWORD;
begin
Result := x xor y xor z;
end;
function I(x, y, z: DWORD): DWORD;
begin
Result := y xor (x or (not z));
end;
procedure rot(var x: DWORD; n: BYTE);
begin
x := (x shl n) or (x shr (32 - n));
end;
procedure FF(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, F(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure GG(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, G(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure HH(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, H(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure II(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, I(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
// -----------------------------------------------------------------------------------------------
// Encode Count bytes at Source into (Count / 4) DWORDs at Target
procedure Encode(Source, Target: pointer; Count: longword);
var
S: PByte;
T: PDWORD;
I: longword;
begin
S := Source;
T := Target;
for I := 1 to Count div 4 do begin
T^ := S^;
inc(S);
T^ := T^ or (S^ shl 8);
inc(S);
T^ := T^ or (S^ shl 16);
inc(S);
T^ := T^ or (S^ shl 24);
inc(S);
inc(T);
end;
end;
// Decode Count DWORDs at Source into (Count * 4) Bytes at Target
procedure Decode(Source, Target: pointer; Count: longword);
var
S: PDWORD;
T: PByte;
I: longword;
begin
S := Source;
T := Target;
for I := 1 to Count do begin
T^ := S^ and $ff;
inc(T);
T^ := (S^ shr 8) and $ff;
inc(T);
T^ := (S^ shr 16) and $ff;
inc(T);
T^ := (S^ shr 24) and $ff;
inc(T);
inc(S);
end;
end;
// Transform State according to first 64 bytes at Buffer
procedure Transform(Buffer: pointer; var State: MD5State);
var
a, b, c, d: DWORD;
Block: MD5Block;
begin
Encode(Buffer, @Block, 64);
a := State;
b := State;
c := State;
d := State;
FF (a, b, c, d, Block[ 0], 7, $d76aa478);
FF (d, a, b, c, Block[ 1], 12, $e8c7b756);
FF (c, d, a, b, Block[ 2], 17, $242070db);
FF (b, c, d, a, Block[ 3], 22, $c1bdceee);
FF (a, b, c, d, Block[ 4], 7, $f57c0faf);
FF (d, a, b, c, Block[ 5], 12, $4787c62a);
FF (c, d, a, b, Block[ 6], 17, $a8304613);
FF (b, c, d, a, Block[ 7], 22, $fd469501);
FF (a, b, c, d, Block[ 8], 7, $698098d8);
FF (d, a, b, c, Block[ 9], 12, $8b44f7af);
FF (c, d, a, b, Block, 17, $ffff5bb1);
FF (b, c, d, a, Block, 22, $895cd7be);
FF (a, b, c, d, Block, 7, $6b901122);
FF (d, a, b, c, Block, 12, $fd987193);
FF (c, d, a, b, Block, 17, $a679438e);
FF (b, c, d, a, Block, 22, $49b40821);
GG (a, b, c, d, Block[ 1], 5, $f61e2562);
GG (d, a, b, c, Block[ 6], 9, $c040b340);
GG (c, d, a, b, Block, 14, $265e5a51);
GG (b, c, d, a, Block[ 0], 20, $e9b6c7aa);
GG (a, b, c, d, Block[ 5], 5, $d62f105d);
GG (d, a, b, c, Block, 9, $2441453);
GG (c, d, a, b, Block, 14, $d8a1e681);
GG (b, c, d, a, Block[ 4], 20, $e7d3fbc8);
GG (a, b, c, d, Block[ 9], 5, $21e1cde6);
GG (d, a, b, c, Block, 9, $c33707d6);
GG (c, d, a, b, Block[ 3], 14, $f4d50d87);
GG (b, c, d, a, Block[ 8], 20, $455a14ed);
GG (a, b, c, d, Block, 5, $a9e3e905);
GG (d, a, b, c, Block[ 2], 9, $fcefa3f8);
GG (c, d, a, b, Block[ 7], 14, $676f02d9);
GG (b, c, d, a, Block, 20, $8d2a4c8a);
HH (a, b, c, d, Block[ 5], 4, $fffa3942);
HH (d, a, b, c, Block[ 8], 11, $8771f681);
HH (c, d, a, b, Block, 16, $6d9d6122);
HH (b, c, d, a, Block, 23, $fde5380c);
HH (a, b, c, d, Block[ 1], 4, $a4beea44);
HH (d, a, b, c, Block[ 4], 11, $4bdecfa9);
HH (c, d, a, b, Block[ 7], 16, $f6bb4b60);
HH (b, c, d, a, Block, 23, $bebfbc70);
HH (a, b, c, d, Block, 4, $289b7ec6);
HH (d, a, b, c, Block[ 0], 11, $eaa127fa);
HH (c, d, a, b, Block[ 3], 16, $d4ef3085);
HH (b, c, d, a, Block[ 6], 23, $4881d05);
HH (a, b, c, d, Block[ 9], 4, $d9d4d039);
HH (d, a, b, c, Block, 11, $e6db99e5);
HH (c, d, a, b, Block, 16, $1fa27cf8);
HH (b, c, d, a, Block[ 2], 23, $c4ac5665);
II (a, b, c, d, Block[ 0], 6, $f4292244);
II (d, a, b, c, Block[ 7], 10, $432aff97);
II (c, d, a, b, Block, 15, $ab9423a7);
II (b, c, d, a, Block[ 5], 21, $fc93a039);
II (a, b, c, d, Block, 6, $655b59c3);
II (d, a, b, c, Block[ 3], 10, $8f0ccc92);
II (c, d, a, b, Block, 15, $ffeff47d);
II (b, c, d, a, Block[ 1], 21, $85845dd1);
II (a, b, c, d, Block[ 8], 6, $6fa87e4f);
II (d, a, b, c, Block, 10, $fe2ce6e0);
II (c, d, a, b, Block[ 6], 15, $a3014314);
II (b, c, d, a, Block, 21, $4e0811a1);
II (a, b, c, d, Block[ 4], 6, $f7537e82);
II (d, a, b, c, Block, 10, $bd3af235);
II (c, d, a, b, Block[ 2], 15, $2ad7d2bb);
II (b, c, d, a, Block[ 9], 21, $eb86d391);
inc(State, a);
inc(State, b);
inc(State, c);
inc(State, d);
end;
// -----------------------------------------------------------------------------------------------
// Initialize given Context
procedure MD5Init(var Context: MD5Context);
begin
with Context do begin
State := $67452301;
State := $efcdab89;
State := $98badcfe;
State := $10325476;
Count := 0;
Count := 0;
ZeroMemory(@Buffer, SizeOf(MD5Buffer));
end;
end;
// Update given Context to include Length bytes of Input
procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
var
Index: longword;
PartLen: longword;
I: longword;
begin
with Context do begin
Index := (Count shr 3) and $3f;
inc(Count, Length shl 3);
if Count < (Length shl 3) then inc(Count);
inc(Count, Length shr 29);
end;
PartLen := 64 - Index;
if Length >= PartLen then begin
CopyMemory(@Context.Buffer, Input, PartLen);
Transform(@Context.Buffer, Context.State);
I := PartLen;
while I + 63 < Length do begin
Transform(@Input, Context.State);
inc(I, 64);
end;
Index := 0;
end else I := 0;
CopyMemory(@Context.Buffer, @Input, Length - I);
end;
// Finalize given Context, create Digest and zeroize Context
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
var
Bits: MD5CBits;
Index: longword;
PadLen: longword;
begin
Decode(@Context.Count, @Bits, 2);
Index := (Context.Count shr 3) and $3f;
if Index < 56 then PadLen := 56 - Index else PadLen := 120 - Index;
MD5Update(Context, @PADDING, PadLen);
MD5Update(Context, @Bits, 8);
Decode(@Context.State, @Digest, 4);
ZeroMemory(@Context, SizeOf(MD5Context));
end;
// -----------------------------------------------------------------------------------------------
// Create digest of given Message
function MD5String(M: string): MD5Digest;
var
Context: MD5Context;
begin
MD5Init(Context);
MD5Update(Context, pChar(M), length(M));
MD5Final(Context, Result);
end;
// Create digest of file with given Name
function MD5File(N: string): MD5Digest;
var
FileHandle: THandle;
MapHandle: THandle;
ViewPointer: pointer;
Context: MD5Context;
begin
MD5Init(Context);
FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
if FileHandle <>INVALID_HANDLE_VALUE then try
MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);
if MapHandle <>0 then try
ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);
if ViewPointer <>nil then try
MD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));
finally
UnmapViewOfFile(ViewPointer);
end;
finally
CloseHandle(MapHandle);
end;
finally
CloseHandle(FileHandle);
end;
MD5Final(Context, Result);
end;
// Create hex representation of given Digest
function MD5Print(D: MD5Digest): string;
var
I: byte;
const
Digits: array of char =
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
begin
Result := '';
for I := 0 to 15 do Result := Result + Digits[(D shr 4) and $0f] + Digits and $0f];
end;
// -----------------------------------------------------------------------------------------------
// Compare two Digests
function MD5Match(D1, D2: MD5Digest): boolean;
var
I: byte;
begin
I := 0;
Result := TRUE;
while Result and (I < 16) do begin
Result := D1 = D2;
inc(I);
end;
end;
end.
一个字"强"!! 两个字"很强"!!!! 三个字:"非常强" 五个字:“真是太强了”(后面的保持队形):loveliness: 四个字:“我看不懂” 楼主太强大了 :)
[ 本帖最后由 wgz001 于 2009-1-9 11:23 编辑 ] 好东西,值得学习。。谢谢, 五个字:“真是太强了”(保持阵型1n9,后面的继续) 六个字,“我还真没看懂!”,楼下的继续