# RtlLoadPeHeaders

```cpp
#include <Windows.h>

BOOL RtlLoadPeHeaders(_Inout_ PIMAGE_DOS_HEADER* Dos, _Inout_ PIMAGE_NT_HEADERS* Nt, _Inout_ PIMAGE_FILE_HEADER* File, _Inout_ PIMAGE_OPTIONAL_HEADER* Optional, _Inout_ PBYTE* ImageBase)
{
	*Dos = (PIMAGE_DOS_HEADER)*ImageBase;
	if ((*Dos)->e_magic != IMAGE_DOS_SIGNATURE)
		return FALSE;

	*Nt = (PIMAGE_NT_HEADERS)((PBYTE)*Dos + (*Dos)->e_lfanew);
	if ((*Nt)->Signature != IMAGE_NT_SIGNATURE)
		return FALSE;

	*File = (PIMAGE_FILE_HEADER)(*ImageBase + (*Dos)->e_lfanew + sizeof(DWORD));
	*Optional = (PIMAGE_OPTIONAL_HEADER)((PBYTE)*File + sizeof(IMAGE_FILE_HEADER));

	return TRUE;
}

INT main(VOID)
{
  PBYTE ImageBase = NULL;

  PIMAGE_DOS_HEADER Dos = NULL;
  PIMAGE_NT_HEADERS64 Nt = NULL;
	PIMAGE_FILE_HEADER File = NULL;
  PIMAGE_OPTIONAL_HEADER64 Optional = NULL;
    
	//get imagebase of ntdll for example
  ImageBase = (PBYTE)GetModuleHandleA("ntdll.dll");
  if (ImageBase == NULL)
      return GetLastError();

	//get file headers
	if (!RtlLoadPeHeaders(&Dos, &Nt, &File, &Optional, &ImageBase))
		return -1;

  return ERROR_SUCCESS;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malwaresourcecode.com/home/library-loading/rtlloadpeheaders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
