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
19 typedef BOOL (WINAPI *tGetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize);
20
SHIM_OBJ_NAME(GetComputerNameA)21 BOOL WINAPI SHIM_OBJ_NAME(GetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize)
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:");
44 StringCchCatA(lpBuffer, *lpnSize, Buffer);
45 StringCchLengthA(lpBuffer, *lpnSize, &cchLen);
46 *lpnSize = (DWORD)cchLen;
47 return TRUE;
48 }
49
50 typedef INT (WINAPI *tSHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax);
SHIM_OBJ_NAME(SHStringFromGUIDA)51 int WINAPI SHIM_OBJ_NAME(SHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax)
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:");
66 StringCchCatA(lpszDest, cchMax, Buffer);
67 return 0;
68 }
69
70
SHIM_OBJ_NAME(Notify)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
89