ReactOS 0.4.15-dev-8344-g0574987
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   RTL_NUMBER_OF("{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)
 
 C_ASSERT (MAX_GUID_STRING_LEN==39)
 
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 156 of file apphelp.c.

◆ APPHELP_DONTWRITE_REASON

#define APPHELP_DONTWRITE_REASON   2

Definition at line 155 of file apphelp.c.

◆ APPHELP_IGNORE_ENVIRONMENT

#define APPHELP_IGNORE_ENVIRONMENT   0x400

Definition at line 157 of file apphelp.c.

◆ APPHELP_RESULT_FOUND

#define APPHELP_RESULT_FOUND   0x40000

Definition at line 161 of file apphelp.c.

◆ APPHELP_RESULT_NOTFOUND

#define APPHELP_RESULT_NOTFOUND   0x20000

Definition at line 160 of file apphelp.c.

◆ APPHELP_VALID_RESULT

#define APPHELP_VALID_RESULT   0x10000

Definition at line 159 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   RTL_NUMBER_OF("{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 33 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 76 of file apphelp.c.

77{
78 SHIM_WARN("stub: ptr=%p, path='%S'\n", ptr, path);
79 return TRUE;
80}
#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 185 of file apphelp.c.

200{
202 HSDB hsdb = NULL;
203 DWORD dwFlags = 0;
204
205 if (SxsData)
206 *SxsData = NULL;
207 if (SxsDataSize)
208 *SxsDataSize = 0;
209 if (FusionFlags)
210 *FusionFlags = 0;
211 if (SomeFlag1)
212 *SomeFlag1 = 0;
213 if (SomeFlag2)
214 *SomeFlag2 = 0;
215 if (Reason)
216 dwFlags = *Reason;
217
218 dwFlags &= ~APPHELP_CLEARBITS;
219
222 *SdbQueryAppCompatDataSize = sizeof(*result);
223
224
226 if (hsdb)
227 {
228 BOOL FoundMatch;
229 DWORD MatchingExeFlags = 0;
230
232 MatchingExeFlags |= SDBGMEF_IGNORE_ENVIRONMENT;
233
234 FoundMatch = SdbGetMatchingExe(hsdb, ApplicationName, NULL, Environment, MatchingExeFlags, result);
236 {
239 }
240
241 SdbReleaseDatabase(hsdb);
242 }
243
245 *Reason = dwFlags;
246
247
248 /* We should _ALWAYS_ return TRUE here, unless we want to block an application from starting! */
249 return TRUE;
250}
#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:157
#define APPHELP_VALID_RESULT
Definition: apphelp.c:159
#define APPHELP_RESULT_NOTFOUND
Definition: apphelp.c:160
#define APPHELP_DONTWRITE_REASON
Definition: apphelp.c:155
#define APPHELP_RESULT_FOUND
Definition: apphelp.c:161
#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 83 of file apphelp.c.

84{
86 if (!ObjectCLSID || !SdbGUIDToString(ObjectCLSID, GuidString, RTL_NUMBER_OF(GuidString)))
87 GuidString[0] = L'\0';
88 SHIM_WARN("stub: ObjectCLSID='%S', bShimIfNecessary=%d, pullFlags=%p)\n", GuidString, bShimIfNecessary, pullFlags);
89
90 if (pullFlags)
91 *pullFlags = 0;
92
93 return TRUE;
94}
#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 39 of file apphelp.c.

40{
41 static const UNICODE_STRING DebugKey = RTL_CONSTANT_STRING(L"SHIM_DEBUG_LEVEL");
42 UNICODE_STRING DebugValue;
44 ULONG NewLevel = SHIM_ERR;
45 WCHAR Buffer[40];
46
47 RtlInitEmptyUnicodeString(&DebugValue, Buffer, sizeof(Buffer));
48
49 Status = RtlQueryEnvironmentVariable_U(NULL, &DebugKey, &DebugValue);
50
51 if (NT_SUCCESS(Status))
52 {
53 if (!NT_SUCCESS(RtlUnicodeStringToInteger(&DebugValue, 10, &NewLevel)))
54 NewLevel = SHIM_ERR;
55 }
56 g_ShimDebugLevel = NewLevel;
57}
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
ULONG g_ShimDebugLevel
Definition: apphelp.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
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().

◆ C_ASSERT()

C_ASSERT ( MAX_GUID_STRING_LEN  = =39)

◆ DllMain()

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

Definition at line 60 of file apphelp.c.

61{
62 switch (reason)
63 {
68 break;
71 break;
72 }
73 return TRUE;
74}
HMODULE g_hInstance
Definition: apphelp.c:37
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 392 of file apphelp.c.

395{
397}
BOOL WINAPI SdbRegisterDatabaseEx(_In_ LPCWSTR pszDatabasePath, _In_ DWORD dwDatabaseType, _In_opt_ const PULONGLONG pTimeStamp)
Definition: apphelp.c:262
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 262 of file apphelp.c.

266{
267 PDB pdb;
269 WCHAR GuidBuffer[MAX_GUID_STRING_LEN];
271 ACCESS_MASK KeyAccess;
274 HANDLE InstalledSDBKey;
275
277 if (!pdb)
278 {
279 SHIM_ERR("Unable to open DB %S\n", pszDatabasePath);
280 return FALSE;
281 }
282
285 {
286 SHIM_ERR("Unable to retrieve DB info\n");
288 return FALSE;
289 }
290
291 if (!SdbGUIDToString(&Information.Id, GuidBuffer, RTL_NUMBER_OF(GuidBuffer)))
292 {
293 SHIM_ERR("Unable to Convert GUID to string\n");
296 return FALSE;
297 }
298
301 Status = NtCreateKey(&InstalledSDBKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
302 if (NT_SUCCESS(Status))
303 {
304 HANDLE DbKey;
305
306 RtlInitUnicodeString(&KeyName, GuidBuffer);
307 ObjectKey.RootDirectory = InstalledSDBKey;
308
309 Status = NtCreateKey(&DbKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
310 if (NT_SUCCESS(Status))
311 {
312 UNICODE_STRING DatabasePathKey = RTL_CONSTANT_STRING(L"DatabasePath");
313 UNICODE_STRING DatabaseInstallTimeStampKey = RTL_CONSTANT_STRING(L"DatabaseInstallTimeStamp");
314 UNICODE_STRING DatabaseTypeKey = RTL_CONSTANT_STRING(L"DatabaseType");
315 UNICODE_STRING DatabaseDescriptionKey = RTL_CONSTANT_STRING(L"DatabaseDescription");
316
317 Status = NtSetValueKey(DbKey, &DatabasePathKey, 0, REG_SZ,
319 if (!NT_SUCCESS(Status))
320 SHIM_ERR("Unable to write %wZ\n", &DatabasePathKey);
321
322 if (NT_SUCCESS(Status))
323 {
324 ULARGE_INTEGER ulTimeStamp;
325 if (pTimeStamp)
326 {
327 ulTimeStamp.QuadPart = *pTimeStamp;
328 }
329 else
330 {
331 FILETIME fi;
333 ulTimeStamp.LowPart = fi.dwLowDateTime;
334 ulTimeStamp.HighPart = fi.dwHighDateTime;
335 }
336 Status = NtSetValueKey(DbKey, &DatabaseInstallTimeStampKey, 0, REG_QWORD,
337 &ulTimeStamp.QuadPart, sizeof(ulTimeStamp));
338 if (!NT_SUCCESS(Status))
339 SHIM_ERR("Unable to write %wZ\n", &DatabaseInstallTimeStampKey);
340 }
341
342 if (NT_SUCCESS(Status))
343 {
344 Status = NtSetValueKey(DbKey, &DatabaseTypeKey, 0, REG_DWORD,
346 if (!NT_SUCCESS(Status))
347 SHIM_ERR("Unable to write %wZ\n", &DatabaseTypeKey);
348 }
349
350 if (NT_SUCCESS(Status) && Information.Description)
351 {
352 Status = NtSetValueKey(DbKey, &DatabaseDescriptionKey, 0, REG_SZ,
353 (PVOID)Information.Description, ((ULONG)wcslen(Information.Description) + 1) * sizeof(WCHAR));
354 if (!NT_SUCCESS(Status))
355 SHIM_ERR("Unable to write %wZ\n", &DatabaseDescriptionKey);
356 }
357
358 NtClose(DbKey);
359
360 if (NT_SUCCESS(Status))
361 {
362 SHIM_INFO("Installed %wS as %wZ\n", pszDatabasePath, &KeyName);
363 }
364 }
365 else
366 {
367 SHIM_ERR("Unable to create key %wZ\n", &KeyName);
368 }
369
370 NtClose(InstalledSDBKey);
371 }
372 else
373 {
374 SHIM_ERR("Unable to create key %wZ\n", &KeyName);
375 }
376
379
380 return NT_SUCCESS(Status);
381}
#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 407 of file apphelp.c.

408{
409 WCHAR KeyBuffer[MAX_PATH], GuidBuffer[MAX_GUID_STRING_LEN];
411 ACCESS_MASK KeyAccess;
414 HANDLE DbKey;
415
416 if (!SdbGUIDToString(pguidDB, GuidBuffer, RTL_NUMBER_OF(GuidBuffer)))
417 {
418 SHIM_ERR("Unable to Convert GUID to string\n");
419 return FALSE;
420 }
421
422 RtlInitEmptyUnicodeString(&KeyName, KeyBuffer, sizeof(KeyBuffer));
425 RtlAppendUnicodeToString(&KeyName, GuidBuffer);
426
427 KeyAccess = Wow64QueryFlag() | DELETE;
428 Status = NtCreateKey(&DbKey, KeyAccess, &ObjectKey, 0, NULL, 0, NULL);
429 if (!NT_SUCCESS(Status))
430 {
431 SHIM_ERR("Unable to open %wZ\n", &KeyName);
432 return FALSE;
433 }
434
435 Status = NtDeleteKey(DbKey);
436 if (!NT_SUCCESS(Status))
437 SHIM_ERR("Unable to delete %wZ\n", &KeyName);
438
439 NtClose(DbKey);
440 return NT_SUCCESS(Status);
441}
#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 107 of file apphelp.c.

108{
109 char Buffer[512];
110 va_list ArgList;
111 char* Current = Buffer;
112 const char* LevelStr;
113 size_t Length = sizeof(Buffer);
114
115 if (g_ShimDebugLevel == ~0)
117
119 return FALSE;
120
121 switch (Level)
122 {
123 case SHIM_ERR:
124 LevelStr = "Err ";
126 break;
127 case SHIM_WARN:
128 LevelStr = "Warn";
130 break;
131 case SHIM_INFO:
132 LevelStr = "Info";
134 break;
135 default:
136 LevelStr = "User";
138 break;
139 }
140 StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "[%s][%-20s] ", LevelStr, FunctionName);
141
142 va_start(ArgList, Format);
143 StringCchVPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
144 va_end(ArgList);
145
146#if defined(APPCOMPAT_USE_DBGPRINTEX) && APPCOMPAT_USE_DBGPRINTEX
148#else
149 DbgPrint("%s", Buffer);
150 return TRUE;
151#endif
152}
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:39
#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 459 of file apphelp.c.

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

◆ ShimFlushCache()

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

Definition at line 474 of file apphelp.c.

475{
477}
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 37 of file apphelp.c.

Referenced by DllMain().

◆ g_ShimDebugLevel

ULONG g_ShimDebugLevel = ~0

Definition at line 36 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().