コード例 #1
0
ファイル: decode.hpp プロジェクト: herumi/msoffice
bool decode(const char *data, uint32_t dataSize, const String& outFile, const std::string& pass, std::string& secretKey, bool doView, int *pSpinCount = 0)
{
	ms::cfb::CompoundFile cfb(data, dataSize);
	cfb.put();

	const std::string& encryptedPackage = GetContensByName(cfb, "EncryptedPackage"); // data
	const EncryptionInfo info(GetContensByName(cfb, "EncryptionInfo")); // xml
	if (pSpinCount) {
		*pSpinCount = info.spinCount;
	}
	info.put();

	std::string decData;
	if (info.isStandardEncryption) {
		if (!decodeStandardEncryption(decData, encryptedPackage, info, pass, secretKey)) return false;
	} else {
		if (!decodeAgile(decData, encryptedPackage, info, pass, secretKey)) return false;
	}
	if (!doView) {
		DetectFormat(decData.c_str(), decData.size());
		cybozu::File out;
		out.openW(outFile);
		out.write(decData.c_str(), decData.size());
	}
	return true;
}
コード例 #2
0
ファイル: spelldump.cpp プロジェクト: jianzchen/sphinx
bool CISpellAffix::Load ( const char * szFilename )
{
    if ( !szFilename )
        return false;

    m_dRules.Reset ();
    memset ( m_dCharset, 0, sizeof ( m_dCharset ) );
    m_bFirstCaseConv = true;
    m_bUseLowerCaser = false;
    m_bUseDictConversion = false;
    m_LowerCaser.Reset ();

    FILE * pFile = fopen ( szFilename, "rt" );
    if ( !pFile )
        return false;

    bool bResult = false;
    AffixFormat_e eFormat = DetectFormat ( pFile );
    if ( eFormat==AFFIX_FORMAT_UNKNOWN )
        printf ( "Failed to detect affix file format\n" );
    else
    {
        fseek ( pFile, SEEK_SET, 0 );
        printf ( "Using %s affix file format\n", AffixFormatName[eFormat] );
        switch ( eFormat )
        {
        case AFFIX_FORMAT_MYSPELL:
            bResult = LoadMySpell ( pFile );
            break;
        case AFFIX_FORMAT_ISPELL:
            bResult = LoadISpell ( pFile );
            break;
        case AFFIX_FORMAT_UNKNOWN:
            break;
        }
    }
    fclose ( pFile );

    bool bHaveCrossPrefix = false;
    for ( int i = 0; i < m_dRules.GetLength () && !bHaveCrossPrefix; i++ )
        if ( m_dRules[i].IsPrefix() && m_dRules[i].IsCrossProduct() )
            bHaveCrossPrefix = true;

    bool bHaveCrossSuffix = false;
    for ( int i = 0; i < m_dRules.GetLength () && !bHaveCrossSuffix; i++ )
        if ( !m_dRules[i].IsPrefix() && m_dRules[i].IsCrossProduct() )
            bHaveCrossSuffix = true;

    m_bCheckCrosses = bHaveCrossPrefix && bHaveCrossSuffix;

    return bResult;
}
コード例 #3
0
ファイル: ParmFile.cpp プロジェクト: jonathandgough/cpptraj
// ParmFile::ReadTopology()
int ParmFile::ReadTopology(Topology& Top, FileName const& fnameIn, 
                           ArgList const& argListIn, int debugIn) 
{
  if (fnameIn.empty()) {
    mprinterr("Error: No input topology name given.\n");
    return 1;
  }
  if (!File::Exists( fnameIn )) {
    mprinterr("Error: Topology '%s' does not exist.\n", fnameIn.full());
    return 1;
  }
  parmName_ = fnameIn;
  ArgList argIn = argListIn;
  ParmFormatType pfType;
  ParmIO* parmio = 0;
  Top.SetDebug( debugIn );
  // Only force bond search when 'bondsearch' is specified.
  bool bondsearch = false;
  if (argIn.Contains("bondsearch")) {
    Top.SetOffset( argIn.getKeyDouble("bondsearch", -1.0) );
    bondsearch = true;
  }
  // 'as' keyword specifies a format
  std::string as_arg = argIn.GetStringKey("as");
  if (!as_arg.empty()) {
    pfType = (ParmFormatType)FileTypes::GetFormatFromString( PF_KeyArray, as_arg, UNKNOWN_PARM );
    if (pfType == UNKNOWN_PARM) {
      mprinterr("Error: Topology format '%s' not recognized.\n", as_arg.c_str());
      return 1;
    }
    parmio = (ParmIO*)FileTypes::AllocIO( PF_AllocArray, pfType, false );
  } else
    parmio = DetectFormat( parmName_, pfType );
  if (parmio == 0) {
    mprinterr("Error: Could not determine format of topology '%s'\n", parmName_.full());
    return 1;
  }
  mprintf("\tReading '%s' as %s\n", parmName_.full(),
          FileTypes::FormatDescription(PF_AllocArray, pfType) );
  parmio->SetDebug( debugIn );
  if (parmio->processReadArgs(argIn)) return 1;
  int err = parmio->ReadParm( parmName_.Full(), Top);
  // Perform setup common to all parm files.
  if (err == 0) 
    err = Top.CommonSetup(bondsearch || parmio->NeedsBondSearch());
  else
    mprinterr("Error reading topology file '%s'\n", parmName_.full());
  delete parmio;
  if (err > 0) return 1;
  return 0;
}
コード例 #4
0
ファイル: Read.cpp プロジェクト: bluehope/Elemental
#include "El.hpp"

#include "./Read/Ascii.hpp"
#include "./Read/AsciiMatlab.hpp"
#include "./Read/Binary.hpp"
#include "./Read/BinaryFlat.hpp"
#include "./Read/MatrixMarket.hpp"

namespace El {

template<typename T>
void Read( Matrix<T>& A, const string filename, FileFormat format )
{
    DEBUG_ONLY(CSE cse("Read"))
    if( format == AUTO )
        format = DetectFormat( filename );

    switch( format )
    {
    case ASCII:
        read::Ascii( A, filename );
        break;
    case ASCII_MATLAB:
        read::AsciiMatlab( A, filename );
        break;
    case BINARY:
        read::Binary( A, filename );
        break;
    case BINARY_FLAT:
        read::BinaryFlat( A, A.Height(), A.Width(), filename );
        break;