ReactOS 0.4.15-dev-7788-g1ad9096
apphelp.c File Reference
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "strsafe.h"
#include "apphelp.h"
#include <ndk/rtlfuncs.h>
#include <ndk/cmfuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/kdtypes.h>
Include dependency graph for apphelp.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define DPFLTR_APPCOMPAT_ID   123
 
#define MAX_GUID_STRING_LEN   sizeof("{12345678-1234-1234-0123-456789abcdef}")
 
#define NT_SUCCESS(StatCode)   ((NTSTATUS)(StatCode) >= 0)
 
#define APPHELP_DONTWRITE_REASON   2
 
#define APPHELP_CLEARBITS   0x100 /* TODO: Investigate */
 
#define APPHELP_IGNORE_ENVIRONMENT   0x400
 
#define APPHELP_VALID_RESULT   0x10000
 
#define APPHELP_RESULT_NOTFOUND   0x20000
 
#define APPHELP_RESULT_FOUND   0x40000
 

Functions

ACCESS_MASK Wow64QueryFlag (void)
 
void ApphelppInitDebugLevel (void)
 
BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)
 
BOOL WINAPI ApphelpCheckInstallShieldPackage (void *ptr, LPCWSTR path)
 
BOOL WINAPI ApphelpCheckShellObject (REFCLSID ObjectCLSID, BOOL bShimIfNecessary, ULONGLONG *pullFlags)
 
BOOL WINAPIV ShimDbgPrint (SHIM_LOG_LEVEL Level, PCSTR FunctionName, PCSTR Format,...)
 
BOOL WINAPI ApphelpCheckRunAppEx (_In_ HANDLE FileHandle, _In_opt_ PVOID Unk1, _In_opt_ PVOID Unk2, _In_opt_z_ PCWSTR ApplicationName, _In_opt_ PVOID Environment, _In_opt_ USHORT ExeType, _Inout_opt_ PULONG Reason, _Out_opt_ PVOID *SdbQueryAppCompatData, _Out_opt_ PULONG SdbQueryAppCompatDataSize, _Out_opt_ PVOID *SxsData, _Out_opt_ PULONG SxsDataSize, _Out_opt_ PULONG FusionFlags, _Out_opt_ PULONG64 SomeFlag1, _Out_opt_ PULONG SomeFlag2)
 
SdbRegisterDatabaseEx

Register an application compatibility database

Parameters
pszDatabasePathThe database. Required
dwDatabaseTypeThe database type. SDB_DATABASE_*
pTimeStampThe timestamp. When this argument is not provided, the system time is used.
Returns
TRUE on success, or FALSE on failure.
BOOL WINAPI SdbRegisterDatabaseEx (_In_ LPCWSTR pszDatabasePath, _In_ DWORD dwDatabaseType, _In_opt_ const PULONGLONG pTimeStamp)
 
SdbRegisterDatabase

Register an application compatibility database

Parameters
pszDatabasePathThe database. Required
dwDatabaseTypeThe database type. SDB_DATABASE_*
Returns
TRUE on success, or FALSE on failure.
BOOL WINAPI SdbRegisterDatabase (_In_ LPCWSTR pszDatabasePath, _In_ DWORD dwDatabaseType)
 
SdbUnregisterDatabase
Parameters
pguidDB
Returns
BOOL WINAPI SdbUnregisterDatabase (_In_ const GUID *pguidDB)
 
BOOL WINAPI BaseDumpAppcompatCache (VOID)
 
BOOL WINAPI BaseFlushAppcompatCache (VOID)
 
ShimDumpCache

Dump contents of the shim cache.

Parameters
hwndUnused, pass 0
hInstanceUnused, pass 0
lpszCmdLineUnused, pass 0
nCmdShowUnused, pass 0
Returns
BOOL WINAPI ShimDumpCache (HWND hwnd, HINSTANCE hInstance, LPCSTR lpszCmdLine, int nCmdShow)
 
ShimFlushCache

Flush the shim cache. Call this after installing a new shim database

Parameters
hwndUnused, pass 0
hInstanceUnused, pass 0
lpszCmdLineUnused, pass 0
nCmdShowUnused, pass 0
Returns
BOOL WINAPI ShimFlushCache (HWND hwnd, HINSTANCE hInstance, LPCSTR lpszCmdLine, int nCmdShow)
 

Variables

const UNICODE_STRING InstalledSDBKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\InstalledSDB")
 
ULONG g_ShimDebugLevel = ~0
 
HMODULE g_hInstance
 

Macro Definition Documentation

◆ APPHELP_CLEARBITS

#define APPHELP_CLEARBITS   0x100 /* TODO: Investigate */

Definition at line 155 of file apphelp.c.

◆ APPHELP_DONTWRITE_REASON

#define APPHELP_DONTWRITE_REASON   2

Definition at line 154 of file apphelp.c.

◆ APPHELP_IGNORE_ENVIRONMENT

#define APPHELP_IGNORE_ENVIRONMENT   0x400

Definition at line 156 of file apphelp.c.

◆ APPHELP_RESULT_FOUND

#define APPHELP_RESULT_FOUND   0x40000

Definition at line 160 of file apphelp.c.

◆ APPHELP_RESULT_NOTFOUND

#define APPHELP_RESULT_NOTFOUND   0x20000

Definition at line 159 of file apphelp.c.

◆ APPHELP_VALID_RESULT

#define APPHELP_VALID_RESULT   0x10000

Definition at line 158 of file apphelp.c.

◆ DPFLTR_APPCOMPAT_ID

#define DPFLTR_APPCOMPAT_ID   123

Definition at line 27 of file apphelp.c.

◆ MAX_GUID_STRING_LEN

#define MAX_GUID_STRING_LEN   sizeof("{12345678-1234-1234-0123-456789abcdef}")

Definition at line 29 of file apphelp.c.

◆ NT_SUCCESS

#define NT_SUCCESS (   StatCode)    ((NTSTATUS)(StatCode) >= 0)

Definition at line 32 of file apphelp.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file apphelp.c.

Function Documentation

◆ ApphelpCheckInstallShieldPackage()

BOOL WINAPI ApphelpCheckInstallShieldPackage ( void ptr,
LPCWSTR  path 
)

Definition at line 75 of file apphelp.c.

76{
77 SHIM_WARN("stub: ptr=%p, path='%S'\n", ptr, path);
78 return TRUE;
79}
#define TRUE
Definition: types.h:120
static PVOID ptr
Definition: dispmode.c:27
#define SHIM_WARN(fmt,...)
Definition: sdbpapi.h:77

◆ ApphelpCheckRunAppEx()

BOOL WINAPI ApphelpCheckRunAppEx ( _In_ HANDLE  FileHandle,
_In_opt_ PVOID  Unk1,
_In_opt_ PVOID  Unk2,
_In_opt_z_ PCWSTR  ApplicationName,
_In_opt_ PVOID  Environment,
_In_opt_ USHORT  ExeType,
_Inout_opt_ PULONG  Reason,
_Out_opt_ PVOID SdbQueryAppCompatData,
_Out_opt_ PULONG  SdbQueryAppCompatDataSize,
_Out_opt_ PVOID SxsData,
_Out_opt_ PULONG  SxsDataSize,
_Out_opt_ PULONG  FusionFlags,
_Out_opt_ PULONG64  SomeFlag1,
_Out_opt_ PULONG  SomeFlag2 
)

Lookup Shims / Fixes for the specified application

Parameters
[in]FileHandleHandle to the file to check.
[in]Unk1
[in]Unk2
[in]ApplicationNameExe to check
[in]EnvironmentThe environment variables to use, or NULL to use the current environment.
[in]ExeTypeExe type (MACHINE_TYPE_XXXX)
[in,out]ReasonInput/output flags
[in]SdbQueryAppCompatDataThe resulting data.
[in]SdbQueryAppCompatDataSizeThe resulting data size.
[in]SxsDataTODO
[in]SxsDataSizeTODO
[in]FusionFlagsTODO
[in]SomeFlag1TODO
[in]SomeFlag2TODO
Returns
TRUE if the application is allowed to run.

Definition at line 184 of file apphelp.c.

199{
201 HSDB hsdb = NULL;
202 DWORD dwFlags = 0;
203
204 if (SxsData)
205 *SxsData = NULL;
206 if (SxsDataSize)
207 *SxsDataSize = 0;
208 if (FusionFlags)
209 *FusionFlags = 0;
210 if (SomeFlag1)
211 *SomeFlag1 = 0;
212 if (SomeFlag2)
213 *SomeFlag2 = 0;
214 if (Reason)
215 dwFlags = *Reason;
216
217 dwFlags &= ~APPHELP_CLEARBITS;
218
221 *SdbQueryAppCompatDataSize = sizeof(*result);
222
223
225 if (hsdb)
226 {
227 BOOL FoundMatch;
228 DWORD MatchingExeFlags = 0;
229
231 MatchingExeFlags |= SDBGMEF_IGNORE_ENVIRONMENT;
232
233 FoundMatch = SdbGetMatchingExe(hsdb, ApplicationName, NULL, Environment, MatchingExeFlags, result);
235 {
238 }
239
240 SdbReleaseDatabase(hsdb);
241 }
242
244 *Reason = dwFlags;
245
246
247 /* We should _ALWAYS_ return TRUE here, unless we want to block an application from starting! */
248 return TRUE;
249}
#define SDB_DATABASE_MAIN_SHIM
Definition: apphelp.h:24
BOOL WINAPI SdbGetMatchingExe(HSDB hsdb, LPCWSTR path, LPCWSTR module_name, LPCWSTR env, DWORD flags, PSDBQUERYRESULT result)
Definition: hsdb.c:439
#define HID_DOS_PATHS
Definition: apphelp.h:19
void WINAPI SdbReleaseDatabase(HSDB)
Definition: hsdb.c:417
#define SDBGMEF_IGNORE_ENVIRONMENT
Definition: apphelp.h:62
HSDB WINAPI SdbInitDatabase(DWORD, LPCWSTR)
Definition: hsdb.c:369
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define NULL
Definition: types.h:112
#define APPHELP_IGNORE_ENVIRONMENT
Definition: apphelp.c:156
#define APPHELP_VALID_RESULT
Definition: apphelp.c:158
#define APPHELP_RESULT_NOTFOUND
Definition: apphelp.c:159
#define APPHELP_DONTWRITE_REASON
Definition: apphelp.c:154
#define APPHELP_RESULT_FOUND
Definition: apphelp.c:160
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
GLuint64EXT * result
Definition: glext.h:11304
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG PULONG64 PULONG SomeFlag2
Definition: env.c:49
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID * SdbQueryAppCompatData
Definition: env.c:48
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG SxsDataSize
Definition: env.c:48
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG PULONG64 SomeFlag1
Definition: env.c:49
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID * SxsData
Definition: env.c:48
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG FusionFlags
Definition: env.c:49
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG SdbQueryAppCompatDataSize
Definition: env.c:48
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:47
Definition: apphelp.h:30
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

◆ ApphelpCheckShellObject()

BOOL WINAPI ApphelpCheckShellObject ( REFCLSID  ObjectCLSID,
BOOL  bShimIfNecessary,
ULONGLONG pullFlags 
)

Definition at line 82 of file apphelp.c.

83{
85 if (!ObjectCLSID || !SdbGUIDToString(ObjectCLSID, GuidString, RTL_NUMBER_OF(GuidString)))
86 GuidString[0] = L'\0';
87 SHIM_WARN("stub: ObjectCLSID='%S', bShimIfNecessary=%d, pullFlags=%p)\n", GuidString, bShimIfNecessary, pullFlags);
88
89 if (pullFlags)
90 *pullFlags = 0;
91
92 return TRUE;
93}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
BOOL WINAPI SdbGUIDToString(CONST GUID *Guid, PWSTR GuidString, SIZE_T Length)
Definition: sdbapi.c:412
#define MAX_GUID_STRING_LEN
Definition: apphelp.c:29
static PWSTR GuidString
Definition: apphelp.c:93
#define L(x)
Definition: ntvdm.h:50
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ ApphelppInitDebugLevel()

void ApphelppInitDebugLevel ( void  )

Definition at line 38 of file apphelp.c.

39{
40 static const UNICODE_STRING DebugKey = RTL_CONSTANT_STRING(L"SHIM_DEBUG_LEVEL");
41 UNICODE_STRING DebugValue;
43 ULONG NewLevel = SHIM_ERR;
44 WCHAR Buffer[40];
45
46 RtlInitEmptyUnicodeString(&DebugValue, Buffer, sizeof(Buffer));
47
48 Status = RtlQueryEnvironmentVariable_U(NULL, &DebugKey, &DebugValue);
49
50 if (NT_SUCCESS(Status))
51 {
52 if (!NT_SUCCESS(RtlUnicodeStringToInteger(&DebugValue, 10, &NewLevel)))
53 NewLevel = SHIM_ERR;
54 }
55 g_ShimDebugLevel = NewLevel;
56}
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
ULONG g_ShimDebugLevel
Definition: apphelp.c:35
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define SHIM_ERR(fmt,...)
Definition: sdbpapi.h:76
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ShimDbgPrint().

◆ BaseDumpAppcompatCache()

BOOL WINAPI BaseDumpAppcompatCache ( VOID  )

Definition at line 418 of file appcache.c.

419{
421
423 return NT_SUCCESS(Status);
424}
@ ApphelpCacheServiceDump
Definition: pstypes.h:977
NTSTATUS NTAPI NtApphelpCacheControl(_In_ APPHELPCACHESERVICECLASS Service, _In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP ServiceData)
Definition: apphelp.c:728

Referenced by ShimDumpCache().

◆ BaseFlushAppcompatCache()

BOOL WINAPI BaseFlushAppcompatCache ( VOID  )

Definition at line 431 of file appcache.c.

432{
434
436 return NT_SUCCESS(Status);
437}
@ ApphelpCacheServiceFlush
Definition: pstypes.h:976

Referenced by ShimFlushCache().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinst,
DWORD  reason,
LPVOID  reserved 
)

Definition at line 59 of file apphelp.c.

60{
61 switch (reason)
62 {
67 break;
70 break;
71 }
72 return TRUE;
73}
HMODULE g_hInstance
Definition: apphelp.c:36
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
static HINSTANCE hinst
Definition: edit.c:551
void SdbpHeapInit(void)
Definition: sdbapi.c:34
void SdbpHeapDeinit(void)
Definition: sdbapi.c:42

◆ SdbRegisterDatabase()

BOOL WINAPI SdbRegisterDatabase ( _In_ LPCWSTR  pszDatabasePath,
_In_ DWORD  dwDatabaseType 
)

Definition at line 391 of file apphelp.c.

394{
396}
BOOL WINAPI SdbRegisterDatabaseEx(_In_ LPCWSTR pszDatabasePath, _In_ DWORD dwDatabaseType, _In_opt_ const PULONGLONG pTimeStamp)
Definition: apphelp.c:261
LPCWSTR pszDatabasePath
Definition: env.c:38
DWORD dwDatabaseType
Definition: register.cpp:75

◆ SdbRegisterDatabaseEx()

BOOL WINAPI SdbRegisterDatabaseEx ( _In_ LPCWSTR  pszDatabasePath,
_In_ DWORD  dwDatabaseType,
_In_opt_ const PULONGLONG  pTimeStamp 
)

Definition at line 261 of file apphelp.c.

265{
266 PDB pdb;
268 WCHAR GuidBuffer[MAX_GUID_STRING_LEN];
270 ACCESS_MASK KeyAccess;
273 HANDLE InstalledSDBKey;
274
276 if (!pdb)
277 {
278 SHIM_ERR("Unable to open DB %S\n", pszDatabasePath);
279 return FALSE;
280 }
281
284 {
285 SHIM_ERR("Unable to retrieve DB info\n");
287 return FALSE;
288 }
289
290 if (!SdbGUIDToString(&Information.Id, GuidBuffer, RTL_NUMBER_OF(GuidBuffer)))
291 {
292 SHIM_ERR("Unable to Convert GUID to string\n");
295 return FALSE;
296 }
297
300 Status = NtCreateKey(&InstalledSDBKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
301 if (NT_SUCCESS(Status))
302 {
303 HANDLE DbKey;
304
305 RtlInitUnicodeString(&KeyName, GuidBuffer);
306 ObjectKey.RootDirectory = InstalledSDBKey;
307
308 Status = NtCreateKey(&DbKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
309 if (NT_SUCCESS(Status))
310 {
311 UNICODE_STRING DatabasePathKey = RTL_CONSTANT_STRING(L"DatabasePath");
312 UNICODE_STRING DatabaseInstallTimeStampKey = RTL_CONSTANT_STRING(L"DatabaseInstallTimeStamp");
313 UNICODE_STRING DatabaseTypeKey = RTL_CONSTANT_STRING(L"DatabaseType");
314 UNICODE_STRING DatabaseDescriptionKey = RTL_CONSTANT_STRING(L"DatabaseDescription");
315
316 Status = NtSetValueKey(DbKey, &DatabasePathKey, 0, REG_SZ,
318 if (!NT_SUCCESS(Status))
319 SHIM_ERR("Unable to write %wZ\n", &DatabasePathKey);
320
321 if (NT_SUCCESS(Status))
322 {
323 ULARGE_INTEGER ulTimeStamp;
324 if (pTimeStamp)
325 {
326 ulTimeStamp.QuadPart = *pTimeStamp;
327 }
328 else
329 {
330 FILETIME fi;
332 ulTimeStamp.LowPart = fi.dwLowDateTime;
333 ulTimeStamp.HighPart = fi.dwHighDateTime;
334 }
335 Status = NtSetValueKey(DbKey, &DatabaseInstallTimeStampKey, 0, REG_QWORD,
336 &ulTimeStamp.QuadPart, sizeof(ulTimeStamp));
337 if (!NT_SUCCESS(Status))
338 SHIM_ERR("Unable to write %wZ\n", &DatabaseInstallTimeStampKey);
339 }
340
341 if (NT_SUCCESS(Status))
342 {
343 Status = NtSetValueKey(DbKey, &DatabaseTypeKey, 0, REG_DWORD,
345 if (!NT_SUCCESS(Status))
346 SHIM_ERR("Unable to write %wZ\n", &DatabaseTypeKey);
347 }
348
349 if (NT_SUCCESS(Status) && Information.Description)
350 {
351 Status = NtSetValueKey(DbKey, &DatabaseDescriptionKey, 0, REG_SZ,
352 (PVOID)Information.Description, ((ULONG)wcslen(Information.Description) + 1) * sizeof(WCHAR));
353 if (!NT_SUCCESS(Status))
354 SHIM_ERR("Unable to write %wZ\n", &DatabaseDescriptionKey);
355 }
356
357 NtClose(DbKey);
358
359 if (NT_SUCCESS(Status))
360 {
361 SHIM_INFO("Installed %wS as %wZ\n", pszDatabasePath, &KeyName);
362 }
363 }
364 else
365 {
366 SHIM_ERR("Unable to create key %wZ\n", &KeyName);
367 }
368
369 NtClose(InstalledSDBKey);
370 }
371 else
372 {
373 SHIM_ERR("Unable to create key %wZ\n", &KeyName);
374 }
375
378
379 return NT_SUCCESS(Status);
380}
#define DB_INFO_FLAGS_VALID_GUID
Definition: apphelp.h:79
BOOL WINAPI SdbGetDatabaseInformation(PDB pdb, PDB_INFORMATION information)
Definition: sdbapi.c:502
PDB WINAPI SdbOpenDatabase(LPCWSTR path, PATH_TYPE type)
Definition: sdbapi.c:329
VOID WINAPI SdbFreeDatabaseInformation(PDB_INFORMATION information)
Definition: sdbapi.c:527
void WINAPI SdbCloseDatabase(PDB)
Definition: sdbapi.c:373
static PDB pdb
Definition: db.cpp:172
#define DOS_PATH
Definition: db.cpp:32
#define FALSE
Definition: types.h:117
const UNICODE_STRING InstalledSDBKeyName
Definition: apphelp.c:24
ACCESS_MASK Wow64QueryFlag(void)
Definition: layer.c:179
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define REG_SZ
Definition: layer.c:22
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define KEY_WRITE
Definition: nt_native.h:1031
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
#define RTL_INIT_OBJECT_ATTRIBUTES(n, a)
DWORD const PULONGLONG pTimeStamp
Definition: register.cpp:76
#define REG_QWORD
Definition: sdbapi.c:597
#define REG_DWORD
Definition: sdbapi.c:596
#define SHIM_INFO(fmt,...)
Definition: sdbpapi.h:78
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
HANDLE RootDirectory
Definition: umtypes.h:184
$ULONG LowPart
Definition: ntbasedef.h:569
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
$ULONG HighPart
Definition: ntbasedef.h:570
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by SdbInstall(), and SdbRegisterDatabase().

◆ SdbUnregisterDatabase()

BOOL WINAPI SdbUnregisterDatabase ( _In_ const GUID pguidDB)

Definition at line 406 of file apphelp.c.

407{
408 WCHAR KeyBuffer[MAX_PATH], GuidBuffer[50];
410 ACCESS_MASK KeyAccess;
413 HANDLE DbKey;
414
415 if (!SdbGUIDToString(pguidDB, GuidBuffer, RTL_NUMBER_OF(GuidBuffer)))
416 {
417 SHIM_ERR("Unable to Convert GUID to string\n");
418 return FALSE;
419 }
420
421 RtlInitEmptyUnicodeString(&KeyName, KeyBuffer, sizeof(KeyBuffer));
424 RtlAppendUnicodeToString(&KeyName, GuidBuffer);
425
426 KeyAccess = Wow64QueryFlag() | DELETE;
427 Status = NtCreateKey(&DbKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
428 if (!NT_SUCCESS(Status))
429 {
430 SHIM_ERR("Unable to open %wZ\n", &KeyName);
431 return FALSE;
432 }
433
434 Status = NtDeleteKey(DbKey);
435 if (!NT_SUCCESS(Status))
436 SHIM_ERR("Unable to delete %wZ\n", &KeyName);
437
438 NtClose(DbKey);
439 return NT_SUCCESS(Status);
440}
#define MAX_PATH
Definition: compat.h:34
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define DELETE
Definition: nt_native.h:57
NTSTATUS NTAPI NtDeleteKey(IN HANDLE KeyHandle)
Definition: ntapi.c:408

Referenced by SdbUninstall().

◆ ShimDbgPrint()

BOOL WINAPIV ShimDbgPrint ( SHIM_LOG_LEVEL  Level,
PCSTR  FunctionName,
PCSTR  Format,
  ... 
)

Outputs diagnostic info.

Parameters
[in]LevelThe level to log this message with, choose any of [SHIM_ERR, SHIM_WARN, SHIM_INFO].
[in]FunctionNameThe function this log should be attributed to.
[in]FormatThe format string.
...Variable arguments providing additional information.
Returns
Success: TRUE Failure: FALSE.

Definition at line 106 of file apphelp.c.

107{
108 char Buffer[512];
109 va_list ArgList;
110 char* Current = Buffer;
111 const char* LevelStr;
112 size_t Length = sizeof(Buffer);
113
114 if (g_ShimDebugLevel == ~0)
116
118 return FALSE;
119
120 switch (Level)
121 {
122 case SHIM_ERR:
123 LevelStr = "Err ";
125 break;
126 case SHIM_WARN:
127 LevelStr = "Warn";
129 break;
130 case SHIM_INFO:
131 LevelStr = "Info";
133 break;
134 default:
135 LevelStr = "User";
137 break;
138 }
139 StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "[%s][%-20s] ", LevelStr, FunctionName);
140
141 va_start(ArgList, Format);
142 StringCchVPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
143 va_end(ArgList);
144
145#if defined(APPCOMPAT_USE_DBGPRINTEX) && APPCOMPAT_USE_DBGPRINTEX
147#else
148 DbgPrint("%s", Buffer);
149 return TRUE;
150#endif
151}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1279
#define DPFLTR_ERROR_LEVEL
Definition: main.cpp:32
#define DPFLTR_APPCOMPAT_ID
Definition: apphelp.c:27
void ApphelppInitDebugLevel(void)
Definition: apphelp.c:38
#define DbgPrint
Definition: hal.h:12
#define DPFLTR_WARNING_LEVEL
Definition: kdtypes.h:31
#define DPFLTR_INFO_LEVEL
Definition: kdtypes.h:33
#define DPFLTR_MASK
Definition: kdtypes.h:34
NTSYSAPI ULONG __cdecl DbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ _Printf_format_string_ PCSTR Format,...)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:34
STRSAFEAPI StringCchVPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat, va_list argList)
Definition: strsafe.h:650
STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:575
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ ShimDumpCache()

BOOL WINAPI ShimDumpCache ( HWND  hwnd,
HINSTANCE  hInstance,
LPCSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 458 of file apphelp.c.

459{
460 return BaseDumpAppcompatCache();
461}
BOOL WINAPI BaseDumpAppcompatCache(VOID)
Definition: appcache.c:418

◆ ShimFlushCache()

BOOL WINAPI ShimFlushCache ( HWND  hwnd,
HINSTANCE  hInstance,
LPCSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 473 of file apphelp.c.

474{
476}
BOOL WINAPI BaseFlushAppcompatCache(VOID)
Definition: appcache.c:431

◆ Wow64QueryFlag()

ACCESS_MASK Wow64QueryFlag ( void  )

Definition at line 179 of file layer.c.

180{
181 if (g_QueryFlag == 0xffffffff)
182 {
183 ULONG_PTR wow64_ptr = 0;
185 g_QueryFlag = (NT_SUCCESS(Status) && wow64_ptr != 0) ? KEY_WOW64_64KEY : 0;
186 }
187 return g_QueryFlag;
188}
@ ProcessWow64Information
Definition: winternl.h:396
static ACCESS_MASK g_QueryFlag
Definition: layer.c:178
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by SdbpOpenKey(), SdbRegisterDatabaseEx(), and SdbUnregisterDatabase().

Variable Documentation

◆ g_hInstance

HMODULE g_hInstance

Definition at line 36 of file apphelp.c.

Referenced by DllMain().

◆ g_ShimDebugLevel

ULONG g_ShimDebugLevel = ~0

Definition at line 35 of file apphelp.c.

Referenced by ApphelppInitDebugLevel(), and ShimDbgPrint().

◆ InstalledSDBKeyName

const UNICODE_STRING InstalledSDBKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\InstalledSDB")

Definition at line 24 of file apphelp.c.

Referenced by SdbRegisterDatabaseEx(), and SdbUnregisterDatabase().