xref: /reactos/sdk/tools/xml2sdb/xml2sdb.h (revision c7bba39a)
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 Data
95 {
96     Data() : Tagid(0), DataType(0), DWordData(0), QWordData(0) { ; }
97 
98     bool fromXml(XMLHandle dbNode);
99     bool toSdb(PDB pdb, Database& db);
100 
101     std::string Name;
102     TAGID Tagid;
103     DWORD DataType;
104 
105     std::string StringData;
106     DWORD DWordData;
107     QWORD QWordData;
108 };
109 
110 struct Layer
111 {
112     Layer() : Tagid(0) { ; }
113 
114     bool fromXml(XMLHandle dbNode);
115     bool toSdb(PDB pdb, Database& db);
116 
117     std::string Name;
118     TAGID Tagid;
119     std::list<ShimRef> ShimRefs;
120     std::list<FlagRef> FlagRefs;
121     std::list<Data> Datas;
122 };
123 
124 struct MatchingFile
125 {
126     MatchingFile() : Size(0), Checksum(0) {;}
127 
128     bool fromXml(XMLHandle dbNode);
129     bool toSdb(PDB pdb, Database& db);
130 
131     std::string Name;
132     DWORD Size;
133     DWORD Checksum;
134     std::string CompanyName;
135     std::string InternalName;
136     std::string ProductName;
137     std::string ProductVersion;
138     std::string FileVersion;
139     std::string BinFileVersion;
140     std::string LinkDate;
141     std::string VerLanguage;
142     std::string FileDescription;
143     std::string OriginalFilename;
144     std::string UptoBinFileVersion;
145     std::string LinkerVersion;
146 };
147 
148 struct Exe
149 {
150     Exe() : Tagid(0) { ; }
151 
152     bool fromXml(XMLHandle dbNode);
153     bool toSdb(PDB pdb, Database& db);
154 
155     std::string Name;
156     GUID ExeID;
157     std::string AppName;
158     std::string Vendor;
159     TAGID Tagid;
160     std::list<MatchingFile> MatchingFiles;
161     std::list<ShimRef> ShimRefs;
162     std::list<FlagRef> FlagRefs;
163 };
164 
165 struct Library
166 {
167     std::list<InExclude> InExcludes;
168     std::list<Shim> Shims;
169     std::list<Flag> Flags;
170 };
171 
172 struct Database
173 {
174 
175     bool fromXml(const char* fileName);
176     bool fromXml(XMLHandle dbNode);
177     bool toSdb(LPCWSTR path);
178 
179     void WriteString(PDB pdb, TAG tag, const sdbstring& str, bool always = false);
180     void WriteString(PDB pdb, TAG tag, const std::string& str, bool always = false);
181     void WriteBinary(PDB pdb, TAG tag, const GUID& guid, bool always = false);
182     void WriteBinary(PDB pdb, TAG tag, const std::vector<BYTE>& data, bool always = false);
183     void WriteDWord(PDB pdb, TAG tag, DWORD value, bool always = false);
184     void WriteQWord(PDB pdb, TAG tag, QWORD value, bool always = false);
185     TAGID BeginWriteListTag(PDB pdb, TAG tag);
186     BOOL EndWriteListTag(PDB pdb, TAGID tagid);
187 
188     void InsertShimTagid(const sdbstring& name, TAGID tagid);
189     inline void InsertShimTagid(const std::string& name, TAGID tagid)
190     {
191         InsertShimTagid(sdbstring(name.begin(), name.end()), tagid);
192     }
193     TAGID FindShimTagid(const sdbstring& name);
194     inline TAGID FindShimTagid(const std::string& name)
195     {
196         return FindShimTagid(sdbstring(name.begin(), name.end()));
197     }
198 
199 
200     void InsertPatchTagid(const sdbstring& name, TAGID tagid);
201     inline void InsertPatchTagid(const std::string& name, TAGID tagid)
202     {
203         InsertPatchTagid(sdbstring(name.begin(), name.end()), tagid);
204     }
205     TAGID FindPatchTagid(const sdbstring& name);
206     inline TAGID FindPatchTagid(const std::string& name)
207     {
208         return FindPatchTagid(sdbstring(name.begin(), name.end()));
209     }
210 
211     void InsertFlagTagid(const sdbstring& name, TAGID tagid);
212     inline void InsertFlagTagid(const std::string& name, TAGID tagid)
213     {
214         InsertFlagTagid(sdbstring(name.begin(), name.end()), tagid);
215     }
216     TAGID FindFlagTagid(const sdbstring& name);
217     inline TAGID FindFlagTagid(const std::string& name)
218     {
219         return FindFlagTagid(sdbstring(name.begin(), name.end()));
220     }
221 
222     std::string Name;
223     GUID ID;
224 
225     struct Library Library;
226     std::list<Layer> Layers;
227     std::list<Exe> Exes;
228 
229 private:
230     std::map<sdbstring, TAGID> KnownShims;
231     std::map<sdbstring, TAGID> KnownPatches;
232     std::map<sdbstring, TAGID> KnownFlags;
233 };
234 
235