summary.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /*
  2. * summary.c
  3. * Copyright (C) 2002-2005 A.J. van Os; Released under GNU GPL
  4. *
  5. * Description:
  6. * Read the summary information of a Word document
  7. */
  8. #include <time.h>
  9. #include <string.h>
  10. #include "antiword.h"
  11. #define P_HEADER_SZ 28
  12. #define P_SECTIONLIST_SZ 20
  13. #define P_LENGTH_SZ 4
  14. #define P_SECTION_MAX_SZ (2 * P_SECTIONLIST_SZ + P_LENGTH_SZ)
  15. #define P_SECTION_SZ(x) ((x) * P_SECTIONLIST_SZ + P_LENGTH_SZ)
  16. #define PID_TITLE 2
  17. #define PID_SUBJECT 3
  18. #define PID_AUTHOR 4
  19. #define PID_CREATE_DTM 12
  20. #define PID_LASTSAVE_DTM 13
  21. #define PID_APPNAME 18
  22. #define PIDD_MANAGER 14
  23. #define PIDD_COMPANY 15
  24. #define VT_LPSTR 30
  25. #define VT_FILETIME 64
  26. #define TIME_OFFSET_HI 0x019db1de
  27. #define TIME_OFFSET_LO 0xd53e8000
  28. static char *szTitle = NULL;
  29. static char *szSubject = NULL;
  30. static char *szAuthor = NULL;
  31. static time_t tCreateDtm = (time_t)-1;
  32. static time_t tLastSaveDtm= (time_t)-1;
  33. static char *szAppName = NULL;
  34. static char *szManager = NULL;
  35. static char *szCompany = NULL;
  36. static USHORT usLid = (USHORT)-1;
  37. /*
  38. * vDestroySummaryInfo - destroy the summary information
  39. */
  40. void
  41. vDestroySummaryInfo(void)
  42. {
  43. TRACE_MSG("vDestroySummaryInfo");
  44. szTitle = xfree(szTitle);
  45. szSubject = xfree(szSubject);
  46. szAuthor = xfree(szAuthor);
  47. tCreateDtm = (time_t)-1;
  48. tLastSaveDtm = (time_t)-1;
  49. szAppName = xfree(szAppName);
  50. szManager = xfree(szManager);
  51. szCompany = xfree(szCompany);
  52. usLid = (USHORT)-1;
  53. } /* end of vDestroySummaryInfo */
  54. /*
  55. * tConvertDosDate - convert DOS date format
  56. *
  57. * returns Unix time_t or -1
  58. */
  59. static time_t
  60. tConvertDosDate(const char *szDosDate)
  61. {
  62. struct tm tTime;
  63. const char *pcTmp;
  64. time_t tResult;
  65. memset(&tTime, 0, sizeof(tTime));
  66. pcTmp = szDosDate;
  67. /* Get the month */
  68. if (!isdigit(*pcTmp)) {
  69. return (time_t)-1;
  70. }
  71. tTime.tm_mon = (int)(*pcTmp - '0');
  72. pcTmp++;
  73. if (isdigit(*pcTmp)) {
  74. tTime.tm_mon *= 10;
  75. tTime.tm_mon += (int)(*pcTmp - '0');
  76. pcTmp++;
  77. }
  78. /* Get the first separater */
  79. if (isalnum(*pcTmp)) {
  80. return (time_t)-1;
  81. }
  82. pcTmp++;
  83. /* Get the day */
  84. if (!isdigit(*pcTmp)) {
  85. return (time_t)-1;
  86. }
  87. tTime.tm_mday = (int)(*pcTmp - '0');
  88. pcTmp++;
  89. if (isdigit(*pcTmp)) {
  90. tTime.tm_mday *= 10;
  91. tTime.tm_mday += (int)(*pcTmp - '0');
  92. pcTmp++;
  93. }
  94. /* Get the second separater */
  95. if (isalnum(*pcTmp)) {
  96. return (time_t)-1;
  97. }
  98. pcTmp++;
  99. /* Get the year */
  100. if (!isdigit(*pcTmp)) {
  101. return (time_t)-1;
  102. }
  103. tTime.tm_year = (int)(*pcTmp - '0');
  104. pcTmp++;
  105. if (isdigit(*pcTmp)) {
  106. tTime.tm_year *= 10;
  107. tTime.tm_year += (int)(*pcTmp - '0');
  108. pcTmp++;
  109. }
  110. /* Check the values */
  111. if (tTime.tm_mon == 0 || tTime.tm_mday == 0 || tTime.tm_mday > 31) {
  112. return (time_t)-1;
  113. }
  114. /* Correct the values */
  115. tTime.tm_mon--; /* From 01-12 to 00-11 */
  116. if (tTime.tm_year < 80) {
  117. tTime.tm_year += 100; /* 00 means 2000 is 100 */
  118. }
  119. tTime.tm_isdst = -1;
  120. tResult = mktime(&tTime);
  121. NO_DBG_MSG(ctime(&tResult));
  122. return tResult;
  123. } /* end of tConvertDosDate */
  124. /*
  125. * szLpstr - get a zero terminate string property
  126. */
  127. static char *
  128. szLpstr(ULONG ulOffset, const UCHAR *aucBuffer)
  129. {
  130. char *szStart, *szResult, *szTmp;
  131. size_t tSize;
  132. tSize = (size_t)ulGetLong(ulOffset + 4, aucBuffer);
  133. NO_DBG_DEC(tSize);
  134. if (tSize == 0) {
  135. return NULL;
  136. }
  137. /* Remove white space from the start of the string */
  138. szStart = (char *)aucBuffer + ulOffset + 8;
  139. NO_DBG_MSG(szStart);
  140. fail(strlen(szStart) >= tSize);
  141. while (isspace(*szStart)) {
  142. szStart++;
  143. }
  144. if (szStart[0] == '\0') {
  145. return NULL;
  146. }
  147. szResult = xstrdup(szStart);
  148. /* Remove white space from the end of the string */
  149. szTmp = szResult + strlen(szResult) - 1;
  150. while (isspace(*szTmp)) {
  151. *szTmp = '\0';
  152. szTmp--;
  153. }
  154. NO_DBG_MSG(szResult);
  155. return szResult;
  156. } /* end of szLpstr */
  157. /*
  158. * tFiletime - get a filetime property
  159. */
  160. static time_t
  161. tFiletime(ULONG ulOffset, const UCHAR *aucBuffer)
  162. {
  163. double dHi, dLo, dTmp;
  164. ULONG ulHi, ulLo;
  165. time_t tResult;
  166. ulLo = ulGetLong(ulOffset + 4, aucBuffer);
  167. ulHi = ulGetLong(ulOffset + 8, aucBuffer);
  168. NO_DBG_HEX(ulHi);
  169. NO_DBG_HEX(ulLo);
  170. /* Move the starting point from 01 Jan 1601 to 01 Jan 1970 */
  171. dHi = (double)ulHi - (double)TIME_OFFSET_HI;
  172. dLo = (double)ulLo - (double)TIME_OFFSET_LO;
  173. NO_DBG_FLT(dHi);
  174. NO_DBG_FLT(dLo);
  175. /* Combine the values and divide by 10^7 to get seconds */
  176. dTmp = dLo / 10000000.0; /* 10^7 */
  177. dTmp += dHi * 429.4967926; /* 2^32 / 10^7 */
  178. NO_DBG_FLT(dTmp);
  179. /* Make a time_t */
  180. if (dTmp - 0.5 < TIME_T_MIN || dTmp + 0.5 > TIME_T_MAX) {
  181. return (time_t)-1;
  182. }
  183. tResult = dTmp < 0.0 ? (time_t)(dTmp - 0.5) : (time_t)(dTmp + 0.5);
  184. NO_DBG_MSG(ctime(&tResult));
  185. return tResult;
  186. } /* end of tFiletime */
  187. /*
  188. * vAnalyseSummaryInfo - analyse the summary information
  189. */
  190. static void
  191. vAnalyseSummaryInfo(const UCHAR *aucBuffer)
  192. {
  193. ULONG ulOffset;
  194. size_t tIndex, tCount, tPropID, tPropType;
  195. tCount = (size_t)ulGetLong(4, aucBuffer);
  196. DBG_DEC(tCount);
  197. for (tIndex = 0; tIndex < tCount; tIndex++) {
  198. tPropID = (size_t)ulGetLong(8 + tIndex * 8, aucBuffer);
  199. ulOffset = ulGetLong(12 + tIndex * 8, aucBuffer);
  200. NO_DBG_DEC(tPropID);
  201. NO_DBG_HEX(ulOffset);
  202. tPropType = (size_t)ulGetLong(ulOffset, aucBuffer);
  203. NO_DBG_DEC(tPropType);
  204. switch (tPropID) {
  205. case PID_TITLE:
  206. if (tPropType == VT_LPSTR && szTitle == NULL) {
  207. szTitle = szLpstr(ulOffset, aucBuffer);
  208. }
  209. break;
  210. case PID_SUBJECT:
  211. if (tPropType == VT_LPSTR && szSubject == NULL) {
  212. szSubject = szLpstr(ulOffset, aucBuffer);
  213. }
  214. break;
  215. case PID_AUTHOR:
  216. if (tPropType == VT_LPSTR && szAuthor == NULL) {
  217. szAuthor = szLpstr(ulOffset, aucBuffer);
  218. }
  219. break;
  220. case PID_CREATE_DTM:
  221. if (tPropType == VT_FILETIME &&
  222. tCreateDtm == (time_t)-1) {
  223. tCreateDtm = tFiletime(ulOffset, aucBuffer);
  224. }
  225. break;
  226. case PID_LASTSAVE_DTM:
  227. if (tPropType == VT_FILETIME &&
  228. tLastSaveDtm == (time_t)-1) {
  229. tLastSaveDtm = tFiletime(ulOffset, aucBuffer);
  230. }
  231. break;
  232. case PID_APPNAME:
  233. if (tPropType == VT_LPSTR && szAppName == NULL) {
  234. szAppName = szLpstr(ulOffset, aucBuffer);
  235. }
  236. break;
  237. default:
  238. break;
  239. }
  240. }
  241. } /* end of vAnalyseSummaryInfo */
  242. /*
  243. * vAnalyseDocumentSummaryInfo - analyse the document summary information
  244. */
  245. static void
  246. vAnalyseDocumentSummaryInfo(const UCHAR *aucBuffer)
  247. {
  248. ULONG ulOffset;
  249. size_t tIndex, tCount, tPropID, tPropType;
  250. tCount = (size_t)ulGetLong(4, aucBuffer);
  251. DBG_DEC(tCount);
  252. for (tIndex = 0; tIndex < tCount; tIndex++) {
  253. tPropID = (size_t)ulGetLong(8 + tIndex * 8, aucBuffer);
  254. ulOffset = ulGetLong(12 + tIndex * 8, aucBuffer);
  255. NO_DBG_DEC(tPropID);
  256. NO_DBG_HEX(ulOffset);
  257. tPropType = (size_t)ulGetLong(ulOffset, aucBuffer);
  258. NO_DBG_DEC(tPropType);
  259. switch (tPropID) {
  260. case PIDD_MANAGER:
  261. if (tPropType == VT_LPSTR && szManager == NULL) {
  262. szManager = szLpstr(ulOffset, aucBuffer);
  263. }
  264. break;
  265. case PIDD_COMPANY:
  266. if (tPropType == VT_LPSTR && szCompany == NULL) {
  267. szCompany = szLpstr(ulOffset, aucBuffer);
  268. }
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. } /* end of vAnalyseDocumentSummaryInfo */
  275. /*
  276. * pucAnalyseSummaryInfoHeader-
  277. */
  278. static UCHAR *
  279. pucAnalyseSummaryInfoHeader(FILE *pFile,
  280. ULONG ulStartBlock, ULONG ulSize,
  281. const ULONG *aulBBD, size_t tBBDLen,
  282. const ULONG *aulSBD, size_t tSBDLen)
  283. {
  284. const ULONG *aulBlockDepot;
  285. UCHAR *aucBuffer;
  286. size_t tBlockDepotLen, tBlockSize, tSectionCount, tLength;
  287. ULONG ulTmp, ulOffset;
  288. USHORT usLittleEndian, usEmpty, usOS, usVersion;
  289. UCHAR aucHdr[P_HEADER_SZ], aucSecLst[P_SECTION_MAX_SZ];
  290. if (ulSize < MIN_SIZE_FOR_BBD_USE) {
  291. /* Use the Small Block Depot */
  292. aulBlockDepot = aulSBD;
  293. tBlockDepotLen = tSBDLen;
  294. tBlockSize = SMALL_BLOCK_SIZE;
  295. } else {
  296. /* Use the Big Block Depot */
  297. aulBlockDepot = aulBBD;
  298. tBlockDepotLen = tBBDLen;
  299. tBlockSize = BIG_BLOCK_SIZE;
  300. }
  301. if (tBlockDepotLen == 0) {
  302. DBG_MSG("The Block Depot length is zero");
  303. return NULL;
  304. }
  305. /* Read the Summery Information header */
  306. if (!bReadBuffer(pFile, ulStartBlock,
  307. aulBlockDepot, tBlockDepotLen, tBlockSize,
  308. aucHdr, 0, P_HEADER_SZ)) {
  309. return NULL;
  310. }
  311. NO_DBG_PRINT_BLOCK(aucHdr, P_HEADER_SZ);
  312. /* Analyse the Summery Information header */
  313. usLittleEndian = usGetWord(0, aucHdr);
  314. if (usLittleEndian != 0xfffe) {
  315. DBG_HEX(usLittleEndian);
  316. DBG_MSG_C(usLittleEndian == 0xfeff, "Big endian");
  317. return NULL;
  318. }
  319. usEmpty = usGetWord(2, aucHdr);
  320. if (usEmpty != 0x0000) {
  321. DBG_DEC(usEmpty);
  322. return NULL;
  323. }
  324. ulTmp = ulGetLong(4, aucHdr);
  325. DBG_HEX(ulTmp);
  326. usOS = (USHORT)(ulTmp >> 16);
  327. usVersion = (USHORT)(ulTmp & 0xffff);
  328. switch (usOS) {
  329. case 0:
  330. DBG_MSG("Win16");
  331. DBG_HEX(usVersion);
  332. break;
  333. case 1:
  334. DBG_MSG("MacOS");
  335. DBG_HEX(usVersion);
  336. break;
  337. case 2:
  338. DBG_MSG("Win32");
  339. DBG_HEX(usVersion);
  340. break;
  341. default:
  342. DBG_DEC(usOS);
  343. DBG_HEX(usVersion);
  344. break;
  345. }
  346. tSectionCount = (size_t)ulGetLong(24, aucHdr);
  347. DBG_DEC_C(tSectionCount != 1 && tSectionCount != 2, tSectionCount);
  348. if (tSectionCount != 1 && tSectionCount != 2) {
  349. return NULL;
  350. }
  351. /* Read the Summery Information Section Lists */
  352. if (!bReadBuffer(pFile, ulStartBlock,
  353. aulBlockDepot, tBlockDepotLen, tBlockSize,
  354. aucSecLst, P_HEADER_SZ, P_SECTION_SZ(tSectionCount))) {
  355. return NULL;
  356. }
  357. NO_DBG_PRINT_BLOCK(aucSecLst, P_SECTION_SZ(tSectionCount));
  358. ulTmp = ulGetLong(0, aucSecLst);
  359. DBG_HEX(ulTmp);
  360. ulTmp = ulGetLong(4, aucSecLst);
  361. DBG_HEX(ulTmp);
  362. ulTmp = ulGetLong(8, aucSecLst);
  363. DBG_HEX(ulTmp);
  364. ulTmp = ulGetLong(12, aucSecLst);
  365. DBG_HEX(ulTmp);
  366. ulOffset = ulGetLong(16, aucSecLst);
  367. DBG_DEC_C(ulOffset != P_HEADER_SZ + P_SECTIONLIST_SZ &&
  368. ulOffset != P_HEADER_SZ + 2 * P_SECTIONLIST_SZ,
  369. ulOffset);
  370. fail(ulOffset != P_HEADER_SZ + P_SECTIONLIST_SZ &&
  371. ulOffset != P_HEADER_SZ + 2 * P_SECTIONLIST_SZ);
  372. tLength =
  373. (size_t)ulGetLong(tSectionCount * P_SECTIONLIST_SZ, aucSecLst);
  374. NO_DBG_HEX(tLength);
  375. fail(ulOffset + tLength > ulSize);
  376. /* Read the Summery Information */
  377. aucBuffer = xmalloc(tLength);
  378. if (!bReadBuffer(pFile, ulStartBlock,
  379. aulBlockDepot, tBlockDepotLen, tBlockSize,
  380. aucBuffer, ulOffset, tLength)) {
  381. aucBuffer = xfree(aucBuffer);
  382. return NULL;
  383. }
  384. NO_DBG_PRINT_BLOCK(aucBuffer, tLength);
  385. return aucBuffer;
  386. } /* end of pucAnalyseSummaryInfoHeader */
  387. /*
  388. * vSet0SummaryInfo - set summary information from a Word for DOS file
  389. */
  390. void
  391. vSet0SummaryInfo(FILE *pFile, const UCHAR *aucHeader)
  392. {
  393. UCHAR *aucBuffer;
  394. ULONG ulBeginSumdInfo, ulBeginNextBlock;
  395. size_t tLen;
  396. USHORT usCodepage, usOffset;
  397. TRACE_MSG("vSet0SummaryInfo");
  398. fail(pFile == NULL || aucHeader == NULL);
  399. /* First check the header */
  400. usCodepage = usGetWord(0x7e, aucHeader);
  401. DBG_DEC(usCodepage);
  402. switch (usCodepage) {
  403. case 850: usLid = 0x0809; break; /* Latin1 -> British English */
  404. case 862: usLid = 0x040d; break; /* Hebrew */
  405. case 866: usLid = 0x0419; break; /* Russian */
  406. case 0:
  407. case 437:
  408. default: usLid = 0x0409; break; /* ASCII -> American English */
  409. }
  410. /* Second check the summary information block */
  411. ulBeginSumdInfo = 128 * (ULONG)usGetWord(0x1c, aucHeader);
  412. DBG_HEX(ulBeginSumdInfo);
  413. ulBeginNextBlock = 128 * (ULONG)usGetWord(0x6a, aucHeader);
  414. DBG_HEX(ulBeginNextBlock);
  415. if (ulBeginSumdInfo >= ulBeginNextBlock || ulBeginNextBlock == 0) {
  416. /* There is no summary information block */
  417. return;
  418. }
  419. tLen = (size_t)(ulBeginNextBlock - ulBeginSumdInfo);
  420. aucBuffer = xmalloc(tLen);
  421. /* Read the summary information block */
  422. if (!bReadBytes(aucBuffer, tLen, ulBeginSumdInfo, pFile)) {
  423. return;
  424. }
  425. usOffset = usGetWord(0, aucBuffer);
  426. if (aucBuffer[usOffset] != 0) {
  427. NO_DBG_MSG(aucBuffer + usOffset);
  428. szTitle = xstrdup((char *)aucBuffer + usOffset);
  429. }
  430. usOffset = usGetWord(2, aucBuffer);
  431. if (aucBuffer[usOffset] != 0) {
  432. NO_DBG_MSG(aucBuffer + usOffset);
  433. szAuthor = xstrdup((char *)aucBuffer + usOffset);
  434. }
  435. usOffset = usGetWord(12, aucBuffer);
  436. if (aucBuffer[usOffset] != 0) {
  437. NO_DBG_STRN(aucBuffer + usOffset, 8);
  438. tLastSaveDtm = tConvertDosDate((char *)aucBuffer + usOffset);
  439. }
  440. usOffset = usGetWord(14, aucBuffer);
  441. if (aucBuffer[usOffset] != 0) {
  442. NO_DBG_STRN(aucBuffer + usOffset, 8);
  443. tCreateDtm = tConvertDosDate((char *)aucBuffer + usOffset);
  444. }
  445. aucBuffer = xfree(aucBuffer);
  446. } /* end of vSet0SummaryInfo */
  447. /*
  448. * vSet2SummaryInfo - set summary information from a WinWord 1/2 file
  449. */
  450. void
  451. vSet2SummaryInfo(FILE *pFile, int iWordVersion, const UCHAR *aucHeader)
  452. {
  453. UCHAR *aucBuffer;
  454. ULONG ulBeginSumdInfo, ulBeginDocpInfo, ulTmp;
  455. size_t tSumdInfoLen, tDocpInfoLen, tLen, tCounter, tStart;
  456. TRACE_MSG("vSet2SummaryInfo");
  457. fail(pFile == NULL || aucHeader == NULL);
  458. fail(iWordVersion != 1 && iWordVersion != 2);
  459. /* First check the header */
  460. usLid = usGetWord(0x06, aucHeader); /* Language IDentification */
  461. DBG_HEX(usLid);
  462. if (usLid < 999 && iWordVersion == 1) {
  463. switch (usLid) {
  464. case 1: usLid = 0x0409; break; /* American English */
  465. case 2: usLid = 0x0c0c; break; /* Canadian French */
  466. case 31: usLid = 0x0413; break; /* Dutch */
  467. case 33: usLid = 0x040c; break; /* French */
  468. case 34: usLid = 0x040a; break; /* Spanish */
  469. case 36: usLid = 0x040e; break; /* Hungarian */
  470. case 39: usLid = 0x0410; break; /* Italian */
  471. case 44: usLid = 0x0809; break; /* British English */
  472. case 45: usLid = 0x0406; break; /* Danish */
  473. case 46: usLid = 0x041f; break; /* Swedish */
  474. case 47: usLid = 0x0414; break; /* Norwegian */
  475. case 48: usLid = 0x0415; break; /* Polish */
  476. case 49: usLid = 0x0407; break; /* German */
  477. case 351: usLid = 0x0816; break; /* Portuguese */
  478. case 358: usLid = 0x040b; break; /* Finnish */
  479. default:
  480. DBG_DEC(usLid);
  481. DBG_FIXME();
  482. usLid = 0x0409; /* American English */
  483. break;
  484. }
  485. }
  486. if (iWordVersion != 2) {
  487. /* Unknown where to find the associated strings */
  488. return;
  489. }
  490. /* Second check the associated strings */
  491. ulBeginSumdInfo = ulGetLong(0x118, aucHeader); /* fcSttbfAssoc */
  492. DBG_HEX(ulBeginSumdInfo);
  493. tSumdInfoLen = (size_t)usGetWord(0x11c, aucHeader); /* cbSttbfAssoc */
  494. DBG_DEC(tSumdInfoLen);
  495. if (tSumdInfoLen == 0) {
  496. /* There is no summary information */
  497. return;
  498. }
  499. aucBuffer = xmalloc(tSumdInfoLen);
  500. if (!bReadBytes(aucBuffer, tSumdInfoLen, ulBeginSumdInfo, pFile)) {
  501. aucBuffer = xfree(aucBuffer);
  502. return;
  503. }
  504. NO_DBG_PRINT_BLOCK(aucBuffer, tSumdInfoLen);
  505. tLen = (size_t)ucGetByte(0, aucBuffer);
  506. DBG_DEC_C(tSumdInfoLen != tLen, tSumdInfoLen);
  507. DBG_DEC_C(tSumdInfoLen != tLen, tLen);
  508. tStart = 1;
  509. for (tCounter = 0; tCounter < 17; tCounter++) {
  510. if (tStart >= tSumdInfoLen) {
  511. break;
  512. }
  513. tLen = (size_t)ucGetByte(tStart, aucBuffer);
  514. if (tLen != 0) {
  515. NO_DBG_DEC(tCounter);
  516. NO_DBG_STRN(aucBuffer + tStart + 1, tLen);
  517. switch (tCounter) {
  518. case 3:
  519. szTitle = xmalloc(tLen + 1);
  520. strncpy(szTitle,
  521. (char *)aucBuffer + tStart + 1, tLen);
  522. szTitle[tLen] = '\0';
  523. break;
  524. case 4:
  525. szSubject = xmalloc(tLen + 1);
  526. strncpy(szSubject,
  527. (char *)aucBuffer + tStart + 1, tLen);
  528. szSubject[tLen] = '\0';
  529. break;
  530. case 7:
  531. szAuthor = xmalloc(tLen + 1);
  532. strncpy(szAuthor,
  533. (char *)aucBuffer + tStart + 1, tLen);
  534. szAuthor[tLen] = '\0';
  535. break;
  536. default:
  537. break;
  538. }
  539. }
  540. tStart += tLen + 1;
  541. }
  542. aucBuffer = xfree(aucBuffer);
  543. /* Third check the document properties */
  544. ulBeginDocpInfo = ulGetLong(0x112, aucHeader); /* fcDop */
  545. DBG_HEX(ulBeginDocpInfo);
  546. tDocpInfoLen = (size_t)usGetWord(0x116, aucHeader); /* cbDop */
  547. DBG_DEC(tDocpInfoLen);
  548. if (tDocpInfoLen < 12) {
  549. return;
  550. }
  551. aucBuffer = xmalloc(tDocpInfoLen);
  552. if (!bReadBytes(aucBuffer, tDocpInfoLen, ulBeginDocpInfo, pFile)) {
  553. aucBuffer = xfree(aucBuffer);
  554. return;
  555. }
  556. ulTmp = ulGetLong(0x14, aucBuffer); /* dttmCreated */
  557. tCreateDtm = tConvertDTTM(ulTmp);
  558. ulTmp = ulGetLong(0x18, aucBuffer); /* dttmRevised */
  559. tLastSaveDtm = tConvertDTTM(ulTmp);
  560. aucBuffer = xfree(aucBuffer);
  561. } /* end of vSet2SummaryInfo */
  562. /*
  563. * vSetSummaryInfoOLE - set summary information from a Word 6+ file
  564. */
  565. static void
  566. vSetSummaryInfoOLE(FILE *pFile, const pps_info_type *pPPS,
  567. const ULONG *aulBBD, size_t tBBDLen,
  568. const ULONG *aulSBD, size_t tSBDLen)
  569. {
  570. UCHAR *pucBuffer;
  571. fail(pFile == NULL || pPPS == NULL);
  572. fail(aulBBD == NULL || aulSBD == NULL);
  573. /* Summary Information */
  574. pucBuffer = pucAnalyseSummaryInfoHeader(pFile,
  575. pPPS->tSummaryInfo.ulSB, pPPS->tSummaryInfo.ulSize,
  576. aulBBD, tBBDLen, aulSBD, tSBDLen);
  577. if (pucBuffer != NULL) {
  578. vAnalyseSummaryInfo(pucBuffer);
  579. pucBuffer = xfree(pucBuffer);
  580. }
  581. /* Document Summary Information */
  582. pucBuffer = pucAnalyseSummaryInfoHeader(pFile,
  583. pPPS->tDocSummaryInfo.ulSB, pPPS->tDocSummaryInfo.ulSize,
  584. aulBBD, tBBDLen, aulSBD, tSBDLen);
  585. if (pucBuffer != NULL) {
  586. vAnalyseDocumentSummaryInfo(pucBuffer);
  587. pucBuffer = xfree(pucBuffer);
  588. }
  589. } /* end of vSetSummaryInfoOLE */
  590. /*
  591. * vSet6SummaryInfo - set summary information from a Word 6/7 file
  592. */
  593. void
  594. vSet6SummaryInfo(FILE *pFile, const pps_info_type *pPPS,
  595. const ULONG *aulBBD, size_t tBBDLen,
  596. const ULONG *aulSBD, size_t tSBDLen,
  597. const UCHAR *aucHeader)
  598. {
  599. TRACE_MSG("vSet6SummaryInfo");
  600. /* Header Information */
  601. usLid = usGetWord(0x06, aucHeader); /* Language IDentification */
  602. DBG_HEX(usLid);
  603. /* Summery Information */
  604. vSetSummaryInfoOLE(pFile, pPPS, aulBBD, tBBDLen, aulSBD, tSBDLen);
  605. } /* end of vSet6SummaryInfo */
  606. /*
  607. * vSet8SummaryInfo - set summary information a Word 8/9/10 file
  608. */
  609. void
  610. vSet8SummaryInfo(FILE *pFile, const pps_info_type *pPPS,
  611. const ULONG *aulBBD, size_t tBBDLen,
  612. const ULONG *aulSBD, size_t tSBDLen,
  613. const UCHAR *aucHeader)
  614. {
  615. USHORT usTmp;
  616. TRACE_MSG("vSet8SummaryInfo");
  617. /* Header Information */
  618. usTmp = usGetWord(0x0a, aucHeader);
  619. if (usTmp & BIT(14)) {
  620. /* Language IDentification Far East */
  621. usLid = usGetWord(0x3c, aucHeader);
  622. } else {
  623. /* Language IDentification */
  624. usLid = usGetWord(0x06, aucHeader);
  625. }
  626. DBG_HEX(usLid);
  627. /* Summery Information */
  628. vSetSummaryInfoOLE(pFile, pPPS, aulBBD, tBBDLen, aulSBD, tSBDLen);
  629. } /* end of vSet8SummaryInfo */
  630. /*
  631. * szGetTitle - get the title field
  632. */
  633. const char *
  634. szGetTitle(void)
  635. {
  636. return szTitle;
  637. } /* end of szGetTitle */
  638. /*
  639. * szGetSubject - get the subject field
  640. */
  641. const char *
  642. szGetSubject(void)
  643. {
  644. return szSubject;
  645. } /* end of szGetSubject */
  646. /*
  647. * szGetAuthor - get the author field
  648. */
  649. const char *
  650. szGetAuthor(void)
  651. {
  652. return szAuthor;
  653. } /* end of szGetAuthor */
  654. /*
  655. * szGetLastSaveDtm - get the last save date field
  656. */
  657. const char *
  658. szGetLastSaveDtm(void)
  659. {
  660. static char szTime[12];
  661. struct tm *pTime;
  662. if (tLastSaveDtm == (time_t)-1) {
  663. return NULL;
  664. }
  665. pTime = localtime(&tLastSaveDtm);
  666. if (pTime == NULL) {
  667. return NULL;
  668. }
  669. sprintf(szTime, "%04d-%02d-%02d",
  670. pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday);
  671. return szTime;
  672. } /* end of szGetLastSaveDtm */
  673. /*
  674. * szGetModDate - get the last save date field
  675. */
  676. const char *
  677. szGetModDate(void)
  678. {
  679. static char szTime[20];
  680. struct tm *pTime;
  681. if (tLastSaveDtm == (time_t)-1) {
  682. return NULL;
  683. }
  684. pTime = localtime(&tLastSaveDtm);
  685. if (pTime == NULL) {
  686. return NULL;
  687. }
  688. sprintf(szTime, "D:%04d%02d%02d%02d%02d",
  689. pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday,
  690. pTime->tm_hour, pTime->tm_min);
  691. return szTime;
  692. } /* end of szGetModDate */
  693. /*
  694. * szGetCreationDate - get the last save date field
  695. */
  696. const char *
  697. szGetCreationDate(void)
  698. {
  699. static char szTime[20];
  700. struct tm *pTime;
  701. if (tCreateDtm == (time_t)-1) {
  702. return NULL;
  703. }
  704. pTime = localtime(&tCreateDtm);
  705. if (pTime == NULL) {
  706. return NULL;
  707. }
  708. sprintf(szTime, "D:%04d%02d%02d%02d%02d",
  709. pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday,
  710. pTime->tm_hour, pTime->tm_min);
  711. return szTime;
  712. } /* end of szGetCreationDate */
  713. /*
  714. * szGetCompany - get the company field
  715. */
  716. const char *
  717. szGetCompany(void)
  718. {
  719. return szCompany;
  720. } /* end of szGetCompany */
  721. /*
  722. * szGetLanguage - get de language field
  723. */
  724. const char *
  725. szGetLanguage(void)
  726. {
  727. if (usLid == (USHORT)-1) {
  728. /* No Language IDentification */
  729. return NULL;
  730. }
  731. if (usLid < 999) {
  732. /* This is a Locale, not a Language IDentification */
  733. DBG_DEC(usLid);
  734. return NULL;
  735. }
  736. /* Exceptions to the general rule */
  737. switch (usLid) {
  738. case 0x0404: return "zh_TW"; /* Traditional Chinese */
  739. case 0x0804: return "zh_CN"; /* Simplified Chinese */
  740. case 0x0c04: return "zh_HK"; /* Hong Kong Chinese */
  741. case 0x1004: return "zh_SG"; /* Singapore Chinese */
  742. case 0x0807: return "de_CH"; /* Swiss German */
  743. case 0x0409: return "en_US"; /* American English */
  744. case 0x0809: return "en_GB"; /* British English */
  745. case 0x0c09: return "en_AU"; /* Australian English */
  746. case 0x080a: return "es_MX"; /* Mexican Spanish */
  747. case 0x080c: return "fr_BE"; /* Belgian French */
  748. case 0x0c0c: return "fr_CA"; /* Canadian French */
  749. case 0x100c: return "fr_CH"; /* Swiss French */
  750. case 0x0810: return "it_CH"; /* Swiss Italian */
  751. case 0x0813: return "nl_BE"; /* Belgian Dutch */
  752. case 0x0416: return "pt_BR"; /* Brazilian Portuguese */
  753. case 0x081a:
  754. case 0x0c1a: return "sr"; /* Serbian */
  755. case 0x081d: return "sv_FI"; /* Finland Swedish */
  756. default:
  757. break;
  758. }
  759. /* The general rule */
  760. switch (usLid & 0x00ff) {
  761. case 0x01: return "ar"; /* Arabic */
  762. case 0x02: return "bg"; /* Bulgarian */
  763. case 0x03: return "ca"; /* Catalan */
  764. case 0x04: return "zh"; /* Chinese */
  765. case 0x05: return "cs"; /* Czech */
  766. case 0x06: return "da"; /* Danish */
  767. case 0x07: return "de"; /* German */
  768. case 0x08: return "el"; /* Greek */
  769. case 0x09: return "en"; /* English */
  770. case 0x0a: return "es"; /* Spanish */
  771. case 0x0b: return "fi"; /* Finnish */
  772. case 0x0c: return "fr"; /* French */
  773. case 0x0d: return "he"; /* Hebrew */
  774. case 0x0e: return "hu"; /* Hungarian */
  775. case 0x0f: return "is"; /* Icelandic */
  776. case 0x10: return "it"; /* Italian */
  777. case 0x11: return "ja"; /* Japanese */
  778. case 0x12: return "ko"; /* Korean */
  779. case 0x13: return "nl"; /* Dutch */
  780. case 0x14: return "no"; /* Norwegian */
  781. case 0x15: return "pl"; /* Polish */
  782. case 0x16: return "pt"; /* Portuguese */
  783. case 0x17: return "rm"; /* Rhaeto-Romance */
  784. case 0x18: return "ro"; /* Romanian */
  785. case 0x19: return "ru"; /* Russian */
  786. case 0x1a: return "hr"; /* Croatian */
  787. case 0x1b: return "sk"; /* Slovak */
  788. case 0x1c: return "sq"; /* Albanian */
  789. case 0x1d: return "sv"; /* Swedish */
  790. case 0x1e: return "th"; /* Thai */
  791. case 0x1f: return "tr"; /* Turkish */
  792. case 0x20: return "ur"; /* Urdu */
  793. case 0x21: return "id"; /* Indonesian */
  794. case 0x22: return "uk"; /* Ukrainian */
  795. case 0x23: return "be"; /* Belarusian */
  796. case 0x24: return "sl"; /* Slovenian */
  797. case 0x25: return "et"; /* Estonian */
  798. case 0x26: return "lv"; /* Latvian */
  799. case 0x27: return "lt"; /* Lithuanian */
  800. case 0x29: return "fa"; /* Farsi */
  801. case 0x2a: return "vi"; /* Viet Nam */
  802. case 0x2b: return "hy"; /* Armenian */
  803. case 0x2c: return "az"; /* Azeri */
  804. case 0x2d: return "eu"; /* Basque */
  805. case 0x2f: return "mk"; /* Macedonian */
  806. case 0x36: return "af"; /* Afrikaans */
  807. case 0x37: return "ka"; /* Georgian */
  808. case 0x38: return "fo"; /* Faeroese */
  809. case 0x39: return "hi"; /* Hindi */
  810. case 0x3e: return "ms"; /* Malay */
  811. case 0x3f: return "kk"; /* Kazakh */
  812. default:
  813. DBG_HEX(usLid);
  814. DBG_FIXME();
  815. return NULL;
  816. }
  817. } /* end of szGetLanguage */