ReactOS 0.4.16-dev-297-gc569aee
sdbread.c File Reference
#include "windef.h"
#include "apphelp.h"
Include dependency graph for sdbread.c:

Go to the source code of this file.

Functions

BOOL WINAPI SdbpReadData (PDB pdb, PVOID dest, DWORD offset, DWORD num)
 
static DWORD WINAPI SdbpGetTagSize (PDB pdb, TAGID tagid)
 
LPWSTR WINAPI SdbpGetString (PDB pdb, TAGID tagid, PDWORD size)
 
TAG WINAPI SdbGetTagFromTagID (PDB pdb, TAGID tagid)
 
DWORD WINAPI SdbGetTagDataSize (PDB pdb, TAGID tagid)
 
TAGID WINAPI SdbGetFirstChild (PDB pdb, TAGID parent)
 
TAGID WINAPI SdbGetNextChild (PDB pdb, TAGID parent, TAGID prev_child)
 
TAGID WINAPI SdbFindFirstTag (PDB pdb, TAGID parent, TAG tag)
 
TAGID WINAPI SdbFindNextTag (PDB pdb, TAGID parent, TAGID prev_child)
 
BOOL WINAPI SdbReadStringTag (PDB pdb, TAGID tagid, LPWSTR buffer, DWORD size)
 
WORD WINAPI SdbReadWORDTag (PDB pdb, TAGID tagid, WORD ret)
 
DWORD WINAPI SdbReadDWORDTag (PDB pdb, TAGID tagid, DWORD ret)
 
QWORD WINAPI SdbReadQWORDTag (PDB pdb, TAGID tagid, QWORD ret)
 
BOOL WINAPI SdbReadBinaryTag (PDB pdb, TAGID tagid, PBYTE buffer, DWORD size)
 
PVOID WINAPI SdbGetBinaryTagData (PDB pdb, TAGID tagid)
 
LPWSTR WINAPI SdbGetStringTagPtr (PDB pdb, TAGID tagid)
 
BOOL WINAPI SdbGetDatabaseID (PDB pdb, GUID *Guid)
 

Function Documentation

◆ SdbFindFirstTag()

TAGID WINAPI SdbFindFirstTag ( PDB  pdb,
TAGID  parent,
TAG  tag 
)

Searches shim database for a tag within specified domain.

Parameters
[in]pdbHandle to the shim database.
[in]parentTAGID of parent.
[in]tagTAG to be located.
Returns
Success: TAGID of first matching tag, Failure: TAGID_NULL.

Definition at line 208 of file sdbread.c.

209{
210 TAGID iter;
211
212 iter = SdbGetFirstChild(pdb, parent);
213 while (iter != TAGID_NULL)
214 {
215 if (SdbGetTagFromTagID(pdb, iter) == tag)
216 return iter;
217 iter = SdbGetNextChild(pdb, parent, iter);
218 }
219 return TAGID_NULL;
220}
DWORD TAGID
static PDB pdb
Definition: db.cpp:172
#define TAGID_NULL
Definition: db.cpp:38
r parent
Definition: btrfs.c:3010
TAG WINAPI SdbGetTagFromTagID(PDB pdb, TAGID tagid)
Definition: sdbread.c:93
TAGID WINAPI SdbGetFirstChild(PDB pdb, TAGID parent)
Definition: sdbread.c:142
TAGID WINAPI SdbGetNextChild(PDB pdb, TAGID parent, TAGID prev_child)
Definition: sdbread.c:171
Definition: ecma_167.h:138

Referenced by GetSdbGuid(), CLayerStringList::Next(), ProcessExe(), ProcessLayers(), CLayerStringList::Reset(), SdbFindFirstNamedTag(), SdbGetDatabaseID(), SdbGetLayerTagRef(), SdbGetMatchingExe(), SdbInstall(), SdbOpenDatabase(), SdbpAddExeLayers(), SdbpAddNamedLayerMatch(), SdbpMatchExe(), SdbQueryDataExTagID(), SdbUninstall(), SeiBuildGlobalInclExclList(), SeiBuildShimRefArray(), SeiGetDWORD(), SeiGetQWORD(), SeiGetStringPtr(), and SeiReadInExclude().

◆ SdbFindNextTag()

TAGID WINAPI SdbFindNextTag ( PDB  pdb,
TAGID  parent,
TAGID  prev_child 
)

Searches shim database for a next tag which matches prev_child within parent's domain.

Parameters
[in]pdbHandle to the shim database.
[in]parentTAGID of parent.
[in]prev_childTAGID of previous match.
Returns
Success: TAGID of next match, Failure: TAGID_NULL.

Definition at line 231 of file sdbread.c.

232{
233 TAG tag;
234 TAGID iter;
235
236 tag = SdbGetTagFromTagID(pdb, prev_child);
237 iter = SdbGetNextChild(pdb, parent, prev_child);
238
239 while (iter != TAGID_NULL)
240 {
241 if (SdbGetTagFromTagID(pdb, iter) == tag)
242 return iter;
243 iter = SdbGetNextChild(pdb, parent, iter);
244 }
245 return TAGID_NULL;
246}
Definition: fs_rec.h:143

Referenced by CLayerStringList::Next(), ProcessExe(), ProcessLayers(), SdbFindFirstNamedTag(), SdbGetMatchingExe(), SdbpAddExeLayers(), SdbpMatchExe(), SeiBuildShimRefArray(), SeiReadInExclude(), and CLayerStringList::Skip().

◆ SdbGetBinaryTagData()

PVOID WINAPI SdbGetBinaryTagData ( PDB  pdb,
TAGID  tagid 
)

Retrieves binary data at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of binary data.
Returns
Success: Pointer to binary data at specified tagid, or NULL on failure.

Definition at line 360 of file sdbread.c.

361{
363 return NULL;
364 return &pdb->data[tagid + sizeof(TAG) + sizeof(DWORD)];
365}
#define TAG(x)
Definition: ObTypes.c:145
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TAG_TYPE_BINARY
Definition: apphelp.c:44
BOOL WINAPI SdbpCheckTagIDType(PDB pdb, TAGID tagid, WORD type)
Definition: sdbapi.c:261

◆ SdbGetDatabaseID()

BOOL WINAPI SdbGetDatabaseID ( PDB  pdb,
GUID Guid 
)

Reads binary data at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[out]GuidDatabase ID.
Returns
true if the ID was found FALSE otherwise.

Definition at line 388 of file sdbread.c.

389{
390 if(SdbIsNullGUID(&pdb->database_id))
391 {
393 if(root != TAGID_NULL)
394 {
396 if(id != TAGID_NULL)
397 {
398 if(!SdbReadBinaryTag(pdb, id, (PBYTE)&pdb->database_id, sizeof(pdb->database_id)))
399 {
400 memset(&pdb->database_id, 0, sizeof(pdb->database_id));
401 }
402 }
403 else
404 {
405 /* Should we silence this if we are opening a system db? */
406 SHIM_ERR("Failed to get the database id\n");
407 }
408 }
409 else
410 {
411 /* Should we silence this if we are opening a system db? */
412 SHIM_ERR("Failed to get root tag\n");
413 }
414 }
415 if(!SdbIsNullGUID(&pdb->database_id))
416 {
417 memcpy(Guid, &pdb->database_id, sizeof(pdb->database_id));
418 return TRUE;
419 }
420 return FALSE;
421}
BOOL WINAPI SdbIsNullGUID(CONST GUID *Guid)
Definition: sdbapi.c:431
#define TAG_DATABASE_ID
Definition: db.cpp:122
#define TAGID_ROOT
Definition: db.cpp:39
#define TAG_DATABASE
Definition: db.cpp:85
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BYTE * PBYTE
Definition: pedump.c:66
#define SHIM_ERR(fmt,...)
Definition: sdbpapi.h:76
TAGID WINAPI SdbFindFirstTag(PDB pdb, TAGID parent, TAG tag)
Definition: sdbread.c:208
BOOL WINAPI SdbReadBinaryTag(PDB pdb, TAGID tagid, PBYTE buffer, DWORD size)
Definition: sdbread.c:338
#define memset(x, y, z)
Definition: compat.h:39
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762

Referenced by SdbOpenDatabase().

◆ SdbGetFirstChild()

TAGID WINAPI SdbGetFirstChild ( PDB  pdb,
TAGID  parent 
)

Searches shim database for a child of specified parent tag.

Parameters
[in]pdbHandle to the shim database.
[in]parentTAGID of parent.
Returns
Success: TAGID of child tag, Failure: TAGID_NULL.

Definition at line 142 of file sdbread.c.

143{
144 /* if we are at beginning of database */
145 if (parent == TAGID_ROOT)
146 {
147 /* header only database: no tags */
148 if (pdb->size <= _TAGID_ROOT)
149 return TAGID_NULL;
150 /* return *real* root tagid */
151 else return _TAGID_ROOT;
152 }
153
154 /* only list tag can have children */
156 return TAGID_NULL;
157
158 /* first child is sizeof(TAG) + sizeof(DWORD) bytes after beginning of list */
159 return parent + sizeof(TAG) + sizeof(DWORD);
160}
#define _TAGID_ROOT
Definition: db.cpp:40
#define TAG_TYPE_LIST
Definition: apphelp.c:42
#define TAG_TYPE_MASK
Definition: shimdbg.c:106

Referenced by SdbFindFirstTag(), and SdbpMatchFileAttributes().

◆ SdbGetNextChild()

TAGID WINAPI SdbGetNextChild ( PDB  pdb,
TAGID  parent,
TAGID  prev_child 
)

Searches shim database for next child of specified parent tag.

Parameters
[in]pdbHandle to the shim database.
[in]parentTAGID of parent.
[in]prev_childTAGID of previous child.
Returns
Success: TAGID of next child tag, Failure: TAGID_NULL.

Definition at line 171 of file sdbread.c.

172{
173 TAGID next_child;
174 DWORD prev_child_size, parent_size;
175
176 prev_child_size = SdbpGetTagSize(pdb, prev_child);
177 if (prev_child_size == 0)
178 return TAGID_NULL;
179
180 /* Bound check */
181 next_child = prev_child + prev_child_size;
182 if (next_child >= pdb->size)
183 return TAGID_NULL;
184
185 if (parent == TAGID_ROOT)
186 return next_child;
187
188 parent_size = SdbpGetTagSize(pdb, parent);
189 if (parent_size == 0)
190 return TAGID_NULL;
191
192 /* Specified parent has no more children */
193 if (next_child >= parent + parent_size)
194 return TAGID_NULL;
195
196 return next_child;
197}
static DWORD WINAPI SdbpGetTagSize(PDB pdb, TAGID tagid)
Definition: sdbread.c:30

Referenced by SdbFindFirstTag(), SdbFindNextTag(), and SdbpMatchFileAttributes().

◆ SdbGetStringTagPtr()

LPWSTR WINAPI SdbGetStringTagPtr ( PDB  pdb,
TAGID  tagid 
)

Searches shim database for string associated with specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of string or stringref associated with the string.
Returns
the LPWSTR associated with specified tagid, or NULL on failure.

Definition at line 375 of file sdbread.c.

376{
377 return SdbpGetString(pdb, tagid, NULL);
378}
LPWSTR WINAPI SdbpGetString(PDB pdb, TAGID tagid, PDWORD size)
Definition: sdbread.c:47

Referenced by CLayerStringList::Next(), ProcessExe(), ProcessLayers(), SdbFindFirstNamedTag(), SdbGetMatchingExe(), SdbInstall(), SdbOpenDatabase(), SdbpAddExeLayers(), SdbpMatchExe(), SdbpMatchFileAttributes(), SeiGetStringPtr(), and SeiReadInExclude().

◆ SdbGetTagDataSize()

DWORD WINAPI SdbGetTagDataSize ( PDB  pdb,
TAGID  tagid 
)

Retrieves size of data at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTagid of tag whose size is queried.
Returns
Success: Size of data at specified tagid, Failure: 0.

Definition at line 109 of file sdbread.c.

110{
111 /* sizes of data types with fixed size */
112 static const SIZE_T sizes[6] = {
113 0, /* NULL */ 1, /* BYTE */
114 2, /* WORD */ 4, /* DWORD */
115 8, /* QWORD */ 4 /* STRINGREF */
116 };
117 WORD type;
118 DWORD size;
119
121 if (type == TAG_NULL)
122 return 0;
123
125 return sizes[(type >> 12) - 1];
126
127 /* tag with dynamic size (e.g. list): must read size */
128 if (!SdbpReadData(pdb, &size, tagid + sizeof(TAG), sizeof(size)))
129 return 0;
130
131 return size;
132}
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
#define TAG_NULL
Definition: apphelp.c:45
static const struct @541 sizes[]
BOOL WINAPI SdbpReadData(PDB pdb, PVOID dest, DWORD offset, DWORD num)
Definition: sdbread.c:14
#define TAG_TYPE_STRINGREF
Definition: shimdbg.c:109
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by SdbpGetTagSize(), and SdbQueryDataExTagID().

◆ SdbGetTagFromTagID()

TAG WINAPI SdbGetTagFromTagID ( PDB  pdb,
TAGID  tagid 
)

Searches shim database for the tag associated with specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidThe TAGID of the tag.
Returns
Success: The tag associated with specified tagid, Failure: TAG_NULL.

Definition at line 93 of file sdbread.c.

94{
95 TAG data;
96 if (!SdbpReadData(pdb, &data, tagid, sizeof(data)))
97 return TAG_NULL;
98 return data;
99}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by SdbFindFirstTag(), SdbFindNextTag(), SdbGetFirstChild(), SdbGetTagDataSize(), SdbpGetString(), and SdbpGetTagSize().

◆ SdbpGetString()

LPWSTR WINAPI SdbpGetString ( PDB  pdb,
TAGID  tagid,
PDWORD  size 
)

Definition at line 47 of file sdbread.c.

48{
49 TAG tag;
51
52 tag = SdbGetTagFromTagID(pdb, tagid);
53 if (tag == TAG_NULL)
54 return NULL;
55
57 {
58 /* No stringtable; all references are invalid */
59 if (pdb->stringtable == TAGID_NULL)
60 return NULL;
61
62 /* TAG_TYPE_STRINGREF contains offset of string relative to stringtable */
63 if (!SdbpReadData(pdb, &tagid, tagid + sizeof(TAG), sizeof(TAGID)))
64 return NULL;
65
66 offset = pdb->stringtable + tagid + sizeof(TAG) + sizeof(TAGID);
67 }
68 else if ((tag & TAG_TYPE_MASK) == TAG_TYPE_STRING)
69 {
70 offset = tagid + sizeof(TAG) + sizeof(TAGID);
71 }
72 else
73 {
74 SHIM_ERR("Tag 0x%u at tagid %u is neither a string or reference to string\n", tag, tagid);
75 return NULL;
76 }
77
78 /* Optionally read string size */
79 if (size && !SdbpReadData(pdb, size, offset - sizeof(TAGID), sizeof(*size)))
80 return FALSE;
81
82 return (LPWSTR)(&pdb->data[offset]);
83}
GLintptr offset
Definition: glext.h:5920
#define TAG_TYPE_STRING
Definition: apphelp.c:43
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SdbGetStringTagPtr(), SdbQueryDataExTagID(), and SdbReadStringTag().

◆ SdbpGetTagSize()

static DWORD WINAPI SdbpGetTagSize ( PDB  pdb,
TAGID  tagid 
)
static

Definition at line 30 of file sdbread.c.

31{
32 WORD type;
33 DWORD size;
34
36 if (type == TAG_NULL)
37 return 0;
38
39 size = SdbGetTagDataSize(pdb, tagid);
41 return size += sizeof(TAG);
42 else size += (sizeof(TAG) + sizeof(DWORD));
43
44 return size;
45}
DWORD WINAPI SdbGetTagDataSize(PDB pdb, TAGID tagid)
Definition: sdbread.c:109

Referenced by SdbGetNextChild().

◆ SdbpReadData()

BOOL WINAPI SdbpReadData ( PDB  pdb,
PVOID  dest,
DWORD  offset,
DWORD  num 
)

Definition at line 14 of file sdbread.c.

15{
16 DWORD size = offset + num;
17
18 /* Either overflow or no data to read */
19 if (size <= offset)
20 return FALSE;
21
22 /* Overflow */
23 if (pdb->size < size)
24 return FALSE;
25
26 memcpy(dest, pdb->data + offset, num);
27 return TRUE;
28}
GLuint GLuint num
Definition: glext.h:9618
static char * dest
Definition: rtl.c:135

Referenced by SdbGetTagDataSize(), SdbGetTagFromTagID(), SdbpGetString(), SdbReadBinaryTag(), SdbReadDWORDTag(), SdbReadQWORDTag(), and SdbReadWORDTag().

◆ SdbReadBinaryTag()

BOOL WINAPI SdbReadBinaryTag ( PDB  pdb,
TAGID  tagid,
PBYTE  buffer,
DWORD  size 
)

Reads binary data at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of binary data.
[out]bufferBuffer in which data will be copied.
[in]sizeSize of the buffer.
Returns
TRUE if data was successfully written, or FALSE otherwise.

Definition at line 338 of file sdbread.c.

339{
340 DWORD data_size = 0;
341
343 {
344 SdbpReadData(pdb, &data_size, tagid + sizeof(TAG), sizeof(data_size));
345 if (size >= data_size)
346 return SdbpReadData(pdb, buffer, tagid + sizeof(TAG) + sizeof(data_size), data_size);
347 }
348
349 return FALSE;
350}
GLuint buffer
Definition: glext.h:5915

Referenced by GetSdbGuid(), and SdbGetDatabaseID().

◆ SdbReadDWORDTag()

DWORD WINAPI SdbReadDWORDTag ( PDB  pdb,
TAGID  tagid,
DWORD  ret 
)

Reads DWORD value at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of DWORD value.
[in]retDefault return value in case function fails.
Returns
Success: DWORD value at specified tagid, otherwise ret.

Definition at line 305 of file sdbread.c.

306{
308 SdbpReadData(pdb, &ret, tagid + 2, sizeof(DWORD));
309 return ret;
310}
#define TAG_TYPE_DWORD
Definition: shimdbg.c:107
int ret

Referenced by SdbpAddExeLayers(), SdbpMatchFileAttributes(), SdbQueryDataExTagID(), and SeiGetDWORD().

◆ SdbReadQWORDTag()

QWORD WINAPI SdbReadQWORDTag ( PDB  pdb,
TAGID  tagid,
QWORD  ret 
)

Reads QWORD value at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of QWORD value.
[in]retDefault return value in case function fails.
Returns
Success: QWORD value at specified tagid, otherwise ret.

Definition at line 321 of file sdbread.c.

322{
324 SdbpReadData(pdb, &ret, tagid + sizeof(TAG), sizeof(QWORD));
325 return ret;
326}
#define TAG_TYPE_QWORD
Definition: shimdbg.c:108
UINT64 QWORD
Definition: shimdbg.c:104

Referenced by SdbpMatchFileAttributes(), and SeiGetQWORD().

◆ SdbReadStringTag()

BOOL WINAPI SdbReadStringTag ( PDB  pdb,
TAGID  tagid,
LPWSTR  buffer,
DWORD  size 
)

Searches shim database for string associated with specified tagid and copies string into a buffer.

If size parameter is less than number of characters in string, this function shall fail and no data shall be copied.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of string or stringref associated with the string.
[out]bufferBuffer in which string will be copied.
[in]sizeNumber of characters to copy.
Returns
TRUE if string was successfully copied to the buffer FALSE if string was not copied to the buffer.

Definition at line 263 of file sdbread.c.

264{
266 DWORD string_size;
267
268 string = SdbpGetString(pdb, tagid, &string_size);
269 if (!string)
270 return FALSE;
271
272 /* Check if buffer is too small */
273 if (size * sizeof(WCHAR) < string_size)
274 return FALSE;
275
276 memcpy(buffer, string, string_size);
277 return TRUE;
278}
char string[160]
Definition: util.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ SdbReadWORDTag()

WORD WINAPI SdbReadWORDTag ( PDB  pdb,
TAGID  tagid,
WORD  ret 
)

Reads WORD value at specified tagid.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of WORD value.
[in]retDefault return value in case function fails.
Returns
Success: WORD value at specified tagid, or ret on failure.

Definition at line 289 of file sdbread.c.

290{
292 SdbpReadData(pdb, &ret, tagid + 2, sizeof(WORD));
293 return ret;
294}
#define TAG_TYPE_WORD
Definition: apphelp.c:38