DbHaspPWD.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. unit DbHaspPwd;
  2. interface
  3. uses
  4. Windows, SysUtils;
  5. function GetHaspPass1: LongInt;
  6. function GetHaspPass2: LongInt;
  7. type
  8. PAuthorizeFile = ^TAuthorizeFile;
  9. TAuthorizeFile = packed record
  10. Head: string[20];
  11. Version: Word;
  12. Edition: Byte;
  13. Hours: Integer;
  14. Times: Word;
  15. Key1: array [0..11] of Byte;
  16. Key2: array [0..11] of Byte;
  17. end;
  18. const
  19. // δ¼ÓÃܳ¤¶È
  20. Length_AuthorizeData = 54;
  21. // ¼ÓÃܺ󳤶È
  22. Length_AuthorizeFile = 60;
  23. const
  24. ScEncryptKey: array [0..16] of Byte =
  25. ($00, $00, $00, $0D, $CF, $CB, $CD, $CF,
  26. $8C, $8B, $BC, $90, $8D, $8B, $92, $9E,
  27. $AC);
  28. ScAuthorizeKey: array [0..16] of Byte =
  29. ($00, $00, $00, $0D, $8C, $8B, $BC, $90,
  30. $8D, $8B, $92, $9E, $8F, $AC, $9E, $8C,
  31. $B7);
  32. HASP_MemorySizeInByte = 48;
  33. HASP_AuthorizeFileHead = 'SmartCost Auth.';
  34. implementation
  35. const
  36. // Demo
  37. //Ps1: array [0..8] of Byte = ($00, $00, $00, $05, $CE, $C8, $CA, $CB, $CE);
  38. //Ps2: array [0..7] of Byte = ($00, $00, $00, $04, $CC, $CD, $C6, $C9);
  39. Ps1: array [0..8] of Byte = ($00, $00, $00, $05, $CD, $C6, $CB, $CA, $CD);
  40. Ps2: array [0..8] of Byte = ($00, $00, $00, $05, $CF, $CA, $CE, $C8, $CE);
  41. // HASPÃÜÂë
  42. function ExtractPwd(AArray: array of Byte; ALength: Integer): LongInt;
  43. var
  44. OrgLength, I, iTemp: Integer;
  45. TestBuf: array [0..1023] of Char;
  46. TargetBuf: array [0..1027] of Char;
  47. strHexLength: string[8];
  48. strTemp: string;
  49. begin
  50. ZeroMemory(@TestBuf, 1024);
  51. ZeroMemory(@TargetBuf, 1028);
  52. CopyMemory(@TargetBuf, @AArray, ALength*SizeOf(Char));
  53. strHexLength := '';
  54. for I := 0 to 3 do
  55. begin
  56. strHexLength := strHexLength + IntToHex(Byte(TargetBuf[I]), 2);
  57. end;
  58. OrgLength := StrToInt('$' + strHexLength);
  59. for I := 0 to OrgLength - 1 do
  60. begin
  61. if not Odd(I) then
  62. begin
  63. if (I + 1 < OrgLength) then
  64. TestBuf[I] := TargetBuf[I + 1 + 4]
  65. else
  66. TestBuf[I] := TargetBuf[I + 4];
  67. end
  68. else
  69. TestBuf[I] := TargetBuf[I - 1 + 4];
  70. end;
  71. for I := 0 to OrgLength - 1 do
  72. begin
  73. TargetBuf[I] := Char($FF - Byte(TestBuf[I]));
  74. end;
  75. for I := 0 to OrgLength - 1 do
  76. begin
  77. TestBuf[I] := TargetBuf[OrgLength - I - 1];
  78. end;
  79. SetString(strTemp, PChar(@TestBuf[0]), ALength);
  80. Result := StrToInt(strTemp);
  81. end;
  82. function GetHaspPass1: LongInt;
  83. begin
  84. Result := ExtractPwd(Ps1, Length(Ps1));
  85. end;
  86. function GetHaspPass2: LongInt;
  87. begin
  88. Result := ExtractPwd(Ps2, Length(Ps2));
  89. end;
  90. end.