Пример #1
0
/*
 * Build the lists with Document Property Information for WinWord 1/2 files
 */
void
vGet2DopInfo(FILE *pFile, const UCHAR *aucHeader)
{
	document_block_type	tDocument;
	UCHAR	*aucBuffer;
	ULONG	ulBeginDocpInfo, ulTmp;
	size_t	tDocpInfoLen;
	USHORT	usTmp;

	ulBeginDocpInfo = ulGetLong(0x112, aucHeader); /* fcDop */
	DBG_HEX(ulBeginDocpInfo);
	tDocpInfoLen = (size_t)usGetWord(0x116, aucHeader); /* cbDop */
	DBG_DEC(tDocpInfoLen);
	if (tDocpInfoLen < 28) {
		DBG_MSG("No Document information");
		return;
	}

	aucBuffer = xmalloc(tDocpInfoLen);
	if (!bReadBytes(aucBuffer, tDocpInfoLen, ulBeginDocpInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}

	usTmp = usGetWord(0x00, aucBuffer);
	tDocument.ucHdrFtrSpecification = (UCHAR)(usTmp >> 8); /* grpfIhdt */
	tDocument.usDefaultTabWidth = usGetWord(0x0a, aucBuffer); /* dxaTab */
	ulTmp = ulGetLong(0x14, aucBuffer); /* dttmCreated */
	tDocument.tCreateDate = tConvertDTTM(ulTmp);
	ulTmp = ulGetLong(0x18, aucBuffer); /* dttmRevised */
	tDocument.tRevisedDate = tConvertDTTM(ulTmp);
	vCreateDocumentInfoList(&tDocument);

	aucBuffer = xfree(aucBuffer);
} /* end of vGet2DopInfo */
Пример #2
0
/*
 * Fill the section information block with information
 * from a WinWord 1/2 file.
 */
static void
vGet2SectionInfo(const UCHAR *aucGrpprl, size_t tBytes,
		section_block_type *pSection)
{
	int	iFodoOff, iInfoLen;
	USHORT	usCcol;
	UCHAR	ucTmp;

	fail(aucGrpprl == NULL || pSection == NULL);

	iFodoOff = 0;
	while (tBytes >= (size_t)iFodoOff + 1) {
		switch (ucGetByte(iFodoOff, aucGrpprl)) {
		case 117:	/* bkc */
			ucTmp = ucGetByte(iFodoOff + 1, aucGrpprl);
			DBG_DEC(ucTmp);
			pSection->bNewPage = ucTmp != 0 && ucTmp != 1;
			break;
		case 119:	/* ccolM1 */
			usCcol = 1 + usGetWord(iFodoOff + 1, aucGrpprl);
			DBG_DEC(usCcol);
			break;
		case 128:	/* grpfIhdt */
			pSection->ucHdrFtrSpecification =
					ucGetByte(iFodoOff + 1, aucGrpprl);
			break;
		default:
			break;
		}
		iInfoLen = iGet2InfoLength(iFodoOff, aucGrpprl);
		fail(iInfoLen <= 0);
		iFodoOff += iInfoLen;
	}
} /* end of vGet2SectionInfo */
Пример #3
0
/*
 * unincpy - copy a counted Unicode string to an single-byte string
 */
char *
unincpy(char *s1, const UCHAR *s2, size_t n)
{
	char	*pcDest;
	ULONG	ulChar;
	size_t	tLen;
	USHORT	usUni;

	for (pcDest = s1, tLen = 0; tLen < n; pcDest++, tLen++) {
		usUni = usGetWord(tLen * 2, s2);
		if (usUni == 0) {
			break;
		}
		ulChar = ulTranslateCharacters(usUni, 0, 8,
				conversion_unknown, encoding_neutral, FALSE);
		if (ulChar == IGNORE_CHARACTER) {
			ulChar = (ULONG)'?';
		}
		*pcDest = (char)ulChar;
	}
	for (; tLen < n; tLen++) {
		*pcDest++ = '\0';
	}
	return s1;
} /* end of unincpy */
Пример #4
0
/*
 * iGet8InfoLength - the length of the information for Word 8/9/10/11 files
 */
static int
iGet8InfoLength(int iByteNbr, const UCHAR *aucGrpprl)
{
	int	iTmp, iDel, iAdd;
	USHORT	usOpCode;

	usOpCode = usGetWord(iByteNbr, aucGrpprl);

	switch (usOpCode & 0xe000) {
	case 0x0000: case 0x2000:
		return 3;
	case 0x4000: case 0x8000: case 0xa000:
		return 4;
	case 0xe000:
		return 5;
	case 0x6000:
		return 6;
	case 0xc000:
		iTmp = (int)ucGetByte(iByteNbr + 2, aucGrpprl);
		if (usOpCode == 0xc615 && iTmp == 255) {
			iDel = (int)ucGetByte(iByteNbr + 3, aucGrpprl);
			iAdd = (int)ucGetByte(
					iByteNbr + 4 + iDel * 4, aucGrpprl);
			iTmp = 2 + iDel * 4 + iAdd * 3;
		}
		return 3 + iTmp;
	default:
		DBG_HEX(usOpCode);
		DBG_FIXME();
		return 1;
	}
} /* end of iGet8InfoLength */
Пример #5
0
/*
 * Build the lists with Document Property Information for Word 8/9/10/11 files
 */
void
vGet8DopInfo(FILE *pFile, const pps_type *pTable,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	document_block_type	tDocument;
	UCHAR	*aucBuffer;
	ULONG	ulBeginDocpInfo, ulTmp;
	size_t	tDocpInfoLen;
	USHORT	usTmp;

	fail(pFile == NULL || pTable == NULL || aucHeader == NULL);
	fail(aulBBD == NULL || aulSBD == NULL);

	ulBeginDocpInfo = ulGetLong(0x192, aucHeader); /* fcDop */
	NO_DBG_HEX(ulBeginSectInfo);
	tDocpInfoLen = (size_t)ulGetLong(0x196, aucHeader); /* lcbDop */
	NO_DBG_DEC(tSectInfoLen);
	if (tDocpInfoLen < 28) {
		DBG_MSG("No Document information");
		return;
	}

	aucBuffer = aucFillInfoBuffer(pFile, pTable,
			aulBBD, tBBDLen, aulSBD, tSBDLen,
			ulBeginDocpInfo, tDocpInfoLen);
	if (aucBuffer == NULL) {
		return;
	}

	usTmp = usGetWord(0x00, aucBuffer);
	tDocument.ucHdrFtrSpecification = (UCHAR)(usTmp >> 8); /* grpfIhdt */
	tDocument.usDefaultTabWidth = usGetWord(0x0a, aucBuffer); /* dxaTab */
	ulTmp = ulGetLong(0x14, aucBuffer); /* dttmCreated */
	tDocument.tCreateDate = tConvertDTTM(ulTmp);
	ulTmp = ulGetLong(0x18, aucBuffer); /* dttmRevised */
	tDocument.tRevisedDate = tConvertDTTM(ulTmp);
	vCreateDocumentInfoList(&tDocument);

	aucBuffer = xfree(aucBuffer);
} /* end of vGet8DopInfo */
Пример #6
0
/*
 * Fill the picture information block with information
 * from a Word 8/9/10/11 file.
 * Returns TRUE when successful, otherwise FALSE
 */
static BOOL
bGet8PicInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, picture_block_type *pPicture)
{
	ULONG	ulTmp;
	int	iFodoOff, iInfoLen;
	BOOL	bFound;
	UCHAR	ucTmp;

	fail(iFodo <= 0 || aucGrpprl == NULL || pPicture == NULL);

	iFodoOff = 0;
	bFound = FALSE;
	while (iBytes >= iFodoOff + 2) {
		switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
#if 0
		case 0x0806:	/* fData */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (ucTmp == 0x01) {
				/* Not a picture, but a form field */
				return FALSE;
			}
			DBG_DEC_C(ucTmp != 0, ucTmp);
			break;
#endif
		case 0x080a:	/* fOle2 */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (ucTmp == 0x01) {
				/* Not a picture, but an OLE object */
				return FALSE;
			}
			DBG_DEC_C(ucTmp != 0, ucTmp);
			break;
		case 0x680e:	/* fcObj */
			ulTmp = ulGetLong(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_HEX(ulTmp);
			break;
		case 0x6a03:	/* fcPic */
			pPicture->ulPictureOffset = ulGetLong(
					iFodo + iFodoOff + 2, aucGrpprl);
			bFound = TRUE;
			break;
		default:
			break;
		}
		iInfoLen = iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
		fail(iInfoLen <= 0);
		iFodoOff += iInfoLen;
	}
	return bFound;
} /* end of bGet8PicInfo */
Пример #7
0
/*
 * Get the left indentation value from the style information block
 *
 * Returns the value when found, otherwise 0
 */
static short
sGetLeftIndent(const UCHAR *aucGrpprl, size_t tBytes)
{
	int	iOffset, iInfoLen;
	USHORT	usOpCode, usTmp;

	fail(aucGrpprl == NULL);

	iOffset = 0;
	while (tBytes >= (size_t)iOffset + 4) {
		usOpCode = usGetWord(iOffset, aucGrpprl);
		if (usOpCode == 0x840f) {	/* dxaLeft */
			usTmp = usGetWord(iOffset + 2, aucGrpprl);
			if (usTmp <= 0x7fff) {
				NO_DBG_DEC(usTmp);
				return (short)usTmp;
			}
		}
		iInfoLen = iGet8InfoLength(iOffset, aucGrpprl);
		fail(iInfoLen <= 0);
		iOffset += iInfoLen;
	}
	return 0;
} /* end of sGetLeftIndent */
Пример #8
0
/*
 * unilen - calculate the length of a Unicode string
 *
 * returns the length in bytes
 */
size_t
unilen(const UCHAR *s)
{
	size_t	tLen;
	USHORT	usUni;

	tLen = 0;
	for (;;) {
		usUni = usGetWord(tLen, s);
		if (usUni == 0) {
			return tLen;
		}
		tLen += 2;
	}
} /* end of unilen */
Пример #9
0
/*
 * 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 */
Пример #10
0
/*
 * 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 */
Пример #11
0
/*
 * Build the list with footnote information for WinWord 1/2 files
 */
static void
vGet2FootnotesInfo(FILE *pFile, const UCHAR *aucHeader)
{
	UCHAR	*aucBuffer;
	ULONG	ulFileOffset, ulBeginOfText, ulOffset, ulBeginFootnoteInfo;
	size_t	tFootnoteInfoLen;
	size_t	tIndex;

	TRACE_MSG("vGet2FootnotesInfo");

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginOfText = ulGetLong(0x18, aucHeader); /* fcMin */
	NO_DBG_HEX(ulBeginOfText);
	ulBeginFootnoteInfo = ulGetLong(0x64, aucHeader); /* fcPlcffndRef */
	NO_DBG_HEX(ulBeginFootnoteInfo);
	tFootnoteInfoLen = (size_t)usGetWord(0x68, aucHeader); /* cbPlcffndRef */
	NO_DBG_DEC(tFootnoteInfoLen);

	if (tFootnoteInfoLen < 10) {
		DBG_MSG("No Footnotes in this document");
		return;
	}

	aucBuffer = xmalloc(tFootnoteInfoLen);
	if (!bReadBytes(aucBuffer,
			tFootnoteInfoLen, ulBeginFootnoteInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tFootnoteInfoLen);

	fail(tFootnoteListLength != 0);
	tFootnoteListLength = (tFootnoteInfoLen - 4) / 6;
	fail(tFootnoteListLength == 0);

	fail(aulFootnoteList != NULL);
	aulFootnoteList = xcalloc(tFootnoteListLength, sizeof(ULONG));

	for (tIndex = 0; tIndex < tFootnoteListLength; tIndex++) {
		ulOffset = ulGetLong(tIndex * 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulFileOffset = ulCharPos2FileOffset(ulBeginOfText + ulOffset);
		NO_DBG_HEX(ulFileOffset);
		aulFootnoteList[tIndex] = ulFileOffset;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet2FootnotesInfo */
Пример #12
0
/*
 * iInitDocumentDOS - initialize an DOS document
 *
 * Returns the version of Word that made the document or -1
 */
int
iInitDocumentDOS(FILE *pFile, long lFilesize)
{
	int	iWordVersion;
	BOOL	bSuccess;
	USHORT	usIdent;
	UCHAR	aucHeader[128];

	fail(pFile == NULL);

	if (lFilesize < 128) {
		return -1;
	}

	/* Read the headerblock */
	if (!bReadBytes(aucHeader, 128, 0x00, pFile)) {
		return -1;
	}
	/* Get the "magic number" from the header */
	usIdent = usGetWord(0x00, aucHeader);
	DBG_HEX(usIdent);
	fail(usIdent != 0xbe31);	/* Word for DOS */
	iWordVersion = iGetVersionNumber(aucHeader);
	if (iWordVersion != 0) {
		werr(0, "This file is not from 'Word for DOS'.");
		return -1;
	}
	bSuccess = bGetDocumentText(pFile, lFilesize, aucHeader);
	if (bSuccess) {
		vGetPropertyInfo(pFile, NULL,
				NULL, 0, NULL, 0,
				aucHeader, iWordVersion);
		vSetDefaultTabWidth(pFile, NULL,
				NULL, 0, NULL, 0,
				aucHeader, iWordVersion);
		vGetNotesInfo(pFile, NULL,
				NULL, 0, NULL, 0,
				aucHeader, iWordVersion);
	}
	return bSuccess ? iWordVersion : -1;
} /* end of iInitDocumentDOS */
Пример #13
0
/*
 * Build the list with Header/Footer Information for WinWord 1/2 files
 */
void
vGet2HdrFtrInfo(FILE *pFile, const UCHAR *aucHeader)
{
	ULONG	*aulCharPos;
	UCHAR	*aucBuffer;
	ULONG	ulHdrFtrOffset, ulBeginHdrFtrInfo;
	size_t	tHdrFtrInfoLen, tIndex, tOffset, tLen;

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginHdrFtrInfo = ulGetLong(0x9a, aucHeader); /* fcPlcfhdd */
	NO_DBG_HEX(ulBeginHdrFtrInfo);
	tHdrFtrInfoLen = (size_t)usGetWord(0x9e, aucHeader); /* cbPlcfhdd */
	NO_DBG_DEC(tHdrFtrInfoLen);
	if (tHdrFtrInfoLen < 8) {
		DBG_DEC_C(tHdrFtrInfoLen != 0, tHdrFtrInfoLen);
		return;
	}

	aucBuffer = xmalloc(tHdrFtrInfoLen);
	if (!bReadBytes(aucBuffer, tHdrFtrInfoLen, ulBeginHdrFtrInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tHdrFtrInfoLen);

	tLen = tHdrFtrInfoLen / 4 - 1;
	/* Save the header/footer offsets */
	aulCharPos = xcalloc(tLen, sizeof(ULONG));
	for (tIndex = 0, tOffset = 0;
	     tIndex < tLen;
	     tIndex++, tOffset += 4) {
		ulHdrFtrOffset = ulGetLong(tOffset, aucBuffer);
		NO_DBG_HEX(ulHdrFtrOffset);
		aulCharPos[tIndex] = ulHdrFtrOffset2CharPos(ulHdrFtrOffset);
		NO_DBG_HEX(aulCharPos[tIndex]);
	}
	vCreat2HdrFtrInfoList(aulCharPos, tLen);
	aulCharPos = xfree(aulCharPos);
	aucBuffer = xfree(aucBuffer);
} /* end of vGet2HdrFtrInfo */
Пример #14
0
/*
 * iInitDocumentMAC - initialize an MAC document
 *
 * Returns the version of Word that made the document or -1
 */
int
iInitDocumentMAC(FILE *pFile, long lFilesize)
{
	int	iWordVersion;
	BOOL	bSuccess;
	USHORT	usIdent;
	UCHAR	aucHeader[256];

	fail(pFile == NULL);

	if (lFilesize < 256) {
		return -1;
	}

	/* Read the headerblock */
	if (!bReadBytes(aucHeader, 256, 0x00, pFile)) {
		return -1;
	}
	/* Get the "magic number" from the header */
	usIdent = usGetWord(0x00, aucHeader);
	DBG_HEX(usIdent);
	fail(usIdent != 0x37fe);	/* MacWord 4 and 5 */
	iWordVersion = iGetVersionNumber(aucHeader);
	if (iWordVersion != 4 && iWordVersion != 5) {
		werr(0, "This file is not from ''Mac Word 4 or 5'.");
		return -1;
	}
	bSuccess = bGetDocumentText(pFile, aucHeader);
	if (bSuccess) {
		vGetPropertyInfo(pFile, NULL,
				NULL, 0, NULL, 0,
				aucHeader, iWordVersion);
		vSetDefaultTabWidth(pFile, NULL,
				NULL, 0, NULL, 0,
				aucHeader, iWordVersion);
	}
	return bSuccess ? iWordVersion : -1;
} /* end of iInitDocumentMAC */
Пример #15
0
/*
 * Fill the style information block with information
 * from a WinWord 1/2 file.
 */
void
vGet2StyleInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, style_block_type *pStyle)
{
	int	iFodoOff, iInfoLen;
	int	iTmp, iDel, iAdd;
	short	sTmp;
	UCHAR	ucTmp;

	fail(iFodo < 0 || aucGrpprl == NULL || pStyle == NULL);

	NO_DBG_DEC(pStyle->usIstd);

	iFodoOff = 0;
	while (iBytes >= iFodoOff + 1) {
		iInfoLen = 0;
		switch (ucGetByte(iFodo + iFodoOff, aucGrpprl)) {
		case   2:	/* istd */
			sTmp = (short)ucGetByte(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(sTmp);
			break;
		case   5:	/* jc */
			pStyle->ucAlignment = ucGetByte(
					iFodo + iFodoOff + 1, aucGrpprl);
			break;
		case  12:	/* nfcSeqNumb */
			pStyle->ucNFC = ucGetByte(
					iFodo + iFodoOff + 1, aucGrpprl);
			break;
		case  13:	/* nLvlAnm */
			ucTmp = ucGetByte(iFodo + iFodoOff + 1, aucGrpprl);
			pStyle->ucNumLevel = ucTmp;
			pStyle->bNumPause =
				eGetNumType(ucTmp) == level_type_pause;
			break;
		case  15:	/* ChgTabsPapx */
		case  23:	/* ChgTabs */
			iTmp = (int)ucGetByte(iFodo + iFodoOff + 1, aucGrpprl);
			if (iTmp < 2) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iTmp);
			iDel = (int)ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (iTmp < 2 + 2 * iDel) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iDel);
			iAdd = (int)ucGetByte(
				iFodo + iFodoOff + 3 + 2 * iDel, aucGrpprl);
			if (iTmp < 2 + 2 * iDel + 2 * iAdd) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iAdd);
			break;
		case  16:	/* dxaRight */
			pStyle->sRightIndent = (short)usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(pStyle->sRightIndent);
			break;
		case  17:	/* dxaLeft */
			pStyle->sLeftIndent = (short)usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(pStyle->sLeftIndent);
			break;
		case  18:	/* Nest dxaLeft */
			sTmp = (short)usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			pStyle->sLeftIndent += sTmp;
			if (pStyle->sLeftIndent < 0) {
				pStyle->sLeftIndent = 0;
			}
			NO_DBG_DEC(sTmp);
			NO_DBG_DEC(pStyle->sLeftIndent);
			break;
		case  19:	/* dxaLeft1 */
			pStyle->sLeftIndent1 = (short)usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(pStyle->sLeftIndent1);
			break;
		case  21:	/* dyaBefore */
			pStyle->usBeforeIndent = usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(pStyle->usBeforeIndent);
			break;
		case  22:	/* dyaAfter */
			pStyle->usAfterIndent = usGetWord(
					iFodo + iFodoOff + 1, aucGrpprl);
			NO_DBG_DEC(pStyle->usAfterIndent);
			break;
		default:
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen =
				iGet2InfoLength(iFodo + iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}
} /* end of vGet2StyleInfo */
Пример #16
0
/*
 * 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;

	TRACE_MSG("vSet2SummaryInfo");

	fail(pFile == NULL || aucHeader == NULL);
	fail(iWordVersion != 1 && iWordVersion != 2);

	/* First check the header */
	usLid = usGetWord(0x06, aucHeader); /* Language IDentification */
	DBG_HEX(usLid);
	if (usLid < 999 && iWordVersion == 1) {
		switch (usLid) {
		case   1: usLid = 0x0409; break;	/* American English */
		case   2: usLid = 0x0c0c; break;	/* Canadian French */
		case  31: usLid = 0x0413; break;	/* Dutch */
		case  33: usLid = 0x040c; break;	/* French */
		case  34: usLid = 0x040a; break;	/* Spanish */
		case  36: usLid = 0x040e; break;	/* Hungarian */
		case  39: usLid = 0x0410; break;	/* Italian */
		case  44: usLid = 0x0809; break;	/* British English */
		case  45: usLid = 0x0406; break;	/* Danish */
		case  46: usLid = 0x041f; break;	/* Swedish */
		case  47: usLid = 0x0414; break;	/* Norwegian */
		case  48: usLid = 0x0415; break;	/* Polish */
		case  49: usLid = 0x0407; break;	/* German */
		case 351: usLid = 0x0816; break;	/* Portuguese */
		case 358: usLid = 0x040b; break;	/* Finnish */
		default:
			DBG_DEC(usLid);
			DBG_FIXME();
			usLid = 0x0409;		/* American English */
			break;
		}
	}

	if (iWordVersion != 2) {
		/* Unknown where to find the associated strings */
		return;
	}

	/* Second check the associated strings */
	ulBeginSumdInfo = ulGetLong(0x118, aucHeader); /* fcSttbfAssoc */
	DBG_HEX(ulBeginSumdInfo);
	tSumdInfoLen = (size_t)usGetWord(0x11c, aucHeader); /* cbSttbfAssoc */
	DBG_DEC(tSumdInfoLen);

	if (tSumdInfoLen == 0) {
		/* There is no summary information */
		return;
	}

	aucBuffer = xmalloc(tSumdInfoLen);
	if (!bReadBytes(aucBuffer, tSumdInfoLen, ulBeginSumdInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tSumdInfoLen);
	tLen = (size_t)ucGetByte(0, aucBuffer);
	DBG_DEC_C(tSumdInfoLen != tLen, tSumdInfoLen);
	DBG_DEC_C(tSumdInfoLen != tLen, tLen);
	tStart = 1;
	for (tCounter = 0; tCounter < 17; tCounter++) {
		if (tStart >= tSumdInfoLen) {
			break;
		}
		tLen = (size_t)ucGetByte(tStart, aucBuffer);
		if (tLen != 0) {
			NO_DBG_DEC(tCounter);
			NO_DBG_STRN(aucBuffer + tStart + 1, tLen);
			switch (tCounter) {
			case 3:
				szTitle = xmalloc(tLen + 1);
				strncpy(szTitle,
					(char *)aucBuffer + tStart + 1, tLen);
				szTitle[tLen] = '\0';
				break;
			case 4:
				szSubject = xmalloc(tLen + 1);
				strncpy(szSubject,
					(char *)aucBuffer + tStart + 1, tLen);
				szSubject[tLen] = '\0';
				break;
			case 7:
				szAuthor = xmalloc(tLen + 1);
				strncpy(szAuthor,
					(char *)aucBuffer + tStart + 1, tLen);
				szAuthor[tLen] = '\0';
				break;
			default:
				break;
			}
		}
		tStart += tLen + 1;
	}
	aucBuffer = xfree(aucBuffer);

	/* Third check the document properties */
	ulBeginDocpInfo = ulGetLong(0x112, aucHeader); /* fcDop */
	DBG_HEX(ulBeginDocpInfo);
	tDocpInfoLen = (size_t)usGetWord(0x116, aucHeader); /* cbDop */
	DBG_DEC(tDocpInfoLen);
	if (tDocpInfoLen < 12) {
		return;
	}

	aucBuffer = xmalloc(tDocpInfoLen);
	if (!bReadBytes(aucBuffer, tDocpInfoLen, ulBeginDocpInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
        ulTmp = ulGetLong(0x14, aucBuffer); /* dttmCreated */
	tCreateDtm = tConvertDTTM(ulTmp);
        ulTmp = ulGetLong(0x18, aucBuffer); /* dttmRevised */
	tLastSaveDtm = tConvertDTTM(ulTmp);
	aucBuffer = xfree(aucBuffer);
} /* end of vSet2SummaryInfo */
Пример #17
0
/*
 * Fill the section information block with information
 * from a Word 8/9/10/11 file.
 */
static void
vGet8SectionInfo(const UCHAR *aucGrpprl, size_t tBytes,
		section_block_type *pSection)
{
	UINT	uiIndex;
	int	iFodoOff, iInfoLen, iSize, iTmp;
	USHORT	usCcol;
	UCHAR	ucTmp;

	fail(aucGrpprl == NULL || pSection == NULL);

	iFodoOff = 0;
	while (tBytes >= (size_t)iFodoOff + 2) {
		iInfoLen = 0;
		switch (usGetWord(iFodoOff, aucGrpprl)) {
		case 0x3009:	/* bkc */
			ucTmp = ucGetByte(iFodoOff + 2, aucGrpprl);
			DBG_DEC(ucTmp);
			pSection->bNewPage = ucTmp != 0 && ucTmp != 1;
			break;
		case 0x3014:	/* grpfIhdt */
			pSection->ucHdrFtrSpecification =
					ucGetByte(iFodoOff + 2, aucGrpprl);
			break;
		case 0x500b:	/* ccolM1 */
			usCcol = 1 + usGetWord(iFodoOff + 2, aucGrpprl);
			DBG_DEC(usCcol);
			break;
		case 0xd202:	/* olstAnm */
			iSize = (int)ucGetByte(iFodoOff + 2, aucGrpprl);
			DBG_DEC_C(iSize != 212, iSize);
			for (uiIndex = 0, iTmp = iFodoOff + 3;
			     uiIndex < 9 && iTmp < iFodoOff + 3 + iSize - 15;
			     uiIndex++, iTmp += 16) {
				pSection->aucNFC[uiIndex] =
						ucGetByte(iTmp, aucGrpprl);
				DBG_DEC(pSection->aucNFC[uiIndex]);
				ucTmp = ucGetByte(iTmp + 3, aucGrpprl);
				DBG_HEX(ucTmp);
				if ((ucTmp & BIT(2)) != 0) {
					pSection->usNeedPrevLvl |=
							(USHORT)BIT(uiIndex);
				}
				if ((ucTmp & BIT(3)) != 0) {
					pSection->usHangingIndent |=
							(USHORT)BIT(uiIndex);
				}
			}
			DBG_HEX(pSection->usNeedPrevLvl);
			DBG_HEX(pSection->usHangingIndent);
			break;
		default:
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen = iGet8InfoLength(iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}
} /* end of vGet8SectionInfo */
Пример #18
0
/*
 * pucAnalyseSummaryInfoHeader-
 */
static UCHAR *
pucAnalyseSummaryInfoHeader(FILE *pFile,
	ULONG ulStartBlock, ULONG ulSize,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen)
{
	const ULONG	*aulBlockDepot;
	UCHAR	*aucBuffer;
	size_t	tBlockDepotLen, tBlockSize, tSectionCount, tLength;
	ULONG	ulTmp, ulOffset;
	USHORT	usLittleEndian, usEmpty, usOS, usVersion;
	UCHAR	aucHdr[P_HEADER_SZ], aucSecLst[P_SECTION_MAX_SZ];

	if (ulSize < MIN_SIZE_FOR_BBD_USE) {
		/* Use the Small Block Depot */
		aulBlockDepot = aulSBD;
		tBlockDepotLen = tSBDLen;
		tBlockSize = SMALL_BLOCK_SIZE;
	} else {
		/* Use the Big Block Depot */
		aulBlockDepot = aulBBD;
		tBlockDepotLen = tBBDLen;
		tBlockSize = BIG_BLOCK_SIZE;
	}

	if (tBlockDepotLen == 0) {
		DBG_MSG("The Block Depot length is zero");
		return NULL;
	}

	/* Read the Summery Information header */
	if (!bReadBuffer(pFile, ulStartBlock,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucHdr, 0, P_HEADER_SZ)) {
		return NULL;
	}
	NO_DBG_PRINT_BLOCK(aucHdr, P_HEADER_SZ);

	/* Analyse the Summery Information header */
	usLittleEndian =  usGetWord(0, aucHdr);
	if (usLittleEndian != 0xfffe) {
		DBG_HEX(usLittleEndian);
		DBG_MSG_C(usLittleEndian == 0xfeff, "Big endian");
		return NULL;
	}
	usEmpty =  usGetWord(2, aucHdr);
	if (usEmpty != 0x0000) {
		DBG_DEC(usEmpty);
		return NULL;
	}
	ulTmp = ulGetLong(4, aucHdr);
	DBG_HEX(ulTmp);
	usOS = (USHORT)(ulTmp >> 16);
	usVersion = (USHORT)(ulTmp & 0xffff);
	switch (usOS) {
	case 0:
		DBG_MSG("Win16");
		DBG_HEX(usVersion);
		break;
	case 1:
		DBG_MSG("MacOS");
		DBG_HEX(usVersion);
		break;
	case 2:
		DBG_MSG("Win32");
		DBG_HEX(usVersion);
		break;
	default:
		DBG_DEC(usOS);
		DBG_HEX(usVersion);
		break;
	}
	tSectionCount = (size_t)ulGetLong(24, aucHdr);
	DBG_DEC_C(tSectionCount != 1 && tSectionCount != 2, tSectionCount);
	if (tSectionCount != 1 && tSectionCount != 2) {
		return NULL;
	}

	/* Read the Summery Information Section Lists */
	if (!bReadBuffer(pFile, ulStartBlock,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucSecLst, P_HEADER_SZ, P_SECTION_SZ(tSectionCount))) {
		return NULL;
	}
	NO_DBG_PRINT_BLOCK(aucSecLst, P_SECTION_SZ(tSectionCount));

	ulTmp = ulGetLong(0, aucSecLst);
	DBG_HEX(ulTmp);
	ulTmp = ulGetLong(4, aucSecLst);
	DBG_HEX(ulTmp);
	ulTmp = ulGetLong(8, aucSecLst);
	DBG_HEX(ulTmp);
	ulTmp = ulGetLong(12, aucSecLst);
	DBG_HEX(ulTmp);
	ulOffset = ulGetLong(16, aucSecLst);
	DBG_DEC_C(ulOffset != P_HEADER_SZ + P_SECTIONLIST_SZ &&
		ulOffset != P_HEADER_SZ + 2 * P_SECTIONLIST_SZ,
		ulOffset);
	fail(ulOffset != P_HEADER_SZ + P_SECTIONLIST_SZ &&
		ulOffset != P_HEADER_SZ + 2 * P_SECTIONLIST_SZ);
	tLength =
		(size_t)ulGetLong(tSectionCount * P_SECTIONLIST_SZ, aucSecLst);
	NO_DBG_HEX(tLength);
	fail(ulOffset + tLength > ulSize);

	/* 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 */
Пример #19
0
/*
 * 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 */
Пример #20
0
/*
 * Translate the rowinfo to a member of the row_info enumeration
 */
row_info_enum
eGet8RowInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, row_block_type *pRow)
{
	int	iFodoOff, iInfoLen;
	int	iIndex, iSize, iCol;
	int	iPosCurr, iPosPrev;
	USHORT	usTmp;
	BOOL	bFound2416_0, bFound2416_1, bFound2417_0, bFound2417_1;
	BOOL	bFound244b_0, bFound244b_1, bFound244c_0, bFound244c_1;
	BOOL	bFoundd608;

	fail(iFodo < 0 || aucGrpprl == NULL || pRow == NULL);

	iFodoOff = 0;
	bFound2416_0 = FALSE;
	bFound2416_1 = FALSE;
	bFound2417_0 = FALSE;
	bFound2417_1 = FALSE;
	bFound244b_0 = FALSE;
	bFound244b_1 = FALSE;
	bFound244c_0 = FALSE;
	bFound244c_1 = FALSE;
	bFoundd608 = FALSE;
	while (iBytes >= iFodoOff + 2) {
		iInfoLen = 0;
		switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
		case 0x2416:	/* fInTable */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound2416_1 = TRUE;
			} else {
				bFound2416_0 = TRUE;
			}
			break;
		case 0x2417:	/* fTtp */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound2417_1 = TRUE;
			} else {
				bFound2417_0 = TRUE;
			}
			break;
		case 0x244b:	/* sub-table fInTable */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound244b_1 = TRUE;
			} else {
				bFound244b_0 = TRUE;
			}
			break;
		case 0x244c:	/* sub-table fTtp */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound244c_1 = TRUE;
			} else {
				bFound244c_0 = TRUE;
			}
			break;
		case 0x6424:	/* brcTop */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_TOP;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_TOP;
			}
			break;
		case 0x6425:	/* brcLeft */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_LEFT;
			}
			break;
		case 0x6426:	/* brcBottom */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM;
			}
			break;
		case 0x6427:	/* brcRight */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_RIGHT;
			}
			break;
		case 0xd606:	/* cDefTable10 */
			DBG_MSG("0xd606: sprmTDefTable10");
			iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC(iSize);
			break;
		case 0xd608:	/* cDefTable */
			iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			if (iSize < 6 || iBytes < iFodoOff + 8) {
				DBG_DEC(iSize);
				DBG_DEC(iFodoOff);
				iInfoLen = 2;
				break;
			}
			iCol = (int)ucGetByte(iFodo + iFodoOff + 4, aucGrpprl);
			if (iCol < 1 ||
			    iBytes < iFodoOff + 4 + (iCol + 1) * 2) {
				DBG_DEC(iCol);
				DBG_DEC(iFodoOff);
				iInfoLen = 2;
				break;
			}
			if (iCol >= (int)elementsof(pRow->asColumnWidth)) {
				DBG_DEC(iCol);
				werr(1, "The number of columns is corrupt");
			}
			pRow->ucNumberOfColumns = (UCHAR)iCol;
			iPosPrev = (int)(short)usGetWord(
					iFodo + iFodoOff + 5,
					aucGrpprl);
			for (iIndex = 0; iIndex < iCol; iIndex++) {
				iPosCurr = (int)(short)usGetWord(
					iFodo + iFodoOff + 7 + iIndex * 2,
					aucGrpprl);
				pRow->asColumnWidth[iIndex] =
						(short)(iPosCurr - iPosPrev);
				iPosPrev = iPosCurr;
			}
			bFoundd608 = TRUE;
			break;
		default:
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen =
				iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}

	if (bFound2417_1 && bFoundd608) {
		return found_end_of_row;
	}
	if (bFound2417_0 && !bFoundd608) {
		return found_not_end_of_row;
	}
	if (bFound2416_1 || bFound244b_1) {
		return found_a_cell;
	}
	if (bFound2416_0 || bFound244b_0) {
		return found_not_a_cell;
	}
	return found_nothing;
} /* end of eGet8RowInfo */
Пример #21
0
/*
 * Build the lists with Section Property Information for Word 8/9/10/11 files
 */
void
vGet8SepInfo(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	section_block_type	tSection;
	ULONG	*aulSectPage, *aulCharPos;
	UCHAR	*aucBuffer, *aucFpage;
	ULONG	ulBeginOfText, ulTextOffset, ulBeginSectInfo;
	size_t	tSectInfoLen, tIndex, tOffset, tLen, tBytes;
	UCHAR	aucTmp[2];

	fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
	fail(aulBBD == NULL || aulSBD == NULL);

	ulBeginOfText = ulGetLong(0x18, aucHeader); /* fcMin */
	NO_DBG_HEX(ulBeginOfText);
	ulBeginSectInfo = ulGetLong(0xca, aucHeader); /* fcPlcfsed */
	NO_DBG_HEX(ulBeginSectInfo);
	tSectInfoLen = (size_t)ulGetLong(0xce, aucHeader); /* lcbPlcfsed */
	NO_DBG_DEC(tSectInfoLen);
	if (tSectInfoLen < 4) {
		DBG_DEC(tSectInfoLen);
		return;
	}

	aucBuffer = aucFillInfoBuffer(pFile, &pPPS->tTable,
			aulBBD, tBBDLen, aulSBD, tSBDLen,
			ulBeginSectInfo, tSectInfoLen);
	if (aucBuffer == NULL) {
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tSectInfoLen);

	/* Read the Section Descriptors */
	tLen = (tSectInfoLen - 4) / 16;
	/* Save the section offsets */
	aulCharPos = xcalloc(tLen, sizeof(ULONG));
	for (tIndex = 0, tOffset = 0;
	     tIndex < tLen;
	     tIndex++, tOffset += 4) {
		ulTextOffset = ulGetLong(tOffset, aucBuffer);
		NO_DBG_HEX(ulTextOffset);
		aulCharPos[tIndex] = ulBeginOfText + ulTextOffset;
		NO_DBG_HEX(aulCharPos[tIndex]);
	}
	/* Save the Sepx offsets */
	aulSectPage = xcalloc(tLen, sizeof(ULONG));
	for (tIndex = 0, tOffset = (tLen + 1) * 4;
	     tIndex < tLen;
	     tIndex++, tOffset += 12) {
		 aulSectPage[tIndex] = ulGetLong(tOffset + 2, aucBuffer);
		 NO_DBG_HEX(aulSectPage[tIndex]); /* fcSepx */
	}
	aucBuffer = xfree(aucBuffer);

	/* Read the Section Properties */
	for (tIndex = 0; tIndex < tLen; tIndex++) {
		if (aulSectPage[tIndex] == FC_INVALID) {
			vDefault2SectionInfoList(aulCharPos[tIndex]);
			continue;
		}
		/* Get the number of bytes to read */
		if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
				aulBBD, tBBDLen, BIG_BLOCK_SIZE,
				aucTmp, aulSectPage[tIndex], 2)) {
			continue;
		}
		tBytes = 2 + (size_t)usGetWord(0, aucTmp);
		NO_DBG_DEC(tBytes);
		/* Read the bytes */
		aucFpage = xmalloc(tBytes);
		if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
				aulBBD, tBBDLen, BIG_BLOCK_SIZE,
				aucFpage, aulSectPage[tIndex], tBytes)) {
			aucFpage = xfree(aucFpage);
			continue;
		}
		NO_DBG_PRINT_BLOCK(aucFpage, tBytes);
		/* Process the bytes */
		vGetDefaultSection(&tSection);
		vGet8SectionInfo(aucFpage + 2, tBytes - 2, &tSection);
		vAdd2SectionInfoList(&tSection, aulCharPos[tIndex]);
		aucFpage = xfree(aucFpage);
	}
	aulCharPos = xfree(aulCharPos);
	aulSectPage = xfree(aulSectPage);
} /* end of vGet8SepInfo */
Пример #22
0
/*
 * Build the list with footnote information for Word for DOS files
 */
static void
vGet0FootnotesInfoAndText(FILE *pFile, const UCHAR *aucHeader)
{
	footnote_local_type	*pCurr;
	UCHAR	*aucBuffer;
	ULONG	ulFileOffset, ulBeginOfText, ulOffset, ulBeginFootnoteInfo;
	ULONG	ulCharPos, ulBeginNextBlock;
	size_t	tFootnotes, tFootnoteInfoLen;
	size_t	tIndex;
	UCHAR   aucTmp[2];

	TRACE_MSG("vGet0FootnotesInfoAndText");

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginOfText = 128;
	NO_DBG_HEX(ulBeginOfText);
	ulBeginFootnoteInfo =  128 * (ULONG)usGetWord(0x14, aucHeader);
	DBG_HEX(ulBeginFootnoteInfo);
	ulBeginNextBlock = 128 * (ULONG)usGetWord(0x16, aucHeader);
	DBG_HEX(ulBeginNextBlock);

	if (ulBeginFootnoteInfo == ulBeginNextBlock) {
		DBG_MSG("No Footnotes in this document");
		return;
	}

	/* Read the the number of footnotes + 1 */
	if (!bReadBytes(aucTmp, 2, ulBeginFootnoteInfo, pFile)) {
		return;
	}
	tFootnotes = (size_t)usGetWord(0, aucTmp);
	if (tFootnotes < 2) {
		DBG_MSG("No Footnotes in this document (2)");
	}
	DBG_DEC(tFootnotes);
	tFootnoteInfoLen =  8 * tFootnotes;

	aucBuffer = xmalloc(tFootnoteInfoLen);
	if (!bReadBytes(aucBuffer,
			tFootnoteInfoLen, ulBeginFootnoteInfo + 4, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	DBG_PRINT_BLOCK(aucBuffer, tFootnoteInfoLen);

	/* Get footnote information */
	fail(tFootnoteListLength != 0);
	tFootnoteListLength = tFootnotes - 1;
	fail(tFootnoteListLength == 0);

	fail(aulFootnoteList != NULL);
	aulFootnoteList = xcalloc(tFootnoteListLength, sizeof(ULONG));

	for (tIndex = 0; tIndex < tFootnoteListLength; tIndex++) {
		ulOffset = ulGetLong(tIndex * 8, aucBuffer);
		DBG_HEX(ulOffset);
		ulFileOffset = ulCharPos2FileOffset(ulBeginOfText + ulOffset);
		DBG_HEX(ulFileOffset);
		aulFootnoteList[tIndex] = ulFileOffset;
	}

	/* Get footnote text */
	fail(tFootnoteTextLength != 0);
	tFootnoteTextLength = tFootnotes - 1;
	fail(tFootnoteTextLength == 0);

	fail(pFootnoteText != NULL);
	pFootnoteText = xcalloc(tFootnoteTextLength,
				sizeof(footnote_local_type));

	for (tIndex = 0; tIndex < tFootnoteTextLength; tIndex++) {
		pCurr = pFootnoteText + tIndex;
		pCurr->tInfo.szText = NULL;
		ulOffset = ulGetLong(tIndex * 8 + 4, aucBuffer);
		DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfText + ulOffset;
		DBG_HEX(ulCharPos);
		DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosStart = ulCharPos;
		ulOffset = ulGetLong((tIndex + 1) * 8 + 4, aucBuffer);
		DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfText + ulOffset;
		DBG_HEX(ulCharPos);
		DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosNext = ulCharPos;
		pCurr->bUseful = pCurr->ulCharPosStart != pCurr->ulCharPosNext;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet0FootnotesInfoAndText */
Пример #23
0
/*
 * Fill the style information block with information
 * from a Word 8/9/10/11 file.
 */
void
vGet8StyleInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, style_block_type *pStyle)
{
	list_block_type	tList6;
	const list_block_type	*pList;
	int	iFodoOff, iInfoLen;
	int	iTmp, iDel, iAdd, iBefore;
	USHORT	usOpCode, usTmp;
	short	sTmp;

	fail(iFodo < 0 || aucGrpprl == NULL || pStyle == NULL);

	NO_DBG_DEC_C(pStyle->usListIndex != 0, pStyle->usIstd);
	NO_DBG_DEC_C(pStyle->usListIndex != 0, pStyle->usListIndex);

	(void)memset(&tList6, 0, sizeof(tList6));

	iFodoOff = 0;
	while (iBytes >= iFodoOff + 2) {
		iInfoLen = 0;
		usOpCode = usGetWord(iFodo + iFodoOff, aucGrpprl);
		switch (usOpCode) {
		case 0x2403:	/* jc */
			pStyle->ucAlignment = ucGetByte(
					iFodo + iFodoOff + 2, aucGrpprl);
			break;
		case 0x260a:	/* ilvl */
			pStyle->ucListLevel =
				ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->ucListLevel);
			pStyle->ucNumLevel = pStyle->ucListLevel;
			break;
		case 0x4600:	/* istd */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(usTmp);
			break;
		case 0x460b:	/* ilfo */
			pStyle->usListIndex =
				usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->usListIndex);
			break;
		case 0x4610: /* Nest dxaLeft */
			sTmp = (short)usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			pStyle->sLeftIndent += sTmp;
			if (pStyle->sLeftIndent < 0) {
				pStyle->sLeftIndent = 0;
			}
			DBG_DEC(sTmp);
			DBG_DEC(pStyle->sLeftIndent);
			break;
		case 0xc60d:	/* ChgTabsPapx */
		case 0xc615:	/* ChgTabs */
			iTmp = (int)ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (iTmp < 2) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iTmp);
			iDel = (int)ucGetByte(iFodo + iFodoOff + 3, aucGrpprl);
			if (iTmp < 2 + 2 * iDel) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iDel);
			iAdd = (int)ucGetByte(
				iFodo + iFodoOff + 4 + 2 * iDel, aucGrpprl);
			if (iTmp < 2 + 2 * iDel + 2 * iAdd) {
				iInfoLen = 1;
				break;
			}
			NO_DBG_DEC(iAdd);
			break;
		case 0x840e:	/* dxaRight */
			pStyle->sRightIndent = (short)usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->sRightIndent);
			break;
		case 0x840f:	/* dxaLeft */
			pStyle->sLeftIndent = (short)usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->sLeftIndent);
			break;
		case 0x8411:	/* dxaLeft1 */
			pStyle->sLeftIndent1 = (short)usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->sLeftIndent1);
			break;
		case 0xa413:	/* dyaBefore */
			pStyle->usBeforeIndent = usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->usBeforeIndent);
			break;
		case 0xa414:	/* dyaAfter */
			pStyle->usAfterIndent = usGetWord(
					iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pStyle->usAfterIndent);
			break;
		case 0xc63e:	/* anld */
			iTmp = (int)ucGetByte(
					iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC_C(iTmp < 84, iTmp);
			if (iTmp >= 1) {
				tList6.ucNFC = ucGetByte(
					iFodo + iFodoOff + 3, aucGrpprl);
			}
			if (tList6.ucNFC != LIST_BULLETS && iTmp >= 2) {
				iBefore = (int)ucGetByte(
					iFodo + iFodoOff + 4, aucGrpprl);
			} else {
				iBefore = 0;
			}
			if (iTmp >= 12) {
				tList6.ulStartAt = (ULONG)usGetWord(
					iFodo + iFodoOff + 13, aucGrpprl);
			}
			if (iTmp >= iBefore + 22) {
				tList6.usListChar = usGetWord(
					iFodo + iFodoOff + iBefore + 23,
					aucGrpprl);
				DBG_HEX(tList6.usListChar);
			}
			break;
		default:
			NO_DBG_HEX(usOpCode);
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen =
				iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}

	if (pStyle->usListIndex == 2047) {
		/* Old style list */
		pStyle->usStartAt = (USHORT)tList6.ulStartAt;
		pStyle->usListChar = tList6.usListChar;
		pStyle->ucNFC = tList6.ucNFC;
	} else {
		/* New style list */
		pList = pGetListInfo(pStyle->usListIndex, pStyle->ucListLevel);
		if (pList != NULL) {
			pStyle->bNoRestart = pList->bNoRestart;
			fail(pList->ulStartAt > (ULONG)USHRT_MAX);
			pStyle->usStartAt = (USHORT)pList->ulStartAt;
			pStyle->usListChar = pList->usListChar;
			pStyle->ucNFC = pList->ucNFC;
			if (pStyle->sLeftIndent <= 0) {
				pStyle->sLeftIndent = pList->sLeftIndent;
			}
		}
	}
} /* end of vGet8StyleInfo */
Пример #24
0
/*
 * Build the list with List Information for Word 8/9/10/11 files
 */
void
vGet8LstInfo(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	list_block_type	tList;
	const ULONG	*aulBlockDepot;
	UCHAR	*aucLfoInfo, *aucLstfInfo, *aucPapx, *aucXString;
	ULONG	ulBeginLfoInfo, ulBeginLstfInfo, ulBeginLvlfInfo;
	ULONG	ulListID, ulStart;
	size_t	tBlockDepotLen, tBlockSize;
	size_t	tLfoInfoLen, tLstfInfoLen, tPapxLen, tXstLen, tOff;
	size_t	tLstfRecords, tStart, tIndex;
	int	iNums;
	USHORT	usIstd;
	UCHAR	ucTmp, ucListLevel, ucMaxLevel, ucChpxLen;
	UCHAR	aucLvlfInfo[28], aucXst[2];

	fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
	fail(aulBBD == NULL || aulSBD == NULL);

	NO_DBG_DEC(pPPS->tTable.ulSB);
	NO_DBG_HEX(pPPS->tTable.ulSize);
	if (pPPS->tTable.ulSize == 0) {
		DBG_MSG("No list information");
		return;
	}

	if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
		/* Use the Small Block Depot */
		aulBlockDepot = aulSBD;
		tBlockDepotLen = tSBDLen;
		tBlockSize = SMALL_BLOCK_SIZE;
	} else {
		/* Use the Big Block Depot */
		aulBlockDepot = aulBBD;
		tBlockDepotLen = tBBDLen;
		tBlockSize = BIG_BLOCK_SIZE;
	}

	/* LFO (List Format Override) */
	ulBeginLfoInfo = ulGetLong(0x2ea, aucHeader); /* fcPlfLfo */
	DBG_HEX(ulBeginLfoInfo);
	tLfoInfoLen = (size_t)ulGetLong(0x2ee, aucHeader); /* lcbPlfLfo */
	DBG_DEC(tLfoInfoLen);
	if (tLfoInfoLen == 0) {
		DBG_MSG("No lists in this document");
		return;
	}

	aucLfoInfo = xmalloc(tLfoInfoLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucLfoInfo, ulBeginLfoInfo, tLfoInfoLen)) {
		aucLfoInfo = xfree(aucLfoInfo);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucLfoInfo, tLfoInfoLen);
	vBuildLfoList(aucLfoInfo, tLfoInfoLen);
	aucLfoInfo = xfree(aucLfoInfo);

	/* LSTF (LiST data on File) */
	ulBeginLstfInfo = ulGetLong(0x2e2, aucHeader); /* fcPlcfLst */
	DBG_HEX(ulBeginLstfInfo);
	tLstfInfoLen = (size_t)ulGetLong(0x2e6, aucHeader); /* lcbPlcfLst */
	DBG_DEC(tLstfInfoLen);
	if (tLstfInfoLen == 0) {
		DBG_MSG("No list data on file");
		return;
	}

	aucLstfInfo = xmalloc(tLstfInfoLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucLstfInfo, ulBeginLstfInfo, tLstfInfoLen)) {
		aucLstfInfo = xfree(aucLstfInfo);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucLstfInfo, tLstfInfoLen);

	tLstfRecords = (size_t)usGetWord(0, aucLstfInfo);
	if (2 + tLstfRecords * 28 < tLstfInfoLen) {
		DBG_DEC(2 + tLstfRecords * 28);
		DBG_DEC(tLstfInfoLen);
		aucLstfInfo = xfree(aucLstfInfo);
		return;
	}

	/* LVLF (List leVeL on File) */
	ulBeginLvlfInfo = ulBeginLstfInfo + tLstfInfoLen;
	DBG_HEX(ulBeginLvlfInfo);

	aucXString = NULL;
	ulStart = ulBeginLvlfInfo;

	for (tIndex = 0, tStart = 2;
	     tIndex < tLstfRecords;
	     tIndex++, tStart += 28) {
		ulListID = ulGetLong(tStart, aucLstfInfo);
		NO_DBG_HEX(ulListID);
		ucTmp = ucGetByte(tStart + 26, aucLstfInfo);
		ucMaxLevel = odd(ucTmp) ? 1 : 9;
		for (ucListLevel = 0; ucListLevel < ucMaxLevel; ucListLevel++) {
			fail(aucXString != NULL);
			usIstd = usGetWord(
					tStart + 8 + 2 * (size_t)ucListLevel,
					aucLstfInfo);
			DBG_DEC_C(usIstd != STI_NIL, usIstd);
			NO_DBG_HEX(ulStart);
			(void)memset(&tList, 0, sizeof(tList));
			/* Read the lvlf (List leVeL on File) */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucLvlfInfo,
					ulStart, sizeof(aucLvlfInfo))) {
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucLvlfInfo, sizeof(aucLvlfInfo));
			if (bAllZero(aucLvlfInfo, sizeof(aucLvlfInfo))) {
				tList.ulStartAt = 1;
				tList.ucNFC = 0x00;
				tList.bNoRestart = FALSE;
			} else {
				tList.ulStartAt = ulGetLong(0, aucLvlfInfo);
				tList.ucNFC = ucGetByte(4, aucLvlfInfo);
				ucTmp = ucGetByte(5, aucLvlfInfo);
				tList.bNoRestart = (ucTmp & BIT(3)) != 0;
				DBG_MSG_C((ucTmp & BIT(4)) != 0 &&
					(ucTmp & BIT(6)) != 0, "Found one");
			}
			ulStart += sizeof(aucLvlfInfo);
			tPapxLen = (size_t)ucGetByte(25, aucLvlfInfo);
			if (tPapxLen != 0) {
				aucPapx = xmalloc(tPapxLen);
				/* Read the Papx */
				if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
						aulBlockDepot, tBlockDepotLen,
						tBlockSize, aucPapx,
						ulStart, tPapxLen)) {
					aucPapx = xfree(aucPapx);
					aucLstfInfo = xfree(aucLstfInfo);
					return;
				}
				NO_DBG_PRINT_BLOCK(aucPapx, tPapxLen);
				tList.sLeftIndent =
					sGetLeftIndent(aucPapx, tPapxLen);
				aucPapx = xfree(aucPapx);
			}
			ulStart += tPapxLen;
			ucChpxLen = ucGetByte(24, aucLvlfInfo);
			ulStart += (ULONG)ucChpxLen;
			/* Read the length of the XString */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucXst,
					ulStart, sizeof(aucXst))) {
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucXst, sizeof(aucXst));
			tXstLen = (size_t)usGetWord(0, aucXst);
			ulStart += sizeof(aucXst);
			if (tXstLen == 0) {
				tList.usListChar = DEFAULT_LISTCHAR;
				vAdd2ListInfoList(ulListID,
						usIstd,
						ucListLevel,
						&tList);
				continue;
			}
			tXstLen *= 2;	/* Length in chars to length in bytes */
			aucXString = xmalloc(tXstLen);
			/* Read the XString */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucXString,
					ulStart, tXstLen)) {
				aucXString = xfree(aucXString);
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucXString, tXstLen);
			tOff = 0;
			for (iNums = 6; iNums < 15; iNums++) {
				ucTmp = ucGetByte(iNums, aucLvlfInfo);
				if (ucTmp == 0) {
					break;
				}
				tOff = (size_t)ucTmp;
			}
			tOff *= 2;	/* Offset in chars to offset in bytes */
			NO_DBG_DEC(tOff);
			if (tList.ucNFC == LIST_SPECIAL ||
			    tList.ucNFC == LIST_SPECIAL2 ||
			    tList.ucNFC == LIST_BULLETS) {
				tList.usListChar = usGetWord(0, aucXString);
			} else if (tOff != 0 && tOff < tXstLen) {
				tList.usListChar = usGetWord(tOff, aucXString);
			} else {
				tList.usListChar = DEFAULT_LISTCHAR;
			}
			vAdd2ListInfoList(ulListID,
					usIstd,
					ucListLevel,
					&tList);
			ulStart += tXstLen;
			aucXString = xfree(aucXString);
		}
	}
	aucLstfInfo = xfree(aucLstfInfo);
} /* end of vGet8LstInfo */
Пример #25
0
/*
 * Build the list with footnote text information for WinWord 1/2 files
 */
static void
vGet2FootnotesText(FILE *pFile, const UCHAR *aucHeader)
{
	footnote_local_type	*pCurr;
	UCHAR	*aucBuffer;
	ULONG	ulCharPos, ulBeginOfFootnotes, ulOffset, ulBeginFootnoteText;
	size_t	tFootnoteTextLen;
	size_t	tIndex;

	TRACE_MSG("vGet2FootnotesText");

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginOfFootnotes = ulGetLong(0x18, aucHeader); /* fcMin */
	ulBeginOfFootnotes += ulGetLong(0x34, aucHeader); /* ccpText */
	NO_DBG_HEX(ulBeginOfFootnotes);

	ulBeginFootnoteText = ulGetLong(0x6a, aucHeader); /* fcPlcffndTxt */
	NO_DBG_HEX(ulBeginFootnoteText);
	tFootnoteTextLen =
		(size_t)usGetWord(0x6e, aucHeader); /* cbPlcffndTxt */
	NO_DBG_DEC(tFootnoteTextLen);

	if (tFootnoteTextLen < 12) {
		DBG_MSG("No Footnote text in this document");
		return;
	}

	aucBuffer = xmalloc(tFootnoteTextLen);
	if (!bReadBytes(aucBuffer,
			tFootnoteTextLen, ulBeginFootnoteText, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tFootnoteTextLen);

	fail(tFootnoteTextLength != 0);
	tFootnoteTextLength = tFootnoteTextLen / 4 - 2;
	fail(tFootnoteTextLength == 0);

	fail(pFootnoteText != NULL);
	pFootnoteText = xcalloc(tFootnoteTextLength,
				sizeof(footnote_local_type));

	for (tIndex = 0; tIndex < tFootnoteTextLength; tIndex++) {
		pCurr = pFootnoteText + tIndex;
		pCurr->tInfo.szText = NULL;
		ulOffset = ulGetLong(tIndex * 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosStart = ulCharPos;
		ulOffset = ulGetLong(tIndex * 4 + 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosNext = ulCharPos;
		pCurr->bUseful = pCurr->ulCharPosStart != pCurr->ulCharPosNext;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet2FootnotesText */
Пример #26
0
/*
 * Fill the font information block with information
 * from a WinWord 1 file.
 */
void
vGet1FontInfo(int iFodo,
	const UCHAR *aucGrpprl, size_t tBytes, font_block_type *pFont)
{
	BOOL	bIcoChange, bFtcChange, bHpsChange, bKulChange;
	USHORT	usTmp;
	UCHAR	ucTmp;
	UCHAR	aucChpx[12];

	fail(iFodo < 0 || aucGrpprl == NULL || pFont == NULL);

	if (tBytes > sizeof(aucChpx)) {
		NO_DBG_PRINT_BLOCK(aucGrpprl + iFodo, tBytes);
		return;
	}

	/* Build the CHPX structure */
	(void)memset(aucChpx, 0, sizeof(aucChpx));
	(void)memcpy(aucChpx, aucGrpprl + iFodo, min(tBytes, sizeof(aucChpx)));

	usTmp = usGetWord(0, aucChpx);
	if ((usTmp & BIT(0)) != 0) {
		pFont->usFontStyle ^= FONT_BOLD;
	}
	if ((usTmp & BIT(1)) != 0) {
		pFont->usFontStyle ^= FONT_ITALIC;
	}
	if ((usTmp & BIT(2)) != 0) {
		pFont->usFontStyle ^= FONT_STRIKE;
	}
	if ((usTmp & BIT(5)) != 0) {
		pFont->usFontStyle ^= FONT_SMALL_CAPITALS;
	}
	if ((usTmp & BIT(6)) != 0) {
		pFont->usFontStyle ^= FONT_CAPITALS;
	}
	if ((usTmp & BIT(7)) != 0) {
		pFont->usFontStyle ^= FONT_HIDDEN;
	}

	ucTmp = ucGetByte(5, aucChpx);
	if (ucTmp != 0) {
		if (ucTmp < 128) {
			pFont->usFontStyle |= FONT_SUPERSCRIPT;
			DBG_MSG("Superscript");
		} else {
			pFont->usFontStyle |= FONT_SUBSCRIPT;
			DBG_MSG("Subscript");
		}
	}

	bIcoChange = (usTmp & BIT(10)) != 0;
	bFtcChange = (usTmp & BIT(11)) != 0;
	bHpsChange = (usTmp & BIT(12)) != 0;
	bKulChange = (usTmp & BIT(13)) != 0;

	if (bFtcChange) {
		usTmp = usGetWord(2, aucChpx);
		if (usTmp <= (USHORT)UCHAR_MAX) {
			pFont->ucFontNumber = (UCHAR)usTmp;
		} else {
			pFont->ucFontNumber = 0;
		}
	}

	if (bHpsChange) {
		pFont->usFontSize = (USHORT)ucGetByte(4, aucChpx);
	}

	if (bIcoChange || bKulChange) {
		usTmp = usGetWord(6, aucChpx);
		if (bIcoChange) {
			pFont->ucFontColor = (UCHAR)((usTmp & 0x0f00) >> 8);
			if (pFont->ucFontColor <= 7) {
				/* Add 1 for compatibility with Word 2 and up */
				pFont->ucFontColor++;
			} else {
				DBG_DEC(pFont->ucFontColor);
				pFont->ucFontColor = 0;
			}
		}
		if (bKulChange) {
			usTmp = (usTmp & 0x7000) >> 12;
			DBG_DEC_C(usTmp > 4, usTmp);
			if (usTmp == 0) {
				pFont->usFontStyle &= ~FONT_UNDERLINE;
			} else {
				pFont->usFontStyle |= FONT_UNDERLINE;
			}
		}
	}
Пример #27
0
/*
 * Build the lists with Paragraph Information for Word 8/9/10/11 files
 */
void
vGet8PapInfo(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	row_block_type		tRow;
	style_block_type	tStyle;
	ULONG		*aulParfPage;
	UCHAR	*aucBuffer;
	ULONG	ulCharPos, ulCharPosFirst, ulCharPosLast;
	ULONG	ulBeginParfInfo;
	size_t	tParfInfoLen, tOffset, tLen;
	int	iIndex, iIndex2, iRun, iFodo, iLen;
	row_info_enum	eRowInfo;
	USHORT	usIstd;
	UCHAR	aucFpage[BIG_BLOCK_SIZE];

	fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
	fail(aulBBD == NULL || aulSBD == NULL);

	ulBeginParfInfo = ulGetLong(0x102, aucHeader); /* fcPlcfbtePapx */
	NO_DBG_HEX(ulBeginParfInfo);
	tParfInfoLen = (size_t)ulGetLong(0x106, aucHeader); /* lcbPlcfbtePapx */
	NO_DBG_DEC(tParfInfoLen);
	if (tParfInfoLen < 4) {
		DBG_DEC(tParfInfoLen);
		return;
	}

	aucBuffer = aucFillInfoBuffer(pFile, &pPPS->tTable,
			aulBBD, tBBDLen, aulSBD, tSBDLen,
			ulBeginParfInfo, tParfInfoLen);
	if (aucBuffer == NULL) {
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tParfInfoLen);

	tLen = (tParfInfoLen / 4 - 1) / 2;
	aulParfPage = xcalloc(tLen, sizeof(ULONG));
	for (iIndex = 0, tOffset = (tLen + 1) * 4;
	     iIndex < (int)tLen;
	     iIndex++, tOffset += 4) {
		 aulParfPage[iIndex] = ulGetLong(tOffset, aucBuffer);
		 NO_DBG_DEC(aulParfPage[iIndex]);
	}
	DBG_HEX(ulGetLong(0, aucBuffer));
	aucBuffer = xfree(aucBuffer);
	NO_DBG_PRINT_BLOCK(aucHeader, HEADER_SIZE);

	(void)memset(&tRow, 0, sizeof(tRow));
	ulCharPosFirst = CP_INVALID;
	for (iIndex = 0; iIndex < (int)tLen; iIndex++) {
		fail(aulParfPage[iIndex] > ULONG_MAX / BIG_BLOCK_SIZE);
		if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
				aulBBD, tBBDLen, BIG_BLOCK_SIZE,
				aucFpage,
				aulParfPage[iIndex] * BIG_BLOCK_SIZE,
				BIG_BLOCK_SIZE)) {
			break;
		}
		NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);
		iRun = (int)ucGetByte(0x1ff, aucFpage);
		NO_DBG_DEC(iRun);
		for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {
			NO_DBG_HEX(ulGetLong(iIndex2 * 4, aucFpage));
			iFodo = 2 * (int)ucGetByte(
				(iRun + 1) * 4 + iIndex2 * 13, aucFpage);
			if (iFodo <= 0) {
				continue;
			}

			iLen = 2 * (int)ucGetByte(iFodo, aucFpage);
			if (iLen == 0) {
				iFodo++;
				iLen = 2 * (int)ucGetByte(iFodo, aucFpage);
			}

			usIstd = usGetWord(iFodo + 1, aucFpage);
			vFillStyleFromStylesheet(usIstd, &tStyle);
			vGet8StyleInfo(iFodo, aucFpage + 3, iLen - 3, &tStyle);
			ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);
			NO_DBG_HEX(ulCharPos);
			tStyle.ulFileOffset = ulCharPos2FileOffsetX(
						ulCharPos, &tStyle.eListID);
			vAdd2StyleInfoList(&tStyle);

			eRowInfo = eGet8RowInfo(iFodo,
					aucFpage + 3, iLen - 3, &tRow);
			switch (eRowInfo) {
			case found_a_cell:
				if (ulCharPosFirst != CP_INVALID) {
					break;
				}
				ulCharPosFirst = ulGetLong(
						iIndex2 * 4, aucFpage);
				NO_DBG_HEX(ulCharPosFirst);
				tRow.ulCharPosStart = ulCharPosFirst;
				tRow.ulFileOffsetStart =
					ulCharPos2FileOffset(ulCharPosFirst);
				NO_DBG_HEX_C(
					tRow.ulFileOffsetStart == FC_INVALID,
					ulCharPosFirst);
				break;
			case found_end_of_row:
				ulCharPosLast = ulGetLong(
						iIndex2 * 4, aucFpage);
				NO_DBG_HEX(ulCharPosLast);
				tRow.ulCharPosEnd = ulCharPosLast;
				tRow.ulFileOffsetEnd =
					ulCharPos2FileOffset(ulCharPosLast);
				NO_DBG_HEX_C(tRow.ulFileOffsetEnd == FC_INVALID,
							ulCharPosLast);
				vAdd2RowInfoList(&tRow);
				(void)memset(&tRow, 0, sizeof(tRow));
				ulCharPosFirst = CP_INVALID;
				break;
			case found_nothing:
				break;
			default:
				DBG_DEC(eRowInfo);
				break;
			}
		}
	}
	aulParfPage = xfree(aulParfPage);
} /* end of vGet8PapInfo */
Пример #28
0
/*
 * Build the lists with Paragraph Information for WinWord 1/2 files
 */
void
vGet2PapInfo(FILE *pFile, const UCHAR *aucHeader)
{
	row_block_type		tRow;
	style_block_type	tStyle;
	USHORT	*ausParfPage;
	UCHAR	*aucBuffer;
	ULONG	ulCharPos, ulCharPosFirst, ulCharPosLast;
	ULONG	ulBeginParfInfo;
	size_t	tParfInfoLen, tParfPageNum, tOffset, tSize, tLenOld, tLen;
	int	iIndex, iIndex2, iRun, iFodo, iLen;
	row_info_enum	eRowInfo;
	USHORT	usParfFirstPage, usCount, usIstd;
	UCHAR	ucStc;
	UCHAR	aucFpage[BIG_BLOCK_SIZE];

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginParfInfo = ulGetLong(0xa6, aucHeader); /* fcPlcfbtePapx */
	NO_DBG_HEX(ulBeginParfInfo);
	tParfInfoLen = (size_t)usGetWord(0xaa, aucHeader); /* cbPlcfbtePapx */
	NO_DBG_DEC(tParfInfoLen);
	if (tParfInfoLen < 4) {
		DBG_DEC(tParfInfoLen);
		return;
	}

	aucBuffer = xmalloc(tParfInfoLen);
	if (!bReadBytes(aucBuffer, tParfInfoLen, ulBeginParfInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tParfInfoLen);

	tLen = (tParfInfoLen - 4) / 6;
	ausParfPage = xcalloc(tLen, sizeof(USHORT));
	for (iIndex = 0, tOffset = (tLen + 1) * 4;
	     iIndex < (int)tLen;
	     iIndex++, tOffset += 2) {
		ausParfPage[iIndex] = usGetWord(tOffset, aucBuffer);
		NO_DBG_DEC(ausParfPage[iIndex]);
	}
	DBG_HEX(ulGetLong(0, aucBuffer));
	aucBuffer = xfree(aucBuffer);
	tParfPageNum = (size_t)usGetWord(0x144, aucHeader); /* cpnBtePap */
	DBG_DEC(tParfPageNum);
	if (tLen < tParfPageNum) {
		/* Replace ParfPage by a longer version */
		tLenOld = tLen;
		usParfFirstPage = usGetWord(0x140, aucHeader); /* pnPapFirst */
		DBG_DEC(usParfFirstPage);
		tLen += tParfPageNum - 1;
		tSize = tLen * sizeof(USHORT);
		ausParfPage = xrealloc(ausParfPage, tSize);
		/* Add new values */
		usCount = usParfFirstPage + 1;
		for (iIndex = (int)tLenOld; iIndex < (int)tLen; iIndex++) {
			ausParfPage[iIndex] = usCount;
			NO_DBG_DEC(ausParfPage[iIndex]);
			usCount++;
		}
	}

	(void)memset(&tRow, 0, sizeof(tRow));
	ulCharPosFirst = CP_INVALID;
	for (iIndex = 0; iIndex < (int)tLen; iIndex++) {
		if (!bReadBytes(aucFpage, BIG_BLOCK_SIZE,
				(ULONG)ausParfPage[iIndex] * BIG_BLOCK_SIZE,
				pFile)) {
			break;
		}
		NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);
		iRun = (int)ucGetByte(0x1ff, aucFpage);
		NO_DBG_DEC(iRun);
		for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {
			if ((iRun + 1) * 4 + iIndex2 * 1 >= BIG_BLOCK_SIZE) {
				break;
			}
			NO_DBG_HEX(ulGetLong(iIndex2 * 4, aucFpage));
			iFodo = 2 * (int)ucGetByte(
				(iRun + 1) * 4 + iIndex2 * 1, aucFpage);
			if (iFodo <= 0) {
				continue;
			}

			iLen = 2 * (int)ucGetByte(iFodo, aucFpage);

			ucStc = ucGetByte(iFodo + 1, aucFpage);
			usIstd = usStc2istd(ucStc);

			vFillStyleFromStylesheet(usIstd, &tStyle);
			vGet2StyleInfo(iFodo, aucFpage + 8, iLen - 8, &tStyle);
			ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);
			NO_DBG_HEX(ulCharPos);
			tStyle.ulFileOffset = ulCharPos;
			vAdd2StyleInfoList(&tStyle);

			eRowInfo = eGet2RowInfo(iFodo,
					aucFpage + 8, iLen - 8, &tRow);

			switch(eRowInfo) {
			case found_a_cell:
				if (ulCharPosFirst != CP_INVALID) {
					break;
				}
				ulCharPosFirst = ulGetLong(
						iIndex2 * 4, aucFpage);
				NO_DBG_HEX(ulCharPosFirst);
				tRow.ulCharPosStart = ulCharPosFirst;
				tRow.ulFileOffsetStart = ulCharPosFirst;
				break;
			case found_end_of_row:
				ulCharPosLast = ulGetLong(
						iIndex2 * 4, aucFpage);
				NO_DBG_HEX(ulCharPosLast);
				tRow.ulCharPosEnd = ulCharPosLast;
				/* Add 1 for compatiblity with Word 6 and up */
				tRow.ulFileOffsetEnd = ulCharPosLast + 1;
				vAdd2RowInfoList(&tRow);
				(void)memset(&tRow, 0, sizeof(tRow));
				ulCharPosFirst = CP_INVALID;
				break;
			case found_nothing:
				break;
			default:
				DBG_DEC(eRowInfo);
				break;
			}
		}
	}
	ausParfPage = xfree(ausParfPage);
} /* end of vGet2PapInfo */
Пример #29
0
/*
 * Build the lists with Section Property Information for WinWord 1/2 files
 */
void
vGet2SepInfo(FILE *pFile, const UCHAR *aucHeader)
{
	section_block_type	tSection;
	ULONG	*aulSectPage, *aulCharPos;
	UCHAR	*aucBuffer, *aucFpage;
	ULONG	ulBeginOfText, ulTextOffset, ulBeginSectInfo;
	size_t	tSectInfoLen, tIndex, tOffset, tLen, tBytes;
	UCHAR	aucTmp[1];

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginOfText = ulGetLong(0x18, aucHeader); /* fcMin */
	NO_DBG_HEX(ulBeginOfText);
	ulBeginSectInfo = ulGetLong(0x7c, aucHeader); /* fcPlcfsed */
	DBG_HEX(ulBeginSectInfo);
	tSectInfoLen = (size_t)usGetWord(0x80, aucHeader); /* cbPlcfsed */
	DBG_DEC(tSectInfoLen);
	if (tSectInfoLen < 4) {
		DBG_DEC(tSectInfoLen);
		return;
	}

	aucBuffer = xmalloc(tSectInfoLen);
	if (!bReadBytes(aucBuffer, tSectInfoLen, ulBeginSectInfo, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tSectInfoLen);

	/* Read the Section Descriptors */
	tLen = (tSectInfoLen - 4) / 10;
	/* Save the section offsets */
	aulCharPos = xcalloc(tLen, sizeof(ULONG));
	for (tIndex = 0, tOffset = 0;
	     tIndex < tLen;
	     tIndex++, tOffset += 4) {
		ulTextOffset = ulGetLong(tOffset, aucBuffer);
		NO_DBG_HEX(ulTextOffset);
		aulCharPos[tIndex] = ulBeginOfText + ulTextOffset;
		NO_DBG_HEX(aulCharPos[tIndex]);
	}
	/* Save the Sepx offsets */
	aulSectPage = xcalloc(tLen, sizeof(ULONG));
	for (tIndex = 0, tOffset = (tLen + 1) * 4;
	     tIndex < tLen;
	     tIndex++, tOffset += 6) {
		aulSectPage[tIndex] = ulGetLong(tOffset + 2, aucBuffer);
		NO_DBG_HEX(aulSectPage[tIndex]); /* fcSepx */
	}
	aucBuffer = xfree(aucBuffer);

	/* Read the Section Properties */
	for (tIndex = 0; tIndex < tLen; tIndex++) {
		if (aulSectPage[tIndex] == FC_INVALID) {
			vDefault2SectionInfoList(aulCharPos[tIndex]);
			continue;
		}
		/* Get the number of bytes to read */
		if (!bReadBytes(aucTmp, 1, aulSectPage[tIndex], pFile)) {
			continue;
		}
		tBytes = 1 + (size_t)ucGetByte(0, aucTmp);
		NO_DBG_DEC(tBytes);
		/* Read the bytes */
		aucFpage = xmalloc(tBytes);
		if (!bReadBytes(aucFpage, tBytes, aulSectPage[tIndex], pFile)) {
			aucFpage = xfree(aucFpage);
			continue;
		}
		NO_DBG_PRINT_BLOCK(aucFpage, tBytes);
		/* Process the bytes */
		vGetDefaultSection(&tSection);
		vGet2SectionInfo(aucFpage + 1, tBytes - 1, &tSection);
		vAdd2SectionInfoList(&tSection, aulCharPos[tIndex]);
		aucFpage = xfree(aucFpage);
	}
	aulCharPos = xfree(aulCharPos);
	aulSectPage = xfree(aulSectPage);
} /* end of vGet2SepInfo */
Пример #30
0
/*
 * Translate the rowinfo to a member of the row_info enumeration
 */
row_info_enum
eGet2RowInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, row_block_type *pRow)
{
	int	iFodoOff, iInfoLen;
	int	iIndex, iSize, iCol;
	int	iPosCurr, iPosPrev;
	USHORT	usTmp;
	BOOL	bFound24_0, bFound24_1, bFound25_0, bFound25_1, bFound154;

	fail(iFodo < 0 || aucGrpprl == NULL || pRow == NULL);

	iFodoOff = 0;
	bFound24_0 = FALSE;
	bFound24_1 = FALSE;
	bFound25_0 = FALSE;
	bFound25_1 = FALSE;
	bFound154 = FALSE;
	while (iBytes >= iFodoOff + 1) {
		iInfoLen = 0;
		switch (ucGetByte(iFodo + iFodoOff, aucGrpprl)) {
		case  24:	/* fIntable */
			if (odd(ucGetByte(iFodo + iFodoOff + 1, aucGrpprl))) {
				bFound24_1 = TRUE;
			} else {
				bFound24_0 = TRUE;
			}
			break;
		case  25:	/* fTtp */
			if (odd(ucGetByte(iFodo + iFodoOff + 1, aucGrpprl))) {
				bFound25_1 = TRUE;
			} else {
				bFound25_0 = TRUE;
			}
			break;
		case 30:	/* brcTop10 */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x01ff;
			NO_DBG_DEC(usTmp >> 6);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_TOP;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_TOP;
			}
			break;
		case 31:	/* brcLeft10 */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x01ff;
			NO_DBG_DEC(usTmp >> 6);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_LEFT;
			}
			break;
		case 32:	/* brcBottom10 */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x01ff;
			NO_DBG_DEC(usTmp >> 6);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM;
			}
			break;
		case 33:	/* brcRight10 */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x01ff;
			NO_DBG_DEC(usTmp >> 6);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_RIGHT;
			}
			break;
		case 38:	/* brcTop */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x0018;
			NO_DBG_DEC(usTmp >> 3);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_TOP;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_TOP;
			}
			break;
		case 39:	/* brcLeft */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x0018;
			NO_DBG_DEC(usTmp >> 3);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_LEFT;
			}
			break;
		case 40:	/* brcBottom */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x0018;
			NO_DBG_DEC(usTmp >> 3);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM;
			}
			break;
		case 41:	/* brcRight */
			usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			usTmp &= 0x0018;
			NO_DBG_DEC(usTmp >> 3);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_RIGHT;
			}
			break;
		case 152:	/* cDefTable10 */
		case 154:	/* cDefTable */
			iSize = (int)usGetWord(iFodo + iFodoOff + 1, aucGrpprl);
			if (iSize < 6 || iBytes < iFodoOff + 7) {
				DBG_DEC(iSize);
				DBG_DEC(iBytes);
				DBG_DEC(iFodoOff);
				iInfoLen = 1;
				break;
			}
			iCol = (int)ucGetByte(iFodo + iFodoOff + 3, aucGrpprl);
			if (iCol < 1 ||
			    iBytes < iFodoOff + 3 + (iCol + 1) * 2) {
				DBG_DEC(iCol);
				DBG_DEC(iBytes);
				DBG_DEC(iFodoOff);
				DBG_DEC(ucGetByte(iFodo + iFodoOff, aucGrpprl));
				iInfoLen = 1;
				break;
			}
			if (iCol >= (int)elementsof(pRow->asColumnWidth)) {
				DBG_DEC(iCol);
				werr(1, "The number of columns is corrupt");
			}
			pRow->ucNumberOfColumns = (UCHAR)iCol;
			iPosPrev = (int)(short)usGetWord(
					iFodo + iFodoOff + 4,
					aucGrpprl);
			for (iIndex = 0; iIndex < iCol; iIndex++) {
				iPosCurr = (int)(short)usGetWord(
					iFodo + iFodoOff + 6 + iIndex * 2,
					aucGrpprl);
				pRow->asColumnWidth[iIndex] =
						(short)(iPosCurr - iPosPrev);
				iPosPrev = iPosCurr;
			}
			bFound154 = TRUE;
			break;
		default:
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen =
				iGet2InfoLength(iFodo + iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}
	if (bFound24_1 && bFound25_1 && bFound154) {
		return found_end_of_row;
	}
	if (bFound24_0 && bFound25_0 && !bFound154) {
		return found_not_end_of_row;
	}
	if (bFound24_1) {
		return found_a_cell;
	}
	if (bFound24_0) {
		return found_not_a_cell;
	}
	return found_nothing;
} /* end of eGet2RowInfo */