ReactOS 0.4.15-dev-8146-gdc0ed6d
shimtest_ros.c
Go to the documentation of this file.
1/*
2 * PROJECT: Shim test application
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test application for the shim engine
5 * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <ctype.h>
11#include <ntndk.h>
12#include <winbase.h>
13
15#define DPFLTR_ERROR_LEVEL 0
16
17void xprintf(const char *fmt, ...)
18{
19 va_list ap;
20
21 va_start(ap, fmt);
22 vprintf(fmt, ap);
24 va_end(ap);
25}
26
28{
29 char buf[100];
32 BOOL (WINAPI *p_GetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize);
33
34 /* Call it directly */
35 ZeroMemory(buf, sizeof(buf));
36 dwSize = sizeof(buf);
38 {
39 xprintf("GetComputerNameA failed: %d\n", GetLastError());
40 }
41 else
42 {
43 xprintf("GetComputerNameA returned: '%s'\n", buf);
44 }
45
46 /* Call it using GetProcAddress */
47 mod = GetModuleHandleA("kernel32.dll");
48 p_GetComputerNameA = (void*)GetProcAddress(mod, "GetComputerNameA");
49 if (p_GetComputerNameA == NULL)
50 {
51 xprintf("GetProcAddress failed: %d\n", GetLastError());
52 }
53 else
54 {
55 ZeroMemory(buf, sizeof(buf));
56 dwSize = sizeof(buf);
57 if (!p_GetComputerNameA(buf, &dwSize))
58 {
59 xprintf("p_GetComputerNameA failed: %d\n", GetLastError());
60 }
61 else
62 {
63 xprintf("p_GetComputerNameA returned: '%s'\n", buf);
64 }
65 }
66}
67
70{
71 GUID guid = { 0x11223344, 0x5566, 0x7788 };
72 char buf[100];
73 int r;
75 INT (WINAPI *p_SHStringFromGUIDA)(REFGUID guid, LPSTR lpszDest, INT cchMax);
76
77 /* Call it directly */
78 ZeroMemory(buf, sizeof(buf));
80 if (r)
81 {
82 xprintf("SHStringFromGUIDA failed (%d)\n", r);
83 }
84 else
85 {
86 xprintf("SHStringFromGUIDA returned: '%s'\n", buf);
87 }
88
89 /* Call it using GetProcAddress */
90 mod = GetModuleHandleA("shlwapi.dll");
91 p_SHStringFromGUIDA = (void*)GetProcAddress(mod, (LPCSTR)23);
92 if (p_SHStringFromGUIDA == NULL)
93 {
94 xprintf("GetProcAddress failed: %d\n", GetLastError());
95 }
96 else
97 {
98 ZeroMemory(buf, sizeof(buf));
99 r = p_SHStringFromGUIDA(&guid, buf, _countof(buf)-1);
100 if (r)
101 {
102 xprintf("p_SHStringFromGUIDA failed (%d)\n", r);
103 }
104 else
105 {
106 xprintf("p_SHStringFromGUIDA returned: '%s'\n", buf);
107 }
108 }
109}
110
111
112int main(int argc, char* argv[])
113{
114 xprintf("Normal import (kernel32!GetComputerNameA)\n");
116 xprintf("\nOrdinal import (shlwapi!#23)\n");
118
119 return 0;
120}
static int argc
Definition: ServiceArgs.c:12
UINT cchMax
WCHAR lpszDest[260]
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1281
#define NTSYSAPI
Definition: ntoskrnl.h:12
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
int main()
Definition: test.c:6
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static int mod
Definition: i386-dis.c:1288
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
const GUID * guid
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define argv
Definition: mplay32.c:18
#define _In_z_
Definition: ms_sal.h:313
#define _In_
Definition: ms_sal.h:308
#define BOOL
Definition: nt_native.h:43
CONST CHAR * PCCH
Definition: ntbasedef.h:392
#define INT
Definition: polytest.cpp:20
static LPSTR PULONG lpnSize
Definition: secur32.c:50
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
void test_normal_imports()
Definition: shimtest_ros.c:27
void xprintf(const char *fmt,...)
Definition: shimtest_ros.c:17
NTSYSAPI ULONG NTAPI vDbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ PCCH Format, _In_ va_list ap)
INT WINAPI SHStringFromGUIDA(REFGUID, LPSTR, INT)
Definition: shimtest.c:51
#define DPFLTR_ERROR_LEVEL
Definition: shimtest_ros.c:15
void test_ordinal_imports()
Definition: shimtest_ros.c:69
#define _countof(array)
Definition: sndvol32.h:70
Definition: scsiwmi.h:51
Definition: dsound.c:943
#define NTAPI
Definition: typedefs.h:36
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182