Leaked source code of windows server 2003
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.

279 lines
6.1 KiB

  1. #define _UNICODE
  2. #define UNICODE
  3. #include "stdafx.h"
  4. #pragma warning (disable : 4786)
  5. #pragma warning (disable : 4275)
  6. #include <iostream>
  7. #include <strstream>
  8. #include <fstream>
  9. #include <string>
  10. #include <sstream>
  11. #include <map>
  12. #include <list>
  13. using namespace std;
  14. #include <tchar.h>
  15. #include <process.h>
  16. #include <windows.h>
  17. #ifdef NONNT5
  18. typedef unsigned long ULONG_PTR;
  19. #endif
  20. #include <wmistr.h>
  21. #include <guiddef.h>
  22. #include <initguid.h>
  23. #include <evntrace.h>
  24. #include <WTYPES.H>
  25. /*
  26. #include "stdafx.h"
  27. #include <string>
  28. #include <iosfwd>
  29. #include <iostream>
  30. #include <fstream>
  31. #include <ctime>
  32. #include <list>
  33. using namespace std;
  34. #include <malloc.h>
  35. #include <windows.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <windows.h>
  39. #include <tchar.h>
  40. #include <wmistr.h>
  41. #include <objbase.h>
  42. #include <initguid.h>
  43. #include <evntrace.h>
  44. */
  45. #include "struct.h"
  46. #include "utils.h"
  47. #include "Readfile.h"
  48. #include "main.h"
  49. FILE *FileP;
  50. LPGUID ControlGuid;
  51. ULONG
  52. ReadInputFile(LPTSTR InputFile, PREGISTER_TRACE_GUID RegisterTraceGuid)
  53. {
  54. TCHAR *String;
  55. String = (TCHAR *) malloc( MAX_STR*sizeof(TCHAR) );
  56. String = (TCHAR *) malloc(100);
  57. if (InputFile == NULL )
  58. return 1;
  59. FileP = _tfopen(InputFile, _T("r"));
  60. if (FileP== NULL )
  61. return 1;
  62. //Now Read MofImagePath
  63. if( !ReadString ( (TCHAR *)RegisterTraceGuid->MofImagePath, MAX_STR) )
  64. {
  65. //Log here and then return
  66. return 1;
  67. }
  68. if ( !_tcsicmp(RegisterTraceGuid->MofImagePath, _T("NULL") ))
  69. RegisterTraceGuid->MofImagePath = (TCHAR *) 0;
  70. //Now Read MofResourceName
  71. if( !ReadString ( (TCHAR *)RegisterTraceGuid->MofResourceName, MAX_STR) )
  72. {
  73. //Log here and then return
  74. return 1;
  75. }
  76. if ( !_tcsicmp(RegisterTraceGuid->MofResourceName, _T("NULL") ))
  77. RegisterTraceGuid->MofResourceName = (TCHAR *) 0;
  78. //Now Read Call backfunction...
  79. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  80. {
  81. //This is optional input so can return success if it is not present
  82. return 0;
  83. }
  84. if ( !_tcsicmp(String, _T("NULL") ))
  85. RegisterTraceGuid->CallBackFunction = (PVOID) 0;
  86. //Now Read TraceGuidReg.
  87. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  88. {
  89. //This is optional input so can return success if it is not present
  90. return 0;
  91. }
  92. if ( !_tcsicmp(String, _T("NULL") ))
  93. RegisterTraceGuid->TraceGuidReg = (PTRACE_GUID_REGISTRATION) 0;
  94. //Now Read Registration Handle.
  95. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  96. {
  97. //This is optional input so can return success if it is not present
  98. return 0;
  99. }
  100. if ( !_tcsicmp(String, _T("NULL") ))
  101. RegisterTraceGuid->RegistrationHandle = (PTRACEHANDLE) 0;
  102. //Now Read GuidCount
  103. //GuidCome will come from main process..But to test 0, this is required.
  104. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  105. {
  106. //This is optional input so can return success if it is not present
  107. return 0;
  108. }
  109. if ( !_tcsicmp(String, _T("0000") ))
  110. RegisterTraceGuid->GuidCount = 0;
  111. //Now Read Handle for UnregisterTraceGuid
  112. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  113. {
  114. //This is optional input so can return success if it is not present
  115. return 0;
  116. }
  117. if ( !_tcsicmp(String, _T("NULL") ))
  118. RegisterTraceGuid->UnRegistrationHandle = (PTRACEHANDLE) 0;
  119. //Now Read Handle for GetTraceLoggerHandle
  120. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  121. {
  122. //This is optional input so can return success if it is not present
  123. return 0;
  124. }
  125. if ( !_tcsicmp(String, _T("NULL") ))
  126. RegisterTraceGuid->GetTraceLoggerHandle = (PTRACEHANDLE) 0;
  127. //Now Read Handle for GetTraceEnableLevel
  128. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  129. {
  130. //This is optional input so can return success if it is not present
  131. return 0;
  132. }
  133. if ( !_tcsicmp(String, _T("NULL") ))
  134. RegisterTraceGuid->GetTraceEnableLevel = (PTRACEHANDLE) 0;
  135. //Now Read Handle for GetTraceEnableFlags
  136. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  137. {
  138. //This is optional input so can return success if it is not present
  139. return 0;
  140. }
  141. if ( !_tcsicmp(String, _T("NULL") ))
  142. RegisterTraceGuid->GetTraceEnableFlag = (PTRACEHANDLE) 0;
  143. //Now Read Handle for UnregisterTraceGuid
  144. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  145. {
  146. //This is optional input so can return success if it is not present
  147. return 0;
  148. }
  149. if ( !_tcsicmp(String, _T("NULL") ))
  150. RegisterTraceGuid->TraceHandle = (PTRACEHANDLE) 0;
  151. //Now Read if Guid Ptr is TRUE
  152. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  153. {
  154. //This is optional input so can return success if it is not present
  155. return 0;
  156. }
  157. if ( !_tcsicmp(String, _T("USE_GUID_PTR") ))
  158. RegisterTraceGuid->UseGuidPtrFlag = 1;
  159. //Now Read if Mof Ptr is TRUE
  160. if( !ReadString ( (TCHAR *)String, MAX_STR) )
  161. {
  162. //This is optional input so can return success if it is not present
  163. return 0;
  164. }
  165. if ( !_tcsicmp(String, _T("USE_MOF_PTR") ))
  166. RegisterTraceGuid->UseMofPtrFlag = 1;
  167. fclose( FileP );
  168. return 0;
  169. }
  170. BOOLEAN
  171. ReadGuid( LPGUID Guid )
  172. {
  173. TCHAR Temp[100];
  174. TCHAR arg[100];
  175. ULONG i;
  176. if( _fgetts(Temp, 100, FileP) != NULL )
  177. {
  178. _tcsncpy(arg, Temp, 37);
  179. arg[8] = 0;
  180. Guid->Data1 = ahextoi(arg);
  181. _tcsncpy(arg, &Temp[9], 4);
  182. arg[4] = 0;
  183. Guid->Data2 = (USHORT) ahextoi(arg);
  184. _tcsncpy(arg, &Temp[14], 4);
  185. arg[4] = 0;
  186. Guid->Data3 = (USHORT) ahextoi(arg);
  187. for (i=0; i<2; i++)
  188. {
  189. _tcsncpy(arg, &Temp[19 + (i*2)], 2);
  190. arg[2] = 0;
  191. Guid->Data4[i] = (UCHAR) ahextoi(arg);
  192. }
  193. for (i=2; i<8; i++)
  194. {
  195. _tcsncpy(arg, &Temp[20 + (i*2)], 2);
  196. arg[2] = 0;
  197. Guid->Data4[i] = (UCHAR) ahextoi(arg);
  198. }
  199. return true;
  200. }
  201. return false;
  202. }
  203. BOOLEAN
  204. ReadUlong( ULONG *GuidCount)
  205. {
  206. TCHAR Temp[100];
  207. if( _fgetts(Temp, 100, FileP) != NULL )
  208. {
  209. RemoveComment( Temp);
  210. Temp[4] = 0;
  211. *GuidCount = ahextoi(Temp);
  212. return true;
  213. }
  214. return false;
  215. }
  216. BOOLEAN
  217. ReadString( TCHAR *String, ULONG StringLength)
  218. {
  219. if( _fgetts(String, StringLength, FileP) != NULL)
  220. {
  221. RemoveComment( String);
  222. return true;
  223. }
  224. else
  225. return false;
  226. }