ReactOS  0.4.14-dev-98-gb0d4763
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 
17 void 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];
30  DWORD dwSize;
31  HMODULE mod;
32  BOOL (WINAPI *p_GetComputerNameA)(LPSTR lpBuffer, LPDWORD lpnSize);
33 
34  /* Call it directly */
35  ZeroMemory(buf, sizeof(buf));
36  dwSize = sizeof(buf);
37  if (!GetComputerNameA(buf, &dwSize))
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;
74  HMODULE mod;
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 
112 int 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 }
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
static int argc
Definition: ServiceArgs.c:12
INT WINAPI SHStringFromGUIDA(REFGUID, LPSTR, INT)
Definition: shimtest.c:51
Definition: scsiwmi.h:51
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
NTSYSAPI ULONG NTAPI vDbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ PCCH Format, _In_ va_list ap)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define _countof(array)
Definition: fontsub.cpp:30
#define INT
Definition: polytest.cpp:20
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
void test_normal_imports()
Definition: shimtest_ros.c:27
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
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:1264
#define argv
Definition: mplay32.c:18
char * LPSTR
Definition: xmlstorage.h:182
#define BOOL
Definition: nt_native.h:43
#define NTSYSAPI
Definition: ntoskrnl.h:14
int32_t INT
Definition: typedefs.h:56
const GUID * guid
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define va_end(ap)
Definition: acmsvcex.h:90
static LPSTR PULONG lpnSize
Definition: secur32.c:50
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
WCHAR lpszDest[260]
char * va_list
Definition: acmsvcex.h:78
const char * LPCSTR
Definition: xmlstorage.h:183
void xprintf(const char *fmt,...)
Definition: shimtest_ros.c:17
CONST CHAR * PCCH
Definition: ntbasedef.h:399
int main(int argc, char *argv[])
Definition: shimtest_ros.c:112
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT cchMax
#define DPFLTR_ERROR_LEVEL
Definition: shimtest_ros.c:15
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define _In_
Definition: no_sal2.h:204
#define _In_z_
Definition: no_sal2.h:239
#define va_start(ap, A)
Definition: acmsvcex.h:91
void test_ordinal_imports()
Definition: shimtest_ros.c:69
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
uint32_t * LPDWORD
Definition: typedefs.h:57
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:410
Definition: dsound.c:943
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
static int mod
Definition: i386-dis.c:1273