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.

675 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. fldump.c
  5. Abstract:
  6. this file dumps the contents of the dat file in readable form
  7. Author:
  8. Kanwaljit Marok (kmarok) 01-May-2000
  9. Revision History:
  10. --*/
  11. #define RING3
  12. #include "common.h"
  13. #include "pathtree.h"
  14. #include "hashlist.h"
  15. //
  16. // INCLUDE the common source files from kernel directory
  17. //
  18. #define _PRECOMP_H_ // don't include the sr\kernel precomp header
  19. #include "ptree.c"
  20. #include "hlist.c"
  21. #include "blob.c"
  22. #include "verifyBlob.c"
  23. static char * nodeTypArr[] = {
  24. "UNKNOWN",
  25. "INCLUDE",
  26. "EXCLUDE",
  27. };
  28. //
  29. // GetNodeTypeStr : Returns node type string
  30. //
  31. PCHAR
  32. GetNodeTypeStr(
  33. INT iNodeType
  34. )
  35. {
  36. return nodeTypArr[ iNodeType ];
  37. }
  38. //
  39. // Ring 3 test code routines begin here
  40. //
  41. VOID
  42. PrintList(
  43. PBYTE pList,
  44. INT iNode,
  45. INT levelIn
  46. )
  47. {
  48. while ( iNode )
  49. {
  50. ListEntry * node = LIST_NODEPTR(pList, iNode);
  51. INT cbChars = (*(wchar_t*)( pList + node->m_dwData ) - 2)/2;
  52. INT level = levelIn;
  53. while( level-- )
  54. printf(" ");
  55. printf(" - %*.*S (%d, %d, %8.8s)\n",
  56. cbChars, cbChars,
  57. pList + node->m_dwData + sizeof(wchar_t),
  58. iNode,
  59. *(wchar_t*)( pList + node->m_dwData ),
  60. GetNodeTypeStr(node->m_dwType));
  61. iNode = node->m_iNext;
  62. }
  63. }
  64. //
  65. // This functions formats and prints the list
  66. //
  67. VOID
  68. PrintListFormatted(
  69. PBYTE pList,
  70. INT level
  71. )
  72. {
  73. if( pList )
  74. {
  75. INT i;
  76. for( i=0; i<(INT)LIST_HEADER(pList)->m_iHashBuckets; i++ )
  77. {
  78. INT iNode;
  79. if( (iNode = HASH_BUCKET(pList, i) ) == 0 )
  80. continue;
  81. PrintList( pList, iNode, level );
  82. }
  83. }
  84. }
  85. //
  86. // PrintNode: Prints out a node in proper format depending on level.
  87. //
  88. VOID
  89. PrintNode(
  90. PBYTE pTree,
  91. INT iNode,
  92. INT levelIn
  93. )
  94. {
  95. TreeNode * node = TREE_NODEPTR(pTree, iNode);
  96. INT cbChars = (*(wchar_t*)( pTree + node->m_dwData ) - sizeof(wchar_t))/sizeof(wchar_t);
  97. INT level = levelIn;
  98. while( level-- )
  99. printf(" ");
  100. printf("%*.*S (%d, %d, %8.8s, 0x%8.8X)\n",
  101. cbChars, cbChars,
  102. pTree + node->m_dwData + sizeof(wchar_t),
  103. iNode,
  104. *(wchar_t*)( pTree + node->m_dwData ),
  105. GetNodeTypeStr(node->m_dwType),
  106. node->m_dwFlags
  107. );
  108. if( node->m_dwFileList )
  109. PrintListFormatted( pTree + node->m_dwFileList, levelIn );
  110. }
  111. //
  112. // PrintTreeFormatted: prints out the tree blod in readable form
  113. //
  114. VOID PrintTreeFormatted(
  115. PBYTE pTree,
  116. INT iNode,
  117. INT *pLevel )
  118. {
  119. TreeNode * node = TREE_NODEPTR(pTree, iNode);
  120. PrintNode( pTree, iNode, *pLevel );
  121. (*pLevel)++;
  122. if(node->m_iSon)
  123. {
  124. TreeNode * son = TREE_NODEPTR(pTree, node->m_iSon);
  125. INT iSonSibling = son->m_iSibling;
  126. PrintTreeFormatted(pTree, node->m_iSon, pLevel);
  127. while(iSonSibling)
  128. {
  129. TreeNode * sonSibling = TREE_NODEPTR(pTree, iSonSibling);
  130. PrintTreeFormatted(pTree, iSonSibling, pLevel);
  131. iSonSibling = sonSibling->m_iSibling;
  132. }
  133. }
  134. (*pLevel)--;
  135. }
  136. //
  137. // TestLookup : This function tests a sample lookup
  138. //
  139. VOID TestLookup(
  140. PBYTE pTree,
  141. PBYTE pList
  142. )
  143. {
  144. INT i = 0;
  145. INT iNode = -1;
  146. INT iType = 0;
  147. INT iLevel = 0;
  148. INT iDrive = DRIVE_INDEX(L'C');
  149. BOOL fFileMatch = FALSE;
  150. BYTE pPathTmp[ MAX_PPATH_SIZE ];
  151. LPWSTR pLookupStr = NULL;
  152. PUNICODE_STRING pUStr = NULL;
  153. if ( !pTree )
  154. {
  155. goto Exit;
  156. }
  157. printf("\n\nTesting some sample lookups in the tree.\n\n\n" );
  158. pLookupStr = L"\\device\\harddiskVolume1\\Winnt\\system32";
  159. if ( ConvertToParsedPath(
  160. pLookupStr,
  161. (USHORT)lstrlenW(pLookupStr),
  162. pPathTmp,
  163. sizeof(pPathTmp)) )
  164. {
  165. printf("Looking up : %S\n\t", pLookupStr);
  166. if( MatchPrefix(
  167. pTree,
  168. TREE_ROOT_NODE,
  169. ((path_t)pPathTmp)->pp_elements,
  170. &iNode,
  171. &iLevel,
  172. &iType,
  173. NULL,
  174. &fFileMatch) )
  175. {
  176. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  177. }
  178. else
  179. {
  180. printf("Not found .\n");
  181. }
  182. }
  183. else
  184. {
  185. printf( "ConvertToParsedPath Not found\n");
  186. }
  187. iLevel = iType= 0;
  188. //
  189. // Test File match
  190. //
  191. pLookupStr = L"\\device\\harddiskVolume1\\Winnt\\system32\\mshtml.tlb";
  192. if ( ConvertToParsedPath(
  193. pLookupStr,
  194. (USHORT)lstrlenW(pLookupStr),
  195. pPathTmp,
  196. sizeof(pPathTmp)) )
  197. {
  198. printf("Looking up : %S\n\t", pLookupStr);
  199. if( MatchPrefix(
  200. pTree,
  201. TREE_ROOT_NODE,
  202. ((path_t)pPathTmp)->pp_elements,
  203. &iNode,
  204. &iLevel,
  205. &iType,
  206. NULL,
  207. &fFileMatch) )
  208. {
  209. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  210. }
  211. else
  212. {
  213. printf("Not Found.\n");
  214. }
  215. }
  216. else
  217. {
  218. printf( "ConvertToParsedPath Not found\n");
  219. }
  220. iLevel = iType= 0;
  221. //
  222. // Test File match
  223. //
  224. pLookupStr = L"\\??\\d:\\sr-wstress\\RF_0_7742.dll";
  225. if ( ConvertToParsedPath(
  226. pLookupStr,
  227. (USHORT)lstrlenW(pLookupStr),
  228. pPathTmp,
  229. sizeof(pPathTmp)) )
  230. {
  231. printf("Looking up : %S\n\t", pLookupStr);
  232. if( MatchPrefix(
  233. pTree,
  234. TREE_ROOT_NODE,
  235. ((path_t)pPathTmp)->pp_elements,
  236. &iNode,
  237. &iLevel,
  238. &iType,
  239. NULL,
  240. &fFileMatch) )
  241. {
  242. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  243. }
  244. else
  245. {
  246. printf("Not Found.\n");
  247. }
  248. }
  249. else
  250. {
  251. printf( "ConvertToParsedPath Not found\n");
  252. }
  253. iLevel = iType= 0;
  254. //
  255. // Test a wildcard in the path
  256. //
  257. pLookupStr = L"\\device\\harddiskVolume1\\wildcards\\kmarok\\xyz";
  258. if ( ConvertToParsedPath(
  259. pLookupStr,
  260. (USHORT)lstrlenW(pLookupStr),
  261. pPathTmp,
  262. sizeof(pPathTmp)) )
  263. {
  264. printf("Looking up : %S\n\t", pLookupStr);
  265. if( MatchPrefix(
  266. pTree,
  267. TREE_ROOT_NODE,
  268. ((path_t)pPathTmp)->pp_elements,
  269. &iNode,
  270. &iLevel,
  271. &iType,
  272. NULL,
  273. &fFileMatch) )
  274. {
  275. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  276. }
  277. else
  278. {
  279. printf("Not Found .\n");
  280. }
  281. }
  282. else
  283. {
  284. printf( "ConvertToParsedPath Not found\n");
  285. }
  286. //
  287. // Test a wildcard in the path
  288. //
  289. pLookupStr = L"\\device\\harddiskVolume1\\wildcards\\kmarok";
  290. if ( ConvertToParsedPath(
  291. pLookupStr,
  292. (USHORT)lstrlenW(pLookupStr),
  293. pPathTmp,
  294. sizeof(pPathTmp)) )
  295. {
  296. printf("Looking up : %S\n\t", pLookupStr);
  297. if( MatchPrefix(
  298. pTree,
  299. TREE_ROOT_NODE,
  300. ((path_t)pPathTmp)->pp_elements,
  301. &iNode,
  302. &iLevel,
  303. &iType,
  304. NULL,
  305. &fFileMatch) )
  306. {
  307. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  308. }
  309. else
  310. {
  311. printf("Not Found .\n");
  312. }
  313. }
  314. else
  315. {
  316. printf( "ConvertToParsedPath Not found\n");
  317. }
  318. iLevel = iType= 0;
  319. //
  320. // Test a wildcard in the path
  321. //
  322. pLookupStr = L"\\device\\harddiskVolume1\\wildcards\\kmarok\\abc";
  323. if ( ConvertToParsedPath(
  324. pLookupStr,
  325. (USHORT)lstrlenW(pLookupStr),
  326. pPathTmp,
  327. sizeof(pPathTmp)) )
  328. {
  329. printf("Looking up : %S\n\t", pLookupStr);
  330. if( MatchPrefix(
  331. pTree,
  332. TREE_ROOT_NODE,
  333. ((path_t)pPathTmp)->pp_elements,
  334. &iNode,
  335. &iLevel,
  336. &iType,
  337. NULL,
  338. &fFileMatch) )
  339. {
  340. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  341. }
  342. else
  343. {
  344. printf("Not Found .\n");
  345. }
  346. }
  347. else
  348. {
  349. printf( "ConvertToParsedPath Not found\n");
  350. }
  351. iLevel = iType= 0;
  352. //
  353. // Test a root level path
  354. //
  355. pLookupStr = L"\\device\\harddiskVolume1\\boot.ini";
  356. if ( ConvertToParsedPath(
  357. pLookupStr,
  358. (USHORT)lstrlenW(pLookupStr),
  359. pPathTmp,
  360. sizeof(pPathTmp)) )
  361. {
  362. printf("Looking up : %S\n\t", pLookupStr);
  363. if( MatchPrefix(
  364. pTree,
  365. TREE_ROOT_NODE,
  366. ((path_t)pPathTmp)->pp_elements,
  367. &iNode,
  368. &iLevel,
  369. &iType,
  370. NULL,
  371. &fFileMatch) )
  372. {
  373. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  374. }
  375. else
  376. {
  377. printf("Not found .\n");
  378. }
  379. }
  380. else
  381. {
  382. printf( "ConvertToParsedPath Not found\n");
  383. }
  384. //
  385. // test a failure
  386. //
  387. iLevel = iType= 0;
  388. pLookupStr = L"\\device\\harddiskVolume1\\Winnt\\system320";
  389. if ( ConvertToParsedPath(
  390. pLookupStr,
  391. (USHORT)lstrlenW(pLookupStr),
  392. pPathTmp,
  393. sizeof(pPathTmp)) )
  394. {
  395. printf("Looking up : %S\n\t", pLookupStr);
  396. if( MatchPrefix(
  397. pTree,
  398. TREE_ROOT_NODE,
  399. ((path_t)pPathTmp)->pp_elements,
  400. &iNode,
  401. &iLevel,
  402. &iType,
  403. NULL,
  404. &fFileMatch) )
  405. {
  406. printf("Found. N:%d L:%d T:%d\n", iNode, iLevel, iType);
  407. }
  408. else
  409. {
  410. printf("Not found .\n");
  411. }
  412. }
  413. else
  414. {
  415. printf( "ConvertToParsedPath Not found\n");
  416. }
  417. //
  418. // Test extension match
  419. //
  420. pLookupStr = L"PWERPNT.INI";
  421. pUStr = (PUNICODE_STRING)pPathTmp;
  422. pUStr->Buffer = (PWCHAR)(pUStr + 1);
  423. pUStr->Length = (USHORT)(lstrlenW(pLookupStr) * sizeof(WCHAR));
  424. pUStr->MaximumLength = pUStr->Length;
  425. RtlCopyMemory( pUStr->Buffer, pLookupStr, pUStr->Length );
  426. pUStr->Buffer[lstrlenW(pLookupStr)] = UNICODE_NULL;
  427. {
  428. printf("Looking up : %S\n\t", pLookupStr);
  429. if( MatchExtension(
  430. pList,
  431. pUStr,
  432. &iType,
  433. &fFileMatch ) )
  434. {
  435. printf("Found. T:%d, HasExtension :%d\n", iType, fFileMatch);
  436. }
  437. else
  438. {
  439. printf("Not found .\n");
  440. }
  441. }
  442. //
  443. // Test extension match
  444. //
  445. pLookupStr = L"PWERPNT.ini";
  446. pUStr = (PUNICODE_STRING)pPathTmp;
  447. pUStr->Buffer = (PWCHAR)(pUStr + 1);
  448. pUStr->Length = (USHORT)(lstrlenW(pLookupStr) * sizeof(WCHAR));
  449. pUStr->MaximumLength = pUStr->Length;
  450. RtlCopyMemory( pUStr->Buffer, pLookupStr, pUStr->Length );
  451. pUStr->Buffer[lstrlenW(pLookupStr)] = UNICODE_NULL;
  452. {
  453. printf("Looking up : %S\n\t", pLookupStr);
  454. if( MatchExtension(
  455. pList,
  456. pUStr,
  457. &iType,
  458. &fFileMatch ) )
  459. {
  460. printf("Found. T:%d, HasExtension :%d\n", iType, fFileMatch);
  461. }
  462. else
  463. {
  464. printf("Not found .\n");
  465. }
  466. }
  467. //
  468. // Test extension match
  469. //
  470. pLookupStr = L"PWERPNT";
  471. pUStr = (PUNICODE_STRING)pPathTmp;
  472. pUStr->Buffer = (PWCHAR)(pUStr + 1);
  473. pUStr->Length = (USHORT)(lstrlenW(pLookupStr) * sizeof(WCHAR));
  474. pUStr->MaximumLength = pUStr->Length;
  475. RtlCopyMemory( pUStr->Buffer, pLookupStr, pUStr->Length );
  476. pUStr->Buffer[lstrlenW(pLookupStr)] = UNICODE_NULL;
  477. {
  478. printf("Looking up : %S\n\t", pLookupStr);
  479. if( MatchExtension(
  480. pList,
  481. pUStr,
  482. &iType,
  483. &fFileMatch ) )
  484. {
  485. printf("Found. T:%d, HasExtension :%d\n", iType, fFileMatch);
  486. }
  487. else
  488. {
  489. printf("Not found .\n");
  490. }
  491. }
  492. Exit:
  493. return;
  494. }
  495. //
  496. // Main function
  497. //
  498. int __cdecl
  499. main(
  500. int argc,
  501. char * argv[]
  502. )
  503. {
  504. BYTE *pBlob, *pTree=NULL, *pList=NULL;
  505. BOOL fFound = FALSE;
  506. PCHAR pszFileName = "filelist.dat";
  507. DWORD dwDefaultType = NODE_TYPE_UNKNOWN;
  508. if( argc != 1 )
  509. {
  510. if( argc >= 2 && !strcmp( argv[1], "-t" ))
  511. {
  512. fFound = TRUE;
  513. }
  514. if( argc == 2 )
  515. {
  516. if( !fFound )
  517. pszFileName = argv[1];
  518. goto cont;
  519. }
  520. if( argc == 3 && fFound )
  521. {
  522. pszFileName = argv[2];
  523. goto cont;
  524. }
  525. printf("USAGE: %s [-t] [filename] \n\n ", argv[0]);
  526. return 0;
  527. }
  528. cont:
  529. if( pBlob = ReadCfgBlob( pszFileName, &pTree, &pList, &dwDefaultType ) )
  530. {
  531. if (!VerifyBlob((DWORD_PTR)pBlob)) {
  532. printf("BLOB validation failed\n");
  533. return 1;
  534. }
  535. PRINT_BLOB_HEADER(pBlob);
  536. printf("Default NodeType : %s\n", GetNodeTypeStr(dwDefaultType) );
  537. if( pTree )
  538. {
  539. INT level = 0;
  540. PRINT_BLOB_HEADER ( pTree );
  541. PrintTreeFormatted( pTree, 0, &level );
  542. }
  543. if( pList )
  544. {
  545. INT level = 0;
  546. PRINT_BLOB_HEADER ( pList );
  547. PrintListFormatted( pList, 0 );
  548. }
  549. }
  550. else
  551. printf( "Error: Not found to load the %s.\n", pszFileName );
  552. if (fFound && pTree && pList)
  553. {
  554. TestLookup( pTree, pList );
  555. }
  556. return 0;
  557. }