From f09669dd5846d95b063712571ccb7519910a0d6e Mon Sep 17 00:00:00 2001 From: auth12 <67507608+auth12@users.noreply.github.com> Date: Tue, 21 Jul 2020 13:07:42 -0700 Subject: Added game selection. Started process wrapper. Removed asmjit. --- client/src/injection/process.cpp | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 client/src/injection/process.cpp (limited to 'client/src/injection/process.cpp') diff --git a/client/src/injection/process.cpp b/client/src/injection/process.cpp new file mode 100644 index 0000000..954e9a8 --- /dev/null +++ b/client/src/injection/process.cpp @@ -0,0 +1,71 @@ +#include "../include.h" +#include "../util/io.h" +#include "../util/syscalls.h" +#include "../util/util.h" +#include "process.h" + +process::process(const SYSTEM_PROCESS_INFORMATION* info) { + std::wstring name; + name.resize(info->ImageName.Length); + + std::memcpy(&name[0], &info->ImageName.Buffer[0], name.size()); + + m_name = util::wide_to_multibyte(name); + m_id = int(info->UniqueProcessId); +} + +process::~process() { + m_name.clear(); +} + +bool process::open() { + CLIENT_ID cid = { HANDLE(m_id), 0 }; + OBJECT_ATTRIBUTES oa; + oa.Length = sizeof(oa); + oa.Attributes = 0; + oa.RootDirectory = 0; + oa.SecurityDescriptor = 0; + oa.ObjectName = 0; + oa.SecurityQualityOfService = 0; + + static auto nt_open = g_syscalls.get("NtOpenProcess"); + + if (!NT_SUCCESS(nt_open(&m_handle, PROCESS_ALL_ACCESS, &oa, &cid))) { + io::logger->error("failed to open handle to {}.", m_name); + return false; + } + + return true; +} + +bool process::read(const uintptr_t addr, void* data, const size_t size) { + static auto nt_read = g_syscalls.get("NtReadVirtualMemory"); + if (!m_handle) { + io::logger->error("invalid process handle.", m_name); + return false; + } + + ULONG read; + if (!NT_SUCCESS(nt_read(m_handle, reinterpret_cast(addr), data, size, &read))) { + io::logger->error("failed to read to {}.", m_name); + return false; + } + + return true; +} + +bool process::write(const uintptr_t addr, void* data, const size_t size) { + static auto nt_write = g_syscalls.get("NtWiteVirtualMemory"); + if (!m_handle) { + io::logger->error("invalid process handle.", m_name); + return false; + } + + ULONG wrote; + if (!NT_SUCCESS(nt_write(m_handle, reinterpret_cast(addr), data, size, &wrote))) { + io::logger->error("failed to write to {}.", m_name); + return false; + } + + return true; +} -- cgit v1.2.3