Windows NT 4.0 source code leak
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.

1089 lines
23 KiB

4 years ago
  1. /***********************************************************************
  2. * Microsoft (R) 32-Bit Incremental Linker
  3. *
  4. * Copyright (C) Microsoft Corp 1992-95. All rights reserved.
  5. *
  6. * File: dbinsp.cpp
  7. *
  8. * File Comments:
  9. *
  10. * Inspects & dumps incremental database files.
  11. *
  12. ***********************************************************************/
  13. #include "link.h"
  14. #if DBG
  15. // macros
  16. #define FileWarning(file, str) printf("%s : %s\n", file, str)
  17. // statics
  18. static PIMAGE pimage;
  19. static void *pvIncr;
  20. static INT FileHandle;
  21. static DWORD FileLen;
  22. static char *SzDbFile;
  23. static BOOL fSymbols;
  24. static BOOL fHashTable;
  25. static BOOL fSectionMap;
  26. static BOOL fLibMap;
  27. static BOOL fHeaders;
  28. // function prototypes
  29. extern void IncrInitImage(PPIMAGE);
  30. void ProcessDbInspSwitches(void);
  31. void DbInsp(PARGUMENT_LIST);
  32. BOOL FVerifyAndDumpHeader(const char *);
  33. BOOL FReadInFile(void);
  34. void DumpIncrDb(const char *);
  35. BOOL DumpIncrImageHeaders(PIMAGE, const char *);
  36. void DumpIncrImgFileHdr(PIMAGE_FILE_HEADER);
  37. void DumpIncrImgOptHdr(PIMAGE_OPTIONAL_HEADER);
  38. void DumpIncrPGRP(PGRP);
  39. void DumpIncrPSEC(PSEC);
  40. void DumpIncrPLIB(PLIB);
  41. void DumpIncrPMOD(PMOD);
  42. void DumpIncrPCON(PCON);
  43. void DumpIncrSectionMap(PSECS, const char *);
  44. void DumpIncrLibMap(PLIB, const char *);
  45. void DumpIncrHashTable(PHT, void *);
  46. void DumpIncrSymbolTable(PST);
  47. // functions
  48. void
  49. DbInspUsage(void)
  50. {
  51. if (fNeedBanner) {
  52. PrintBanner();
  53. }
  54. puts("usage: DBINSP [options] [files]\n\n"
  55. " options:\n\n"
  56. " /ALL\n"
  57. " /HASH\n"
  58. " /HEADERS\n"
  59. " /LIBMAP\n"
  60. " /NOLOGO\n"
  61. " /OUT:filename\n"
  62. " /SECMAP\n"
  63. " /SYMBOLS");
  64. fflush(stdout);
  65. exit(USAGE);
  66. }
  67. MainFunc DbInspMain(int Argc, char *Argv[])
  68. /*++
  69. Routine Description:
  70. Dumps an incremental database in human readable form.
  71. Arguments:
  72. Argc - Standard C argument count.
  73. Argv - Standard C argument strings.
  74. Return Value:
  75. 0 Dump was successful.
  76. !0 Dumper error index.
  77. --*/
  78. {
  79. WORD i;
  80. PARGUMENT_LIST parg;
  81. if (Argc < 2) {
  82. DbInspUsage();
  83. }
  84. ParseCommandLine(Argc, Argv, NULL);
  85. ProcessDbInspSwitches();
  86. if (fNeedBanner) {
  87. PrintBanner();
  88. }
  89. for(i = 0, parg = ObjectFilenameArguments.First;
  90. i < ObjectFilenameArguments.Count;
  91. i++, parg = parg->Next) {
  92. DbInsp(parg);
  93. }
  94. FileCloseAll();
  95. fclose(InfoStream);
  96. return (0);
  97. }
  98. void
  99. ProcessDbInspSwitches (
  100. void
  101. )
  102. /*++
  103. Routine Description:
  104. Process incr db inspector switches.
  105. Arguments:
  106. None.
  107. Return Value:
  108. None.
  109. --*/
  110. {
  111. PARGUMENT_LIST parg;
  112. WORD i;
  113. for (i=0,parg=SwitchArguments.First;
  114. i<SwitchArguments.Count;
  115. parg=parg->Next, i++) {
  116. if (!strcmp(parg->OriginalName, "?")) {
  117. DbInspUsage();
  118. assert(FALSE); // doesn't return
  119. }
  120. if (!_strnicmp(parg->OriginalName, "out:", 4)) {
  121. if (*(parg->OriginalName+4)) {
  122. szInfoFilename = parg->OriginalName+4;
  123. if (!(InfoStream = fopen(szInfoFilename, "wt"))) {
  124. Fatal(NULL, CANTOPENFILE, szInfoFilename);
  125. }
  126. }
  127. continue;
  128. }
  129. if (!_stricmp(parg->OriginalName, "nologo")) {
  130. fNeedBanner = FALSE;
  131. continue;
  132. }
  133. if (!_stricmp(parg->OriginalName, "symbols")) {
  134. fSymbols = TRUE;
  135. continue;
  136. }
  137. if (!_stricmp(parg->OriginalName, "all")) {
  138. fSymbols = TRUE;
  139. fHashTable = TRUE;
  140. fSectionMap = TRUE;
  141. fLibMap = TRUE;
  142. fHeaders = TRUE;
  143. continue;
  144. }
  145. if (!_stricmp(parg->OriginalName, "hash")) {
  146. fHashTable = TRUE;
  147. continue;
  148. }
  149. if (!_stricmp(parg->OriginalName, "secmap")) {
  150. fSectionMap = TRUE;
  151. continue;
  152. }
  153. if (!_stricmp(parg->OriginalName, "libmap")) {
  154. fLibMap = TRUE;
  155. continue;
  156. }
  157. if (!_stricmp(parg->OriginalName, "headers")) {
  158. fHeaders = TRUE;
  159. continue;
  160. }
  161. Warning(NULL, WARN_UNKNOWN_SWITCH, parg->OriginalName);
  162. } // end for
  163. }
  164. void
  165. DbInsp (
  166. PARGUMENT_LIST parg
  167. )
  168. /*++
  169. Routine Description:
  170. Verifies and dumps contents of incremental database.
  171. Arguments:
  172. parg - ptr to argument.
  173. Return Value:
  174. None.
  175. --*/
  176. {
  177. fprintf(InfoStream, "\nInspecting file %s\n", parg->OriginalName);
  178. // Set the incr db filename
  179. szIncrDbFilename = parg->OriginalName;
  180. // Peek at the header
  181. if (!FVerifyAndDumpHeader(parg->OriginalName)) {
  182. return;
  183. }
  184. // Read in the entire file
  185. if (!FReadInFile()) {
  186. return;
  187. }
  188. // verify symbol table (ptrs are valid only after reading it in the entire image)
  189. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD) FileLen, (DWORD) pimage->pst->blkStringTable.pb, pimage->pst->blkStringTable.cb)) {
  190. FileWarning(parg->OriginalName, "invalid pointer to string table");
  191. return;
  192. }
  193. if (Align(sizeof(DWORD), ((DWORD) pimage->pst->blkStringTable.pb + pimage->pst->blkStringTable.cb - (DWORD) pvIncr))
  194. != FileLen) {
  195. FileWarning(parg->OriginalName, "garbage beyond string table");
  196. return;
  197. }
  198. // Dump the rest of the stuff
  199. DumpIncrDb(parg->OriginalName);
  200. // Close the incr db file
  201. FileClose(FileIncrDbHandle, TRUE);
  202. }
  203. BOOL
  204. FVerifyAndDumpHeader (
  205. const char *szFile
  206. )
  207. /*++
  208. Routine Description:
  209. Reads in just the header and verifies it & dumps interesting info.
  210. Arguments:
  211. szFile - name of the incr db file.
  212. Return Value:
  213. None.
  214. --*/
  215. {
  216. struct _stat statfile;
  217. IMAGE image;
  218. // stat the file
  219. if (_stat(szFile, &statfile) == -1) {
  220. Fatal(NULL, CANTOPENFILE, szFile);
  221. }
  222. FileLen = statfile.st_size;
  223. if (FileLen < sizeof(IMAGE)) {
  224. FileWarning(szFile, "file too small to be incr db");
  225. return(FALSE);
  226. }
  227. FileHandle = FileOpen(szFile, O_RDONLY | O_BINARY, 0);
  228. FileRead(FileHandle, &image, sizeof(IMAGE));
  229. FileClose(FileHandle, TRUE);
  230. // verify the incr db signature
  231. if (strcmp(image.Sig, INCDB_SIGNATURE)) {
  232. FileWarning(szFile, "invalid incr db signature found");
  233. return(FALSE);
  234. }
  235. // verify the version numbers
  236. if (image.MajVersNum != INCDB_MAJVERSNUM) {
  237. FileWarning(szFile, "invalid version number found");
  238. return(FALSE);
  239. }
  240. pvIncr = image.pvBase;
  241. if (!DumpIncrImageHeaders(&image, szFile)) {
  242. return(FALSE);
  243. }
  244. return(TRUE);
  245. }
  246. BOOL FReadInFile(void)
  247. /*++
  248. Routine Description:
  249. Reads in file onto private heap.
  250. Arguments:
  251. szFile - name of file.
  252. Return Value:
  253. None.
  254. --*/
  255. {
  256. DWORD dwErr = 0;
  257. // create a private heap to load the image
  258. if (CreateHeap(pvIncr, FileLen, FALSE, &dwErr) != pvIncr) {
  259. puts("failed to map ILK file");
  260. return(FALSE);
  261. }
  262. pimage = (PIMAGE) pvIncr;
  263. IncrInitImage(&pimage);
  264. return(TRUE);
  265. }
  266. BOOL
  267. DumpIncrImageHeaders (
  268. PIMAGE pimg,
  269. const char *szFile
  270. )
  271. /*++
  272. Routine Description:
  273. Dumps out the various headers.
  274. Arguments:
  275. pimg - pointer to IMAGE struct
  276. szFile - name of file for error reporting
  277. Return Value:
  278. TRUE if everything is valid.
  279. --*/
  280. {
  281. BYTE Sig[32];
  282. BOOL fValid = TRUE;
  283. fprintf(InfoStream, "\nIMAGE HEADER VALUES\n");
  284. strcpy((char *) Sig, pimg->Sig);
  285. Sig[26]='\0';
  286. fprintf(InfoStream, " Signature: %s", Sig);
  287. fprintf(InfoStream, " MajVersNum: 0x%.4x\n", pimg->MajVersNum);
  288. fprintf(InfoStream, " MinVersNum: 0x%.4x\n", pimg->MinVersNum);
  289. fprintf(InfoStream, " Heap Base: 0x%.8lx\n",pvIncr);
  290. fprintf(InfoStream, " secs.psecHead: 0x%.8lx\n", pimg->secs.psecHead);
  291. fprintf(InfoStream, " libs.plibHead: 0x%.8lx\n", pimg->libs.plibHead);
  292. fprintf(InfoStream, " libs.fNoDefaultLibs: %c\n", pimg->libs.fNoDefaultLibs ? '1':'0');
  293. fprintf(InfoStream, " plibCmdLineObjs: 0x%.8lx\n",pimg->plibCmdLineObjs);
  294. fprintf(InfoStream, " pst: 0x%.8lx\n",pimg->pst);
  295. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)pimg->secs.psecHead, 0)) {
  296. FileWarning(szFile, "invalid pointer to section list");
  297. fValid = FALSE;
  298. }
  299. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)pimg->libs.plibHead, 0)) {
  300. FileWarning(szFile, "invalid pointer to lib list");
  301. fValid = FALSE;
  302. }
  303. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)pimg->plibCmdLineObjs, 0)) {
  304. FileWarning(szFile, "invalid pointer to cmdline objs lib");
  305. fValid = FALSE;
  306. }
  307. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)pimg->pst, 0)) {
  308. FileWarning(szFile, "invalid pointer to symbol table");
  309. fValid = FALSE;
  310. }
  311. DumpIncrImgFileHdr(&pimg->ImgFileHdr);
  312. DumpIncrImgOptHdr(&pimg->ImgOptHdr);
  313. return(fValid);
  314. }
  315. void
  316. DumpIncrImgFileHdr (
  317. PIMAGE_FILE_HEADER pImgFileHdr
  318. )
  319. /*++
  320. Routine Description:
  321. Dumps out the IMAGE_FILE_HEADER.
  322. Arguments:
  323. pImgFileHdr - pointer to IMAGE_FILE_HEADER struct
  324. Return Value:
  325. None.
  326. --*/
  327. {
  328. if (!fHeaders) {
  329. return;
  330. }
  331. fprintf(InfoStream, "\nIMAGE FILE HEADER VALUES\n");
  332. fprintf(InfoStream, " Machine: 0x%.4x\n", pImgFileHdr->Machine);
  333. fprintf(InfoStream, " NumOfSec: 0x%.4x\n", pImgFileHdr->NumberOfSections);
  334. fprintf(InfoStream, " TimeStamp: %s", ctime((time_t *)&pImgFileHdr->TimeDateStamp));
  335. fprintf(InfoStream, " PtrToSymTbl: 0x%.8lx\n", pImgFileHdr->PointerToSymbolTable);
  336. fprintf(InfoStream, " NumOfSyms: 0x%.8lx\n", pImgFileHdr->NumberOfSymbols);
  337. fprintf(InfoStream, " SizeOfOptHdr: 0x%.4x\n", pImgFileHdr->SizeOfOptionalHeader);
  338. fprintf(InfoStream, " Character.: 0x%.4x\n", pImgFileHdr->Characteristics);
  339. }
  340. static const char * const SubsystemName[] = {
  341. "Unknown",
  342. "Native",
  343. "Windows GUI",
  344. "Windows CUI",
  345. "Posix CUI",
  346. "MMOSA",
  347. };
  348. static const char * const DirectoryEntryName[] = {
  349. "Export",
  350. "Import",
  351. "Resource",
  352. "Exception",
  353. "Security",
  354. "Base Relocation",
  355. "Debug",
  356. "Description",
  357. "Special",
  358. "Thread Storage",
  359. NULL
  360. };
  361. void
  362. DumpIncrImgOptHdr (
  363. PIMAGE_OPTIONAL_HEADER pImgOptHdr
  364. )
  365. /*++
  366. Routine Description:
  367. Dumps out the IMAGE_OPTIONAL_HEADER. Code taken from dump.c yikes!
  368. Arguments:
  369. pImgFileHdr - pointer to IMAGE_OPTIONAL_HEADER struct
  370. Return Value:
  371. None.
  372. --*/
  373. {
  374. WORD i, j;
  375. char version[30];
  376. if (!fHeaders) {
  377. return;
  378. }
  379. fprintf(InfoStream, "\nIMAGE OPTIONAL FILE HEADER VALUES\n");
  380. fprintf(InfoStream, "% 8hX magic #\n", pImgOptHdr->Magic);
  381. j = (WORD) sprintf(version, "%d.%d", pImgOptHdr->MajorLinkerVersion, pImgOptHdr->MinorLinkerVersion);
  382. if (j > 8) {
  383. j = 8;
  384. }
  385. for (j = (WORD) (8-j); j; j--) {
  386. fputc(' ', InfoStream);
  387. }
  388. fprintf(InfoStream, "%s linker version\n% 8lX size of code\n% 8lX size of initialized data\n% 8lX size of uninitialized data\n% 8lX address of entry point\n% 8lX base of code\n% 8lX base of data\n",
  389. version,
  390. pImgOptHdr->SizeOfCode,
  391. pImgOptHdr->SizeOfInitializedData,
  392. pImgOptHdr->SizeOfUninitializedData,
  393. pImgOptHdr->AddressOfEntryPoint,
  394. pImgOptHdr->BaseOfCode,
  395. pImgOptHdr->BaseOfData);
  396. switch (pImgOptHdr->Subsystem) {
  397. case IMAGE_SUBSYSTEM_MMOSA : i = 5; break;
  398. case IMAGE_SUBSYSTEM_POSIX_CUI : i = 4; break;
  399. case IMAGE_SUBSYSTEM_WINDOWS_CUI : i = 3; break;
  400. case IMAGE_SUBSYSTEM_WINDOWS_GUI : i = 2; break;
  401. case IMAGE_SUBSYSTEM_NATIVE : i = 1; break;
  402. default : i = 0;
  403. }
  404. fprintf(InfoStream, " ----- new -----\n% 8lX image base\n% 8lX section alignment\n% 8lX file alignment\n% 8hX subsystem (%s)\n",
  405. pImgOptHdr->ImageBase,
  406. pImgOptHdr->SectionAlignment,
  407. pImgOptHdr->FileAlignment,
  408. pImgOptHdr->Subsystem,
  409. SubsystemName[i]);
  410. j = (WORD) sprintf(version, "%hX.%hX", pImgOptHdr->MajorOperatingSystemVersion, pImgOptHdr->MinorOperatingSystemVersion);
  411. if (j > 8) {
  412. j = 8;
  413. }
  414. for (j = (WORD) (8-j); j; j--) {
  415. fputc(' ', InfoStream);
  416. }
  417. fprintf(InfoStream, "%s operating system version\n", version);
  418. j = (WORD) sprintf(version, "%hX.%hX", pImgOptHdr->MajorImageVersion, pImgOptHdr->MinorImageVersion);
  419. if (j > 8) {
  420. j = 8;
  421. }
  422. for (j = (WORD) (8-j); j; j--) {
  423. fputc(' ', InfoStream);
  424. }
  425. fprintf(InfoStream, "%s image version\n", version);
  426. j = (WORD) sprintf(version, "%hX.%hX", pImgOptHdr->MajorSubsystemVersion, pImgOptHdr->MinorSubsystemVersion);
  427. if (j > 8) {
  428. j = 8;
  429. }
  430. for (j = (WORD) (8-j); j; j--) {
  431. fputc(' ', InfoStream);
  432. }
  433. fprintf(InfoStream, "%s subsystem version\n% 8lX size of image\n% 8lX size of headers\n% 8lX checksum\n",
  434. version,
  435. pImgOptHdr->SizeOfImage,
  436. pImgOptHdr->SizeOfHeaders,
  437. pImgOptHdr->CheckSum);
  438. fprintf(InfoStream, "% 8lX size of stack reserve\n% 8lX size of stack commit\n% 8lX size of heap reserve\n% 8lX size of heap commit\n%",
  439. pImgOptHdr->SizeOfStackReserve,
  440. pImgOptHdr->SizeOfStackCommit,
  441. pImgOptHdr->SizeOfHeapReserve,
  442. pImgOptHdr->SizeOfHeapCommit);
  443. for (i=0; i<IMAGE_NUMBEROF_DIRECTORY_ENTRIES; i++) {
  444. if (!DirectoryEntryName[i]) {
  445. break;
  446. }
  447. fprintf(InfoStream, "% 8lX [% 8lx] address [size] of %s Directory\n%",
  448. pImgOptHdr->DataDirectory[i].VirtualAddress,
  449. pImgOptHdr->DataDirectory[i].Size,
  450. DirectoryEntryName[i]
  451. );
  452. }
  453. fputc('\n', InfoStream);
  454. }
  455. void
  456. DumpIncrDb (
  457. const char *szFile
  458. )
  459. /*++
  460. Routine Description:
  461. Dumps the contents of the incr db file.
  462. Arguments:
  463. szFile - name of the file to dump.
  464. Return Value:
  465. None.
  466. --*/
  467. {
  468. DumpIncrSymbolTable(pimage->pst);
  469. DumpIncrHashTable(pimage->pst->pht, &pimage->pst->blkStringTable);
  470. DumpIncrSectionMap(&pimage->secs, szFile);
  471. DumpIncrLibMap(pimage->libs.plibHead, szFile);
  472. }
  473. void
  474. DumpIncrSectionMap(
  475. PSECS psecs,
  476. const char *szFile
  477. )
  478. /*++
  479. Routine Description:
  480. Dump the image map.
  481. Arguments:
  482. None.
  483. Return Value:
  484. None.
  485. --*/
  486. {
  487. ENM_SEC enm_sec;
  488. ENM_GRP enm_grp;
  489. ENM_DST enm_dst;
  490. CHAR buf[128];
  491. if (!fSectionMap) {
  492. return;
  493. }
  494. fprintf(InfoStream, "\nSECTION MAP DUMP\n");
  495. InitEnmSec(&enm_sec, psecs);
  496. while (FNextEnmSec(&enm_sec)) {
  497. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_sec.psec, sizeof(SEC))) {
  498. sprintf(buf, "invalid ptr to SEC 0x%lx found\n",enm_sec.psec);
  499. FileWarning(szFile, buf);
  500. goto InvalidSectionMap;
  501. }
  502. DumpIncrPSEC(enm_sec.psec);
  503. InitEnmGrp(&enm_grp, enm_sec.psec);
  504. while (FNextEnmGrp(&enm_grp)) {
  505. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_grp.pgrp, sizeof(GRP))) {
  506. sprintf(buf, "invalid ptr to GRP 0x%lx found\n",enm_grp.pgrp);
  507. FileWarning(szFile, buf);
  508. goto InvalidSectionMap;
  509. }
  510. DumpIncrPGRP(enm_grp.pgrp);
  511. InitEnmDst(&enm_dst, enm_grp.pgrp);
  512. while (FNextEnmDst(&enm_dst)) {
  513. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_dst.pcon, sizeof(CON))) {
  514. sprintf(buf, "invalid ptr to CON 0x%lx found\n",enm_dst.pcon);
  515. FileWarning(szFile, buf);
  516. goto InvalidSectionMap;
  517. }
  518. DumpIncrPCON(enm_dst.pcon);
  519. }
  520. }
  521. }
  522. InvalidSectionMap:
  523. fprintf(InfoStream, "\n");
  524. }
  525. void
  526. DumpIncrLibMap(
  527. PLIB plibHead,
  528. const char *szFile
  529. )
  530. /*++
  531. Routine Description:
  532. Dump the driver map.
  533. Arguments:
  534. None.
  535. Return Value:
  536. None.
  537. --*/
  538. {
  539. ENM_LIB enm_lib;
  540. ENM_MOD enm_mod;
  541. ENM_SRC enm_src;
  542. CHAR buf[128];
  543. if (!fLibMap) {
  544. return;
  545. }
  546. fprintf(InfoStream, "\nLIBRARY MAP OF IMAGE\n");
  547. InitEnmLib(&enm_lib, plibHead);
  548. while (FNextEnmLib(&enm_lib)) {
  549. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_lib.plib, sizeof(LIB))) {
  550. sprintf(buf, "invalid ptr to LIB 0x%lx found\n",enm_lib.plib);
  551. FileWarning(szFile, buf);
  552. goto InvalidLibMap;
  553. }
  554. DumpIncrPLIB(enm_lib.plib);
  555. InitEnmMod(&enm_mod, enm_lib.plib);
  556. while (FNextEnmMod(&enm_mod)) {
  557. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_mod.pmod, sizeof(MOD))) {
  558. sprintf(buf, "invalid ptr to MOD 0x%lx found\n",enm_mod.pmod);
  559. FileWarning(szFile, buf);
  560. goto InvalidLibMap;
  561. }
  562. DumpIncrPMOD(enm_mod.pmod);
  563. InitEnmSrc(&enm_src, enm_mod.pmod);
  564. while (FNextEnmSrc(&enm_src)) {
  565. if (!FValidPtrInfo((DWORD) pvIncr, (DWORD)FileLen, (DWORD)enm_src.pcon, sizeof(CON))) {
  566. sprintf(buf, "invalid ptr to CON 0x%lx found\n",enm_src.pcon);
  567. FileWarning(szFile, buf);
  568. goto InvalidLibMap;
  569. }
  570. DumpIncrPCON(enm_src.pcon);
  571. }
  572. }
  573. }
  574. InvalidLibMap:
  575. fprintf(InfoStream, "\n");
  576. }
  577. void
  578. DumpIncrPSEC(
  579. PSEC psec)
  580. /*++
  581. Routine Description:
  582. Dump an image section.
  583. Arguments:
  584. psec - section to dump.
  585. Return Value:
  586. None.
  587. --*/
  588. {
  589. assert(psec);
  590. fprintf(InfoStream, "\n==========\n");
  591. fprintf(InfoStream, "section=%.8s, isec=%.4x\n", psec->szName, psec->isec);
  592. fprintf(InfoStream, "rva= %.8lX ", psec->rva);
  593. fprintf(InfoStream, "foPad= %.8lx ", psec->foPad);
  594. fprintf(InfoStream, "cbRawData= %.8lx ", psec->cbRawData);
  595. fprintf(InfoStream, "foRawData= %.8lx\n", psec->foRawData);
  596. fprintf(InfoStream, "foLinenum= %.8lx ", psec->foLinenum);
  597. fprintf(InfoStream, "flags= %.8lx ", psec->flags);
  598. fprintf(InfoStream, "cLinenum= %.4x\n", psec->cLinenum);
  599. fflush(InfoStream);
  600. }
  601. void
  602. DumpIncrPGRP(
  603. PGRP pgrp)
  604. /*++
  605. Routine Description:
  606. Dump an image group.
  607. Arguments:
  608. pgrp - group to dump.
  609. Return Value:
  610. None.
  611. --*/
  612. {
  613. fprintf(InfoStream, "\n----------\n");
  614. fprintf(InfoStream, "\n group=%s\n", pgrp->szName);
  615. fflush(InfoStream);
  616. }
  617. void
  618. DumpIncrPLIB(
  619. PLIB plib)
  620. /*++
  621. Routine Description:
  622. Dump a library.
  623. Arguments:
  624. plib - library to dump.
  625. Return Value:
  626. None.
  627. --*/
  628. {
  629. fprintf(InfoStream, "\n==========\n");
  630. fprintf(InfoStream, "library=%s\n", plib->szName);
  631. fprintf(InfoStream, "foIntMemST=%.8lx ", plib->foIntMemSymTab);
  632. fprintf(InfoStream, "csymIntMem=%.8lx ", plib->csymIntMem);
  633. fprintf(InfoStream, "flags= %.8lx\n", plib->flags);
  634. fprintf(InfoStream, "TimeStamp= %s", ctime((time_t *)&plib->TimeStamp));
  635. fflush(InfoStream);
  636. }
  637. void
  638. DumpIncrPMOD(
  639. PMOD pmod)
  640. /*++
  641. Routine Description:
  642. Dump a module.
  643. Arguments:
  644. pmod - module to dump.
  645. Return Value:
  646. None.
  647. --*/
  648. {
  649. fprintf(InfoStream, "\n----------\n");
  650. fprintf(InfoStream, " module=%s, ", SzOrigFilePMOD(pmod));
  651. if (FIsLibPMOD(pmod)) {
  652. fprintf(InfoStream, "foMember=%.8lx\n", pmod->foMember);
  653. } else {
  654. fprintf(InfoStream, "szNameMod=%s\n", pmod->szNameMod);
  655. }
  656. fprintf(InfoStream, "foSymTable=%.8lx ", pmod->foSymbolTable);
  657. fprintf(InfoStream, "csymbols= %.8lx ", pmod->csymbols);
  658. fprintf(InfoStream, "cbOptHdr= %.8lx\n", pmod->cbOptHdr);
  659. fprintf(InfoStream, "flags= %.8lx ", pmod->flags);
  660. fprintf(InfoStream, "ccon= %.8lx ", pmod->ccon);
  661. fprintf(InfoStream, "icon= %.8lx ", pmod->icon);
  662. fprintf(InfoStream, "TimeStamp= (%.8lx) %s", pmod->TimeStamp, ctime((time_t *)&pmod->TimeStamp));
  663. fprintf(InfoStream, "cbFile= %.8lx ", pmod->cbFile);
  664. fprintf(InfoStream, "HdrTime= %.8lx\n", pmod->HdrTimeStamp);
  665. fflush(InfoStream);
  666. }
  667. void
  668. DumpIncrPCON(
  669. PCON pcon)
  670. /*++
  671. Routine Description:
  672. Dump a contribution.
  673. Arguments:
  674. pcon - contribution to dump.
  675. Return Value:
  676. None.
  677. --*/
  678. {
  679. fprintf(InfoStream, "\n contributor: flags=%.8lx, rva=%.8lx, module=%s\n",
  680. pcon->flags, pcon->rva, SzObjNamePCON(pcon));
  681. fprintf(InfoStream, "cbRawData= %.8lx ", pcon->cbRawData);
  682. fprintf(InfoStream, "foRawDataD=%.8lx ", pcon->foRawDataDest);
  683. fprintf(InfoStream, "chksum =%.8lx ", pcon->chksumComdat);
  684. fprintf(InfoStream, "selComdat= %.4x\n", pcon->selComdat);
  685. fprintf(InfoStream, "cbPad = %.4x\n", pcon->cbPad);
  686. fflush(InfoStream);
  687. }
  688. void
  689. DumpIncrHashTable(
  690. PHT pht,
  691. void *pvBlk)
  692. /*++
  693. Routine Description:
  694. Dump a hash table.
  695. Arguments:
  696. pht - hast table
  697. pvBlk - ptr to string table
  698. Return Value:
  699. None.
  700. --*/
  701. {
  702. PELEMENT pelement;
  703. DWORD ibucket;
  704. assert(pht);
  705. if (!fHashTable) {
  706. return;
  707. }
  708. fprintf(InfoStream, "\nHASH TABLE DUMP\n");
  709. for (ibucket = 0; ibucket < pht->cbuckets; ibucket++) {
  710. assert(ibucket / pht->celementInChunk < pht->cchunkInDir);
  711. pelement = pht->rgpchunk[ibucket / pht->celementInChunk]->
  712. rgpelement[ibucket % pht->celementInChunk];
  713. fprintf(InfoStream, "bucket = %u\n", ibucket);
  714. while (pelement) {
  715. fprintf(InfoStream, " %s\n", pht->SzFromPv(pelement->pv, pvBlk));
  716. pelement = pelement->pelementNext;
  717. }
  718. }
  719. fprintf(InfoStream, "\n");
  720. }
  721. void
  722. DumpIncrSymbolTable (
  723. PST pst
  724. )
  725. /*++
  726. Routine Description:
  727. Dump the symbol table.
  728. Arguments:
  729. pst - symbol table
  730. Return Value:
  731. None.
  732. --*/
  733. {
  734. PPEXTERNAL rgpexternal;
  735. DWORD cexternal;
  736. DWORD i;
  737. if (!fSymbols) {
  738. return;
  739. }
  740. fprintf(InfoStream, "\nSYMBOL TABLE DUMP\n");
  741. // put them out sorted by name
  742. rgpexternal = RgpexternalByName(pst);
  743. cexternal = Cexternal(pst);
  744. for (i = 0; i < cexternal; i++) {
  745. PEXTERNAL pext;
  746. char *szSym;
  747. const char *szType;
  748. pext = rgpexternal[i];
  749. szSym = SzOutputSymbolName(SzNamePext(pext, pst), TRUE);
  750. if (!pext->pcon || (pext->Flags & EXTERN_IGNORE)) {
  751. fprintf(InfoStream, "%s off=%.8lx flags=%.8lx %s name=%s\n",
  752. pext->Offset ? "THUNK" : " ",
  753. pext->Offset,
  754. pext->Flags,
  755. "IGNR",
  756. szSym);
  757. continue;
  758. }
  759. if (pext->pcon && !FIsLibPCON(pext->pcon)) {
  760. if (ISFCN(pext->ImageSymbol.Type)) {
  761. szType = "FUNC";
  762. } else {
  763. szType = "DATA";
  764. }
  765. } else {
  766. szType = " ";
  767. }
  768. fprintf(InfoStream, "%s off=%.8lx flags=%.8lx %s name=%s\n",
  769. pext->Offset ? "THUNK" : " ",
  770. pext->Offset,
  771. pext->Flags,
  772. szType,
  773. szSym);
  774. if (szSym != SzNamePext(pext, pst)) {
  775. free(szSym);
  776. }
  777. }
  778. }
  779. #endif // DBG