/*
* tConvertDosDate - convert DOS date format
*
* returns Unix time_t or -1
*/
static time_t
tConvertDosDate(const char *szDosDate)
{
struct tm tTime;
const char *pcTmp;
time_t tResult;
memset(&tTime, 0, sizeof(tTime));
pcTmp = szDosDate;
/* Get the month */
if (!isdigit(*pcTmp)) {
return (time_t)-1;
}
tTime.tm_mon = (int)(*pcTmp - '0');
pcTmp++;
if (isdigit(*pcTmp)) {
tTime.tm_mon *= 10;
tTime.tm_mon += (int)(*pcTmp - '0');
pcTmp++;
}
/* Get the first separater */
if (isalnum(*pcTmp)) {
return (time_t)-1;
}
pcTmp++;
/* Get the day */
if (!isdigit(*pcTmp)) {
return (time_t)-1;
}
tTime.tm_mday = (int)(*pcTmp - '0');
pcTmp++;
if (isdigit(*pcTmp)) {
tTime.tm_mday *= 10;
tTime.tm_mday += (int)(*pcTmp - '0');
pcTmp++;
}
/* Get the second separater */
if (isalnum(*pcTmp)) {
return (time_t)-1;
}
pcTmp++;
/* Get the year */
if (!isdigit(*pcTmp)) {
return (time_t)-1;
}
tTime.tm_year = (int)(*pcTmp - '0');
pcTmp++;
if (isdigit(*pcTmp)) {
tTime.tm_year *= 10;
tTime.tm_year += (int)(*pcTmp - '0');
pcTmp++;
}
/* Check the values */
if (tTime.tm_mon == 0 || tTime.tm_mday == 0 || tTime.tm_mday > 31) {
return (time_t)-1;
}
/* Correct the values */
tTime.tm_mon--; /* From 01-12 to 00-11 */
if (tTime.tm_year < 80) {
tTime.tm_year += 100; /* 00 means 2000 is 100 */
}
tTime.tm_isdst = -1;
tResult = mktime(&tTime);
NO_DBG_MSG(ctime(&tResult));
return tResult;
} /* end of tConvertDosDate */
/*
* szLpstr - get a zero terminate string property
*/
static char *
szLpstr(ULONG ulOffset, const UCHAR *aucBuffer)
{
char *szStart, *szResult, *szTmp;
size_t tSize;
tSize = (size_t)ulGetLong(ulOffset + 4, aucBuffer);
NO_DBG_DEC(tSize);
if (tSize == 0) {
return NULL;
}
/* Remove white space from the start of the string */
szStart = (char *)aucBuffer + ulOffset + 8;
NO_DBG_MSG(szStart);
fail(strlen(szStart) >= tSize);
while (isspace(*szStart)) {
szStart++;
}
if (szStart[0] == '\0') {
return NULL;
}
szResult = xstrdup(szStart);
/* Remove white space from the end of the string */
szTmp = szResult + strlen(szResult) - 1;
while (isspace(*szTmp)) {
*szTmp = '\0';
szTmp--;
}
NO_DBG_MSG(szResult);
return szResult;
} /* end of szLpstr */
/* Move the starting point from 01 Jan 1601 to 01 Jan 1970 */
dHi = (double)ulHi - (double)TIME_OFFSET_HI;
dLo = (double)ulLo - (double)TIME_OFFSET_LO;
NO_DBG_FLT(dHi);
NO_DBG_FLT(dLo);
/* Combine the values and divide by 10^7 to get seconds */
dTmp = dLo / 10000000.0; /* 10^7 */
dTmp += dHi * 429.4967926; /* 2^32 / 10^7 */
NO_DBG_FLT(dTmp);
/* Make a time_t */
if (dTmp - 0.5 < TIME_T_MIN || dTmp + 0.5 > TIME_T_MAX) {
return (time_t)-1;
}
tResult = dTmp < 0.0 ? (time_t)(dTmp - 0.5) : (time_t)(dTmp + 0.5);
NO_DBG_MSG(ctime(&tResult));
return tResult;
} /* end of tFiletime */
/* Read the Summery Information */
aucBuffer = xmalloc(tLength);
if (!bReadBuffer(pFile, ulStartBlock,
aulBlockDepot, tBlockDepotLen, tBlockSize,
aucBuffer, ulOffset, tLength)) {
aucBuffer = xfree(aucBuffer);
return NULL;
}
NO_DBG_PRINT_BLOCK(aucBuffer, tLength);
return aucBuffer;
} /* end of pucAnalyseSummaryInfoHeader */
/*
* vSet0SummaryInfo - set summary information from a Word for DOS file
*/
void
vSet0SummaryInfo(FILE *pFile, const UCHAR *aucHeader)
{
UCHAR *aucBuffer;
ULONG ulBeginSumdInfo, ulBeginNextBlock;
size_t tLen;
USHORT usCodepage, usOffset;
TRACE_MSG("vSet0SummaryInfo");
fail(pFile == NULL || aucHeader == NULL);
/* First check the header */
usCodepage = usGetWord(0x7e, aucHeader);
DBG_DEC(usCodepage);
switch (usCodepage) {
case 850: usLid = 0x0809; break; /* Latin1 -> British English */
case 862: usLid = 0x040d; break; /* Hebrew */
case 866: usLid = 0x0419; break; /* Russian */
case 0:
case 437:
default: usLid = 0x0409; break; /* ASCII -> American English */
}
/* Second check the summary information block */
ulBeginSumdInfo = 128 * (ULONG)usGetWord(0x1c, aucHeader);
DBG_HEX(ulBeginSumdInfo);
ulBeginNextBlock = 128 * (ULONG)usGetWord(0x6a, aucHeader);
DBG_HEX(ulBeginNextBlock);
if (ulBeginSumdInfo >= ulBeginNextBlock || ulBeginNextBlock == 0) {
/* There is no summary information block */
return;
}
tLen = (size_t)(ulBeginNextBlock - ulBeginSumdInfo);
aucBuffer = xmalloc(tLen);
/* Read the summary information block */
if (!bReadBytes(aucBuffer, tLen, ulBeginSumdInfo, pFile)) {
return;
}
usOffset = usGetWord(0, aucBuffer);
if (aucBuffer[usOffset] != 0) {
NO_DBG_MSG(aucBuffer + usOffset);
szTitle = xstrdup((char *)aucBuffer + usOffset);
}
usOffset = usGetWord(2, aucBuffer);
if (aucBuffer[usOffset] != 0) {
NO_DBG_MSG(aucBuffer + usOffset);
szAuthor = xstrdup((char *)aucBuffer + usOffset);
}
usOffset = usGetWord(12, aucBuffer);
if (aucBuffer[usOffset] != 0) {
NO_DBG_STRN(aucBuffer + usOffset, 8);
tLastSaveDtm = tConvertDosDate((char *)aucBuffer + usOffset);
}
usOffset = usGetWord(14, aucBuffer);
if (aucBuffer[usOffset] != 0) {
NO_DBG_STRN(aucBuffer + usOffset, 8);
tCreateDtm = tConvertDosDate((char *)aucBuffer + usOffset);
}
aucBuffer = xfree(aucBuffer);
} /* end of vSet0SummaryInfo */
/*
* vSet2SummaryInfo - set summary information from a WinWord 1/2 file
*/
void
vSet2SummaryInfo(FILE *pFile, int iWordVersion, const UCHAR *aucHeader)
{
UCHAR *aucBuffer;
ULONG ulBeginSumdInfo, ulBeginDocpInfo, ulTmp;
size_t tSumdInfoLen, tDocpInfoLen, tLen, tCounter, tStart;
/* Document Summary Information */
pucBuffer = pucAnalyseSummaryInfoHeader(pFile,
pPPS->tDocSummaryInfo.ulSB, pPPS->tDocSummaryInfo.ulSize,
aulBBD, tBBDLen, aulSBD, tSBDLen);
if (pucBuffer != NULL) {
vAnalyseDocumentSummaryInfo(pucBuffer);
pucBuffer = xfree(pucBuffer);
}
} /* end of vSetSummaryInfoOLE */
/*
* vSet6SummaryInfo - set summary information from a Word 6/7 file
*/
void
vSet6SummaryInfo(FILE *pFile, const pps_info_type *pPPS,
const ULONG *aulBBD, size_t tBBDLen,
const ULONG *aulSBD, size_t tSBDLen,
const UCHAR *aucHeader)
{
TRACE_MSG("vSet6SummaryInfo");
/* Header Information */
usLid = usGetWord(0x06, aucHeader); /* Language IDentification */
DBG_HEX(usLid);
/* Summery Information */
vSetSummaryInfoOLE(pFile, pPPS, aulBBD, tBBDLen, aulSBD, tSBDLen);
} /* end of vSet6SummaryInfo */
/*
* vSet8SummaryInfo - set summary information a Word 8/9/10 file
*/
void
vSet8SummaryInfo(FILE *pFile, const pps_info_type *pPPS,
const ULONG *aulBBD, size_t tBBDLen,
const ULONG *aulSBD, size_t tSBDLen,
const UCHAR *aucHeader)
{
USHORT usTmp;
TRACE_MSG("vSet8SummaryInfo");
/* Header Information */
usTmp = usGetWord(0x0a, aucHeader);
if (usTmp & BIT(14)) {
/* Language IDentification Far East */
usLid = usGetWord(0x3c, aucHeader);
} else {
/* Language IDentification */
usLid = usGetWord(0x06, aucHeader);
}
DBG_HEX(usLid);
/* Summery Information */
vSetSummaryInfoOLE(pFile, pPPS, aulBBD, tBBDLen, aulSBD, tSBDLen);
} /* end of vSet8SummaryInfo */
/*
* szGetTitle - get the title field
*/
const char *
szGetTitle(void)
{
return szTitle;
} /* end of szGetTitle */
/*
* szGetSubject - get the subject field
*/
const char *
szGetSubject(void)
{
return szSubject;
} /* end of szGetSubject */
/*
* szGetAuthor - get the author field
*/
const char *
szGetAuthor(void)
{
return szAuthor;
} /* end of szGetAuthor */
/*
* szGetLastSaveDtm - get the last save date field
*/
const char *
szGetLastSaveDtm(void)
{
static char szTime[12];
struct tm *pTime;
if (tLastSaveDtm == (time_t)-1) {
return NULL;
}
pTime = localtime(&tLastSaveDtm);
if (pTime == NULL) {
return NULL;
}
sprintf(szTime, "%04d-%02d-%02d",
pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday);
return szTime;
} /* end of szGetLastSaveDtm */
/*
* szGetModDate - get the last save date field
*/
const char *
szGetModDate(void)
{
static char szTime[20];
struct tm *pTime;
if (tLastSaveDtm == (time_t)-1) {
return NULL;
}
pTime = localtime(&tLastSaveDtm);
if (pTime == NULL) {
return NULL;
}
sprintf(szTime, "D:%04d%02d%02d%02d%02d",
pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday,
pTime->tm_hour, pTime->tm_min);
return szTime;
} /* end of szGetModDate */
/*
* szGetCreationDate - get the last save date field
*/
const char *
szGetCreationDate(void)
{
static char szTime[20];
struct tm *pTime;
if (tCreateDtm == (time_t)-1) {
return NULL;
}
pTime = localtime(&tCreateDtm);
if (pTime == NULL) {
return NULL;
}
sprintf(szTime, "D:%04d%02d%02d%02d%02d",
pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday,
pTime->tm_hour, pTime->tm_min);
return szTime;
} /* end of szGetCreationDate */
/*
* szGetCompany - get the company field
*/
const char *
szGetCompany(void)
{
return szCompany;
} /* end of szGetCompany */
/*
* szGetLanguage - get de language field
*/
const char *
szGetLanguage(void)
{
if (usLid == (USHORT)-1) {
/* No Language IDentification */
return NULL;
}
if (usLid < 999) {
/* This is a Locale, not a Language IDentification */
DBG_DEC(usLid);
return NULL;
}
/* Exceptions to the general rule */
switch (usLid) {
case 0x0404: return "zh_TW"; /* Traditional Chinese */
case 0x0804: return "zh_CN"; /* Simplified Chinese */
case 0x0c04: return "zh_HK"; /* Hong Kong Chinese */
case 0x1004: return "zh_SG"; /* Singapore Chinese */
case 0x0807: return "de_CH"; /* Swiss German */
case 0x0409: return "en_US"; /* American English */
case 0x0809: return "en_GB"; /* British English */
case 0x0c09: return "en_AU"; /* Australian English */
case 0x080a: return "es_MX"; /* Mexican Spanish */
case 0x080c: return "fr_BE"; /* Belgian French */
case 0x0c0c: return "fr_CA"; /* Canadian French */
case 0x100c: return "fr_CH"; /* Swiss French */
case 0x0810: return "it_CH"; /* Swiss Italian */
case 0x0813: return "nl_BE"; /* Belgian Dutch */
case 0x0416: return "pt_BR"; /* Brazilian Portuguese */
case 0x081a:
case 0x0c1a: return "sr"; /* Serbian */
case 0x081d: return "sv_FI"; /* Finland Swedish */
default:
break;
}
/* The general rule */
switch (usLid & 0x00ff) {
case 0x01: return "ar"; /* Arabic */
case 0x02: return "bg"; /* Bulgarian */
case 0x03: return "ca"; /* Catalan */
case 0x04: return "zh"; /* Chinese */
case 0x05: return "cs"; /* Czech */
case 0x06: return "da"; /* Danish */
case 0x07: return "de"; /* German */
case 0x08: return "el"; /* Greek */
case 0x09: return "en"; /* English */
case 0x0a: return "es"; /* Spanish */
case 0x0b: return "fi"; /* Finnish */
case 0x0c: return "fr"; /* French */
case 0x0d: return "he"; /* Hebrew */
case 0x0e: return "hu"; /* Hungarian */
case 0x0f: return "is"; /* Icelandic */
case 0x10: return "it"; /* Italian */
case 0x11: return "ja"; /* Japanese */
case 0x12: return "ko"; /* Korean */
case 0x13: return "nl"; /* Dutch */
case 0x14: return "no"; /* Norwegian */
case 0x15: return "pl"; /* Polish */
case 0x16: return "pt"; /* Portuguese */
case 0x17: return "rm"; /* Rhaeto-Romance */
case 0x18: return "ro"; /* Romanian */
case 0x19: return "ru"; /* Russian */
case 0x1a: return "hr"; /* Croatian */
case 0x1b: return "sk"; /* Slovak */
case 0x1c: return "sq"; /* Albanian */
case 0x1d: return "sv"; /* Swedish */
case 0x1e: return "th"; /* Thai */
case 0x1f: return "tr"; /* Turkish */
case 0x20: return "ur"; /* Urdu */
case 0x21: return "id"; /* Indonesian */
case 0x22: return "uk"; /* Ukrainian */
case 0x23: return "be"; /* Belarusian */
case 0x24: return "sl"; /* Slovenian */
case 0x25: return "et"; /* Estonian */
case 0x26: return "lv"; /* Latvian */
case 0x27: return "lt"; /* Lithuanian */
case 0x29: return "fa"; /* Farsi */
case 0x2a: return "vi"; /* Viet Nam */
case 0x2b: return "hy"; /* Armenian */
case 0x2c: return "az"; /* Azeri */
case 0x2d: return "eu"; /* Basque */
case 0x2f: return "mk"; /* Macedonian */
case 0x36: return "af"; /* Afrikaans */
case 0x37: return "ka"; /* Georgian */
case 0x38: return "fo"; /* Faeroese */
case 0x39: return "hi"; /* Hindi */
case 0x3e: return "ms"; /* Malay */
case 0x3f: return "kk"; /* Kazakh */
default:
DBG_HEX(usLid);
DBG_FIXME();
return NULL;
}
} /* end of szGetLanguage */