ReactOS  0.4.15-dev-3295-gaa8fc87
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. More...
 

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