ReactOS  0.4.13-dev-66-gc714b7f
psapi.c File Reference
#include <apitest.h>
#include <psapi.h>
#include <tlhelp32.h>
#include <stdio.h>
Include dependency graph for psapi.c:

Go to the source code of this file.

Classes

struct  TEST_MODULE_INFO
 

Functions

static LPVOID IntGetImageBase (LPCSTR Image)
 
static BOOLEAN IntGetModuleInformation (LPCSTR Module, BOOLEAN IsDriver, BOOLEAN IsProcMod, BOOLEAN BaseName, TEST_MODULE_INFO *Info)
 
 START_TEST (GetDeviceDriverFileName)
 
 START_TEST (GetDeviceDriverBaseName)
 

Function Documentation

◆ IntGetImageBase()

static LPVOID IntGetImageBase ( LPCSTR  Image)
static

Definition at line 20 of file psapi.c.

21 {
22  HANDLE Snap;
23  MODULEENTRY32 Module;
24 
26  if (Snap == INVALID_HANDLE_VALUE)
27  {
28  return NULL;
29  }
30 
31  Module.dwSize = sizeof(MODULEENTRY32);
32  if(!Module32First(Snap, &Module))
33  {
34  CloseHandle(Snap);
35  return NULL;
36  }
37 
38  do
39  {
40  if (lstrcmpiA(Module.szExePath, Image) == 0)
41  {
42  CloseHandle(Snap);
43  return (LPVOID)Module.modBaseAddr;
44  }
45  } while(Module32Next(Snap, &Module));
46 
47  CloseHandle(Snap);
48  return NULL;
49 }
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI Module32Next(HANDLE hSnapshot, LPMODULEENTRY32 lpme)
Definition: toolhelp.c:864
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
char szExePath[MAX_PATH]
Definition: tlhelp32.h:103
BYTE * modBaseAddr
Definition: tlhelp32.h:99
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
struct tagMODULEENTRY32 MODULEENTRY32
#define TH32CS_SNAPMODULE
Definition: tlhelp32.h:28
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI Module32First(HANDLE hSnapshot, LPMODULEENTRY32 lpme)
Definition: toolhelp.c:777
HANDLE WINAPI CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID)
Definition: toolhelp.c:1255

Referenced by IntGetModuleInformation().

◆ IntGetModuleInformation()

static BOOLEAN IntGetModuleInformation ( LPCSTR  Module,
BOOLEAN  IsDriver,
BOOLEAN  IsProcMod,
BOOLEAN  BaseName,
TEST_MODULE_INFO Info 
)
static

Definition at line 51 of file psapi.c.

52 {
53  CHAR System[255];
54  UINT Len;
55 
56  memset(Info, 0, sizeof(TEST_MODULE_INFO));
57 
58  /* Get system path */
59  Len = GetSystemWindowsDirectory(System, 255);
60  if (Len > 255 || Len == 0)
61  {
62  printf("GetSystemWindowsDirectory failed\n");
63  return FALSE;
64  }
65 
66  /* Make path to module */
67  strcat(System, "\\system32\\");
68  if (IsDriver) strcat(System, "drivers\\");
69  strcat(System, Module);
70 
71  /* Get base address */
72  if (IsProcMod)
73  {
74  Info->ImageBase = IntGetImageBase(System);
75  if (!Info->ImageBase)
76  {
77  printf("IntGetImageBase failed\n");
78  return FALSE;
79  }
80  }
81  else
82  {
83  /* FIXME */
84  printf("Not supported yet!\n");
85  return FALSE;
86  }
87 
88  if (BaseName)
89  {
90  strcpy(Info->Path, Module);
91  Info->Len = strlen(Info->Path);
92  }
93  else
94  {
95  /* Skip disk */
96  strcpy(Info->Path, System + 2);
97  Info->Len = strlen(Info->Path);
98  }
99 
100  return TRUE;
101 }
#define TRUE
Definition: types.h:120
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
static LPVOID IntGetImageBase(LPCSTR Image)
Definition: psapi.c:20
struct TraceInfo Info
#define Len
Definition: deflate.h:82
unsigned int UINT
Definition: ndis.h:50
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define memset(x, y, z)
Definition: compat.h:39
#define printf
Definition: config.h:203

Referenced by START_TEST().

◆ START_TEST() [1/2]

START_TEST ( GetDeviceDriverFileName  )

Definition at line 103 of file psapi.c.

104 {
105  DWORD Len;
106  CHAR FileName[255];
107  TEST_MODULE_INFO ModInfo;
108 
109  SetLastError(0xDEADBEEF);
111  ok(Len == 0, "Len: %lu\n", Len);
112  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
113 
114  if (IntGetModuleInformation("ntdll.dll", FALSE, TRUE, FALSE, &ModInfo))
115  {
116  SetLastError(0xDEADBEEF);
118  ok(Len == ModInfo.Len, "Len: %lu\n", Len);
119  ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
120  ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n", FileName);
121 
122  /* Test with too small buffer */
123  SetLastError(0xDEADBEEF);
124  ModInfo.Len--;
125  ModInfo.Path[ModInfo.Len] = 0;
126  FileName[ModInfo.Len] = 0;
127  Len = GetDeviceDriverFileNameA(ModInfo.ImageBase, FileName, ModInfo.Len);
128  ok(Len == ModInfo.Len, "Len: %lu\n", Len);
129  ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
130  ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n", FileName);
131  }
132  else
133  {
134  skip("Couldn't find info about ntdll.dll\n");
135  }
136 
137  if (IntGetModuleInformation("msvcrt.dll", FALSE, TRUE, FALSE, &ModInfo))
138  {
139  SetLastError(0xDEADBEEF);
141  ok(Len == 0, "Len: %lu\n", Len);
142  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
143  }
144  else
145  {
146  skip("Couldn't find info about msvcrt.dll\n");
147  }
148 
149  if (IntGetModuleInformation("psapi.dll", FALSE, TRUE, FALSE, &ModInfo))
150  {
151  SetLastError(0xDEADBEEF);
153  ok(Len == 0, "Len: %lu\n", Len);
154  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
155  }
156  else
157  {
158  skip("Couldn't find info about psapi.dll\n");
159  }
160 }
#define TRUE
Definition: types.h:120
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
char CHAR
Definition: xmlstorage.h:175
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
Definition: psapi.c:684
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD Len
Definition: psapi.c:17
#define ok(value,...)
LPVOID ImageBase
Definition: psapi.c:15
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:409
static BOOLEAN IntGetModuleInformation(LPCSTR Module, BOOLEAN IsDriver, BOOLEAN IsProcMod, BOOLEAN BaseName, TEST_MODULE_INFO *Info)
Definition: psapi.c:51
#define skip(...)
CHAR Path[255]
Definition: psapi.c:16

◆ START_TEST() [2/2]

START_TEST ( GetDeviceDriverBaseName  )

Definition at line 162 of file psapi.c.

163 {
164  DWORD Len;
165  CHAR FileName[255];
166  TEST_MODULE_INFO ModInfo;
167 
168  SetLastError(0xDEADBEEF);
170  ok(Len == 0, "Len: %lu\n", Len);
171  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
172 
173  if (IntGetModuleInformation("ntdll.dll", FALSE, TRUE, TRUE, &ModInfo))
174  {
175  SetLastError(0xDEADBEEF);
177  ok(Len == ModInfo.Len, "Len: %lu\n", Len);
178  ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
179  ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n", FileName);
180 
181  /* Test with too small buffer */
182  SetLastError(0xDEADBEEF);
183  ModInfo.Len--;
184  ModInfo.Path[ModInfo.Len] = 0;
185  FileName[ModInfo.Len] = 0;
186  Len = GetDeviceDriverBaseNameA(ModInfo.ImageBase, FileName, ModInfo.Len);
187  ok(Len == ModInfo.Len, "Len: %lu\n", Len);
188  ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
189  ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n", FileName);
190  }
191  else
192  {
193  skip("Couldn't find info about ntdll.dll\n");
194  }
195 
196  if (IntGetModuleInformation("msvcrt.dll", FALSE, TRUE, TRUE, &ModInfo))
197  {
198  SetLastError(0xDEADBEEF);
200  ok(Len == 0, "Len: %lu\n", Len);
201  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
202  }
203  else
204  {
205  skip("Couldn't find info about msvcrt.dll\n");
206  }
207 
208  if (IntGetModuleInformation("psapi.dll", FALSE, TRUE, TRUE, &ModInfo))
209  {
210  SetLastError(0xDEADBEEF);
212  ok(Len == 0, "Len: %lu\n", Len);
213  ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n", GetLastError());
214  }
215  else
216  {
217  skip("Couldn't find info about psapi.dll\n");
218  }
219 }
#define TRUE
Definition: types.h:120
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
DWORD WINAPI GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
Definition: psapi.c:645
char CHAR
Definition: xmlstorage.h:175
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD Len
Definition: psapi.c:17
#define ok(value,...)
LPVOID ImageBase
Definition: psapi.c:15
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:409
static BOOLEAN IntGetModuleInformation(LPCSTR Module, BOOLEAN IsDriver, BOOLEAN IsProcMod, BOOLEAN BaseName, TEST_MODULE_INFO *Info)
Definition: psapi.c:51
#define skip(...)
CHAR Path[255]
Definition: psapi.c:16