2017-09-08 20:19:51 +00:00
|
|
|
|
/*
|
|
|
|
|
* PROJECT: ReactOS Application compatibility module
|
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
|
* PURPOSE: Shim database query functions
|
|
|
|
|
* COPYRIGHT: Copyright 2011 André Hentschel
|
|
|
|
|
* Copyright 2013 Mislav Blaževic
|
2018-04-10 20:42:03 +00:00
|
|
|
|
* Copyright 2015-2018 Mark Jansen (mark.jansen@reactos.org)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
|
#include "apphelp.h"
|
|
|
|
|
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
BOOL WINAPI SdbpReadData(PDB pdb, PVOID dest, DWORD offset, DWORD num)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
DWORD size = offset + num;
|
|
|
|
|
|
|
|
|
|
/* Either overflow or no data to read */
|
|
|
|
|
if (size <= offset)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Overflow */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (pdb->size < size)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
memcpy(dest, pdb->data + offset, num);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
static DWORD WINAPI SdbpGetTagSize(PDB pdb, TAGID tagid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
WORD type;
|
|
|
|
|
DWORD size;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
type = SdbGetTagFromTagID(pdb, tagid) & TAG_TYPE_MASK;
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (type == TAG_NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
size = SdbGetTagDataSize(pdb, tagid);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (type <= TAG_TYPE_STRINGREF)
|
|
|
|
|
return size += sizeof(TAG);
|
|
|
|
|
else size += (sizeof(TAG) + sizeof(DWORD));
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 20:42:03 +00:00
|
|
|
|
LPWSTR WINAPI SdbpGetString(PDB pdb, TAGID tagid, PDWORD size)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
TAG tag;
|
|
|
|
|
TAGID offset;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
tag = SdbGetTagFromTagID(pdb, tagid);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (tag == TAG_NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if ((tag & TAG_TYPE_MASK) == TAG_TYPE_STRINGREF)
|
|
|
|
|
{
|
|
|
|
|
/* No stringtable; all references are invalid */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (pdb->stringtable == TAGID_NULL)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* TAG_TYPE_STRINGREF contains offset of string relative to stringtable */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (!SdbpReadData(pdb, &tagid, tagid + sizeof(TAG), sizeof(TAGID)))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
offset = pdb->stringtable + tagid + sizeof(TAG) + sizeof(TAGID);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
else if ((tag & TAG_TYPE_MASK) == TAG_TYPE_STRING)
|
|
|
|
|
{
|
|
|
|
|
offset = tagid + sizeof(TAG) + sizeof(TAGID);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SHIM_ERR("Tag 0x%u at tagid %u is neither a string or reference to string\n", tag, tagid);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Optionally read string size */
|
2018-04-10 20:42:03 +00:00
|
|
|
|
if (size && !SdbpReadData(pdb, size, offset - sizeof(TAGID), sizeof(*size)))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
return (LPWSTR)(&pdb->data[offset]);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for the tag associated with specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid The TAGID of the tag.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: The tag associated with specified tagid, Failure: TAG_NULL.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAG WINAPI SdbGetTagFromTagID(PDB pdb, TAGID tagid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
TAG data;
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (!SdbpReadData(pdb, &data, tagid, sizeof(data)))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TAG_NULL;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves size of data at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid Tagid of tag whose size is queried.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: Size of data at specified tagid, Failure: 0.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
DWORD WINAPI SdbGetTagDataSize(PDB pdb, TAGID tagid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
/* sizes of data types with fixed size */
|
|
|
|
|
static const SIZE_T sizes[6] = {
|
|
|
|
|
0, /* NULL */ 1, /* BYTE */
|
|
|
|
|
2, /* WORD */ 4, /* DWORD */
|
|
|
|
|
8, /* QWORD */ 4 /* STRINGREF */
|
|
|
|
|
};
|
|
|
|
|
WORD type;
|
|
|
|
|
DWORD size;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
type = SdbGetTagFromTagID(pdb, tagid) & TAG_TYPE_MASK;
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (type == TAG_NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (type <= TAG_TYPE_STRINGREF)
|
|
|
|
|
return sizes[(type >> 12) - 1];
|
|
|
|
|
|
|
|
|
|
/* tag with dynamic size (e.g. list): must read size */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (!SdbpReadData(pdb, &size, tagid + sizeof(TAG), sizeof(size)))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for a child of specified parent tag.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] parent TAGID of parent.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: TAGID of child tag, Failure: TAGID_NULL.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID WINAPI SdbGetFirstChild(PDB pdb, TAGID parent)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
/* if we are at beginning of database */
|
|
|
|
|
if (parent == TAGID_ROOT)
|
|
|
|
|
{
|
|
|
|
|
/* header only database: no tags */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (pdb->size <= _TAGID_ROOT)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
/* return *real* root tagid */
|
|
|
|
|
else return _TAGID_ROOT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only list tag can have children */
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if ((SdbGetTagFromTagID(pdb, parent) & TAG_TYPE_MASK) != TAG_TYPE_LIST)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
|
|
|
|
|
/* first child is sizeof(TAG) + sizeof(DWORD) bytes after beginning of list */
|
|
|
|
|
return parent + sizeof(TAG) + sizeof(DWORD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for next child of specified parent tag.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] parent TAGID of parent.
|
|
|
|
|
* @param [in] prev_child TAGID of previous child.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: TAGID of next child tag, Failure: TAGID_NULL.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID WINAPI SdbGetNextChild(PDB pdb, TAGID parent, TAGID prev_child)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
TAGID next_child;
|
|
|
|
|
DWORD prev_child_size, parent_size;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
prev_child_size = SdbpGetTagSize(pdb, prev_child);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (prev_child_size == 0)
|
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
|
|
|
|
|
/* Bound check */
|
|
|
|
|
next_child = prev_child + prev_child_size;
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (next_child >= pdb->size)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
|
|
|
|
|
if (parent == TAGID_ROOT)
|
|
|
|
|
return next_child;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
parent_size = SdbpGetTagSize(pdb, parent);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (parent_size == 0)
|
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
|
|
|
|
|
/* Specified parent has no more children */
|
|
|
|
|
if (next_child >= parent + parent_size)
|
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
|
|
|
|
|
return next_child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for a tag within specified domain.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] parent TAGID of parent.
|
|
|
|
|
* @param [in] tag TAG to be located.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: TAGID of first matching tag, Failure: TAGID_NULL.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID WINAPI SdbFindFirstTag(PDB pdb, TAGID parent, TAG tag)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
TAGID iter;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
iter = SdbGetFirstChild(pdb, parent);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
while (iter != TAGID_NULL)
|
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbGetTagFromTagID(pdb, iter) == tag)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return iter;
|
2017-08-05 12:05:06 +00:00
|
|
|
|
iter = SdbGetNextChild(pdb, parent, iter);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for a next tag which matches prev_child within parent's domain.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] parent TAGID of parent.
|
|
|
|
|
* @param [in] prev_child TAGID of previous match.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: TAGID of next match, Failure: TAGID_NULL.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID WINAPI SdbFindNextTag(PDB pdb, TAGID parent, TAGID prev_child)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
TAG tag;
|
|
|
|
|
TAGID iter;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
tag = SdbGetTagFromTagID(pdb, prev_child);
|
|
|
|
|
iter = SdbGetNextChild(pdb, parent, prev_child);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
|
|
|
|
|
while (iter != TAGID_NULL)
|
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbGetTagFromTagID(pdb, iter) == tag)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return iter;
|
2017-08-05 12:05:06 +00:00
|
|
|
|
iter = SdbGetNextChild(pdb, parent, iter);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
return TAGID_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of string or stringref associated with the string.
|
|
|
|
|
* @param [out] buffer Buffer in which string will be copied.
|
|
|
|
|
* @param [in] size Number of characters to copy.
|
|
|
|
|
*
|
|
|
|
|
* @return TRUE if string was successfully copied to the buffer FALSE if string was not copied
|
|
|
|
|
* to the buffer.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
BOOL WINAPI SdbReadStringTag(PDB pdb, TAGID tagid, LPWSTR buffer, DWORD size)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
LPWSTR string;
|
|
|
|
|
DWORD string_size;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
string = SdbpGetString(pdb, tagid, &string_size);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (!string)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check if buffer is too small */
|
|
|
|
|
if (size * sizeof(WCHAR) < string_size)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
memcpy(buffer, string, string_size);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads WORD value at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of WORD value.
|
|
|
|
|
* @param [in] ret Default return value in case function fails.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: WORD value at specified tagid, or ret on failure.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
WORD WINAPI SdbReadWORDTag(PDB pdb, TAGID tagid, WORD ret)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_WORD))
|
|
|
|
|
SdbpReadData(pdb, &ret, tagid + 2, sizeof(WORD));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads DWORD value at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of DWORD value.
|
|
|
|
|
* @param [in] ret Default return value in case function fails.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: DWORD value at specified tagid, otherwise ret.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
DWORD WINAPI SdbReadDWORDTag(PDB pdb, TAGID tagid, DWORD ret)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_DWORD))
|
|
|
|
|
SdbpReadData(pdb, &ret, tagid + 2, sizeof(DWORD));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads QWORD value at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of QWORD value.
|
|
|
|
|
* @param [in] ret Default return value in case function fails.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: QWORD value at specified tagid, otherwise ret.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
QWORD WINAPI SdbReadQWORDTag(PDB pdb, TAGID tagid, QWORD ret)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_QWORD))
|
|
|
|
|
SdbpReadData(pdb, &ret, tagid + sizeof(TAG), sizeof(QWORD));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads binary data at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of binary data.
|
|
|
|
|
* @param [out] buffer Buffer in which data will be copied.
|
|
|
|
|
* @param [in] size Size of the buffer.
|
|
|
|
|
*
|
|
|
|
|
* @return TRUE if data was successfully written, or FALSE otherwise.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
BOOL WINAPI SdbReadBinaryTag(PDB pdb, TAGID tagid, PBYTE buffer, DWORD size)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
|
|
|
|
DWORD data_size = 0;
|
|
|
|
|
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_BINARY))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
SdbpReadData(pdb, &data_size, tagid + sizeof(TAG), sizeof(data_size));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if (size >= data_size)
|
2017-08-05 12:05:06 +00:00
|
|
|
|
return SdbpReadData(pdb, buffer, tagid + sizeof(TAG) + sizeof(data_size), data_size);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves binary data at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of binary data.
|
|
|
|
|
*
|
|
|
|
|
* @return Success: Pointer to binary data at specified tagid, or NULL on failure.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
PVOID WINAPI SdbGetBinaryTagData(PDB pdb, TAGID tagid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if (!SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_BINARY))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return NULL;
|
2017-08-05 12:05:06 +00:00
|
|
|
|
return &pdb->data[tagid + sizeof(TAG) + sizeof(DWORD)];
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches shim database for string associated with specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [in] tagid TAGID of string or stringref associated with the string.
|
|
|
|
|
*
|
|
|
|
|
* @return the LPWSTR associated with specified tagid, or NULL on failure.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
LPWSTR WINAPI SdbGetStringTagPtr(PDB pdb, TAGID tagid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
return SdbpGetString(pdb, tagid, NULL);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads binary data at specified tagid.
|
|
|
|
|
*
|
2017-08-05 12:05:06 +00:00
|
|
|
|
* @param [in] pdb Handle to the shim database.
|
2016-05-22 20:27:02 +00:00
|
|
|
|
* @param [out] Guid Database ID.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the ID was found FALSE otherwise.
|
|
|
|
|
*/
|
2017-08-05 12:05:06 +00:00
|
|
|
|
BOOL WINAPI SdbGetDatabaseID(PDB pdb, GUID* Guid)
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if(SdbIsNullGUID(&pdb->database_id))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID root = SdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if(root != TAGID_NULL)
|
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
TAGID id = SdbFindFirstTag(pdb, root, TAG_DATABASE_ID);
|
2016-05-22 20:27:02 +00:00
|
|
|
|
if(id != TAGID_NULL)
|
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if(!SdbReadBinaryTag(pdb, id, (PBYTE)&pdb->database_id, sizeof(pdb->database_id)))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
memset(&pdb->database_id, 0, sizeof(pdb->database_id));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Should we silence this if we are opening a system db? */
|
|
|
|
|
SHIM_ERR("Failed to get the database id\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Should we silence this if we are opening a system db? */
|
|
|
|
|
SHIM_ERR("Failed to get root tag\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-05 12:05:06 +00:00
|
|
|
|
if(!SdbIsNullGUID(&pdb->database_id))
|
2016-05-22 20:27:02 +00:00
|
|
|
|
{
|
2017-08-05 12:05:06 +00:00
|
|
|
|
memcpy(Guid, &pdb->database_id, sizeof(pdb->database_id));
|
2016-05-22 20:27:02 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|