[ROSAPPS] Add a test application for shims
authorMark Jansen <mark.jansen@reactos.org>
Tue, 30 Apr 2019 20:50:21 +0000 (22:50 +0200)
committerMark Jansen <mark.jansen@reactos.org>
Wed, 1 May 2019 17:22:19 +0000 (19:22 +0200)
modules/rosapps/applications/devutils/CMakeLists.txt
modules/rosapps/applications/devutils/shimtest_ros/CMakeLists.txt [new file with mode: 0644]
modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.c [new file with mode: 0644]
modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.rc [new file with mode: 0644]

index 5ea4b08..ccbc43e 100644 (file)
@@ -5,6 +5,7 @@ add_subdirectory(gdihv)
 add_subdirectory(genguid)
 add_subdirectory(nls2txt)
 add_subdirectory(shimdbg)
+add_subdirectory(shimtest_ros)
 add_subdirectory(shlextdbg)
 add_subdirectory(symdump)
 add_subdirectory(syscalldump)
diff --git a/modules/rosapps/applications/devutils/shimtest_ros/CMakeLists.txt b/modules/rosapps/applications/devutils/shimtest_ros/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d4fc954
--- /dev/null
@@ -0,0 +1,8 @@
+
+project(appcompat)
+
+add_executable(shimtest_ros shimtest_ros.c shimtest_ros.rc)
+
+set_module_type(shimtest_ros win32cui)
+add_importlibs(shimtest_ros shlwapi msvcrt kernel32 ntdll)
+add_cd_file(TARGET shimtest_ros DESTINATION reactos/bin FOR all)
diff --git a/modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.c b/modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.c
new file mode 100644 (file)
index 0000000..6959229
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * PROJECT:     Shim test application
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     Test application for the shim engine
+ * COPYRIGHT:   Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <ntndk.h>
+#include <winbase.h>
+
+NTSYSAPI ULONG NTAPI vDbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ PCCH Format, _In_ va_list ap);
+#define DPFLTR_ERROR_LEVEL 0
+
+void xprintf(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vprintf(fmt, ap);
+    vDbgPrintEx(-1, DPFLTR_ERROR_LEVEL, fmt, ap);
+    va_end(ap);
+}
+
+void test_normal_imports()
+{
+    char buf[100];
+    DWORD dwSize;
+    HMODULE mod;
+    BOOL (WINAPI *p_GetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize);
+
+    /* Call it directly */
+    ZeroMemory(buf, sizeof(buf));
+    dwSize = sizeof(buf);
+    if (!GetComputerNameA(buf, &dwSize))
+    {
+        xprintf("GetComputerNameA failed: %d\n", GetLastError());
+    }
+    else
+    {
+        xprintf("GetComputerNameA returned: '%s'\n", buf);
+    }
+
+    /* Call it using GetProcAddress */
+    mod = GetModuleHandleA("kernel32.dll");
+    p_GetComputerNameA = (void*)GetProcAddress(mod, "GetComputerNameA");
+    if (p_GetComputerNameA == NULL)
+    {
+        xprintf("GetProcAddress failed: %d\n", GetLastError());
+    }
+    else
+    {
+        ZeroMemory(buf, sizeof(buf));
+        dwSize = sizeof(buf);
+        if (!p_GetComputerNameA(buf, &dwSize))
+        {
+            xprintf("p_GetComputerNameA failed: %d\n", GetLastError());
+        }
+        else
+        {
+            xprintf("p_GetComputerNameA returned: '%s'\n", buf);
+        }
+    }
+}
+
+INT WINAPI SHStringFromGUIDA(REFGUID,LPSTR,INT);
+void test_ordinal_imports()
+{
+    GUID guid = { 0x11223344, 0x5566, 0x7788 };
+    char buf[100];
+    int r;
+    HMODULE mod;
+    INT (WINAPI *p_SHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax);
+
+    /* Call it directly */
+    ZeroMemory(buf, sizeof(buf));
+    r = SHStringFromGUIDA(&guid, buf, _countof(buf)-1);
+    if (r)
+    {
+        xprintf("SHStringFromGUIDA failed (%d)\n", r);
+    }
+    else
+    {
+        xprintf("SHStringFromGUIDA returned: '%s'\n", buf);
+    }
+
+    /* Call it using GetProcAddress */
+    mod = GetModuleHandleA("shlwapi.dll");
+    p_SHStringFromGUIDA = (void*)GetProcAddress(mod, (LPCSTR)23);
+    if (p_SHStringFromGUIDA == NULL)
+    {
+        xprintf("GetProcAddress failed: %d\n", GetLastError());
+    }
+    else
+    {
+        ZeroMemory(buf, sizeof(buf));
+        r = p_SHStringFromGUIDA(&guid, buf, _countof(buf)-1);
+        if (r)
+        {
+            xprintf("p_SHStringFromGUIDA failed (%d)\n", r);
+        }
+        else
+        {
+            xprintf("p_SHStringFromGUIDA returned: '%s'\n", buf);
+        }
+    }
+}
+
+
+int main(int argc, char* argv[])
+{
+    xprintf("Normal import (kernel32!GetComputerNameA)\n");
+    test_normal_imports();
+    xprintf("\nOrdinal import (shlwapi!#23)\n");
+    test_ordinal_imports();
+
+    return 0;
+}
diff --git a/modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.rc b/modules/rosapps/applications/devutils/shimtest_ros/shimtest_ros.rc
new file mode 100644 (file)
index 0000000..147e770
--- /dev/null
@@ -0,0 +1,6 @@
+
+#define REACTOS_STR_FILE_DESCRIPTION  "ReactOS Shim Engine test utility"
+#define REACTOS_STR_INTERNAL_NAME     "shimtest_ros"
+#define REACTOS_STR_ORIGINAL_FILENAME "shimtest_ros.exe"
+#define REACTOS_STR_COMPANY_NAME      "ReactOS - test"
+#include <reactos/version.rc>