Base Process class, to be expanded

This commit is contained in:
2026-08-04 20:09:50 +02:00
parent 6e3590d532
commit ab0090ddb1
8 changed files with 214 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <windows.h>
#include "ntproc.h"
namespace Nt {
inline HMODULE ntdll() {
static HMODULE mod = LoadLibraryA("ntdll.dll");
return mod;
}
template<typename T>
T resolve(const char *name) {
static T fn = reinterpret_cast<T>(GetProcAddress(ntdll(), name));
return fn;
}
}
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include <Windows.h>
#include <winternl.h>
namespace Nt {
typedef NTSTATUS(NTAPI* OpenProcess)(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
CLIENT_ID *ClientId
);
typedef NTSTATUS(NTAPI* DuplicateObject)(
HANDLE SourceProcessHandle,
HANDLE SourceHandle,
HANDLE TargetProcessHandle,
PHANDLE TargetHandle,
ACCESS_MASK DesiredAccess,
ULONG HandleAttributes,
ULONG Options
);
typedef NTSTATUS(NTAPI *Close)(
HANDLE Handle
);
typedef NTSTATUS(NTAPI *QuerySystemInformation)(
SYSTEM_INFORMATION_CLASS,
PVOID,
ULONG,
PULONG
);
typedef NTSTATUS(NTAPI *QueryInformationProcess)(
HANDLE,
PROCESSINFOCLASS,
PVOID,
ULONG,
PULONG
);
struct PROCESS_BASIC_INFORMATION {
NTSTATUS ExitStatus;
PPEB PebBaseAddress;
ULONG_PTR AffinityMask;
LONG BasePriority;
ULONG_PTR UniqueProcessId;
ULONG_PTR InheritedFromUniqueProcessId;
};
typedef NTSTATUS(NTAPI *ReadVirtualMemory)(
HANDLE,
PVOID,
PVOID,
SIZE_T,
PSIZE_T
);
typedef struct _PEB_PARTIAL
{
BYTE Reserved1[4];
PVOID Mutant;
PVOID ImageBaseAddress;
} PEB_PARTIAL;
}
+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include <format>
#include <stdexcept>
#include <windows.h>
#include <vector>
#include <string>
#include <winnt.h>
#include "nt/nt.h"
#include "xrbx/nt/ntproc.h"
class Process {
private:
DWORD pid;
HANDLE proc;
BYTE *base;
HANDLE openProcess();
BYTE *getImageBase(void);
public:
static DWORD findProcessByName(const std::wstring &name);
inline BYTE *imageBase(void) {
return base;
}
template <typename T>
inline T Read(BYTE *addr) {
T buf;
SIZE_T bytesRead;
NTSTATUS status = Nt::resolve<Nt::ReadVirtualMemory>("NtReadVirtualMemory")(proc, addr, &buf, sizeof(buf), &bytesRead);
if (status < 0) {
throw std::runtime_error(std::format("Failed to read {} bytes from {:X}", sizeof(buf), uintptr_t(addr)));
}
return buf;
}
inline Process(const std::wstring &name) {
pid = findProcessByName(name);
if (pid == 0) {
throw std::runtime_error("Process not found");
}
proc = openProcess();
base = getImageBase();
}
inline ~Process() {
Nt::resolve<Nt::Close>("NtClose")(proc);
}
};
+2
View File
@@ -1,3 +1,5 @@
#pragma once
#include "process.h"
void helloWorld(void);