קוד:
program RecoverPwd;
uses
Windows, Messages;
var
hOutput: HWND;
const
ID_ABOUT = 1001;
IDC_EDIT = 1000;
AboutText: PChar = 'ICQ2003/Lite Password Recovery'#13#10'
{$R ResFile.res}
procedure DecryptPass(dwVolumeSerial: LongWord; lpszMainLocation: Pointer; dwMainLocationLen: LongWord; lpszUIN: PChar); stdcall; external 'ICQ2003Decrypt.dll';
const
Key = 'SOFTWARE\Mirabilis\ICQ\NewOwners';
function OpenKey(SubKey: String; var Handle: HKEY): Boolean;
begin
Result := RegCreateKey(HKEY_CURRENT_USER, PChar(Key + SubKey), Handle) = ERROR_SUCCESS;
end;
function CloseKey(Handle: HKey): Boolean;
begin
Result := RegCloseKey(Handle) = ERROR_SUCCESS;
end;
const
HexChars: array[0..$F] of Char = ('0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F');
function ByteToHex(Int: Byte): String;
begin
Result := HexChars[(Int shr 4) and $F] + HexChars[Int and $F];
end;
function PassToHex(const Value: String): String;
var
i: Word;
begin
Result := '';
for i := 1 to Length(Value) do
Result := Result + ' ' + ByteToHex(Ord(Value[i]));
end;
function GetDriveSerial: LongWord;
var
lpRoot: String;
lpVolume: String;
Serial: LongWord;
Max: LongWord;
Flags: LongWord;
NameBuffer: String;
begin
Result := 0;
SetLength(lpRoot, MAX_PATH);
if GetWindowsDirectory(@lpRoot[1], MAX_PATH) = 0 then Exit;
SetLength(lpVolume, 40);
SetLength(NameBuffer, 40);
if not GetVolumeInformation(PChar(Copy(lpRoot, 0, 3)), @lpVolume[1], 40, @Serial, Max, Flags, @NameBuffer[1], 40) then Exit;
Result := Serial;
end;
procedure SetText(Control: HWND; const Value: String);
begin
SendMessage(Control, WM_SETTEXT, Length(Value), Integer(@Value[1]));
end;
function AddPass(const SubKey: String): String;
var
Buffer: array[0..15] of Byte;
DataType, BufSize: Integer;
Handle: HKey;
begin
Result := '';
if not OpenKey('\' + SubKey, Handle) then Exit;
BufSize := SizeOf(Buffer);
if RegQueryValueEx(Handle, 'MainLocation', nil, @DataType, @Buffer, @BufSize) = ERROR_SUCCESS then begin
DecryptPass(GetDriveSerial, @Buffer, BufSize, PChar(SubKey));
Result := PChar(@Buffer);
end;
CloseKey(Handle);
end;
procedure ShowMeThePasswords;
var
S: String;
Pass: String;
Handle: HKEY;
lpName: PChar;
lpNameLen: LongWord;
KeyIndex: Integer;
begin
SetText(hOutput, 'Could not find any passwords');
if not OpenKey('', Handle) then Exit;
S := '';
GetMem(lpName, 20);
lpNameLen := 20;
KeyIndex := 0;
while RegEnumKeyEx(Handle, KeyIndex, lpName, lpNameLen, nil, nil, nil, nil) = ERROR_SUCCESS do begin
Pass := AddPass(lpName);
if Pass <> '' then begin
if S = '' then
S := 'Decrypted passwords:'#13#10;
S := S + lpName + ': ' + Pass + ' (in hex:' + PassToHex(Pass) + ')'#13#10;
end;
lpNameLen := 20;
Inc(KeyIndex);
end;
CloseKey(Handle);
FreeMem(lpName);
if S <> '' then
SetText(hOutput, S);
end;
function WndProc(hwnd, wmsg, wParam, lParam: HWND): Integer; stdcall;
begin
case wmsg Of
WM_INITDIALOG: begin
hOutput := GetDlgItem(hwnd, IDC_EDIT);
ShowMeThePasswords;
end;
WM_COMMAND:
if wParam = ID_OK then
EndDialog(hwnd, 0)
else if wParam = ID_ABOUT then
MessageBox(hwnd, AboutText, 'About', MB_ICONINFORMATION);
WM_CLOSE:
EndDialog(hwnd, 0);
end;
Result := 0;
end;
begin
DialogBoxParam(hInstance, '#101', 0, @WndProc, 0);
ShowMeThePasswords;
end.