Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

How to get base address of ntdll.dll under kernel Windows 8

Valery_DrubaValery_Druba Member Posts: 27
Hello!

I need get pase address of ntdll.dll. For Windows 7 and lower I used
ZwQuerySystemInformation. But under Windows 8 ntdll.dll is invisible
for this function.
I have implemented another algorithm using ZwQuerySection. It correct
works on Windows 7, but it returns bad address for Windows 8. The
address defers from real base address on constant 0x30670.

Could anybody explain what is the problem ?
There is the code of my new algorithm implementation :

PVOID LookforNtdll( )
{
PVOID pDLL = NULL;
IO_STATUS_BLOCK IoStBlock;
UNICODE_STRING usLibraryName ;
OBJECT_ATTRIBUTES ObjAttrF;
NTSTATUS status = 0;
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hSect = INVALID_HANDLE_VALUE;
PSECTION_IMAGE_INFORMATION pB = NULL;

RtlInitUnicodeString ( &usLibraryName,
L"\\DosDevices\\c:\\windows\\system32\\ntdll.dll" ) ;
InitializeObjectAttributes( &ObjAttrF, &usLibraryName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL );

status = ZwOpenFile(&hFile, GENERIC_READ, &ObjAttrF, &IoStBlock,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_NON_DIRECTORY_FILE );
if ( status == STATUS_SUCCESS ) {
UNICODE_STRING usSectName;
OBJECT_ATTRIBUTES ObjAttrS;
LARGE_INTEGER Size;

RtlInitUnicodeString ( &usSectName,
L"\\BaseNamedObjects\\NtDllSharedSection" ) ;
InitializeObjectAttributes ( &ObjAttrS, &usSectName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL ) ;

Size.HighPart = 0 ;
Size.LowPart = 0x1000 ;

status = ZwCreateSection ( &hSect, SECTION_ALL_ACCESS,
&ObjAttrS, &Size, PAGE_EXECUTE_READ, 0x1000000, hFile ) ;
if ( status == STATUS_SUCCESS ) {
ULONG bufSize = 0;

bufSize = Size.LowPart;
pB = ExAllocatePoolWithTag(NonPagedPool, bufSize, 'Fnd2' );
if (pB) {
status = ZwQuerySection ( hSect,
SectionImageInformation, pB, bufSize, &bufSize );
if (status == STATUS_SUCCESS)
pDLL = pB->EntryPoint ;
}
}
}
}

if (hFile != INVALID_HANDLE_VALUE)
ZwClose( hFile ) ;

if (hSect != INVALID_HANDLE_VALUE)
ZwClose( hSect ) ;

if (pB)
ExFreePool(pB);

return ( pDLL ) ;
}

Thanks
Valery

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 24 January 2022 Live, Online
Internals & Software Drivers 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online
Developing Minifilters 23 May 2022 Live, Online