#pragma once
#include <ntifs.h>

#include "driver_util.h"
#include "types.h"
#include "detour.hpp"

namespace hooks
{
	inline void* orig_irp_ioctl = NULL;
	inline void* orig_driver_unload = NULL;
	inline void* last_mapped_ptr = NULL;
	inline void* mapped_io_space_addr = NULL;
	inline PDRIVER_OBJECT unfair_drv_obj = NULL;

	void* get_addr_hook(
		void* base_addr,
		const char* func_name
	);

	void unmap_io_space(
		void* base_addr,
		SIZE_T size
	);

	void* map_io_space(
		PHYSICAL_ADDRESS    phys_addr,
		SIZE_T              size,
		MEMORY_CACHING_TYPE cache_type
	);

	PHYSICAL_ADDRESS get_phys_addr(
		void* base_addr
	);

	NTSTATUS create_sym_link(
		PUNICODE_STRING sym_link,
		PUNICODE_STRING device_name
	);

	NTSTATUS device_control(
		PDEVICE_OBJECT  device_obj,
		PIRP  irp
	);

	NTSTATUS create_device(
		PDRIVER_OBJECT  drv_obj,
		ULONG           drv_ext,
		PUNICODE_STRING device_name,
		DEVICE_TYPE     device_type,
		ULONG           device_char,
		BOOLEAN         exclusive,
		PDEVICE_OBJECT* device_obj
	);

	void driver_unload(
		PDRIVER_OBJECT drv_obj
	);

	void* allocate_pool(
		POOL_TYPE pool_type,
		SIZE_T    size
	);
}