ReactOS 0.4.16-dev-1946-g52006dd
xml2sdb.cpp File Reference
#include "xml2sdb.h"
#include "sdbpapi.h"
#include "tinyxml2.h"
#include <time.h>
#include <algorithm>
#include <sstream>
Include dependency graph for xml2sdb.cpp:

Go to the source code of this file.

Macros

#define C_ASSERT(expr)   extern char (*c_assert(void)) [(expr) ? 1 : -1]
 
#define REG_SZ   1
 
#define REG_DWORD   4
 
#define REG_QWORD   11
 

Functions

 C_ASSERT (sizeof(GUID)==16)
 
 C_ASSERT (sizeof(ULONG)==4)
 
 C_ASSERT (sizeof(LARGE_INTEGER)==8)
 
 C_ASSERT (sizeof(WCHAR)==2)
 
 C_ASSERT (sizeof(wchar_t)==2)
 
 C_ASSERT (sizeof(TAG)==2)
 
 C_ASSERT (sizeof(TAGID)==4)
 
VOID NTAPI RtlSecondsSince1970ToTime (IN ULONG SecondsSince1970, OUT PLARGE_INTEGER Time)
 
DWORD str_to_enum (const std::string &str, const str_to_flag *table)
 
bool IsEmptyGuid (const GUID &g)
 
void RandomGuid (GUID &g)
 
std::string ToString (XMLHandle node)
 
std::string ToNodeName (XMLHandle node)
 
std::string ReadStringNode (XMLHandle dbNode, const char *nodeName)
 
QWORD ReadQWordNode (XMLHandle dbNode, const char *nodeName)
 
DWORD ReadDWordNode (XMLHandle dbNode, const char *nodeName)
 
PlatformType ReadPlatformNode (XMLHandle dbNode, const char *nodeName)
 
unsigned char char2byte (char hexChar, bool *success=NULL)
 
static bool StringToGuid (const std::string &str, GUID &guid)
 
bool ReadGuidNode (XMLHandle dbNode, const char *nodeName, GUID &guid)
 
bool ReadBinaryNode (XMLHandle dbNode, const char *nodeName, std::vector< BYTE > &data)
 
template<typename T >
void ReadGeneric (XMLHandle dbNode, std::list< T > &result, const char *nodeName)
 
template<typename T >
void ReadGeneric (XMLHandle dbNode, std::list< T > &result, const char *nodeName, PlatformType platform)
 
template<typename T >
bool WriteGeneric (std::list< T > &data, Database &db)
 
static void InsertTagid (const sdbstring &name, TAGID tagid, std::map< sdbstring, TAGID > &lookup, const char *type)
 
static TAGID FindTagid (const sdbstring &name, const std::map< sdbstring, TAGID > &lookup)
 

Variables

static const GUID GUID_NULL = { 0 }
 
static const char szCompilerVersion [] = "1.8.0.0"
 
str_to_flag platform_to_flag []
 

Macro Definition Documentation

◆ C_ASSERT

#define C_ASSERT (   expr)    extern char (*c_assert(void)) [(expr) ? 1 : -1]

Definition at line 21 of file xml2sdb.cpp.

◆ REG_DWORD

#define REG_DWORD   4

Definition at line 462 of file xml2sdb.cpp.

◆ REG_QWORD

#define REG_QWORD   11

Definition at line 463 of file xml2sdb.cpp.

◆ REG_SZ

#define REG_SZ   1

Definition at line 460 of file xml2sdb.cpp.

Function Documentation

◆ C_ASSERT() [1/7]

C_ASSERT ( sizeof(GUID = =16)

◆ C_ASSERT() [2/7]

C_ASSERT ( sizeof(LARGE_INTEGER = =8)

◆ C_ASSERT() [3/7]

C_ASSERT ( sizeof(TAG = =2)

◆ C_ASSERT() [4/7]

C_ASSERT ( sizeof(TAGID = =4)

◆ C_ASSERT() [5/7]

C_ASSERT ( sizeof(ULONG = =4)

◆ C_ASSERT() [6/7]

C_ASSERT ( sizeof(WCHAR = =2)

◆ C_ASSERT() [7/7]

C_ASSERT ( sizeof(wchar_t = =2)

◆ char2byte()

unsigned char char2byte ( char  hexChar,
bool success = NULL 
)

Definition at line 148 of file xml2sdb.cpp.

149{
150 if (hexChar >= '0' && hexChar <= '9')
151 return hexChar - '0';
152 if (hexChar >= 'A' && hexChar <= 'F')
153 return hexChar - 'A' + 10;
154 if (hexChar >= 'a' && hexChar <= 'f')
155 return hexChar - 'a' + 10;
156
157 if (success)
158 *success = false;
159 return 0;
160}
#define hexChar
Definition: udf_info.cpp:45
#define success(from, fromstr, to, tostr)

Referenced by ReadBinaryNode(), and StringToGuid().

◆ FindTagid()

static TAGID FindTagid ( const sdbstring name,
const std::map< sdbstring, TAGID > &  lookup 
)
static

Definition at line 787 of file xml2sdb.cpp.

788{
789 sdbstring nameLower = name;
790 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
791 std::map<sdbstring, TAGID>::const_iterator it = lookup.find(nameLower);
792 if (it == lookup.end())
793 return 0;
794 return it->second;
795}
int tolower(int c)
Definition: utclib.c:902
static ULONG lookup[16]
Definition: vga.c:48
Definition: name.c:39
std::basic_string< WCHAR > sdbstring
Definition: xml2sdb.h:27

Referenced by Database::FindFlagTagid(), Database::FindPatchTagid(), and Database::FindShimTagid().

◆ InsertTagid()

static void InsertTagid ( const sdbstring name,
TAGID  tagid,
std::map< sdbstring, TAGID > &  lookup,
const char type 
)
static

Definition at line 774 of file xml2sdb.cpp.

775{
776 sdbstring nameLower = name;
777 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
778 if (lookup.find(nameLower) != lookup.end())
779 {
780 std::string nameA(name.begin(), name.end());
781 SHIM_WARN("%s '%s' redefined\n", type, nameA.c_str());
782 return;
783 }
784 lookup[nameLower] = tagid;
785}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define SHIM_WARN(fmt,...)
Definition: sdbpapi.h:77

Referenced by Database::InsertFlagTagid(), Database::InsertPatchTagid(), and Database::InsertShimTagid().

◆ IsEmptyGuid()

bool IsEmptyGuid ( const GUID g)

Definition at line 77 of file xml2sdb.cpp.

78{
79 return !memcmp(&g, &GUID_NULL, sizeof(GUID));
80}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLboolean GLboolean g
Definition: glext.h:6204
static const GUID GUID_NULL
Definition: xml2sdb.cpp:17

Referenced by Shim::toSdb(), Exe::toSdb(), Database::toSdb(), and Database::WriteBinary().

◆ RandomGuid()

void RandomGuid ( GUID g)

Definition at line 82 of file xml2sdb.cpp.

83{
84 BYTE* p = (BYTE*)&g;
85 for (size_t n = 0; n < sizeof(GUID); ++n)
86 p[n] = (BYTE)(rand() % 0xff);
87}
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
unsigned char BYTE
Definition: xxhash.c:193

Referenced by Shim::toSdb(), Exe::toSdb(), and Database::toSdb().

◆ ReadBinaryNode()

bool ReadBinaryNode ( XMLHandle  dbNode,
const char nodeName,
std::vector< BYTE > &  data 
)

Definition at line 262 of file xml2sdb.cpp.

263{
264 std::string value = ReadStringNode(dbNode, nodeName);
265 value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
266
267 size_t length = value.size() / 2;
268 if (length * 2 != value.size())
269 return false;
270
271 data.resize(length);
272 for (size_t n = 0; n < length; ++n)
273 {
274 data[n] = (BYTE)(char2byte(value[n * 2]) << 4 | char2byte(value[(n * 2) + 1]));
275 }
276 return true;
277}
#define isspace(c)
Definition: acclib.h:69
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
Definition: pdh_main.c:96
unsigned char char2byte(char hexChar, bool *success=NULL)
Definition: xml2sdb.cpp:148
std::string ReadStringNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:110

◆ ReadDWordNode()

DWORD ReadDWordNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 134 of file xml2sdb.cpp.

135{
136 return static_cast<DWORD>(ReadQWordNode(dbNode, nodeName));
137}
unsigned long DWORD
Definition: ntddk_ex.h:95
QWORD ReadQWordNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:122

Referenced by Data::fromXml(), and MatchingFile::fromXml().

◆ ReadGeneric() [1/2]

template<typename T >
void ReadGeneric ( XMLHandle  dbNode,
std::list< T > &  result,
const char nodeName 
)

Definition at line 307 of file xml2sdb.cpp.

308{
309 XMLHandle node = dbNode.FirstChildElement(nodeName);
310 while (node.ToNode())
311 {
312 T object;
313 if (object.fromXml(node))
314 result.push_back(object);
315
316 node = node.NextSiblingElement(nodeName);
317 }
318}
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:1814
GLuint64EXT * result
Definition: glext.h:11304
#define T(num)
Definition: thunks.c:311
Definition: dlist.c:348

Referenced by ShimRef::fromXml(), Shim::fromXml(), Layer::fromXml(), Exe::fromXml(), and Database::fromXml().

◆ ReadGeneric() [2/2]

template<typename T >
void ReadGeneric ( XMLHandle  dbNode,
std::list< T > &  result,
const char nodeName,
PlatformType  platform 
)

Definition at line 321 of file xml2sdb.cpp.

322{
323 XMLHandle node = dbNode.FirstChildElement(nodeName);
324 while (node.ToNode())
325 {
326 T object;
327 if (object.fromXml(node) && ((object.Platform & platform) != PLATFORM_NONE))
328 result.push_back(object);
329
330 node = node.NextSiblingElement(nodeName);
331 }
332}
platform
Definition: msipriv.h:364
@ PLATFORM_NONE
Definition: xml2sdb.h:33

◆ ReadGuidNode()

bool ReadGuidNode ( XMLHandle  dbNode,
const char nodeName,
GUID guid 
)

Definition at line 251 of file xml2sdb.cpp.

252{
253 std::string value = ReadStringNode(dbNode, nodeName);
254 if (!StringToGuid(value, guid))
255 {
256 memset(&guid, 0, sizeof(GUID));
257 return false;
258 }
259 return true;
260}
GUID guid
Definition: version.c:147
#define memset(x, y, z)
Definition: compat.h:39
static bool StringToGuid(const std::string &str, GUID &guid)
Definition: xml2sdb.cpp:163

Referenced by Shim::fromXml(), Exe::fromXml(), and Database::fromXml().

◆ ReadPlatformNode()

PlatformType ReadPlatformNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 139 of file xml2sdb.cpp.

140{
141 std::string value = ReadStringNode(dbNode, nodeName);
142 if (value.empty())
143 return PLATFORM_ANY;
145 return static_cast<PlatformType>(platform);
146}
DWORD str_to_enum(const std::string &str, const str_to_flag *table)
Definition: xml2sdb.cpp:51
str_to_flag platform_to_flag[]
Definition: xml2sdb.cpp:42
PlatformType
Definition: xml2sdb.h:32
@ PLATFORM_ANY
Definition: xml2sdb.h:41

Referenced by Exe::fromXml().

◆ ReadQWordNode()

QWORD ReadQWordNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 122 of file xml2sdb.cpp.

123{
124 std::string value = ReadStringNode(dbNode, nodeName);
125 int base = 10;
126 if (value.size() > 2 && value[0] == '0' && value[1] == 'x')
127 {
128 base = 16;
129 value = value.substr(2);
130 }
131 return static_cast<QWORD>(strtoull(value.c_str(), NULL, base));
132}
#define NULL
Definition: types.h:112
UINT64 QWORD
Definition: shimdbg.c:104
#define strtoull
Definition: stabs.c:58

Referenced by Flag::fromXml(), Data::fromXml(), and ReadDWordNode().

◆ ReadStringNode()

std::string ReadStringNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 110 of file xml2sdb.cpp.

111{
113 if (elem)
114 {
115 const char* rawVal = elem->Attribute(nodeName);
116 if (rawVal)
117 return std::string(rawVal);
118 }
119 return ToString(dbNode.FirstChildElement(nodeName));
120}
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:1847
static size_t elem
Definition: string.c:71
std::string ToString(XMLHandle node)
Definition: xml2sdb.cpp:90

Referenced by InExclude::fromXml(), ShimRef::fromXml(), FlagRef::fromXml(), Shim::fromXml(), Flag::fromXml(), Data::fromXml(), Layer::fromXml(), MatchingFile::fromXml(), Exe::fromXml(), Database::fromXml(), ReadBinaryNode(), ReadGuidNode(), ReadPlatformNode(), and ReadQWordNode().

◆ RtlSecondsSince1970ToTime()

VOID NTAPI RtlSecondsSince1970ToTime ( IN ULONG  SecondsSince1970,
OUT PLARGE_INTEGER  Time 
)

Definition at line 406 of file time.c.

408{
409 Time->QuadPart = ((LONGLONG)SecondsSince1970 * TICKSPERSEC) + TICKSTO1970;
410}
static PLARGE_INTEGER Time
Definition: time.c:105
#define TICKSPERSEC
Definition: time.c:17
#define TICKSTO1970
Definition: time.c:35
int64_t LONGLONG
Definition: typedefs.h:68
LONGLONG QuadPart
Definition: typedefs.h:114

◆ str_to_enum()

DWORD str_to_enum ( const std::string &  str,
const str_to_flag table 
)

Definition at line 51 of file xml2sdb.cpp.

52{
53 DWORD value = 0;
54 std::istringstream iss(str);
55 std::string item;
56 while (std::getline(iss, item, ','))
57 {
58 std::string trimmedItem = item;
59 trimmedItem.erase(remove_if(trimmedItem.begin(), trimmedItem.end(), isspace), trimmedItem.end());
60 std::transform(trimmedItem.begin(), trimmedItem.end(), trimmedItem.begin(), ::toupper);
61 for (const str_to_flag* p = table; p->name; ++p)
62 {
63 if (trimmedItem == p->name)
64 {
65 value |= p->flag;
66 break;
67 }
68 }
69 }
70 return value;
71}
_STLP_INLINE_LOOP _ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred)
Definition: _algo.h:278
int toupper(int c)
Definition: utclib.c:881
const WCHAR * str
const WCHAR * name

Referenced by parse_platform(), and ReadPlatformNode().

◆ StringToGuid()

static bool StringToGuid ( const std::string &  str,
GUID guid 
)
static

Definition at line 163 of file xml2sdb.cpp.

164{
165 const char *lpszGUID = str.c_str();
166 BYTE* lpOut = (BYTE*)&guid;
167 int i = 0;
168 bool expectBrace = true;
169 while (i <= 37)
170 {
171 switch (i)
172 {
173 case 0:
174 if (*lpszGUID != '{')
175 {
176 i++;
177 expectBrace = false;
178 continue;
179 }
180 break;
181
182 case 9:
183 case 14:
184 case 19:
185 case 24:
186 if (*lpszGUID != '-')
187 return false;
188 break;
189
190 case 37:
191 return expectBrace == (*lpszGUID == '}');
192
193 default:
194 {
195 CHAR ch = *lpszGUID, ch2 = lpszGUID[1];
196 unsigned char byte;
197 bool converted = true;
198
199 byte = char2byte(ch, &converted) << 4 | char2byte(ch2, &converted);
200 if (!converted)
201 return false;
202
203 switch (i)
204 {
205#ifndef WORDS_BIGENDIAN
206 /* For Big Endian machines, we store the data such that the
207 * dword/word members can be read as DWORDS and WORDS correctly. */
208 /* Dword */
209 case 1:
210 lpOut[3] = byte;
211 break;
212 case 3:
213 lpOut[2] = byte;
214 break;
215 case 5:
216 lpOut[1] = byte;
217 break;
218 case 7:
219 lpOut[0] = byte;
220 lpOut += 4;
221 break;
222 /* Word */
223 case 10:
224 case 15:
225 lpOut[1] = byte;
226 break;
227 case 12:
228 case 17:
229 lpOut[0] = byte;
230 lpOut += 2;
231 break;
232#endif
233 /* Byte */
234 default:
235 lpOut[0] = byte;
236 lpOut++;
237 break;
238 }
239
240 lpszGUID++; /* Skip 2nd character of byte */
241 i++;
242 }
243 }
244
245 lpszGUID++;
246 i++;
247 }
248 return false;
249}
#define byte(x, n)
Definition: tomcrypt.h:118
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
char CHAR
Definition: xmlstorage.h:175

Referenced by ReadGuidNode().

◆ ToNodeName()

std::string ToNodeName ( XMLHandle  node)

Definition at line 100 of file xml2sdb.cpp.

101{
102 tinyxml2::XMLNode* raw = node.ToNode();
103 const char* txt = raw ? raw->Value() : NULL;
104 if (txt)
105 return std::string(txt);
106 return std::string();
107}
const char * Value() const
Definition: tinyxml2.cpp:719

Referenced by InExclude::fromXml(), and Database::fromXml().

◆ ToString()

std::string ToString ( XMLHandle  node)

Definition at line 90 of file xml2sdb.cpp.

91{
92 XMLText* txtNode = node.FirstChild().ToText();
93 const char* txt = txtNode ? txtNode->Value() : NULL;
94 if (txt)
95 return std::string(txt);
96 return std::string();
97}

Referenced by DECLARE_INTERFACE_(), PcRegisterPhysicalConnectionToExternal(), ReadStringNode(), and RegisterConnection().

◆ WriteGeneric()

template<typename T >
bool WriteGeneric ( std::list< T > &  data,
Database db 
)

Definition at line 335 of file xml2sdb.cpp.

336{
337 for (typename std::list<T>::iterator it = data.begin(); it != data.end(); ++it)
338 {
339 if (!it->toSdb(db))
340 return false;
341 }
342 return true;
343}

Referenced by Shim::toSdb(), Layer::toSdb(), Exe::toSdb(), and Database::toSdb().

Variable Documentation

◆ GUID_NULL

const GUID GUID_NULL = { 0 }
static

Definition at line 17 of file xml2sdb.cpp.

Referenced by IsEmptyGuid().

◆ platform_to_flag

str_to_flag platform_to_flag[]
Initial value:
= {
{"X86", PLATFORM_X86},
{"I386", PLATFORM_X86},
{"AMD64", PLATFORM_AMD64},
{"ANY", PLATFORM_ANY},
{nullptr, 0},
}
@ PLATFORM_X86
Definition: xml2sdb.h:36
@ PLATFORM_AMD64
Definition: xml2sdb.h:39

Definition at line 42 of file xml2sdb.cpp.

Referenced by parse_platform(), and ReadPlatformNode().

◆ szCompilerVersion

const char szCompilerVersion[] = "1.8.0.0"
static

Definition at line 18 of file xml2sdb.cpp.

Referenced by Database::toSdb().