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.

1612 lines
51 KiB

  1. #include <wmiexts.h>
  2. #include <utilfun.h>
  3. #include <wbemint.h>
  4. #include <tchar.h>
  5. #include <sync.h>
  6. #include <flexq.h>
  7. #include <arrtempl.h>
  8. #include <newnew.h>
  9. #include <malloc.h>
  10. #ifndef POLARITY
  11. #define POLARITY
  12. #endif
  13. #ifndef RELEASE_ME
  14. #define RELEASE_ME
  15. #endif
  16. #ifndef DELETE_ME
  17. #define DELETE_ME
  18. #endif
  19. #ifndef INTERNAL
  20. #define INTERNAL
  21. #endif
  22. #include <wstring.h>
  23. #include <filecach.h>
  24. #include <flexq.h>
  25. #include <arrtempl.h>
  26. #include <hiecache.h>
  27. #include <creposit.h>
  28. void
  29. DumpMemManager(ULONG_PTR pByte)
  30. {
  31. DEFINE_CPP_VAR( CTempMemoryManager, varCTempMemoryManager);
  32. CTempMemoryManager * pTmpAll = GET_CPP_VAR_PTR( CTempMemoryManager , varCTempMemoryManager );
  33. ReadMemory(pByte,pTmpAll,sizeof(CTempMemoryManager),0);
  34. dprintf(" m_dwTotalUsed %08x\n",pTmpAll->m_dwTotalUsed);
  35. dprintf(" m_dwTotalAllocated %08x\n",pTmpAll->m_dwTotalAllocated);
  36. dprintf(" m_dwNumAllocations %08x\n",pTmpAll->m_dwNumAllocations);
  37. dprintf(" m_dwNumMisses %08x\n",pTmpAll->m_dwNumMisses);
  38. DEFINE_CPP_VAR( CFlexArray, varArr);
  39. CFlexArray * pArr = GET_CPP_VAR_PTR(CFlexArray,varArr);
  40. DWORD i;
  41. ReadMemory((ULONG_PTR)pTmpAll->m_pAllocations,pArr,sizeof(CFlexArray),0);
  42. CTempMemoryManager::CAllocation ** pAllocs = (CTempMemoryManager::CAllocation **)_alloca(pArr->m_nSize*sizeof(void*));
  43. ReadMemory((ULONG_PTR)pArr->m_pArray,pAllocs,pArr->m_nSize*sizeof(void*),0);
  44. dprintf(" m_pArray %p %d\n",pArr->m_pArray,pArr->m_nSize);
  45. DWORD dwTotal = 0;
  46. for (i=0;i<pArr->m_nSize;i++)
  47. {
  48. dprintf(" CAllocation %d - %p\n",i,pAllocs[i]);
  49. DEFINE_CPP_VAR( CTempMemoryManager::CAllocation, varCAllocation );
  50. CTempMemoryManager::CAllocation * pCAll = GET_CPP_VAR_PTR( CTempMemoryManager::CAllocation, varCAllocation );
  51. ReadMemory((ULONG_PTR)pAllocs[i],pCAll,sizeof(CTempMemoryManager::CAllocation),0);
  52. dprintf(" m_dwAllocationSize %p\n",pCAll->m_dwAllocationSize);
  53. dprintf(" m_dwUsed %p\n",pCAll->m_dwUsed);
  54. dprintf(" m_dwFirstFree %p\n",pCAll->m_dwFirstFree);
  55. dwTotal += pCAll->m_dwAllocationSize;
  56. }
  57. dprintf(" TOT %p\n",dwTotal);
  58. }
  59. //
  60. //
  61. // dumps the CTempMemoryManagers in repdrvfs
  62. //
  63. //////////////////////////////////////////////////////
  64. DECLARE_API(tmpall)
  65. {
  66. INIT_API();
  67. ULONG_PTR pByte = GetExpression(args);
  68. if (pByte)
  69. {
  70. DumpMemManager(pByte);
  71. return;
  72. }
  73. pByte = GetExpression("repdrvfs!g_Manager");
  74. dprintf("repdrvfs!g_Manager @ %p\n",pByte);
  75. if (pByte)
  76. {
  77. DumpMemManager(pByte);
  78. }
  79. }
  80. //
  81. //
  82. // this enum is copyed from btr.h
  83. //
  84. //
  85. enum { const_DefaultPageSize = 0x2000, const_CurrentVersion = 0x101 };
  86. enum {
  87. PAGE_TYPE_IMPOSSIBLE = 0x0, // Not supposed to happen
  88. PAGE_TYPE_ACTIVE = 0xACCC, // Page is active with data
  89. PAGE_TYPE_DELETED = 0xBADD, // A deleted page on free list
  90. PAGE_TYPE_ADMIN = 0xADDD, // Page zero only
  91. // All pages
  92. OFFSET_PAGE_TYPE = 0, // True for all pages
  93. OFFSET_PAGE_ID = 1, // True for all pages
  94. OFFSET_NEXT_PAGE = 2, // True for all pages (Page continuator)
  95. // Admin Page (page zero) only
  96. OFFSET_LOGICAL_ROOT = 3, // Root of database
  97. };
  98. #define PS_PAGE_SIZE (8192)
  99. #define MIN_ARRAY_KEYS (256)
  100. /*
  101. void
  102. DumpFile(HANDLE hFile,DWORD * pPage)
  103. {
  104. // read the AdminPage
  105. BOOL bRet;
  106. DWORD nRead;
  107. bRet = ReadFile(hFile,pPage,PS_PAGE_SIZE,&nRead,0);
  108. if (bRet && (PS_PAGE_SIZE == nRead))
  109. {
  110. dprintf(" A %08x %08x %08x R %08x F %08x T %08x %08x %08x\n",
  111. pPage[OFFSET_PAGE_TYPE],
  112. pPage[OFFSET_PAGE_ID],
  113. pPage[OFFSET_NEXT_PAGE],
  114. pPage[OFFSET_LOGICAL_ROOT],
  115. pPage[OFFSET_FREE_LIST_ROOT],
  116. pPage[OFFSET_TOTAL_PAGES],
  117. pPage[OFFSET_PAGE_SIZE],
  118. pPage[OFFSET_IMPL_VERSION ]);
  119. }
  120. else
  121. {
  122. dprintf(" ReadFile %d\n",GetLastError());
  123. }
  124. // read the other pages
  125. DWORD i;
  126. DWORD dwTotPages = pPage[OFFSET_TOTAL_PAGES];
  127. for (i=1;i<dwTotPages;i++)
  128. {
  129. bRet = ReadFile(hFile,pPage,PS_PAGE_SIZE,&nRead,0);
  130. if (bRet && (PS_PAGE_SIZE == nRead))
  131. {
  132. dprintf(" %02x %08x %08x %08x - P %08x %08x %08x %08x\n",
  133. i,
  134. pPage[OFFSET_PAGE_TYPE],
  135. pPage[OFFSET_PAGE_ID],
  136. pPage[OFFSET_NEXT_PAGE],
  137. pPage[OFFSET_NEXT_PAGE+1], // Parent
  138. pPage[OFFSET_NEXT_PAGE+2], // NumKey
  139. pPage[OFFSET_NEXT_PAGE+2+pPage[OFFSET_NEXT_PAGE+2]], // UserData
  140. pPage[OFFSET_NEXT_PAGE+2+pPage[OFFSET_NEXT_PAGE+2]+1]); //ChildPageMap
  141. }
  142. }
  143. DWORD dwFileSize = GetFileSize(hFile,NULL);
  144. if (dwFileSize != (dwTotPages)*PS_PAGE_SIZE)
  145. {
  146. dprintf(" filesize %d expected %d\n",dwFileSize,((1+dwTotPages)*PS_PAGE_SIZE));
  147. }
  148. }
  149. */
  150. void PrintDWORDS(DWORD * pDW,DWORD nSize)
  151. {
  152. DWORD i;
  153. for (i=0;i<(nSize/4);i++)
  154. {
  155. dprintf(" %08x %08x %08x %08x %08x\n",i,
  156. pDW[0+i*4],pDW[1+i*4],pDW[2+i*4],pDW[3+i*4]);
  157. }
  158. if (nSize%4)
  159. {
  160. DWORD dwPAD[4];
  161. memset(dwPAD,0xff,sizeof(dwPAD));
  162. memcpy(dwPAD,pDW+i*4,(nSize%4)*sizeof(DWORD));
  163. dprintf(" %08x %08x %08x %08x %08x\n",i,
  164. dwPAD[0],dwPAD[1],dwPAD[2],dwPAD[3]);
  165. }
  166. }
  167. void PrintWORDS(WORD * pDW,DWORD nSize)
  168. {
  169. DWORD i;
  170. for (i=0;i<(nSize/8);i++)
  171. {
  172. dprintf(" %08x %04x %04x %04x %04x %04x %04x %04x %04x\n",i,
  173. pDW[0+i*8],pDW[1+i*8],pDW[2+i*8],pDW[3+i*8],
  174. pDW[4+i*8],pDW[5+i*8],pDW[6+i*8],pDW[7+i*8]);
  175. }
  176. if (nSize%8)
  177. {
  178. WORD dwPAD[8];
  179. memset(dwPAD,0xff,sizeof(dwPAD));
  180. memcpy(dwPAD,pDW+i*8,(nSize%8)*sizeof(WORD));
  181. dprintf(" %08x %04x %04x %04x %04x %04x %04x %04x %04x\n",i,
  182. dwPAD[0],dwPAD[1],dwPAD[2],dwPAD[3],
  183. dwPAD[4],dwPAD[5],dwPAD[6],dwPAD[7]);
  184. }
  185. }
  186. void
  187. DumpPage(DWORD * pPage)
  188. {
  189. if (TRUE)
  190. {
  191. // here we've read the page
  192. if (0xACCC != pPage[OFFSET_PAGE_TYPE])
  193. {
  194. return;
  195. }
  196. dprintf(" SIGN %08x PAGE %08x NEXT %08x\n",
  197. pPage[OFFSET_PAGE_TYPE],pPage[OFFSET_PAGE_ID],pPage[OFFSET_NEXT_PAGE]);
  198. pPage+=3;
  199. dprintf(" PAR %08x NUM %08x\n",pPage[0],pPage[1]);
  200. DWORD dwParent = pPage[0];
  201. DWORD dwNumKey = pPage[1];
  202. pPage+=2;
  203. //DWORD dwAlloc = (dwNumKey<=MIN_ARRAY_KEYS)?MIN_ARRAY_KEYS:dwNumKey;
  204. //DWORD * m_pdwUserData = HeapAlloc(GetProcessHeap(),0,sizeof(DWORD) *());
  205. //DWORD * m_pdwChildPageMap = HeapAlloc(GetProcessHeap(),0,sizeof(DWORD) *(1+));
  206. //WORD * m_pwKeyLookup = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * ());
  207. // dwNumKey DWORD USER_DATA
  208. // dwNumKey+1 DWORD CHILD_PAGE_MAP
  209. // dwNumKey WORD KEY_LOOKUP
  210. dprintf(" User Data\n");
  211. PrintDWORDS(pPage,dwNumKey);
  212. pPage+=dwNumKey;
  213. dprintf(" Child PageMap\n");
  214. PrintDWORDS(pPage,dwNumKey+1);
  215. pPage+=(dwNumKey+1);
  216. WORD * pKeyLookup = (WORD *)pPage;
  217. dprintf(" Key Lookup\n");
  218. PrintWORDS((WORD *)pPage,dwNumKey);
  219. WORD * pWPage = ((WORD *)pPage + dwNumKey);
  220. dprintf(" KEY CODE %08x\n",*pWPage);
  221. DWORD dwKeyUsed = *pWPage;
  222. pWPage++;
  223. WORD * pKeyCodes = pWPage;
  224. dprintf(" Key Codes\n");
  225. PrintWORDS((WORD *)pWPage,dwKeyUsed);
  226. pWPage += dwKeyUsed;
  227. DWORD dwNumStrings = *pWPage++;
  228. dprintf(" NUM STRINGS %08x\n",dwNumStrings);
  229. WORD * ArrayOffsets = pWPage;
  230. dprintf(" Strings Offsets\n");
  231. PrintWORDS((WORD *)pWPage,dwNumStrings);
  232. pWPage += dwNumStrings;
  233. DWORD dwPoolUsed = *pWPage++;
  234. dprintf(" POOL USED %08x\n",dwPoolUsed);
  235. //
  236. DWORD i;
  237. LPSTR pStrings = (LPSTR)pWPage;
  238. for (i=0;i<dwNumStrings;i++)
  239. {
  240. dprintf(" %08x %04x %s\n",i,ArrayOffsets[i],pStrings+ArrayOffsets[i]);
  241. }
  242. //
  243. // better view
  244. //
  245. for (i=0;i<dwNumKey;i++)
  246. {
  247. DWORD j;
  248. WORD NumToken = pKeyCodes[pKeyLookup[i]];
  249. dprintf(" ( ");
  250. for (j=0;j<NumToken;j++)
  251. {
  252. dprintf("%04x ",pKeyCodes[pKeyLookup[i]+1+j]);
  253. }
  254. dprintf(")\n");
  255. dprintf(" - ");
  256. for (j=0;j<NumToken;j++)
  257. {
  258. //pStrings+ArrayOffsets[i]
  259. dprintf("%s\\",pStrings+ArrayOffsets[pKeyCodes[pKeyLookup[i]+1+j]]);
  260. }
  261. dprintf("\n");
  262. }
  263. }
  264. }
  265. /*
  266. void
  267. DumpAllPages(HANDLE hFile,DWORD * pPage)
  268. {
  269. // read the AdminPage
  270. BOOL bRet;
  271. DWORD nRead;
  272. bRet = ReadFile(hFile,pPage,PS_PAGE_SIZE,&nRead,0);
  273. if (bRet && (PS_PAGE_SIZE == nRead))
  274. {
  275. dprintf(" A %08x %08x %08x R %08x F %08x T %08x %08x %08x\n",
  276. pPage[OFFSET_PAGE_TYPE],
  277. pPage[OFFSET_PAGE_ID],
  278. pPage[OFFSET_NEXT_PAGE],
  279. pPage[OFFSET_LOGICAL_ROOT],
  280. pPage[OFFSET_FREE_LIST_ROOT],
  281. pPage[OFFSET_TOTAL_PAGES],
  282. pPage[OFFSET_PAGE_SIZE],
  283. pPage[OFFSET_IMPL_VERSION ]);
  284. }
  285. else
  286. {
  287. dprintf(" ReadFile %d\n",GetLastError());
  288. return;
  289. }
  290. // read the other pages
  291. DWORD i;
  292. DWORD dwTotPages = pPage[OFFSET_TOTAL_PAGES];
  293. for (i=1;i<dwTotPages;i++)
  294. {
  295. DumpPage(hFile,i,pPage);
  296. }
  297. DWORD dwFileSize = GetFileSize(hFile,NULL);
  298. if (dwFileSize != (dwTotPages)*PS_PAGE_SIZE)
  299. {
  300. dprintf(" filesize %d expected %d\n",dwFileSize,((1+dwTotPages)*PS_PAGE_SIZE));
  301. }
  302. }
  303. */
  304. //
  305. // performs the same operations of CPageFile::ReadMap with a buffer
  306. //
  307. struct debugCPageFile
  308. {
  309. DWORD dwSign;
  310. DWORD dwTrans;
  311. DWORD dwPhysical;
  312. DWORD dwNumPagesA;
  313. DWORD * pPagesA;
  314. DWORD dwPagesFreeList;
  315. DWORD * pFreePages;
  316. DWORD dwSignTail;
  317. BYTE * pEnd;
  318. debugCPageFile(BYTE * pMap)
  319. {
  320. DWORD * pCurrent = (DWORD *)pMap;
  321. dwSign = *pCurrent++;
  322. dwTrans = *pCurrent++;
  323. dwPhysical = *pCurrent++;
  324. dwNumPagesA = *pCurrent++;
  325. pPagesA = pCurrent;
  326. pCurrent+=dwNumPagesA;
  327. dwPagesFreeList = *pCurrent++;
  328. pFreePages = pCurrent;
  329. pCurrent += dwPagesFreeList;
  330. dwSignTail = *pCurrent++;
  331. pEnd = (BYTE *)pCurrent;
  332. };
  333. BYTE * getEnd(){ return pEnd; }
  334. };
  335. struct debugBtrPage
  336. {
  337. DWORD dwPageType;
  338. DWORD dwPageId;
  339. DWORD dwNextPage;
  340. DWORD dwLogicalRoot;
  341. debugBtrPage(BYTE * pBtr)
  342. {
  343. DWORD * pdwCurrent = (DWORD *)pBtr;
  344. dwPageType = *pdwCurrent++;
  345. dwPageId = *pdwCurrent++;
  346. dwNextPage = *pdwCurrent++;
  347. dwLogicalRoot = *pdwCurrent++;
  348. }
  349. };
  350. #define MAP_LEADING_SIGNATURE 0xABCD
  351. #define MAP_TRAILING_SIGNATURE 0xDCBA
  352. void
  353. Dump_Map(HANDLE hFile)
  354. {
  355. HANDLE hFileMap = NULL;
  356. BYTE * pMap = NULL;
  357. DWORD dwSize = 0;
  358. dwSize = GetFileSize(hFile,NULL);
  359. hFileMap = CreateFileMapping(hFile,
  360. NULL,
  361. PAGE_READONLY,
  362. 0,
  363. dwSize,
  364. NULL);
  365. if (hFileMap)
  366. {
  367. pMap = (BYTE *)MapViewOfFile(hFileMap,
  368. FILE_MAP_READ,
  369. 0,0,0);
  370. }
  371. else
  372. {
  373. dprintf("MapViewOfFile(hFileMap) %d\n",GetLastError());
  374. goto cleanup;
  375. };
  376. dwSize = GetFileSize(hFile,NULL);
  377. hFileMap = CreateFileMapping(hFile,
  378. NULL,
  379. PAGE_READONLY,
  380. 0,
  381. dwSize,
  382. NULL);
  383. if (hFileMap)
  384. {
  385. pMap = (BYTE *)MapViewOfFile(hFileMap,
  386. FILE_MAP_READ,
  387. 0,0,0);
  388. }
  389. else
  390. {
  391. dprintf("MapViewOfFile(hFileMapFre) %d\n",GetLastError());
  392. goto cleanup;
  393. };
  394. if (pMap)
  395. {
  396. debugCPageFile a(pMap);
  397. dprintf(" m_ObjPF\n");
  398. dprintf(" %08x SIGN HEAD\n",a.dwSign);
  399. dprintf(" %08x Trans\n",a.dwTrans);
  400. dprintf(" %08x m_dwPhysPagesA\n",a.dwPhysical);
  401. dprintf(" %08x m_aPageMapA.size()\n",a.dwNumPagesA);
  402. PrintDWORDS(a.pPagesA,a.dwNumPagesA);
  403. dprintf(" %08x m_aPhysFreeListA.size()\n",a.dwPagesFreeList);
  404. PrintDWORDS(a.pFreePages,a.dwPagesFreeList);
  405. dprintf(" %08x SIGN TAIL\n",a.dwSignTail);
  406. debugCPageFile b(a.getEnd());
  407. dprintf(" m_BTreePF\n");
  408. dprintf(" %08x SIGN HEAD\n",b.dwSign);
  409. dprintf(" %08x Trans\n",b.dwTrans);
  410. dprintf(" %08x m_dwPhysPagesA\n",b.dwPhysical);
  411. dprintf(" %08x m_aPageMapA.size()\n",b.dwNumPagesA);
  412. PrintDWORDS(b.pPagesA,b.dwNumPagesA);
  413. dprintf(" %08x m_aPhysFreeListA.size()\n",b.dwPagesFreeList);
  414. PrintDWORDS(a.pFreePages,b.dwPagesFreeList);
  415. dprintf(" %08x SIGN TAIL\n",b.dwSignTail);
  416. }
  417. cleanup:
  418. if (pMap)
  419. UnmapViewOfFile(pMap);
  420. if (hFileMap)
  421. CloseHandle(hFileMap);
  422. };
  423. void
  424. Dump_AdminPage(BYTE * pMap,BYTE * pObj)
  425. {
  426. if (pMap && pObj)
  427. {
  428. debugCPageFile a(pMap);
  429. DWORD i;
  430. DWORD AdminIndex = 0;
  431. do {
  432. if (WMIREP_INVALID_PAGE == a.pPagesA[AdminIndex] ||
  433. WMIREP_RESERVED_PAGE == a.pPagesA[AdminIndex])
  434. {
  435. dprintf("BAD dwNextAdminPage %08x index %x\n",a.pPagesA[AdminIndex],AdminIndex);
  436. break;
  437. }
  438. BYTE * pAdminPage = pObj + (a.pPagesA[AdminIndex]*PS_PAGE_SIZE);
  439. VarObjHeapAdminPage * pAdmin = (VarObjHeapAdminPage *)pAdminPage;
  440. AdminIndex = pAdmin->dwNextAdminPage;
  441. dprintf(" ver %08x Next %08x Ent %08x\n",pAdmin->dwVersion,pAdmin->dwNextAdminPage,pAdmin->dwNumberEntriesOnPage);
  442. VarObjHeapFreeList * pFreeEntry = (VarObjHeapFreeList *)(pAdmin+1);
  443. dprintf(" dwPageId dwFreeSp dwCRC32\n");
  444. if (pAdmin->dwNumberEntriesOnPage > (PS_PAGE_SIZE/sizeof(VarObjHeapFreeList)))
  445. {
  446. dprintf("Suspicious dwNumberEntriesOnPage %08x on page %x\n",pAdmin->dwNumberEntriesOnPage,AdminIndex);
  447. break;
  448. }
  449. for (i=0;i<pAdmin->dwNumberEntriesOnPage;i++)
  450. {
  451. dprintf(" %08x - %08x %08x %08X\n",i,pFreeEntry->dwPageId,pFreeEntry->dwFreeSpace,pFreeEntry->dwCRC32);
  452. pFreeEntry++;
  453. }
  454. } while(AdminIndex);
  455. }
  456. };
  457. void
  458. Dump_Index(BYTE * pMap,BYTE * pBtr)
  459. {
  460. if (pMap && pBtr)
  461. {
  462. debugCPageFile a0(pMap);
  463. debugCPageFile a(a0.getEnd());
  464. BYTE * pStart = pBtr + (a.pPagesA[0]*PS_PAGE_SIZE);
  465. debugBtrPage b(pStart);
  466. dprintf(" %08x %08x %08x %08x - %08X\n",b.dwPageType,b.dwPageId,b.dwNextPage,b.dwLogicalRoot,a.pPagesA[0]);
  467. //other pages
  468. DWORD i;
  469. for (i=0;i<a.dwNumPagesA;i++)
  470. {
  471. dprintf(" ---- %08x - %08x\n",i,a.pPagesA[i]);
  472. if (WMIREP_INVALID_PAGE != a.pPagesA[i] &&
  473. WMIREP_RESERVED_PAGE != a.pPagesA[i])
  474. {
  475. pStart = pBtr + (a.pPagesA[i]*PS_PAGE_SIZE);
  476. DumpPage((DWORD *)pStart );
  477. }
  478. }
  479. }
  480. }
  481. #define INDEX_FILE _T("\\FS\\index.btr")
  482. #define HEAP_FILE _T("\\FS\\Objects.data")
  483. #define FILE_MAP_1 _T("\\FS\\mapping1.map")
  484. #define FILE_MAP_2 _T("\\FS\\mapping2.map")
  485. #define FILE_MAP_VER _T("\\FS\\mapping.ver")
  486. #define REG_WBEM _T("Software\\Microsoft\\WBEM\\CIMOM")
  487. #define REG_DIR _T("Repository Directory")
  488. HANDLE
  489. GetRepositoryFile(TCHAR * pFileName)
  490. {
  491. HKEY hKey;
  492. LONG lRet;
  493. HANDLE hFile = INVALID_HANDLE_VALUE;
  494. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  495. REG_WBEM,
  496. NULL,
  497. KEY_READ,
  498. &hKey);
  499. if (ERROR_SUCCESS == lRet)
  500. {
  501. TCHAR pPath[MAX_PATH];
  502. DWORD dwType;
  503. DWORD dwLen = MAX_PATH;
  504. lRet = RegQueryValueEx(hKey,
  505. REG_DIR,
  506. NULL,
  507. &dwType,
  508. (BYTE*)pPath,
  509. &dwLen);
  510. if (ERROR_SUCCESS == lRet)
  511. {
  512. TCHAR pPath2[MAX_PATH];
  513. ExpandEnvironmentStrings(pPath,pPath2,MAX_PATH);
  514. lstrcat(pPath2,pFileName);
  515. hFile = CreateFile(pPath2,
  516. GENERIC_READ,
  517. FILE_SHARE_WRITE|FILE_SHARE_READ,
  518. NULL,
  519. OPEN_EXISTING,
  520. 0,NULL);
  521. if (INVALID_HANDLE_VALUE != hFile)
  522. {
  523. // this is the OK path
  524. }
  525. else
  526. {
  527. dprintf("CreateFile(%s) %d\n",pPath2,GetLastError());
  528. }
  529. }
  530. else
  531. {
  532. dprintf("unable to RegQueryValueEx: %d\n",GetLastError());
  533. }
  534. RegCloseKey(hKey);
  535. }
  536. else
  537. {
  538. dprintf("unable to RegOpenKeyEx: %d\n",GetLastError());
  539. }
  540. return hFile;
  541. }
  542. //
  543. // Dumps the .MAP file as a CPageFile
  544. //
  545. /////////////////////////////////////////////
  546. DECLARE_API(fmap)
  547. {
  548. INIT_API();
  549. HANDLE hFile;
  550. hFile = GetRepositoryFile(FILE_MAP_VER);
  551. if (INVALID_HANDLE_VALUE != hFile)
  552. {
  553. DWORD dwWhichFile;
  554. DWORD nRead;
  555. if (ReadFile(hFile,&dwWhichFile,sizeof(DWORD),&nRead,NULL))
  556. {
  557. TCHAR * pFileName = (0 == dwWhichFile)?FILE_MAP_1:FILE_MAP_2;
  558. HANDLE hFileWithMaps = GetRepositoryFile(pFileName);
  559. if (INVALID_HANDLE_VALUE != hFileWithMaps)
  560. {
  561. Dump_Map(hFileWithMaps);
  562. CloseHandle(hFileWithMaps);
  563. }
  564. else
  565. {
  566. dprintf("GetRepositoryFile(%S) %d\n",pFileName,GetLastError());
  567. }
  568. }
  569. else
  570. {
  571. dprintf("ReadFile %d\n",GetLastError());
  572. }
  573. CloseHandle(hFile);
  574. }
  575. else
  576. {
  577. dprintf("GetRepositoryFile(%S) %d\n",FILE_MAP_VER,GetLastError());
  578. }
  579. }
  580. //
  581. // Dump the Admin page of the objects.data
  582. //
  583. //////////////////////////////////////////
  584. DECLARE_API(varobj)
  585. {
  586. INIT_API();
  587. HANDLE hFileWhich = INVALID_HANDLE_VALUE;
  588. HANDLE hFileMap = INVALID_HANDLE_VALUE;
  589. HANDLE hFileObj = INVALID_HANDLE_VALUE;
  590. HANDLE hMappingMap = NULL;
  591. HANDLE hMappingObj = NULL;
  592. DWORD dwSizeMap = 0;
  593. DWORD dwSizeObj = 0;
  594. BYTE * pMap;
  595. BYTE * pObj;
  596. hFileWhich = GetRepositoryFile(FILE_MAP_VER);
  597. if (INVALID_HANDLE_VALUE == hFileWhich)
  598. {
  599. goto Cleanup;
  600. }
  601. DWORD dwWhichFile;
  602. DWORD nRead;
  603. if (FALSE == ReadFile(hFileWhich,&dwWhichFile,sizeof(DWORD),&nRead,NULL))
  604. {
  605. goto Cleanup;
  606. }
  607. TCHAR * pFileName = (0 == dwWhichFile)?FILE_MAP_1:FILE_MAP_2;
  608. hFileMap = GetRepositoryFile(pFileName);
  609. if (INVALID_HANDLE_VALUE == hFileMap)
  610. {
  611. goto Cleanup;
  612. }
  613. dwSizeMap = GetFileSize(hFileMap,NULL);
  614. hMappingMap = CreateFileMapping(hFileMap,
  615. NULL,
  616. PAGE_READONLY,
  617. 0,
  618. dwSizeMap,
  619. NULL);
  620. if (hFileMap)
  621. {
  622. pMap = (BYTE *)MapViewOfFile(hMappingMap,
  623. FILE_MAP_READ,
  624. 0,0,0);
  625. }
  626. else
  627. {
  628. dprintf("MapViewOfFile(hMappingMap) %d\n",GetLastError());
  629. goto Cleanup;
  630. };
  631. hFileObj = GetRepositoryFile(HEAP_FILE);
  632. if (INVALID_HANDLE_VALUE == hFileObj)
  633. {
  634. //dprintf("");
  635. goto Cleanup;
  636. }
  637. dwSizeObj = GetFileSize(hFileObj,NULL);
  638. hMappingObj = CreateFileMapping(hFileObj,
  639. NULL,
  640. PAGE_READONLY,
  641. 0,
  642. dwSizeObj,
  643. NULL);
  644. if (hMappingObj)
  645. {
  646. pObj = (BYTE *)MapViewOfFile(hMappingObj,
  647. FILE_MAP_READ,
  648. 0,0,0);
  649. }
  650. else
  651. {
  652. dprintf("MapViewOfFile(hMappingObj) %d\n",GetLastError());
  653. goto Cleanup;
  654. };
  655. if (pMap && pObj)
  656. {
  657. Dump_AdminPage(pMap,pObj);
  658. }
  659. Cleanup:
  660. if (pMap)
  661. UnmapViewOfFile(pMap);
  662. if (hMappingMap)
  663. CloseHandle(hMappingMap);
  664. if (INVALID_HANDLE_VALUE != hFileMap)
  665. CloseHandle(hFileMap);
  666. if (pObj)
  667. UnmapViewOfFile(pObj);
  668. if (hMappingObj)
  669. CloseHandle(hMappingObj);
  670. if (INVALID_HANDLE_VALUE != hFileObj)
  671. CloseHandle(hFileObj);
  672. if (INVALID_HANDLE_VALUE != hFileWhich)
  673. CloseHandle(hFileWhich);
  674. }
  675. //
  676. // Dump the Admin page of the btr
  677. //
  678. //////////////////////////////////////////
  679. DECLARE_API(btr)
  680. {
  681. INIT_API();
  682. HANDLE hFileWhich = INVALID_HANDLE_VALUE;
  683. HANDLE hFileMap = INVALID_HANDLE_VALUE;
  684. HANDLE hFileBtr = INVALID_HANDLE_VALUE;
  685. HANDLE hMappingMap = NULL;
  686. HANDLE hMappingBtr = NULL;
  687. DWORD dwSizeMap = 0;
  688. DWORD dwSizeBtr = 0;
  689. BYTE * pMap;
  690. BYTE * pBtr;
  691. hFileWhich = GetRepositoryFile(FILE_MAP_VER);
  692. if (INVALID_HANDLE_VALUE == hFileWhich)
  693. {
  694. goto Cleanup;
  695. }
  696. DWORD dwWhichFile;
  697. DWORD nRead;
  698. if (FALSE == ReadFile(hFileWhich,&dwWhichFile,sizeof(DWORD),&nRead,NULL))
  699. {
  700. goto Cleanup;
  701. }
  702. TCHAR * pFileName = (0 == dwWhichFile)?FILE_MAP_1:FILE_MAP_2;
  703. hFileMap = GetRepositoryFile(pFileName);
  704. dwSizeMap = GetFileSize(hFileMap,NULL);
  705. hMappingMap = CreateFileMapping(hFileMap,
  706. NULL,
  707. PAGE_READONLY,
  708. 0,
  709. dwSizeMap,
  710. NULL);
  711. if (hFileMap)
  712. {
  713. pMap = (BYTE *)MapViewOfFile(hMappingMap,
  714. FILE_MAP_READ,
  715. 0,0,0);
  716. }
  717. else
  718. {
  719. dprintf("MapViewOfFile(hMappingMap) %d\n",GetLastError());
  720. goto Cleanup;
  721. };
  722. hFileBtr = GetRepositoryFile(INDEX_FILE);
  723. if (INVALID_HANDLE_VALUE == hFileBtr)
  724. {
  725. //dprintf("");
  726. goto Cleanup;
  727. }
  728. dwSizeBtr = GetFileSize(hFileBtr,NULL);
  729. hMappingBtr = CreateFileMapping(hFileBtr,
  730. NULL,
  731. PAGE_READONLY,
  732. 0,
  733. dwSizeBtr,
  734. NULL);
  735. if (hMappingBtr)
  736. {
  737. pBtr = (BYTE *)MapViewOfFile(hMappingBtr,
  738. FILE_MAP_READ,
  739. 0,0,0);
  740. }
  741. else
  742. {
  743. dprintf("MapViewOfFile(hMappingBtr) %d\n",GetLastError());
  744. goto Cleanup;
  745. };
  746. if (pMap && pBtr)
  747. {
  748. Dump_Index(pMap,pBtr);
  749. }
  750. Cleanup:
  751. if (pMap)
  752. UnmapViewOfFile(pMap);
  753. if (hMappingMap)
  754. CloseHandle(hMappingMap);
  755. if (INVALID_HANDLE_VALUE != hFileMap)
  756. CloseHandle(hFileMap);
  757. if (pBtr)
  758. UnmapViewOfFile(pBtr);
  759. if (hMappingBtr)
  760. CloseHandle(hMappingBtr);
  761. if (INVALID_HANDLE_VALUE != hFileBtr)
  762. CloseHandle(hFileBtr);
  763. if (INVALID_HANDLE_VALUE != hFileWhich)
  764. CloseHandle(hFileWhich);
  765. }
  766. //
  767. //
  768. // dumps the g_FileCache
  769. //
  770. //
  771. /*
  772. DWORD WINAPI
  773. CallBackWriteInst(VOID * pData1)
  774. {
  775. DEFINE_CPP_VAR(CWriteFileInstruction,varCWriteFileInstruction);
  776. CWriteFileInstruction * pWriteInst = GET_CPP_VAR_PTR(CWriteFileInstruction,varCWriteFileInstruction);
  777. if (ReadMemory((ULONG_PTR)pData1,pWriteInst,sizeof(CWriteFileInstruction),NULL))
  778. {
  779. dprintf(" m_lStageOffset %p m_bCommitted %d\n",pWriteInst->m_lStageOffset,pWriteInst->m_bCommitted);
  780. dprintf(" m_dwLen %08x m_Location.m_nFileId %02x m_Location.m_lStartOffset %I64x\n",pWriteInst->m_dwLen,pWriteInst->m_Location.m_nFileId,pWriteInst->m_Location.m_lStartOffset);
  781. dprintf(" m_lZOrder %x m_bReuse %02x\n",pWriteInst->m_lZOrder,pWriteInst->m_bReuse);
  782. }
  783. return 0;
  784. }
  785. void DumpLongStage(ULONG_PTR Addr, // FileCache OOP pointer
  786. CFileCache * pFileCache, // inproc pointer
  787. ULONG_PTR Verbose)
  788. {
  789. //
  790. // CAbstractSource
  791. //
  792. dprintf(" + CLongFileStagingFile %p\n",Addr+FIELD_OFFSET(CFileCache,m_AbstractSource));
  793. CAbstractFileSource * pAbsS = &pFileCache->m_AbstractSource;
  794. CLongFileStagingFile * pLongStage = &pAbsS->m_Stage;
  795. CLongFileStagingFile * pLongStag_OOP = (CLongFileStagingFile *)(Addr + FIELD_OFFSET(CFileCache,m_AbstractSource) + FIELD_OFFSET(CAbstractFileSource,m_Stage));
  796. // CStageMgr members
  797. dprintf(" m_hFile %x m_hFlushFile %x\n",pLongStage->m_hFile,pLongStage->m_hFlushFile);
  798. //long m_lFirstFreeOffset;
  799. //CCritSec m_cs;
  800. dprintf(" m_qToWrite\n");
  801. _List * pList_OOP = (_List *)((BYTE *)pLongStag_OOP + FIELD_OFFSET(CLongFileStagingFile,m_qToWrite));
  802. PrintListCB(pList_OOP,CallBackWriteInst);
  803. dprintf(" m_stReplacedInstructions\n");
  804. pList_OOP = (_List *)((BYTE *)pLongStag_OOP + FIELD_OFFSET(CLongFileStagingFile,m_stReplacedInstructions));
  805. PrintListCB(pList_OOP,NULL);
  806. dprintf(" m_qTransaction\n");
  807. pList_OOP = (_List *)((BYTE *)pLongStag_OOP + FIELD_OFFSET(CLongFileStagingFile,m_qTransaction));
  808. PrintListCB(pList_OOP,CallBackWriteInst);
  809. dprintf(" TransIdx %I64d m_lTransactionStartOffset %x\n",pLongStage->m_nTransactionIndex,pLongStage->m_lTransactionStartOffset);
  810. //BYTE m_TransactionHash[16];
  811. dprintf(" bInTransaction %d bFailedBefore %d lStatus %d\n",pLongStage->m_bInTransaction,pLongStage->m_bFailedBefore,pLongStage->m_lStatus);
  812. //pStage->m_lMaxFileSize;
  813. //pStage->m_lAbortTransactionFileSize;
  814. // bool m_bMustFail;
  815. // bool m_bNonEmptyTransaction;
  816. if (Verbose)
  817. {
  818. // the multimap has the compare function
  819. _Map * pMapStarts = (_Map *)((BYTE*)pLongStag_OOP + sizeof(void *) + FIELD_OFFSET(CLongFileStagingFile,m_mapStarts));
  820. dprintf(" m_mapStarts\n");
  821. dprintf(" std::multimap< { CFileLocation::m_nFileId, CFileLocation::m_lStartOffset }, CWriteFileInstruction* >\n");
  822. PrintMapCB(pMapStarts,TRUE,NULL);
  823. _Map * pMapEnds = (_Map *)((BYTE*)pLongStag_OOP + sizeof(void *) + FIELD_OFFSET(CLongFileStagingFile,m_mapEnds));
  824. dprintf(" m_mapEnds\n");
  825. dprintf(" std::multimap< { CFileLocation::m_nFileId, CFileLocation::m_lStartOffset }, CWriteFileInstruction* >\n");
  826. PrintMapCB(pMapEnds,TRUE,NULL);
  827. }
  828. }
  829. DECLARE_API( stage )
  830. {
  831. INIT_API();
  832. ULONG_PTR Addr = 0;
  833. ULONG_PTR Verbose = GetExpression(args);
  834. Addr = GetExpression("repdrvfs!g_Glob");
  835. if (Addr)
  836. {
  837. Addr += FIELD_OFFSET(CGlobals,m_FileCache);
  838. }
  839. if (Addr)
  840. {
  841. DEFINE_CPP_VAR(CFileCache,varCFileCache);
  842. CFileCache * pFileCache = GET_CPP_VAR_PTR(CFileCache,varCFileCache);
  843. dprintf("CFileCache @ %p\n",Addr);
  844. if (ReadMemory((ULONG_PTR)Addr,pFileCache,sizeof(CFileCache),0))
  845. {
  846. DumpLongStage(Addr,pFileCache,Verbose);
  847. }
  848. else
  849. {
  850. dprintf("RM %p\n",Addr);
  851. }
  852. }
  853. else
  854. {
  855. dprintf("unable to resolve repdrvfs!g_Glob\n");
  856. }
  857. }
  858. */
  859. /*
  860. DECLARE_API( filec_old )
  861. {
  862. INIT_API();
  863. ULONG_PTR Addr = 0;
  864. if (0 != strlen(args))
  865. {
  866. Addr = GetExpression(args);
  867. }
  868. else
  869. {
  870. Addr = GetExpression("repdrvfs!g_Glob");
  871. if (Addr)
  872. {
  873. Addr += FIELD_OFFSET(CGlobals,m_FileCache);
  874. }
  875. }
  876. if (Addr)
  877. {
  878. DEFINE_CPP_VAR(CFileCache,varCFileCache);
  879. CFileCache * pFileCache = GET_CPP_VAR_PTR(CFileCache,varCFileCache);
  880. dprintf("CFileCache @ %p\n",Addr);
  881. if (ReadMemory((ULONG_PTR)Addr,pFileCache,sizeof(CFileCache),0))
  882. {
  883. dprintf(" m_lRef %d\n",pFileCache->m_lRef);
  884. DumpLongStage(Addr,pFileCache,TRUE);
  885. //
  886. // CObjectHeap
  887. //
  888. dprintf(" + CObjectHeap %p\n",Addr+FIELD_OFFSET(CFileCache,m_ObjectHeap));
  889. CObjectHeap * pObjectHeap_OOP = (CObjectHeap *)(Addr+FIELD_OFFSET(CFileCache,m_ObjectHeap));
  890. DEFINE_CPP_VAR(CFileHeap,varCFileHeap);
  891. CFileHeap * pFileHeap = GET_CPP_VAR_PTR(CFileHeap,varCFileHeap);
  892. CFileHeap * pFileHeap_OOP = (CFileHeap *)((ULONG_PTR)pObjectHeap_OOP+FIELD_OFFSET(CObjectHeap,m_Heap));
  893. dprintf(" +++ CFileHeap %p\n",pFileHeap_OOP);
  894. if (ReadMemory((ULONG_PTR)pFileHeap_OOP,pFileHeap,sizeof(CFileHeap),NULL))
  895. {
  896. DEFINE_CPP_VAR(CAbstractFile,varCAbstractFile);
  897. CAbstractFile * pAbstract = GET_CPP_VAR_PTR(CAbstractFile,varCAbstractFile);
  898. dprintf(" m_pMainFile %p\n",pFileHeap->m_pMainFile);
  899. ReadMemory((ULONG_PTR)pFileHeap->m_pMainFile,pAbstract,sizeof(CAbstractFile),NULL);
  900. dprintf(" m_pStage %p m_nId %d\n",pAbstract->m_pStage,pAbstract->m_nId);
  901. dprintf(" m_pFreeFile %p\n",pFileHeap->m_pFreeFile);
  902. ReadMemory((ULONG_PTR)pFileHeap->m_pFreeFile,pAbstract,sizeof(CAbstractFile),NULL);
  903. dprintf(" m_pStage %p m_nId %d\n",pAbstract->m_pStage,pAbstract->m_nId);
  904. dprintf(" m_mapFree\n");
  905. dprintf(" std::map< DWORD , { CRecordInfo::m_dwIndex, CRecordInfo::m_nOffset } >\n");
  906. _Map * pMapFree = (_Map *)((BYTE *)pFileCache->m_ObjectHeap.m_pHeap+FIELD_OFFSET(CFileHeap,m_mapFree));
  907. PrintMapCB(pMapFree,TRUE,NULL);
  908. dprintf(" m_mapFreeOffset\n");
  909. dprintf(" std::map< TOffset , DWORD >\n");
  910. _Map * pMapOffset = (_Map *)((BYTE *)pFileCache->m_ObjectHeap.m_pHeap+FIELD_OFFSET(CFileHeap,m_mapFreeOffset));
  911. PrintMapCB(pMapOffset,TRUE,NULL);
  912. }
  913. else
  914. {
  915. dprintf("RM %p %d\n",Addr,GetLastError());
  916. }
  917. CBtrIndex * pBtrIndex_OOP = (CBtrIndex *)((ULONG_PTR)pObjectHeap_OOP+FIELD_OFFSET(CObjectHeap,m_Index));
  918. dprintf(" +++ CBtrIndex %p\n",pBtrIndex_OOP);
  919. }
  920. else
  921. {
  922. dprintf("RM %p %d\n",Addr,GetLastError());
  923. }
  924. }
  925. else
  926. {
  927. dprintf("cannot resolve repdrvfs!g_Glob\n");
  928. }
  929. }
  930. */
  931. /*
  932. long m_lRef;
  933. BOOL m_bInit;
  934. CPageSource m_TransactionManager;
  935. CObjectHeap m_ObjectHeap;
  936. */
  937. void
  938. Print_CPageCache(ULONG_PTR pPageCache_OOP)
  939. {
  940. DEFINE_CPP_VAR(CPageCache,varCPageCache);
  941. CPageCache * pPageCache = GET_CPP_VAR_PTR(CPageCache,varCPageCache);
  942. dprintf(" + CPageCache @ %p\n",pPageCache_OOP);
  943. if (ReadMemory(pPageCache_OOP,pPageCache,sizeof(CPageCache),NULL))
  944. {
  945. /*
  946. DWORD m_dwStatus;
  947. DWORD m_dwPageSize;
  948. DWORD m_dwCacheSize;
  949. DWORD m_dwCachePromoteThreshold;
  950. DWORD m_dwCacheSpillRatio;
  951. DWORD m_dwLastFlushTime;
  952. DWORD m_dwWritesSinceFlush;
  953. DWORD m_dwLastCacheAccess;
  954. DWORD m_dwReadHits;
  955. DWORD m_dwReadMisses;
  956. DWORD m_dwWriteHits;
  957. DWORD m_dwWriteMisses;
  958. HANDLE m_hFile;
  959. std::vector <SCachePage *, wbem_allocator<SCachePage *> > m_aCache;
  960. */
  961. // dprintf(" m_dwStatus %08x\n",pPageCache->m_dwStatus);
  962. dprintf(" m_dwPageSize %08x\n",pPageCache->m_dwPageSize);
  963. dprintf(" m_dwCacheSize %08x\n",pPageCache->m_dwCacheSize);
  964. dprintf(" m_hFile %p\n",pPageCache->m_hFile);
  965. _Vector * pVector;
  966. ULONG_PTR Size;
  967. SCachePage ** ppSCachePage;
  968. pVector = (_Vector *)&pPageCache->m_aCache;
  969. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(SCachePage *);
  970. dprintf(" m_aCache - S %x - P %p\n",Size,pVector->_First);
  971. ppSCachePage = new SCachePage *[Size];
  972. if(ppSCachePage)
  973. {
  974. if (ReadMemory((ULONG_PTR)pVector->_First,ppSCachePage,sizeof(SCachePage *)*Size,NULL))
  975. {
  976. for (ULONG_PTR i=0;i<Size;i++)
  977. {
  978. //dprintf(" - %p - %d\n",ppSCachePage[i],i);
  979. DEFINE_CPP_VAR(SCachePage,varSCachePage);
  980. SCachePage * pSCachePage = GET_CPP_VAR_PTR(SCachePage,varSCachePage);
  981. if (ReadMemory((ULONG_PTR)ppSCachePage[i],pSCachePage,sizeof(SCachePage),NULL))
  982. {
  983. dprintf(" D %d %08x - %p\n",pSCachePage->m_bDirty,pSCachePage->m_dwPhysId,pSCachePage->m_pPage);
  984. }
  985. };
  986. }
  987. delete [] ppSCachePage;
  988. };
  989. }
  990. else
  991. {
  992. dprintf("RM %p\n",pPageCache_OOP);
  993. }
  994. };
  995. void
  996. Print_CPageFile(ULONG_PTR pPageFile_OOP, BOOL bVerbose)
  997. {
  998. DEFINE_CPP_VAR(CPageFile,varCPageFile);
  999. CPageFile * pPageFile = GET_CPP_VAR_PTR(CPageFile,varCPageFile);
  1000. dprintf(" + CPageFile @ %p\n",pPageFile_OOP);
  1001. if (ReadMemory(pPageFile_OOP,pPageFile,sizeof(CPageFile),NULL))
  1002. {
  1003. /*
  1004. LONG m_lRef;
  1005. DWORD m_dwStatus;
  1006. DWORD m_dwPageSize;
  1007. CRITICAL_SECTION m_cs;
  1008. WString m_sDirectory;
  1009. WString m_sMapFile;
  1010. WString m_sMainFile;
  1011. CPageCache *m_pCache;
  1012. BOOL m_bInTransaction;
  1013. DWORD m_dwLastCheckpoint;
  1014. DWORD m_dwTransVersion;
  1015. // Generation A Mapping
  1016. std::vector <DWORD, wbem_allocator<DWORD> > m_aPageMapA;
  1017. std::vector <DWORD, wbem_allocator<DWORD> > m_aPhysFreeListA;
  1018. std::vector <DWORD, wbem_allocator<DWORD> > m_aLogicalFreeListA;
  1019. std::vector <DWORD, wbem_allocator<DWORD> > m_aReplacedPagesA;
  1020. DWORD m_dwPhysPagesA;
  1021. // Generation B Mapping
  1022. std::vector <DWORD, wbem_allocator<DWORD> > m_aPageMapB;
  1023. std::vector <DWORD, wbem_allocator<DWORD> > m_aPhysFreeListB;
  1024. std::vector <DWORD, wbem_allocator<DWORD> > m_aLogicalFreeListB;
  1025. std::vector <DWORD, wbem_allocator<DWORD> > m_aReplacedPagesB;
  1026. DWORD m_dwPhysPagesB;
  1027. */
  1028. dprintf(" m_lRef %08x\n",pPageFile->m_lRef);
  1029. // dprintf(" m_dwStatus %08x\n",pPageFile->m_dwStatus);
  1030. dprintf(" m_dwPageSize %08x\n",pPageFile->m_dwPageSize);
  1031. // dprintf(" m_pCache %p\n",pPageFile->m_pCache);
  1032. // Print_CPageCache((ULONG_PTR)pPageFile->m_pCache);
  1033. dprintf(" m_bInTransaction %08x\n",pPageFile->m_bInTransaction);
  1034. dprintf(" m_dwLastCheckpoint %08x\n",pPageFile->m_dwLastCheckpoint);
  1035. dprintf(" m_dwTransVersion %08x\n",pPageFile->m_dwTransVersion);
  1036. _Vector * pVector;
  1037. ULONG_PTR Size;
  1038. DWORD * pDW;
  1039. pVector = (_Vector *)&pPageFile->m_aPageMapA;
  1040. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1041. dprintf(" m_aPageMapA - S %x - P %p\n",Size,pVector->_First);
  1042. if (bVerbose)
  1043. {
  1044. pDW = new DWORD[Size];
  1045. if(pDW)
  1046. {
  1047. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1048. {
  1049. PrintDWORDS(pDW,Size);
  1050. }
  1051. delete [] pDW;
  1052. };
  1053. }
  1054. pVector = (_Vector *)&pPageFile->m_aPhysFreeListA;
  1055. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1056. dprintf(" m_aPhysFreeListA - S %x - P %p\n",Size,pVector->_First);
  1057. if (bVerbose)
  1058. {
  1059. pDW = new DWORD[Size];
  1060. if(pDW)
  1061. {
  1062. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1063. {
  1064. PrintDWORDS(pDW,Size);
  1065. }
  1066. delete [] pDW;
  1067. };
  1068. };
  1069. pVector = (_Vector *)&pPageFile->m_aLogicalFreeListA;
  1070. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1071. dprintf(" m_aLogicalFreeListA - S %x - P %p\n",Size,pVector->_First);
  1072. if (bVerbose)
  1073. {
  1074. pDW = new DWORD[Size];
  1075. if(pDW)
  1076. {
  1077. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1078. {
  1079. PrintDWORDS(pDW,Size);
  1080. }
  1081. delete [] pDW;
  1082. };
  1083. }
  1084. pVector = (_Vector *)&pPageFile->m_aReplacedPagesA;
  1085. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1086. dprintf(" m_aReplacedPagesA - S %x - P %p\n",Size,pVector->_First);
  1087. if (bVerbose)
  1088. {
  1089. pDW = new DWORD[Size];
  1090. if(pDW)
  1091. {
  1092. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1093. {
  1094. PrintDWORDS(pDW,Size);
  1095. }
  1096. delete [] pDW;
  1097. };
  1098. }
  1099. dprintf(" m_dwPhysPagesA %08x\n",pPageFile->m_dwPhysPagesA);
  1100. pVector = (_Vector *)&pPageFile->m_aPageMapB;
  1101. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1102. dprintf(" m_aPageMapB - S %x - P %p\n",Size,pVector->_First);
  1103. if (bVerbose)
  1104. {
  1105. pDW = new DWORD[Size];
  1106. if(pDW)
  1107. {
  1108. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1109. {
  1110. PrintDWORDS(pDW,Size);
  1111. }
  1112. delete [] pDW;
  1113. };
  1114. }
  1115. pVector = (_Vector *)&pPageFile->m_aPhysFreeListB;
  1116. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1117. dprintf(" m_aPhysFreeListB - S %x - P %p\n",Size,pVector->_First);
  1118. if (bVerbose)
  1119. {
  1120. pDW = new DWORD[Size];
  1121. if(pDW)
  1122. {
  1123. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1124. {
  1125. PrintDWORDS(pDW,Size);
  1126. }
  1127. delete [] pDW;
  1128. };
  1129. }
  1130. pVector = (_Vector *)&pPageFile->m_aLogicalFreeListB;
  1131. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1132. dprintf(" m_aLogicalFreeListB - S %x - P %p\n",Size,pVector->_First);
  1133. if (bVerbose)
  1134. {
  1135. pDW = new DWORD[Size];
  1136. if(pDW)
  1137. {
  1138. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1139. {
  1140. PrintDWORDS(pDW,Size);
  1141. }
  1142. delete [] pDW;
  1143. };
  1144. }
  1145. pVector = (_Vector *)&pPageFile->m_aReplacedPagesB;
  1146. Size = ((ULONG_PTR)pVector->_Last - (ULONG_PTR)pVector->_First)/sizeof(DWORD);
  1147. dprintf(" m_aReplacedPagesB - S %x - P %p\n",Size,pVector->_First);
  1148. if (bVerbose)
  1149. {
  1150. pDW = new DWORD[Size];
  1151. if(pDW)
  1152. {
  1153. if (ReadMemory((ULONG_PTR)pVector->_First,pDW,sizeof(DWORD)*Size,NULL))
  1154. {
  1155. PrintDWORDS(pDW,Size);
  1156. }
  1157. delete [] pDW;
  1158. };
  1159. }
  1160. dprintf(" m_dwPhysPagesB %08x\n",pPageFile->m_dwPhysPagesB);
  1161. }
  1162. else
  1163. {
  1164. dprintf("RM %p\n",pPageFile_OOP);
  1165. }
  1166. }
  1167. DECLARE_API( filec )
  1168. {
  1169. INIT_API();
  1170. ULONG_PTR Addr = 0;
  1171. if (0 != strlen(args))
  1172. {
  1173. Addr = GetExpression(args);
  1174. }
  1175. else
  1176. {
  1177. Addr = GetExpression("repdrvfs!g_Glob");
  1178. if (Addr)
  1179. {
  1180. Addr += FIELD_OFFSET(CGlobals,m_FileCache);
  1181. }
  1182. }
  1183. if (Addr)
  1184. {
  1185. DEFINE_CPP_VAR(CFileCache,varCFileCache);
  1186. CFileCache * pFileCache = GET_CPP_VAR_PTR(CFileCache,varCFileCache);
  1187. dprintf("CFileCache @ %p\n",Addr);
  1188. if (ReadMemory((ULONG_PTR)Addr,pFileCache,sizeof(CFileCache),0))
  1189. {
  1190. dprintf(" m_lRef %d m_bInit %d\n",pFileCache->m_lRef,pFileCache->m_bInit);
  1191. //
  1192. // CPageSource
  1193. //
  1194. dprintf(" + CPageSource %p\n",Addr+FIELD_OFFSET(CFileCache,m_TransactionManager));
  1195. CPageSource * pPageSource_OOP = (CPageSource *)(Addr+FIELD_OFFSET(CFileCache,m_TransactionManager));
  1196. CPageSource * pPageSource = (CPageSource *)((BYTE *)pFileCache+FIELD_OFFSET(CFileCache,m_TransactionManager));
  1197. //dprintf();
  1198. dprintf(" m_dwStatus %08x\n",pPageSource->m_dwStatus);
  1199. dprintf(" m_dwPageSize %08x\n",pPageSource->m_dwPageSize);
  1200. dprintf(" m_dwCacheSize %08x\n",pPageSource->m_dwCacheSize);
  1201. dprintf(" m_dwCacheSpillRatio %08x\n",pPageSource->m_dwCacheSpillRatio);
  1202. dprintf(" m_dwLastCheckpoint %08x\n",pPageSource->m_dwLastCheckpoint);
  1203. // dprintf(" m_dwCheckpointInterval %08x\n",pPageSource->m_dwCheckpointInterval);
  1204. // WString m_sDirectory;
  1205. // WString m_sBTreeMap;
  1206. // WString m_sObjMap;
  1207. // CPageFile *
  1208. dprintf(" m_BTreePF\n");
  1209. Print_CPageFile((ULONG_PTR)pPageSource_OOP+FIELD_OFFSET(CPageSource,m_BTreePF),FALSE);
  1210. dprintf(" m_ObjPF\n");
  1211. Print_CPageFile((ULONG_PTR)pPageSource_OOP+FIELD_OFFSET(CPageSource,m_ObjPF),FALSE);
  1212. dprintf(" m_hFileMap1 %x\n",pPageSource->m_hFileMap1);
  1213. dprintf(" m_hFileMap2 %x\n",pPageSource->m_hFileMap2);
  1214. dprintf(" m_hFileMapVer %x\n",pPageSource->m_hFileMapVer);
  1215. dprintf(" m_dwFileMapVer %08x\n",pPageSource->m_dwFileMapVer);
  1216. //
  1217. // CObjectHeap
  1218. //
  1219. dprintf(" + CObjectHeap %p\n",Addr+FIELD_OFFSET(CFileCache,m_ObjectHeap));
  1220. CObjectHeap * pObjectHeap_OOP = (CObjectHeap *)(Addr+FIELD_OFFSET(CFileCache,m_ObjectHeap));
  1221. DEFINE_CPP_VAR(CVarObjHeap,varCVarObjHeap);
  1222. CVarObjHeap * pVarObjHeap = GET_CPP_VAR_PTR(CVarObjHeap,varCVarObjHeap);
  1223. CVarObjHeap * pVarObjHeap_OOP = (CVarObjHeap *)((ULONG_PTR)pObjectHeap_OOP+FIELD_OFFSET(CObjectHeap,m_Heap));
  1224. dprintf(" +++ CVarObjHeap %p\n",pVarObjHeap_OOP);
  1225. if (ReadMemory((ULONG_PTR)pVarObjHeap_OOP,pVarObjHeap,sizeof(CVarObjHeap),NULL))
  1226. {
  1227. // this pagefile is the same as CPageSource::m_pObjPF
  1228. VarObjAdminPageEntry ** ppEntries = (VarObjAdminPageEntry **)_alloca(sizeof(VarObjAdminPageEntry *)*pVarObjHeap->m_aAdminPages.m_nSize);
  1229. if (ReadMemory((ULONG_PTR)pVarObjHeap->m_aAdminPages.m_pArray,ppEntries,sizeof(VarObjAdminPageEntry *)*pVarObjHeap->m_aAdminPages.m_nSize,NULL))
  1230. {
  1231. dprintf(" admin pages\n");
  1232. for(DWORD i=0;i<pVarObjHeap->m_aAdminPages.m_nSize;i++)
  1233. {
  1234. //VarObjAdminPageEntry
  1235. //dprintf(" - %x P %p\n",i,ppEntries[i]);
  1236. VarObjAdminPageEntry Entry;
  1237. if (ReadMemory((ULONG_PTR)ppEntries[i],&Entry,sizeof(Entry),NULL))
  1238. {
  1239. dprintf(" %08x %p %d\n",Entry.dwPageId,Entry.pbPage,Entry.bDirty);
  1240. }
  1241. else
  1242. {
  1243. dprintf("RM %p\n",ppEntries[i]);
  1244. }
  1245. }
  1246. }
  1247. else
  1248. {
  1249. dprintf("RM %p\n",pVarObjHeap->m_aAdminPages.m_pArray);
  1250. }
  1251. }
  1252. else
  1253. {
  1254. dprintf("RM %p %d\n",pVarObjHeap_OOP,GetLastError());
  1255. }
  1256. DEFINE_CPP_VAR(CBtrIndex,varCBtrIndex);
  1257. CBtrIndex * pBtrIndex = GET_CPP_VAR_PTR(CBtrIndex,varCBtrIndex);
  1258. CBtrIndex * pBtrIndex_OOP = (CBtrIndex *)((ULONG_PTR)pObjectHeap_OOP+FIELD_OFFSET(CObjectHeap,m_Index));
  1259. dprintf(" +++ CBtrIndex %p\n",pBtrIndex_OOP);
  1260. if (ReadMemory((ULONG_PTR)pBtrIndex_OOP,pBtrIndex,sizeof(CBtrIndex),NULL))
  1261. {
  1262. }
  1263. else
  1264. {
  1265. dprintf("RM %p %d\n",pBtrIndex_OOP,GetLastError());
  1266. }
  1267. }
  1268. else
  1269. {
  1270. dprintf("RM %p %d\n",Addr,GetLastError());
  1271. }
  1272. }
  1273. else
  1274. {
  1275. dprintf("cannot resolve repdrvfs!g_Glob\n");
  1276. }
  1277. }
  1278. DWORD
  1279. Dump_CClassRecord(void * pKey,void * pData)
  1280. {
  1281. //dprintf("Dump_CClassRecord\n");
  1282. DEFINE_CPP_VAR(CClassRecord,MyClassRecord);
  1283. CClassRecord * pClassRecord = GET_CPP_VAR_PTR(CClassRecord,MyClassRecord);
  1284. if (pData)
  1285. {
  1286. ReadMemory((ULONG_PTR)pData,pClassRecord,sizeof(CClassRecord),NULL);
  1287. WCHAR pName[MAX_PATH];
  1288. ReadMemory((ULONG_PTR)pClassRecord->m_wszClassName,pName,MAX_PATH,NULL);
  1289. pName[MAX_PATH-1]=0;
  1290. dprintf(" %p - %S\n",pClassRecord->m_pClassDef,pName);
  1291. }
  1292. return 0;
  1293. }
  1294. DWORD
  1295. Dump_CHierarchyCacheMap(void * pKey,void * pData)
  1296. {
  1297. //dprintf("Dump_CHierarchyCacheMap\n");
  1298. DEFINE_CPP_VAR(CHierarchyCache,MyHierarchyCache);
  1299. CHierarchyCache * pHieCache = GET_CPP_VAR_PTR(CHierarchyCache,MyHierarchyCache);
  1300. if (pKey)
  1301. {
  1302. WCHAR pString[MAX_PATH+1];
  1303. pString[MAX_PATH]=0;
  1304. if (ReadMemory((MEMORY_ADDRESS)pKey,pString,MAX_PATH*sizeof(WCHAR),NULL))
  1305. {
  1306. dprintf(" - %S\n",pString);
  1307. }
  1308. }
  1309. if (pData)
  1310. {
  1311. DWORD Num;
  1312. PrintMapCB((_Map *)((ULONG_PTR)pData+FIELD_OFFSET(CHierarchyCache,m_map)),TRUE,Dump_CClassRecord);
  1313. }
  1314. return 0;
  1315. };
  1316. //
  1317. //
  1318. // dumps the Forest Cache
  1319. //
  1320. //
  1321. DECLARE_API( forestc )
  1322. {
  1323. INIT_API();
  1324. ULONG_PTR Addr = 0;
  1325. if (0 != strlen(args))
  1326. {
  1327. Addr = GetExpression(args);
  1328. }
  1329. else
  1330. {
  1331. Addr = GetExpression("repdrvfs!g_Glob");
  1332. if (Addr)
  1333. {
  1334. Addr += FIELD_OFFSET(CGlobals,m_ForestCache);
  1335. }
  1336. }
  1337. if (Addr)
  1338. {
  1339. CForestCache * pForestCache_OOP = (CForestCache *)Addr;
  1340. if (pForestCache_OOP)
  1341. {
  1342. dprintf("CForestCache @ %p\n",pForestCache_OOP);
  1343. DEFINE_CPP_VAR(CForestCache,varCForestCache);
  1344. CForestCache * pForestCache = GET_CPP_VAR_PTR(CForestCache,varCForestCache);
  1345. ReadMemory((ULONG_PTR)pForestCache_OOP,pForestCache,sizeof(CForestCache),0);
  1346. DWORD Num;
  1347. PrintMapCB((_Map *)((ULONG_PTR)pForestCache_OOP+FIELD_OFFSET(CForestCache,m_map)),TRUE,Dump_CHierarchyCacheMap);
  1348. dprintf(" CClassRecord list\n");
  1349. CClassRecord * pCRec = pForestCache->m_pMostRecentlyUsed;
  1350. Num = 0;
  1351. while(pCRec)
  1352. {
  1353. DEFINE_CPP_VAR(CClassRecord,CRec);
  1354. ReadMemory((ULONG_PTR)pCRec,&CRec,sizeof(CClassRecord),0);
  1355. pCRec = ((CClassRecord *)&CRec)->m_pLessRecentlyUsed;
  1356. dprintf(" %d - %p\n",Num,pCRec);
  1357. Num++;
  1358. if (CheckControlC())
  1359. break;
  1360. };
  1361. dprintf(" T %d CClassRecord\n",Num);
  1362. }
  1363. } else {
  1364. dprintf(" unable to resolve repdrvfs!g_Glob\n");
  1365. }
  1366. }