forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptFunc_R.pas
1858 lines (1749 loc) · 74.1 KB
/
ScriptFunc_R.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
unit ScriptFunc_R;
{
Inno Setup
Copyright (C) 1997-2012 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Script support functions (run time)
}
interface
{$I VERSION.INC}
uses
uPSRuntime;
procedure ScriptFuncLibraryRegister_R(ScriptInterpreter: TPSExec);
implementation
uses
Windows, ScriptFunc,
Forms, uPSUtils, SysUtils, Classes, Graphics, Controls, TypInfo,
{$IFNDEF Delphi3orHigher} Ole2, {$ELSE} ActiveX, {$ENDIF}
Struct, ScriptDlg, Main, PathFunc, CmnFunc, CmnFunc2, FileClass, RedirFunc,
Install, InstFunc, InstFnc2, Msgs, MsgIDs, NewDisk, BrowseFunc, Wizard, VerInfo,
SetupTypes, Int64Em, MD5, SHA1, Logging, SetupForm, RegDLL, Helper,
SpawnClient, UninstProgressForm;
var
ScaleBaseUnitsInitialized: Boolean;
ScaleBaseUnitX, ScaleBaseUnitY: Integer;
procedure NoSetupFuncError(const C: AnsiString);{$IFDEF UNICODE} overload;{$ENDIF}
begin
InternalError(Format('Cannot call "%s" function during Setup', [C]));
end;
procedure NoUninstallFuncError(const C: AnsiString);{$IFDEF UNICODE} overload;{$ENDIF}
begin
InternalError(Format('Cannot call "%s" function during Uninstall', [C]));
end;
{$IFDEF UNICODE}
procedure NoSetupFuncError(const C: UnicodeString); overload;
begin
InternalError(Format('Cannot call "%s" function during Setup', [C]));
end;
procedure NoUninstallFuncError(const C: UnicodeString); overload;
begin
InternalError(Format('Cannot call "%s" function during Uninstall', [C]));
end;
{$ENDIF}
{$IFNDEF UNICODE}
procedure NoNonUnicodeFuncError(const C: String);
begin
InternalError(Format('Cannot call "%s" function during non Unicode Setup or Uninstall', [C]));
end;
{$ENDIF}
function StackGetAnsiString(Stack: TPSStack; ItemNo: LongInt): AnsiString;
begin
{$IFDEF UNICODE}
Result := Stack.GetAnsiString(ItemNo);
{$ELSE}
Result := Stack.GetString(ItemNo);
{$ENDIF}
end;
procedure StackSetAnsiString(Stack: TPSStack; ItemNo: LongInt; const Data: AnsiString);
begin
{$IFDEF UNICODE}
Stack.SetAnsiString(ItemNo, Data);
{$ELSE}
Stack.SetString(ItemNo, Data);
{$ENDIF}
end;
function GetMainForm: TMainForm;
begin
Result := MainForm;
if Result = nil then
InternalError('An attempt was made to access MainForm before it has been created');
end;
function GetWizardForm: TWizardForm;
begin
Result := WizardForm;
if Result = nil then
InternalError('An attempt was made to access WizardForm before it has been created');
end;
function GetUninstallProgressForm: TUninstallProgressForm;
begin
Result := UninstallProgressForm;
if Result = nil then
InternalError('An attempt was made to access UninstallProgressForm before it has been created');
end;
procedure InitializeScaleBaseUnits;
var
Font: TFont;
begin
if ScaleBaseUnitsInitialized then
Exit;
Font := TFont.Create;
try
SetFontNameSize(Font, LangOptions.DialogFontName, LangOptions.DialogFontSize,
'', 8);
CalculateBaseUnitsFromFont(Font, ScaleBaseUnitX, ScaleBaseUnitY);
finally
Font.Free;
end;
ScaleBaseUnitsInitialized := True;
end;
{---}
{ ScriptDlg }
function ScriptDlgProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
function ArrayToStringList(Arr: PPSVariantIFC): TStringList;
var
StringList: TStringList;
I, N: Integer;
begin
StringList := TStringList.Create();
N := PSDynArrayGetLength(Pointer(Arr.Dta^), Arr.aType);
for I := 0 to N-1 do
StringList.Append(VNGetString(PSGetArrayField(Arr^, I)));
Result := StringList;
end;
procedure StringListToArray(StringList: TStringList; Arr: PPSVariantIFC);
var
I, N: Integer;
begin
N := StringList.Count;
for I := 0 to N-1 do
VNSetString(PSGetArrayField(Arr^, I), StringList[I]);
end;
var
PStart: Cardinal;
NewPage: TWizardPage;
NewInputQueryPage: TInputQueryWizardPage;
NewInputOptionPage: TInputOptionWizardPage;
NewInputDirPage: TInputDirWizardPage;
NewInputFilePage: TInputFileWizardPage;
NewOutputMsgPage: TOutputMsgWizardPage;
NewOutputMsgMemoPage: TOutputMsgMemoWizardPage;
NewOutputProgressPage: TOutputProgressWizardPage;
NewSetupForm: TSetupForm;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'PAGEFROMID' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
Stack.SetClass(PStart, GetWizardForm.PageFromID(Stack.GetInt(PStart-1)));
end else if Proc.Name = 'PAGEINDEXFROMID' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
Stack.SetInt(PStart, GetWizardForm.PageIndexFromID(Stack.GetInt(PStart-1)));
end else if Proc.Name = 'CREATECUSTOMPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewPage := TWizardPage.Create(GetWizardForm);
try
NewPage.Caption := Stack.GetString(PStart-2);
NewPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewPage, Stack.GetInt(PStart-1));
except
NewPage.Free;
raise;
end;
Stack.SetClass(PStart, NewPage);
end else if Proc.Name = 'CREATEINPUTQUERYPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewInputQueryPage := TInputQueryWizardPage.Create(GetWizardForm);
try
NewInputQueryPage.Caption := Stack.GetString(PStart-2);
NewInputQueryPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewInputQueryPage, Stack.GetInt(PStart-1));
NewInputQueryPage.Initialize(Stack.GetString(PStart-4));
except
NewInputQueryPage.Free;
raise;
end;
Stack.SetClass(PStart, NewInputQueryPage);
end else if Proc.Name = 'CREATEINPUTOPTIONPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewInputOptionPage := TInputOptionWizardPage.Create(GetWizardForm);
try
NewInputOptionPage.Caption := Stack.GetString(PStart-2);
NewInputOptionPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewInputOptionPage, Stack.GetInt(PStart-1));
NewInputOptionPage.Initialize(Stack.GetString(PStart-4),
Stack.GetBool(PStart-5), Stack.GetBool(PStart-6));
except
NewInputOptionPage.Free;
raise;
end;
Stack.SetClass(PStart, NewInputOptionPage);
end else if Proc.Name = 'CREATEINPUTDIRPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewInputDirPage := TInputDirWizardPage.Create(GetWizardForm);
try
NewInputDirPage.Caption := Stack.GetString(PStart-2);
NewInputDirPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewInputDirPage, Stack.GetInt(PStart-1));
NewInputDirPage.Initialize(Stack.GetString(PStart-4), Stack.GetBool(PStart-5),
Stack.GetString(PStart-6));
except
NewInputDirPage.Free;
raise;
end;
Stack.SetClass(PStart, NewInputDirPage);
end else if Proc.Name = 'CREATEINPUTFILEPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewInputFilePage := TInputFileWizardPage.Create(GetWizardForm);
try
NewInputFilePage.Caption := Stack.GetString(PStart-2);
NewInputFilePage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewInputFilePage, Stack.GetInt(PStart-1));
NewInputFilePage.Initialize(Stack.GetString(PStart-4));
except
NewInputFilePage.Free;
raise;
end;
Stack.SetClass(PStart, NewInputFilePage);
end else if Proc.Name = 'CREATEOUTPUTMSGPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewOutputMsgPage := TOutputMsgWizardPage.Create(GetWizardForm);
try
NewOutputMsgPage.Caption := Stack.GetString(PStart-2);
NewOutputMsgPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewOutputMsgPage, Stack.GetInt(PStart-1));
NewOutputMsgPage.Initialize(Stack.GetString(PStart-4));
except
NewOutputMsgPage.Free;
raise;
end;
Stack.SetClass(PStart, NewOutputMsgPage);
end else if Proc.Name = 'CREATEOUTPUTMSGMEMOPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewOutputMsgMemoPage := TOutputMsgMemoWizardPage.Create(GetWizardForm);
try
NewOutputMsgMemoPage.Caption := Stack.GetString(PStart-2);
NewOutputMsgMemoPage.Description := Stack.GetString(PStart-3);
GetWizardForm.AddPage(NewOutputMsgMemoPage, Stack.GetInt(PStart-1));
NewOutputMsgMemoPage.Initialize(Stack.GetString(PStart-4),
StackGetAnsiString(Stack, PStart-5));
except
NewOutputMsgMemoPage.Free;
raise;
end;
Stack.SetClass(PStart, NewOutputMsgMemoPage);
end else if Proc.Name = 'CREATEOUTPUTPROGRESSPAGE' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
NewOutputProgressPage := TOutputProgressWizardPage.Create(GetWizardForm);
try
NewOutputProgressPage.Caption := Stack.GetString(PStart-1);
NewOutputProgressPage.Description := Stack.GetString(PStart-2);
GetWizardForm.AddPage(NewOutputProgressPage, -1);
NewOutputProgressPage.Initialize;
except
NewOutputProgressPage.Free;
raise;
end;
Stack.SetClass(PStart, NewOutputProgressPage);
end else if Proc.Name = 'SCALEX' then begin
InitializeScaleBaseUnits;
Stack.SetInt(PStart, MulDiv(Stack.GetInt(PStart-1), ScaleBaseUnitX, OrigBaseUnitX));
end else if Proc.Name = 'SCALEY' then begin
InitializeScaleBaseUnits;
Stack.SetInt(PStart, MulDiv(Stack.GetInt(PStart-1), ScaleBaseUnitY, OrigBaseUnitY));
end else if Proc.Name = 'CREATECUSTOMFORM' then begin
NewSetupForm := TSetupForm.CreateNew(nil);
try
NewSetupForm.AutoScroll := False;
NewSetupForm.BorderStyle := bsDialog;
NewSetupForm.InitializeFont;
except
NewSetupForm.Free;
raise;
end;
Stack.SetClass(PStart, NewSetupForm);
end else
Result := False;
end;
{ NewDisk }
function NewDiskProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
S: String;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'SELECTDISK' then begin
S := Stack.GetString(PStart-3);
Stack.SetBool(PStart, SelectDisk(Stack.GetInt(PStart-1), Stack.GetString(PStart-2), S));
Stack.SetString(PStart-3, S);
end else
Result := False;
end;
{ BrowseFunc }
function BrowseFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
S: String;
ParentWnd: HWND;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'BROWSEFORFOLDER' then begin
if Assigned(WizardForm) then
ParentWnd := WizardForm.Handle
else
ParentWnd := 0;
S := Stack.GetString(PStart-2);
Stack.SetBool(PStart, BrowseForFolder(Stack.GetString(PStart-1), S, ParentWnd, Stack.GetBool(PStart-3)));
Stack.SetString(PStart-2, S);
end else if Proc.Name = 'GETOPENFILENAME' then begin
if Assigned(WizardForm) then
ParentWnd := WizardForm.Handle
else
ParentWnd := 0;
S := Stack.GetString(PStart-2);
Stack.SetBool(PStart, NewGetOpenFileName(Stack.GetString(PStart-1), S, Stack.GetString(PStart-3), Stack.GetString(PStart-4), Stack.GetString(PStart-5), ParentWnd));
Stack.SetString(PStart-2, S);
end else if Proc.Name = 'GETOPENFILENAMEMULTI' then begin
if Assigned(WizardForm) then
ParentWnd := WizardForm.Handle
else
ParentWnd := 0;
Stack.SetBool(PStart, NewGetOpenFileNameMulti(Stack.GetString(PStart-1), TStrings(Stack.GetClass(PStart-2)), Stack.GetString(PStart-3), Stack.GetString(PStart-4), Stack.GetString(PStart-5), ParentWnd));
end else if Proc.Name = 'GETSAVEFILENAME' then begin
if Assigned(WizardForm) then
ParentWnd := WizardForm.Handle
else
ParentWnd := 0;
S := Stack.GetString(PStart-2);
Stack.SetBool(PStart, NewGetSaveFileName(Stack.GetString(PStart-1), S, Stack.GetString(PStart-3), Stack.GetString(PStart-4), Stack.GetString(PStart-5), ParentWnd));
Stack.SetString(PStart-2, S);
end else
Result := False;
end;
{ CmnFunc }
function CmnFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
ID: TSetupMessageID;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'MSGBOX' then begin
if IsUninstaller then
ID := msgUninstallAppTitle
else
ID := msgSetupAppTitle;
Stack.SetInt(PStart, LoggedMsgBox(Stack.GetString(PStart-1), SetupMessages[ID], TMsgBoxType(Stack.GetInt(PStart-2)), Stack.GetInt(PStart-3), False, 0));
end else if Proc.Name = 'MINIMIZEPATHNAME' then begin
Stack.SetString(PStart, MinimizePathName(Stack.GetString(PStart-1), TFont(Stack.GetClass(PStart-2)), Stack.GetInt(PStart-3)));
end else
Result := False;
end;
{ CmnFunc2 }
function CmnFunc2Proc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
procedure CrackCodeRootKey(const CodeRootKey: Longint; var RegView: TRegView;
var RootKey: HKEY);
begin
{ Allow only predefined key handles (8xxxxxxx). Can't accept handles to
open keys because they might have our special flag bits set.
Also reject unknown flags which may have a meaning in the future. }
if (CodeRootKey shr 31 <> 1) or
((CodeRootKey and CodeRootKeyFlagMask) and not CodeRootKeyValidFlags <> 0) then
InternalError('Invalid RootKey value');
if CodeRootKey and CodeRootKeyFlag32Bit <> 0 then
RegView := rv32Bit
else if CodeRootKey and CodeRootKeyFlag64Bit <> 0 then begin
if not IsWin64 then
InternalError('Cannot access 64-bit registry keys on this version of Windows');
RegView := rv64Bit;
end
else
RegView := InstallDefaultRegView;
RootKey := CodeRootKey and not CodeRootKeyFlagMask;
end;
function GetSubkeyOrValueNames(const RegView: TRegView; const RootKey: HKEY;
const SubKeyName: String; Arr: PPSVariantIFC; const Subkey: Boolean): Boolean;
const
samDesired: array [Boolean] of REGSAM = (KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS);
var
K: HKEY;
I: Cardinal;
Buf, S: String;
BufSize, R: DWORD;
begin
Result := False;
SetString(Buf, nil, 512);
if RegOpenKeyExView(RegView, RootKey, PChar(SubKeyName), 0, samDesired[Subkey], K) <> ERROR_SUCCESS then
Exit;
try
PSDynArraySetLength(Pointer(Arr.Dta^), Arr.aType, 0);
I := 0;
while True do begin
BufSize := Length(Buf);
if Subkey then
R := RegEnumKeyEx(K, I, @Buf[1], BufSize, nil, nil, nil, nil)
else
R := RegEnumValue(K, I, @Buf[1], BufSize, nil, nil, nil, nil);
case R of
ERROR_SUCCESS: ;
ERROR_NO_MORE_ITEMS: Break;
ERROR_MORE_DATA:
begin
{ Double the size of the buffer and try again }
if Length(Buf) >= 65536 then begin
{ Sanity check: If we tried a 64 KB buffer and it's still saying
there's more data, something must be seriously wrong. Bail. }
Exit;
end;
SetString(Buf, nil, Length(Buf) * 2);
Continue;
end;
else
Exit; { unknown failure... }
end;
PSDynArraySetLength(Pointer(Arr.Dta^), Arr.aType, I+1);
SetString(S, PChar(@Buf[1]), BufSize);
VNSetString(PSGetArrayField(Arr^, I), S);
Inc(I);
end;
finally
RegCloseKey(K);
end;
Result := True;
end;
var
PStart: Cardinal;
ExistingFilename: String;
RegView: TRegView;
K, RootKey: HKEY;
S, N, V: String;
DataS: AnsiString;
Typ, ExistingTyp, Data, Size: DWORD;
Arr: TPSVariantIFC;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'FILEEXISTS' then begin
Stack.SetBool(PStart, NewFileExistsRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else if Proc.Name = 'DIREXISTS' then begin
Stack.SetBool(PStart, DirExistsRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else if Proc.Name = 'FILEORDIREXISTS' then begin
Stack.SetBool(PStart, FileOrDirExistsRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else if Proc.Name = 'GETINISTRING' then begin
Stack.SetString(PStart, GetIniString(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetString(PStart-3), Stack.GetString(PStart-4)));
end else if Proc.Name = 'GETINIINT' then begin
Stack.SetInt(PStart, GetIniInt(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetInt(PStart-3), Stack.GetInt(PStart-4), Stack.GetInt(PStart-5), Stack.GetString(PStart-6)));
end else if Proc.Name = 'GETINIBOOL' then begin
Stack.SetBool(PStart, GetIniBool(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetBool(PStart-3), Stack.GetString(PStart-4)));
end else if Proc.Name = 'INIKEYEXISTS' then begin
Stack.SetBool(PStart, IniKeyExists(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetString(PStart-3)));
end else if Proc.Name = 'ISINISECTIONEMPTY' then begin
Stack.SetBool(PStart, IsIniSectionEmpty(Stack.GetString(PStart-1), Stack.GetString(PStart-2)));
end else if Proc.Name = 'SETINISTRING' then begin
Stack.SetBool(PStart, SetIniString(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetString(PStart-3), Stack.GetString(PStart-4)));
end else if Proc.Name = 'SETINIINT' then begin
Stack.SetBool(PStart, SetIniInt(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetInt(PStart-3), Stack.GetString(PStart-4)));
end else if Proc.Name = 'SETINIBOOL' then begin
Stack.SetBool(PStart, SetIniBool(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetBool(PStart-3), Stack.GetString(PStart-4)));
end else if Proc.Name = 'DELETEINIENTRY' then begin
DeleteIniEntry(Stack.GetString(PStart), Stack.GetString(PStart-1), Stack.GetString(PStart-2));
end else if Proc.Name = 'DELETEINISECTION' then begin
DeleteIniSection(Stack.GetString(PStart), Stack.GetString(PStart-1));
end else if Proc.Name = 'GETENV' then begin
Stack.SetString(PStart, GetEnv(Stack.GetString(PStart-1)));
end else if Proc.Name = 'GETCMDTAIL' then begin
Stack.SetString(PStart, GetCmdTail());
end else if Proc.Name = 'PARAMCOUNT' then begin
Stack.SetInt(PStart, NewParamCount());
end else if Proc.Name = 'PARAMSTR' then begin
Stack.SetString(PStart, NewParamStr(Stack.GetInt(PStart-1)));
end else if Proc.Name = 'ADDBACKSLASH' then begin
Stack.SetString(PStart, AddBackslash(Stack.GetString(PStart-1)));
end else if Proc.Name = 'REMOVEBACKSLASH' then begin
Stack.SetString(PStart, RemoveBackslash(Stack.GetString(PStart-1)));
end else if Proc.Name = 'REMOVEBACKSLASHUNLESSROOT' then begin
Stack.SetString(PStart, RemoveBackslashUnlessRoot(Stack.GetString(PStart-1)));
end else if Proc.Name = 'ADDQUOTES' then begin
Stack.SetString(PStart, AddQuotes(Stack.GetString(PStart-1)));
end else if Proc.Name = 'REMOVEQUOTES' then begin
Stack.SetString(PStart, RemoveQuotes(Stack.GetString(PStart-1)));
end else if Proc.Name = 'GETSHORTNAME' then begin
Stack.SetString(PStart, GetShortNameRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else if Proc.Name = 'GETWINDIR' then begin
Stack.SetString(PStart, GetWinDir());
end else if Proc.Name = 'GETSYSTEMDIR' then begin
Stack.SetString(PStart, GetSystemDir());
end else if Proc.Name = 'GETSYSWOW64DIR' then begin
Stack.SetString(PStart, GetSysWow64Dir());
end else if Proc.Name = 'GETSYSNATIVEDIR' then begin
Stack.SetString(PStart, GetSysNativeDir(IsWin64));
end else if Proc.Name = 'GETTEMPDIR' then begin
Stack.SetString(PStart, GetTempDir());
end else if Proc.Name = 'STRINGCHANGE' then begin
S := Stack.GetString(PStart-1);
Stack.SetInt(PStart, StringChange(S, Stack.GetString(PStart-2), Stack.GetString(PStart-3)));
Stack.SetString(PStart-1, S);
end else if Proc.Name = 'STRINGCHANGEEX' then begin
S := Stack.GetString(PStart-1);
Stack.SetInt(PStart, StringChangeEx(S, Stack.GetString(PStart-2), Stack.GetString(PStart-3), Stack.GetBool(PStart-4)));
Stack.SetString(PStart-1, S);
end else if Proc.Name = 'USINGWINNT' then begin
Stack.SetBool(PStart, UsingWinNT());
end else if Proc.Name = 'FILECOPY' then begin
ExistingFilename := Stack.GetString(PStart-1);
if PathCompare(ExistingFilename, SetupLdrOriginalFilename) <> 0 then
Stack.SetBool(PStart, CopyFileRedir(ScriptFuncDisableFsRedir,
ExistingFilename, Stack.GetString(PStart-2), Stack.GetBool(PStart-3)))
else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'CONVERTPERCENTSTR' then begin
S := Stack.GetString(PStart-1);
Stack.SetBool(PStart, ConvertPercentStr(S));
Stack.SetString(PStart-1, S);
end else if Proc.Name = 'REGKEYEXISTS' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
Stack.SetBool(PStart, True);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGVALUEEXISTS' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
Stack.SetBool(PStart, RegValueExists(K, PChar(N)));
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGDELETEKEYINCLUDINGSUBKEYS' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
Stack.SetBool(PStart, RegDeleteKeyIncludingSubkeys(RegView, RootKey, PChar(S)) = ERROR_SUCCESS);
end else if Proc.Name = 'REGDELETEKEYIFEMPTY' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
Stack.SetBool(PStart, RegDeleteKeyIfEmpty(RegView, RootKey, PChar(S)) = ERROR_SUCCESS);
end else if Proc.Name = 'REGDELETEVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_SET_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
Stack.SetBool(PStart, RegDeleteValue(K, PChar(N)) = ERROR_SUCCESS);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGGETSUBKEYNAMES' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
Arr := NewTPSVariantIFC(Stack[PStart-3], True);
Stack.SetBool(PStart, GetSubkeyOrValueNames(RegView, RootKey,
Stack.GetString(PStart-2), @Arr, True));
end else if Proc.Name = 'REGGETVALUENAMES' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
Arr := NewTPSVariantIFC(Stack[PStart-3], True);
Stack.SetBool(PStart, GetSubkeyOrValueNames(RegView, RootKey,
Stack.GetString(PStart-2), @Arr, False));
end else if Proc.Name = 'REGQUERYSTRINGVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
S := Stack.GetString(PStart-4);
Stack.SetBool(PStart, RegQueryStringValue(K, PChar(N), S));
Stack.SetString(PStart-4, S);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGQUERYMULTISTRINGVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
S := Stack.GetString(PStart-4);
Stack.SetBool(PStart, RegQueryMultiStringValue(K, PChar(N), S));
Stack.SetString(PStart-4, S);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGQUERYDWORDVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
Size := SizeOf(Data);
if (RegQueryValueEx(K, PChar(N), nil, @Typ, @Data, @Size) = ERROR_SUCCESS) and (Typ = REG_DWORD) then begin
Stack.SetInt(PStart-4, Data);
Stack.SetBool(PStart, True);
end else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGQUERYBINARYVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegOpenKeyExView(RegView, RootKey, PChar(S), 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
if RegQueryValueEx(K, PChar(N), nil, @Typ, nil, @Size) = ERROR_SUCCESS then begin
SetLength(DataS, Size);
if RegQueryValueEx(K, PChar(N), nil, @Typ, @DataS[1], @Size) = ERROR_SUCCESS then begin
StackSetAnsiString(Stack, PStart-4, DataS);
Stack.SetBool(PStart, True);
end else
Stack.SetBool(PStart, False);
end else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGWRITESTRINGVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegCreateKeyExView(RegView, RootKey, PChar(S), 0, nil, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE or KEY_SET_VALUE, nil, K, nil) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
V := Stack.GetString(PStart-4);
if (RegQueryValueEx(K, PChar(N), nil, @ExistingTyp, nil, nil) = ERROR_SUCCESS) and (ExistingTyp = REG_EXPAND_SZ) then
Typ := REG_EXPAND_SZ
else
Typ := REG_SZ;
if RegSetValueEx(K, PChar(N), 0, Typ, PChar(V), (Length(V)+1)*SizeOf(V[1])) = ERROR_SUCCESS then
Stack.SetBool(PStart, True)
else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGWRITEEXPANDSTRINGVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegCreateKeyExView(RegView, RootKey, PChar(S), 0, nil, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nil, K, nil) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
V := Stack.GetString(PStart-4);
if RegSetValueEx(K, PChar(N), 0, REG_EXPAND_SZ, PChar(V), (Length(V)+1)*SizeOf(V[1])) = ERROR_SUCCESS then
Stack.SetBool(PStart, True)
else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGWRITEMULTISTRINGVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegCreateKeyExView(RegView, RootKey, PChar(S), 0, nil, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nil, K, nil) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
V := Stack.GetString(PStart-4);
{ Multi-string data requires two null terminators: one after the last
string, and one to mark the end.
Delphi's String type is implicitly null-terminated, so only one null
needs to be added to the end. }
if (V <> '') and (V[Length(V)] <> #0) then
V := V + #0;
if RegSetValueEx(K, PChar(N), 0, REG_MULTI_SZ, PChar(V), (Length(V)+1)*SizeOf(V[1])) = ERROR_SUCCESS then
Stack.SetBool(PStart, True)
else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGWRITEDWORDVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegCreateKeyExView(RegView, RootKey, PChar(S), 0, nil, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nil, K, nil) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
Data := Stack.GetInt(PStart-4);
if RegSetValueEx(K, PChar(N), 0, REG_DWORD, @Data, SizeOf(Data)) = ERROR_SUCCESS then
Stack.SetBool(PStart, True)
else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'REGWRITEBINARYVALUE' then begin
CrackCodeRootKey(Stack.GetInt(PStart-1), RegView, RootKey);
S := Stack.GetString(PStart-2);
if RegCreateKeyExView(RegView, RootKey, PChar(S), 0, nil, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nil, K, nil) = ERROR_SUCCESS then begin
N := Stack.GetString(PStart-3);
DataS := StackGetAnsiString(Stack, PStart-4);
if RegSetValueEx(K, PChar(N), 0, REG_BINARY, @DataS[1], Length(DataS)) = ERROR_SUCCESS then
Stack.SetBool(PStart, True)
else
Stack.SetBool(PStart, False);
RegCloseKey(K);
end else
Stack.SetBool(PStart, False);
end else if Proc.Name = 'ISADMINLOGGEDON' then begin
Stack.SetBool(PStart, IsAdminLoggedOn());
end else if Proc.Name = 'ISPOWERUSERLOGGEDON' then begin
Stack.SetBool(PStart, IsPowerUserLoggedOn());
end else if Proc.Name = 'FONTEXISTS' then begin
Stack.SetBool(PStart, FontExists(Stack.GetString(PStart-1)));
end else if Proc.Name = 'GETUILANGUAGE' then begin
Stack.SetInt(PStart, GetUILanguage);
end else if Proc.Name = 'ADDPERIOD' then begin
Stack.SetString(PStart, AddPeriod(Stack.GetString(PStart-1)));
end else if Proc.Name = 'CHARLENGTH' then begin
Stack.SetInt(PStart, PathCharLength(Stack.GetString(PStart-1), Stack.GetInt(PStart-2)));
end else if Proc.Name = 'SETNTFSCOMPRESSION' then begin
Stack.SetBool(PStart, SetNTFSCompressionRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), Stack.GetBool(PStart-2)));
end else
Result := False;
end;
{ Install }
function InstallProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'EXTRACTTEMPORARYFILE' then begin
ExtractTemporaryFile(Stack.GetString(PStart));
end else if Proc.Name = 'EXTRACTTEMPORARYFILES' then begin
Stack.SetInt(PStart, ExtractTemporaryFiles(Stack.GetString(PStart-1)));
end else
Result := False;
end;
{ InstFunc }
procedure ProcessMessagesProc; far;
begin
Application.ProcessMessages;
end;
function InstFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
Filename: String;
WindowDisabler: TWindowDisabler;
ResultCode, ErrorCode: Integer;
FreeBytes, TotalBytes: Integer64;
RunAsOriginalUser: Boolean;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'CHECKFORMUTEXES' then begin
Stack.SetBool(PStart, CheckForMutexes(Stack.GetString(PStart-1)));
end else if Proc.Name = 'DECREMENTSHAREDCOUNT' then begin
if Stack.GetBool(PStart-1) then begin
if not IsWin64 then
InternalError('Cannot access 64-bit registry keys on this version of Windows');
Stack.SetBool(PStart, DecrementSharedCount(rv64Bit, Stack.GetString(PStart-2)));
end
else
Stack.SetBool(PStart, DecrementSharedCount(rv32Bit, Stack.GetString(PStart-2)));
end else if Proc.Name = 'DELAYDELETEFILE' then begin
DelayDeleteFile(ScriptFuncDisableFsRedir, Stack.GetString(PStart), Stack.GetInt(PStart-1), 250, 250);
end else if Proc.Name = 'DELTREE' then begin
Stack.SetBool(PStart, DelTree(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), Stack.GetBool(PStart-2), Stack.GetBool(PStart-3), Stack.GetBool(PStart-4), False, nil, nil, nil));
end else if Proc.Name = 'GENERATEUNIQUENAME' then begin
Stack.SetString(PStart, GenerateUniqueName(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), Stack.GetString(PStart-2)));
end else if Proc.Name = 'GETCOMPUTERNAMESTRING' then begin
Stack.SetString(PStart, GetComputerNameString());
end else if Proc.Name = 'GETMD5OFFILE' then begin
Stack.SetString(PStart, MD5DigestToString(GetMD5OfFile(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1))));
end else if Proc.Name = 'GETMD5OFSTRING' then begin
Stack.SetString(PStart, MD5DigestToString(GetMD5OfAnsiString(StackGetAnsiString(Stack, PStart-1))));
end else if Proc.Name = 'GETMD5OFUNICODESTRING' then begin
{$IFDEF UNICODE}
Stack.SetString(PStart, MD5DigestToString(GetMD5OfUnicodeString(Stack.GetString(PStart-1))));
{$ELSE}
NoNonUnicodeFuncError(Proc.Name);
{$ENDIF}
end else if Proc.Name = 'GETSHA1OFFILE' then begin
Stack.SetString(PStart, SHA1DigestToString(GetSHA1OfFile(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1))));
end else if Proc.Name = 'GETSHA1OFSTRING' then begin
Stack.SetString(PStart, SHA1DigestToString(GetSHA1OfAnsiString(StackGetAnsiString(Stack, PStart-1))));
end else if Proc.Name = 'GETSHA1OFUNICODESTRING' then begin
{$IFDEF UNICODE}
Stack.SetString(PStart, SHA1DigestToString(GetSHA1OfUnicodeString(Stack.GetString(PStart-1))));
{$ELSE}
NoNonUnicodeFuncError(Proc.Name);
{$ENDIF}
end else if Proc.Name = 'GETSPACEONDISK' then begin
if GetSpaceOnDisk(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
if Stack.GetBool(PStart-2) then begin
Div64(FreeBytes, 1024*1024);
Div64(TotalBytes, 1024*1024);
end;
{ Cap at 2 GB, as [Code] doesn't support 64-bit integers }
if (FreeBytes.Hi <> 0) or (FreeBytes.Lo and $80000000 <> 0) then
FreeBytes.Lo := $7FFFFFFF;
if (TotalBytes.Hi <> 0) or (TotalBytes.Lo and $80000000 <> 0) then
TotalBytes.Lo := $7FFFFFFF;
Stack.SetUInt(PStart-3, FreeBytes.Lo);
Stack.SetUInt(PStart-4, TotalBytes.Lo);
Stack.SetBool(PStart, True);
end else
Stack.SetBool(PStart, False);
{$IFNDEF PS_NOINT64}
end else if Proc.Name = 'GETSPACEONDISK64' then begin
if GetSpaceOnDisk(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), FreeBytes, TotalBytes) then begin
Stack.SetInt64(PStart-2, Int64(FreeBytes.Hi) shl 32 + FreeBytes.Lo);
Stack.SetInt64(PStart-3, Int64(TotalBytes.Hi) shl 32 + TotalBytes.Lo);
Stack.SetBool(PStart, True);
end else
Stack.SetBool(PStart, False);
{$ENDIF}
end else if Proc.Name = 'GETUSERNAMESTRING' then begin
Stack.SetString(PStart, GetUserNameString());
end else if Proc.Name = 'INCREMENTSHAREDCOUNT' then begin
if Stack.GetBool(PStart) then begin
if not IsWin64 then
InternalError('Cannot access 64-bit registry keys on this version of Windows');
IncrementSharedCount(rv64Bit, Stack.GetString(PStart-1), Stack.GetBool(PStart-2));
end
else
IncrementSharedCount(rv32Bit, Stack.GetString(PStart-1), Stack.GetBool(PStart-2));
end else if (Proc.Name = 'EXEC') or (Proc.Name = 'EXECASORIGINALUSER') then begin
RunAsOriginalUser := Proc.Name = 'EXECASORIGINALUSER';
if IsUninstaller and RunAsOriginalUser then
NoUninstallFuncError(Proc.Name);
Filename := Stack.GetString(PStart-1);
if PathCompare(Filename, SetupLdrOriginalFilename) <> 0 then begin
{ Disable windows so the user can't utilize our UI during the InstExec
call }
WindowDisabler := TWindowDisabler.Create;
try
Stack.SetBool(PStart, InstExecEx(RunAsOriginalUser,
ScriptFuncDisableFsRedir, Filename, Stack.GetString(PStart-2),
Stack.GetString(PStart-3), TExecWait(Stack.GetInt(PStart-5)),
Stack.GetInt(PStart-4), ProcessMessagesProc, ResultCode));
finally
WindowDisabler.Free;
end;
Stack.SetInt(PStart-6, ResultCode);
end else begin
Stack.SetBool(PStart, False);
Stack.SetInt(PStart-6, ERROR_ACCESS_DENIED);
end;
end else if (Proc.Name = 'SHELLEXEC') or (Proc.Name = 'SHELLEXECASORIGINALUSER') then begin
RunAsOriginalUser := Proc.Name = 'SHELLEXECASORIGINALUSER';
if IsUninstaller and RunAsOriginalUser then
NoUninstallFuncError(Proc.Name);
Filename := Stack.GetString(PStart-2);
if PathCompare(Filename, SetupLdrOriginalFilename) <> 0 then begin
{ Disable windows so the user can't utilize our UI during the
InstShellExec call }
WindowDisabler := TWindowDisabler.Create;
try
Stack.SetBool(PStart, InstShellExecEx(RunAsOriginalUser,
Stack.GetString(PStart-1), Filename, Stack.GetString(PStart-3),
Stack.GetString(PStart-4), TExecWait(Stack.GetInt(PStart-6)),
Stack.GetInt(PStart-5), ProcessMessagesProc, ErrorCode));
finally
WindowDisabler.Free;
end;
Stack.SetInt(PStart-7, ErrorCode);
end else begin
Stack.SetBool(PStart, False);
Stack.SetInt(PStart-7, ERROR_ACCESS_DENIED);
end;
end else if Proc.Name = 'ISPROTECTEDSYSTEMFILE' then begin
Stack.SetBool(PStart, IsProtectedSystemFile(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else if Proc.Name = 'MAKEPENDINGFILERENAMEOPERATIONSCHECKSUM' then begin
Stack.SetString(PStart, MD5DigestToString(MakePendingFileRenameOperationsChecksum));
end else if Proc.Name = 'MODIFYPIFFILE' then begin
Stack.SetBool(PStart, ModifyPifFile(Stack.GetString(PStart-1), Stack.GetBool(PStart-2)));
end else if Proc.Name = 'REGISTERSERVER' then begin
RegisterServer(False, Stack.GetBool(PStart), Stack.GetString(PStart-1), Stack.GetBool(PStart-2));
end else if Proc.Name = 'UNREGISTERSERVER' then begin
try
RegisterServer(True, Stack.GetBool(PStart-1), Stack.GetString(PStart-2), Stack.GetBool(PStart-3));
Stack.SetBool(PStart, True);
except
Stack.SetBool(PStart, False);
end;
end else if Proc.Name = 'UNREGISTERFONT' then begin
UnregisterFont(Stack.GetString(PStart), Stack.GetString(PStart-1));
end else if Proc.Name = 'RESTARTREPLACE' then begin
RestartReplace(ScriptFuncDisableFsRedir, Stack.GetString(PStart), Stack.GetString(PStart-1));
end else if Proc.Name = 'FORCEDIRECTORIES' then begin
Stack.SetBool(PStart, ForceDirectories(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1)));
end else
Result := False;
end;
{ InstFnc2 }
function InstFnc2Proc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
var
PStart: Cardinal;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'CREATESHELLLINK' then begin
Stack.SetString(PStart, CreateShellLink(Stack.GetString(PStart-1),
Stack.GetString(PStart-2), Stack.GetString(PStart-3),
Stack.GetString(PStart-4), Stack.GetString(PStart-5),
Stack.GetString(PStart-6), Stack.GetInt(PStart-7),
Stack.GetInt(PStart-8), 0, False, '', False, False));
end else if Proc.Name = 'REGISTERTYPELIBRARY' then begin
if Stack.GetBool(PStart) then
HelperRegisterTypeLibrary(False, Stack.GetString(PStart-1))
else
RegisterTypeLibrary(Stack.GetString(PStart-1));
end else if Proc.Name = 'UNREGISTERTYPELIBRARY' then begin
try
if Stack.GetBool(PStart-1) then
HelperRegisterTypeLibrary(True, Stack.GetString(PStart-2))
else
UnregisterTypeLibrary(Stack.GetString(PStart-2));
Stack.SetBool(PStart, True);
except
Stack.SetBool(PStart, False);
end;
end else if Proc.Name = 'UNPINSHELLLINK' then begin
Stack.SetBool(PStart, UnpinShellLink(Stack.GetString(PStart-1)));
end else
Result := False;
end;
{ Main }
function MainProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
function CustomMessage(const MsgName: String): String;
begin
if not GetCustomMessageValue(MsgName, Result) then
InternalError(Format('Unknown custom message name "%s"', [MsgName]));
end;
var
PStart: Cardinal;
MinVersion, OnlyBelowVersion: TSetupVersionData;
WizardComponents, WizardTasks: TStringList;
ID: TSetupMessageID;
S: String;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'WIZARDFORM' then begin
Stack.SetClass(PStart, GetWizardForm);
end else if Proc.Name = 'MAINFORM' then begin
Stack.SetClass(PStart, GetMainForm);
end else if Proc.Name = 'ACTIVELANGUAGE' then begin
Stack.SetString(PStart, ExpandConst('{language}'));
end else if Proc.Name = 'ISCOMPONENTSELECTED' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
WizardComponents := TStringList.Create();
try
GetWizardForm.GetSelectedComponents(WizardComponents, False, False);
S := Stack.GetString(PStart-1);
StringChange(S, '/', '\');
Stack.SetBool(PStart, ShouldProcessEntry(WizardComponents, nil, S, '', '', ''));
finally
WizardComponents.Free();
end;
end else if Proc.Name = 'ISTASKSELECTED' then begin
if IsUninstaller then
NoUninstallFuncError(Proc.Name);
WizardTasks := TStringList.Create();
try