diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index d28edfc..2d4e6d3 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -892,6 +892,25 @@ QIcon FileUtils::iconFromTheme(const QString &name, const QIcon &iconDefault) return QIcon::fromTheme(name, iconDefault); } +bool FileUtils::isOpenXMLFileEncrypted(QString &path) +{ + QFile file(path); + file.open(QIODevice::ReadOnly|QIODevice::Text); + QByteArray encrypt = file.read(4); + file.close(); + if (encrypt.length() < 4) { + qDebug() << "Reading file error!" << path; + return true; + } + //比较前四位是否为对应值来判断OpenXML类型文件是否加密 + if (encrypt[0] == 0x50 && encrypt[1] == 0x4b && encrypt[2] == 0x03 && encrypt[3] == 0x04) { + return false; + } else { + qDebug() << "Encrypt!" << path; + return true; + } +} + QString FileUtils::getHtmlText(const QString &text, const QString &keyword) { QString htmlString; diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index 7aa2e5a..671a426 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -96,6 +96,7 @@ public: static QString escapeHtml(const QString & str); static QString chineseSubString(const std::string &myStr,int start,int length); static QIcon iconFromTheme(const QString& name, const QIcon &iconDefault); + static bool isOpenXMLFileEncrypted(QString &path); static size_t _max_index_count; static size_t _current_index_count; //this one has been Abandoned,do not use it. static unsigned short _index_status; diff --git a/libsearch/parser/binary-parser.cpp b/libsearch/parser/binary-parser.cpp index 040a2cb..fedf507 100644 --- a/libsearch/parser/binary-parser.cpp +++ b/libsearch/parser/binary-parser.cpp @@ -4884,7 +4884,7 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS, ulBeginTextInfo = ulGetLong(0x1a2, aucHeader); /* fcClx */ tTextInfoLen = (size_t)ulGetLong(0x1a6, aucHeader); /* lcbClx */ ulEncryptInfo = ulGetLong(0x0a, aucHeader); - if(ulEncryptInfo & 0x0100) { + if(ulEncryptInfo & BIT(8)) { qDebug() << "Encrypt file:" << m_strFileName << (size_t)ulEncryptInfo; return false; }