ReactOS 0.4.15-dev-7961-gdcf9eb0
aux_klib.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS SDK: Auxiliary Kernel-Mode Library
3 * LICENSE: BSD-2-Clause-Views (https://spdx.org/licenses/BSD-2-Clause-Views)
4 * PURPOSE: Main source file
5 * COPYRIGHT: Copyright 2019-2020 Max Korostil <mrmks04@yandex.ru>
6 * Copyright 2021 Victor Perevertkin <victor.perevertkin@reactos.org>
7 */
8
9#include <ntifs.h>
10#include <ntintsafe.h>
11#include <ndk/ntndk.h>
12#include <pseh/pseh2.h>
13#include <aux_klib.h>
14
15#define TAG_AUXK 'AuxK'
16
18
21
22
23CODE_SEG("PAGE")
27{
28 RTL_OSVERSIONINFOW osVersion;
29 UNICODE_STRING strRtlQueryModuleInformation = RTL_CONSTANT_STRING(L"RtlQueryModuleInformation");
30
31 PAGED_CODE();
32
34 {
35 RtlGetVersion(&osVersion);
36 if (osVersion.dwMajorVersion >= 5)
37 {
38 pfnRtlQueryModuleInformation = MmGetSystemRoutineAddress(&strRtlQueryModuleInformation);
40 }
41 else
42 {
44 }
45 }
46
47 return STATUS_SUCCESS;
48}
49
50CODE_SEG("PAGE")
54 _In_ PULONG InformationLength,
57{
59
60 PAGED_CODE();
61
62 if (gKlibInitialized != 1)
63 {
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
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
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;
161 RtlCopyMemory(&ModuleInfo[i].FullPathName,
162 processModules->Modules[i].FullPathName,
163 sizeof(processModules->Modules[i].FullPathName));
164 }
165 }
166
167Cleanup:
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}
176
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}
194
197 _In_ PVOID ImageBase)
198{
199 ULONG size;
201}
202
204CODE_SEG("PAGE")
206NTAPI
207AuxKlibEnumerateSystemFirmwareTables (
208 _In_ ULONG FirmwareTableProviderSignature,
212{
214}
215
217CODE_SEG("PAGE")
219NTAPI
220AuxKlibGetSystemFirmwareTable (
221 _In_ ULONG FirmwareTableProviderSignature,
226{
228}
#define PAGED_CODE()
#define CODE_SEG(...)
static tBugCheckData BugCheckData
unsigned int UINT32
#define InterlockedExchange
Definition: armddk.h:54
PIMAGE_EXPORT_DIRECTORY AuxKlibGetImageExportDirectory(_In_ PVOID ImageBase)
Definition: aux_klib.c:196
NTSTATUS NTAPI AuxKlibInitialize(VOID)
Definition: aux_klib.c:26
#define TAG_AUXK
Definition: aux_klib.c:15
NTSTATUS AuxKlibGetBugCheckData(_Inout_ PKBUGCHECK_DATA BugCheckData)
Definition: aux_klib.c:178
NTSTATUS(NTAPI * PFN_RTLQUERYMODULEINFORMATION)(PULONG, ULONG, PVOID)
Definition: aux_klib.c:17
NTSTATUS NTAPI AuxKlibQueryModuleInformation(_In_ PULONG InformationLength, _In_ ULONG SizePerModule, _Inout_ PAUX_MODULE_EXTENDED_INFO ModuleInfo)
Definition: aux_klib.c:53
LONG gKlibInitialized
Definition: aux_klib.c:20
PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation
Definition: aux_klib.c:19
_In_ ULONG SizePerModule
Definition: aux_klib.h:64
_In_ ULONG FirmwareTableID
Definition: aux_klib.h:91
_In_ ULONG _Out_writes_bytes_opt_ InformationLength PAUX_MODULE_EXTENDED_INFO ModuleInfo
Definition: aux_klib.h:65
LONG NTSTATUS
Definition: precomp.h:26
ULONG_PTR KiBugCheckData[5]
Definition: bug.c:31
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define NTSTATUS
Definition: precomp.h:21
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
static const WCHAR Cleanup[]
Definition: register.c:80
#define _IRQL_requires_max_(irql)
Definition: driverspecs.h:230
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PagedPool
Definition: env_spec_w32.h:308
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
@ SystemModuleInformation
Definition: ntddk_ex.h:22
GLsizeiptr size
Definition: glext.h:5919
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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define _Out_opt_
Definition: ms_sal.h:346
#define _Inout_
Definition: ms_sal.h:378
#define _Out_writes_bytes_to_opt_(size, count)
Definition: ms_sal.h:361
#define _In_
Definition: ms_sal.h:308
#define TYPE_ALIGNMENT(t)
Definition: ntbasedef.h:117
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
AUX_MODULE_BASIC_INFO BasicInfo
Definition: aux_klib.h:38
ULONG dwMajorVersion
Definition: rtltypes.h:247
RTL_PROCESS_MODULE_INFORMATION Modules[1]
Definition: rtltypes.h:1018
Definition: ps.c:97
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3604
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
#define ExAllocatePoolWithQuotaTag(a, b, c)
Definition: exfuncs.h:530