Files
cs2-external-esp/memory-external/memory/memory.hpp
T
IMXNOOBX 509d2b5f2d Implemented #20 into hack.hpp now featuring a better entity loop and fixing known bugs while cleaning the code.
Added simple config system to enable team esp, automatic updates, and render distance.

Also moved the offsets to the updater namespace and read/writte methods to the offsets.json

Implemented Handle Hijacking method requested by #19 to improve the security. Credits to Apxaey on github for the source
2023-10-03 17:52:46 +02:00

103 lines
2.6 KiB
C++

#ifndef _PPROCESS_HPP_
#define _PPROCESS_HPP_
#include <vector>
#include <math.h>
#include <Windows.h>
#include <TlHelp32.h>
#include <string>
#include <iostream>
#include <Psapi.h>
struct ProcessModule
{
uintptr_t base, size;
};
class pProcess
{
public:
DWORD pid_; // process id
HANDLE handle_; // handle to process
HWND hwnd_; // window handle
ProcessModule base_module_;
public:
bool AttachProcess(const char* process_name);
bool AttachProcessHj(const char* process_name);
bool AttachWindow(const char* window_name);
bool UpdateHWND();
void Close();
public:
ProcessModule GetModule(const char* module_name);
LPVOID Allocate(size_t size_in_bytes);
uintptr_t FindCodeCave(uint32_t length_in_bytes);
uintptr_t FindSignature(std::vector<uint8_t> signature);
uintptr_t FindSignature(ProcessModule target_module, std::vector<uint8_t> signature);
template<class T>
uintptr_t ReadOffsetFromSignature(std::vector<uint8_t> signature, uint8_t offset) // offset example: "FF 05 ->22628B01<-" offset is 2
{
uintptr_t pattern_address = this->FindSignature(signature);
if (!pattern_address)
return 0x0;
T offset_value = this->read<T>(pattern_address + offset);
return pattern_address + offset_value + offset + sizeof(T);
}
bool read_raw(uintptr_t address, void* buffer, size_t size)
{
SIZE_T bytesRead;
if (ReadProcessMemory(this->handle_, reinterpret_cast<LPCVOID>(address), buffer, size, &bytesRead))
{
return bytesRead == size;
}
return false;
}
template<class T>
void write(uintptr_t address, T value)
{
WriteProcessMemory(handle_, (void*)address, &value, sizeof(T), 0);
}
template<class T>
T read(uintptr_t address)
{
T buffer{};
ReadProcessMemory(handle_, (void*)address, &buffer, sizeof(T), 0);
return buffer;
}
void write_bytes(uintptr_t addr, std::vector<uint8_t> patch)
{
WriteProcessMemory(handle_, (void*)addr, &patch[0], patch.size(), 0);
}
uintptr_t read_multi_address(uintptr_t ptr, std::vector<uintptr_t> offsets)
{
uintptr_t buffer = ptr;
for (int i = 0; i < offsets.size(); i++)
buffer = this->read<uintptr_t>(buffer + offsets[i]);
return buffer;
}
template <typename T>
T read_multi(uintptr_t base, std::vector<uintptr_t> offsets) {
uintptr_t buffer = base;
for (int i = 0; i < offsets.size() - 1; i++)
{
buffer = this->read<uintptr_t>(buffer + offsets[i]);
}
return this->read<T>(buffer + offsets.back());
}
private:
uint32_t FindProcessIdByProcessName(const char* process_name);
uint32_t FindProcessIdByWindowName(const char* window_name);
HWND GetWindowHandleFromProcessId(DWORD ProcessId);
};
#endif