ReactOS  0.4.13-dev-544-gede3fdd
shimtest.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS 'General' Shim library
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Test shim used to verify the inner working of the shim engine
5  * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #define WIN32_NO_STATUS
9 #include <windef.h>
10 #include <winbase.h>
11 #include <shimlib.h>
12 #include <strsafe.h>
13 
14 
15 #define SHIM_NS ShimTest
16 #include <setup_shim.inl>
17 
18 
20 
22 {
23  CHAR Buffer[100] = {0};
24  DWORD dwSize = sizeof(Buffer) - 1;
25  size_t cchLen;
26 
27  if (CALL_SHIM(0, tGetComputerNameA)(Buffer, &dwSize))
28  {
29  SHIM_INFO("Original function returned: '%s'\n", Buffer);
30  }
31  else
32  {
33  SHIM_INFO("Original function failed\n");
34  Buffer[0] = '\0';
35  }
36 
37  if (!lpnSize)
38  {
39  SHIM_WARN("No lpnSize\n");
40  return FALSE;
41  }
42 
43  StringCchCopyA(lpBuffer, *lpnSize, "ShimTest:");
45  StringCchLengthA(lpBuffer, *lpnSize, &cchLen);
46  *lpnSize = (DWORD)cchLen;
47  return TRUE;
48 }
49 
52 {
53  CHAR Buffer[100] = {0};
54 
55  if (CALL_SHIM(1, tSHStringFromGUIDA)(guid, Buffer, sizeof(Buffer)-1))
56  {
57  SHIM_INFO("Original function returned: '%s'\n", Buffer);
58  }
59  else
60  {
61  SHIM_INFO("Original function failed\n");
62  Buffer[0] = '\0';
63  }
64 
65  StringCchCopyA(lpszDest, cchMax, "ShimTest:");
67  return 0;
68 }
69 
70 
71 BOOL WINAPI SHIM_OBJ_NAME(Notify)(DWORD fdwReason, PVOID ptr)
72 {
73  if (fdwReason == SHIM_REASON_INIT)
74  {
75  SHIM_MSG("SHIM_REASON_INIT\n");
76  }
77  return TRUE;
78 }
79 
80 #define SHIM_NOTIFY_FN SHIM_OBJ_NAME(Notify)
81 #define SHIM_NUM_HOOKS 2
82 #define SHIM_SETUP_HOOKS \
83  SHIM_HOOK(0, "KERNEL32.DLL", "GetComputerNameA", SHIM_OBJ_NAME(GetComputerNameA)) \
84  SHIM_HOOK(1, "SHLWAPI.DLL", (PCSTR)23, SHIM_OBJ_NAME(SHStringFromGUIDA))
85 
86 
87 #include <implement_shim.inl>
88 
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
#define TRUE
Definition: types.h:120
Definition: scsiwmi.h:51
char CHAR
Definition: xmlstorage.h:175
#define INT
Definition: polytest.cpp:20
char * LPSTR
Definition: xmlstorage.h:182
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
BOOL(WINAPI * tGetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:19
int32_t INT
Definition: typedefs.h:56
const GUID * guid
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
static LPSTR PULONG lpnSize
Definition: secur32.c:50
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
static PVOID ptr
Definition: dispmode.c:27
WCHAR lpszDest[260]
#define SHIM_REASON_INIT
Definition: shimlib.h:45
Definition: bufpool.h:45
INT(WINAPI * tSHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax)
Definition: shimtest.c:50
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT cchMax
int WINAPI SHIM_OBJ_NAME() SHStringFromGUIDA(REFGUID guid, LPSTR lpszDest, INT cchMax)
Definition: shimtest.c:51
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:832
BOOL WINAPI SHIM_OBJ_NAME() Notify(DWORD fdwReason, PVOID ptr)
Definition: shimtest.c:71
uint32_t * LPDWORD
Definition: typedefs.h:57
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54