-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMain.pas
2975 lines (2758 loc) · 99.9 KB
/
Main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
The Enchanted Keyfinder is a free utility that retrieves your
Product Key (cd key) used to install Windows from your registry.
Copyright (C) 2011 Enchanted Keyfinder Project
Copyright (C) 1999-2008 Magical Jelly Bean Software
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contributor(s):
Oliver Schneider (assarbad)
Sam Gleske (sag47)
VersionBoy (versionboy)
Compiles With: Delphi 7, Boreland Dev Studio 2006, DS Turbo Delphi 2006, Delphi 2007
}
unit Main;
interface
uses
// Delphi
Classes, ComCtrls, Controls, Dialogs, ExtCtrls, Forms,
Graphics, Grids,
IniFiles, jpeg, Menus, Messages, Printers, Registry, ShellAPI, StdCtrls,
StrUtils, SysUtils, ValEdit, Variants, Windows, ExtActns;
type
TfrmMain = class(TForm)
MainMenu1: TMainMenu;
About1: TMenuItem;
ListBox1: TListBox;
Splitter1: TSplitter;
Memo1: TMemo;
StatusBar1: TStatusBar;
File2: TMenuItem;
Exit2: TMenuItem;
N1: TMenuItem;
SaveAs1: TMenuItem;
Tools1: TMenuItem;
ModifyConfig1: TMenuItem;
About2: TMenuItem;
Options1: TMenuItem;
FontDialog: TFontDialog;
ListBox2: TListBox;
Panel1: TPanel;
RefreshPanel: TPanel;
lblVersion: TLabel;
lblLastUpdate: TLabel;
PrintAll1: TMenuItem;
Memo2: TMemo;
SaveDialog1: TSaveDialog;
PrintDialog1: TPrintDialog;
MnuItmLoadHive1: TMenuItem;
RemotePC1: TMenuItem;
N2: TMenuItem;
ChangeRegistrationInfo1: TMenuItem;
Label8: TLabel;
AlwaysOnTop1: TMenuItem;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
Memo3: TMemo;
N3: TMenuItem;
MnuSourceforgeWeb: TMenuItem;
MnuItmWebUpdate: TMenuItem;
N4: TMenuItem;
CommunityForums1: TMenuItem;
BugandFeatureTracker1: TMenuItem;
CommunityWiki1: TMenuItem;
Label2: TLabel;
ChangeWindowsKey1: TMenuItem;
Label3: TLabel;
Label5: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Logo: TImage;
Label1: TLabel;
Refresh1: TMenuItem;
lblRefresh: TLabel;
procedure Refresh1Click(Sender: TObject);
procedure Label13Click(Sender: TObject);
procedure Label15Click(Sender: TObject);
procedure Label10Click(Sender: TObject);
procedure Label5Click(Sender: TObject);
procedure ChangeWindowsKey1Click(Sender: TObject);
procedure Label2Click(Sender: TObject);
procedure CommunityWiki1Click(Sender: TObject);
procedure CommunityForums1Click(Sender: TObject);
procedure BugandFeatureTracker1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Exit2Click(Sender: TObject);
procedure FindWinVersion;
procedure GetVistaKey;
procedure GetXPKey;
procedure GetNT4Key;
procedure Get9xKey;
procedure GetOfficeKey;
procedure OfficeList;
procedure SaveFileDone;
procedure ReadCfg;
procedure ProgramInit;
procedure LoadHive;
procedure UnLoadHive;
procedure ParseConfig;
procedure ConvertSaveFormat;
procedure About2Click(Sender: TObject);
procedure Label6Click(Sender: TObject);
procedure LogoClick(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Label4Click(Sender: TObject);
procedure lblLastUpdateClick(Sender: TObject);
procedure lblVersionClick(Sender: TObject);
procedure Label1Click(Sender: TObject);
procedure Options1Click(Sender: TObject);
procedure SaveAs1Click(Sender: TObject);
procedure PrintAll1Click(Sender: TObject);
procedure ModifyConfig1Click(Sender: TObject);
procedure MnuItmLoadHive1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Label7Click(Sender: TObject);
procedure Label8Click(Sender: TObject);
procedure ChangeRegistrationInfo1Click(Sender: TObject);
procedure RemotePC1Click(Sender: TObject);
procedure AlwaysOnTop1Click(Sender: TObject);
procedure Label9Click(Sender: TObject);
procedure MnuSourceforgeWebClick(Sender: TObject);
procedure MnuItmWebUpdateClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure SaveDialogTypeChange(Sender: TObject);
procedure LoadSettings(Sender: TObject);
procedure SaveSettings(Sender: TObject);
procedure FormatSettingsPath;
procedure UnformatSettingsPath;
private
// Private declarations
function DecodeAdobeKey(const sAdobeEncryptedKey: string): string;
function DecodeMSKey(const HexSrc: array of byte; const ID: boolean): string;
function StripTags(const sText: string): string;
procedure FormatAdobeKey(var sAdobeKey: string);
procedure GetMSDPID3(const sHivePath: string; var sProdID, sMSKey: string);
public
// Public declarations
sDelimCSV: string;
sPCName: string;
sLogPath: string;
sUserCFG: string;
sSettingsFile: string;
//bLogOverwrite: boolean;
bAutoSave: boolean;
bAutoClose: boolean;
//bAppendTop: boolean;
//bAppendBottom: boolean;
bCFGVerFound: boolean;
sCFGVer: string;
iEntriesRead: integer;
bFormattedSettings: boolean;
end;
var
frmMain: TfrmMain;
iSaveKeysToFile: integer;
bToBePrinted: boolean;
sAutoSaveDir: string;
bAutoHive: boolean; // True if a hive load is requested from cmd line.
bHiveLoaded: boolean; // True when a registry hive is loaded.
sHiveLoc: string;
sHiveLoc2: string;
//sReportsPath: string;
//sLogFilePath: string;
//bLogging: boolean;
followUnstable: boolean;
showBlankSerials: boolean;
bSaveSettings: boolean;
//sUserHivePath, sSoftwareHivePath: string;
bWin2k, bWinXP, bVista, bWinNT4: boolean;
{$INCLUDE VersionConsts.inc}
const
kfDate = PROGRAM_RELEASE_DATE;
DefDelimCSV = ',';
DefLogPath = '.';
KEY_WOW64_64KEY = $0100;
KEY_WOW64_32KEY = $0200;
SE_PRIVILEGE_DISABLED = 0;
SE_RESTORE_NAME = 'SeRestorePrivilege';
sLineBreak = {$IFDEF LINUX} AnsiChar(#10) {$ENDIF}
{$IFDEF MSWINDOWS} AnsiString(#13#10) {$ENDIF}
{$IFDEF MACOSX} AnsiChar(#10) {$ENDIF};
function IsWow64: boolean;
function BrowseForFolder(var Foldr: string; const Title: string): boolean;
function BrowseDialogCallBack(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): integer stdcall;
function StringToCaseSelect(const Selector: string; const CaseList: array of string): integer;
function IsValidWinProdID(const sProdID: string): boolean;
function GetCurrentUser: string;
function GetPCName: string;
function IsWinXP: boolean;
function IsWinNT4: boolean;
procedure SaveFont(FStream: TIniFile; Section: string; smFont: TFont);
procedure LoadFont(FStream: TIniFile; Section: string; smFont: TFont);
function IsNumeric(Value: string; const AllowFloat: boolean): boolean;
procedure convertIniFile(filename : string);
implementation
uses
CommDlg, Dlgs, ShlObj, License, Options, Registration, Remote, WindowsUser,
WinXPKey, ActnList;
resourcestring
rsSetPrivUserNotHaveAccess = 'The current user does not have the required ' +
'access to load a registry hive.';
rsSetPrivIncompatOS = 'This program is incompatible with the operating sys' +
'tem installed on this computer.';
rsMnuItmLoadHive = '&Load Hive...';
rsMnuItmUnLoadHive = 'Un&Load Hive...';
rsNotFound = 'Not found';
rsLicenseKeyEmpty = 'The license key registry entry is empty!';
{$R *.dfm} // Include form definitions
function IsWow64: boolean;
type
TIsWow64Process = function( // Type of IsWow64Process API fn
Handle: Windows.THandle;
var Res: Windows.BOOL
): Windows.BOOL; stdcall;
var
IsWow64Result: Windows.BOOL; // Result from IsWow64Process
IsWow64Process: TIsWow64Process; // IsWow64Process fn reference
begin
// Try to load required function from kernel32
IsWow64Process := Windows.GetProcAddress(
Windows.GetModuleHandle('kernel32.dll'), 'IsWow64Process'
);
if Assigned(IsWow64Process) then
begin
// Function is implemented: call it
if not IsWow64Process(Windows.GetCurrentProcess, IsWow64Result) then
raise SysUtils.Exception.Create('IsWow64: bad process handle');
// Return result of function
Result := IsWow64Result;
end
else
// Function not implemented: can't be running on Wow64
Result := False;
end; // IsWow64
function BrowseForFolder(var Foldr: string; const Title: string): boolean;
var
BrowseInfo: TBrowseInfo;
ItemIDList: PItemIDList;
DisplayName: array[0..MAX_PATH] of char;
begin
Result := False;
FillChar(BrowseInfo, SizeOf(BrowseInfo), #0);
FillChar(DisplayName, SizeOf(DisplayName), #0);
with BrowseInfo do
begin
hwndOwner := Application.Handle;
// With this the browse dialog should appear on the application's main form
pszDisplayName := @DisplayName[0];
lpszTitle := PChar(Title);
ulFlags := BIF_RETURNONLYFSDIRS;
lpfn := BrowseDialogCallBack;
end;
ItemIDList := SHBrowseForFolder(BrowseInfo);
if Assigned(ItemIDList) then
if SHGetPathFromIDList(ItemIDList, DisplayName) then
begin
Foldr := StrPas(DisplayName);
Result := True;
GlobalFreePtr(ItemIDList);
end;
end; // BrowseForFolder
function BrowseDialogCallBack(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): integer stdcall;
// In later versions of Delphi you may find the two constants for BIF_NEWDIALOGSTYLE and BIF_NONEWFOLDERBUTTON are defined in the unit shlobj, but these were missing in Delphi 7
const
BIF_NEWDIALOGSTYLE = $40;
BIF_NONEWFOLDERBUTTON = $200;
var
wa, rect: TRect;
dialogPT: TPoint;
begin
// Center dialog in work area
if uMsg = BFFM_INITIALIZED then
begin
wa := Screen.WorkAreaRect;
GetWindowRect(Wnd, Rect);
dialogPT.X := ((wa.Right - wa.Left) div 2) - ((rect.Right - rect.Left) div 2);
dialogPT.Y := ((wa.Bottom - wa.Top) div 2) - ((rect.Bottom - rect.Top) div 2);
MoveWindow(Wnd, dialogPT.X, dialogPT.Y, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top, True);
SendMessage(Wnd, BFFM_SETSELECTIONA, Longint(true), lpData);
end;
Result := 0;
end; // BrowseDialogCallBack
procedure SetTokenPrivilege(aSystemName: PChar; aPrivilegeName: PChar; aEnabled: boolean);
{******************************************************************************
SetTokenPrivilege
A helper function that enables or disables specific privileges on the
specified computer. A NIL in SystemName means the privilege will be granted
for the current computer. Any other value must match the name of a computer
on your network.
Written by Brian Layman (AKA Capt. Queeg)
Visit him at http://www.TheCodeCave.com
******************************************************************************}
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
TokenOpened, ValueFound: boolean;
begin
// SetPrivilege
// The privilege system is only available on NT and beyond
if (Win32Platform = VER_PLATFORM_WIN32_NT) then
begin
// Retrieve the Token that represents this current application session
TokenOpened := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, TTokenHd);
// Check for failure
if (not TokenOpened) then
raise Exception.Create(
'The current user does not have the access required to run this program.')
else
begin
// Get the name of the privilege (since Windows is multi-lingual, this must be done)
ValueFound := LookupPrivilegeValue(aSystemName, aPrivilegeName,
TTokenPvg.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
// Enable or disable the flag according to the bool passed
if (aEnabled) then
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_DISABLED;
// See note on local constant declaration
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if (not ValueFound) then
raise Exception.Create(rsSetPrivIncompatOS)
else
try
// Adjust the permissions as required.
Windows.AdjustTokenPrivileges(TTokenHd, False, TTokenPvg, cbtpPrevious,
rTTokenPvg, pcbtpPreviousRequired);
except
raise Exception.Create(rsSetPrivUserNotHaveAccess)
end;
end;
end;
end; // SetPrivilege
procedure GrantPrivilege(const aPrivilegeName: string);
begin
SetTokenPrivilege(nil, PChar(aPrivilegeName), True);
end; // GrantPrivilege
procedure RevokePrivilege(const aPrivilegeName: string);
begin
SetTokenPrivilege(nil, PChar(aPrivilegeName), False);
end; // RevokePrivilege
function GetCurrentUser: string;
const
cnMaxUserNameLen = 254;
var
sUserName: string;
dwUserNameLen: DWORD;
begin
try
dwUserNameLen := cnMaxUserNameLen - 1;
SetLength(sUserName, cnMaxUserNameLen);
GetUserName(PChar(sUserName), dwUserNameLen);
SetLength(sUserName, dwUserNameLen - 1); // -1 to remove null char
Result := sUserName;
except
Result := '';
end;
end;
function GetPCName: string;
var
i: cardinal;
sComputer: string;
begin
try
i := 255;
SetLength(sComputer, i);
GetComputerName(PChar(sComputer), i);
SetLength(sComputer, (i));
except
// ShowMessage('Can''t get local PC name!');
sComputer := 'Unknown PC';
end;
if sComputer = '' then // Test result for a string
sComputer := 'Unknown PC';
Result := sComputer;
end;
function StringToCaseSelect(const Selector: string; const CaseList: array of string): integer;
{Usage:
case StringToCaseSelect('Delphi', ['About','Borland','Delphi']) of
0:ShowMessage('You''ve picked About') ;
1:ShowMessage('You''ve picked Borland') ;
2:ShowMessage('You''ve picked Delphi') ;
end;
}
var
cnt: integer;
begin
Result := -1;
for cnt := 0 to Length(CaseList) - 1 do
if CompareText(Selector, CaseList[cnt]) = 0 then
begin
Result := cnt;
Break;
end;
end;
function IsWinXP: boolean;
// Returns true if the operating system is Windows XP
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion = 5) and
(Win32MinorVersion = 1);
end;
function IsWinPE: boolean;
begin
Result := FileExists(GetEnvironmentVariable('SystemRoot') + '\system32\winpeshl.exe');
end;
function IsWinNT4: boolean;
// Returns true if the operating system is Windows NT
// (excluding 2000 and XP) and false if not.
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion = 4);
end;
function IsWin2k: boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion = 5) and
(Win32MinorVersion = 0);
end;
procedure TfrmMain.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.ListBox1Click(Sender: TObject);
var
i: integer;
begin
Assert(Memo1 <> nil);
Memo1.Clear;
About2.Checked := False;
Panel1.Visible := False;
for i := 0 to (ListBox1.Items.Count - 1) do
if ListBox1.Selected[i] then
begin
//StatusBar1.Panels[0].Text := Trim(ListBox1.Items.Strings[i]); //trim any spaces
Memo1.Lines.Add(ListBox1.Items.Strings[i]);
if ListBox2.Items.Strings[i] = 'Vista' then
GetVistaKey;
if ListBox2.Items.Strings[i] = 'WinXP' then
GetXPKey;
if ListBox2.Items.Strings[i] = 'WinNT4' then
GetNT4Key;
if ListBox2.Items.Strings[i] = 'Win9x' then
Get9xKey;
if LeftStr(ListBox2.Items.Strings[i], 6) = 'Office' then
GetOfficeKey;
if LeftStr(ListBox2.Items.Strings[i], 6) = 'Config' then
ParseConfig;
end;
StatusBar1.Panels.Items[2].Text := 'Detected: ' + IntToStr(ListBox2.Items.Count);
end;
procedure TfrmMain.ProgramInit;
begin
ListBox1.Clear;
Listbox2.Clear;
Memo1.Clear;
FindWinVersion;
OfficeList;
ReadCfg;
if ListBox1.Items.Count > 0 then
begin
ListBox1.Selected[0] := True;
frmMain.ListBox1Click(frmMain);
end;
end;
function IsValidWinProdID(const sProdID: string): boolean;
type
TBadProductIDS = array[1..23] of string;
const
// Represents the stripped list of bad Product ID's.
BadProductIDList: TBadProductIDS =
('64064371823', '64130937623', '64206458023', '64246436423',
'64333470123', '64408177223', '64445126523', '64487489623',
'64493370423', '64496239623', '64583325423', '64599496223',
'64603184323', '64610408123', '64610510323', '64731883823',
'64759202923', '64767783423', '64830169123', '64881999223',
'64910676523', '64994139223', '65029231223');
var
sStripedProdID: string;
begin
Result := True;
if isWinXP then
begin
// Remove hyphens if any from Product ID.
sStripedProdID := StringReplace(sProdID, '-', '', [rfReplaceAll, rfIgnoreCase]);
// Remove the first 5 characters from Product ID.
Delete(sStripedProdID, 1, 5);
// Remove the last 3 characters from Product ID.
Delete(sStripedProdID, 13, 3);
// Devel's own
if (sStripedProdID = '640000035623') or (sStripedProdID = '640200176523') then
begin
Result := False;
Exit;
end;
// Remove the 10th character from Product ID.
Delete(sStripedProdID, 10, 1);
case StringToCaseSelect(sStripedProdID, BadProductIDList) of
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23: Result := False;
end;
end;
end;
procedure TfrmMain.LoadSettings(Sender: TObject);
var
myINI: TINIFile;
fs: TFormatSettings;
begin
//read for an alternate path to the settings
myINI := TINIFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try
sSettingsFile := myINI.ReadString('keyfinder', 'Settings', '');
finally
myINI.Free;
end;
if (sSettingsFile <> '') and FileExists(sSettingsFile) then
myINI := TINIFile.Create(sSettingsFile)
else
myINI := TINIFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
//begin parsing the settings
try
GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, FS);
sDelimCSV := myINI.ReadString('Settings', 'CSVDelim', fs.ListSeparator);
bAutoSave := myINI.ReadBool('Settings', 'AutoSave', False);
bAutoHive := myINI.ReadBool('Settings', 'LoadHive', False);
bToBePrinted := myINI.ReadBool('Settings', 'PrintKeys', False);
sAutoSaveDir := myINI.ReadString('Settings', 'SavePath', '.\');
if not (RightStr(sAutoSaveDir,1) = '\') then
sAutoSaveDir := sAutoSaveDir + '\';//make sure there's a trailing slash
sHiveLoc2 := myINI.ReadString('Settings', 'SoftwareHivePath', '');
if kfVersion = kfUnstableVersion then
followUnstable := myINI.ReadBool('Settings', 'UnstableUpdates', True)
else
followUnstable := myINI.ReadBool('Settings', 'UnstableUpdates', False);
sUserCFG := myINI.ReadString('Settings', 'UserConfig','.\user.cfg');
showBlankSerials := myINI.ReadBool('Settings', 'ShowBlankSerials', False);
LoadFont(myINI, 'AppListFont', frmMain.ListBox1.Font);
LoadFont(myINI, 'KeyListFont', frmMain.Memo1.Font);
//set relative paths to be interpreted from the settings file location
if not bFormattedSettings then
FormatSettingsPath;
//These are all settings which have been discarded.
//sLogFilePath := myINI.ReadString('Settings', 'LogFilePath', '.\');
//if not (RightStr(sLogFilePath,1) = '\') then
// sLogFilePath := sLogFilePath + '\';//make sure there's a trailing slash
//bLogging := myINI.ReadBool('Settings', 'Logging', False);
//bAppendTop := myINI.ReadBool('Settings', 'AppendTop', False);
//bLogOverwrite := myINI.ReadBool('Settings', 'LogOverwrite', False);
//sReportsPath := myINI.ReadString('Settings', 'ReportsPath', '');
//sUserHivePath := myINI.ReadString('Settings', 'UserHivePath', '');
//sSoftwareHivePath := myINI.ReadString('Settings', 'SoftwareHivePath', '');
finally
myINI.Free;
end; // try..finally
end;
procedure TfrmMain.FormatSettingsPath;
begin
if sSettingsFile <> '' then
begin
//set relative paths to be interpreted from the settings file location
if LeftStr(sAutoSaveDir,1) = '.' then
sAutoSaveDir := ExtractFilePath(sSettingsFile) + sAutoSaveDir;
if LeftStr(sHiveLoc2,1) = '.' then
sHiveLoc2 := ExtractFilePath(sSettingsFile) + sHiveLoc2;
if LeftStr(sUserCFG,1) = '.' then
sUserCFG := ExtractFilePath(sSettingsFile) + sUserCFG;
bFormattedSettings := True;
end;
end;
procedure TfrmMain.UnformatSettingsPath;
begin
if sSettingsFile <> '' then
begin
//restore paths to their original form.
sAutoSaveDir := RightStr(sAutoSaveDir,Length(sAutoSaveDir)-Length(ExtractFilePath(sSettingsFile)));
sHiveLoc2 := RightStr(sHiveLoc2,Length(sHiveLoc2)-Length(ExtractFilePath(sSettingsFile)));
sUserCFG := RightStr(sUserCFG,Length(sUserCFG)-Length(ExtractFilePath(sSettingsFile)));
bFormattedSettings := False;
end;
end;
procedure TfrmMain.SaveSettings(Sender: TObject);
var
myINI: TINIFile;
begin
//ShowMessage(RightStr(sAutoSaveDir,Length(sAutoSaveDir)-Length(ExtractFilePath(sSettingsFile))));
if sSettingsFile <> '' then
myINI := TINIFile.Create(sSettingsFile)
else
myINI := TINIFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try
if bFormattedSettings then
UnformatSettingsPath;
myINI.WriteBool('Settings', 'AutoSave', bAutoSave);
myINI.WriteString('Settings', 'CSVDelim', sDelimCSV);
myINI.WriteBool('Settings', 'LoadHive', bAutoHive);
myINI.WriteBool('Settings', 'PrintKeys', bToBePrinted);
myINI.WriteString('Settings', 'SavePath', sAutoSaveDir);
myINI.WriteBool('Settings', 'ShowBlankSerials', showBlankSerials);
myINI.WriteString('Settings', 'SoftwareHivePath', sHiveLoc2);
myINI.WriteBool('Settings', 'UnstableUpdates', followUnstable);
myINI.WriteString('Settings', 'UserConfig', sUserCFG);
SaveFont(myINI, 'AppListFont', frmMain.ListBox1.Font);
SaveFont(myINI, 'KeyListFont', frmMain.Memo1.Font);
//myINI.WriteString('Settings', 'LogFilePath', sLogFilePath);
//myINI.WriteBool('Settings', 'Logging', bLogging);
//myINI.WriteBool('Settings', 'AppendTop', bAppendTop);
//myINI.WriteBool('Settings', 'LogOverwrite', bLogOverwrite);
//myINI.WriteString('Settings', 'ReportsPath', sReportsPath);
//myINI.WriteString('Settings', 'UserHivePath', sUserHivePath);
//myINI.WriteString('Settings', 'SoftwareHivePath', sSoftwareHivePath);
myINI.UpdateFile;
finally
myINI.Free;
end; // try..finally
end;
procedure SaveFont(FStream: TIniFile; Section: string; smFont: TFont);
begin
FStream.WriteString(Section, 'Font', smFont.Name + ',' +
IntToStr(smFont.CharSet) + ',' +
IntToStr(smFont.Color) + ',' +
IntToStr(smFont.Size) + ',' +
IntToStr(byte(smFont.Style)));
end;
procedure LoadFont(FStream: TIniFile; Section: string; smFont: TFont);
var
s, Data: string;
i: integer;
begin
s := FStream.ReadString(Section, 'Font', ',,,,');
try
i := Pos(',', s);
if i > 0 then
begin
{Name}
Data := Trim(Copy(s, 1, i - 1));
if Data <> '' then
smFont.Name := Data;
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{CharSet}
Data := Trim(Copy(s, 1, i - 1));
if Data <> '' then
smFont.Charset := TFontCharSet(StrToIntDef(Data, smFont.Charset));
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{Color}
Data := Trim(Copy(s, 1, i - 1));
if Data <> '' then
smFont.Color := TColor(StrToIntDef(Data, smFont.Color));
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{Size}
Data := Trim(Copy(s, 1, i - 1));
if Data <> '' then
smFont.Size := StrToIntDef(Data, smFont.Size);
Delete(s, 1, i);
{Style}
Data := Trim(s);
if Data <> '' then
smFont.Style := TFontStyles(byte(StrToIntDef(Data, byte(smFont.Style))));
end;
end;
end;
end;
except
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
i: integer;
sCurParam: string;
begin
// Program startup default settings
Width := 640;
Height := 480;
bFormattedSettings := False;
//bLogging := False;
//bAutoHive := False;
//bAutoSave := False;
//bAppendTop := False;
//sLogFilePath := '.\';
sDelimCSV := DefDelimCSV;
sHiveLoc := 'Software';
bWinNT4 := IsWinNT4;
bWin2k := IsWin2k;
bWinXP := IsWinXP;
//bVista := IsVista;
frmMain.Memo1.Font.Style := [fsBold];
frmMain.LoadSettings(frmMain);
if bWinXP then
ChangeWindowsKey1.Enabled := True;
if Win32Platform <> VER_PLATFORM_WIN32_NT then
begin
ChangeWindowsKey1.Enabled := False;
MnuItmLoadHive1.Enabled := False;
end;
if IsWinPE then
begin
// Switch off I/O error checking
{$IOChecks off}
MkDir(GetEnvironmentVariable('SystemRoot') + '\system32\config\systemprofile\Desktop');
{$IOChecks on}
frmMain.Scaled := False;
ChangeRegistrationInfo1.Enabled := False;
PrintAll1.Enabled := False;
ChangeWindowsKey1.Enabled := False;
end;
sPCName := GetPCName;
if sPCName = '' then
sPCName := 'Unknown';
frmMain.SaveDialog1.DefaultExt := '.txt';
SaveDialog1.FileName := sPCName + '.txt';
//sAutoSaveDir := ExtractFilePath(Application.ExeName);
iSaveKeysToFile := -1;
frmMain.Text := frmMain.Text + kfversion;
lblVersion.Caption := lblVersion.Caption + kfversion;
lblLastUpdate.Caption := lblLastUpdate.Caption + kfdate;
//autoload hive from settings
if bAutoHive then
begin
if IsWindowsAdmin then
LoadHive
else
ShowMessage('Not running with admin privledges, Can''t load hive.');
end;
// Parse the command line switches
i := 1;
while i <= ParamCount do
begin
while (i < ParamCount) and (ParamStr(i)[1] <> '/') do
i := i + 1;
sCurParam := AnsiLowerCase(ParamStr(i));
if (sCurParam = '/close') or (sCurParam = '/quiet') or (sCurParam = '/silent') then
begin
bAutoClose := True;
// Minimise the application so it's main window is not visable.
//Application.Minimize;
end;
if sCurParam = '/delim' then
sDelimCSV := ParamStr(i + 1);
if sCurParam = '/file' then
if LeftStr(ParamStr(i + 1), 1) <> '/' then
SaveDialog1.FileName := ParamStr(i + 1);
if sCurParam = '/hive' then
if LeftStr(ParamStr(i + 1), 1) <> '/' then
begin
bAutoHive := True;
sHiveLoc2 := ParamStr(i + 1);
// Are we running with admin privledges??
if IsWindowsAdmin then
LoadHive
else ShowMessage('Not running with admin privledges, Can''t load hive.');
end;
if sCurParam = '/save' then
begin
bAutoSave := True;
if LeftStr(ParamStr(i + 1), 1) <> '/' then
sAutoSaveDir := ParamStr(i + 1);
SaveDialog1.FilterIndex := 1;
frmMain.SaveDialog1.DefaultExt := '.txt';
SaveDialog1.FileName := sPCName + '.txt'; // Use PC name as default save name
end;
if sCurParam = '/savecsv' then
begin
bAutoSave := True;
if LeftStr(ParamStr(i + 1), 1) <> '/' then
sAutoSaveDir := ParamStr(i + 1);
SaveDialog1.FilterIndex := 2;
SaveDialog1.FileName := sPCName + '.csv';
end;
if sCurParam = '/saveini' then
begin
bAutoSave := True;
if LeftStr(ParamStr(i + 1), 1) <> '/' then
sAutoSaveDir := ParamStr(i + 1);
SaveDialog1.FilterIndex := 3;
SaveDialog1.FileName := sPCName + '.ini';
end;
if sCurParam = '/savehtml' then
begin
bAutoSave := True;
if LeftStr(ParamStr(i + 1), 1) <> '/' then
sAutoSaveDir := ParamStr(i + 1);
SaveDialog1.FilterIndex := 4;
SaveDialog1.FileName := sPCName + '.html';
end;
//if sCurParam = '/appendtop' then
// bAppendTop := True;
//if sCurParam = '/appendbottom' then
// bAppendBottom := True;
i := i + 1;
end;
ProgramInit;
if bAutoSave then
begin
SaveAs1Click(frmMain);
if SaveDialog1.FilterIndex = 3 then
convertIniFile(sAutoSaveDir + SaveDialog1.FileName);
end;
if bAutoClose then // Time to close the main application
Application.Terminate;
end;
procedure TfrmMain.Exit2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.MnuSourceforgeWebClick(Sender: TObject);
begin
ShellExecute(Handle, nil, PChar(PROGRAM_HOME_PAGE), nil, nil, SW_NORMAL);
end;
procedure TfrmMain.FindWinVersion;
var
MyReg: TRegistry;
begin
{ if RemotePC1.Checked then
begin
if MyReg.RegistryConnect(frmRemote.Edit1.Text) = False then
begin
ShowMessage('Unable to connect to remote mchine.');
RemotePC1.Checked := False;
end
else if not MyReg.OpenKey('Software\Microsoft\Windows NT\CurrentVersion', False) then
begin
ShowMessage('No access to registry key.');
RemotePC1.Checked := False;
MyReg.Free;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_LOCAL_MACHINE;
end;
end;
}
MyReg := TRegistry.Create;
try
MyReg.RootKey := HKEY_LOCAL_MACHINE;
// This bit won't work for NT 4 as there is no ProductName value
if MyReg.OpenKey(sHiveLoc + '\Microsoft\Windows NT\CurrentVersion', False) and
MyReg.ValueExists('ProductName') then
begin
ListBox1.Items.Add(MyReg.ReadString('ProductName'));
ListBox2.Items.Add('WinXP');
end;
finally
MyReg.Free;
end;
if bWinNT4 then // Test for NT 4.0
begin
ListBox1.Items.Add('Microsoft Windows NT');
ListBox2.Items.Add('WinNT4');
end;
// Win 9x/me check
try
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_LOCAL_MACHINE;
if MyReg.OpenKeyReadOnly(sHiveLoc + '\Microsoft\Windows\CurrentVersion') and
MyReg.ValueExists('Version') then
begin
ListBox2.Items.Add('Win9x');
if MyReg.ReadString('ProductName') <> '' then
ListBox1.Items.Add(MyReg.ReadString('ProductName'))
else
ListBox1.Items.Add(MyReg.ReadString('Version'));
end;
finally
MyReg.Free;
end;
end; // FindWinVersion
procedure TfrmMain.GetVistaKey;
var
ProdSpec: TIniFile;
sOSEdition: string;
sCSDVersion, sProductKey,
sProductID, sRegOwn,
sRegOrg: string;
begin
sCSDVersion := '';
sOSEdition := '';
if (sHiveLoc = 'Software') and
(FileExists(GetEnvironmentVariable('SystemRoot') + '\system32\prodspec.ini')) then
begin
ProdSpec := TIniFile.Create(GetEnvironmentVariable('SystemRoot') + '\system32\prodspec.ini');
sOSEdition := ProdSpec.ReadString('Product Specification', 'Product', '');
ProdSpec.Free;
end;
// Check for other OS location
if (sHiveLoc <> 'Software') and (FileExists(sHiveLoc2 + '\System32\Prodspec.ini')) then
begin
ProdSpec := TIniFile.Create(sHiveLoc2 + '\system32\prodspec.ini');
sOSEdition := ProdSpec.ReadString('Product Specification', 'Product', '');
ProdSpec.Free;
end;
if sOSEdition <> '' then
Memo1.Lines[0] := ('Microsoft ' + sOSEdition); // Don't want sOSEdition on seperate line
GetMSDPID3(sHiveLoc + '\Microsoft\Windows NT\CurrentVersion', sProductID, sProductKey);
// Retrieve ID, User + Company name
with TRegistry.Create() do
try
RootKey := HKEY_LOCAL_MACHINE;