You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

#include "hyper_ctx.hpp"
namespace hyperspace
{
hyper_ctx::hyper_ctx(ptm::ptm_ctx* target_ctx)
:
target_ctx(target_ctx),
v_ctx(target_ctx->v_ctx)
{
orig_context.first = v_ctx->get_virtual(
reinterpret_cast<std::uintptr_t>(target_ctx->dirbase));
orig_context.second =
reinterpret_cast<std::uintptr_t>(target_ctx->dirbase);
// make a new context 1:1 with the target process...
hyperspace_context.first = v_ctx->kalloc(PAGE_4KB);
hyperspace_context.second =
v_ctx->get_physical(this->hyperspace_context.first);
v_ctx->wkm(reinterpret_cast<void*>(this->hyperspace_context.first),
reinterpret_cast<void*>(this->orig_context.first), PAGE_4KB);
// make a new kprocess 1:1 with the target process...
orig_peproc = v_ctx->get_peprocess(target_ctx->pid);
clone_peproc = reinterpret_cast<PEPROCESS>(v_ctx->kalloc(PAGE_4KB));
v_ctx->wkm(clone_peproc, orig_peproc, PAGE_4KB);
// 1: kd > dt !_KPROCESS
// nt!_KPROCESS
// + 0x000 Header : _DISPATCHER_HEADER
// + 0x018 ProfileListHead : _LIST_ENTRY
// + 0x028 DirectoryTableBase : Uint8B <=== swap this with new pml4...
const auto dirbase_ptr =
reinterpret_cast<std::uintptr_t>(clone_peproc) + KPROCESS_DIRBASE_OFFSET;
v_ctx->wkm<std::uintptr_t>(dirbase_ptr, hyperspace_context.second);
}
auto hyper_ctx::hyper_jmp(std::uint32_t tid) -> void
{
const auto current_thread =
reinterpret_cast<std::uintptr_t>(
v_ctx->get_current_thread());
v_ctx->wkm<PEPROCESS>(
current_thread + KTHREAD_PKPROCESS_OFFSET, clone_peproc);
}
auto hyper_ctx::hyper_ret(std::uint32_t tid) -> void
{
const auto current_thread =
reinterpret_cast<std::uintptr_t>(
v_ctx->get_current_thread());
v_ctx->wkm<PEPROCESS>(
current_thread + KTHREAD_PKPROCESS_OFFSET, orig_peproc);
}
}