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.

246 lines
5.4 KiB

  1. #include "globals.h"
  2. kWin9xDevWalk::kWin9xDevWalk(kLogFile *Proc)
  3. {
  4. LogProc=Proc;
  5. }
  6. kWin9xDevWalk::~kWin9xDevWalk()
  7. {
  8. }
  9. int kWin9xDevWalk::Go()
  10. {
  11. if(!LoadResourceFile ("c:\\syspar16.exe", "EXEResource1" ))
  12. return FALSE;
  13. _spawnl (_P_WAIT, "c:\\syspar16.exe", "c:\\syspar16.exe", "_spawnl", "two", NULL);
  14. AppendToLogFile("c:\\sp16temp.tmz");
  15. DeleteFile ("c:\\sp16temp.tmz");
  16. DeleteFile ("c:\\syspar16.exe");
  17. return TRUE;
  18. }
  19. BOOL kWin9xDevWalk::LoadResourceFile(PSTR FilePath,PSTR ResName)
  20. {
  21. HGLOBAL hObj;
  22. HRSRC hResource;
  23. LPSTR lpStr;
  24. DWORD dwSize = 0;
  25. DWORD dwBytesWritten = 0;
  26. char ErrorString[MAX_PATH * 4];
  27. if ( !(hResource = FindResource(NULL, ResName, RT_RCDATA)) )
  28. return FALSE;
  29. if ( !(hObj = LoadResource(NULL,hResource)) )
  30. return FALSE;
  31. if ( !(lpStr = (LPSTR)LockResource(hObj)) )
  32. return FALSE;
  33. if ( !(dwSize = SizeofResource( NULL, hResource)))
  34. {
  35. UnlockResource(hObj);
  36. return FALSE;
  37. }
  38. HANDLE hfFile = CreateFile(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  39. if (hfFile == INVALID_HANDLE_VALUE)
  40. {
  41. UnlockResource(hObj);
  42. return FALSE;
  43. }
  44. if (!WriteFile(hfFile, lpStr, dwSize, &dwBytesWritten, NULL))
  45. {
  46. UnlockResource(hObj);
  47. CloseHandle(hfFile);
  48. return FALSE;
  49. }
  50. UnlockResource(hObj);
  51. CloseHandle(hfFile);
  52. return TRUE;
  53. }
  54. kNT5DevWalk::kNT5DevWalk(kLogFile *Proc)
  55. {
  56. LogProc=Proc;
  57. }
  58. kNT5DevWalk::~kNT5DevWalk()
  59. {
  60. }
  61. int kNT5DevWalk::Go()
  62. {
  63. if(!LoadResourceFile("c:\\syspar32.exe", "EXEResource2" ))
  64. return FALSE;
  65. _spawnl(_P_WAIT, "c:\\syspar32.exe", "c:\\syspar32.exe", "_spawnl", "two", NULL);
  66. AppendToLogFile("c:\\sp32temp.tmz");
  67. DeleteFile("c:\\sp32temp.tmz");
  68. DeleteFile("c:\\syspar32.exe");
  69. return TRUE;
  70. }
  71. BOOL kNT5DevWalk::LoadResourceFile(PSTR FilePath,PSTR ResName)
  72. {
  73. HGLOBAL hObj;
  74. HRSRC hResource;
  75. LPSTR lpStr;
  76. DWORD dwSize = 0;
  77. DWORD dwBytesWritten = 0;
  78. char ErrorString[MAX_PATH * 4];
  79. if ( !(hResource = FindResource(NULL, ResName, RT_RCDATA)) )
  80. return FALSE;
  81. if ( !(hObj = LoadResource(NULL,hResource)) )
  82. return FALSE;
  83. if ( !(lpStr = (LPSTR)LockResource(hObj)) )
  84. return FALSE;
  85. if ( !(dwSize = SizeofResource( NULL, hResource)))
  86. {
  87. UnlockResource(hObj);
  88. return FALSE;
  89. }
  90. HANDLE hfFile = CreateFile(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  91. if (hfFile == INVALID_HANDLE_VALUE)
  92. {
  93. UnlockResource(hObj);
  94. return FALSE;
  95. }
  96. if (!WriteFile(hfFile, lpStr, dwSize, &dwBytesWritten, NULL))
  97. {
  98. UnlockResource(hObj);
  99. CloseHandle(hfFile);
  100. return FALSE;
  101. }
  102. UnlockResource(hObj);
  103. CloseHandle(hfFile);
  104. return TRUE;
  105. }
  106. void kNT5DevWalk::AppendToLogFile(PTCHAR szFile)
  107. {
  108. FILE *fFile = NULL;
  109. FILE *fOutFile = NULL;
  110. PTCHAR szString = NULL;
  111. if( !(fFile = fopen(szFile, "r")))
  112. return;
  113. if( !(fOutFile = fopen(LogProc->szFile, "a+")))
  114. {
  115. fclose(fFile);
  116. return;
  117. }
  118. if( !(szString = (PTCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 11000)))
  119. {
  120. fclose(fFile);
  121. fclose(fOutFile);
  122. return;
  123. }
  124. int iHold;
  125. iHold = fgetc(fFile);
  126. while (EOF != iHold)
  127. {
  128. fputc(iHold, fOutFile);
  129. iHold = fgetc(fFile);
  130. }
  131. fclose(fFile);
  132. fclose(fOutFile);
  133. HeapFree(GetProcessHeap(), 0, szString);
  134. }
  135. void kWin9xDevWalk::AppendToLogFile(PTCHAR szFile)
  136. {
  137. FILE *fFile = NULL;
  138. FILE *fOutFile = NULL;
  139. PTCHAR szString = NULL;
  140. if( !(fFile = fopen(szFile, "r")))
  141. return;
  142. if( !(fOutFile = fopen(LogProc->szFile, "a+")))
  143. {
  144. fclose(fFile);
  145. return;
  146. }
  147. if( !(szString = (PTCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 11000)))
  148. {
  149. fclose(fFile);
  150. fclose(fOutFile);
  151. return;
  152. }
  153. int iHold;
  154. iHold = fgetc(fFile);
  155. while (EOF != iHold)
  156. {
  157. fputc(iHold, fOutFile);
  158. iHold = fgetc(fFile);
  159. }
  160. fclose(fFile);
  161. fclose(fOutFile);
  162. HeapFree(GetProcessHeap(), 0, szString);
  163. }
  164. //DWORD WalkLogConfForResources(
  165. /*
  166. DWORD EnumerateClasses(ULONG ulIndex)
  167. {
  168. GUID *pClassID=(GUID*)malloc(sizeof(GUID));
  169. char szBuf[500];
  170. ULONG ulSize=499;
  171. DWORD dwRet=0;
  172. dwRet=CM_Enumerate_Classes(ulIndex, pClassID, 0);
  173. CM_Get_Class_Name(pClassID, szBuf, &ulSize, 0);
  174. //printf("CLASS = %s\r\n", szBuf);
  175. GetClassDevs(szBuf);
  176. return dwRet;
  177. }
  178. DWORD GetClassDevs(CHAR *szClassName)
  179. {
  180. HDEVINFO hDevInfo;
  181. LPGUID pguid;
  182. DWORD dwSize=0;
  183. SetupDiClassGuidsFromName(szClassName, pguid, 100, &dwSize);
  184. //SetupDiBuildClassInfoList(NULL, pguid, 1, &dwSize);
  185. //hDevInfo = SetupDiGetClassDevs(szClassName, NULL, NULL, DIGCF_ALLCLASSES);
  186. printf("Need %d more GUIDs for class %s \r\n", dwSize, szClassName);
  187. hDevInfo = SetupDiGetClassDevs(pguid, NULL, NULL, NULL);
  188. printf("hDevInfo=%d\r\n",hDevInfo);
  189. printf("GUid? %c%c%c%c%c%c%c\r\n", pguid->Data4[0],
  190. pguid->Data4[1],
  191. pguid->Data4[2],
  192. pguid->Data4[3],
  193. pguid->Data4[4],
  194. pguid->Data4[5],
  195. pguid->Data4[6],
  196. pguid->Data4[7]);
  197. return TRUE;
  198. }
  199. */