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.

555 lines
17 KiB

  1. //---------------------------------------------------------------------------
  2. // FileDump.cpp - Writes the contents of a theme file as formatted
  3. // text to a text file. Used for uxbud and other testing so
  4. // its in both FRE and DEBUG builds.
  5. //---------------------------------------------------------------------------
  6. #include "stdafx.h"
  7. #include "Loader.h"
  8. #include "Loader.h"
  9. #include "borderfill.h"
  10. #include "imagefile.h"
  11. #include "textdraw.h"
  12. #include "tmutils.h"
  13. //---------------------------------------------------------------------------
  14. int DumpType(CSimpleFile *pFile, CUxThemeFile *pThemeFile, MIXEDPTRS &u,
  15. BOOL fPacked, BOOL fFullInfo)
  16. {
  17. BOOL fPropDump = (! fPacked);
  18. UNPACKED_ENTRYHDR hdr;
  19. FillAndSkipHdr(u, &hdr);
  20. BYTE *origPd = u.pb;
  21. int i;
  22. if (fPropDump)
  23. {
  24. if (hdr.ePrimVal == TMT_DIBDATA && !fFullInfo)
  25. {
  26. pFile->OutLine(L" type=%d, primType=%d", hdr.usTypeNum, hdr.ePrimVal);
  27. }
  28. else
  29. {
  30. pFile->OutLine(L" type=%d, primType=%d, len=%d",
  31. hdr.usTypeNum, hdr.ePrimVal, hdr.dwDataLen);
  32. }
  33. }
  34. switch (hdr.ePrimVal)
  35. {
  36. case TMT_JUMPTOPARENT:
  37. if (fPropDump)
  38. {
  39. if (fFullInfo)
  40. pFile->OutLine(L" JumpToParent: index=%d", *u.pi);
  41. else
  42. pFile->OutLine(L" JumpToParent");
  43. }
  44. break;
  45. case TMT_PARTJUMPTABLE:
  46. return hdr.ePrimVal; // let caller process data for this
  47. case TMT_STATEJUMPTABLE:
  48. return hdr.ePrimVal; // let caller process data for this
  49. case TMT_STRING:
  50. if (fPropDump)
  51. pFile->OutLine(L" String: %s", u.pc);
  52. break;
  53. case TMT_INT:
  54. if (fPropDump)
  55. pFile->OutLine(L" Int: %d", *u.pi);
  56. break;
  57. case TMT_BOOL:
  58. if (fPropDump)
  59. pFile->OutLine(L" Bool: %d", *u.pb);
  60. break;
  61. case TMT_COLOR:
  62. if (fPropDump)
  63. {
  64. int color;
  65. color = *u.pi;
  66. pFile->OutLine(L" Color: %d, %d, %d", color & 0xff, (color >> 8) & 0xff,
  67. (color >> 16) & 0xff);
  68. }
  69. break;
  70. case TMT_MARGINS:
  71. if (fPropDump)
  72. {
  73. int vals[4];
  74. for (i=0; i < 4; i++)
  75. vals[i] = *u.pi++;
  76. pFile->OutLine(L" Margins: lw=%d, rw=%d, th=%d, bh=%d", vals[0],
  77. vals[1], vals[2], vals[3]);
  78. }
  79. break;
  80. case TMT_FILENAME:
  81. if (fPropDump)
  82. pFile->OutLine(L" Filename: %s", u.pw);
  83. break;
  84. case TMT_SIZE:
  85. if (fPropDump)
  86. pFile->OutLine(L" Size: %d", *u.pi);
  87. break;
  88. case TMT_POSITION:
  89. if (fPropDump)
  90. {
  91. int val1, val2;
  92. val1 = *u.pi++;
  93. val2 = *u.pi++;
  94. pFile->OutLine(L" Position: x=%d, y=%d", val1, val2);
  95. }
  96. break;
  97. case TMT_RECT:
  98. if (fPropDump)
  99. {
  100. int vals[4];
  101. for (i=0; i < 4; i++)
  102. vals[i] = *u.pi++;
  103. pFile->OutLine(L" Rect: left=%d, top=%d, width=%d, height=%d", vals[0],
  104. vals[1], vals[2], vals[3]);
  105. }
  106. break;
  107. case TMT_FONT:
  108. if (fPropDump)
  109. {
  110. LOGFONT *plf;
  111. plf = (LOGFONT *)u.pb;
  112. //---- dump resolution-independent font points ----
  113. int iFontPoints = FontPointSize(plf->lfHeight);
  114. pFile->OutLine(L" Font: name=%s, size=%d points", plf->lfFaceName, iFontPoints);
  115. }
  116. break;
  117. case TMT_THEMEMETRICS:
  118. if (fPropDump)
  119. {
  120. THEMEMETRICS *ptm;
  121. ptm= (THEMEMETRICS *)u.pb;
  122. //---- dump theme metrics: fonts ----
  123. for (i=0; i < TM_FONTCOUNT; i++)
  124. {
  125. //---- dump resolution-independent font points ----
  126. int iFontPoints = FontPointSize(ptm->lfFonts[i].lfHeight);
  127. pFile->OutLine(L" TM_Font[%d]: name=%s, size=%d points",
  128. i, ptm->lfFonts[i].lfFaceName, iFontPoints);
  129. }
  130. pFile->OutLine(L" -----------------------------------------");
  131. //---- dump theme metrics: colors ----
  132. for (i=0; i < TM_COLORCOUNT; i++)
  133. {
  134. pFile->OutLine(L" TM_Color[%d]: %d, %d, %d",
  135. i, RED(ptm->crColors[i]), GREEN(ptm->crColors[i]), BLUE(ptm->crColors[i]));
  136. }
  137. pFile->OutLine(L" -----------------------------------------");
  138. //---- dump theme metrics: sizes ----
  139. for (i=0; i < TM_SIZECOUNT; i++)
  140. {
  141. pFile->OutLine(L" TM_Size[%d]: %d",
  142. i, ptm->iSizes[i]);
  143. }
  144. pFile->OutLine(L" -----------------------------------------");
  145. //---- dump theme metrics: bools ----
  146. for (i=0; i < TM_BOOLCOUNT; i++)
  147. {
  148. pFile->OutLine(L" TM_Bool[%d]: %d",
  149. i, ptm->fBools[i]);
  150. }
  151. pFile->OutLine(L" -----------------------------------------");
  152. //---- dump theme metrics: strings ----
  153. for (i=0; i < TM_STRINGCOUNT; i++)
  154. {
  155. WCHAR *psz;
  156. if (ptm->iStringOffsets[i])
  157. psz = (LPWSTR)(pThemeFile->_pbThemeData + ptm->iStringOffsets[i]);
  158. else
  159. psz = L"";
  160. pFile->OutLine(L" TM_String[%d]: %s", i, psz);
  161. }
  162. pFile->OutLine(L" -----------------------------------------");
  163. }
  164. break;
  165. case TMT_ENUM:
  166. if (fPropDump)
  167. pFile->OutLine(L" Enum: dtype=%d, val=%d", hdr.usTypeNum, *u.pi);
  168. break;
  169. case TMT_DIBDATA:
  170. if (fPropDump)
  171. {
  172. TMBITMAPHEADER *pThemeBitmapHeader;
  173. pThemeBitmapHeader = reinterpret_cast<TMBITMAPHEADER*>(u.pb);
  174. if (pThemeBitmapHeader->hBitmap == NULL)
  175. {
  176. BITMAPINFOHEADER *pHdr;
  177. pHdr = BITMAPDATA(pThemeBitmapHeader);
  178. if (fFullInfo)
  179. {
  180. pFile->OutLine(L" DibData: width=%d, height=%d, total size: %d",
  181. pHdr->biWidth, pHdr->biHeight, hdr.dwDataLen);
  182. }
  183. else
  184. {
  185. pFile->OutLine(L" DibData: width=%d, height=%d",
  186. pHdr->biWidth, pHdr->biHeight);
  187. }
  188. }
  189. else // STOCKBITMAPHDR
  190. {
  191. if (fFullInfo)
  192. {
  193. pFile->OutLine(L" STOCKBITMAPHDR: dwColorDepth=%d, hBitmap=%8X, total size: %d",
  194. pThemeBitmapHeader->dwColorDepth,
  195. pThemeBitmapHeader->hBitmap, hdr.dwDataLen);
  196. }
  197. else
  198. {
  199. pFile->OutLine(L" STOCKBITMAPHDR: dwColorDepth=%d",
  200. pThemeBitmapHeader->dwColorDepth);
  201. }
  202. }
  203. }
  204. break;
  205. default:
  206. if (fPropDump)
  207. pFile->OutLine(L" Unexpected ptype=%d", hdr.ePrimVal);
  208. break;
  209. }
  210. u.pb = origPd + hdr.dwDataLen;
  211. return hdr.ePrimVal;
  212. }
  213. //---------------------------------------------------------------------------
  214. void DumpPackedObjs(CSimpleFile *pFile, CUxThemeFile *pThemeFile, int iOffset,
  215. BOOL fPacked, BOOL fFullInfo)
  216. {
  217. MIXEDPTRS u;
  218. UNPACKED_ENTRYHDR hdr;
  219. u.pb = pThemeFile->_pbThemeData + iOffset;
  220. //---- first come the draw objects ----
  221. while (1)
  222. {
  223. if (*u.ps == TMT_RGNLIST)
  224. {
  225. FillAndSkipHdr(u, &hdr);
  226. int iStateCount = *u.pb;
  227. pFile->OutLine(L"RgnDataList: StateCount=%d", iStateCount);
  228. pFile->OutLine(L" ");
  229. u.pb += hdr.dwDataLen;
  230. continue;
  231. }
  232. if (*u.ps == TMT_STOCKBRUSHES)
  233. {
  234. FillAndSkipHdr(u, &hdr);
  235. pFile->OutLine(L"StockBrushes");
  236. pFile->OutLine(L" ");
  237. u.pb += hdr.dwDataLen;
  238. continue;
  239. }
  240. if (*u.ps != TMT_DRAWOBJ)
  241. break;
  242. FillAndSkipHdr(u, &hdr);
  243. DRAWOBJHDR *ph = (DRAWOBJHDR *)u.pb;
  244. u.pb += sizeof(DRAWOBJHDR);
  245. pFile->OutLine(L"DrawObj: part=%d, state=%d", ph->iPartNum, ph->iStateNum);
  246. BGTYPE eBgType = *(BGTYPE *)u.pb;
  247. if (eBgType == BT_BORDERFILL)
  248. {
  249. CBorderFill *bfobj = (CBorderFill *)u.pb;
  250. u.pb += sizeof(CBorderFill);
  251. bfobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  252. }
  253. else
  254. {
  255. CImageFile *ifobj = (CImageFile *)u.pb;
  256. u.pb += sizeof(CImageFile) + sizeof(DIBINFO)*ifobj->_iMultiImageCount;
  257. ifobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  258. }
  259. pFile->OutLine(L" ");
  260. }
  261. //---- then come the text objects ----
  262. while (*u.ps == TMT_TEXTOBJ)
  263. {
  264. u.pb += ENTRYHDR_SIZE;
  265. DRAWOBJHDR *ph = (DRAWOBJHDR *)u.pb;
  266. u.pb += sizeof(DRAWOBJHDR);
  267. pFile->OutLine(L"TextObj: part=%d, state=%d", ph->iPartNum, ph->iStateNum);
  268. CTextDraw *tdobj = (CTextDraw *)u.pb;
  269. u.pb += sizeof(CTextDraw);
  270. tdobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  271. pFile->OutLine(L" ");
  272. }
  273. }
  274. //---------------------------------------------------------------------------
  275. void DumpSectionData(CSimpleFile *pFile, CUxThemeFile *pThemeFile, int iIndex,
  276. BOOL fPacked, BOOL fFullInfo)
  277. {
  278. MIXEDPTRS u;
  279. u.pb = pThemeFile->_pbThemeData + iIndex;
  280. bool atend = false;
  281. while (! atend)
  282. {
  283. int pnum = DumpType(pFile, pThemeFile, u, fPacked, fFullInfo);
  284. //---- special post-handling ----
  285. switch (pnum)
  286. {
  287. case TMT_PARTJUMPTABLE:
  288. {
  289. int iPackObjsOffset = *u.pi++;
  290. if (! fPacked) // property dump
  291. {
  292. BYTE cnt = *u.pb++;
  293. if (fFullInfo)
  294. {
  295. pFile->OutLine(L" PartJumpTable: drawobj offset=%d, cnt=%d",
  296. iPackObjsOffset, cnt);
  297. }
  298. else
  299. {
  300. pFile->OutLine(L" PartJumpTable: drawobj cnt=%d",
  301. cnt);
  302. }
  303. for (int i=0; i < cnt; i++)
  304. {
  305. int index = *u.pi++;
  306. if (fFullInfo)
  307. pFile->OutLine(L" Part[%d]: index=%d", i, index);
  308. else
  309. pFile->OutLine(L" Part[%d]", i);
  310. if (index > -1)
  311. DumpSectionData(pFile, pThemeFile, index, fPacked, fFullInfo);
  312. }
  313. }
  314. else // packed object dump
  315. {
  316. DumpPackedObjs(pFile, pThemeFile, iPackObjsOffset, fPacked, fFullInfo);
  317. }
  318. }
  319. atend = true;
  320. break;
  321. case TMT_STATEJUMPTABLE:
  322. {
  323. if (! fPacked)
  324. {
  325. BYTE cnt = *u.pb++;
  326. pFile->OutLine(L" StateJumpTable: cnt=%d", cnt);
  327. for (int i=0; i < cnt; i++)
  328. {
  329. int index = *u.pi++;
  330. if (fFullInfo)
  331. pFile->OutLine(L" State[%d]: index=%d", i, index);
  332. else
  333. pFile->OutLine(L" State[%d]", i);
  334. if (index > -1)
  335. DumpSectionData(pFile, pThemeFile, index, fPacked, fFullInfo);
  336. }
  337. }
  338. }
  339. atend = true;
  340. break;
  341. case TMT_JUMPTOPARENT:
  342. atend = true;
  343. break;
  344. }
  345. }
  346. }
  347. //---------------------------------------------------------------------------
  348. HRESULT DumpThemeFile(LPCWSTR pszFileName, CUxThemeFile *pThemeFile, BOOL fPacked,
  349. BOOL fFullInfo)
  350. {
  351. MIXEDPTRS u;
  352. CHAR szSignature[kcbBeginSignature + 1];
  353. CSimpleFile OutFile;
  354. CSimpleFile *pFile = &OutFile;
  355. HRESULT hr = OutFile.Create(pszFileName, TRUE);
  356. if (FAILED(hr))
  357. goto exit;
  358. u.pb = pThemeFile->_pbThemeData;
  359. pFile->OutLine(L"Loaded Theme Dump");
  360. pFile->OutLine(L""); // blank line
  361. pFile->OutLine(L"Header Section");
  362. //---- dump header ----
  363. THEMEHDR *hdr = (THEMEHDR *)u.pb;
  364. u.pb += sizeof(THEMEHDR);
  365. if (fFullInfo)
  366. pFile->OutLine(L" dwTotalLength: %d", hdr->dwTotalLength);
  367. memcpy(szSignature, hdr->szSignature, kcbBeginSignature);
  368. szSignature[kcbBeginSignature] = '\0';
  369. pFile->OutLine(L" szSignature: %S", szSignature);
  370. pFile->OutLine(L" dwVersion: 0x%x", hdr->dwVersion);
  371. pFile->OutLine(L" dwFlags: 0x%x", hdr->dwFlags);
  372. if (fFullInfo)
  373. pFile->OutLine(L" dwCheckSum: 0x%x", hdr->dwCheckSum);
  374. if (fFullInfo)
  375. pFile->OutLine(L" DllName: %s", ThemeString(pThemeFile, hdr->iDllNameOffset));
  376. pFile->OutLine(L" Color: %s", ThemeString(pThemeFile, hdr->iColorParamOffset));
  377. pFile->OutLine(L" Size: %s", ThemeString(pThemeFile, hdr->iSizeParamOffset));
  378. if (fFullInfo)
  379. {
  380. pFile->OutLine(L" Strings: index=%d, length=%d", hdr->iStringsOffset, hdr->iStringsLength);
  381. pFile->OutLine(L" SectionIndex: index=%d, length=%d", hdr->iSectionIndexOffset, hdr->iSectionIndexLength);
  382. pFile->OutLine(L" iGlobalsOffset: %d", hdr->iGlobalsOffset);
  383. pFile->OutLine(L" iGlobalsTextObjOffset: %d", hdr->iGlobalsTextObjOffset);
  384. pFile->OutLine(L" iGlobalsDrawObjOffset: %d", hdr->iGlobalsDrawObjOffset);
  385. pFile->OutLine(L" iSysMetricsOffset: %d", hdr->iSysMetricsOffset);
  386. }
  387. //---- dump strings section ----
  388. pFile->OutLine(L""); // blank line
  389. if (fFullInfo)
  390. {
  391. pFile->OutLine(L"Strings Section (index=%d, length=%d)",
  392. THEMEFILE_OFFSET(u.pb), hdr->iStringsLength);
  393. }
  394. else
  395. {
  396. pFile->OutLine(L"Strings Section");
  397. }
  398. u.pb = pThemeFile->_pbThemeData + hdr->iStringsOffset;
  399. int len = lstrlen(u.pw);
  400. WCHAR *pLastStringChar = (WCHAR *)(u.pb + hdr->iStringsLength - 1);
  401. BOOL fFirstString = TRUE;
  402. while (u.pw <= pLastStringChar)
  403. {
  404. if (fFullInfo)
  405. pFile->OutLine(L" index=%d: %s", THEMEFILE_OFFSET(u.pb), u.pw);
  406. else
  407. {
  408. if (! fFirstString) // don't show pathnames
  409. pFile->OutLine(L" %s", u.pw);
  410. }
  411. u.pw += (1 + len);
  412. len = lstrlen(u.pw);
  413. if (fFirstString)
  414. fFirstString = FALSE;
  415. }
  416. //---- index section ----
  417. u.pb = pThemeFile->_pbThemeData + hdr->iSectionIndexOffset;
  418. pFile->OutLine(L""); // blank line
  419. if (fFullInfo)
  420. {
  421. pFile->OutLine(L"Index Section (index=%d, length=%d)",
  422. THEMEFILE_OFFSET(u.pb), hdr->iSectionIndexLength);
  423. }
  424. else
  425. {
  426. pFile->OutLine(L"Index Section");
  427. }
  428. APPCLASSLIVE *ac = (APPCLASSLIVE *)u.pb;
  429. DWORD cnt = hdr->iSectionIndexLength/sizeof(APPCLASSLIVE);
  430. for (DWORD i=0; i < cnt; i++)
  431. {
  432. LPCWSTR pszApp = ThemeString(pThemeFile, ac->dwAppNameIndex);
  433. LPCWSTR pszClass = ThemeString(pThemeFile, ac->dwClassNameIndex);
  434. if (fFullInfo)
  435. {
  436. pFile->OutLine(L"[%s::%s] (index=%d, length=%d)", pszApp, pszClass,
  437. ac->iIndex, ac->iLen);
  438. }
  439. else
  440. {
  441. pFile->OutLine(L"[%s::%s]", pszApp, pszClass);
  442. }
  443. DumpSectionData(pFile, pThemeFile, ac->iIndex, fPacked, fFullInfo);
  444. ac++;
  445. }
  446. pFile->OutLine(L"END of Live Data dump");
  447. pFile->OutLine(L""); // blank line
  448. exit:
  449. return hr;
  450. }
  451. //---------------------------------------------------------------------------