ReactOS  0.4.15-dev-2993-g14fbe80
aux_klib.c File Reference
#include <ntifs.h>
#include <ntintsafe.h>
#include <ndk/ntndk.h>
#include <pseh/pseh2.h>
#include <aux_klib.h>
Include dependency graph for aux_klib.c:

Go to the source code of this file.

Macros

#define TAG_AUXK   'AuxK'
 

Typedefs

typedef NTSTATUS(NTAPIPFN_RTLQUERYMODULEINFORMATION) (PULONG, ULONG, PVOID)
 

Functions

NTSTATUS NTAPI AuxKlibInitialize (VOID)
 
NTSTATUS NTAPI AuxKlibQueryModuleInformation (_In_ PULONG InformationLength, _In_ ULONG SizePerModule, _Inout_ PAUX_MODULE_EXTENDED_INFO ModuleInfo)
 
NTSTATUS AuxKlibGetBugCheckData (_Inout_ PKBUGCHECK_DATA BugCheckData)
 
PIMAGE_EXPORT_DIRECTORY AuxKlibGetImageExportDirectory (_In_ PVOID ImageBase)
 
 _IRQL_requires_max_ (PASSIVE_LEVEL)
 

Variables

PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation
 
LONG gKlibInitialized = 0
 

Macro Definition Documentation

◆ TAG_AUXK

#define TAG_AUXK   'AuxK'

Definition at line 15 of file aux_klib.c.

Typedef Documentation

◆ PFN_RTLQUERYMODULEINFORMATION

typedef NTSTATUS(NTAPI * PFN_RTLQUERYMODULEINFORMATION) (PULONG, ULONG, PVOID)

Definition at line 17 of file aux_klib.c.

Function Documentation

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 203 of file aux_klib.c.

212 {
213  return STATUS_NOT_IMPLEMENTED;
214 }
return STATUS_NOT_IMPLEMENTED

◆ AuxKlibGetBugCheckData()

NTSTATUS AuxKlibGetBugCheckData ( _Inout_ PKBUGCHECK_DATA  BugCheckData)

Definition at line 178 of file aux_klib.c.

180 {
181  if (BugCheckData->BugCheckDataSize != sizeof(*BugCheckData))
182  {
184  }
185 
186  BugCheckData->BugCheckCode = KiBugCheckData[0];
187  BugCheckData->Parameter1 = KiBugCheckData[1];
188  BugCheckData->Parameter2 = KiBugCheckData[2];
189  BugCheckData->Parameter3 = KiBugCheckData[3];
190  BugCheckData->Parameter4 = KiBugCheckData[4];
191 
192  return STATUS_SUCCESS;
193 }
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
ULONG_PTR KiBugCheckData[5]
Definition: bug.c:27
static tBugCheckData BugCheckData
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by FxpBugCheckCallbackFilter().

◆ AuxKlibGetImageExportDirectory()

PIMAGE_EXPORT_DIRECTORY AuxKlibGetImageExportDirectory ( _In_ PVOID  ImageBase)

Definition at line 196 of file aux_klib.c.

198 {
199  ULONG size;
201 }
#define TRUE
Definition: types.h:120
GLsizeiptr size
Definition: glext.h:5919
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
unsigned int ULONG
Definition: retypes.h:1

◆ AuxKlibInitialize()

NTSTATUS NTAPI AuxKlibInitialize ( VOID  )

Definition at line 26 of file aux_klib.c.

27 {
28  RTL_OSVERSIONINFOW osVersion;
29  UNICODE_STRING strRtlQueryModuleInformation = RTL_CONSTANT_STRING(L"RtlQueryModuleInformation");
30 
31  PAGED_CODE();
32 
33  if (!gKlibInitialized)
34  {
35  RtlGetVersion(&osVersion);
36  if (osVersion.dwMajorVersion >= 5)
37  {
38  pfnRtlQueryModuleInformation = MmGetSystemRoutineAddress(&strRtlQueryModuleInformation);
40  }
41  else
42  {
43  return STATUS_NOT_SUPPORTED;
44  }
45  }
46 
47  return STATUS_SUCCESS;
48 }
LONG gKlibInitialized
Definition: aux_klib.c:20
return STATUS_NOT_SUPPORTED
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation
Definition: aux_klib.c:19
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3514
ULONG dwMajorVersion
Definition: rtltypes.h:247
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedExchange
Definition: armddk.h:54
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by FxpGetImageBase().

◆ AuxKlibQueryModuleInformation()

NTSTATUS NTAPI AuxKlibQueryModuleInformation ( _In_ PULONG  InformationLength,
_In_ ULONG  SizePerModule,
_Inout_ PAUX_MODULE_EXTENDED_INFO  ModuleInfo 
)

Definition at line 53 of file aux_klib.c.

57 {
59 
60  PAGED_CODE();
61 
62  if (gKlibInitialized != 1)
63  {
64  return STATUS_UNSUCCESSFUL;
65  }
66 
67  // if we have the function exported from the kernel, use it
69  {
70  return pfnRtlQueryModuleInformation(InformationLength, SizePerModule, ModuleInfo);
71  }
72 
73  if (SizePerModule != sizeof(AUX_MODULE_BASIC_INFO) &&
75  {
77  }
78 
80  {
82  }
83 
84  // first call the function with a place for only 1 module
85  RTL_PROCESS_MODULES processModulesMinimal;
86  PRTL_PROCESS_MODULES processModules = &processModulesMinimal;
87  ULONG sysInfoLength = sizeof(processModulesMinimal);
88  ULONG resultLength;
89 
90  // loop until we have a large-enough buffer for all modules
91  do
92  {
94  processModules,
95  sysInfoLength,
96  &resultLength);
97 
99  {
100  // free the old buffer if it's not the first one
101  if (processModules != &processModulesMinimal)
102  {
103  ExFreePoolWithTag(processModules, TAG_AUXK);
104  }
105 
106  _SEH2_TRY
107  {
108  // allocate the new one
109  processModules = ExAllocatePoolWithQuotaTag(PagedPool, resultLength, TAG_AUXK);
110  }
112  {
114  }
115  _SEH2_END;
116 
117  if (!processModules)
118  {
120  }
121  sysInfoLength = resultLength;
122  }
123 
124  } while (status == STATUS_INFO_LENGTH_MISMATCH);
125 
126  if (!NT_SUCCESS(status))
127  {
128  goto Cleanup;
129  }
130 
131  ULONG modulesSize;
132  status = RtlULongMult(SizePerModule, processModules->NumberOfModules, &modulesSize);
133  if (!NT_SUCCESS(status))
134  {
135  goto Cleanup;
136  }
137 
138  if (ModuleInfo == NULL)
139  {
141  *InformationLength = modulesSize;
142  goto Cleanup;
143  }
144 
145  if (*InformationLength < modulesSize)
146  {
148  *InformationLength = modulesSize;
149  goto Cleanup;
150  }
151 
152  // copy the information to the input array
153  for (UINT32 i = 0; i < processModules->NumberOfModules; i++)
154  {
155  ModuleInfo[i].BasicInfo.ImageBase = processModules->Modules[i].ImageBase;
156 
158  {
159  ModuleInfo[i].ImageSize = processModules->Modules[i].ImageSize;
160  ModuleInfo[i].FileNameOffset = processModules->Modules[i].OffsetToFileName;
161  RtlCopyMemory(&ModuleInfo[i].FullPathName,
162  processModules->Modules[i].FullPathName,
163  sizeof(processModules->Modules[i].FullPathName));
164  }
165  }
166 
167 Cleanup:
168  // don't accidentally free the stack buffer
169  if (processModules != NULL && processModules != &processModulesMinimal)
170  {
171  ExFreePoolWithTag(processModules, TAG_AUXK);
172  }
173 
174  return status;
175 }
LONG gKlibInitialized
Definition: aux_klib.c:20
#define TYPE_ALIGNMENT(t)
Definition: ntbasedef.h:117
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID NTAPI ExAllocatePoolWithQuotaTag(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
Definition: expool.c:2984
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation
Definition: aux_klib.c:19
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
unsigned int UINT32
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
_In_ ULONG _Out_writes_bytes_opt_ InformationLength PAUX_MODULE_EXTENDED_INFO ModuleInfo
Definition: aux_klib.h:65
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TAG_AUXK
Definition: aux_klib.c:15
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR Cleanup[]
Definition: register.c:80
_In_ ULONG SizePerModule
Definition: aux_klib.h:64
_SEH2_END
Definition: create.c:4400
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
AUX_MODULE_BASIC_INFO BasicInfo
Definition: aux_klib.h:38
unsigned int ULONG
Definition: retypes.h:1
RTL_PROCESS_MODULE_INFORMATION Modules[1]
Definition: rtltypes.h:1016
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by FxpGetImageBase().

Variable Documentation

◆ gKlibInitialized

LONG gKlibInitialized = 0

Definition at line 20 of file aux_klib.c.

Referenced by AuxKlibInitialize(), and AuxKlibQueryModuleInformation().

◆ pfnRtlQueryModuleInformation

PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation

Definition at line 19 of file aux_klib.c.

Referenced by AuxKlibInitialize(), and AuxKlibQueryModuleInformation().