How could I go about loading functions from NTDLL without linking against it or any other DLLs?

693 views Asked by At

I've been experimenting with loading functions from the Windows system DLLs using only the loader functions exported by NTDLL. This works as expected. For the sake of curiosity and getting an even better understanding of the process structure in NT-based systems, I've started trying to load functions from NTDLL by doing the following steps:

  1. Load the PEB of the process from gs:[60h]
  2. Iterate over the modules loaded into the process according to the loader to find NTDLL's base address
  3. Parse the PE headers of NTDLL
  4. Try to parse the export table to find LdrLoadDll, LdrGetDllHandle, and LdrGetProcedureAddress

This fails at step 4. After stepping through it in a debugger (both VS2019 and WinDbg Preview), it seems as though the offsets I've tried yield an invalid structure that leads to an access violation when my code compares the current function name to one of the ones I'm searching for. My code is being compiled and run on a 64-bit copy of Windows 10 Pro build 21364. Note that I'm using my own header that contains definitions for the structures used for this (these definitions are from winnt.h and here) because the Windows headers don't really play nice with the rest of my code. The function trying to do this is here. For the record, this is part of an attempt to implement my own libc (again, for the sake of curiosity). The code that calls the functions is here. Any help with this is tremendously appreciated.

1

There are 1 answers

0
mobslicer152 On BEST ANSWER

Nevermind, turns out I had outdated verbose definitions of the structures I was using. I found better (more up-to-date) definitions at https://vergiliusproject.com.