summaryrefslogtreecommitdiffstats
path: root/private/sdktools/instaler/instaler.h
blob: 5ae44b683037f1a13ab5bab6ce3103f4c7420536 (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
/*++

Copyright (c) 1992  Microsoft Corporation

Module Name:

    instaler.h

Abstract:

    Main include file for the INSTALER application.

Author:

    Steve Wood (stevewo) 09-Aug-1994

Revision History:

--*/

#ifdef RC_INVOKED
#include <windows.h>

#define FILEBMP  500
#define DIRBMP   501

#else

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <ntdbg.h>
#include <windows.h>
#include <vdmdbg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "errormsg.h"

//
// Data structures and entry points in ERROR.C
//

#define TRACE_ENABLED 1

#if TRACE_ENABLED
extern ULONG EnabledTraceEvents;

#define DBG_MASK_DBGEVENT       0x00000001
#define DBG_MASK_INTERNALERROR  0x00000002
#define DBG_MASK_MEMORYERROR    0x00000004
#define DBG_MASK_CREATEEVENT    0x00000008

VOID
TraceDisplay(
    const char *FormatString,
    ...
    );

#define DbgEvent( m, x ) if (EnabledTraceEvents & (DBG_MASK_##m)) TraceDisplay x
#define TestDbgEvent( m ) (EnabledTraceEvents & (DBG_MASK_##m))
#else
#define DbgEvent( m, x )
#define TestDbgEvent( m ) (FALSE)
#endif


VOID
CDECL
DeclareError(
    UINT ErrorCode,
    UINT SupplementalErrorCode,
    ...
    );

UINT
CDECL
AskUser(
    UINT MessageBoxFlags,
    UINT MessageId,
    UINT NumberOfArguments,
    ...
    );


//
// Data structures and entry points in EVENT.C
//

VOID
CDECL
LogEvent(
    UINT MessageId,
    UINT NumberOfArguments,
    ...
    );

//
// Data structures and entry points in PROCESS.C
//

#define HANDLE_TYPE_FILE 0
#define HANDLE_TYPE_KEY 1
#define HANDLE_TYPE_NONE 2

typedef struct _OPENHANDLE_INFO {
    LIST_ENTRY Entry;
    HANDLE Handle;
    BOOLEAN Inherit;
    BOOLEAN RootDirectory;
    USHORT Type;
    USHORT LengthOfName;
    PWSTR Name;

    //
    // Union for handlers that need to store state in a handle during
    // use.
    //
    union {
        PWSTR QueryName;
    };
} OPENHANDLE_INFO, *POPENHANDLE_INFO;

typedef struct _PROCESS_INFO {
    LIST_ENTRY Entry;
    LIST_ENTRY ThreadListHead;
    LIST_ENTRY BreakpointListHead;
    LIST_ENTRY OpenHandleListHead;
    DWORD Id;
    HANDLE Handle;
    PROCESS_BASIC_INFORMATION ProcessInformation;
    WCHAR ImageFileName[ 32 ];
} PROCESS_INFO, *PPROCESS_INFO;

typedef struct _THREAD_INFO {
    LIST_ENTRY Entry;
    LIST_ENTRY BreakpointListHead;
    DWORD Id;
    HANDLE Handle;
    PVOID StartAddress;
    ULONG ModuleIndexCurrentlyIn;
    BOOLEAN SingleStepExpected;
    struct _BREAKPOINT_INFO *BreakpointToStepOver;
} THREAD_INFO, *PTHREAD_INFO;

LIST_ENTRY ProcessListHead;

BOOLEAN
AddProcess(
    LPDEBUG_EVENT DebugEvent,
    PPROCESS_INFO *ReturnedProcess
    );

BOOLEAN
DeleteProcess(
    PPROCESS_INFO Process
    );

BOOLEAN
AddThread(
    LPDEBUG_EVENT DebugEvent,
    PPROCESS_INFO Process,
    PTHREAD_INFO *ReturnedThread
    );

BOOLEAN
DeleteThread(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

PPROCESS_INFO
FindProcessById(
    ULONG Id
    );

BOOLEAN
FindProcessAndThreadForEvent(
    LPDEBUG_EVENT DebugEvent,
    PPROCESS_INFO *ReturnedProcess,
    PTHREAD_INFO *ReturnedThread
    );

BOOLEAN
HandleThreadsForSingleStep(
    PPROCESS_INFO Process,
    PTHREAD_INFO ThreadToSingleStep,
    BOOLEAN SuspendThreads
    );

BOOLEAN
ReadMemory(
    PPROCESS_INFO Process,
    PVOID Address,
    PVOID DataRead,
    ULONG BytesToRead,
    PCHAR Reason
    );

BOOLEAN
WriteMemory(
    PPROCESS_INFO Process,
    PVOID Address,
    PVOID DataToWrite,
    ULONG BytesToWrite,
    PCHAR Reason
    );

PVOID
AllocMem(
    ULONG Size
    );

VOID
FreeMem(
    PVOID *p
    );


//
// Data structures and entry points in MACHINE.C
//

PVOID BreakpointInstruction;
ULONG SizeofBreakpointInstruction;

PVOID
GetAddressForEntryPointBreakpoint(
    PVOID EntryPointAddress,
    DWORD NumberOfFunctionTableEntries OPTIONAL,
    PIMAGE_RUNTIME_FUNCTION_ENTRY FunctionTableEntries OPTIONAL
    );

BOOLEAN
SkipOverHardcodedBreakpoint(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PVOID BreakpointAddress
    );

BOOLEAN
ExtractProcedureParameters(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PULONG ReturnAddress,
    ULONG SizeOfParameters,
    PULONG Parameters
    );

BOOLEAN
ExtractProcedureReturnValue(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PVOID ReturnValue,
    ULONG SizeOfReturnValue
    );

BOOLEAN
SetProcedureReturnValue(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PVOID ReturnValue,
    ULONG SizeOfReturnValue
    );

BOOLEAN
ForceReturnToCaller(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    ULONG SizeOfParameters,
    PVOID ReturnAddress,
    PVOID ReturnValue,
    ULONG SizeOfReturnValue
    );

BOOLEAN
UndoReturnAddressBreakpoint(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

BOOLEAN
BeginSingleStepBreakpoint(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

BOOLEAN
EndSingleStepBreakpoint(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

typedef enum _API_ACTION {
    QueryPath,
    OpenPath,
    RenamePath,
    DeletePath,
    SetValue,
    DeleteValue,
    WriteIniValue,
    WriteIniSection
} API_ACTION;

typedef struct _API_SAVED_CALL_STATE {
    LIST_ENTRY Entry;
    API_ACTION Action;
    ULONG Type;
    PWSTR FullName;
    PVOID Reference;
    union {
        struct {
            BOOLEAN InheritHandle;
            BOOLEAN WriteAccessRequested;
            PHANDLE ResultHandleAddress;
        } PathOpen;
        struct {
            PWSTR NewName;
            BOOLEAN ReplaceIfExists;
        } PathRename;
        struct {
            PWSTR SectionName;
            PWSTR VariableName;
            PWSTR VariableValue;
        } SetIniValue;
        struct {
            PWSTR SectionName;
            PWSTR SectionValue;
        } SetIniSection;
    };
} API_SAVED_CALL_STATE, *PAPI_SAVED_CALL_STATE;

BOOLEAN
CreateSavedCallState(
    PPROCESS_INFO Process,
    PAPI_SAVED_CALL_STATE SavedCallState,
    API_ACTION Action,
    ULONG Type,
    PWSTR FullName,
    ...
    );

VOID
FreeSavedCallState(
    PAPI_SAVED_CALL_STATE CallState
    );



//
// Data structures and entry points in HANDLER.C
//

typedef struct _CREATEFILE_PARAMETERS {
    PHANDLE FileHandle;
    ACCESS_MASK DesiredAccess;
    POBJECT_ATTRIBUTES ObjectAttributes;
    PIO_STATUS_BLOCK IoStatusBlock;
    PLARGE_INTEGER AllocationSize;
    ULONG FileAttributes;
    ULONG ShareAccess;
    ULONG CreateDisposition;
    ULONG CreateOptions;
} CREATEFILE_PARAMETERS, *PCREATEFILE_PARAMETERS;

typedef struct _OPENFILE_PARAMETERS {
    PHANDLE FileHandle;
    ACCESS_MASK DesiredAccess;
    POBJECT_ATTRIBUTES ObjectAttributes;
    PIO_STATUS_BLOCK IoStatusBlock;
    ULONG ShareAccess;
    ULONG OpenOptions;
} OPENFILE_PARAMETERS, *POPENFILE_PARAMETERS;

typedef struct _DELETEFILE_PARAMETERS {
    POBJECT_ATTRIBUTES ObjectAttributes;
} DELETEFILE_PARAMETERS, *PDELETEFILE_PARAMETERS;

typedef struct _SETINFORMATIONFILE_PARAMETERS {
    HANDLE FileHandle;
    PIO_STATUS_BLOCK IoStatusBlock;
    PVOID FileInformation;
    ULONG Length;
    FILE_INFORMATION_CLASS FileInformationClass;
} SETINFORMATIONFILE_PARAMETERS, *PSETINFORMATIONFILE_PARAMETERS;

typedef struct _QUERYATTRIBUTESFILE_PARAMETERS {
    POBJECT_ATTRIBUTES ObjectAttributes;
    PFILE_BASIC_INFORMATION FileInformation;
} QUERYATTRIBUTESFILE_PARAMETERS, *PQUERYATTRIBUTESFILE_PARAMETERS;

typedef struct _QUERYDIRECTORYFILE_PARAMETERS {
    HANDLE FileHandle;
    HANDLE Event;
    PIO_APC_ROUTINE ApcRoutine;
    PVOID ApcContext;
    PIO_STATUS_BLOCK IoStatusBlock;
    PVOID FileInformation;
    ULONG Length;
    FILE_INFORMATION_CLASS FileInformationClass;
    BOOLEAN ReturnSingleEntry;
    PUNICODE_STRING FileName;
    BOOLEAN RestartScan;
} QUERYDIRECTORYFILE_PARAMETERS, *PQUERYDIRECTORYFILE_PARAMETERS;

typedef struct _CREATEKEY_PARAMETERS {
    PHANDLE KeyHandle;
    ACCESS_MASK DesiredAccess;
    POBJECT_ATTRIBUTES ObjectAttributes;
    ULONG TitleIndex;
    PUNICODE_STRING Class;
    ULONG CreateOptions;
    PULONG Disposition;
} CREATEKEY_PARAMETERS, *PCREATEKEY_PARAMETERS;

typedef struct _OPENKEY_PARAMETERS {
    PHANDLE KeyHandle;
    ACCESS_MASK DesiredAccess;
    POBJECT_ATTRIBUTES ObjectAttributes;
} OPENKEY_PARAMETERS, *POPENKEY_PARAMETERS;

typedef struct _DELETEKEY_PARAMETERS {
    HANDLE KeyHandle;
} DELETEKEY_PARAMETERS, *PDELETEKEY_PARAMETERS;

typedef struct _SETVALUEKEY_PARAMETERS {
    HANDLE KeyHandle;
    PUNICODE_STRING ValueName;
    ULONG TitleIndex;
    ULONG Type;
    PVOID Data;
    ULONG DataLength;
} SETVALUEKEY_PARAMETERS, *PSETVALUEKEY_PARAMETERS;

typedef struct _DELETEVALUEKEY_PARAMETERS {
    HANDLE KeyHandle;
    PUNICODE_STRING ValueName;
} DELETEVALUEKEY_PARAMETERS, *PDELETEVALUEKEY_PARAMETERS;

typedef struct _CLOSEHANDLE_PARAMETERS {
    HANDLE Handle;
} CLOSEHANDLE_PARAMETERS, *PCLOSEHANDLE_PARAMETERS;

typedef struct _GETVERSIONEXW_PARAMETERS {
    LPOSVERSIONINFOA lpVersionInformation;
} GETVERSIONEXW_PARAMETERS, *PGETVERSIONEXW_PARAMETERS;

typedef struct _SETCURRENTDIRECTORYA_PARAMETERS {
    LPSTR lpPathName;
} SETCURRENTDIRECTORYA_PARAMETERS, *PSETCURRENTDIRECTORYA_PARAMETERS;

typedef struct _SETCURRENTDIRECTORYW_PARAMETERS {
    PWSTR lpPathName;
} SETCURRENTDIRECTORYW_PARAMETERS, *PSETCURRENTDIRECTORYW_PARAMETERS;

typedef struct _WRITEPRIVATEPROFILESTRINGA_PARAMETERS {
    LPCSTR lpAppName;
    LPCSTR lpKeyName;
    LPCSTR lpString;
    LPCSTR lpFileName;
} WRITEPRIVATEPROFILESTRINGA_PARAMETERS, *PWRITEPRIVATEPROFILESTRINGA_PARAMETERS;

typedef struct _WRITEPRIVATEPROFILESTRINGW_PARAMETERS {
    LPCWSTR lpAppName;
    LPCWSTR lpKeyName;
    LPCWSTR lpString;
    LPCWSTR lpFileName;
} WRITEPRIVATEPROFILESTRINGW_PARAMETERS, *PWRITEPRIVATEPROFILESTRINGW_PARAMETERS;

typedef struct _WRITEPRIVATEPROFILESECTIONA_PARAMETERS {
    LPCSTR lpAppName;
    LPCSTR lpString;
    LPCSTR lpFileName;
} WRITEPRIVATEPROFILESECTIONA_PARAMETERS, *PWRITEPRIVATEPROFILESECTIONA_PARAMETERS;

typedef struct _WRITEPRIVATEPROFILESECTIONW_PARAMETERS {
    LPCWSTR lpAppName;
    LPCWSTR lpString;
    LPCWSTR lpFileName;
} WRITEPRIVATEPROFILESECTIONW_PARAMETERS, *PWRITEPRIVATEPROFILESECTIONW_PARAMETERS;

typedef struct _REGCONNECTREGISTRYW_PARAMETERS {
    LPWSTR lpMachineName;
    HKEY hKey;
    PHKEY phkResult;
} REGCONNECTREGISTRYW_PARAMETERS, *PREGCONNECTREGISTRYW_PARAMETERS;

typedef struct _API_SAVED_PARAMETERS {
    API_SAVED_CALL_STATE SavedCallState;
    union {
        CREATEFILE_PARAMETERS CreateFile;
        OPENFILE_PARAMETERS OpenFile;
        DELETEFILE_PARAMETERS DeleteFile;
        SETINFORMATIONFILE_PARAMETERS SetInformationFile;
        QUERYATTRIBUTESFILE_PARAMETERS QueryAttributesFile;
        QUERYDIRECTORYFILE_PARAMETERS QueryDirectoryFile;
        CREATEKEY_PARAMETERS CreateKey;
        OPENKEY_PARAMETERS OpenKey;
        DELETEKEY_PARAMETERS DeleteKey;
        SETVALUEKEY_PARAMETERS SetValueKey;
        DELETEVALUEKEY_PARAMETERS DeleteValueKey;
        CLOSEHANDLE_PARAMETERS CloseHandle;
        GETVERSIONEXW_PARAMETERS GetVersionExW;
        SETCURRENTDIRECTORYA_PARAMETERS SetCurrentDirectoryA;
        SETCURRENTDIRECTORYW_PARAMETERS SetCurrentDirectoryW;
        WRITEPRIVATEPROFILESTRINGA_PARAMETERS WritePrivateProfileStringA;
        WRITEPRIVATEPROFILESTRINGW_PARAMETERS WritePrivateProfileStringW;
        WRITEPRIVATEPROFILESECTIONA_PARAMETERS WritePrivateProfileSectionA;
        WRITEPRIVATEPROFILESECTIONW_PARAMETERS WritePrivateProfileSectionW;
        REGCONNECTREGISTRYW_PARAMETERS RegConnectRegistryW;
    } InputParameters;
    PVOID ReturnAddress;
    union {
        UCHAR ReturnedByte;
        USHORT ReturnedShort;
        ULONG ReturnedLong;
        ULONGLONG ReturnedQuad;
        BOOL ReturnedBool;
    } ReturnValue;
    BOOLEAN ReturnValueValid;

    //
    // Union for handlers that need to store state between entry and
    // exit, without the overhead of allocating an API_SAVED_CALL_STATE
    //
    union {
        BOOLEAN AbortCall;
        PWSTR CurrentDirectory;
    };
} API_SAVED_PARAMETERS, *PAPI_SAVED_PARAMETERS;

BOOLEAN
NtCreateFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtOpenFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtDeleteFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtSetInformationFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtQueryAttributesFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtQueryDirectoryFileHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtCreateKeyHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtOpenKeyHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtDeleteKeyHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtSetValueKeyHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
NtDeleteValueKeyHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );


BOOLEAN
NtCloseHandleHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
GetVersionHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
GetVersionExWHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
SetCurrentDirectoryAHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
SetCurrentDirectoryWHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
WritePrivateProfileStringAHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
WritePrivateProfileStringWHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
WritePrivateProfileSectionAHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
WritePrivateProfileSectionWHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

BOOLEAN
RegConnectRegistryWHandler(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

//
// Data structures and entry points in DEBUG.C
//

CRITICAL_SECTION BreakTable;

typedef struct _BREAKPOINT_INFO {
    LIST_ENTRY Entry;
    PVOID Address;
    UCHAR ApiIndex;
    PWSTR ModuleName;
    LPSTR ProcedureName;
    BOOLEAN SavedInstructionValid;
    BOOLEAN SavedParametersValid;
    union {
        UCHAR Byte;
        USHORT Short;
        ULONG Long;
        ULONGLONG LongLong;
    } SavedInstruction;
    API_SAVED_PARAMETERS SavedParameters;
} BREAKPOINT_INFO, *PBREAKPOINT_INFO;

VOID
DebugEventLoop( VOID );


BOOLEAN
InstallBreakpoint(
    PPROCESS_INFO Process,
    PBREAKPOINT_INFO Breakpoint
    );

BOOLEAN
RemoveBreakpoint(
    PPROCESS_INFO Process,
    PBREAKPOINT_INFO Breakpoint
    );

BOOLEAN
HandleBreakpoint(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PBREAKPOINT_INFO Breakpoint
    );


BOOLEAN
CreateBreakpoint(
    PVOID Address,
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    UCHAR ApiIndex,
    PVOID SavedParameters,
    PBREAKPOINT_INFO *Breakpoint
    );

BOOLEAN
DestroyBreakpoint(
    PVOID Address,
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

PBREAKPOINT_INFO
FindBreakpoint(
    PVOID Address,
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread
    );

//
// Data structures and entry points in HANDLEDB.C
//

POPENHANDLE_INFO
FindOpenHandle(
    PPROCESS_INFO Process,
    HANDLE Handle,
    ULONG Type
    );

BOOLEAN
AddOpenHandle(
    PPROCESS_INFO Process,
    HANDLE Handle,
    ULONG Type,
    PWSTR Name,
    BOOLEAN InheritHandle
    );

BOOLEAN
DeleteOpenHandle(
    PPROCESS_INFO Process,
    HANDLE Handle,
    ULONG Type
    );

VOID
InheritHandles(
    PPROCESS_INFO Process
    );



//
// Data structures and entry points in FILE.C
//


typedef struct _FILE_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    ULONG PrefixLength;
    BOOLEAN WriteAccess;
    BOOLEAN Deleted;
    BOOLEAN Created;
    BOOLEAN AttributesModified;
    BOOLEAN DateModified;
    BOOLEAN ContentsModified;
    BOOLEAN DirectoryFile;
    USHORT BackupFileUniqueId;
    DWORD BackupFileAttributes;
    FILETIME BackupLastWriteTime;
    ULARGE_INTEGER BackupFileSize;
} FILE_REFERENCE, *PFILE_REFERENCE;


BOOLEAN
CreateFileReference(
    PWSTR Name,
    BOOLEAN WriteAccess,
    PFILE_REFERENCE *ReturnedReference
    );

BOOLEAN
CompleteFileReference(
    PFILE_REFERENCE p,
    BOOLEAN CallSuccessful,
    BOOLEAN Delete,
    PFILE_REFERENCE RenameReference
    );

BOOLEAN
DestroyFileReference(
    PFILE_REFERENCE p
    );

BOOLEAN
IsNewFileSameAsBackup(
    PFILE_REFERENCE p
    );

PFILE_REFERENCE
FindFileReference(
    PWSTR Name
    );

VOID
DumpFileReferenceList(
    FILE *LogFile
    );

//
// Data structures and entry points in KEY.C
//

typedef struct _KEY_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    ULONG PrefixLength;
    BOOLEAN WriteAccess;
    BOOLEAN Deleted;
    BOOLEAN Created;
    PKEY_FULL_INFORMATION BackupKeyInfo;
    LIST_ENTRY ValueReferencesListHead;
} KEY_REFERENCE, *PKEY_REFERENCE;

typedef struct _VALUE_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    BOOLEAN Modified;
    BOOLEAN Deleted;
    BOOLEAN Created;
    PKEY_VALUE_PARTIAL_INFORMATION Value;
    KEY_VALUE_PARTIAL_INFORMATION OriginalValue;
} VALUE_REFERENCE, *PVALUE_REFERENCE;

BOOLEAN
CreateKeyReference(
    PWSTR Name,
    BOOLEAN WriteAccess,
    PKEY_REFERENCE *ReturnedReference
    );

BOOLEAN
CompleteKeyReference(
    PKEY_REFERENCE p,
    BOOLEAN CallSuccessful,
    BOOLEAN Delete
    );

BOOLEAN
DestroyKeyReference(
    PKEY_REFERENCE p
    );

PKEY_REFERENCE
FindKeyReference(
    PWSTR Name
    );

VOID
MarkKeyDeleted(
    PKEY_REFERENCE KeyReference
    );

BOOLEAN
CreateValueReference(
    PPROCESS_INFO Process,
    PKEY_REFERENCE KeyReference,
    PWSTR Name,
    ULONG TitleIndex,
    ULONG Type,
    PVOID Data,
    ULONG DataLength,
    PVALUE_REFERENCE *ReturnedValueReference
    );

PVALUE_REFERENCE
FindValueReference(
    PKEY_REFERENCE KeyReference,
    PWSTR Name
    );

BOOLEAN
DestroyValueReference(
    PVALUE_REFERENCE p
    );

VOID
DumpKeyReferenceList(
    FILE *LogFile
    );

//
// Data structures and entry points in INI.C
//

typedef struct _INI_FILE_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    ULONG PrefixLength;
    BOOLEAN Created;
    FILETIME BackupLastWriteTime;
    LIST_ENTRY SectionReferencesListHead;
} INI_FILE_REFERENCE, *PINI_FILE_REFERENCE;

typedef struct _INI_SECTION_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    BOOLEAN Deleted;
    BOOLEAN Created;
    LIST_ENTRY VariableReferencesListHead;
} INI_SECTION_REFERENCE, *PINI_SECTION_REFERENCE;

typedef struct _INI_VARIABLE_REFERENCE {
    LIST_ENTRY Entry;
    PWSTR Name;
    BOOLEAN Modified;
    BOOLEAN Deleted;
    BOOLEAN Created;
    PWSTR OriginalValue;
    PWSTR Value;
} INI_VARIABLE_REFERENCE, *PINI_VARIABLE_REFERENCE;


BOOLEAN
CreateIniFileReference(
    PWSTR Name,
    PINI_FILE_REFERENCE *ReturnedReference
    );

BOOLEAN
DestroyIniFileReference(
    PINI_FILE_REFERENCE p
    );

BOOLEAN
DestroyIniSectionReference(
    PINI_SECTION_REFERENCE p1
    );

BOOLEAN
DestroyIniVariableReference(
    PINI_VARIABLE_REFERENCE p2
    );

PINI_FILE_REFERENCE
FindIniFileReference(
    PWSTR Name
    );

PINI_SECTION_REFERENCE
FindIniSectionReference(
    PINI_FILE_REFERENCE p,
    PWSTR Name,
    BOOLEAN CreateOkay
    );

PINI_VARIABLE_REFERENCE
FindIniVariableReference(
    PINI_SECTION_REFERENCE p1,
    PWSTR Name,
    BOOLEAN CreateOkay
    );

VOID
DumpIniFileReferenceList(
    FILE *LogFile
    );

//
// Data structures and entry points in NAMEDB.C
//

PWSTR
AddName(
    PUNICODE_STRING Name
    );

VOID
DumpNameDataBase(
    FILE *LogFile
    );

BOOLEAN
IncrementOpenCount(
    PWSTR Name,
    BOOLEAN CallSuccessful
    );

ULONG
QueryOpenCount(
    PWSTR Name,
    BOOLEAN CallSuccessful
    );



//
// Data structures and entry points in INIT.C
//

HMODULE InstalerModuleHandle;
HANDLE AppHeap;
UNICODE_STRING WindowsDirectory;
ULONG StartProcessTickCount;
FILE *InstalerLogFile;
BOOLEAN AskUserOnce;
BOOLEAN DefaultGetVersionToWin95;
BOOLEAN FailAllScansOfRootDirectories;



LIST_ENTRY FileReferenceListHead;
ULONG NumberOfFileReferences;
LIST_ENTRY KeyReferenceListHead;
ULONG NumberOfKeyReferences;
LIST_ENTRY IniReferenceListHead;
ULONG NumberOfIniReferences;

#define NTDLL_MODULE_INDEX 0
#define KERNEL32_MODULE_INDEX 1
#define ADVAPI32_MODULE_INDEX 2
#define MAXIMUM_MODULE_INDEX 3

typedef struct _MODULE_INFO {
    PWSTR ModuleName;
    HMODULE ModuleHandle;
} MODULE_INFO, *PMODULE_INFO;

MODULE_INFO ModuleInfo[ MAXIMUM_MODULE_INDEX ];

typedef BOOLEAN (*PAPI_HANDLER)(
    PPROCESS_INFO Process,
    PTHREAD_INFO Thread,
    PAPI_SAVED_PARAMETERS Parameters
    );

typedef struct _API_INFO {
    ULONG ModuleIndex;
    LPSTR EntryPointName;                   // Exported names are ANSI only
    PVOID EntryPointAddress;
    PAPI_HANDLER EntryPointHandler;
    ULONG SizeOfParameters;
    ULONG SizeOfReturnValue;
} API_INFO, *PAPI_INFO;

#define NTCREATEFILE_INDEX                  0
#define NTOPENFILE_INDEX                    1
#define NTDELETEFILE_INDEX                  2
#define NTSETINFORMATIONFILE_INDEX          3
#define NTQUERYATTRIBUTESFILE_INDEX         4
#define NTQUERYDIRECTORYFILE_INDEX          5
#define NTCREATEKEY_INDEX                   6
#define NTOPENKEY_INDEX                     7
#define NTDELETEKEY_INDEX                   8
#define NTSETVALUEKEY_INDEX                 9
#define NTDELETEVALUEKEY_INDEX              10
#define NTCLOSEHANDLE_INDEX                 11
#define GETVERSION_INDEX                    12
#define GETVERSIONEXW_INDEX                 13
#define SETCURRENTDIRECTORYA_INDEX          14
#define SETCURRENTDIRECTORYW_INDEX          15
#define WRITEPRIVATEPROFILESTRINGA_INDEX    16
#define WRITEPRIVATEPROFILESTRINGW_INDEX    17
#define WRITEPRIVATEPROFILESECTIONA_INDEX   18
#define WRITEPRIVATEPROFILESECTIONW_INDEX   19
#define GETPRIVATEPROFILESTRINGA_INDEX      20
#define GETPRIVATEPROFILESTRINGW_INDEX      21
#define GETPRIVATEPROFILESECTIONA_INDEX     22
#define GETPRIVATEPROFILESECTIONW_INDEX     23
#define REGCONNECTREGISTRYW_INDEX           24
#define MAXIMUM_API_INDEX                   25

API_INFO ApiInfo[ MAXIMUM_API_INDEX ];

typedef struct _DRIVE_LETTER_INFO {
    WCHAR DriveLetter;
    BOOLEAN DriveLetterValid;
    UNICODE_STRING NtLinkTarget;
} DRIVE_LETTER_INFO, *PDRIVE_LETTER_INFO;

UNICODE_STRING UNCPrefix;
UNICODE_STRING DriveLetterPrefix;
UNICODE_STRING AltDriveLetterPrefix;
DRIVE_LETTER_INFO DriveLetters[ 32 ];

BOOLEAN
InitializeInstaler(
    int argc,
    char *argv[]
    );

PVOID
LookupEntryPointInIAT(
    HMODULE ModuleHandle,
    PCHAR EntryPointName
    );

BOOLEAN
IsDriveLetterPath(
    PUNICODE_STRING Path
    );


PVOID TemporaryBuffer;
ULONG TemporaryBufferLength;
ULONG TemporaryBufferLengthGrowth;
ULONG TemporaryBufferMaximumLength;

VOID
TrimTemporaryBuffer( VOID );

BOOLEAN
GrowTemporaryBuffer(
    ULONG NeededSize
    );

ULONG
FillTemporaryBuffer(
    PPROCESS_INFO Process,
    PVOID Address,
    BOOLEAN Unicode,
    BOOLEAN DoubleNullTermination
    );

#include "instutil.h"
#include "iml.h"

PINSTALLATION_MODIFICATION_LOGFILE pImlNew;


#endif // defined( RC_INVOKED )