Пример #1
0
std::string OleMainStream::getPiecesTableBuffer(const char *headerBuffer, OleStream &tableStream) {
	unsigned int clxOffset = OleUtil::getU4Bytes(headerBuffer, 0x01A2); //offset for CLX structure
	unsigned int clxLength = OleUtil::getU4Bytes(headerBuffer, 0x01A6); //offset for value of CLX structure length

	//1 step : loading CLX table from table stream
	char *clxBuffer = new char[clxLength];
	tableStream.seek(clxOffset, true);
	tableStream.read(clxBuffer, clxLength);
	std::string clx(clxBuffer, clxLength);
	delete[] clxBuffer;

	//2 step: searching for pieces table buffer at CLX
	//(determines it by 0x02 as start symbol)
	size_t from = 0;
	size_t i;
	std::string pieceTableBuffer;
	while ((i = clx.find_first_of(0x02, from)) != std::string::npos) {
		unsigned int pieceTableLength = OleUtil::getU4Bytes(clx.c_str(), i + 1);
		pieceTableBuffer = std::string(clx, i + 1 + 4);
		if (pieceTableBuffer.length() != pieceTableLength) {
			from = i + 1;
			continue;
		}
		break;
	}
	return pieceTableBuffer;
}
Пример #2
0
bool OleMainStream::readToBuffer(std::string &result, unsigned int offset, std::size_t length, OleStream &stream) {
	char *buffer = new char[length];
	stream.seek(offset, true);
	if (stream.read(buffer, length) != length) {
		return false;
	}
	result = std::string(buffer, length);
	delete[] buffer;
	return true;
}
Пример #3
0
std::string OleMainStream::getPiecesTableBuffer(const char *headerBuffer, OleStream &tableStream) {
	unsigned int clxOffset = OleUtil::getU4Bytes(headerBuffer, 0x01A2); //offset for CLX structure
	unsigned int clxLength = OleUtil::getU4Bytes(headerBuffer, 0x01A6); //offset for value of CLX structure length

	//1 step : loading CLX table from table stream
	char *clxBuffer = new char[clxLength];
	if (!tableStream.seek(clxOffset, true)) {
		ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- error for seeking to CLX structure");
		return std::string();
	}
	if (tableStream.read(clxBuffer, clxLength) != clxLength) {
		ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure length is invalid");
		return std::string();
	}
	std::string clx(clxBuffer, clxLength);
	delete[] clxBuffer;

	//2 step: searching for pieces table buffer at CLX
	//(determines it by 0x02 as start symbol)
	std::size_t from = 0;
	std::size_t i;
	std::string pieceTableBuffer;
	while ((i = clx.find_first_of(0x02, from)) != std::string::npos) {
		if (clx.size() < i + 1 + 4) {
			ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure has invalid format");
			return std::string();
		}
		unsigned int pieceTableLength = OleUtil::getU4Bytes(clx.c_str(), i + 1);
		pieceTableBuffer = std::string(clx, i + 1 + 4);
		if (pieceTableBuffer.length() != pieceTableLength) {
			from = i + 1;
			continue;
		}
		break;
	}
	return pieceTableBuffer;
}