/** * Reads binary data at specified tagid. * * @param [in] pdb Handle to the shim database. * @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. */ BOOL WINAPI SdbReadBinaryTag(PDB pdb, TAGID tagid, PBYTE buffer, DWORD size) { DWORD data_size = 0; if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_BINARY)) { SdbpReadData(pdb, &data_size, tagid + sizeof(TAG), sizeof(data_size)); if (size >= data_size) return SdbpReadData(pdb, buffer, tagid + sizeof(TAG) + sizeof(data_size), data_size); } return FALSE; }
TAG WINAPI SdbGetTagFromTagID(PDB db, TAGID tagid) { TAG data; if (!SdbpReadData(db, &data, tagid, sizeof(data))) return TAG_NULL; return data; }
LPWSTR WINAPI SdbpGetString(PDB pdb, TAGID tagid, PDWORD size) { TAG tag; TAGID offset; tag = SdbGetTagFromTagID(pdb, tagid); if (tag == TAG_NULL) return NULL; if ((tag & TAG_TYPE_MASK) == TAG_TYPE_STRINGREF) { /* No stringtable; all references are invalid */ if (pdb->stringtable == TAGID_NULL) return NULL; /* TAG_TYPE_STRINGREF contains offset of string relative to stringtable */ if (!SdbpReadData(pdb, &tagid, tagid + sizeof(TAG), sizeof(TAGID))) return NULL; offset = pdb->stringtable + tagid + sizeof(TAG) + sizeof(TAGID); } 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 */ if (size && !SdbpReadData(pdb, size, offset - sizeof(TAGID), sizeof(*size))) return FALSE; return (LPWSTR)(&pdb->data[offset]); }
/** * Retrieves size of data at specified tagid. * * @param [in] pdb Handle to the shim database. * @param [in] tagid Tagid of tag whose size is queried. * * @return Success: Size of data at specified tagid, Failure: 0. */ DWORD WINAPI SdbGetTagDataSize(PDB pdb, TAGID tagid) { /* 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; type = SdbGetTagFromTagID(pdb, tagid) & TAG_TYPE_MASK; 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 */ if (!SdbpReadData(pdb, &size, tagid + sizeof(TAG), sizeof(size))) return 0; return size; }
/** * Reads QWORD value at specified tagid. * * @param [in] pdb Handle to the shim database. * @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. */ QWORD WINAPI SdbReadQWORDTag(PDB pdb, TAGID tagid, QWORD ret) { if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_QWORD)) SdbpReadData(pdb, &ret, tagid + sizeof(TAG), sizeof(QWORD)); return ret; }
/** * Reads DWORD value at specified tagid. * * @param [in] pdb Handle to the shim database. * @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. */ DWORD WINAPI SdbReadDWORDTag(PDB pdb, TAGID tagid, DWORD ret) { if (SdbpCheckTagIDType(pdb, tagid, TAG_TYPE_DWORD)) SdbpReadData(pdb, &ret, tagid + 2, sizeof(DWORD)); return ret; }