xref: /reactos/sdk/tools/xml2sdb/xml2sdb.h (revision 8c2e9189)
1 /*
2  * PROJECT:     xml2sdb
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Define mapping of all shim database types to xml
5  * COPYRIGHT:   Copyright 2016-2018 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #pragma once
9 
10 #include <string>
11 #include <list>
12 #include <vector>
13 #include <map>
14 
15 #include <typedefs.h>
16 #include <guiddef.h>
17 #include "sdbtypes.h"
18 #include "sdbwrite.h"
19 #include "sdbtagid.h"
20 
21 namespace tinyxml2
22 {
23 class XMLHandle;
24 }
25 using tinyxml2::XMLHandle;
26 
27 typedef std::basic_string<WCHAR> sdbstring;
28 
29 struct Database;
30 
31 struct InExclude
32 {
33     InExclude() : Include(false) { ; }
34     bool fromXml(XMLHandle dbNode);
35     bool toSdb(PDB pdb, Database& db);
36 
37     std::string Module;
38     bool Include;
39 };
40 
41 struct ShimRef
42 {
43     ShimRef() : ShimTagid(0) { ; }
44 
45     bool fromXml(XMLHandle dbNode);
46     bool toSdb(PDB pdb, Database& db);
47 
48     std::string Name;
49     std::string CommandLine;
50     TAGID ShimTagid;
51     std::list<InExclude> InExcludes;
52 };
53 
54 struct FlagRef
55 {
56     FlagRef() : FlagTagid(0) { ; }
57 
58     bool fromXml(XMLHandle dbNode);
59     bool toSdb(PDB pdb, Database& db);
60 
61     std::string Name;
62     TAGID FlagTagid;
63 };
64 
65 struct Shim
66 {
67     Shim() : Tagid(0) { ; }
68 
69     bool fromXml(XMLHandle dbNode);
70     bool toSdb(PDB pdb, Database& db);
71 
72     std::string Name;
73     std::string DllFile;
74     GUID FixID;
75     TAGID Tagid;
76     std::list<InExclude> InExcludes;
77 };
78 
79 struct Flag
80 {
81     Flag() : Tagid(0), KernelFlags(0), UserFlags(0), ProcessParamFlags(0) { ; }
82 
83     bool fromXml(XMLHandle dbNode);
84     bool toSdb(PDB pdb, Database& db);
85 
86     std::string Name;
87     TAGID Tagid;
88     QWORD KernelFlags;
89     QWORD UserFlags;
90     QWORD ProcessParamFlags;
91 };
92 
93 
94 struct Layer
95 {
96     Layer() : Tagid(0) { ; }
97 
98     bool fromXml(XMLHandle dbNode);
99     bool toSdb(PDB pdb, Database& db);
100 
101     std::string Name;
102     TAGID Tagid;
103     std::list<ShimRef> ShimRefs;
104     std::list<FlagRef> FlagRefs;
105 };
106 
107 struct MatchingFile
108 {
109     MatchingFile() : Size(0), Checksum(0) {;}
110 
111     bool fromXml(XMLHandle dbNode);
112     bool toSdb(PDB pdb, Database& db);
113 
114     std::string Name;
115     DWORD Size;
116     DWORD Checksum;
117     std::string CompanyName;
118     std::string InternalName;
119     std::string ProductName;
120     std::string ProductVersion;
121     std::string FileVersion;
122     std::string BinFileVersion;
123     std::string LinkDate;
124     std::string VerLanguage;
125     std::string FileDescription;
126     std::string OriginalFilename;
127     std::string UptoBinFileVersion;
128     std::string LinkerVersion;
129 };
130 
131 struct Exe
132 {
133     Exe() : Tagid(0) { ; }
134 
135     bool fromXml(XMLHandle dbNode);
136     bool toSdb(PDB pdb, Database& db);
137 
138     std::string Name;
139     GUID ExeID;
140     std::string AppName;
141     std::string Vendor;
142     TAGID Tagid;
143     std::list<MatchingFile> MatchingFiles;
144     std::list<ShimRef> ShimRefs;
145     std::list<FlagRef> FlagRefs;
146 };
147 
148 struct Library
149 {
150     std::list<InExclude> InExcludes;
151     std::list<Shim> Shims;
152     std::list<Flag> Flags;
153 };
154 
155 struct Database
156 {
157 
158     bool fromXml(const char* fileName);
159     bool fromXml(XMLHandle dbNode);
160     bool toSdb(LPCWSTR path);
161 
162     void WriteString(PDB pdb, TAG tag, const sdbstring& str, bool always = false);
163     void WriteString(PDB pdb, TAG tag, const std::string& str, bool always = false);
164     void WriteBinary(PDB pdb, TAG tag, const GUID& guid, bool always = false);
165     void WriteBinary(PDB pdb, TAG tag, const std::vector<BYTE>& data, bool always = false);
166     void WriteDWord(PDB pdb, TAG tag, DWORD value, bool always = false);
167     void WriteQWord(PDB pdb, TAG tag, QWORD value, bool always = false);
168     TAGID BeginWriteListTag(PDB pdb, TAG tag);
169     BOOL EndWriteListTag(PDB pdb, TAGID tagid);
170 
171     void InsertShimTagid(const sdbstring& name, TAGID tagid);
172     inline void InsertShimTagid(const std::string& name, TAGID tagid)
173     {
174         InsertShimTagid(sdbstring(name.begin(), name.end()), tagid);
175     }
176     TAGID FindShimTagid(const sdbstring& name);
177     inline TAGID FindShimTagid(const std::string& name)
178     {
179         return FindShimTagid(sdbstring(name.begin(), name.end()));
180     }
181 
182 
183     void InsertPatchTagid(const sdbstring& name, TAGID tagid);
184     inline void InsertPatchTagid(const std::string& name, TAGID tagid)
185     {
186         InsertPatchTagid(sdbstring(name.begin(), name.end()), tagid);
187     }
188     TAGID FindPatchTagid(const sdbstring& name);
189     inline TAGID FindPatchTagid(const std::string& name)
190     {
191         return FindPatchTagid(sdbstring(name.begin(), name.end()));
192     }
193 
194     void InsertFlagTagid(const sdbstring& name, TAGID tagid);
195     inline void InsertFlagTagid(const std::string& name, TAGID tagid)
196     {
197         InsertFlagTagid(sdbstring(name.begin(), name.end()), tagid);
198     }
199     TAGID FindFlagTagid(const sdbstring& name);
200     inline TAGID FindFlagTagid(const std::string& name)
201     {
202         return FindFlagTagid(sdbstring(name.begin(), name.end()));
203     }
204 
205     std::string Name;
206     GUID ID;
207 
208     struct Library Library;
209     std::list<Layer> Layers;
210     std::list<Exe> Exes;
211 
212 private:
213     std::map<sdbstring, TAGID> KnownShims;
214     std::map<sdbstring, TAGID> KnownPatches;
215     std::map<sdbstring, TAGID> KnownFlags;
216 };
217 
218