Reactos
at master 245 lines 5.7 kB view raw
1/* 2 * PROJECT: xml2sdb 3 * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 * PURPOSE: Define mapping of all shim database types to xml 5 * COPYRIGHT: Copyright 2016-2025 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 21namespace tinyxml2 22{ 23class XMLHandle; 24} 25using tinyxml2::XMLHandle; 26 27typedef std::basic_string<WCHAR> sdbstring; 28 29struct Database; 30 31enum PlatformType 32{ 33 PLATFORM_NONE = 0, 34 35 // This is all we support for now 36 PLATFORM_X86 = 1, 37 // There is another platform here, but we don't support it yet 38 // https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/kshim/drvmain.htm 39 PLATFORM_AMD64 = 4, 40 41 PLATFORM_ANY = PLATFORM_X86 | PLATFORM_AMD64 42}; 43 44struct str_to_flag 45{ 46 const char *name; 47 DWORD flag; 48}; 49 50extern str_to_flag platform_to_flag[]; 51 52DWORD str_to_enum(const std::string &str, const str_to_flag *table); 53 54struct InExclude 55{ 56 bool fromXml(XMLHandle dbNode); 57 bool toSdb(Database& db); 58 59 std::string Module; 60 bool Include = false; 61}; 62 63struct ShimRef 64{ 65 bool fromXml(XMLHandle dbNode); 66 bool toSdb(Database& db); 67 68 std::string Name; 69 std::string CommandLine; 70 TAGID ShimTagid = 0; 71 std::list<InExclude> InExcludes; 72}; 73 74struct FlagRef 75{ 76 bool fromXml(XMLHandle dbNode); 77 bool toSdb(Database& db); 78 79 std::string Name; 80 TAGID FlagTagid = 0; 81}; 82 83struct Shim 84{ 85 bool fromXml(XMLHandle dbNode); 86 bool toSdb(Database& db); 87 88 std::string Name; 89 std::string DllFile; 90 GUID FixID = {}; 91 TAGID Tagid = 0; 92 std::list<InExclude> InExcludes; 93 PlatformType Platform = PLATFORM_ANY; 94}; 95 96struct Flag 97{ 98 bool fromXml(XMLHandle dbNode); 99 bool toSdb(Database& db); 100 101 std::string Name; 102 TAGID Tagid = 0; 103 QWORD KernelFlags = 0; 104 QWORD UserFlags = 0; 105 QWORD ProcessParamFlags = 0; 106}; 107 108 109struct Data 110{ 111 bool fromXml(XMLHandle dbNode); 112 bool toSdb(Database& db); 113 114 std::string Name; 115 TAGID Tagid = 0; 116 DWORD DataType = 0; 117 118 std::string StringData; 119 DWORD DWordData = 0; 120 QWORD QWordData = 0; 121}; 122 123struct Layer 124{ 125 bool fromXml(XMLHandle dbNode); 126 bool toSdb(Database& db); 127 128 std::string Name; 129 TAGID Tagid = 0; 130 std::list<ShimRef> ShimRefs; 131 std::list<FlagRef> FlagRefs; 132 std::list<Data> Datas; 133 PlatformType Platform = PLATFORM_ANY; 134}; 135 136struct MatchingFile 137{ 138 bool fromXml(XMLHandle dbNode); 139 bool toSdb(Database& db); 140 141 std::string Name; 142 DWORD Size = 0; 143 DWORD Checksum = 0; 144 std::string CompanyName; 145 std::string InternalName; 146 std::string ProductName; 147 std::string ProductVersion; 148 std::string FileVersion; 149 std::string BinFileVersion; 150 DWORD LinkDate = 0; 151 std::string VerLanguage; 152 std::string FileDescription; 153 std::string OriginalFilename; 154 std::string UptoBinFileVersion; 155 DWORD LinkerVersion = 0; 156}; 157 158struct Exe 159{ 160 bool fromXml(XMLHandle dbNode); 161 bool toSdb(Database& db); 162 163 std::string Name; 164 GUID ExeID = {}; 165 std::string AppName; 166 std::string Vendor; 167 TAGID Tagid = 0; 168 std::list<MatchingFile> MatchingFiles; 169 std::list<ShimRef> ShimRefs; 170 std::list<FlagRef> FlagRefs; 171 PlatformType Platform = PLATFORM_ANY; 172}; 173 174struct Library 175{ 176 std::list<InExclude> InExcludes; 177 std::list<Shim> Shims; 178 std::list<Flag> Flags; 179}; 180 181struct Database 182{ 183 bool fromXml(const char* fileName, PlatformType platform); 184 bool fromXml(XMLHandle dbNode); 185 bool toSdb(LPCWSTR path); 186 187 void WriteString(TAG tag, const sdbstring& str, bool always = false); 188 void WriteString(TAG tag, const std::string& str, bool always = false); 189 void WriteBinary(TAG tag, const GUID& guid, bool always = false); 190 void WriteBinary(TAG tag, const std::vector<BYTE>& data, bool always = false); 191 void WriteDWord(TAG tag, DWORD value, bool always = false); 192 void WriteQWord(TAG tag, QWORD value, bool always = false); 193 void WriteNull(TAG tag); 194 TAGID BeginWriteListTag(TAG tag); 195 BOOL EndWriteListTag(TAGID tagid); 196 197 void InsertShimTagid(const sdbstring& name, TAGID tagid); 198 inline void InsertShimTagid(const std::string& name, TAGID tagid) 199 { 200 InsertShimTagid(sdbstring(name.begin(), name.end()), tagid); 201 } 202 TAGID FindShimTagid(const sdbstring& name); 203 inline TAGID FindShimTagid(const std::string& name) 204 { 205 return FindShimTagid(sdbstring(name.begin(), name.end())); 206 } 207 208 209 void InsertPatchTagid(const sdbstring& name, TAGID tagid); 210 inline void InsertPatchTagid(const std::string& name, TAGID tagid) 211 { 212 InsertPatchTagid(sdbstring(name.begin(), name.end()), tagid); 213 } 214 TAGID FindPatchTagid(const sdbstring& name); 215 inline TAGID FindPatchTagid(const std::string& name) 216 { 217 return FindPatchTagid(sdbstring(name.begin(), name.end())); 218 } 219 220 void InsertFlagTagid(const sdbstring& name, TAGID tagid); 221 inline void InsertFlagTagid(const std::string& name, TAGID tagid) 222 { 223 InsertFlagTagid(sdbstring(name.begin(), name.end()), tagid); 224 } 225 TAGID FindFlagTagid(const sdbstring& name); 226 inline TAGID FindFlagTagid(const std::string& name) 227 { 228 return FindFlagTagid(sdbstring(name.begin(), name.end())); 229 } 230 231 std::string Name; 232 GUID ID = {}; 233 234 struct Library Library; 235 std::list<Layer> Layers; 236 std::list<Exe> Exes; 237 238private: 239 std::map<sdbstring, TAGID> KnownShims; 240 std::map<sdbstring, TAGID> KnownPatches; 241 std::map<sdbstring, TAGID> KnownFlags; 242 PDB pdb = nullptr; 243 PlatformType platform = PLATFORM_ANY; 244}; 245