ReactOS 0.4.15-dev-7085-g12a5971
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)
 Queries information details about a security descriptor.
 

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  )

Queries information details about a security descriptor.

Computes the quota size of a security descriptor.

Assigns a security descriptor for a new object.

An extended function that assigns a security descriptor for a new object.

Frees a security descriptor.

An extended function that sets new information data to a security descriptor.

Modifies some information data about a security descriptor.

Parameters
[in]SecurityInformationSecurity information details to be queried from a security descriptor.
[out]SecurityDescriptorThe returned security descriptor with security information data.
[in,out]LengthThe returned length of a security descriptor.
[in,out]ObjectsSecurityDescriptorThe returned object security descriptor.
Returns
Returns STATUS_SUCCESS if the operations have been completed successfully and that the specific information about the security descriptor has been queried. STATUS_BUFFER_TOO_SMALL is returned if the buffer size is too small to contain the queried info about the security descriptor.
Parameters
[in]ObjectIf specified, the function will use this arbitrary object that points to an object security descriptor.
[in]SecurityInformationSecurity information details to be set.
[in]SecurityDescriptorA security descriptor where its info is to be changed.
[in,out]ObjectsSecurityDescriptorThe returned pointer to security descriptor objects.
[in]PoolTypePool type for the new security descriptor to allocate.
[in]GenericMappingThe generic mapping of access rights masks.
Returns
See SeSetSecurityDescriptorInfoEx.
Parameters
[in]ObjectIf specified, the function will use this arbitrary object that points to an object security descriptor.
[in]SecurityInformationSecurity information details to be set.
[in]SecurityDescriptorA security descriptor where its info is to be changed.
[in,out]ObjectsSecurityDescriptorThe returned pointer to security descriptor objects.
[in]AutoInheritFlagsFlags bitmask inheritation, influencing how the security descriptor can be inherited and if it can be in the first place.
[in]PoolTypePool type for the new security descriptor to allocate.
[in]GenericMappingThe generic mapping of access rights masks.
Returns
Returns STATUS_SUCCESS if the operations have been completed without problems and that new info has been set to the security descriptor. STATUS_NO_SECURITY_ON_OBJECT is returned if the object does not have a security descriptor. STATUS_INSUFFICIENT_RESOURCES is returned if memory pool allocation for the new security descriptor with new info set has failed.
Parameters
[in]SecurityDescriptorA security descriptor to be freed from memory.
Returns
Returns STATUS_SUCCESS.
Parameters
[in]_ParentDescriptorA security descriptor of the parent object that is being created.
[in]_ExplicitDescriptorAn explicit security descriptor that is applied to a new object.
[out]NewDescriptorThe new allocated security descriptor.
[in]ObjectTypeThe type of the new object.
[in]IsDirectoryObjectSet this to TRUE if the newly created object is a directory object, otherwise set this to FALSE.
[in]AutoInheritFlagsAutomatic inheritance flags that influence how access control entries within ACLs from security descriptors are inherited.
[in]SubjectContextSecurity subject context of the new object.
[in]GenericMappingGeneric mapping of access mask rights.
[in]PoolTypeThis parameter is unused.
Returns
Returns STATUS_SUCCESS if the operations have been completed successfully and that the security descriptor has been assigned to the new object. STATUS_NO_TOKEN is returned if the caller hasn't supplied a valid argument to a security subject context. STATUS_INVALID_OWNER is returned if the caller hasn't supplied a parent descriptor that belongs to the main user (owner). STATUS_INVALID_PRIMARY_GROUP is returned by the same reason as with the previous NTSTATUS code. The two NTSTATUS codes are returned if the calling thread stated that the owner and/or group is defaulted to the parent descriptor (SEF_DEFAULT_OWNER_FROM_PARENT and/or SEF_DEFAULT_GROUP_FROM_PARENT respectively). STATUS_INSUFFICIENT_RESOURCES is returned if memory pool allocation for the descriptor buffer has failed. A failure NTSTATUS is returned otherwise.
Parameters
[in]ParentDescriptorA security descriptor of the parent object that is being created.
[in]ExplicitDescriptorAn explicit security descriptor that is applied to a new object.
[out]NewDescriptorThe new allocated security descriptor.
[in]IsDirectoryObjectSet this to TRUE if the newly created object is a directory object, otherwise set this to FALSE.
[in]SubjectContextSecurity subject context of the new object.
[in]GenericMappingGeneric mapping of access mask rights.
[in]PoolTypeThis parameter is unused.
Returns
See SeAssignSecurityEx.
Parameters
[in]SecurityDescriptorA security descriptor.
[out]QuotaInfoSizeThe returned quota size of the given security descriptor to the caller. The function may return 0 to this parameter if the descriptor doesn't have a group or a discretionary access control list (DACL) even.
Returns
Returns STATUS_SUCCESS if the quota size of a security descriptor has been computed successfully. STATUS_UNKNOWN_REVISION is returned if the security descriptor has an invalid revision.

Definition at line 203 of file aux_klib.c.

212{
214}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

◆ 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}
static tBugCheckData BugCheckData
ULONG_PTR KiBugCheckData[5]
Definition: bug.c:31
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

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
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
GLsizeiptr size
Definition: glext.h:5919
uint32_t ULONG
Definition: typedefs.h:59

◆ 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
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}
#define PAGED_CODE()
#define InterlockedExchange
Definition: armddk.h:54
LONG gKlibInitialized
Definition: aux_klib.c:20
PFN_RTLQUERYMODULEINFORMATION pfnRtlQueryModuleInformation
Definition: aux_klib.c:19
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define L(x)
Definition: ntvdm.h:50
ULONG dwMajorVersion
Definition: rtltypes.h:247
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3601
#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 {
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}
unsigned int UINT32
#define TAG_AUXK
Definition: aux_klib.c:15
_In_ ULONG SizePerModule
Definition: aux_klib.h:64
_In_ ULONG _Out_writes_bytes_opt_ InformationLength PAUX_MODULE_EXTENDED_INFO ModuleInfo
Definition: aux_klib.h:65
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR Cleanup[]
Definition: register.c:80
#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
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 TYPE_ALIGNMENT(t)
Definition: ntbasedef.h:117
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#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_BUFFER_TOO_SMALL
Definition: shellext.h:69
AUX_MODULE_BASIC_INFO BasicInfo
Definition: aux_klib.h:38
RTL_PROCESS_MODULE_INFORMATION Modules[1]
Definition: rtltypes.h:1018
Definition: ps.c:97
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ExAllocatePoolWithQuotaTag(a, b, c)
Definition: exfuncs.h:530

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().