ReactOS  0.4.11-dev-791-gf6f1255
apphelp.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for apphelp.c:

Go to the source code of this file.

Classes

struct  SHIM_PERSISTENT_CACHE_HEADER_52
 
struct  SHIM_PERSISTENT_CACHE_ENTRY_52
 
struct  SHIM_CACHE_ENTRY
 

Macros

#define NDEBUG
 
#define EMPTY_SHIM_ENTRY   { { 0 }, { { 0 } }, 0 }
 
#define MAX_SHIM_ENTRIES   0x200
 
#define TAG_SHIM   'MIHS'
 
#define INVALID_HANDLE_VALUE   (HANDLE)(-1)
 
#define CACHE_MAGIC_NT_52   0xbadc0ffe
 
#define CACHE_HEADER_SIZE_NT_52   0x8
 
#define NT52_PERSISTENT_ENTRY_SIZE32   0x18
 
#define NT52_PERSISTENT_ENTRY_SIZE64   0x20
 
#define SHIM_CACHE_MAGIC   CACHE_MAGIC_NT_52
 
#define SHIM_CACHE_HEADER_SIZE   CACHE_HEADER_SIZE_NT_52
 
#define SHIM_PERSISTENT_CACHE_ENTRY_SIZE   NT52_PERSISTENT_ENTRY_SIZE32
 
#define SHIM_PERSISTENT_CACHE_HEADER   SHIM_PERSISTENT_CACHE_HEADER_52
 
#define PSHIM_PERSISTENT_CACHE_HEADER   PSHIM_PERSISTENT_CACHE_HEADER_52
 
#define SHIM_PERSISTENT_CACHE_ENTRY   SHIM_PERSISTENT_CACHE_ENTRY_52
 
#define PSHIM_PERSISTENT_CACHE_ENTRY   PSHIM_PERSISTENT_CACHE_ENTRY_52
 

Typedefs

typedef struct
SHIM_PERSISTENT_CACHE_HEADER_52 
SHIM_PERSISTENT_CACHE_HEADER_52
 
typedef struct
SHIM_PERSISTENT_CACHE_HEADER_52
PSHIM_PERSISTENT_CACHE_HEADER_52
 
typedef struct
SHIM_PERSISTENT_CACHE_ENTRY_52 
SHIM_PERSISTENT_CACHE_ENTRY_52
 
typedef struct
SHIM_PERSISTENT_CACHE_ENTRY_52
PSHIM_PERSISTENT_CACHE_ENTRY_52
 
typedef struct SHIM_CACHE_ENTRY SHIM_CACHE_ENTRY
 
typedef struct SHIM_CACHE_ENTRYPSHIM_CACHE_ENTRY
 

Functions

 C_ASSERT (sizeof(SHIM_PERSISTENT_CACHE_ENTRY)==SHIM_PERSISTENT_CACHE_ENTRY_SIZE)
 
 C_ASSERT (sizeof(SHIM_PERSISTENT_CACHE_HEADER)==SHIM_CACHE_HEADER_SIZE)
 
PVOID ApphelpAlloc (_In_ ULONG ByteSize)
 
VOID ApphelpFree (_In_ PVOID Data)
 
VOID ApphelpCacheAcquireLock (VOID)
 
BOOLEAN ApphelpCacheTryAcquireLock (VOID)
 
VOID ApphelpCacheReleaseLock (VOID)
 
VOID ApphelpDuplicateUnicodeString (_Out_ PUNICODE_STRING Destination, _In_ PCUNICODE_STRING Source)
 
VOID ApphelpFreeUnicodeString (_Inout_ PUNICODE_STRING String)
 
NTSTATUS ApphelpCacheQueryInfo (_In_ HANDLE ImageHandle, _Out_ PSHIM_CACHE_ENTRY Entry)
 
RTL_GENERIC_COMPARE_RESULTS NTAPI ApphelpShimCacheCompareRoutine (_In_ struct _RTL_AVL_TABLE *Table, _In_ PVOID FirstStruct, _In_ PVOID SecondStruct)
 
PVOID NTAPI ApphelpShimCacheAllocateRoutine (_In_ struct _RTL_AVL_TABLE *Table, _In_ CLONG ByteSize)
 
VOID NTAPI ApphelpShimCacheFreeRoutine (_In_ struct _RTL_AVL_TABLE *Table, _In_ PVOID Buffer)
 
NTSTATUS ApphelpCacheParse (_In_reads_(DataLength) PUCHAR Data, _In_ ULONG DataLength)
 
BOOLEAN ApphelpCacheRead (VOID)
 
BOOLEAN ApphelpCacheWrite (VOID)
 
NTSTATUS NTAPI INIT_FUNCTION ApphelpCacheInitialize (VOID)
 
VOID NTAPI ApphelpCacheShutdown (VOID)
 
NTSTATUS ApphelpValidateData (_In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP ServiceData, _Out_ PUNICODE_STRING ImageName, _Out_ PHANDLE ImageHandle)
 
NTSTATUS ApphelpCacheRemoveEntryNolock (_In_ PSHIM_CACHE_ENTRY Entry)
 
NTSTATUS ApphelpCacheLookupEntry (_In_ PUNICODE_STRING ImageName, _In_ HANDLE ImageHandle)
 
NTSTATUS ApphelpCacheRemoveEntry (_In_ PUNICODE_STRING ImageName)
 
NTSTATUS ApphelpCacheAccessCheck (VOID)
 
NTSTATUS ApphelpCacheUpdateEntry (_In_ PUNICODE_STRING ImageName, _In_ HANDLE ImageHandle)
 
NTSTATUS ApphelpCacheFlush (VOID)
 
NTSTATUS ApphelpCacheDump (VOID)
 
NTSTATUS NTAPI NtApphelpCacheControl (_In_ APPHELPCACHESERVICECLASS Service, _In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP ServiceData)
 

Variables

static BOOLEAN ApphelpCacheEnabled = FALSE
 
static ERESOURCE ApphelpCacheLock
 
static RTL_AVL_TABLE ApphelpShimCache
 
static LIST_ENTRY ApphelpShimCacheAge
 
ULONG InitSafeBootMode
 
static UNICODE_STRING AppCompatCacheKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCompatCache")
 
static OBJECT_ATTRIBUTES AppCompatKeyAttributes = RTL_CONSTANT_OBJECT_ATTRIBUTES(&AppCompatCacheKey, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE)
 
static UNICODE_STRING AppCompatCacheValue = RTL_CONSTANT_STRING(L"AppCompatCache")
 

Macro Definition Documentation

#define CACHE_HEADER_SIZE_NT_52   0x8

Definition at line 67 of file apphelp.c.

Referenced by ApphelpCacheParse().

#define CACHE_MAGIC_NT_52   0xbadc0ffe

Definition at line 66 of file apphelp.c.

#define EMPTY_SHIM_ENTRY   { { 0 }, { { 0 } }, 0 }

Definition at line 40 of file apphelp.c.

Referenced by ApphelpCacheLookupEntry(), ApphelpCacheParse(), and ApphelpCacheUpdateEntry().

#define INVALID_HANDLE_VALUE   (HANDLE)(-1)
#define MAX_SHIM_ENTRIES   0x200

Definition at line 41 of file apphelp.c.

Referenced by ApphelpCacheUpdateEntry().

#define NDEBUG

Definition at line 24 of file apphelp.c.

#define NT52_PERSISTENT_ENTRY_SIZE32   0x18

Definition at line 68 of file apphelp.c.

#define NT52_PERSISTENT_ENTRY_SIZE64   0x20

Definition at line 69 of file apphelp.c.

#define PSHIM_PERSISTENT_CACHE_ENTRY   PSHIM_PERSISTENT_CACHE_ENTRY_52

Definition at line 86 of file apphelp.c.

Referenced by ApphelpCacheParse(), and ApphelpCacheWrite().

#define PSHIM_PERSISTENT_CACHE_HEADER   PSHIM_PERSISTENT_CACHE_HEADER_52

Definition at line 84 of file apphelp.c.

Referenced by ApphelpCacheParse(), and ApphelpCacheWrite().

#define SHIM_CACHE_HEADER_SIZE   CACHE_HEADER_SIZE_NT_52

Definition at line 77 of file apphelp.c.

Referenced by ApphelpCacheParse(), and ApphelpCacheWrite().

#define SHIM_CACHE_MAGIC   CACHE_MAGIC_NT_52

Definition at line 76 of file apphelp.c.

Referenced by ApphelpCacheParse(), and ApphelpCacheWrite().

#define SHIM_PERSISTENT_CACHE_ENTRY   SHIM_PERSISTENT_CACHE_ENTRY_52

Definition at line 85 of file apphelp.c.

#define SHIM_PERSISTENT_CACHE_ENTRY_SIZE   NT52_PERSISTENT_ENTRY_SIZE32

Definition at line 81 of file apphelp.c.

Referenced by ApphelpCacheParse(), and ApphelpCacheWrite().

#define SHIM_PERSISTENT_CACHE_HEADER   SHIM_PERSISTENT_CACHE_HEADER_52

Definition at line 83 of file apphelp.c.

#define TAG_SHIM   'MIHS'

Definition at line 42 of file apphelp.c.

Referenced by ApphelpAlloc(), and ApphelpFree().

Typedef Documentation

Function Documentation

PVOID ApphelpAlloc ( _In_ ULONG  ByteSize)

Definition at line 102 of file apphelp.c.

Referenced by ApphelpCacheRead(), ApphelpCacheWrite(), ApphelpDuplicateUnicodeString(), and ApphelpShimCacheAllocateRoutine().

104 {
106 }
#define TAG_SHIM
Definition: apphelp.c:42
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:389
NTSTATUS ApphelpCacheAccessCheck ( VOID  )

Definition at line 603 of file apphelp.c.

Referenced by NtApphelpCacheControl().

604 {
605  if (ExGetPreviousMode() != KernelMode)
606  {
608  {
609  DPRINT1("SHIMS: ApphelpCacheAccessCheck failed\n");
610  return STATUS_ACCESS_DENIED;
611  }
612  }
613  return STATUS_SUCCESS;
614 }
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
const LUID SeTcbPrivilege
Definition: priv.c:28
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2710
VOID ApphelpCacheAcquireLock ( VOID  )

Definition at line 116 of file apphelp.c.

Referenced by ApphelpCacheDump(), ApphelpCacheFlush(), ApphelpCacheRemoveEntry(), ApphelpCacheUpdateEntry(), and ApphelpCacheWrite().

117 {
120 }
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
static ERESOURCE ApphelpCacheLock
Definition: apphelp.c:30
NTSTATUS ApphelpCacheDump ( VOID  )

Definition at line 704 of file apphelp.c.

Referenced by NtApphelpCacheControl().

705 {
706  PLIST_ENTRY ListEntry;
708 
709  DPRINT1("SHIMS: NtApphelpCacheControl( Dumping entries, newest to oldest )\n");
711  ListEntry = ApphelpShimCacheAge.Flink;
712  while (ListEntry != &ApphelpShimCacheAge)
713  {
714  Entry = CONTAINING_RECORD(ListEntry, SHIM_CACHE_ENTRY, List);
715  DPRINT1("Entry: %wZ\n", &Entry->Persistent.ImageName);
716  DPRINT1("DateTime: 0x%I64x\n", Entry->Persistent.DateTime.QuadPart);
717  DPRINT1("FileSize: 0x%I64x\n", Entry->Persistent.FileSize.QuadPart);
718  DPRINT1("Flags: 0x%x\n", Entry->CompatFlags);
719  ListEntry = ListEntry->Flink;
720  }
722  return STATUS_SUCCESS;
723 }
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
struct _Entry Entry
Definition: kefuncs.h:640
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
ULONG CompatFlags
Definition: apphelp.c:96
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
Definition: apphelp.c:92
Definition: typedefs.h:117
VOID ApphelpCacheAcquireLock(VOID)
Definition: apphelp.c:116
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS ApphelpCacheFlush ( VOID  )

Definition at line 689 of file apphelp.c.

Referenced by NtApphelpCacheControl().

690 {
691  PVOID p;
692 
693  DPRINT1("SHIMS: ApphelpCacheFlush\n");
696  {
698  }
700  return STATUS_SUCCESS;
701 }
DWORD *typedef PVOID
Definition: winlogon.h:61
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
#define TRUE
Definition: types.h:120
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_ BOOLEAN Restart)
Definition: apphelp.c:92
VOID ApphelpCacheAcquireLock(VOID)
Definition: apphelp.c:116
#define DPRINT1
Definition: precomp.h:8
NTSTATUS ApphelpCacheRemoveEntryNolock(_In_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:515
GLfloat GLfloat p
Definition: glext.h:8902
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS NTAPI INIT_FUNCTION ApphelpCacheInitialize ( VOID  )

Definition at line 440 of file apphelp.c.

Referenced by IoInitSystem().

441 {
442  DPRINT("SHIMS: ApphelpCacheInitialize\n");
443  /* If we are booting in safemode we do not want to use the apphelp cache */
444  if (InitSafeBootMode)
445  {
446  DPRINT1("SHIMS: Safe mode detected, disabling cache.\n");
448  }
449  else
450  {
456  NULL);
459  }
460  DPRINT("SHIMS: ApphelpCacheInitialize: %d\n", ApphelpCacheEnabled);
461  return STATUS_SUCCESS;
462 }
PVOID NTAPI ApphelpShimCacheAllocateRoutine(_In_ struct _RTL_AVL_TABLE *Table, _In_ CLONG ByteSize)
Definition: apphelp.c:235
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
BOOLEAN ApphelpCacheRead(VOID)
Definition: apphelp.c:307
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ULONG InitSafeBootMode
Definition: init.c:68
static BOOLEAN ApphelpCacheEnabled
Definition: apphelp.c:29
VOID NTAPI ApphelpShimCacheFreeRoutine(_In_ struct _RTL_AVL_TABLE *Table, _In_ PVOID Buffer)
Definition: apphelp.c:244
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
VOID NTAPI RtlInitializeGenericTableAvl(IN OUT PRTL_AVL_TABLE Table, IN PRTL_AVL_COMPARE_ROUTINE CompareRoutine, IN PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_AVL_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: avltable.c:26
RTL_GENERIC_COMPARE_RESULTS NTAPI ApphelpShimCacheCompareRoutine(_In_ struct _RTL_AVL_TABLE *Table, _In_ PVOID FirstStruct, _In_ PVOID SecondStruct)
Definition: apphelp.c:210
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DPRINT1
Definition: precomp.h:8
static ERESOURCE ApphelpCacheLock
Definition: apphelp.c:30
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS ApphelpCacheLookupEntry ( _In_ PUNICODE_STRING  ImageName,
_In_ HANDLE  ImageHandle 
)

Definition at line 532 of file apphelp.c.

Referenced by NtApphelpCacheControl().

535 {
539 
541  {
542  return Status;
543  }
544 
545  Lookup.Persistent.ImageName = *ImageName;
547  if (Entry == NULL)
548  {
549  DPRINT("SHIMS: ApphelpCacheLookupEntry: could not find %wZ\n", ImageName);
550  goto Cleanup;
551  }
552 
553  DPRINT("SHIMS: ApphelpCacheLookupEntry: found %wZ\n", ImageName);
555  {
556  DPRINT("SHIMS: ApphelpCacheLookupEntry: ok\n");
557  /* just return if we know it, do not query file info */
558  Status = STATUS_SUCCESS;
559  }
560  else
561  {
562  Status = ApphelpCacheQueryInfo(ImageHandle, &Lookup);
563  if (NT_SUCCESS(Status) &&
564  Lookup.Persistent.DateTime.QuadPart == Entry->Persistent.DateTime.QuadPart &&
565  Lookup.Persistent.FileSize.QuadPart == Entry->Persistent.FileSize.QuadPart)
566  {
567  DPRINT("SHIMS: ApphelpCacheLookupEntry: found & validated\n");
568  Status = STATUS_SUCCESS;
569  /* move it to the front to keep it alive */
570  RemoveEntryList(&Entry->List);
572  }
573  else
574  {
575  DPRINT1("SHIMS: ApphelpCacheLookupEntry: file info mismatch (%lx)\n", Status);
576  Status = STATUS_NOT_FOUND;
577  /* Could not read file info, or it did not match, drop it from the cache */
579  }
580  }
581 
582 Cleanup:
584  return Status;
585 }
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
struct _Entry Entry
Definition: kefuncs.h:640
#define INVALID_HANDLE_VALUE
Definition: apphelp.c:45
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
#define EMPTY_SHIM_ENTRY
Definition: apphelp.c:40
NTSTATUS ApphelpCacheQueryInfo(_In_ HANDLE ImageHandle, _Out_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:176
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
static void Lookup(RTF_Info *, char *)
Definition: reader.c:2229
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_NOT_FOUND
Definition: shellext.h:55
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
Definition: apphelp.c:92
static const char * ImageName
Definition: image.c:34
static const WCHAR Cleanup[]
Definition: register.c:80
ACPI_EFI_HANDLE ACPI_EFI_DEVICE_PATH VOID UINTN ACPI_EFI_HANDLE * ImageHandle
Definition: acefiex.h:463
LIST_ENTRY List
Definition: apphelp.c:94
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTSTATUS ApphelpCacheRemoveEntryNolock(_In_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:515
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_ PVOID Buffer)
BOOLEAN ApphelpCacheTryAcquireLock(VOID)
Definition: apphelp.c:123
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS ApphelpCacheParse ( _In_reads_(DataLength) PUCHAR  Data,
_In_ ULONG  DataLength 
)

Definition at line 252 of file apphelp.c.

Referenced by ApphelpCacheRead().

255 {
257  ULONG Cur;
258  ULONG NumEntries;
262  PSHIM_PERSISTENT_CACHE_ENTRY Persistent;
263 
265  {
266  DPRINT1("SHIMS: ApphelpCacheParse not enough data for a minimal header (0x%x)\n", DataLength);
268  }
269 
270  if (Header->Magic != SHIM_CACHE_MAGIC)
271  {
272  DPRINT1("SHIMS: ApphelpCacheParse found invalid magic (0x%x)\n", Header->Magic);
274  }
275 
276  NumEntries = Header->NumEntries;
277  DPRINT("SHIMS: ApphelpCacheParse walking %d entries\n", NumEntries);
278  for (Cur = 0; Cur < NumEntries; ++Cur)
279  {
282  /* The entry in the Persistent storage is not really a UNICODE_STRING,
283  so we have to convert the offset into a real pointer before using it. */
284  String.Length = Persistent->ImageName.Length;
285  String.MaximumLength = Persistent->ImageName.MaximumLength;
286  String.Buffer = (PWCHAR)((ULONG_PTR)Persistent->ImageName.Buffer + Data);
287 
288  /* Now we copy all data to a local buffer, that can be safely duplicated by RtlInsert */
289  Entry.Persistent = *Persistent;
290  ApphelpDuplicateUnicodeString(&Entry.Persistent.ImageName, &String);
292  &Entry,
293  sizeof(Entry),
294  NULL);
295  if (!Result)
296  {
297  DPRINT1("SHIMS: ApphelpCacheParse insert failed\n");
298  ApphelpFreeUnicodeString(&Entry.Persistent.ImageName);
300  }
302  }
303  return STATUS_SUCCESS;
304 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
#define EMPTY_SHIM_ENTRY
Definition: apphelp.c:40
PVOID ULONG ULONG PULONG Data
Definition: oprghdlr.h:14
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
uint16_t * PWCHAR
Definition: typedefs.h:54
#define InsertTailList(ListHead, Entry)
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID ApphelpFreeUnicodeString(_Inout_ PUNICODE_STRING String)
Definition: apphelp.c:162
CHAR16 * String
Definition: acefiex.h:201
#define SHIM_CACHE_HEADER_SIZE
Definition: apphelp.c:77
Definition: Header.h:8
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement)
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
smooth NULL
Definition: ftsmooth.c:416
#define PSHIM_PERSISTENT_CACHE_HEADER
Definition: apphelp.c:84
void DPRINT(...)
Definition: polytest.cpp:61
#define SHIM_PERSISTENT_CACHE_ENTRY_SIZE
Definition: apphelp.c:81
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
Definition: apphelp.c:92
#define PSHIM_PERSISTENT_CACHE_ENTRY
Definition: apphelp.c:86
LIST_ENTRY List
Definition: apphelp.c:94
VOID ApphelpDuplicateUnicodeString(_Out_ PUNICODE_STRING Destination, _In_ PCUNICODE_STRING Source)
Definition: apphelp.c:142
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define SHIM_CACHE_MAGIC
Definition: apphelp.c:76
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define CACHE_HEADER_SIZE_NT_52
Definition: apphelp.c:67
base of all file and directory entries
Definition: entries.h:82
NTSTATUS ApphelpCacheQueryInfo ( _In_ HANDLE  ImageHandle,
_Out_ PSHIM_CACHE_ENTRY  Entry 
)

Definition at line 176 of file apphelp.c.

Referenced by ApphelpCacheLookupEntry(), and ApphelpCacheUpdateEntry().

179 {
181  FILE_BASIC_INFORMATION FileBasic;
182  FILE_STANDARD_INFORMATION FileStandard;
184 
185  Status = ZwQueryInformationFile(ImageHandle,
186  &IoStatusBlock,
187  &FileBasic,
188  sizeof(FileBasic),
190  if (!NT_SUCCESS(Status))
191  {
192  return Status;
193  }
194 
195  Status = ZwQueryInformationFile(ImageHandle,
196  &IoStatusBlock,
197  &FileStandard,
198  sizeof(FileStandard),
200  if (NT_SUCCESS(Status))
201  {
202  Entry->Persistent.DateTime = FileBasic.LastWriteTime;
203  Entry->Persistent.FileSize = FileStandard.EndOfFile;
204  }
205  return Status;
206 }
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ACPI_EFI_HANDLE ACPI_EFI_DEVICE_PATH VOID UINTN ACPI_EFI_HANDLE * ImageHandle
Definition: acefiex.h:463
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
base of all file and directory entries
Definition: entries.h:82
BOOLEAN ApphelpCacheRead ( VOID  )

Definition at line 307 of file apphelp.c.

Referenced by ApphelpCacheInitialize(), and NtApphelpCacheControl().

308 {
311  KEY_VALUE_PARTIAL_INFORMATION KeyValueObject;
312  PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation = &KeyValueObject;
313  ULONG KeyInfoSize, ResultSize;
314 
315  Status = ZwOpenKey(&KeyHandle, KEY_QUERY_VALUE, &AppCompatKeyAttributes);
316  if (!NT_SUCCESS(Status))
317  {
318  DPRINT1("SHIMS: ApphelpCacheRead could not even open Session Manager\\AppCompatCache (0x%x)\n", Status);
319  return FALSE;
320  }
321 
322  Status = ZwQueryValueKey(KeyHandle,
325  KeyValueInformation,
326  sizeof(KeyValueObject),
327  &ResultSize);
328  if (Status == STATUS_BUFFER_OVERFLOW)
329  {
330  KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + KeyValueInformation->DataLength;
331  KeyValueInformation = ApphelpAlloc(KeyInfoSize);
332  if (KeyValueInformation != NULL)
333  {
334  Status = ZwQueryValueKey(KeyHandle,
337  KeyValueInformation,
338  KeyInfoSize,
339  &ResultSize);
340  }
341  }
342 
343  if (NT_SUCCESS(Status) && KeyValueInformation->Type == REG_BINARY)
344  {
345  Status = ApphelpCacheParse(KeyValueInformation->Data,
346  KeyValueInformation->DataLength);
347  }
348  else
349  {
350  DPRINT1("SHIMS: ApphelpCacheRead not loaded from registry (0x%x)\n", Status);
351  }
352 
353  if (KeyValueInformation != &KeyValueObject && KeyValueInformation != NULL)
354  {
355  ApphelpFree(KeyValueInformation);
356  }
357 
358  ZwClose(KeyHandle);
359  return NT_SUCCESS(Status);
360 }
NTSTATUS ApphelpCacheParse(_In_reads_(DataLength) PUCHAR Data, _In_ ULONG DataLength)
Definition: apphelp.c:252
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
static UNICODE_STRING AppCompatCacheValue
Definition: apphelp.c:38
#define REG_BINARY
Definition: nt_native.h:1496
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define DPRINT1
Definition: precomp.h:8
PVOID ApphelpAlloc(_In_ ULONG ByteSize)
Definition: apphelp.c:102
unsigned int ULONG
Definition: retypes.h:1
VOID ApphelpFree(_In_ PVOID Data)
Definition: apphelp.c:109
static OBJECT_ATTRIBUTES AppCompatKeyAttributes
Definition: apphelp.c:37
VOID ApphelpCacheReleaseLock ( VOID  )

Definition at line 135 of file apphelp.c.

Referenced by ApphelpCacheDump(), ApphelpCacheFlush(), ApphelpCacheLookupEntry(), ApphelpCacheRemoveEntry(), ApphelpCacheUpdateEntry(), and ApphelpCacheWrite().

136 {
139 }
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
static ERESOURCE ApphelpCacheLock
Definition: apphelp.c:30
NTSTATUS ApphelpCacheRemoveEntry ( _In_ PUNICODE_STRING  ImageName)

Definition at line 588 of file apphelp.c.

Referenced by NtApphelpCacheControl().

590 {
593 
596  Status = ApphelpCacheRemoveEntryNolock(Entry);
598  return Status;
599 }
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
struct _Entry Entry
Definition: kefuncs.h:640
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
LONG NTSTATUS
Definition: precomp.h:26
Definition: apphelp.c:92
static const char * ImageName
Definition: image.c:34
VOID ApphelpCacheAcquireLock(VOID)
Definition: apphelp.c:116
Status
Definition: gdiplustypes.h:24
NTSTATUS ApphelpCacheRemoveEntryNolock(_In_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:515
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_ PVOID Buffer)
NTSTATUS ApphelpCacheRemoveEntryNolock ( _In_ PSHIM_CACHE_ENTRY  Entry)

Definition at line 515 of file apphelp.c.

Referenced by ApphelpCacheFlush(), ApphelpCacheLookupEntry(), ApphelpCacheRemoveEntry(), and ApphelpCacheUpdateEntry().

517 {
518  if (Entry)
519  {
520  PWSTR Buffer = Entry->Persistent.ImageName.Buffer;
521  RemoveEntryList(&Entry->List);
523  {
524  ApphelpFree(Buffer);
525  }
526  return STATUS_SUCCESS;
527  }
528  return STATUS_NOT_FOUND;
529 }
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_ PVOID Buffer)
PVOID *typedef PWSTR
Definition: winlogon.h:66
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
Definition: bufpool.h:45
#define STATUS_NOT_FOUND
Definition: shellext.h:55
VOID ApphelpFree(_In_ PVOID Data)
Definition: apphelp.c:109
return STATUS_SUCCESS
Definition: btrfs.c:2710
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI ApphelpCacheShutdown ( VOID  )

Definition at line 466 of file apphelp.c.

Referenced by PopGracefulShutdown().

467 {
469  {
471  }
472 }
BOOLEAN ApphelpCacheWrite(VOID)
Definition: apphelp.c:363
static BOOLEAN ApphelpCacheEnabled
Definition: apphelp.c:29
BOOLEAN ApphelpCacheTryAcquireLock ( VOID  )

Definition at line 123 of file apphelp.c.

Referenced by ApphelpCacheLookupEntry().

124 {
127  {
129  return FALSE;
130  }
131  return TRUE;
132 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
BOOLEAN NTAPI ExTryToAcquireResourceExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:2129
static ERESOURCE ApphelpCacheLock
Definition: apphelp.c:30
NTSTATUS ApphelpCacheUpdateEntry ( _In_ PUNICODE_STRING  ImageName,
_In_ HANDLE  ImageHandle 
)

Definition at line 617 of file apphelp.c.

Referenced by NtApphelpCacheControl().

620 {
624  PVOID NodeOrParent;
625  TABLE_SEARCH_RESULT SearchResult;
626 
628 
629  /* If we got a file handle, query it for info */
631  {
632  Status = ApphelpCacheQueryInfo(ImageHandle, &Entry);
633  if (!NT_SUCCESS(Status))
634  {
635  goto Cleanup;
636  }
637  }
638 
639  /* Use ImageName for the lookup, don't actually duplicate it */
640  Entry.Persistent.ImageName = *ImageName;
642  &Entry,
643  &NodeOrParent, &SearchResult);
644  if (Lookup)
645  {
646  DPRINT("SHIMS: ApphelpCacheUpdateEntry: Entry already exists, reusing it\n");
647  /* Unlink the found item, so we can put it back at the front,
648  and copy the earlier obtained file info*/
649  RemoveEntryList(&Lookup->List);
650  Lookup->Persistent.DateTime = Entry.Persistent.DateTime;
651  Lookup->Persistent.FileSize = Entry.Persistent.FileSize;
652  }
653  else
654  {
655  DPRINT("SHIMS: ApphelpCacheUpdateEntry: Inserting new Entry\n");
656  /* Insert a new entry, with its own copy of the ImageName */
659  &Entry,
660  sizeof(Entry),
661  0,
662  NodeOrParent,
663  SearchResult);
664  if (!Lookup)
665  {
666  ApphelpFreeUnicodeString(&Entry.Persistent.ImageName);
667  Status = STATUS_NO_MEMORY;
668  }
669  }
670  if (Lookup)
671  {
672  /* Either we re-used an existing item, or we inserted a new one, keep it alive */
675  {
677  DPRINT1("SHIMS: ApphelpCacheUpdateEntry: Cache growing too big, dropping oldest item\n");
679  Status = ApphelpCacheRemoveEntryNolock(Remove);
680  }
681  }
682 
683 Cleanup:
685  return Status;
686 }
DWORD *typedef PVOID
Definition: winlogon.h:61
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
#define INVALID_HANDLE_VALUE
Definition: apphelp.c:45
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
static RTL_AVL_TABLE ApphelpShimCache
Definition: apphelp.c:31
#define EMPTY_SHIM_ENTRY
Definition: apphelp.c:40
enum _TABLE_SEARCH_RESULT TABLE_SEARCH_RESULT
NTSYSAPI PVOID NTAPI RtlLookupElementGenericTableFullAvl(_In_ PRTL_AVL_TABLE Table, _In_ PVOID Buffer, _Out_ PVOID *NodeOrParent, _Out_ TABLE_SEARCH_RESULT *SearchResult)
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTableFullAvl(_In_ PRTL_AVL_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement, _In_ PVOID NodeOrParent, _In_ TABLE_SEARCH_RESULT SearchResult)
NTSTATUS ApphelpCacheQueryInfo(_In_ HANDLE ImageHandle, _Out_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:176
VOID ApphelpFreeUnicodeString(_Inout_ PUNICODE_STRING String)
Definition: apphelp.c:162
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
static void Lookup(RTF_Info *, char *)
Definition: reader.c:2229
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
void DPRINT(...)
Definition: polytest.cpp:61
_In_ BOOLEAN Remove
Definition: psfuncs.h:110
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY List
Definition: psmgr.c:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElementsAvl(_In_ PRTL_AVL_TABLE Table)
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
Definition: apphelp.c:92
#define MAX_SHIM_ENTRIES
Definition: apphelp.c:41
static const char * ImageName
Definition: image.c:34
static const WCHAR Cleanup[]
Definition: register.c:80
ACPI_EFI_HANDLE ACPI_EFI_DEVICE_PATH VOID UINTN ACPI_EFI_HANDLE * ImageHandle
Definition: acefiex.h:463
LIST_ENTRY List
Definition: apphelp.c:94
VOID ApphelpCacheAcquireLock(VOID)
Definition: apphelp.c:116
Status
Definition: gdiplustypes.h:24
VOID ApphelpDuplicateUnicodeString(_Out_ PUNICODE_STRING Destination, _In_ PCUNICODE_STRING Source)
Definition: apphelp.c:142
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
NTSTATUS ApphelpCacheRemoveEntryNolock(_In_ PSHIM_CACHE_ENTRY Entry)
Definition: apphelp.c:515
return STATUS_SUCCESS
Definition: btrfs.c:2710
base of all file and directory entries
Definition: entries.h:82
BOOLEAN ApphelpCacheWrite ( VOID  )

Definition at line 363 of file apphelp.c.

Referenced by ApphelpCacheShutdown(), and NtApphelpCacheControl().

364 {
366  ULONG NumEntries = 0;
367  PLIST_ENTRY ListEntry;
368  PUCHAR Buffer, BufferNamePos;
370  PSHIM_PERSISTENT_CACHE_ENTRY WriteEntry;
373 
374  /* First we have to calculate the required size. */
376  ListEntry = ApphelpShimCacheAge.Flink;
377  while (ListEntry != &ApphelpShimCacheAge)
378  {
381  Length += Entry->Persistent.ImageName.MaximumLength;
382  ++NumEntries;
383  ListEntry = ListEntry->Flink;
384  }
385  DPRINT("SHIMS: ApphelpCacheWrite, %d Entries, total size: %d\n", NumEntries, Length);
386  Length = ROUND_UP(Length, sizeof(ULONGLONG));
387  DPRINT("SHIMS: ApphelpCacheWrite, Rounded to: %d\n", Length);
388 
389  /* Now we allocate and prepare some helpers */
390  Buffer = ApphelpAlloc(Length);
391  BufferNamePos = Buffer + Length;
392  Header = (PSHIM_PERSISTENT_CACHE_HEADER)Buffer;
393  WriteEntry = (PSHIM_PERSISTENT_CACHE_ENTRY)(Buffer + SHIM_CACHE_HEADER_SIZE);
394 
395  Header->Magic = SHIM_CACHE_MAGIC;
396  Header->NumEntries = NumEntries;
397 
398  ListEntry = ApphelpShimCacheAge.Flink;
399  while (ListEntry != &ApphelpShimCacheAge)
400  {
402  USHORT ImageNameLen = Entry->Persistent.ImageName.MaximumLength;
403  /* Copy the Persistent structure over */
404  *WriteEntry = Entry->Persistent;
405  BufferNamePos -= ImageNameLen;
406  /* Copy the image name over */
407  RtlCopyMemory(BufferNamePos, Entry->Persistent.ImageName.Buffer, ImageNameLen);
408  /* Fix the Persistent structure, so that Buffer is once again an offset */
409  WriteEntry->ImageName.Buffer = (PWCH)(BufferNamePos - Buffer);
410 
411  ++WriteEntry;
412  ListEntry = ListEntry->Flink;
413  }
415 
416  Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &AppCompatKeyAttributes);
417  if (NT_SUCCESS(Status))
418  {
419  Status = ZwSetValueKey(KeyHandle,
421  0,
422  REG_BINARY,
423  Buffer,
424  Length);
425  ZwClose(KeyHandle);
426  }
427  else
428  {
429  DPRINT1("SHIMS: ApphelpCacheWrite could not even open Session Manager\\AppCompatCache (0x%x)\n", Status);
430  }
431 
432  ApphelpFree(Buffer);
433  return NT_SUCCESS(Status);
434 }
VOID ApphelpCacheReleaseLock(VOID)
Definition: apphelp.c:135
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
#define KEY_SET_VALUE
Definition: nt_native.h:1017
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
static UNICODE_STRING AppCompatCacheValue
Definition: apphelp.c:38
#define REG_BINARY
Definition: nt_native.h:1496
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define SHIM_CACHE_HEADER_SIZE
Definition: apphelp.c:77
Definition: Header.h:8
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
#define PSHIM_PERSISTENT_CACHE_HEADER
Definition: apphelp.c:84
void DPRINT(...)
Definition: polytest.cpp:61
#define SHIM_PERSISTENT_CACHE_ENTRY_SIZE
Definition: apphelp.c:81
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY List
Definition: psmgr.c:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
uint64_t ULONGLONG
Definition: typedefs.h:65
static LIST_ENTRY ApphelpShimCacheAge
Definition: apphelp.c:32
WCHAR * PWCH
Definition: ntbasedef.h:417
Definition: apphelp.c:92
#define PSHIM_PERSISTENT_CACHE_ENTRY
Definition: apphelp.c:86
VOID UINTN Length
Definition: acefiex.h:744
Definition: typedefs.h:117
static PWSTR SIZE_T Length
Definition: apphelp.c:91
VOID ApphelpCacheAcquireLock(VOID)
Definition: apphelp.c:116
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT1
Definition: precomp.h:8
PVOID ApphelpAlloc(_In_ ULONG ByteSize)
Definition: apphelp.c:102
unsigned int ULONG
Definition: retypes.h:1
#define SHIM_CACHE_MAGIC
Definition: apphelp.c:76
VOID ApphelpFree(_In_ PVOID Data)
Definition: apphelp.c:109
static OBJECT_ATTRIBUTES AppCompatKeyAttributes
Definition: apphelp.c:37
base of all file and directory entries
Definition: entries.h:82
VOID ApphelpDuplicateUnicodeString ( _Out_ PUNICODE_STRING  Destination,
_In_ PCUNICODE_STRING  Source 
)

Definition at line 142 of file apphelp.c.

Referenced by ApphelpCacheParse(), ApphelpCacheUpdateEntry(), and ApphelpValidateData().

145 {
146  Destination->Length = Source->Length;
147  if (Destination->Length)
148  {
153  }
154  else
155  {
158  }
159 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define WCHAR
Definition: msvc.h:43
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2875
PVOID ApphelpAlloc(_In_ ULONG ByteSize)
Definition: apphelp.c:102
VOID ApphelpFree ( _In_ PVOID  Data)

Definition at line 109 of file apphelp.c.

Referenced by ApphelpCacheRead(), ApphelpCacheRemoveEntryNolock(), ApphelpCacheWrite(), ApphelpFreeUnicodeString(), and ApphelpShimCacheFreeRoutine().

111 {
113 }
#define TAG_SHIM
Definition: apphelp.c:42
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID ApphelpFreeUnicodeString ( _Inout_ PUNICODE_STRING  String)

Definition at line 162 of file apphelp.c.

Referenced by ApphelpCacheParse(), ApphelpCacheUpdateEntry(), and NtApphelpCacheControl().

164 {
165  if (String->Buffer)
166  {
167  ApphelpFree(String->Buffer);
168  }
169  String->Length = 0;
170  String->MaximumLength = 0;
171  String->Buffer = NULL;
172 }
CHAR16 * String
Definition: acefiex.h:201
smooth NULL
Definition: ftsmooth.c:416
VOID ApphelpFree(_In_ PVOID Data)
Definition: apphelp.c:109
PVOID NTAPI ApphelpShimCacheAllocateRoutine ( _In_ struct _RTL_AVL_TABLE Table,
_In_ CLONG  ByteSize 
)

Definition at line 235 of file apphelp.c.

Referenced by ApphelpCacheInitialize().

238 {
239  return ApphelpAlloc(ByteSize);
240 }
PVOID ApphelpAlloc(_In_ ULONG ByteSize)
Definition: apphelp.c:102
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:389
RTL_GENERIC_COMPARE_RESULTS NTAPI ApphelpShimCacheCompareRoutine ( _In_ struct _RTL_AVL_TABLE Table,
_In_ PVOID  FirstStruct,
_In_ PVOID  SecondStruct 
)

Definition at line 210 of file apphelp.c.

Referenced by ApphelpCacheInitialize().

214 {
215  PSHIM_CACHE_ENTRY FirstEntry = FirstStruct;
216  PSHIM_CACHE_ENTRY SecondEntry = SecondStruct;
217  LONG Result;
218 
219  Result = RtlCompareUnicodeString(&FirstEntry->Persistent.ImageName,
220  &SecondEntry->Persistent.ImageName,
221  TRUE);
222  if (Result < 0)
223  {
224  return GenericLessThan;
225  }
226  else if (Result == 0)
227  {
228  return GenericEqual;
229  }
230  return GenericGreaterThan;
231 }
#define TRUE
Definition: types.h:120
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
long LONG
Definition: pedump.c:60
SHIM_PERSISTENT_CACHE_ENTRY Persistent
Definition: apphelp.c:95
_IRQL_requires_same_ _In_ PVOID _In_ PVOID SecondStruct
Definition: rtltypes.h:379
Definition: apphelp.c:92
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
_IRQL_requires_same_ _In_ PVOID FirstStruct
Definition: rtltypes.h:379
VOID NTAPI ApphelpShimCacheFreeRoutine ( _In_ struct _RTL_AVL_TABLE Table,
_In_ PVOID  Buffer 
)

Definition at line 244 of file apphelp.c.

Referenced by ApphelpCacheInitialize().

247 {
249 }
Definition: bufpool.h:45
VOID ApphelpFree(_In_ PVOID Data)
Definition: apphelp.c:109
NTSTATUS ApphelpValidateData ( _In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP  ServiceData,
_Out_ PUNICODE_STRING  ImageName,
_Out_ PHANDLE  ImageHandle 
)

Definition at line 475 of file apphelp.c.

Referenced by NtApphelpCacheControl().

479 {
481 
482  if (ServiceData)
483  {
484  UNICODE_STRING LocalImageName;
485  _SEH2_TRY
486  {
487  ProbeForRead(ServiceData,
489  sizeof(ULONG));
490  LocalImageName = ServiceData->ImageName;
491  *ImageHandle = ServiceData->ImageHandle;
492  if (LocalImageName.Length && LocalImageName.Buffer)
493  {
494  ProbeForRead(LocalImageName.Buffer,
495  LocalImageName.Length * sizeof(WCHAR),
496  1);
497  ApphelpDuplicateUnicodeString(ImageName, &LocalImageName);
498  Status = STATUS_SUCCESS;
499  }
500  }
502  {
504  }
505  _SEH2_END;
506  }
507  if (!NT_SUCCESS(Status))
508  {
509  DPRINT1("SHIMS: ApphelpValidateData: invalid data passed\n");
510  }
511  return Status;
512 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static const char * ImageName
Definition: image.c:34
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
ACPI_EFI_HANDLE ACPI_EFI_DEVICE_PATH VOID UINTN ACPI_EFI_HANDLE * ImageHandle
Definition: acefiex.h:463
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
VOID ApphelpDuplicateUnicodeString(_Out_ PUNICODE_STRING Destination, _In_ PCUNICODE_STRING Source)
Definition: apphelp.c:142
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS NTAPI NtApphelpCacheControl ( _In_ APPHELPCACHESERVICECLASS  Service,
_In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP  ServiceData 
)

Definition at line 729 of file apphelp.c.

Referenced by CallApphelp().

732 {
734  UNICODE_STRING ImageName = { 0 };
736 
737  if (!ApphelpCacheEnabled)
738  {
739  DPRINT1("NtApphelpCacheControl: ApphelpCacheEnabled == 0\n");
740  return Status;
741  }
742  switch (Service)
743  {
745  DPRINT("SHIMS: NtApphelpCacheControl( ApphelpCacheServiceLookup )\n");
746  Status = ApphelpValidateData(ServiceData, &ImageName, &Handle);
747  if (NT_SUCCESS(Status))
748  Status = ApphelpCacheLookupEntry(&ImageName, Handle);
749  break;
751  DPRINT("SHIMS: NtApphelpCacheControl( ApphelpCacheServiceRemove )\n");
752  Status = ApphelpValidateData(ServiceData, &ImageName, &Handle);
753  if (NT_SUCCESS(Status))
754  Status = ApphelpCacheRemoveEntry(&ImageName);
755  break;
757  DPRINT("SHIMS: NtApphelpCacheControl( ApphelpCacheServiceUpdate )\n");
758  Status = ApphelpCacheAccessCheck();
759  if (NT_SUCCESS(Status))
760  {
761  Status = ApphelpValidateData(ServiceData, &ImageName, &Handle);
762  if (NT_SUCCESS(Status))
763  Status = ApphelpCacheUpdateEntry(&ImageName, Handle);
764  }
765  break;
767  Status = ApphelpCacheFlush();
768  break;
770  Status = ApphelpCacheDump();
771  break;
773  DPRINT1("SHIMS: NtApphelpCacheControl( ApphelpDBGReadRegistry ): flushing cache.\n");
775  DPRINT1("SHIMS: NtApphelpCacheControl( ApphelpDBGReadRegistry ): reading cache.\n");
777  break;
779  DPRINT1("SHIMS: NtApphelpCacheControl( ApphelpDBGWriteRegistry ): writing cache.\n");
781  break;
782  default:
783  DPRINT1("SHIMS: NtApphelpCacheControl( Invalid service requested )\n");
784  break;
785  }
786  if (ImageName.Buffer)
787  {
788  ApphelpFreeUnicodeString(&ImageName);
789  }
790  return Status;
791 }
NTSTATUS ApphelpCacheDump(VOID)
Definition: apphelp.c:704
#define INVALID_HANDLE_VALUE
Definition: apphelp.c:45
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS ApphelpCacheUpdateEntry(_In_ PUNICODE_STRING ImageName, _In_ HANDLE ImageHandle)
Definition: apphelp.c:617
BOOLEAN ApphelpCacheRead(VOID)
Definition: apphelp.c:307
VOID ApphelpFreeUnicodeString(_Inout_ PUNICODE_STRING String)
Definition: apphelp.c:162
BOOLEAN ApphelpCacheWrite(VOID)
Definition: apphelp.c:363
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
#define STATUS_NOT_FOUND
Definition: shellext.h:55
NTSTATUS ApphelpCacheAccessCheck(VOID)
Definition: apphelp.c:603
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN ApphelpCacheEnabled
Definition: apphelp.c:29
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static const char * ImageName
Definition: image.c:34
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
NTSTATUS ApphelpValidateData(_In_opt_ PAPPHELP_CACHE_SERVICE_LOOKUP ServiceData, _Out_ PUNICODE_STRING ImageName, _Out_ PHANDLE ImageHandle)
Definition: apphelp.c:475
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS ApphelpCacheRemoveEntry(_In_ PUNICODE_STRING ImageName)
Definition: apphelp.c:588
NTSTATUS ApphelpCacheFlush(VOID)
Definition: apphelp.c:689
NTSTATUS ApphelpCacheLookupEntry(_In_ PUNICODE_STRING ImageName, _In_ HANDLE ImageHandle)
Definition: apphelp.c:532

Variable Documentation

UNICODE_STRING AppCompatCacheKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCompatCache")
static

Definition at line 36 of file apphelp.c.

UNICODE_STRING AppCompatCacheValue = RTL_CONSTANT_STRING(L"AppCompatCache")
static

Definition at line 38 of file apphelp.c.

BOOLEAN ApphelpCacheEnabled = FALSE
static

Definition at line 29 of file apphelp.c.

Referenced by ApphelpCacheInitialize(), ApphelpCacheShutdown(), and NtApphelpCacheControl().

ERESOURCE ApphelpCacheLock
static
RTL_AVL_TABLE ApphelpShimCache
static

Definition at line 31 of file apphelp.c.

LIST_ENTRY ApphelpShimCacheAge
static

Definition at line 32 of file apphelp.c.

ULONG InitSafeBootMode

Definition at line 68 of file init.c.

Referenced by ApphelpCacheInitialize(), and Phase1InitializationDiscard().