private ProtectedString ReadProtectedString(XmlReader xr) { XorredBuffer xb = ProcessNode(xr); if (xb != null) { try { return(new ProtectedString(true, xb)); } finally { xb.Dispose(); } } bool bProtect = false; if (m_format == KdbxFormat.PlainXml) { if (xr.MoveToAttribute(AttrProtectedInMemPlainXml)) { string strProtect = xr.Value; bProtect = ((strProtect != null) && (strProtect == ValTrue)); } } return(new ProtectedString(bProtect, ReadString(xr))); }
private string ReadString(XmlReader xr) { XorredBuffer xb = ProcessNode(xr); if (xb != null) { Debug.Assert(false); // Protected data is unexpected here try { byte[] pb = xb.ReadPlainText(); if (pb.Length == 0) { return(string.Empty); } try { return(StrUtil.Utf8.GetString(pb, 0, pb.Length)); } finally { MemUtil.ZeroByteArray(pb); } } finally { xb.Dispose(); } } m_bReadNextNode = false; // ReadElementString skips end tag return(xr.ReadElementString()); }
private void ReadUnknown(XmlReader xr) { Debug.Assert(false); // Unknown node! Debug.Assert(xr.NodeType == XmlNodeType.Element); bool bRead = false; int cOpen = 0; do { if (bRead) { xr.Read(); } bRead = true; if (xr.NodeType == XmlNodeType.EndElement) { --cOpen; } else if (xr.NodeType == XmlNodeType.Element) { if (!xr.IsEmptyElement) { XorredBuffer xb = ProcessNode(xr); if (xb != null) { xb.Dispose(); bRead = m_bReadNextNode; continue; } ++cOpen; } } }while(cOpen > 0); m_bReadNextNode = bRead; }
private ProtectedBinary ReadProtectedBinary(XmlReader xr) { if (xr.MoveToAttribute(AttrRef)) { string strRef = xr.Value; if (!string.IsNullOrEmpty(strRef)) { int iRef; if (StrUtil.TryParseIntInvariant(strRef, out iRef)) { ProtectedBinary pb = m_pbsBinaries.Get(iRef); if (pb != null) { // https://sourceforge.net/p/keepass/feature-requests/2023/ xr.MoveToElement(); #if DEBUG string strInner = ReadStringRaw(xr); Debug.Assert(string.IsNullOrEmpty(strInner)); #else ReadStringRaw(xr); #endif return(pb); } else { Debug.Assert(false); } } else { Debug.Assert(false); } } else { Debug.Assert(false); } } bool bCompressed = false; if (xr.MoveToAttribute(AttrCompressed)) { bCompressed = (xr.Value == ValTrue); } XorredBuffer xb = ProcessNode(xr); if (xb != null) { Debug.Assert(!bCompressed); // See SubWriteValue(ProtectedBinary value) try { return(new ProtectedBinary(true, xb)); } finally { xb.Dispose(); } } byte[] pbData = ReadBase64(xr, true); if (pbData.Length == 0) { return(new ProtectedBinary()); } if (bCompressed) { pbData = MemUtil.Decompress(pbData); } return(new ProtectedBinary(false, pbData)); }