https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1d0e7bddea48cca2023bb…
commit 1d0e7bddea48cca2023bb3d62a962b3647e4918c
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Wed Jan 24 22:35:12 2018 +0100
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sat Jan 27 15:12:24 2018 +0100
[XML2SDB] Parse Flags.
---
sdk/tools/xml2sdb/xml2sdb.cpp | 92 ++++++++++++++++++++++++++++++++++++++++---
sdk/tools/xml2sdb/xml2sdb.h | 46 +++++++++++++++++++++-
2 files changed, 131 insertions(+), 7 deletions(-)
diff --git a/sdk/tools/xml2sdb/xml2sdb.cpp b/sdk/tools/xml2sdb/xml2sdb.cpp
index 4d136d2606..091177362f 100644
--- a/sdk/tools/xml2sdb/xml2sdb.cpp
+++ b/sdk/tools/xml2sdb/xml2sdb.cpp
@@ -2,7 +2,7 @@
* PROJECT: xml2sdb
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Conversion functions from xml -> db
- * COPYRIGHT: Copyright 2016,2017 Mark Jansen (mark.jansen(a)reactos.org)
+ * COPYRIGHT: Copyright 2016-2018 Mark Jansen (mark.jansen(a)reactos.org)
*/
#include "xml2sdb.h"
@@ -14,7 +14,7 @@
using tinyxml2::XMLText;
static const GUID GUID_NULL = { 0 };
-static const char szCompilerVersion[] = "1.6.0.0";
+static const char szCompilerVersion[] = "1.7.0.0";
#if !defined(C_ASSERT)
#define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
@@ -88,7 +88,7 @@ std::string ReadStringNode(XMLHandle dbNode, const char* nodeName)
return ToString(dbNode.FirstChildElement(nodeName));
}
-DWORD ReadDWordNode(XMLHandle dbNode, const char* nodeName)
+DWORD ReadQWordNode(XMLHandle dbNode, const char* nodeName)
{
std::string value = ReadStringNode(dbNode, nodeName);
int base = 10;
@@ -97,7 +97,12 @@ DWORD ReadDWordNode(XMLHandle dbNode, const char* nodeName)
base = 16;
value = value.substr(2);
}
- return static_cast<DWORD>(strtoul(value.c_str(), NULL, base));
+ return static_cast<QWORD>(strtoul(value.c_str(), NULL, base));
+}
+
+DWORD ReadDWordNode(XMLHandle dbNode, const char* nodeName)
+{
+ return static_cast<DWORD>(ReadQWordNode(dbNode, nodeName));
}
unsigned char char2byte(char hexChar, bool* success = NULL)
@@ -310,6 +315,29 @@ bool ShimRef::toSdb(PDB pdb, Database& db)
}
+
+/***********************************************************************
+ * FlagRef
+ */
+
+bool FlagRef::fromXml(XMLHandle dbNode)
+{
+ Name = ReadStringNode(dbNode, "NAME");
+ return !Name.empty();
+}
+
+bool FlagRef::toSdb(PDB pdb, Database& db)
+{
+ TAGID tagid = db.BeginWriteListTag(pdb, TAG_FLAG_REF);
+ db.WriteString(pdb, TAG_NAME, Name, true);
+
+ if (!FlagTagid)
+ FlagTagid = db.FindFlagTagid(Name);
+ SdbWriteDWORDTag(pdb, TAG_FLAG_TAGID, FlagTagid);
+ return !!db.EndWriteListTag(pdb, tagid);
+}
+
+
/***********************************************************************
* Shim
*/
@@ -341,6 +369,35 @@ bool Shim::toSdb(PDB pdb, Database& db)
}
+/***********************************************************************
+ * Flag
+ */
+
+bool Flag::fromXml(XMLHandle dbNode)
+{
+ Name = ReadStringNode(dbNode, "NAME");
+
+ KernelFlags = ReadQWordNode(dbNode, "FLAG_MASK_KERNEL");
+ UserFlags = ReadQWordNode(dbNode, "FLAG_MASK_USER");
+ ProcessParamFlags = ReadQWordNode(dbNode, "FLAG_PROCESSPARAM");
+
+ return !Name.empty();
+}
+
+bool Flag::toSdb(PDB pdb, Database& db)
+{
+ Tagid = db.BeginWriteListTag(pdb, TAG_FLAG);
+ db.InsertFlagTagid(Name, Tagid);
+ db.WriteString(pdb, TAG_NAME, Name, true);
+
+ db.WriteQWord(pdb, TAG_FLAG_MASK_KERNEL, KernelFlags);
+ db.WriteQWord(pdb, TAG_FLAG_MASK_USER, UserFlags);
+ db.WriteQWord(pdb, TAG_FLAG_PROCESSPARAM, ProcessParamFlags);
+
+ return !!db.EndWriteListTag(pdb, Tagid);
+}
+
+
/***********************************************************************
* Layer
*/
@@ -349,6 +406,7 @@ bool Layer::fromXml(XMLHandle dbNode)
{
Name = ReadStringNode(dbNode, "NAME");
ReadGeneric(dbNode, ShimRefs, "SHIM_REF");
+ ReadGeneric(dbNode, FlagRefs, "FLAG_REF");
return true;
}
@@ -358,6 +416,8 @@ bool Layer::toSdb(PDB pdb, Database& db)
db.WriteString(pdb, TAG_NAME, Name, true);
if (!WriteGeneric(pdb, ShimRefs, db))
return false;
+ if (!WriteGeneric(pdb, FlagRefs, db))
+ return false;
return !!db.EndWriteListTag(pdb, Tagid);
}
@@ -430,6 +490,7 @@ bool Exe::fromXml(XMLHandle dbNode)
ReadGeneric(dbNode, MatchingFiles, "MATCHING_FILE");
ReadGeneric(dbNode, ShimRefs, "SHIM_REF");
+ ReadGeneric(dbNode, FlagRefs, "FLAG_REF");
return !Name.empty();
}
@@ -451,6 +512,8 @@ bool Exe::toSdb(PDB pdb, Database& db)
return false;
if (!WriteGeneric(pdb, ShimRefs, db))
return false;
+ if (!WriteGeneric(pdb, FlagRefs, db))
+ return false;
return !!db.EndWriteListTag(pdb, Tagid);
}
@@ -489,6 +552,12 @@ void Database::WriteDWord(PDB pdb, TAG tag, DWORD value, bool
always)
SdbWriteDWORDTag(pdb, tag, value);
}
+void Database::WriteQWord(PDB pdb, TAG tag, QWORD value, bool always)
+{
+ if (always || value)
+ SdbWriteQWORDTag(pdb, tag, value);
+}
+
TAGID Database::BeginWriteListTag(PDB pdb, TAG tag)
{
return SdbBeginWriteListTag(pdb, tag);
@@ -516,7 +585,9 @@ bool Database::fromXml(XMLHandle dbNode)
}
else if (NodeName == "FLAG")
{
- SHIM_ERR("Unhanled FLAG type\n");
+ Flag flag;
+ if (flag.fromXml(libChild))
+ Library.Flags.push_back(flag);
}
else if (NodeName == "INCLUDE" || NodeName == "EXCLUDE")
{
@@ -561,6 +632,8 @@ bool Database::toSdb(LPCWSTR path)
return false;
if (!WriteGeneric(pdb, Library.Shims, *this))
return false;
+ if (!WriteGeneric(pdb, Library.Flags, *this))
+ return false;
EndWriteListTag(pdb, tidLibrary);
if (!WriteGeneric(pdb, Layers, *this))
return false;
@@ -615,6 +688,15 @@ TAGID Database::FindPatchTagid(const sdbstring& name)
return FindTagid(name, KnownPatches);
}
+void Database::InsertFlagTagid(const sdbstring& name, TAGID tagid)
+{
+ InsertTagid(name, tagid, KnownFlags, "Flag");
+}
+
+TAGID Database::FindFlagTagid(const sdbstring& name)
+{
+ return FindTagid(name, KnownFlags);
+}
bool xml_2_db(const char* xml, const WCHAR* sdb)
diff --git a/sdk/tools/xml2sdb/xml2sdb.h b/sdk/tools/xml2sdb/xml2sdb.h
index 201348f5a6..031b9ffcea 100644
--- a/sdk/tools/xml2sdb/xml2sdb.h
+++ b/sdk/tools/xml2sdb/xml2sdb.h
@@ -1,8 +1,8 @@
/*
* PROJECT: xml2sdb
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
- * PURPOSE: .
- * COPYRIGHT: Copyright 2016,2017 Mark Jansen (mark.jansen(a)reactos.org)
+ * PURPOSE: Define mapping of all shim database types to xml
+ * COPYRIGHT: Copyright 2016-2018 Mark Jansen (mark.jansen(a)reactos.org)
*/
#pragma once
@@ -51,6 +51,17 @@ struct ShimRef
std::list<InExclude> InExcludes;
};
+struct FlagRef
+{
+ FlagRef() : FlagTagid(0) { ; }
+
+ bool fromXml(XMLHandle dbNode);
+ bool toSdb(PDB pdb, Database& db);
+
+ std::string Name;
+ TAGID FlagTagid;
+};
+
struct Shim
{
Shim() : Tagid(0) { ; }
@@ -65,6 +76,21 @@ struct Shim
std::list<InExclude> InExcludes;
};
+struct Flag
+{
+ Flag() : Tagid(0), KernelFlags(0), UserFlags(0), ProcessParamFlags(0) { ; }
+
+ bool fromXml(XMLHandle dbNode);
+ bool toSdb(PDB pdb, Database& db);
+
+ std::string Name;
+ TAGID Tagid;
+ QWORD KernelFlags;
+ QWORD UserFlags;
+ QWORD ProcessParamFlags;
+};
+
+
struct Layer
{
Layer() : Tagid(0) { ; }
@@ -75,6 +101,7 @@ struct Layer
std::string Name;
TAGID Tagid;
std::list<ShimRef> ShimRefs;
+ std::list<FlagRef> FlagRefs;
};
struct MatchingFile
@@ -115,12 +142,14 @@ struct Exe
TAGID Tagid;
std::list<MatchingFile> MatchingFiles;
std::list<ShimRef> ShimRefs;
+ std::list<FlagRef> FlagRefs;
};
struct Library
{
std::list<InExclude> InExcludes;
std::list<Shim> Shims;
+ std::list<Flag> Flags;
};
struct Database
@@ -135,6 +164,7 @@ struct Database
void WriteBinary(PDB pdb, TAG tag, const GUID& guid, bool always = false);
void WriteBinary(PDB pdb, TAG tag, const std::vector<BYTE>& data, bool
always = false);
void WriteDWord(PDB pdb, TAG tag, DWORD value, bool always = false);
+ void WriteQWord(PDB pdb, TAG tag, QWORD value, bool always = false);
TAGID BeginWriteListTag(PDB pdb, TAG tag);
BOOL EndWriteListTag(PDB pdb, TAGID tagid);
@@ -161,6 +191,17 @@ struct Database
return FindPatchTagid(sdbstring(name.begin(), name.end()));
}
+ void InsertFlagTagid(const sdbstring& name, TAGID tagid);
+ inline void InsertFlagTagid(const std::string& name, TAGID tagid)
+ {
+ InsertFlagTagid(sdbstring(name.begin(), name.end()), tagid);
+ }
+ TAGID FindFlagTagid(const sdbstring& name);
+ inline TAGID FindFlagTagid(const std::string& name)
+ {
+ return FindFlagTagid(sdbstring(name.begin(), name.end()));
+ }
+
std::string Name;
GUID ID;
@@ -171,5 +212,6 @@ struct Database
private:
std::map<sdbstring, TAGID> KnownShims;
std::map<sdbstring, TAGID> KnownPatches;
+ std::map<sdbstring, TAGID> KnownFlags;
};