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.

544 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_DRAWOBJ)
  233. break;
  234. FillAndSkipHdr(u, &hdr);
  235. DRAWOBJHDR *ph = (DRAWOBJHDR *)u.pb;
  236. u.pb += sizeof(DRAWOBJHDR);
  237. pFile->OutLine(L"DrawObj: part=%d, state=%d", ph->iPartNum, ph->iStateNum);
  238. BGTYPE eBgType = *(BGTYPE *)u.pb;
  239. if (eBgType == BT_BORDERFILL)
  240. {
  241. CBorderFill *bfobj = (CBorderFill *)u.pb;
  242. u.pb += sizeof(CBorderFill);
  243. bfobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  244. }
  245. else
  246. {
  247. CImageFile *ifobj = (CImageFile *)u.pb;
  248. u.pb += sizeof(CImageFile) + sizeof(DIBINFO)*ifobj->_iMultiImageCount;
  249. ifobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  250. }
  251. pFile->OutLine(L" ");
  252. }
  253. //---- then come the text objects ----
  254. while (*u.ps == TMT_TEXTOBJ)
  255. {
  256. u.pb += ENTRYHDR_SIZE;
  257. DRAWOBJHDR *ph = (DRAWOBJHDR *)u.pb;
  258. u.pb += sizeof(DRAWOBJHDR);
  259. pFile->OutLine(L"TextObj: part=%d, state=%d", ph->iPartNum, ph->iStateNum);
  260. CTextDraw *tdobj = (CTextDraw *)u.pb;
  261. u.pb += sizeof(CTextDraw);
  262. tdobj->DumpProperties(pFile, pThemeFile->_pbThemeData, fFullInfo);
  263. pFile->OutLine(L" ");
  264. }
  265. }
  266. //---------------------------------------------------------------------------
  267. void DumpSectionData(CSimpleFile *pFile, CUxThemeFile *pThemeFile, int iIndex,
  268. BOOL fPacked, BOOL fFullInfo)
  269. {
  270. MIXEDPTRS u;
  271. u.pb = pThemeFile->_pbThemeData + iIndex;
  272. bool atend = false;
  273. while (! atend)
  274. {
  275. int pnum = DumpType(pFile, pThemeFile, u, fPacked, fFullInfo);
  276. //---- special post-handling ----
  277. switch (pnum)
  278. {
  279. case TMT_PARTJUMPTABLE:
  280. {
  281. int iPackObjsOffset = *u.pi++;
  282. if (! fPacked) // property dump
  283. {
  284. BYTE cnt = *u.pb++;
  285. if (fFullInfo)
  286. {
  287. pFile->OutLine(L" PartJumpTable: drawobj offset=%d, cnt=%d",
  288. iPackObjsOffset, cnt);
  289. }
  290. else
  291. {
  292. pFile->OutLine(L" PartJumpTable: drawobj cnt=%d",
  293. cnt);
  294. }
  295. for (int i=0; i < cnt; i++)
  296. {
  297. int index = *u.pi++;
  298. if (fFullInfo)
  299. pFile->OutLine(L" Part[%d]: index=%d", i, index);
  300. else
  301. pFile->OutLine(L" Part[%d]", i);
  302. if (index > -1)
  303. DumpSectionData(pFile, pThemeFile, index, fPacked, fFullInfo);
  304. }
  305. }
  306. else // packed object dump
  307. {
  308. DumpPackedObjs(pFile, pThemeFile, iPackObjsOffset, fPacked, fFullInfo);
  309. }
  310. }
  311. atend = true;
  312. break;
  313. case TMT_STATEJUMPTABLE:
  314. {
  315. if (! fPacked)
  316. {
  317. BYTE cnt = *u.pb++;
  318. pFile->OutLine(L" StateJumpTable: cnt=%d", cnt);
  319. for (int i=0; i < cnt; i++)
  320. {
  321. int index = *u.pi++;
  322. if (fFullInfo)
  323. pFile->OutLine(L" State[%d]: index=%d", i, index);
  324. else
  325. pFile->OutLine(L" State[%d]", i);
  326. if (index > -1)
  327. DumpSectionData(pFile, pThemeFile, index, fPacked, fFullInfo);
  328. }
  329. }
  330. }
  331. atend = true;
  332. break;
  333. case TMT_JUMPTOPARENT:
  334. atend = true;
  335. break;
  336. }
  337. }
  338. }
  339. //---------------------------------------------------------------------------
  340. HRESULT DumpThemeFile(LPCWSTR pszFileName, CUxThemeFile *pThemeFile, BOOL fPacked,
  341. BOOL fFullInfo)
  342. {
  343. MIXEDPTRS u;
  344. CHAR szSignature[kcbBeginSignature + 1];
  345. CSimpleFile OutFile;
  346. CSimpleFile *pFile = &OutFile;
  347. HRESULT hr = OutFile.Create(pszFileName, TRUE);
  348. if (FAILED(hr))
  349. goto exit;
  350. u.pb = pThemeFile->_pbThemeData;
  351. pFile->OutLine(L"Loaded Theme Dump");
  352. pFile->OutLine(L""); // blank line
  353. pFile->OutLine(L"Header Section");
  354. //---- dump header ----
  355. THEMEHDR *hdr = (THEMEHDR *)u.pb;
  356. u.pb += sizeof(THEMEHDR);
  357. if (fFullInfo)
  358. pFile->OutLine(L" dwTotalLength: %d", hdr->dwTotalLength);
  359. CopyMemory(szSignature, hdr->szSignature, kcbBeginSignature); // hdr->szSignature is not zero-terminated.
  360. szSignature[kcbBeginSignature] = '\0';
  361. pFile->OutLine(L" szSignature: %S", szSignature);
  362. pFile->OutLine(L" dwVersion: 0x%x", hdr->dwVersion);
  363. pFile->OutLine(L" dwFlags: 0x%x", hdr->dwFlags);
  364. if (fFullInfo)
  365. pFile->OutLine(L" dwCheckSum: 0x%x", hdr->dwCheckSum);
  366. if (fFullInfo)
  367. pFile->OutLine(L" DllName: %s", ThemeString(pThemeFile, hdr->iDllNameOffset));
  368. pFile->OutLine(L" Color: %s", ThemeString(pThemeFile, hdr->iColorParamOffset));
  369. pFile->OutLine(L" Size: %s", ThemeString(pThemeFile, hdr->iSizeParamOffset));
  370. if (fFullInfo)
  371. {
  372. pFile->OutLine(L" Strings: index=%d, length=%d", hdr->iStringsOffset, hdr->iStringsLength);
  373. pFile->OutLine(L" SectionIndex: index=%d, length=%d", hdr->iSectionIndexOffset, hdr->iSectionIndexLength);
  374. pFile->OutLine(L" iGlobalsOffset: %d", hdr->iGlobalsOffset);
  375. pFile->OutLine(L" iGlobalsTextObjOffset: %d", hdr->iGlobalsTextObjOffset);
  376. pFile->OutLine(L" iGlobalsDrawObjOffset: %d", hdr->iGlobalsDrawObjOffset);
  377. pFile->OutLine(L" iSysMetricsOffset: %d", hdr->iSysMetricsOffset);
  378. }
  379. //---- dump strings section ----
  380. pFile->OutLine(L""); // blank line
  381. if (fFullInfo)
  382. {
  383. pFile->OutLine(L"Strings Section (index=%d, length=%d)",
  384. THEMEFILE_OFFSET(u.pb), hdr->iStringsLength);
  385. }
  386. else
  387. {
  388. pFile->OutLine(L"Strings Section");
  389. }
  390. u.pb = pThemeFile->_pbThemeData + hdr->iStringsOffset;
  391. int len = lstrlen(u.pw);
  392. WCHAR *pLastStringChar = (WCHAR *)(u.pb + hdr->iStringsLength - 1);
  393. BOOL fFirstString = TRUE;
  394. while (u.pw <= pLastStringChar)
  395. {
  396. if (fFullInfo)
  397. pFile->OutLine(L" index=%d: %s", THEMEFILE_OFFSET(u.pb), u.pw);
  398. else
  399. {
  400. if (! fFirstString) // don't show pathnames
  401. pFile->OutLine(L" %s", u.pw);
  402. }
  403. u.pw += (1 + len);
  404. len = lstrlen(u.pw);
  405. if (fFirstString)
  406. fFirstString = FALSE;
  407. }
  408. //---- index section ----
  409. u.pb = pThemeFile->_pbThemeData + hdr->iSectionIndexOffset;
  410. pFile->OutLine(L""); // blank line
  411. if (fFullInfo)
  412. {
  413. pFile->OutLine(L"Index Section (index=%d, length=%d)",
  414. THEMEFILE_OFFSET(u.pb), hdr->iSectionIndexLength);
  415. }
  416. else
  417. {
  418. pFile->OutLine(L"Index Section");
  419. }
  420. APPCLASSLIVE *ac = (APPCLASSLIVE *)u.pb;
  421. DWORD cnt = hdr->iSectionIndexLength/sizeof(APPCLASSLIVE);
  422. for (DWORD i=0; i < cnt; i++)
  423. {
  424. LPCWSTR pszApp = ThemeString(pThemeFile, ac->dwAppNameIndex);
  425. LPCWSTR pszClass = ThemeString(pThemeFile, ac->dwClassNameIndex);
  426. if (fFullInfo)
  427. {
  428. pFile->OutLine(L"[%s::%s] (index=%d, length=%d)", pszApp, pszClass,
  429. ac->iIndex, ac->iLen);
  430. }
  431. else
  432. {
  433. pFile->OutLine(L"[%s::%s]", pszApp, pszClass);
  434. }
  435. DumpSectionData(pFile, pThemeFile, ac->iIndex, fPacked, fFullInfo);
  436. ac++;
  437. }
  438. pFile->OutLine(L"END of Live Data dump");
  439. pFile->OutLine(L""); // blank line
  440. exit:
  441. return hr;
  442. }
  443. //---------------------------------------------------------------------------