// // Using simplified database matching api // // Sample Pseudo-Code :-) // // /* ANNOTATED XML: ============= Created this nifty sample database to demonstrate functionality of sdbapint.dll This is my string Using SdbQueryDriverInformation : Note the change DWORD SdbQueryDriverInformation( IN HSDB hSDB, // Database handle IN TAGREF trExe, // matching entry IN LPCWSTR lpszPolicyName, // Policy name which is to be retrieved OUT LPDWORD lpdwDataType, // Optional, receives information on the target data type OUT LPVOID lpBuffer, // buffer to fill with data IN OUT LPDWORD lpdwBufferSize // buffer size ); Notes: 1. If lpszPolicyName == NULL then the function will attempt to copy all the available policy names into buffer pointed to by lpBuffer. If lpBuffer is NULL, lpdwBufferSize will receive the required size. Possible return values: ERROR_INSUFFICIENT_BUFFER - when lpBuffer == NULL or the size of the buffer is insufficient to hold the list of policy names ERROR_INVALID_PARAMETER - one of the parameters was invalid ERROR_INTERNAL_DB_CORRUPTION - the database is unusable ERROR_SUCCESS 2. If lpszPolicyName != NULL then the function will attempt to find the data for this policy. If lpBuffer is specified, lpdwBufferSize should point to the buffer size. lpdwBUfferSize could be NULL -- an attempt to copy data into lpBuffer will be made (under try/except). Possible return values: ERROR_NOT_FOUND - policy could not be found ERROR_INTERNAL_DB_CORRUPTION - the database is unusable ERROR_INSUFFICIENT_BUFFER - lpdwBufferSize will be updated with the correct size of the buffer ERROR_INVALID_DATA - lpBuffer parameter is invalid ERROR_SUCCESS */ #include "shimdb.h" // .... // // it is assumed that the database has been mapped into memory // pDatabase is the pointer to the beginning of the database image // dwDatabaseSize is the size of the database image // // Also assumed: // lpszDriverPath - fully qualified name of the driver file that we're checking // { HSDB hSDB; TAGREF trDriver; SDBDRIVERINFORMATION DriverInfo; BOOL bSuccess; DWORD Status; DWORD dwDataSize; DWORD dwDataType; LPVOID pBuffer; DWORD dwData; // // hSDB = SdbInitDatabaseInMemory(pDatabase, dwDatabaseSize); if (NULL == hSDB) { // // something is terribly wrong -- database has failed to initialize // } // // Match exe // trDriver = SdbGetDatabaseMatch(hSDB, lpszDriverPath); if (TAGREF_NULL == trDriver) { // // there is no match in the database for this file // } else { // // we have a match, trExe is the "token" that references the match // now we shall read the relevant info bSuccess = SdbReadDriverInformation(hSDB, trDriver, &DriverInfo); if (!bSuccess) { // // for one reason or the other, this entry is corrupted // } // // DriverInfo contains the following: // // GUID guidID; // guid ID for this entry - ID attribute in XML // DWORD dwFlags; // registry flags for this exe - see below // // Each EXE can have flags in AppCompatibility section of the registry associated with it, // we should check whether this entry is disabled via a registry flag // if (DriverInfo.dwFlags & SHIMREG_DISABLE_DRIVER) { // // don't apply this entry, it has been de-activated through the registry // } // // Query for information - step 1 -- obtain all the available policies for this driver // Status = SdbQueryDriverInformation(hSDB, trDriver, NULL, // policy name &dwDataType, // pointer to the data type NULL, // pointer to the buffer &dwDataSize); // expected return value: // ERROR_INSUFFICIENT_BUFFER // dwDataSize will contain the required buffer size in bytes // // assuming that we allocated dwDataSize bytes, pBuffer is the buffer pointer // Status = SdbQueryDriverInformation(hSDB, trDriver, NULL, &dwDataType, pBuffer, &dwDataSize); // // expected return value: // ERROR_SUCCESS // dwDataSize will contain the number of bytes written into the buffer // dwDataType will contain REG_MULTI_SZ // pBuffer will receive the following data (unicode strings, assuming xml above was used) // Policy1\0Policy2\0Policy3.... \0\0 // Status = SdbQueryDriverInformation(hSDB, trDriver, L"Policy1", &dwDataType, NULL, &dwDataSize); // // Expected return value: // ERROR_INSUFFICIENT_BUFFER // dwDataSize will contain 4 // dwDataType will contain REG_DWORD // dwDataSize = sizeof(dwData); Status = SdbQueryDriverInformation(hSDB, trDriver, L"Policy1", &dwDataType, &dwData, &dwDataSize); // expected return value: // ERROR_SUCCESS // dwData will have a value of 0x12345 // } // // After all the work is done - release the database // // SdbReleaseDatabase(hSDB); }