Blame src/modules/pe_get_ntdll_module_handle.c

feffc7
/*****************************************************************************/
feffc7
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
b6ea9a
/*  Copyright (C) 2013--2017  Z. Gilboa                                      */
feffc7
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
feffc7
/*****************************************************************************/
feffc7
feffc7
#include <psxtypes/psxtypes.h>
feffc7
#include <pemagine/pe_consts.h>
feffc7
#include <pemagine/pe_structs.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
#include "pe_impl.h"
feffc7
9541a4
feffc7
void * pe_get_ntdll_module_handle(void)
feffc7
{
feffc7
	struct pe_peb_ldr_data * 	peb_ldr_data;
feffc7
	struct pe_list_entry *   	peb_list_entry;
feffc7
	intptr_t 			peb_tbl_addr;
feffc7
	struct pe_ldr_tbl_entry *	peb_ldr_tbl_entry;
feffc7
feffc7
	peb_ldr_data = (struct pe_peb_ldr_data *)pe_get_peb_ldr_data_address();
feffc7
	peb_list_entry = peb_ldr_data->in_init_order_module_list.flink;
feffc7
	peb_tbl_addr = (intptr_t)peb_list_entry - IN_INITIALIZATION_ORDER_MODULE_LIST_OFFSET;
feffc7
	peb_ldr_tbl_entry = (struct pe_ldr_tbl_entry *)peb_tbl_addr;
feffc7
feffc7
	return peb_ldr_tbl_entry->dll_base;
feffc7
}