00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "mi.h"
00024
00025
#ifdef ALLOC_PRAGMA
00026
#pragma alloc_text(PAGE,NtQuerySection)
00027
#endif
00028
00029
00030
NTSTATUS
00031 NtQuerySection(
00032 IN HANDLE SectionHandle,
00033 IN SECTION_INFORMATION_CLASS SectionInformationClass,
00034 OUT PVOID SectionInformation,
00035 IN ULONG SectionInformationLength,
00036 OUT PULONG ReturnLength OPTIONAL
00037 )
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 {
00110
PSECTION Section;
00111
KPROCESSOR_MODE PreviousMode;
00112
NTSTATUS Status;
00113
00114
PAGED_CODE();
00115
00116
00117
00118
00119
00120 PreviousMode = KeGetPreviousMode();
00121
if (PreviousMode !=
KernelMode) {
00122
00123
00124
00125
00126
00127
try {
00128
00129
ProbeForWrite(SectionInformation,
00130 SectionInformationLength,
00131
sizeof(ULONG));
00132
00133
if (ARGUMENT_PRESENT (ReturnLength)) {
00134
ProbeForWriteUlong(ReturnLength);
00135 }
00136
00137 } except (
EXCEPTION_EXECUTE_HANDLER) {
00138
00139
00140
00141
00142
00143
00144
00145
return GetExceptionCode();
00146 }
00147 }
00148
00149
00150
00151
00152
00153
if ((SectionInformationClass != SectionBasicInformation) &&
00154 (SectionInformationClass != SectionImageInformation)) {
00155
return STATUS_INVALID_INFO_CLASS;
00156 }
00157
00158
if (SectionInformationClass == SectionBasicInformation) {
00159
if (SectionInformationLength < (ULONG)
sizeof(SECTION_BASIC_INFORMATION)) {
00160
return STATUS_INFO_LENGTH_MISMATCH;
00161 }
00162 }
else {
00163
if (SectionInformationLength < (ULONG)
sizeof(SECTION_IMAGE_INFORMATION)) {
00164
return STATUS_INFO_LENGTH_MISMATCH;
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
Status =
ObReferenceObjectByHandle(SectionHandle, SECTION_QUERY,
00176
MmSectionObjectType,
00177 PreviousMode, (PVOID *)&Section,
NULL);
00178
00179
if (
NT_SUCCESS(
Status)) {
00180
00181
try {
00182
00183
if (SectionInformationClass == SectionBasicInformation) {
00184 ((PSECTION_BASIC_INFORMATION)SectionInformation)->BaseAddress =
00185 (PVOID)Section->Address.StartingVpn;
00186
00187 ((PSECTION_BASIC_INFORMATION)SectionInformation)->MaximumSize =
00188 Section->SizeOfSection;
00189
00190 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes =
00191 0;
00192
00193
if (Section->u.Flags.Image) {
00194 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes =
00195 SEC_IMAGE;
00196 }
00197
if (Section->u.Flags.Based) {
00198 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00199 SEC_BASED;
00200 }
00201
if (Section->u.Flags.File) {
00202 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00203 SEC_FILE;
00204 }
00205
if (Section->u.Flags.NoCache) {
00206 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00207 SEC_NOCACHE;
00208 }
00209
if (Section->u.Flags.Reserve) {
00210 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00211 SEC_RESERVE;
00212 }
00213
if (Section->u.Flags.Commit) {
00214 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00215 SEC_COMMIT;
00216 }
00217
if (Section->Segment->ControlArea->u.Flags.GlobalMemory) {
00218 ((PSECTION_BASIC_INFORMATION)SectionInformation)->AllocationAttributes |=
00219 SEC_GLOBAL;
00220 }
00221
00222
if (ARGUMENT_PRESENT(ReturnLength)) {
00223 *ReturnLength =
sizeof(SECTION_BASIC_INFORMATION);
00224 }
00225
00226 }
else {
00227
00228
if (Section->u.Flags.Image == 0) {
00229
Status = STATUS_SECTION_NOT_IMAGE;
00230 }
00231
else {
00232 *((PSECTION_IMAGE_INFORMATION)SectionInformation) =
00233 *Section->Segment->ImageInformation;
00234
00235
if (ARGUMENT_PRESENT(ReturnLength)) {
00236 *ReturnLength =
sizeof(SECTION_IMAGE_INFORMATION);
00237 }
00238 }
00239 }
00240
00241 } except (
EXCEPTION_EXECUTE_HANDLER) {
00242
00243 }
00244
00245
ObDereferenceObject ((PVOID)Section);
00246 }
00247
return Status;
00248 }