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.

834 lines
27 KiB

  1. //When invoked from WDM makefile the debug condition is different
  2. #ifdef COMPILE_FOR_WDM_KERNEL_MODE
  3. #if (DBG==1)
  4. #undef _NDEBUG
  5. #else
  6. #define _NDEBUG
  7. #endif
  8. #endif
  9. //
  10. // This entire module is debug only
  11. //
  12. #ifndef _NDEBUG
  13. #define __DEBUG_MODULE_IN_USE__ CIC_DUMPCOMMANDBLOCK_CPP
  14. #include "stdhdrs.h"
  15. #include <stdio.h>
  16. #include "Actions.h"
  17. #include "DumpCommandBlock.h"
  18. //----------------------------------------------------
  19. // Global variables
  20. //----------------------------------------------------
  21. PFNSTRING_DUMP_FUNC CDumpItem::ms_pfnDumpFunc = NULL;
  22. static PFNSTRING_DUMP_FUNC g_pfnDumpFunc = NULL;
  23. CControlItemCollection<CDumpItem> *g_pDumpCollection = NULL;
  24. static char GlobalTempBuffer[1024];
  25. const ULONG XDF_Trigger = 1;
  26. const ULONG XDF_Event = 2;
  27. //-----------------------------------------------------------------------------------------
  28. // Interface Functions - Implementation
  29. //-----------------------------------------------------------------------------------------
  30. BOOLEAN DumpCommandBlock(PUCHAR pucBlock, ULONG ulSize)
  31. {
  32. BOOLEAN fRetVal = DumpRecurse(pucBlock, ulSize, 0);
  33. DumpString("///////////////End of Dump//////////////////\n");
  34. return fRetVal;
  35. }
  36. void SetDumpFunc(PFNSTRING_DUMP_FUNC pfnDumpFunc)
  37. {
  38. g_pfnDumpFunc = pfnDumpFunc;
  39. CDumpItem::SetDumpFunc(pfnDumpFunc);
  40. }
  41. void InitDumpModule(ULONG ulVidPid)
  42. {
  43. //Initializing to new VidPid - destroy the existing one
  44. if(g_pDumpCollection)
  45. {
  46. delete g_pDumpCollection;
  47. }
  48. g_pDumpCollection = new WDM_NON_PAGED_POOL CControlItemCollection<CDumpItem>(ulVidPid, &DumpItemFactory);
  49. if(!g_pDumpCollection)
  50. {
  51. DumpString("ERROR: Couldn't create Dump Collection, won't be able to give detailed Xfer info.\n");
  52. }
  53. }
  54. //-----------------------------------------------------------------------------------------
  55. // Internal functions - Implementation
  56. //-----------------------------------------------------------------------------------------
  57. void DumpString(LPSTR lpszDumpString)
  58. {
  59. if(g_pfnDumpFunc)
  60. {
  61. g_pfnDumpFunc(lpszDumpString);
  62. }
  63. else
  64. {
  65. DCB_TRACE(lpszDumpString);
  66. }
  67. }
  68. BOOLEAN DumpDirectory(PUCHAR pucBlock, ULONG ulSize)
  69. {
  70. PCOMMAND_DIRECTORY pCommandDirectory = reinterpret_cast<PCOMMAND_DIRECTORY>(pucBlock);
  71. // Check the type
  72. if( eDirectory != pCommandDirectory->CommandHeader.eID )
  73. {
  74. sprintf(GlobalTempBuffer, "ERROR: Expecting eDirectory\n");
  75. DumpString(GlobalTempBuffer);
  76. return FALSE;
  77. }
  78. // Check the size
  79. if ( ulSize < pCommandDirectory->ulEntireSize )
  80. {
  81. sprintf(GlobalTempBuffer, "ERROR: Buffer Size Allocation, %d bytes expected, %d allocated.\n", pCommandDirectory->ulEntireSize, ulSize);
  82. DumpString(GlobalTempBuffer);
  83. return FALSE ;
  84. }
  85. // Dump the Directory information
  86. sprintf(GlobalTempBuffer, "///////eDirectory/////////////////////////////////////////\n");
  87. DumpString(GlobalTempBuffer);
  88. sprintf(GlobalTempBuffer, "Command Header: \n");
  89. DumpString(GlobalTempBuffer);
  90. sprintf(GlobalTempBuffer, " eID: %x\n",pCommandDirectory->CommandHeader.eID);
  91. DumpString(GlobalTempBuffer);
  92. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pCommandDirectory->CommandHeader.ulByteSize);
  93. DumpString(GlobalTempBuffer);
  94. sprintf(GlobalTempBuffer, "ulEntireSize: %d\n",pCommandDirectory->ulEntireSize);
  95. DumpString(GlobalTempBuffer);
  96. sprintf(GlobalTempBuffer, "NumEntries: %d\n",pCommandDirectory->usNumEntries);
  97. DumpString(GlobalTempBuffer);
  98. return TRUE;
  99. }
  100. // Just What kind of command is this
  101. BOOLEAN DumpAssignmentTarget(PUCHAR pucBlock, ULONG ulSize)
  102. {
  103. PASSIGNMENT_TARGET pAssignmentTarget = reinterpret_cast<PASSIGNMENT_TARGET> (pucBlock);
  104. // Check the size
  105. if ( ulSize < pAssignmentTarget->CommandHeader.ulByteSize )
  106. {
  107. sprintf(GlobalTempBuffer, "ERROR: Buffer Size Allocation\n");
  108. DumpString(GlobalTempBuffer);
  109. return FALSE ;
  110. }
  111. switch( pAssignmentTarget->CommandHeader.eID )
  112. {
  113. case eBehaviorAction:
  114. sprintf(GlobalTempBuffer, "////////////////////////eBehaviorAction////////\n");
  115. break;
  116. case eRecordableAction:
  117. sprintf(GlobalTempBuffer, "////////////////////////eRecordableAction////////\n");
  118. break;
  119. default:
  120. return FALSE;
  121. }
  122. DumpString(GlobalTempBuffer);
  123. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pAssignmentTarget->CommandHeader.ulByteSize);
  124. DumpString(GlobalTempBuffer);
  125. return DumpTriggerXfer(&pAssignmentTarget->cixAssignment);
  126. }
  127. BOOLEAN DumpTimedMacro(PUCHAR pucBlock, ULONG ulSize)
  128. {
  129. PTIMED_MACRO pTimedMacro = reinterpret_cast<PTIMED_MACRO>(pucBlock);
  130. PASSIGNMENT_BLOCK pAssBlock = &pTimedMacro->AssignmentBlock ;
  131. ULONG ulCurrentEvent = 0;
  132. PTIMED_EVENT pCurrentEvent = NULL;
  133. sprintf(GlobalTempBuffer, "/////////////////////////////////Timed Macro////\n");
  134. DumpString(GlobalTempBuffer);
  135. sprintf(GlobalTempBuffer, "Assignment Block: \n");
  136. DumpString(GlobalTempBuffer);
  137. sprintf(GlobalTempBuffer, " Command Header: \n");
  138. DumpString(GlobalTempBuffer);
  139. sprintf(GlobalTempBuffer, " eID: %x\n",pAssBlock->CommandHeader.eID);
  140. DumpString(GlobalTempBuffer);
  141. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pAssBlock->CommandHeader.ulByteSize);
  142. DumpString(GlobalTempBuffer);
  143. sprintf(GlobalTempBuffer, " VidPid: %x\n",pAssBlock->ulVidPid);
  144. DumpString(GlobalTempBuffer);
  145. sprintf(GlobalTempBuffer, "ulFlags: %x\n",pTimedMacro->ulFlags);
  146. DumpString(GlobalTempBuffer);
  147. sprintf(GlobalTempBuffer, "ulEventCount: %x\n",pTimedMacro->ulEventCount);
  148. DumpString(GlobalTempBuffer);
  149. if ( ulSize < pAssBlock->CommandHeader.ulByteSize )
  150. {
  151. sprintf(GlobalTempBuffer, "ERROR: Buffer Size Allocation\n");
  152. DumpString(GlobalTempBuffer);
  153. return FALSE ;
  154. }
  155. while ( pCurrentEvent = pTimedMacro->GetNextEvent(pCurrentEvent, ulCurrentEvent))
  156. {
  157. if (!DumpTimedEvent( pCurrentEvent))
  158. return FALSE;
  159. }
  160. return TRUE;
  161. }
  162. BOOLEAN DumpKeyString(PUCHAR pucBlock, ULONG ulSize)
  163. {
  164. PKEYSTRING_MAP pKeyStringMap = reinterpret_cast<PKEYSTRING_MAP> (pucBlock) ;
  165. PASSIGNMENT_BLOCK pAssBlock = &pKeyStringMap->AssignmentBlock ;
  166. ULONG ulEvent = 0;
  167. PEVENT pEvent = NULL;
  168. sprintf(GlobalTempBuffer, "/////////////////////////////////Key String/////////\n");
  169. DumpString(GlobalTempBuffer);
  170. sprintf(GlobalTempBuffer, "Assignment Block: \n");
  171. DumpString(GlobalTempBuffer);
  172. sprintf(GlobalTempBuffer, " Command Header: \n");
  173. DumpString(GlobalTempBuffer);
  174. sprintf(GlobalTempBuffer, " eID: %x\n",pAssBlock->CommandHeader.eID);
  175. DumpString(GlobalTempBuffer);
  176. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pAssBlock->CommandHeader.ulByteSize);
  177. DumpString(GlobalTempBuffer);
  178. sprintf(GlobalTempBuffer, " VidPid: %x\n",pAssBlock->ulVidPid);
  179. DumpString(GlobalTempBuffer);
  180. sprintf(GlobalTempBuffer, "ulFlags: %x\n",pKeyStringMap->ulFlags);
  181. DumpString(GlobalTempBuffer);
  182. sprintf(GlobalTempBuffer, "ulEventCount: %x\n",pKeyStringMap->ulEventCount);
  183. DumpString(GlobalTempBuffer);
  184. if ( ulSize < pKeyStringMap->AssignmentBlock.CommandHeader.ulByteSize )
  185. {
  186. sprintf(GlobalTempBuffer, "ERROR: Buffer Size Allocation\n");
  187. DumpString(GlobalTempBuffer);
  188. return FALSE ;
  189. }
  190. while ( pEvent = pKeyStringMap->GetNextEvent(pEvent, ulEvent))
  191. {
  192. if (!DumpEvent( pEvent))
  193. return FALSE;
  194. }
  195. return TRUE;
  196. }
  197. BOOLEAN DumpMouseFxAxisMap(PUCHAR pucBlock, ULONG ulSize)
  198. {
  199. PMOUSE_FX_AXIS_MAP pMouseFxAxisMap = (PMOUSE_FX_AXIS_MAP)pucBlock;
  200. ASSERT(ulSize == sizeof(MOUSE_FX_AXIS_MAP));
  201. sprintf(GlobalTempBuffer, "/////////////////////////////////MouseFxAxisMap////\n");
  202. DumpString(GlobalTempBuffer);
  203. sprintf(GlobalTempBuffer, "Assignment Block: \n");
  204. DumpString(GlobalTempBuffer);
  205. sprintf(GlobalTempBuffer, " Command Header: \n");
  206. DumpString(GlobalTempBuffer);
  207. sprintf(GlobalTempBuffer, " eID: %x\n",pMouseFxAxisMap->AssignmentBlock.CommandHeader.eID);
  208. DumpString(GlobalTempBuffer);
  209. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pMouseFxAxisMap->AssignmentBlock.CommandHeader.ulByteSize);
  210. DumpString(GlobalTempBuffer);
  211. sprintf(GlobalTempBuffer, " VidPid: %x\n",pMouseFxAxisMap->AssignmentBlock.ulVidPid);
  212. DumpString(GlobalTempBuffer);
  213. if(pMouseFxAxisMap->fIsX)
  214. {
  215. DumpString("X Axis\n");
  216. }
  217. else
  218. {
  219. DumpString("Y Axis\n");
  220. }
  221. sprintf(GlobalTempBuffer, "Model Parameters:\n");
  222. DumpString(GlobalTempBuffer);
  223. sprintf(GlobalTempBuffer, "ulAbsZoneSense = %d\n", pMouseFxAxisMap->AxisModelParameters.ulAbsZoneSense);
  224. DumpString(GlobalTempBuffer);
  225. sprintf(GlobalTempBuffer, "ulContZoneMaxRate = %d\n", pMouseFxAxisMap->AxisModelParameters.ulContZoneMaxRate);
  226. DumpString(GlobalTempBuffer);
  227. sprintf(GlobalTempBuffer, "ulPulseWidth = %d\n", pMouseFxAxisMap->AxisModelParameters.ulPulseWidth);
  228. DumpString(GlobalTempBuffer);
  229. sprintf(GlobalTempBuffer, "ulPulsePeriod = %d\n", pMouseFxAxisMap->AxisModelParameters.ulPulsePeriod);
  230. DumpString(GlobalTempBuffer);
  231. sprintf(GlobalTempBuffer, "ulInertiaTime = %d\n", pMouseFxAxisMap->AxisModelParameters.ulInertiaTime);
  232. DumpString(GlobalTempBuffer);
  233. sprintf(GlobalTempBuffer, "ulAcceleration = %d\n", pMouseFxAxisMap->AxisModelParameters.ulAcceleration);
  234. DumpString(GlobalTempBuffer);
  235. sprintf(GlobalTempBuffer, "fAccelerate = %s\n", ((pMouseFxAxisMap->AxisModelParameters.fPulse) ? "T" : "F"));
  236. DumpString(GlobalTempBuffer);
  237. sprintf(GlobalTempBuffer, "fPulse = %s\n", ((pMouseFxAxisMap->AxisModelParameters.fPulse) ? "T" : "F"));
  238. DumpString(GlobalTempBuffer);
  239. return TRUE;
  240. }
  241. /*
  242. typedef struct tagAXIS_MAP
  243. {
  244. ASSIGNMENT_BLOCK AssignmentBlock; //eAxisMap is the type
  245. LONG lCoefficient1024x; //A mapping coeffiecient times 1024 (should be between -1024 and 1024)
  246. CONTROL_ITEM_XFER cixDestinationAxis; //Axis to map to.
  247. } AXIS_MAP, *PAXIS_MAP;
  248. */
  249. BOOLEAN DumpAxisMap(PUCHAR pucBlock, ULONG ulSize)
  250. {
  251. PAXIS_MAP pAxisMap = (PAXIS_MAP)pucBlock;
  252. ASSERT(ulSize == sizeof(AXIS_MAP));
  253. sprintf(GlobalTempBuffer, "/////////////////////////////////AxisMap////\n");
  254. DumpString(GlobalTempBuffer);
  255. sprintf(GlobalTempBuffer, "Assignment Block: \n");
  256. DumpString(GlobalTempBuffer);
  257. sprintf(GlobalTempBuffer, " Command Header: \n");
  258. DumpString(GlobalTempBuffer);
  259. sprintf(GlobalTempBuffer, " eID: %x\n",pAxisMap->AssignmentBlock.CommandHeader.eID);
  260. DumpString(GlobalTempBuffer);
  261. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pAxisMap->AssignmentBlock.CommandHeader.ulByteSize);
  262. DumpString(GlobalTempBuffer);
  263. sprintf(GlobalTempBuffer, " VidPid: %x\n",pAxisMap->AssignmentBlock.ulVidPid);
  264. DumpString(GlobalTempBuffer);
  265. /*
  266. if(pMouseFxAxisMap->fIsX)
  267. {
  268. DumpString("X Axis\n");
  269. }
  270. else
  271. {
  272. DumpString("Y Axis\n");
  273. }
  274. */
  275. sprintf(GlobalTempBuffer, "Model Parameters:\n");
  276. DumpString(GlobalTempBuffer);
  277. sprintf(GlobalTempBuffer, "lCoefficient1024x = %d\n", pAxisMap->lCoefficient1024x);
  278. DumpString(GlobalTempBuffer);
  279. if(!DumpEventXfer(&pAxisMap->cixDestinationAxis))
  280. return FALSE;
  281. return TRUE;
  282. }
  283. BOOLEAN DumpForceMap(PUCHAR pucBlock, ULONG ulSize)
  284. {
  285. FORCE_BLOCK* pForceMap = (FORCE_BLOCK*)pucBlock;
  286. ASSERT(ulSize == sizeof(FORCE_BLOCK));
  287. sprintf(GlobalTempBuffer, "/////////////////////////////////ForceMap////\n");
  288. DumpString(GlobalTempBuffer);
  289. sprintf(GlobalTempBuffer, "Assignment Block: \n");
  290. DumpString(GlobalTempBuffer);
  291. sprintf(GlobalTempBuffer, " Command Header: \n");
  292. DumpString(GlobalTempBuffer);
  293. sprintf(GlobalTempBuffer, " eID: %x\n",pForceMap->AssignmentBlock.CommandHeader.eID);
  294. DumpString(GlobalTempBuffer);
  295. sprintf(GlobalTempBuffer, " ulByteSize: %d\n",pForceMap->AssignmentBlock.CommandHeader.ulByteSize);
  296. DumpString(GlobalTempBuffer);
  297. sprintf(GlobalTempBuffer, " VidPid: %x\n", pForceMap->AssignmentBlock.ulVidPid);
  298. DumpString(GlobalTempBuffer);
  299. sprintf(GlobalTempBuffer, "Force Map Parameters:\n");
  300. DumpString(GlobalTempBuffer);
  301. sprintf(GlobalTempBuffer, "bMapYToX = %d\n", pForceMap->bMapYToX);
  302. DumpString(GlobalTempBuffer);
  303. sprintf(GlobalTempBuffer, "usRTC = %d\n", pForceMap->usRTC);
  304. DumpString(GlobalTempBuffer);
  305. sprintf(GlobalTempBuffer, "usGain = %d\n", pForceMap->usGain);
  306. DumpString(GlobalTempBuffer);
  307. return TRUE;
  308. }
  309. BOOLEAN DumpUnknown(PUCHAR pucBufferLocation, ULONG ulSize)
  310. {
  311. COMMAND_HEADER* pHeader = (COMMAND_HEADER*)pucBufferLocation;
  312. sprintf(GlobalTempBuffer, "/////////////////////////////////Unknown Item////\n");
  313. DumpString(GlobalTempBuffer);
  314. sprintf(GlobalTempBuffer, "eID : 0x%X\n", pHeader->eID);
  315. DumpString(GlobalTempBuffer);
  316. sprintf(GlobalTempBuffer, " ulByteSize: %d\n", pHeader->ulByteSize);
  317. DumpString(GlobalTempBuffer);
  318. return TRUE;
  319. }
  320. BOOLEAN DumpTimedEvent(PTIMED_EVENT pTimedEvent)
  321. {
  322. PEVENT pEvent = &pTimedEvent->Event;
  323. sprintf(GlobalTempBuffer,"ulDuration: %d\n",pTimedEvent->ulDuration);
  324. DumpString(GlobalTempBuffer);
  325. return DumpEvent(pEvent);
  326. }
  327. BOOLEAN DumpEvent(PEVENT pEvent)
  328. {
  329. sprintf(GlobalTempBuffer,"ulNumXfers: %d\n",pEvent->ulNumXfers);
  330. DumpString(GlobalTempBuffer);
  331. sprintf(GlobalTempBuffer,"Required bytes: %d\n",pEvent->RequiredByteSize( pEvent->ulNumXfers));
  332. DumpString(GlobalTempBuffer);
  333. ULONG ulXferIndex;
  334. for(ulXferIndex=0; ulXferIndex < pEvent->ulNumXfers; ulXferIndex++)
  335. {
  336. sprintf(GlobalTempBuffer, "Dumping Xfer #%d\n", ulXferIndex);
  337. DumpString(GlobalTempBuffer);
  338. if(!DumpEventXfer(&pEvent->rgXfers[ulXferIndex]))
  339. return FALSE;
  340. }
  341. return TRUE;
  342. }
  343. #define SKIP_TO_NEXT_COMMAND_BLOCK(pCommandHeader)\
  344. (reinterpret_cast<PCOMMAND_HEADER>\
  345. ( reinterpret_cast<PUCHAR>(pCommandHeader) +\
  346. reinterpret_cast<PCOMMAND_HEADER>(pCommandHeader)->ulByteSize )\
  347. )
  348. #define SKIP_TO_NEXT_COMMAND_DIRECTORY(pCommandDirectory)\
  349. (reinterpret_cast<PCOMMAND_DIRECTORY>\
  350. (reinterpret_cast<PUCHAR>(pCommandDirectory) +\
  351. pCommandDirectory->ulEntireSize)\
  352. )
  353. #define COMMAND_BLOCK_FITS_IN_DIRECTORY(pCommandDirectory, pCommandHeader)\
  354. (pCommandDirectory->ulEntireSize >=\
  355. (\
  356. (reinterpret_cast<PUCHAR>(pCommandDirectory) - reinterpret_cast<PUCHAR>(pCommandHeader)) +\
  357. reinterpret_cast<PCOMMAND_HEADER>(pCommandHeader)->ulByteSize\
  358. )\
  359. )
  360. #define COMMAND_DIRECTORY_FITS_IN_DIRECTORY(pCommandDirectory, pCommandSubDirectory)\
  361. (pCommandDirectory->ulEntireSize >=\
  362. (\
  363. (reinterpret_cast<PUCHAR>(pCommandDirectory) - reinterpret_cast<PUCHAR>(pCommandHeader)) +\
  364. pCommandSubDirectory->ulEntireSize\
  365. )\
  366. )
  367. BOOLEAN DumpRecurse(PUCHAR pucBlock, ULONG ulSize, ULONG ulDepth)
  368. {
  369. PCOMMAND_DIRECTORY pCommandDirectory = reinterpret_cast<PCOMMAND_DIRECTORY>(pucBlock);
  370. PCOMMAND_HEADER pCommandHeader;
  371. PUCHAR pucBufferLocation = pucBlock;
  372. // Sanity Check
  373. if( eDirectory != pCommandDirectory->CommandHeader.eID )
  374. {
  375. sprintf(GlobalTempBuffer, "ERROR: Expecting eDirectory, recursion depth = %ld\n", ulDepth);
  376. DumpString(GlobalTempBuffer);
  377. return FALSE;
  378. }
  379. //Print out starting address of Directory
  380. sprintf(GlobalTempBuffer, "Next Directory starts at 0x%0.8x\n", pucBlock);
  381. DumpString(GlobalTempBuffer);
  382. // Dump COMMAND_DIRECTORY info - this will inherently check the size
  383. if( !DumpDirectory(pucBlock, ulSize) )
  384. return FALSE;
  385. // If there are no entries are done
  386. if( 0 == pCommandDirectory->usNumEntries)
  387. {
  388. sprintf(GlobalTempBuffer, "WARNING: Lowest level sub-directory with no blocks\n");
  389. DumpString(GlobalTempBuffer);
  390. return TRUE;
  391. }
  392. // Skip Directory header to get to first block
  393. pCommandHeader = SKIP_TO_NEXT_COMMAND_BLOCK(pCommandDirectory);
  394. //Forget the allocate size (which we now by now is at least
  395. //as big as the entire size of the directory) and start using the directory size
  396. ulSize = pCommandDirectory->ulEntireSize;
  397. // Reduce the size by the size of the header
  398. ulSize -= (PUCHAR)pCommandHeader - pucBufferLocation;
  399. pucBufferLocation = (PUCHAR)pCommandHeader;
  400. //Ensure that there is at least enough room for COMMAND_HEADER
  401. if( sizeof(COMMAND_HEADER) > ulSize)
  402. {
  403. DumpString("ERROR: Unexpected end of buffer\n");
  404. return FALSE;
  405. }
  406. // If we have a sub-directory, call ourselves recursively, for each sub-directory
  407. if( eDirectory == pCommandHeader->eID)
  408. {
  409. PCOMMAND_DIRECTORY pCurDirectory = reinterpret_cast<PCOMMAND_DIRECTORY>(pCommandHeader);
  410. USHORT usDirectoryNum = 1;
  411. while( usDirectoryNum <= pCommandDirectory->usNumEntries)
  412. {
  413. //Call ourselves recursively
  414. if( !DumpRecurse(pucBufferLocation, ulSize, ulDepth+1) )
  415. return FALSE;
  416. //Skip to next directory
  417. pCurDirectory = SKIP_TO_NEXT_COMMAND_DIRECTORY(pCurDirectory);
  418. // Reduce the size by the size of the directory just parsed
  419. ulSize -= (PUCHAR)pCurDirectory - pucBufferLocation;
  420. pucBufferLocation = (PUCHAR)pCurDirectory;
  421. usDirectoryNum++;
  422. }
  423. //Nobody failed so return TRUE
  424. return TRUE;
  425. }
  426. //
  427. // If we are here, we have reached the bottom of a directory,
  428. // to a command we need to dump
  429. //
  430. USHORT usEntryNum = 1;
  431. while( usEntryNum <= pCommandDirectory->usNumEntries)
  432. {
  433. //Ensure that there is at least enough room for COMMAND_HEADER
  434. if( sizeof(COMMAND_HEADER) > ulSize)
  435. {
  436. DumpString("ERROR: Unexpected end of buffer\n");
  437. return FALSE;
  438. }
  439. sprintf(GlobalTempBuffer, "Next Block starts at 0x%0.8x\n", pucBufferLocation);
  440. DumpString(GlobalTempBuffer);
  441. //Dump info about block
  442. switch( pCommandHeader->eID )
  443. {
  444. case eBehaviorAction:
  445. case eRecordableAction:
  446. if( !DumpAssignmentTarget(pucBufferLocation, ulSize) )
  447. return FALSE;
  448. break;
  449. case eTimedMacro:
  450. if( !DumpTimedMacro(pucBufferLocation, ulSize) )
  451. return FALSE;
  452. break;
  453. case eKeyString:
  454. if( !DumpKeyString(pucBufferLocation, ulSize) )
  455. return FALSE;
  456. break;
  457. case eMouseFXAxisMap:
  458. if( !DumpMouseFxAxisMap(pucBufferLocation, ulSize) )
  459. return FALSE;
  460. break;
  461. case eAxisMap:
  462. if( !DumpAxisMap(pucBufferLocation, ulSize) )
  463. return FALSE;
  464. break;
  465. #if 1
  466. case eForceMap:
  467. if( !DumpForceMap(pucBufferLocation, ulSize) )
  468. return FALSE;
  469. break;
  470. #endif
  471. default:
  472. if ( !DumpUnknown(pucBufferLocation, ulSize) )
  473. return FALSE;
  474. break;
  475. }
  476. // skip to next block
  477. pCommandHeader = SKIP_TO_NEXT_COMMAND_BLOCK(pCommandHeader);
  478. ulSize -= (PUCHAR)pCommandHeader - pucBufferLocation;
  479. pucBufferLocation = (PUCHAR)pCommandHeader;
  480. usEntryNum++;
  481. }
  482. //we've reached the end of this directory
  483. return TRUE;
  484. }
  485. BOOLEAN DumpTriggerXfer(PCONTROL_ITEM_XFER pControlItemXfer)
  486. {
  487. //Is Xfer for a keyboard
  488. if( NonGameDeviceXfer::IsKeyboardXfer(*pControlItemXfer) )
  489. {
  490. sprintf(GlobalTempBuffer, "ERROR: Invalid Trigger. Keyboard data encountered.\n");
  491. DumpString(GlobalTempBuffer);
  492. return FALSE;
  493. }
  494. if(g_pDumpCollection)
  495. {
  496. CDumpItem *pDumpItem;
  497. pDumpItem = g_pDumpCollection->GetFromControlItemXfer(*pControlItemXfer);
  498. if( !pDumpItem )
  499. {
  500. sprintf(GlobalTempBuffer, "ERROR: Xfer packet not supported for device.\n");
  501. DumpString(GlobalTempBuffer);
  502. return FALSE;
  503. }
  504. pDumpItem->SetItemState(*pControlItemXfer);
  505. pDumpItem->DumpItemInfo(XDF_Trigger);
  506. }
  507. else
  508. {
  509. sprintf(GlobalTempBuffer, "WARNING: Dump Module not initialized for device, detailed Xfer info not available.\n");
  510. DumpString(GlobalTempBuffer);
  511. }
  512. return TRUE;
  513. }
  514. BOOLEAN DumpEventXfer(PCONTROL_ITEM_XFER pControlItemXfer)
  515. {
  516. //Is Xfer for a keyboard
  517. if( NonGameDeviceXfer::IsKeyboardXfer(*pControlItemXfer) )
  518. {
  519. DumpKeyboardData(pControlItemXfer);
  520. return TRUE;
  521. }
  522. if(g_pDumpCollection)
  523. {
  524. CDumpItem *pDumpItem;
  525. pDumpItem = g_pDumpCollection->GetFromControlItemXfer(*pControlItemXfer);
  526. if( !pDumpItem )
  527. {
  528. sprintf(GlobalTempBuffer, "ERROR: Xfer packet not supported for device.\n");
  529. DumpString(GlobalTempBuffer);
  530. return FALSE;
  531. }
  532. pDumpItem->SetItemState(*pControlItemXfer);
  533. pDumpItem->DumpItemInfo(XDF_Event);
  534. }
  535. else
  536. {
  537. sprintf(GlobalTempBuffer, "WARNING: Dump Module not initialized for device, detailed Xfer info not available.\n");
  538. DumpString(GlobalTempBuffer);
  539. }
  540. return TRUE;
  541. }
  542. void CDumpItem::DumpItemInfo(ULONG ulDumpFlags)
  543. {
  544. DumpString("ERROR: Should never be called!\n");
  545. }
  546. void CAxesDump::DumpItemInfo(ULONG ulDumpFlags)
  547. {
  548. // Read data
  549. LONG lValX, lValY;
  550. GetXY( lValX, lValY);
  551. if(XDF_Event == ulDumpFlags)
  552. {
  553. sprintf(GlobalTempBuffer, "AXES: X = %d, Y = %d\n", lValX, lValY);
  554. }
  555. else if(XDF_Trigger == ulDumpFlags)
  556. {
  557. if( lValX )
  558. {
  559. sprintf(GlobalTempBuffer, "AXES: Assign to X\n");
  560. }
  561. else if (lValY)
  562. {
  563. sprintf(GlobalTempBuffer, "AXES: Assign to Y\n");
  564. }
  565. else
  566. {
  567. sprintf(GlobalTempBuffer, "AXES: Invalid Assignment\n");
  568. }
  569. }
  570. DumpString(GlobalTempBuffer);
  571. }
  572. void CDPADDump::DumpItemInfo(ULONG ulDumpFlags)
  573. {
  574. UNREFERENCED_PARAMETER(ulDumpFlags);
  575. LONG lDirection;
  576. GetDirection(lDirection);
  577. sprintf(GlobalTempBuffer, "DPAD: Direction = %d\n", lDirection);
  578. DumpString(GlobalTempBuffer);
  579. }
  580. void CPropDPADDump::DumpItemInfo(ULONG ulDumpFlags)
  581. {
  582. UNREFERENCED_PARAMETER(ulDumpFlags);
  583. LONG lDirection;
  584. GetDirection(lDirection);
  585. sprintf(GlobalTempBuffer, "DPAD: Direction = %d\n", lDirection);
  586. DumpString(GlobalTempBuffer);
  587. }
  588. void CButtonsDump::DumpItemInfo(ULONG ulDumpFlags)
  589. {
  590. USHORT usButtonNum;
  591. ULONG ulButtonBitArray;
  592. GetButtons( usButtonNum, ulButtonBitArray );
  593. if(XDF_Event == ulDumpFlags)
  594. {
  595. sprintf(GlobalTempBuffer, "BUTTONS: BitArray = 0x%0.8x, ButtonNum = %d\n", ulButtonBitArray, (ULONG)usButtonNum);
  596. }
  597. else if(XDF_Trigger == ulDumpFlags)
  598. {
  599. sprintf(GlobalTempBuffer, "BUTTONS: ButtonNum = %d MODIFIERS = %d\n", (ULONG)usButtonNum, GetNumModifiers());
  600. }
  601. DumpString(GlobalTempBuffer);
  602. }
  603. void CPOVDump::DumpItemInfo(ULONG ulDumpFlags)
  604. {
  605. UNREFERENCED_PARAMETER(ulDumpFlags);
  606. LONG lDirection;
  607. GetValue(lDirection);
  608. sprintf(GlobalTempBuffer, "POV: Direction = %d\n", lDirection);
  609. DumpString(GlobalTempBuffer);
  610. }
  611. void CThrottleDump::DumpItemInfo(ULONG ulDumpFlags)
  612. {
  613. UNREFERENCED_PARAMETER(ulDumpFlags);
  614. LONG lVal;
  615. GetValue(lVal);
  616. sprintf(GlobalTempBuffer, "THROTTLE: Value = %d\n", lVal);
  617. DumpString(GlobalTempBuffer);
  618. }
  619. void CRudderDump::DumpItemInfo(ULONG ulDumpFlags)
  620. {
  621. UNREFERENCED_PARAMETER(ulDumpFlags);
  622. LONG lVal;
  623. GetValue(lVal);
  624. sprintf(GlobalTempBuffer, "RUDDER: Value = %d\n", lVal);
  625. DumpString(GlobalTempBuffer);
  626. }
  627. void CWheelDump::DumpItemInfo(ULONG ulDumpFlags)
  628. {
  629. UNREFERENCED_PARAMETER(ulDumpFlags);
  630. LONG lVal;
  631. GetValue(lVal);
  632. sprintf(GlobalTempBuffer, "WHEEL: Value = %d\n", lVal);
  633. DumpString(GlobalTempBuffer);
  634. }
  635. void CPedalDump::DumpItemInfo(ULONG ulDumpFlags)
  636. {
  637. UNREFERENCED_PARAMETER(ulDumpFlags);
  638. LONG lVal;
  639. GetValue(lVal);
  640. sprintf(GlobalTempBuffer, "PEDAL: Value = %d\n", lVal);
  641. DumpString(GlobalTempBuffer);
  642. }
  643. void CZoneIndicatorDump::DumpItemInfo(ULONG ulDumpFlags)
  644. {
  645. UNREFERENCED_PARAMETER(ulDumpFlags);
  646. if( GetXIndicator() )
  647. {
  648. DumpString("ZoneIndicator: X is set\n");
  649. }
  650. if( GetYIndicator() )
  651. {
  652. DumpString("ZoneIndicator: X is set\n");
  653. }
  654. }
  655. void CDualZoneIndicatorDump::DumpItemInfo(ULONG ulDumpFlags)
  656. {
  657. UNREFERENCED_PARAMETER(ulDumpFlags);
  658. static char* s_pszXY = "XY";
  659. static char* s_pszRz = "Rz";
  660. char *psz;
  661. if( IsXYIndicator() )
  662. {
  663. psz = s_pszXY;
  664. }
  665. else if( IsRzIndicator() )
  666. {
  667. psz = s_pszRz;
  668. }
  669. else
  670. psz = "Unknown Zone";
  671. sprintf(GlobalTempBuffer, "DualZoneIndicator (XY:%d/%d)\n", GetActiveZone(), GetNumZones());
  672. DumpString (GlobalTempBuffer);
  673. }
  674. void CForceMapDump::DumpItemInfo(ULONG ulDumpFlags)
  675. {
  676. UNREFERENCED_PARAMETER(ulDumpFlags);
  677. CHAR szBuf[0x100];
  678. sprintf (szBuf, "MapYToX: %s\n", GetMapYToX() ? "ON" : "OFF");
  679. DumpString (szBuf);
  680. sprintf (szBuf, "RTC: %d\n", GetRTC());
  681. DumpString (szBuf);
  682. sprintf (szBuf, "Gain: %d\n", GetGain());
  683. DumpString (szBuf);
  684. }
  685. HRESULT DumpItemFactory
  686. (
  687. USHORT usType,
  688. const CONTROL_ITEM_DESC* cpControlItemDesc,
  689. CDumpItem **ppControlItem
  690. )
  691. {
  692. HRESULT hr = S_OK;
  693. switch(usType)
  694. {
  695. case ControlItemConst::usAxes:
  696. *ppControlItem = new WDM_NON_PAGED_POOL CAxesDump(cpControlItemDesc);
  697. break;
  698. case ControlItemConst::usDPAD:
  699. *ppControlItem = new WDM_NON_PAGED_POOL CDPADDump(cpControlItemDesc);
  700. break;
  701. case ControlItemConst::usPropDPAD:
  702. *ppControlItem = new WDM_NON_PAGED_POOL CPropDPADDump(cpControlItemDesc);
  703. break;
  704. case ControlItemConst::usWheel:
  705. *ppControlItem= new WDM_NON_PAGED_POOL CWheelDump(cpControlItemDesc);
  706. break;
  707. case ControlItemConst::usPOV:
  708. *ppControlItem = new WDM_NON_PAGED_POOL CPOVDump(cpControlItemDesc);
  709. break;
  710. case ControlItemConst::usThrottle:
  711. *ppControlItem = new WDM_NON_PAGED_POOL CThrottleDump(cpControlItemDesc);
  712. break;
  713. case ControlItemConst::usRudder:
  714. *ppControlItem = new WDM_NON_PAGED_POOL CRudderDump(cpControlItemDesc);
  715. break;
  716. case ControlItemConst::usPedal:
  717. *ppControlItem = new WDM_NON_PAGED_POOL CPedalDump(cpControlItemDesc);
  718. break;
  719. case ControlItemConst::usButton:
  720. *ppControlItem = new WDM_NON_PAGED_POOL CButtonsDump(cpControlItemDesc);
  721. break;
  722. case ControlItemConst::usZoneIndicator:
  723. *ppControlItem = new WDM_NON_PAGED_POOL CZoneIndicatorDump(cpControlItemDesc);
  724. break;
  725. case ControlItemConst::usDualZoneIndicator:
  726. *ppControlItem = new WDM_NON_PAGED_POOL CDualZoneIndicatorDump(cpControlItemDesc);
  727. break;
  728. case ControlItemConst::usForceMap:
  729. *ppControlItem = new WDM_NON_PAGED_POOL CForceMapDump(cpControlItemDesc);
  730. break;
  731. default:
  732. *ppControlItem = NULL;
  733. return S_FALSE;
  734. }
  735. if(!*ppControlItem)
  736. {
  737. return E_FAIL;
  738. }
  739. return S_OK;
  740. }
  741. BOOLEAN DumpKeyboardData(PCONTROL_ITEM_XFER pControlItemXfer)
  742. {
  743. sprintf(GlobalTempBuffer, "Keyboard.ucModifier = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.ucModifierByte);
  744. DumpString(GlobalTempBuffer);
  745. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[0] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[0]);
  746. DumpString(GlobalTempBuffer);
  747. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[1] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[1]);
  748. DumpString(GlobalTempBuffer);
  749. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[2] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[2]);
  750. DumpString(GlobalTempBuffer);
  751. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[3] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[3]);
  752. DumpString(GlobalTempBuffer);
  753. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[4] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[4]);
  754. DumpString(GlobalTempBuffer);
  755. sprintf(GlobalTempBuffer, "Keyboard.rgucKeysDown[5] = 0x%0.8x\n", (ULONG)pControlItemXfer->Keyboard.rgucKeysDown[5]);
  756. DumpString(GlobalTempBuffer);
  757. sprintf(GlobalTempBuffer, "ulModifiers = 0x%0.8x\n", pControlItemXfer->ulModifiers);
  758. DumpString(GlobalTempBuffer);
  759. return TRUE;
  760. }
  761. #endif