| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/include/xfa_checksum.h" | 7 #include "xfa/fxfa/include/xfa_checksum.h" |
| 8 | 8 |
| 9 #include "core/fdrm/crypto/include/fx_crypt.h" | 9 #include "core/fdrm/crypto/include/fx_crypt.h" |
| 10 #include "xfa/fgas/crt/fgas_algorithm.h" | 10 #include "xfa/fgas/crt/fgas_algorithm.h" |
| 11 | 11 |
| 12 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) | 12 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) |
| 13 : m_pContext(pContext) { | 13 : m_pContext(pContext) { |
| 14 ASSERT(m_pContext); | 14 ASSERT(m_pContext); |
| 15 } | 15 } |
| 16 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} | 16 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} |
| 17 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName, | 17 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName, |
| 18 FX_SAXNODE eType, | 18 CFX_SAXItem::Type eType, |
| 19 uint32_t dwStartPos) { | 19 uint32_t dwStartPos) { |
| 20 UpdateChecksum(TRUE); | 20 UpdateChecksum(TRUE); |
| 21 if (eType != FX_SAXNODE_Tag && eType != FX_SAXNODE_Instruction) { | 21 if (eType != CFX_SAXItem::Type::Tag && |
| 22 eType != CFX_SAXItem::Type::Instruction) { |
| 22 return NULL; | 23 return NULL; |
| 23 } | 24 } |
| 24 m_SAXContext.m_eNode = eType; | 25 m_SAXContext.m_eNode = eType; |
| 25 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; | 26 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; |
| 26 textBuf << "<"; | 27 textBuf << "<"; |
| 27 if (eType == FX_SAXNODE_Instruction) { | 28 if (eType == CFX_SAXItem::Type::Instruction) { |
| 28 textBuf << "?"; | 29 textBuf << "?"; |
| 29 } | 30 } |
| 30 textBuf << bsTagName; | 31 textBuf << bsTagName; |
| 31 m_SAXContext.m_bsTagName = bsTagName; | 32 m_SAXContext.m_bsTagName = bsTagName; |
| 32 return &m_SAXContext; | 33 return &m_SAXContext; |
| 33 } | 34 } |
| 34 void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag, | 35 void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag, |
| 35 const CFX_ByteStringC& bsAttri, | 36 const CFX_ByteStringC& bsAttri, |
| 36 const CFX_ByteStringC& bsValue) { | 37 const CFX_ByteStringC& bsValue) { |
| 37 if (pTag == NULL) { | 38 if (pTag == NULL) { |
| 38 return; | 39 return; |
| 39 } | 40 } |
| 40 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 41 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
| 41 textBuf << " " << bsAttri << "=\"" << bsValue << "\""; | 42 textBuf << " " << bsAttri << "=\"" << bsValue << "\""; |
| 42 } | 43 } |
| 43 void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) { | 44 void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) { |
| 44 if (pTag == NULL) { | 45 if (pTag == NULL) { |
| 45 return; | 46 return; |
| 46 } | 47 } |
| 47 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 48 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
| 48 textBuf << ">"; | 49 textBuf << ">"; |
| 49 UpdateChecksum(FALSE); | 50 UpdateChecksum(FALSE); |
| 50 } | 51 } |
| 51 void CXFA_SAXReaderHandler::OnTagData(void* pTag, | 52 void CXFA_SAXReaderHandler::OnTagData(void* pTag, |
| 52 FX_SAXNODE eType, | 53 CFX_SAXItem::Type eType, |
| 53 const CFX_ByteStringC& bsData, | 54 const CFX_ByteStringC& bsData, |
| 54 uint32_t dwStartPos) { | 55 uint32_t dwStartPos) { |
| 55 if (pTag == NULL) { | 56 if (pTag == NULL) { |
| 56 return; | 57 return; |
| 57 } | 58 } |
| 58 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 59 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
| 59 if (eType == FX_SAXNODE_CharData) { | 60 if (eType == CFX_SAXItem::Type::CharData) { |
| 60 textBuf << "<![CDATA["; | 61 textBuf << "<![CDATA["; |
| 61 } | 62 } |
| 62 textBuf << bsData; | 63 textBuf << bsData; |
| 63 if (eType == FX_SAXNODE_CharData) { | 64 if (eType == CFX_SAXItem::Type::CharData) { |
| 64 textBuf << "]]>"; | 65 textBuf << "]]>"; |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 void CXFA_SAXReaderHandler::OnTagClose(void* pTag, uint32_t dwEndPos) { | 68 void CXFA_SAXReaderHandler::OnTagClose(void* pTag, uint32_t dwEndPos) { |
| 68 if (pTag == NULL) { | 69 if (pTag == NULL) { |
| 69 return; | 70 return; |
| 70 } | 71 } |
| 71 CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag; | 72 CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag; |
| 72 CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf; | 73 CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf; |
| 73 if (pSAXContext->m_eNode == FX_SAXNODE_Instruction) { | 74 if (pSAXContext->m_eNode == CFX_SAXItem::Type::Instruction) { |
| 74 textBuf << "?>"; | 75 textBuf << "?>"; |
| 75 } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) { | 76 } else if (pSAXContext->m_eNode == CFX_SAXItem::Type::Tag) { |
| 76 textBuf << "></" << pSAXContext->m_bsTagName.AsStringC() << ">"; | 77 textBuf << "></" << pSAXContext->m_bsTagName.AsStringC() << ">"; |
| 77 } | 78 } |
| 78 UpdateChecksum(FALSE); | 79 UpdateChecksum(FALSE); |
| 79 } | 80 } |
| 80 void CXFA_SAXReaderHandler::OnTagEnd(void* pTag, | 81 void CXFA_SAXReaderHandler::OnTagEnd(void* pTag, |
| 81 const CFX_ByteStringC& bsTagName, | 82 const CFX_ByteStringC& bsTagName, |
| 82 uint32_t dwEndPos) { | 83 uint32_t dwEndPos) { |
| 83 if (pTag == NULL) { | 84 if (pTag == NULL) { |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 87 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
| 87 textBuf << "</" << bsTagName << ">"; | 88 textBuf << "</" << bsTagName << ">"; |
| 88 UpdateChecksum(FALSE); | 89 UpdateChecksum(FALSE); |
| 89 } | 90 } |
| 90 void CXFA_SAXReaderHandler::OnTargetData(void* pTag, | 91 void CXFA_SAXReaderHandler::OnTargetData(void* pTag, |
| 91 FX_SAXNODE eType, | 92 CFX_SAXItem::Type eType, |
| 92 const CFX_ByteStringC& bsData, | 93 const CFX_ByteStringC& bsData, |
| 93 uint32_t dwStartPos) { | 94 uint32_t dwStartPos) { |
| 94 if (pTag == NULL && eType != FX_SAXNODE_Comment) { | 95 if (pTag == NULL && eType != CFX_SAXItem::Type::Comment) { |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 if (eType == FX_SAXNODE_Comment) { | 98 if (eType == CFX_SAXItem::Type::Comment) { |
| 98 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; | 99 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; |
| 99 textBuf << "<!--" << bsData << "-->"; | 100 textBuf << "<!--" << bsData << "-->"; |
| 100 UpdateChecksum(FALSE); | 101 UpdateChecksum(FALSE); |
| 101 } else { | 102 } else { |
| 102 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 103 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
| 103 textBuf << " " << bsData; | 104 textBuf << " " << bsData; |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) { | 107 void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) { |
| 107 int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); | 108 int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 size_t size) { | 146 size_t size) { |
| 146 if (!m_pSAXReader || !pSrcFile) | 147 if (!m_pSAXReader || !pSrcFile) |
| 147 return FALSE; | 148 return FALSE; |
| 148 if (size < 1) | 149 if (size < 1) |
| 149 size = pSrcFile->GetSize(); | 150 size = pSrcFile->GetSize(); |
| 150 | 151 |
| 151 CXFA_SAXReaderHandler handler(this); | 152 CXFA_SAXReaderHandler handler(this); |
| 152 m_pSAXReader->SetHandler(&handler); | 153 m_pSAXReader->SetHandler(&handler); |
| 153 if (m_pSAXReader->StartParse( | 154 if (m_pSAXReader->StartParse( |
| 154 pSrcFile, (uint32_t)offset, (uint32_t)size, | 155 pSrcFile, (uint32_t)offset, (uint32_t)size, |
| 155 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | | 156 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | |
| 156 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | | 157 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | |
| 157 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { | 158 CFX_SaxParseMode_NotConvert_sharp) < 0) { |
| 158 return FALSE; | 159 return FALSE; |
| 159 } | 160 } |
| 160 return m_pSAXReader->ContinueParse(NULL) > 99; | 161 return m_pSAXReader->ContinueParse(NULL) > 99; |
| 161 } | 162 } |
| 162 | 163 |
| 163 void CXFA_ChecksumContext::FinishChecksum() { | 164 void CXFA_ChecksumContext::FinishChecksum() { |
| 164 delete m_pSAXReader; | 165 delete m_pSAXReader; |
| 165 m_pSAXReader = nullptr; | 166 m_pSAXReader = nullptr; |
| 166 if (m_pByteContext) { | 167 if (m_pByteContext) { |
| 167 uint8_t digest[20]; | 168 uint8_t digest[20]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 178 | 179 |
| 179 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { | 180 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { |
| 180 return m_bsChecksum; | 181 return m_bsChecksum; |
| 181 } | 182 } |
| 182 | 183 |
| 183 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { | 184 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { |
| 184 if (m_pByteContext) { | 185 if (m_pByteContext) { |
| 185 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); | 186 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); |
| 186 } | 187 } |
| 187 } | 188 } |
| OLD | NEW |