Windows NT 4.0 source code leak
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.

210 lines
4.1 KiB

4 years ago
  1. #include<windows.h>
  2. #include<string.h>
  3. #include"dll_list.h"
  4. #include"fernldmp.h"
  5. #define APFDUMPDATA "ApfDumpData"
  6. #define APFCLEARDATA "ApfClearData"
  7. ////////////////////////////////////////////////////////////////////////////////
  8. DllEntry::DllEntry(char * string)
  9. // Creates a DllEntry with name of "string".
  10. // "string" may be deleted since a copy of it is made
  11. {
  12. int size;
  13. size=strlen(string)+1;
  14. name=new char[size];
  15. strcpy(name,string);
  16. fernel=FALSE;
  17. selected=TRUE;
  18. hInstance=NULL;
  19. next=NULL;
  20. }
  21. ////////////////////////////////////////////////////////////////////////////////
  22. DllEntry::~DllEntry()
  23. {
  24. if(name!=NULL)
  25. delete name;
  26. if(next!=NULL)
  27. delete next;
  28. }
  29. ////////////////////////////////////////////////////////////////////////////////
  30. BOOL DllEntry::OnSystem()
  31. // loads and frees dll in order to see if its on the system
  32. // Returns TRUE if on system else FALSE
  33. {
  34. HINSTANCE hInst;
  35. char szFileName[256];
  36. if( fernel )
  37. {
  38. if( InitFernel() )
  39. {
  40. CleanupFernel();
  41. return TRUE;
  42. }
  43. return FALSE;
  44. }
  45. strcpy( szFileName, name );
  46. szFileName[0]= 'z';
  47. hInst= LoadLibraryEx( szFileName, NULL, DONT_RESOLVE_DLL_REFERENCES );
  48. if( hInst==NULL )
  49. return FALSE; // didn't load, not on system
  50. // on system, free it and return TRUE
  51. FreeLibrary( hInst );
  52. return TRUE;
  53. }
  54. ////////////////////////////////////////////////////////////////////////////////
  55. HINSTANCE DllEntry::Load()
  56. {
  57. char szFileName[256];
  58. if( fernel )
  59. return hInstance= (HINSTANCE)InitFernel();
  60. strcpy( szFileName, name );
  61. szFileName[0]= 'z';
  62. return hInstance= LoadLibrary( szFileName );
  63. }
  64. ////////////////////////////////////////////////////////////////////////////////
  65. void DllEntry::Unload()
  66. {
  67. if( hInstance )
  68. {
  69. if( fernel )
  70. CleanupFernel();
  71. else
  72. FreeLibrary( hInstance );
  73. }
  74. }
  75. ////////////////////////////////////////////////////////////////////////////////
  76. void DllEntry::Dump(char * szDumpExt)
  77. {
  78. int i;
  79. char szDumpFile[256];
  80. void (*pfnApfDumpData)(char *);
  81. // make name of data file
  82. strcpy(szDumpFile, name );
  83. // remove current extension
  84. i= 0;
  85. while( szDumpFile[i]!='\0' && szDumpFile[i]!='.' )
  86. i++;
  87. if( szDumpFile[i]=='.' )
  88. szDumpFile[i]= '\0';
  89. // tack on new extension
  90. strcat (szDumpFile, ".");
  91. strcat (szDumpFile, szDumpExt);
  92. if( fernel )
  93. {
  94. SignalDumpFernel (szDumpFile);
  95. }
  96. else
  97. {
  98. pfnApfDumpData= (void(__stdcall*)(char*)) GetProcAddress( hInstance,APFDUMPDATA);
  99. if( pfnApfDumpData != NULL )
  100. (*pfnApfDumpData)(szDumpFile);
  101. }
  102. }
  103. ////////////////////////////////////////////////////////////////////////////////
  104. void DllEntry::Clear()
  105. {
  106. void (*pfnApfClearData)(void);
  107. if( fernel )
  108. {
  109. // The fernel32 dll for the File I/O Profiler creates private data that
  110. // can not be seen by other processes (eg. apd32dmp). Hence, the two
  111. // processes need to communicate through events (so that apf32dmp can
  112. // signal the fernel32 dll that a dump should take place)
  113. SignalClearFernel();
  114. }
  115. else
  116. {
  117. pfnApfClearData= (void(__stdcall *)(void)) GetProcAddress( hInstance, APFCLEARDATA);
  118. if (pfnApfClearData != NULL)
  119. {
  120. (*pfnApfClearData)();
  121. }
  122. }
  123. }
  124. ////////////////////////////////////////////////////////////////////////////////
  125. ////////////////////////////////////////////////////////////////////////////////
  126. ////////////////////////////////////////////////////////////////////////////////
  127. void DllList::Add(DllEntry * entry)
  128. // Adds "entry" to end of list
  129. {
  130. if(dllList==NULL)
  131. dllList=entry;
  132. else
  133. {
  134. DllEntry * cur=dllList;
  135. while(cur->next!=NULL) // find end of list
  136. cur=cur->next;
  137. cur->next=entry; // add entry to end of list
  138. }
  139. }
  140. ////////////////////////////////////////////////////////////////////////////////
  141. DllEntry* DllList::FindByName(char * name)
  142. // In: string
  143. // Out: DllEntry with name of the string
  144. // NULL if no match
  145. {
  146. DllEntry * entry;
  147. entry=dllList;
  148. while(entry!=NULL)
  149. {
  150. if( !strcmp( name, entry->name ) )
  151. return entry;
  152. entry= entry->next;
  153. }
  154. return NULL;
  155. }