Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Create the permanent section which maps physical memory.
- //
- Segment = (PSEGMENT)ExAllocatePoolWithTag (PagedPool,
- sizeof(SEGMENT),
- 'gSmM');
- if (Segment == NULL) {
- return FALSE;
- }
- ControlArea = ExAllocatePoolWithTag (NonPagedPool,
- (ULONG)sizeof(CONTROL_AREA),
- MMCONTROL);
- if (ControlArea == NULL) {
- ExFreePool (Segment);
- return FALSE;
- }
- RtlZeroMemory (Segment, sizeof(SEGMENT));
- RtlZeroMemory (ControlArea, sizeof(CONTROL_AREA));
- ControlArea->Segment = Segment;
- ControlArea->NumberOfSectionReferences = 1;
- ControlArea->u.Flags.PhysicalMemory = 1;
- Segment->ControlArea = ControlArea;
- Segment->SegmentPteTemplate.u.Long = 0;
- //
- // Now that the segment object is created, create a section object
- // which refers to the segment object.
- //
- #define DEVICE_PHYSICAL_MEMORY L"\\Device\\PhysicalMemory"
- #if NTDDI_VERSION >= NTDDI_WS03
- #define DEVICE_PHYSICAL_MEMORY_ATTRIBUTES (OBJ_PERMANENT | OBJ_KERNEL_EXCLUSIVE)
- #else
- // XP x86 version
- #define DEVICE_PHYSICAL_MEMORY_ATTRIBUTES (OBJ_PERMANENT)
- #endif
- SectionName.Buffer = (const PUSHORT)DEVICE_PHYSICAL_MEMORY;
- SectionName.Length = sizeof (DEVICE_PHYSICAL_MEMORY) - sizeof (WCHAR);
- SectionName.MaximumLength = sizeof (DEVICE_PHYSICAL_MEMORY);
- InitializeObjectAttributes (&ObjectAttributes,
- &SectionName,
- DEVICE_PHYSICAL_MEMORY_ATTRIBUTES,
- NULL,
- NULL);
- Status = ObCreateObject (KernelMode,
- MmSectionObjectType,
- &ObjectAttributes,
- KernelMode,
- NULL,
- sizeof(SECTION),
- sizeof(SECTION),
- 0,
- (PVOID *)&Section);
- if (!NT_SUCCESS(Status)) {
- ExFreePool (ControlArea);
- ExFreePool (Segment);
- return FALSE;
- }
- Section->Segment = Segment;
- Section->SizeOfSection.QuadPart = ((LONGLONG)1 << PHYSICAL_ADDRESS_BITS) - 1;
- Section->u.LongFlags = 0;
- Section->InitialPageProtection = PAGE_EXECUTE_READWRITE;
- Status = ObInsertObject ((PVOID)Section,
- NULL,
- SECTION_MAP_READ,
- 0,
- NULL,
- &Handle);
- if (!NT_SUCCESS (Status)) {
- return FALSE;
- }
- ZwClose(Handle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement