Exemplo n.º 1
0
int main(int argc, char *argv[])
{
  if( argc < 2 )
  {
    std::cout << "Usage:" << std::endl;
    std::cout << argv[0] << " filename [stream-name [output-file]]" << std::endl;
    return 0;
  }

  char* filename = argv[1];
  char* streamname = (argc<3) ? 0 : argv[2];
  char* outfile = (argc<4) ? 0 : argv[3];

  POLE::Storage* storage = new POLE::Storage( filename );
  storage->open();
  if( storage->result() != POLE::Storage::Ok )
  {
    std::cout << "Error on file " << filename << std::endl;
    return 1;
  }

  if( !streamname )
    visit( 0, storage, "/" );
  else if( !outfile )
     dump( storage, streamname );
  else
     extract( storage, streamname, outfile );

  delete storage;

  return 0;
}
Exemplo n.º 2
0
bool
readStream(POLE::Storage& storage, const char* streampath, QBuffer& buffer)
{
    std::string path(streampath);
    if (storage.isDirectory("PP97_DUALSTORAGE")) {
        qDebug() << "PP97_DUALSTORAGE";
        path = "PP97_DUALSTORAGE" + path;
    }
    POLE::Stream stream(&storage, path);
    if (stream.fail()) {
        qDebug() << "Unable to construct " << streampath << "stream";
        return false;
    }

    QByteArray array;
    array.resize(stream.size());
    unsigned long r = stream.read((unsigned char*)array.data(), stream.size());
    if (r != stream.size()) {
        qDebug() << "Error while reading from " << streampath << "stream";
        return false;
    }
    buffer.setData(array);
    buffer.open(QIODevice::ReadOnly);
    return true;
}
Exemplo n.º 3
0
// Extract encryption data from Microsoft Word file
// Place 48 bytes at record_out:
// 16 byte Salt, followed by
// 16 byte EncryptedVerifier, followed by
// 16 byte EncryptedVerifierHash
extern "C" void extract_doc(const char *file_name, unsigned char *record_out) {
  int n; // Used for number of bytes read
  POLE::Storage* storage = new POLE::Storage(file_name );
  storage->open();
  if( storage->result() != POLE::Storage::Ok )
  {
    std::cout << "Error on file " << std::endl;
    exit(1);
    return;
  }

  // Check File Information Block to see if document is encrypted

  POLE::Stream* stream = new POLE::Stream( storage, "WordDocument" );
  if (!stream || stream->fail() ) {
	std::cerr << "Could not open WordDocument stream\n";
	exit(1);
  }

  // FibBase should be at the beginning of the WordDocument stream
  unsigned char wIdent[2];
  n = stream->read(wIdent, 2);
  if (n != 2) return;

  if (! (wIdent[0] == 0xEC && wIdent[1] == 0xA5 )) {
    std::cerr << "FibBase not found\n";
    exit(1);
    return;
  }

  // fEncrypted is in 12th byte of FibBase. 2 bytes have been read
  // already and 12 = 2 + 10.
  unsigned char byte;
  for (int i = 1; i <= 10; i++) {
  	n = stream->read(&byte, 1);
	if (n != 1) {
		std::cerr << "Error reading FibBase\n";
		exit(1);
	}
  }

  if ((byte & 0x01) == 0) {
	std::cerr << "File is not encrypted\n";
	exit(1);
  }

  // Look for encryption header in 1Table or 0Table stream
  // See http://msdn.microsoft.com/en-us/library/dd923367(v=office.12).aspx
  // and http://msdn.microsoft.com/en-us/library/dd908560(v=office.12).aspx

  delete stream;
  stream = new POLE::Stream( storage, "1Table" );
  if (!stream || stream->fail() ) {
	stream = new POLE::Stream( storage, "0Table" );
  }
  if (!stream || stream->fail() ) {
	std::cerr << "Couldn't open 1Table or 0Table stream\n";
	exit(1);
  }
  unsigned char EncryptionHeader[52];
  n = stream->read(EncryptionHeader, 52);
  memcpy(record_out, EncryptionHeader + 4, 48);
}
Exemplo n.º 4
0
	void WordprocessingDocument::SaveDocument(bool &bMacros)
	{
		std::wstring pathWord = m_strOutputPath + FILE_SEPARATOR_STR + L"word" ;
		NSDirectory::CreateDirectory( pathWord );

		if (bMacros && docFile->GetStorage()->isDirectory(L"Macros"))
		{
			std::wstring sVbaProjectFile = pathWord + FILE_SEPARATOR_STR + L"vbaProject.bin";

			POLE::Storage *storageVbaProject = new POLE::Storage(sVbaProjectFile.c_str());

			if ((storageVbaProject) && (storageVbaProject->open(true, true)))
			{			
				docFile->GetStorage()->copy(0, L"Macros/", storageVbaProject, false);

				storageVbaProject->close();
				delete storageVbaProject;

				RegisterDocumentMacros();
				RegisterVbaProject();	
				//output_document->get_xl_files().add_vba_project();
			}
			else bMacros = false;
		}
		else 
			bMacros = false;

		if (!bMacros)
		{
			RegisterDocument();
		}
		OOX::CContentTypes oContentTypes;
		OOX::CPath pathDocProps = m_strOutputPath + FILE_SEPARATOR_STR + _T("docProps");
		NSDirectory::CreateDirectory(pathDocProps.GetPath());
		
		OOX::CPath DocProps = std::wstring(_T("docProps"));

		OOX::CApp* pApp = new OOX::CApp(NULL);
		if (pApp)
		{
			std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvApplicationName);
			if (sApplication.empty())
				sApplication = NSSystemUtils::gc_EnvApplicationNameDefault;
			pApp->SetApplication(sApplication);
	#if defined(INTVER)
			pApp->SetAppVersion(VALUE2STR(INTVER));
	#endif
			pApp->SetDocSecurity(0);
			pApp->SetScaleCrop(false);
			pApp->SetLinksUpToDate(false);
			pApp->SetSharedDoc(false);
			pApp->SetHyperlinksChanged(false);
			
			pApp->write(pathDocProps + FILE_SEPARATOR_STR + _T("app.xml"), DocProps, oContentTypes);
			delete pApp;
		}				
		OOX::CCore* pCore = new OOX::CCore(NULL);
		if (pCore)
		{
			pCore->SetCreator(_T(""));
			pCore->SetLastModifiedBy(_T(""));
			pCore->write(pathDocProps + FILE_SEPARATOR_STR + _T("core.xml"), DocProps, oContentTypes);
			delete pCore;
		} 
		RegisterDocPr();

		WritePackage();

		//Write main content. (word directory)

        SaveToFile(pathWord, std::wstring( L"document.xml" ),		DocumentXML );
        SaveToFile(pathWord, std::wstring( L"fontTable.xml" ),      FontTableXML );
        SaveToFile(pathWord, std::wstring( L"styles.xml" ),         StyleSheetXML );
        SaveToFile(pathWord, std::wstring( L"footnotes.xml" ),      FootnotesXML );
        SaveToFile(pathWord, std::wstring( L"endnotes.xml" ),		EndnotesXML );
        SaveToFile(pathWord, std::wstring( L"numbering.xml" ),      NumberingXML );
        SaveToFile(pathWord, std::wstring( L"comments.xml" ),		CommentsXML );
        SaveToFile(pathWord, std::wstring( L"settings.xml" ),		SettingsXML );
        SaveToFile(pathWord, std::wstring( L"customizations.xml" ), CommandTableXML );

		if (!ImagesList.empty())
		{
            std::wstring pathMedia = pathWord + FILE_SEPARATOR_STR + L"media";
 
            NSDirectory::CreateDirectory(pathMedia);

			int i = 1;

			for (std::list<ImageFileStructure>::iterator iter = ImagesList.begin(); iter != ImagesList.end(); ++iter)
			{
				unsigned char* bytes = NULL;
				bytes = new unsigned char[iter->data.size()];
				if (bytes) 
				{
					copy(iter->data.begin(), iter->data.end(), bytes);

					if (Global::msoblipDIB == iter->blipType)
					{//user_manual_v52.doc						
                        std::wstring file_name = pathMedia + FILE_SEPARATOR_STR + L"image" + FormatUtils::IntToWideString(i++);
						iter->blipType = ImageHelper::SaveImageToFileFromDIB(bytes, iter->data.size(), file_name);
					}
					else
					{
                        SaveToFile(pathMedia, std::wstring(L"image" ) + FormatUtils::IntToWideString(i++) + iter->ext, (void*)bytes, (unsigned int)iter->data.size());
					}
					
					RELEASEARRAYOBJECTS(bytes);
				}
			}
		}

		if (!OleObjectsList.empty())
		{
            std::wstring pathObjects = pathWord + FILE_SEPARATOR_STR + L"embeddings" ;
            NSDirectory::CreateDirectory( pathObjects );

			int i = 1;
			for (std::list<OleObjectFileStructure>::iterator iter = OleObjectsList.begin(); iter != OleObjectsList.end(); ++iter)
			{
                std::wstring fileName = pathObjects + FILE_SEPARATOR_STR  + L"oleObject" + FormatUtils::IntToWideString(i++) + iter->ext;

				if (!iter->data.empty())
				{
					SaveEmbeddedObject(fileName, *iter);
				}
				else
				{
					SaveOLEObject( fileName, *iter );	
				}
			}
		}

		int headersCount = 0;
		int footersCount = 0;

		for (std::list<std::wstring>::iterator iter = HeaderXMLList.begin(); iter != HeaderXMLList.end(); ++iter)
		{
            SaveToFile(pathWord, ( std::wstring( L"header" ) + FormatUtils::IntToWideString(++headersCount) + std::wstring( L".xml" ) ), *iter);
		}

		for (std::list<std::wstring>::iterator iter = FooterXMLList.begin(); iter != FooterXMLList.end(); ++iter)
		{
            SaveToFile(pathWord, ( std::wstring( L"footer" ) + FormatUtils::IntToWideString(++footersCount) + std::wstring( L".xml" ) ), *iter);
		}
	}