void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Entry* entry) { if (entry) { writeUuid(qualifiedName, entry->uuid()); } else { writeUuid(qualifiedName, QUuid()); } }
void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Group* group) { if (group) { writeUuid(qualifiedName, group->uuid()); } else { writeUuid(qualifiedName, QUuid()); } }
void KdbxXmlWriter::writeDeletedObject(const DeletedObject& delObj) { m_xml.writeStartElement("DeletedObject"); writeUuid("UUID", delObj.uuid); writeDateTime("DeletionTime", delObj.deletionTime); m_xml.writeEndElement(); }
void KdbxXmlWriter::writeGroup(const Group* group) { Q_ASSERT(!group->uuid().isNull()); m_xml.writeStartElement("Group"); writeUuid("UUID", group->uuid()); writeString("Name", group->name()); writeString("Notes", group->notes()); writeNumber("IconID", group->iconNumber()); if (!group->iconUuid().isNull()) { writeUuid("CustomIconUUID", group->iconUuid()); } writeTimes(group->timeInfo()); writeBool("IsExpanded", group->isExpanded()); writeString("DefaultAutoTypeSequence", group->defaultAutoTypeSequence()); writeTriState("EnableAutoType", group->autoTypeEnabled()); writeTriState("EnableSearching", group->searchingEnabled()); writeUuid("LastTopVisibleEntry", group->lastTopVisibleEntry()); if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) { writeCustomData(group->customData()); } const QList<Entry*>& entryList = group->entries(); for (const Entry* entry : entryList) { writeEntry(entry); } const QList<Group*>& children = group->children(); for (const Group* child : children) { writeGroup(child); } m_xml.writeEndElement(); }
void KdbxXmlWriter::writeMetadata() { m_xml.writeStartElement("Meta"); writeString("Generator", m_meta->generator()); if (m_kdbxVersion < KeePass2::FILE_VERSION_4 && !m_headerHash.isEmpty()) { writeBinary("HeaderHash", m_headerHash); } writeString("DatabaseName", m_meta->name()); writeDateTime("DatabaseNameChanged", m_meta->nameChanged()); writeString("DatabaseDescription", m_meta->description()); writeDateTime("DatabaseDescriptionChanged", m_meta->descriptionChanged()); writeString("DefaultUserName", m_meta->defaultUserName()); writeDateTime("DefaultUserNameChanged", m_meta->defaultUserNameChanged()); writeNumber("MaintenanceHistoryDays", m_meta->maintenanceHistoryDays()); writeColor("Color", m_meta->color()); writeDateTime("MasterKeyChanged", m_meta->masterKeyChanged()); writeNumber("MasterKeyChangeRec", m_meta->masterKeyChangeRec()); writeNumber("MasterKeyChangeForce", m_meta->masterKeyChangeForce()); writeMemoryProtection(); writeCustomIcons(); writeBool("RecycleBinEnabled", m_meta->recycleBinEnabled()); writeUuid("RecycleBinUUID", m_meta->recycleBin()); writeDateTime("RecycleBinChanged", m_meta->recycleBinChanged()); writeUuid("EntryTemplatesGroup", m_meta->entryTemplatesGroup()); writeDateTime("EntryTemplatesGroupChanged", m_meta->entryTemplatesGroupChanged()); writeUuid("LastSelectedGroup", m_meta->lastSelectedGroup()); writeUuid("LastTopVisibleGroup", m_meta->lastTopVisibleGroup()); writeNumber("HistoryMaxItems", m_meta->historyMaxItems()); writeNumber("HistoryMaxSize", m_meta->historyMaxSize()); if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) { writeDateTime("SettingsChanged", m_meta->settingsChanged()); } if (m_kdbxVersion < KeePass2::FILE_VERSION_4) { writeBinaries(); } writeCustomData(m_meta->customData()); m_xml.writeEndElement(); }
void KdbxXmlWriter::writeIcon(const QUuid& uuid, const QImage& icon) { m_xml.writeStartElement("Icon"); writeUuid("UUID", uuid); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); // TODO: check !icon.save() icon.save(&buffer, "PNG"); buffer.close(); writeBinary("Data", ba); m_xml.writeEndElement(); }
void KdbxXmlWriter::writeEntry(const Entry* entry) { Q_ASSERT(!entry->uuid().isNull()); m_xml.writeStartElement("Entry"); writeUuid("UUID", entry->uuid()); writeNumber("IconID", entry->iconNumber()); if (!entry->iconUuid().isNull()) { writeUuid("CustomIconUUID", entry->iconUuid()); } writeColor("ForegroundColor", entry->foregroundColor()); writeColor("BackgroundColor", entry->backgroundColor()); writeString("OverrideURL", entry->overrideUrl()); writeString("Tags", entry->tags()); writeTimes(entry->timeInfo()); const QList<QString> attributesKeyList = entry->attributes()->keys(); for (const QString& key : attributesKeyList) { m_xml.writeStartElement("String"); // clang-format off bool protect = (((key == "Title") && m_meta->protectTitle()) || ((key == "UserName") && m_meta->protectUsername()) || ((key == "Password") && m_meta->protectPassword()) || ((key == "URL") && m_meta->protectUrl()) || ((key == "Notes") && m_meta->protectNotes()) || entry->attributes()->isProtected(key)); // clang-format on writeString("Key", key); m_xml.writeStartElement("Value"); QString value; if (protect) { if (!m_innerStreamProtectionDisabled && m_randomStream) { m_xml.writeAttribute("Protected", "True"); bool ok; QByteArray rawData = m_randomStream->process(entry->attributes()->value(key).toUtf8(), &ok); if (!ok) { raiseError(m_randomStream->errorString()); } value = QString::fromLatin1(rawData.toBase64()); } else { m_xml.writeAttribute("ProtectInMemory", "True"); value = entry->attributes()->value(key); } } else { value = entry->attributes()->value(key); } if (!value.isEmpty()) { m_xml.writeCharacters(stripInvalidXml10Chars(value)); } m_xml.writeEndElement(); m_xml.writeEndElement(); } const QList<QString> attachmentsKeyList = entry->attachments()->keys(); for (const QString& key : attachmentsKeyList) { m_xml.writeStartElement("Binary"); writeString("Key", key); m_xml.writeStartElement("Value"); m_xml.writeAttribute("Ref", QString::number(m_idMap[entry->attachments()->value(key)])); m_xml.writeEndElement(); m_xml.writeEndElement(); } writeAutoType(entry); if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) { writeCustomData(entry->customData()); } // write history only for entries that are not history items if (entry->parent()) { writeEntryHistory(entry); } m_xml.writeEndElement(); }
void MessageEncoder::writeMap(const qpid::types::Variant::Map& properties, const Descriptor* d, bool large) { void* token = large ? startMap32(d) : startMap8(d); for (qpid::types::Variant::Map::const_iterator i = properties.begin(); i != properties.end(); ++i) { writeString(i->first); switch (i->second.getType()) { case qpid::types::VAR_MAP: case qpid::types::VAR_LIST: //not allowed (TODO: revise, only strictly true for application-properties) whereas this is now a more general method) QPID_LOG(warning, "Ignoring nested map/list; not allowed in application-properties for AMQP 1.0"); case qpid::types::VAR_VOID: writeNull(); break; case qpid::types::VAR_BOOL: writeBoolean(i->second); break; case qpid::types::VAR_UINT8: writeUByte(i->second); break; case qpid::types::VAR_UINT16: writeUShort(i->second); break; case qpid::types::VAR_UINT32: writeUInt(i->second); break; case qpid::types::VAR_UINT64: writeULong(i->second); break; case qpid::types::VAR_INT8: writeByte(i->second); break; case qpid::types::VAR_INT16: writeShort(i->second); break; case qpid::types::VAR_INT32: writeInt(i->second); break; case qpid::types::VAR_INT64: writeULong(i->second); break; case qpid::types::VAR_FLOAT: writeFloat(i->second); break; case qpid::types::VAR_DOUBLE: writeDouble(i->second); break; case qpid::types::VAR_STRING: if (i->second.getEncoding() == BINARY) { writeBinary(i->second); } else { writeString(i->second); } break; case qpid::types::VAR_UUID: writeUuid(i->second); break; } } if (large) endMap32(properties.size()*2, token); else endMap8(properties.size()*2, token); }
void pnVaultNode::write(unsigned char* buffer, size_t size) const { if (size < sizeof(uint64_t)) { plDebug::Error("Invalid node buffer"); return; } writeU64(fDirtyMask, buffer, size); for (size_t bit=0; bit<kNumFields; bit++) { if ((fDirtyMask & (1ULL<<bit)) == 0) continue; switch (bit) { case kNodeIdx: writeU32(fNodeIdx, buffer, size); break; case kCreateTime: writeU32(fCreateTime, buffer, size); break; case kModifyTime: writeU32(fModifyTime, buffer, size); break; case kCreateAgeName: writeString(fCreateAgeName, buffer, size); break; case kCreateAgeUuid: writeUuid(fCreateAgeUuid, buffer, size); break; case kCreatorUuid: writeUuid(fCreatorUuid, buffer, size); break; case kCreatorIdx: writeU32(fCreatorIdx, buffer, size); break; case kNodeType: writeU32(fNodeType, buffer, size); break; case kInt32_1: case kInt32_2: case kInt32_3: case kInt32_4: writeS32(fInt32[bit - kInt32_1], buffer, size); break; case kUint32_1: case kUint32_2: case kUint32_3: case kUint32_4: writeU32(fUint32[bit - kUint32_1], buffer, size); break; case kUuid_1: case kUuid_2: case kUuid_3: case kUuid_4: writeUuid(fUuid[bit - kUuid_1], buffer, size); break; case kString64_1: case kString64_2: case kString64_3: case kString64_4: case kString64_5: case kString64_6: writeString(fString64[bit - kString64_1], buffer, size); break; case kIString64_1: case kIString64_2: writeString(fIString64[bit - kIString64_1], buffer, size); break; case kText_1: case kText_2: writeString(fText[bit - kText_1], buffer, size); break; case kBlob_1: case kBlob_2: writeU32(fBlob[bit - kBlob_1].getSize(), buffer, size); memcpy(buffer, fBlob[bit - kBlob_1].getData(), fBlob[bit - kBlob_1].getSize()); buffer += fBlob[bit - kBlob_1].getSize(); size -= fBlob[bit - kBlob_1].getSize(); break; } } if (size != 0) plDebug::Warning("Node %d is truncated", fNodeIdx); }