Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. instaler.c
  5. Abstract:
  6. USAGE: instaler "setup/install command line"
  7. Main source file for the INSTALER application. This application is
  8. intended for use as a wrapper application around another
  9. application's setup/install program. This program uses the Debugger
  10. API calls to set breakpoints in the setup/install program and its
  11. descendents at all calls to NT/Win32 API calls that modify the
  12. current system. The API calls that are tracked include:
  13. NtCreateFile
  14. NtDeleteFile
  15. NtSetInformationFile (FileRenameInformation, FileDispositionInformation)
  16. NtCreateKey
  17. NtOpenKey
  18. NtDeleteKey
  19. NtSetValueKey
  20. NtDeleteValueKey
  21. GetVersion
  22. GetVersionExW
  23. WriteProfileStringA/W
  24. WritePrivateProfileStringA/W
  25. WriteProfileSectionA/W
  26. WritePrivateProfileSectionA/W
  27. RegConnectRegistryW
  28. This program sets breakpoints around each of the above API entry
  29. points. At the breakpoint at the entry to an API call, the
  30. parameters are inspected and if the call is going to overwrite some
  31. state (e.g. create/open a file/key for write access, store a new
  32. key value or profile string), then this program will save the old
  33. state in a temporary directory before letting the API call proceed.
  34. At the exit from the API call, it will determine if the operation
  35. was successful. If not, the saved state will be discarded. If
  36. successful, it will keep the saved state for when the application
  37. setup/install program completes. Part of the Create/Open API
  38. tracking is the maintenance of a handle database so that relative opens
  39. can be handled correctly with the full path.
  40. Author:
  41. Steve Wood (stevewo) 09-Aug-1994
  42. --*/
  43. #include "instaler.h"
  44. BOOLEAN
  45. SortReferenceList(
  46. PLIST_ENTRY OldHead,
  47. ULONG NumberOfEntriesInList
  48. );
  49. int
  50. __cdecl
  51. main(
  52. int argc,
  53. char *argv[]
  54. )
  55. {
  56. if (!InitializeInstaler( argc, argv )) {
  57. ExitProcess( 1 );
  58. }
  59. else {
  60. StartProcessTickCount = GetTickCount();
  61. DebugEventLoop();
  62. printf( "Creating %ws\n", ImlPath );
  63. SortReferenceList( &FileReferenceListHead, NumberOfFileReferences );
  64. SortReferenceList( &KeyReferenceListHead, NumberOfKeyReferences );
  65. SortReferenceList( &IniReferenceListHead, NumberOfIniReferences );
  66. DumpFileReferenceList( InstalerLogFile );
  67. DumpKeyReferenceList( InstalerLogFile );
  68. DumpIniFileReferenceList( InstalerLogFile );
  69. DumpNameDataBase( InstalerLogFile );
  70. CloseIml( pImlNew );
  71. fclose( InstalerLogFile );
  72. ExitProcess( 0 );
  73. }
  74. return 0;
  75. }
  76. typedef struct _GENERIC_REFERENCE {
  77. LIST_ENTRY Entry;
  78. PWSTR Name;
  79. } GENERIC_REFERENCE, *PGENERIC_REFERENCE;
  80. int
  81. __cdecl
  82. CompareReferences(
  83. const void *Reference1,
  84. const void *Reference2
  85. )
  86. {
  87. PGENERIC_REFERENCE p1 = *(PGENERIC_REFERENCE *)Reference1;
  88. PGENERIC_REFERENCE p2 = *(PGENERIC_REFERENCE *)Reference2;
  89. return _wcsicmp( p1->Name, p2->Name );
  90. }
  91. BOOLEAN
  92. SortReferenceList(
  93. PLIST_ENTRY Head,
  94. ULONG NumberOfEntriesInList
  95. )
  96. {
  97. PGENERIC_REFERENCE p, *SortedArray;
  98. PLIST_ENTRY Next;
  99. ULONG i;
  100. if (NumberOfEntriesInList == 0) {
  101. return TRUE;
  102. }
  103. SortedArray = AllocMem( NumberOfEntriesInList * sizeof( *SortedArray ) );
  104. if (SortedArray == NULL) {
  105. return FALSE;
  106. }
  107. Next = Head->Flink;
  108. i = 0;
  109. while (Head != Next) {
  110. p = CONTAINING_RECORD( Next, GENERIC_REFERENCE, Entry );
  111. if (i >= NumberOfEntriesInList) {
  112. break;
  113. }
  114. SortedArray[ i++ ] = p;
  115. Next = Next->Flink;
  116. }
  117. qsort( (void *)SortedArray,
  118. NumberOfEntriesInList,
  119. sizeof( *SortedArray ),
  120. CompareReferences
  121. );
  122. InitializeListHead( Head );
  123. for (i=0; i<NumberOfEntriesInList; i++) {
  124. p = SortedArray[ i ];
  125. InsertTailList( Head, &p->Entry );
  126. }
  127. FreeMem( (PVOID *)&SortedArray );
  128. return TRUE;
  129. }