00041 :
00042
00043 This function returns information about an opened section object.
00044 This function provides
the capability to determine
the base address,
00045 size, granted access, and allocation of an opened section object.
00046
00047 Arguments:
00048
00049 SectionHandle - Supplies an open handle to a section object.
00050
00051 SectionInformationClass - The section information
class about
00052 which to retrieve information.
00053
00054 SectionInformation -
A pointer to a buffer that receives
the
00055 specified information. The
format and content of
the buffer
00056 depend on
the specified section class.
00057
00058 SectionInformation Format by Information Class:
00059
00060 SectionBasicInformation - Data
type is PSECTION_BASIC_INFORMATION.
00061
00062 SECTION_BASIC_INFORMATION Structure
00063
00064 PVOID BaseAddress - The base
virtual address of
the
00065 section if
the section
is based.
00066
00067 LARGE_INTEGER MaximumSize - The maximum size of
the section in
00068 bytes.
00069
00070 ULONG AllocationAttributes - The allocation attributes
00071 flags.
00072
00073 AllocationAttributes Flags
00074
00075 SEC_BASED - The section
is a based section.
00076
00077 SEC_TILE - The section must be allocated in
the first
00078 512mb of
the virtual address space.
00079
00080 SEC_FILE - The section
is backed by a data
file.
00081
00082 SEC_RESERVE - All pages of
the section were initially
00083 set to
the reserved state.
00084
00085 SEC_COMMIT - All pages of
the section were initially
00086 to
the committed state.
00087
00088 SEC_IMAGE - The section was mapped as an executable
00089 image
file.
00090
00091 SECTION_IMAGE_INFORMATION
00092
00093 SectionInformationLength - Specifies
the length in bytes of
the
00094 section information buffer.
00095
00096 ReturnLength - An optional pointer which, if specified, receives
00097
the number of bytes placed in
the section information buffer.
00098
00099
00100 Return Value:
00101
00102 Returns
the status
00103
00104 TBS
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 }
}