ReactOS 0.4.16-dev-329-g9223134
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:");
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
71BOOL 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
UINT cchMax
WCHAR lpszDest[260]
Definition: bufpool.h:45
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GUID * guid
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static PVOID ptr
Definition: dispmode.c:27
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define INT
Definition: polytest.cpp:20
#define SHIM_INFO(fmt,...)
Definition: sdbpapi.h:78
#define SHIM_WARN(fmt,...)
Definition: sdbpapi.h:77
static LPSTR PULONG lpnSize
Definition: secur32.c:50
#define SHIM_REASON_INIT
Definition: shimlib.h:45
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
int WINAPI SHIM_OBJ_NAME() SHStringFromGUIDA(REFGUID guid, LPSTR lpszDest, INT cchMax)
Definition: shimtest.c:51
BOOL(WINAPI * tGetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:19
INT(WINAPI * tSHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax)
Definition: shimtest.c:50
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
BOOL WINAPI SHIM_OBJ_NAME() Notify(DWORD fdwReason, PVOID ptr)
Definition: shimtest.c:71
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:832
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
Definition: scsiwmi.h:51
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
#define WINAPI
Definition: msvc.h:6
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175