ReactOS  0.4.12-dev-396-g37af787
apphelp.c File Reference
#include "windef.h"
#include "winbase.h"
#include "winver.h"
#include "strsafe.h"
#include "apphelp.h"
#include "ndk/rtlfuncs.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 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

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_ PWCHAR 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)
 

Variables

ULONG g_ShimDebugLevel = 0xffffffff
 
HMODULE g_hInstance
 

Macro Definition Documentation

◆ APPHELP_CLEARBITS

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

Definition at line 147 of file apphelp.c.

◆ APPHELP_DONTWRITE_REASON

#define APPHELP_DONTWRITE_REASON   2

Definition at line 146 of file apphelp.c.

◆ APPHELP_IGNORE_ENVIRONMENT

#define APPHELP_IGNORE_ENVIRONMENT   0x400

Definition at line 148 of file apphelp.c.

◆ APPHELP_RESULT_FOUND

#define APPHELP_RESULT_FOUND   0x40000

Definition at line 152 of file apphelp.c.

◆ APPHELP_RESULT_NOTFOUND

#define APPHELP_RESULT_NOTFOUND   0x20000

Definition at line 151 of file apphelp.c.

◆ APPHELP_VALID_RESULT

#define APPHELP_VALID_RESULT   0x10000

Definition at line 150 of file apphelp.c.

◆ DPFLTR_APPCOMPAT_ID

#define DPFLTR_APPCOMPAT_ID   123

Definition at line 21 of file apphelp.c.

◆ NT_SUCCESS

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

Definition at line 24 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 67 of file apphelp.c.

68 {
69  SHIM_WARN("stub: ptr=%p, path='%S'\r\n", ptr, path);
70  return TRUE;
71 }
#define TRUE
Definition: types.h:120
static PVOID ptr
Definition: dispmode.c:27
Definition: services.c:325

◆ ApphelpCheckRunAppEx()

BOOL WINAPI ApphelpCheckRunAppEx ( _In_ HANDLE  FileHandle,
_In_opt_ PVOID  Unk1,
_In_opt_ PVOID  Unk2,
_In_opt_z_ PWCHAR  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 176 of file apphelp.c.

191 {
193  HSDB hsdb = NULL;
194  DWORD dwFlags = 0;
195 
196  if (SxsData)
197  *SxsData = NULL;
198  if (SxsDataSize)
199  *SxsDataSize = 0;
200  if (FusionFlags)
201  *FusionFlags = 0;
202  if (SomeFlag1)
203  *SomeFlag1 = 0;
204  if (SomeFlag2)
205  *SomeFlag2 = 0;
206  if (Reason)
207  dwFlags = *Reason;
208 
210 
211  *SdbQueryAppCompatData = result = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SDBQUERYRESULT));
213  *SdbQueryAppCompatDataSize = sizeof(*result);
214 
215 
217  if (hsdb)
218  {
219  BOOL FoundMatch;
220  DWORD MatchingExeFlags = 0;
221 
223  MatchingExeFlags |= SDBGMEF_IGNORE_ENVIRONMENT;
224 
225  FoundMatch = SdbGetMatchingExe(hsdb, ApplicationName, NULL, Environment, MatchingExeFlags, result);
227  {
230  }
231 
232  SdbReleaseDatabase(hsdb);
233  }
234 
236  *Reason = dwFlags;
237 
238 
239  /* We should _ALWAYS_ return TRUE here, unless we want to block an application from starting! */
240  return TRUE;
241 }
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:45
#define APPHELP_DONTWRITE_REASON
Definition: apphelp.c:146
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG FusionFlags
Definition: env.c:45
#define TRUE
Definition: types.h:120
#define SDBGMEF_IGNORE_ENVIRONMENT
Definition: apphelp.h:59
#define INVALID_HANDLE_VALUE
Definition: apphelp.c:45
HSDB WINAPI SdbInitDatabase(DWORD, LPCWSTR)
Definition: hsdb.c:369
BOOL WINAPI SdbGetMatchingExe(HSDB hsdb, LPCWSTR path, LPCWSTR module_name, LPCWSTR env, DWORD flags, PSDBQUERYRESULT result)
Definition: hsdb.c:439
#define APPHELP_CLEARBITS
Definition: apphelp.c:147
Definition: apphelp.h:27
#define SDB_DATABASE_MAIN_SHIM
Definition: apphelp.h:24
HANDLE FileHandle
Definition: stats.c:38
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG PULONG64 SomeFlag1
Definition: env.c:45
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
unsigned int BOOL
Definition: ntddk_ex.h:94
#define APPHELP_RESULT_NOTFOUND
Definition: apphelp.c:151
unsigned long DWORD
Definition: ntddk_ex.h:95
#define HID_DOS_PATHS
Definition: apphelp.h:19
#define APPHELP_IGNORE_ENVIRONMENT
Definition: apphelp.c:148
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
void WINAPI SdbReleaseDatabase(HSDB)
Definition: hsdb.c:417
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:45
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG SxsDataSize
Definition: env.c:45
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG PULONG64 PULONG SomeFlag2
Definition: env.c:45
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define APPHELP_RESULT_FOUND
Definition: apphelp.c:152
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID * SxsData
Definition: env.c:45
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:45
GLuint64EXT * result
Definition: glext.h:11304
#define APPHELP_VALID_RESULT
Definition: apphelp.c:150
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID * SdbQueryAppCompatData
Definition: env.c:45
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG SdbQueryAppCompatDataSize
Definition: env.c:45

◆ ApphelpCheckShellObject()

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

Definition at line 74 of file apphelp.c.

75 {
76  WCHAR GuidString[100];
77  if (!ObjectCLSID || !SdbGUIDToString(ObjectCLSID, GuidString, 100))
78  GuidString[0] = L'\0';
79  SHIM_WARN("stub: ObjectCLSID='%S', bShimIfNecessary=%d, pullFlags=%p)\n", GuidString, bShimIfNecessary, pullFlags);
80 
81  if (pullFlags)
82  *pullFlags = 0;
83 
84  return TRUE;
85 }
static PWSTR GuidString
Definition: apphelp.c:91
#define TRUE
Definition: types.h:120
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SdbGUIDToString(CONST GUID *Guid, PWSTR GuidString, SIZE_T Length)
Definition: sdbapi.c:397
static const WCHAR L[]
Definition: oid.c:1087

Referenced by START_TEST().

◆ ApphelppInitDebugLevel()

void ApphelppInitDebugLevel ( void  )

Definition at line 30 of file apphelp.c.

31 {
32  static const UNICODE_STRING DebugKey = RTL_CONSTANT_STRING(L"SHIM_DEBUG_LEVEL");
33  UNICODE_STRING DebugValue;
35  ULONG NewLevel = SHIM_ERR;
36  WCHAR Buffer[40];
37 
38  RtlInitEmptyUnicodeString(&DebugValue, Buffer, sizeof(Buffer));
39 
40  Status = RtlQueryEnvironmentVariable_U(NULL, &DebugKey, &DebugValue);
41 
42  if (NT_SUCCESS(Status))
43  {
44  if (!NT_SUCCESS(RtlUnicodeStringToInteger(&DebugValue, 10, &NewLevel)))
45  NewLevel = SHIM_ERR;
46  }
47  g_ShimDebugLevel = NewLevel;
48 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static const WCHAR L[]
Definition: oid.c:1087
ULONG g_ShimDebugLevel
Definition: apphelp.c:27
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
unsigned int ULONG
Definition: retypes.h:1
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by ShimDbgPrint().

◆ DllMain()

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

Definition at line 51 of file apphelp.c.

52 {
53  switch (reason)
54  {
55  case DLL_PROCESS_ATTACH:
58  SdbpHeapInit();
59  break;
60  case DLL_PROCESS_DETACH:
62  break;
63  }
64  return TRUE;
65 }
#define TRUE
Definition: types.h:120
void SdbpHeapDeinit(void)
Definition: sdbapi.c:42
void SdbpHeapInit(void)
Definition: sdbapi.c:34
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
static HINSTANCE hinst
Definition: edit.c:551
HMODULE g_hInstance
Definition: apphelp.c:28

◆ 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 98 of file apphelp.c.

99 {
100  char Buffer[512];
101  va_list ArgList;
102  char* Current = Buffer;
103  const char* LevelStr;
104  size_t Length = sizeof(Buffer);
105 
106  if (g_ShimDebugLevel == 0xffffffff)
108 
109  if (Level > g_ShimDebugLevel)
110  return FALSE;
111 
112  switch (Level)
113  {
114  case SHIM_ERR:
115  LevelStr = "Err ";
117  break;
118  case SHIM_WARN:
119  LevelStr = "Warn";
121  break;
122  case SHIM_INFO:
123  LevelStr = "Info";
125  break;
126  default:
127  LevelStr = "User";
129  break;
130  }
131  StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "[%s][%-20s] ", LevelStr, FunctionName);
132 
133  va_start(ArgList, Format);
134  StringCchVPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
135  va_end(ArgList);
136 
137 #if defined(APPCOMPAT_USE_DBGPRINTEX) && APPCOMPAT_USE_DBGPRINTEX
139 #else
140  DbgPrint("%s", Buffer);
141  return TRUE;
142 #endif
143 }
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
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
#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,...)
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:575
#define DPFLTR_WARNING_LEVEL
Definition: kdtypes.h:31
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG g_ShimDebugLevel
Definition: apphelp.c:27
void ApphelppInitDebugLevel(void)
Definition: apphelp.c:30
#define DPFLTR_ERROR_LEVEL
Definition: main.cpp:32
#define DPFLTR_APPCOMPAT_ID
Definition: apphelp.c:21
#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:1260
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:47
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Variable Documentation

◆ g_hInstance

HMODULE g_hInstance

Definition at line 28 of file apphelp.c.

Referenced by DllMain().

◆ g_ShimDebugLevel

ULONG g_ShimDebugLevel = 0xffffffff

Definition at line 27 of file apphelp.c.

Referenced by ApphelppInitDebugLevel(), and ShimDbgPrint().