From 575ab6c760ccc1439cf829824b5721c0426cb88c Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Tue, 30 Apr 2019 22:51:28 +0200 Subject: [PATCH] [ACGENRAL] Add a test shim --- dll/appcompat/shims/genral/CMakeLists.txt | 1 + dll/appcompat/shims/genral/shimtest.c | 88 +++++++++++++++++++++++ media/sdb/sysmain.xml | 14 ++++ 3 files changed, 103 insertions(+) create mode 100644 dll/appcompat/shims/genral/shimtest.c diff --git a/dll/appcompat/shims/genral/CMakeLists.txt b/dll/appcompat/shims/genral/CMakeLists.txt index da6a55d9989..bc2c1d083f4 100644 --- a/dll/appcompat/shims/genral/CMakeLists.txt +++ b/dll/appcompat/shims/genral/CMakeLists.txt @@ -7,6 +7,7 @@ list(APPEND SOURCE ignoredbgout.c ignorefreelib.c main.c + shimtest.c themes.c genral.spec) diff --git a/dll/appcompat/shims/genral/shimtest.c b/dll/appcompat/shims/genral/shimtest.c new file mode 100644 index 00000000000..630b04263b0 --- /dev/null +++ b/dll/appcompat/shims/genral/shimtest.c @@ -0,0 +1,88 @@ +/* + * PROJECT: ReactOS 'General' Shim library + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Test shim used to verify the inner working of the shim engine + * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org) + */ + +#define WIN32_NO_STATUS +#include +#include +#include +#include + + +#define SHIM_NS ShimTest +#include + + +typedef BOOL (WINAPI *tGetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize); + +BOOL WINAPI SHIM_OBJ_NAME(GetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize) +{ + CHAR Buffer[100] = {0}; + DWORD dwSize = sizeof(Buffer) - 1; + size_t cchLen; + + if (CALL_SHIM(0, tGetComputerNameA)(Buffer, &dwSize)) + { + SHIM_INFO("Original function returned: '%s'\n", Buffer); + } + else + { + SHIM_INFO("Original function failed\n"); + Buffer[0] = '\0'; + } + + if (!lpnSize) + { + SHIM_WARN("No lpnSize\n"); + return FALSE; + } + + StringCchCopyA(lpBuffer, *lpnSize, "ShimTest:"); + StringCchCatA(lpBuffer, *lpnSize, Buffer); + StringCchLengthA(lpBuffer, *lpnSize, &cchLen); + *lpnSize = (DWORD)cchLen; + return TRUE; +} + +typedef INT (WINAPI *tSHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax); +int WINAPI SHIM_OBJ_NAME(SHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax) +{ + CHAR Buffer[100] = {0}; + + if (CALL_SHIM(1, tSHStringFromGUIDA)(guid, Buffer, sizeof(Buffer)-1)) + { + SHIM_INFO("Original function returned: '%s'\n", Buffer); + } + else + { + SHIM_INFO("Original function failed\n"); + Buffer[0] = '\0'; + } + + StringCchCopyA(lpszDest, cchMax, "ShimTest:"); + StringCchCatA(lpszDest, cchMax, Buffer); + return 0; +} + + +BOOL WINAPI SHIM_OBJ_NAME(Notify)(DWORD fdwReason, PVOID ptr) +{ + if (fdwReason == SHIM_REASON_INIT) + { + SHIM_MSG("SHIM_REASON_INIT\n"); + } + return TRUE; +} + +#define SHIM_NOTIFY_FN SHIM_OBJ_NAME(Notify) +#define SHIM_NUM_HOOKS 2 +#define SHIM_SETUP_HOOKS \ + SHIM_HOOK(0, "KERNEL32.DLL", "GetComputerNameA", SHIM_OBJ_NAME(GetComputerNameA)) \ + SHIM_HOOK(1, "SHLWAPI.DLL", (PCSTR)23, SHIM_OBJ_NAME(SHStringFromGUIDA)) + + +#include + diff --git a/media/sdb/sysmain.xml b/media/sdb/sysmain.xml index de87df7c0d1..7afab95388e 100644 --- a/media/sdb/sysmain.xml +++ b/media/sdb/sysmain.xml @@ -225,6 +225,10 @@ aclayers.dll + + acgenral.dll + Shim used to test ReactOS shim engine functionality + aclayers.dll @@ -405,5 +409,15 @@ + + + + ReactOS Shim Engine test utility + shimtest_ros.exe + shimtest_ros + ReactOS - test + + + \ No newline at end of file