First Commit
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* https://github.com/SamuelTulach/OverlayCord
|
||||
*/
|
||||
|
||||
#ifndef OVERLAYCORD_H
|
||||
#define OVERLAYCORD_H
|
||||
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace OverlayCord
|
||||
{
|
||||
namespace Communication
|
||||
{
|
||||
typedef struct _Header
|
||||
{
|
||||
UINT Magic;
|
||||
UINT FrameCount;
|
||||
UINT NoClue;
|
||||
UINT Width;
|
||||
UINT Height;
|
||||
BYTE Buffer[1];
|
||||
} Header;
|
||||
|
||||
typedef struct _ConnectedProcessInfo
|
||||
{
|
||||
UINT ProcessId;
|
||||
HANDLE File;
|
||||
Header* MappedAddress;
|
||||
} ConnectedProcessInfo;
|
||||
|
||||
inline bool ConnectToProcess(ConnectedProcessInfo& processInfo)
|
||||
{
|
||||
std::string mappedFilename = "DiscordOverlay_Framebuffer_Memory_" + std::to_string(processInfo.ProcessId);
|
||||
processInfo.File = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, mappedFilename.c_str());
|
||||
if (!processInfo.File || processInfo.File == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
processInfo.MappedAddress = static_cast<Header*>(MapViewOfFile(processInfo.File, FILE_MAP_ALL_ACCESS, 0, 0, 0));
|
||||
return processInfo.MappedAddress;
|
||||
}
|
||||
|
||||
inline void DisconnectFromProcess(ConnectedProcessInfo& processInfo)
|
||||
{
|
||||
UnmapViewOfFile(processInfo.MappedAddress);
|
||||
processInfo.MappedAddress = nullptr;
|
||||
|
||||
CloseHandle(processInfo.File);
|
||||
processInfo.File = nullptr;
|
||||
}
|
||||
|
||||
inline void SendFrame(ConnectedProcessInfo& processInfo, UINT width, UINT height, void* frame, UINT size)
|
||||
{
|
||||
// frame is in B8G8R8A8 format
|
||||
// size can be nearly anything since it will get resized
|
||||
// for the screen appropriately, although the maximum size is
|
||||
// game window width * height * 4 (BGRA)
|
||||
processInfo.MappedAddress->Width = width;
|
||||
processInfo.MappedAddress->Height = height;
|
||||
|
||||
memcpy(processInfo.MappedAddress->Buffer, frame, size);
|
||||
|
||||
processInfo.MappedAddress->FrameCount++; // this will cause the internal module to copy over the framebuffer
|
||||
}
|
||||
}
|
||||
|
||||
namespace Drawing
|
||||
{
|
||||
typedef struct _Frame
|
||||
{
|
||||
UINT Width;
|
||||
UINT Height;
|
||||
UINT Size;
|
||||
void* Buffer;
|
||||
} Frame;
|
||||
|
||||
typedef struct _Pixel
|
||||
{
|
||||
BYTE B, G, R, A;
|
||||
} Pixel;
|
||||
|
||||
inline Frame CreateFrame(UINT width, UINT height)
|
||||
{
|
||||
Frame output;
|
||||
output.Width = width;
|
||||
output.Height = height;
|
||||
output.Size = width * height * 4;
|
||||
|
||||
output.Buffer = malloc(output.Size);
|
||||
memset(output.Buffer, 0, output.Size);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
inline void CleanFrame(Frame& frame)
|
||||
{
|
||||
memset(frame.Buffer, 0, frame.Size);
|
||||
}
|
||||
|
||||
inline void SetPixel(Frame& frame, UINT x, UINT y, Pixel color)
|
||||
{
|
||||
if (x < frame.Width && y < frame.Height)
|
||||
{
|
||||
Pixel* buf = static_cast<Pixel*>(frame.Buffer);
|
||||
buf[y * frame.Width + x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
inline void DrawLine(Frame& frame, UINT x1, UINT y1, UINT x2, UINT y2, Pixel color)
|
||||
{
|
||||
int dx = abs(static_cast<int>(x2 - x1)), sx = x1 < x2 ? 1 : -1;
|
||||
int dy = -abs(static_cast<int>(y2 - y1)), sy = y1 < y2 ? 1 : -1;
|
||||
int err = dx + dy, e2;
|
||||
|
||||
while (true)
|
||||
{
|
||||
SetPixel(frame, x1, y1, color);
|
||||
if (x1 == x2 && y1 == y2)
|
||||
break;
|
||||
e2 = 2 * err;
|
||||
if (e2 >= dy) { err += dy; x1 += sx; }
|
||||
if (e2 <= dx) { err += dx; y1 += sy; }
|
||||
}
|
||||
}
|
||||
|
||||
inline void DrawRectangle(Frame& frame, UINT x1, UINT y1, UINT width, UINT height, Pixel color)
|
||||
{
|
||||
for (UINT x = x1; x < x1 + width; x++)
|
||||
{
|
||||
SetPixel(frame, x, y1, color);
|
||||
SetPixel(frame, x, y1 + height - 1, color);
|
||||
}
|
||||
|
||||
for (UINT y = y1; y < y1 + height; y++)
|
||||
{
|
||||
SetPixel(frame, x1, y, color);
|
||||
SetPixel(frame, x1 + width - 1, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
inline void DrawCircle(Frame& frame, UINT x0, UINT y0, UINT radius, Pixel color)
|
||||
{
|
||||
int x = radius;
|
||||
int y = 0;
|
||||
int radiusError = 1 - x;
|
||||
|
||||
while (x >= y)
|
||||
{
|
||||
SetPixel(frame, x0 + x, y0 + y, color);
|
||||
SetPixel(frame, x0 - x, y0 + y, color);
|
||||
SetPixel(frame, x0 - x, y0 - y, color);
|
||||
SetPixel(frame, x0 + x, y0 - y, color);
|
||||
SetPixel(frame, x0 + y, y0 + x, color);
|
||||
SetPixel(frame, x0 - y, y0 + x, color);
|
||||
SetPixel(frame, x0 - y, y0 - x, color);
|
||||
SetPixel(frame, x0 + y, y0 - x, color);
|
||||
|
||||
y++;
|
||||
if (radiusError < 0)
|
||||
{
|
||||
radiusError += 2 * y + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x--;
|
||||
radiusError += 2 * (y - x + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
#include <numbers>
|
||||
#include <cmath>
|
||||
|
||||
int screen_x = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screen_y = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
struct view_matrix_t {
|
||||
float* operator[ ](int index) {
|
||||
return matrix[index];
|
||||
}
|
||||
|
||||
float matrix[4][4];
|
||||
};
|
||||
|
||||
struct Vector3
|
||||
{
|
||||
// constructor
|
||||
constexpr Vector3(
|
||||
const float x = 0.f,
|
||||
const float y = 0.f,
|
||||
const float z = 0.f) noexcept :
|
||||
x(x), y(y), z(z) { }
|
||||
|
||||
// operator overloads
|
||||
constexpr const Vector3& operator-(const Vector3& other) const noexcept
|
||||
{
|
||||
return Vector3{ x - other.x, y - other.y, z - other.z };
|
||||
}
|
||||
|
||||
constexpr const Vector3& operator+(const Vector3& other) const noexcept
|
||||
{
|
||||
return Vector3{ x + other.x, y + other.y, z + other.z };
|
||||
}
|
||||
|
||||
constexpr const Vector3& operator/(const float factor) const noexcept
|
||||
{
|
||||
return Vector3{ x / factor, y / factor, z / factor };
|
||||
}
|
||||
|
||||
constexpr const Vector3& operator*(const float factor) const noexcept
|
||||
{
|
||||
return Vector3{ x * factor, y * factor, z * factor };
|
||||
}
|
||||
|
||||
constexpr const bool operator>(const Vector3& other) const noexcept {
|
||||
return x > other.x && y > other.y && z > other.z;
|
||||
}
|
||||
|
||||
constexpr const bool operator>=(const Vector3& other) const noexcept {
|
||||
return x >= other.x && y >= other.y && z >= other.z;
|
||||
}
|
||||
|
||||
constexpr const bool operator<(const Vector3& other) const noexcept {
|
||||
return x < other.x && y < other.y && z < other.z;
|
||||
}
|
||||
|
||||
constexpr const bool operator<=(const Vector3& other) const noexcept {
|
||||
return x <= other.x && y <= other.y && z <= other.z;
|
||||
}
|
||||
|
||||
// utils
|
||||
constexpr const Vector3& ToAngle() const noexcept
|
||||
{
|
||||
return Vector3{
|
||||
std::atan2(-z, std::hypot(x, y)) * (180.0f / std::numbers::pi_v<float>),
|
||||
std::atan2(y, x) * (180.0f / std::numbers::pi_v<float>),
|
||||
0.0f };
|
||||
}
|
||||
|
||||
float length() const {
|
||||
return std::sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
float length2d() const {
|
||||
return std::sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
constexpr const bool IsZero() const noexcept
|
||||
{
|
||||
return x == 0.f && y == 0.f && z == 0.f;
|
||||
}
|
||||
|
||||
Vector3 world_to_screen(view_matrix_t matrix) const {
|
||||
float _x = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z + matrix[0][3];
|
||||
float _y = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z + matrix[1][3];
|
||||
|
||||
float w = matrix[3][0] * x + matrix[3][1] * y + matrix[3][2] * z + matrix[3][3];
|
||||
|
||||
float inv_w = 1.f / w;
|
||||
_x *= inv_w;
|
||||
_y *= inv_w;
|
||||
|
||||
float x = screen_x * .5f;
|
||||
float y = screen_y * .5f;
|
||||
|
||||
x += 0.5f * _x * screen_x + 0.5f;
|
||||
y -= 0.5f * _y * screen_y + 0.5f;
|
||||
|
||||
return { x, y, w };
|
||||
}
|
||||
|
||||
// struct data
|
||||
float x, y, z;
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "memory/memory.hpp"
|
||||
#include "classes/vector.hpp"
|
||||
#include "classes/OverlayCord.h"
|
||||
|
||||
// https://www.unknowncheats.me/forum/3846642-post734.html
|
||||
|
||||
#define dwLocalPlayer 0x1713348
|
||||
#define dwEntityList 0x1679C38
|
||||
#define dwPawnHealth 0x808
|
||||
#define dwPlayerPawn 0x5dc
|
||||
#define dwViewMatrix 0x1713CF0
|
||||
#define m_iTeamNum 0x3bf
|
||||
#define m_vecOrigin 0x12AC
|
||||
|
||||
int main() {
|
||||
std::shared_ptr<pProcess> process = std::make_shared<pProcess>();
|
||||
|
||||
std::cout << "[cs2] Waiting for cs2.exe..." << std::endl;
|
||||
|
||||
while (!process->AttachProcess("cs2.exe"))
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
std::cout << "[cs2] Attached to cs2.exe" << std::endl;
|
||||
|
||||
ProcessModule base_module;
|
||||
|
||||
do {
|
||||
base_module = process->GetModule("client.dll");
|
||||
if (base_module.base == 0) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::cout << "[cs2] Failed to find module client.dll" << std::endl;
|
||||
}
|
||||
} while (base_module.base == 0);
|
||||
|
||||
std::cout << "[overlay] Connecting to the process..." << std::endl;
|
||||
OverlayCord::Communication::ConnectedProcessInfo processInfo = { 0 };
|
||||
processInfo.ProcessId = process->pid_;
|
||||
|
||||
bool status = false;
|
||||
do {
|
||||
status = OverlayCord::Communication::ConnectToProcess(processInfo);
|
||||
if (!status) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::cout << "[overlay] Failed to connect to the process overlay backend" << std::endl;
|
||||
}
|
||||
} while (!status);
|
||||
|
||||
std::cout << "[overlay] Connected to the process with mapped address 0x" << processInfo.MappedAddress << std::endl;
|
||||
|
||||
OverlayCord::Drawing::Frame mainFrame = OverlayCord::Drawing::CreateFrame(screen_x, screen_y);
|
||||
|
||||
OverlayCord::Drawing::Pixel enemy_color = { 75, 75, 175, 255 }; // BYTE B, G, R, A;
|
||||
OverlayCord::Drawing::Pixel team_color = { 75, 175, 75, 255 };
|
||||
|
||||
std::cout << "[cs2] Fully set up, running main loop now" << std::endl;
|
||||
|
||||
while (!(GetAsyncKeyState(VK_END) & 0x8000)) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
|
||||
uintptr_t localPlayer = process->read<uintptr_t>(base_module.base + dwLocalPlayer);
|
||||
|
||||
if (!localPlayer) continue;
|
||||
|
||||
int localTeam = process->read<int>(localPlayer + m_iTeamNum);
|
||||
|
||||
view_matrix_t view_matrix = process->read<view_matrix_t>(base_module.base + dwViewMatrix);
|
||||
|
||||
Vector3 localOrigin = process->read<Vector3>(localPlayer + m_vecOrigin);
|
||||
|
||||
OverlayCord::Drawing::CleanFrame(mainFrame);
|
||||
|
||||
uintptr_t entity_list = process->read<uintptr_t>(base_module.base + dwEntityList);
|
||||
|
||||
for (int i = 1; i < 32; i++) {
|
||||
uintptr_t list_entry = process->read<uintptr_t>(entity_list + (8 * (i & 0x7FFF) >> 9) + 16);
|
||||
if (!list_entry) continue;
|
||||
uintptr_t player = process->read<uintptr_t>(list_entry + 120 * (i & 0x1FF));
|
||||
|
||||
if (!player) continue;
|
||||
|
||||
int playerHealth = process->read<int>(player + dwPawnHealth);
|
||||
if (playerHealth < 0 || playerHealth > 100) continue;
|
||||
|
||||
int playerTeam = process->read<int>(player + m_iTeamNum);
|
||||
|
||||
// https://github.com/UnnamedZ03/CS2-external-base/blob/main/source/CSSPlayer.hpp#L132
|
||||
std::uint32_t playerpawn = process->read<std::uint32_t>(player + dwPlayerPawn);
|
||||
|
||||
uintptr_t list_entry2 = process->read<uintptr_t>(entity_list + 0x8 * ((playerpawn & 0x7FFF) >> 9) + 16);
|
||||
if (!list_entry2) continue;
|
||||
uintptr_t pCSPlayerPawn = process->read<uintptr_t>(list_entry2 + 120 * (playerpawn & 0x1FF));
|
||||
|
||||
if (pCSPlayerPawn == localPlayer) continue;
|
||||
|
||||
// https://github.com/UnnamedZ03/CS2-external-base/blob/main/source/CSSPlayer.hpp#L132
|
||||
Vector3 origin = process->read<Vector3>(pCSPlayerPawn + m_vecOrigin);
|
||||
|
||||
//if ((localOrigin - origin).length2d() > 1000) continue;
|
||||
|
||||
Vector3 head;
|
||||
head.x = origin.x;
|
||||
head.y = origin.y;
|
||||
head.z = origin.z + 75.f;
|
||||
|
||||
Vector3 screenpos = origin.world_to_screen(view_matrix);
|
||||
Vector3 screenhead = head.world_to_screen(view_matrix);
|
||||
|
||||
float height = screenpos.y - screenhead.y;
|
||||
float width = height / 2.4f;
|
||||
if (screenpos.z >= 0.01f) {
|
||||
OverlayCord::Drawing::Pixel health_color = { 75,
|
||||
(unsigned char)(55 + playerHealth * 2),
|
||||
(unsigned char)(255 - playerHealth),
|
||||
255
|
||||
};
|
||||
|
||||
OverlayCord::Drawing::DrawRectangle(
|
||||
mainFrame,
|
||||
screenhead.x - 25.f,
|
||||
screenhead.y,
|
||||
width,
|
||||
height,
|
||||
(localTeam == playerTeam ? team_color : enemy_color)
|
||||
);
|
||||
|
||||
OverlayCord::Drawing::DrawRectangle(
|
||||
mainFrame,
|
||||
screenhead.x - 30.f,
|
||||
screenhead.y + (height * (100 - playerHealth) / 100),
|
||||
2,
|
||||
height - (height * (100 - playerHealth) / 100),
|
||||
health_color
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
OverlayCord::Drawing::DrawCircle(mainFrame, 15, 15, i, enemy_color);
|
||||
|
||||
OverlayCord::Communication::SendFrame(processInfo, mainFrame.Width, mainFrame.Height, mainFrame.Buffer, mainFrame.Size);
|
||||
}
|
||||
|
||||
std::cout << "[overlay] Cleaning frame" << std::endl;
|
||||
OverlayCord::Drawing::CleanFrame(mainFrame);
|
||||
std::cout << "[overlay] Disconnecting from process" << std::endl;
|
||||
OverlayCord::Communication::DisconnectFromProcess(processInfo);
|
||||
|
||||
std::cout << "[cs2] Deataching from process" << std::endl;
|
||||
process->Close();
|
||||
|
||||
std::cout << "[cs2] Press any key to close" << std::endl;
|
||||
std::cin.get();
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{b87ab66d-73cc-48a1-9d3a-76b2ecbd3a64}</ProjectGuid>
|
||||
<RootNamespace>memoryexternal</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>cs2-external-esp</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="memory\memory.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="classes\OverlayCord.h" />
|
||||
<ClInclude Include="classes\vector.hpp" />
|
||||
<ClInclude Include="memory\memory.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="memory\memory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="memory\memory.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="classes\OverlayCord.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="classes\vector.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "memory.hpp"
|
||||
#include <tlhelp32.h>
|
||||
|
||||
uint32_t pProcess::FindProcessIdByProcessName(const char* ProcessName)
|
||||
{
|
||||
std::wstring wideProcessName;
|
||||
int wideCharLength = MultiByteToWideChar(CP_UTF8, 0, ProcessName, -1, nullptr, 0);
|
||||
if (wideCharLength > 0)
|
||||
{
|
||||
wideProcessName.resize(wideCharLength);
|
||||
MultiByteToWideChar(CP_UTF8, 0, ProcessName, -1, &wideProcessName[0], wideCharLength);
|
||||
}
|
||||
|
||||
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
|
||||
PROCESSENTRY32W process_entry_{ };
|
||||
process_entry_.dwSize = sizeof(PROCESSENTRY32W);
|
||||
|
||||
DWORD pid = 0;
|
||||
if (Process32FirstW(hPID, &process_entry_))
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!wcscmp(process_entry_.szExeFile, wideProcessName.c_str()))
|
||||
{
|
||||
pid = process_entry_.th32ProcessID;
|
||||
break;
|
||||
}
|
||||
} while (Process32NextW(hPID, &process_entry_));
|
||||
}
|
||||
CloseHandle(hPID);
|
||||
return pid;
|
||||
}
|
||||
|
||||
uint32_t pProcess::FindProcessIdByWindowName(const char* WindowName)
|
||||
{
|
||||
DWORD process_id = 0;
|
||||
HWND windowHandle = FindWindowA(nullptr, WindowName);
|
||||
if (windowHandle)
|
||||
GetWindowThreadProcessId(windowHandle, &process_id);
|
||||
return process_id;
|
||||
}
|
||||
|
||||
HWND pProcess::GetWindowHandleFromProcessId(DWORD ProcessId) {
|
||||
HWND hwnd = NULL;
|
||||
do {
|
||||
hwnd = FindWindowEx(NULL, hwnd, NULL, NULL);
|
||||
DWORD pid = 0;
|
||||
GetWindowThreadProcessId(hwnd, &pid);
|
||||
if (pid == ProcessId) {
|
||||
TCHAR windowTitle[MAX_PATH];
|
||||
GetWindowText(hwnd, windowTitle, MAX_PATH);
|
||||
if (IsWindowVisible(hwnd) && windowTitle[0] != '\0') {
|
||||
return hwnd;
|
||||
}
|
||||
}
|
||||
} while (hwnd != NULL);
|
||||
return NULL; // No main window found for the given process ID
|
||||
}
|
||||
|
||||
bool pProcess::AttachProcess(const char* ProcessName)
|
||||
{
|
||||
this->pid_ = this->FindProcessIdByProcessName(ProcessName);
|
||||
|
||||
if (pid_)
|
||||
{
|
||||
HMODULE modules[0xFF];
|
||||
MODULEINFO module_info;
|
||||
DWORD _;
|
||||
|
||||
handle_ = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid_);
|
||||
|
||||
EnumProcessModulesEx(this->handle_, modules, sizeof(modules), &_, LIST_MODULES_64BIT);
|
||||
base_module_.base = (uintptr_t)modules[0];
|
||||
|
||||
GetModuleInformation(this->handle_, modules[0], &module_info, sizeof(module_info));
|
||||
base_module_.size = module_info.SizeOfImage;
|
||||
|
||||
hwnd_ = this->GetWindowHandleFromProcessId(pid_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pProcess::AttachWindow(const char* WindowName)
|
||||
{
|
||||
this->pid_ = this->FindProcessIdByWindowName(WindowName);
|
||||
|
||||
if (pid_)
|
||||
{
|
||||
HMODULE modules[0xFF];
|
||||
MODULEINFO module_info;
|
||||
DWORD _;
|
||||
|
||||
handle_ = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid_);
|
||||
|
||||
EnumProcessModulesEx(this->handle_, modules, sizeof(modules), &_, LIST_MODULES_64BIT);
|
||||
base_module_.base = (uintptr_t)modules[0];
|
||||
|
||||
GetModuleInformation(this->handle_, modules[0], &module_info, sizeof(module_info));
|
||||
base_module_.size = module_info.SizeOfImage;
|
||||
|
||||
hwnd_ = this->GetWindowHandleFromProcessId(pid_);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessModule pProcess::GetModule(const char* lModule)
|
||||
{
|
||||
std::wstring wideModule;
|
||||
int wideCharLength = MultiByteToWideChar(CP_UTF8, 0, lModule, -1, nullptr, 0);
|
||||
if (wideCharLength > 0)
|
||||
{
|
||||
wideModule.resize(wideCharLength);
|
||||
MultiByteToWideChar(CP_UTF8, 0, lModule, -1, &wideModule[0], wideCharLength);
|
||||
}
|
||||
|
||||
HANDLE handle_module = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid_);
|
||||
MODULEENTRY32W module_entry_{};
|
||||
module_entry_.dwSize = sizeof(MODULEENTRY32W);
|
||||
|
||||
do
|
||||
{
|
||||
if (!wcscmp(module_entry_.szModule, wideModule.c_str()))
|
||||
{
|
||||
CloseHandle(handle_module);
|
||||
return { (DWORD_PTR)module_entry_.modBaseAddr, module_entry_.dwSize };
|
||||
}
|
||||
} while (Module32NextW(handle_module, &module_entry_));
|
||||
|
||||
CloseHandle(handle_module);
|
||||
return { 0, 0 };
|
||||
}
|
||||
|
||||
LPVOID pProcess::Allocate(size_t size_in_bytes)
|
||||
{
|
||||
return VirtualAllocEx(this->handle_, NULL, size_in_bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
uintptr_t pProcess::FindSignature(std::vector<uint8_t> signature)
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
data = std::make_unique<uint8_t[]>(this->base_module_.size);
|
||||
|
||||
if (!ReadProcessMemory(this->handle_, (void*)(this->base_module_.base), data.get(), this->base_module_.size, NULL)) {
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
for (uintptr_t i = 0; i < this->base_module_.size; i++)
|
||||
{
|
||||
for (uintptr_t j = 0; j < signature.size(); j++)
|
||||
{
|
||||
if (signature.at(j) == 0x00)
|
||||
continue;
|
||||
|
||||
if (*reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(&data[i + j])) == signature.at(j))
|
||||
{
|
||||
if (j == signature.size() - 1)
|
||||
return this->base_module_.base + i;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
uintptr_t pProcess::FindSignature(ProcessModule target_module, std::vector<uint8_t> signature)
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
data = std::make_unique<uint8_t[]>(0xFFFFFFF);
|
||||
|
||||
if (!ReadProcessMemory(this->handle_, (void*)(target_module.base), data.get(), 0xFFFFFFF, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (uintptr_t i = 0; i < 0xFFFFFFF; i++)
|
||||
{
|
||||
for (uintptr_t j = 0; j < signature.size(); j++)
|
||||
{
|
||||
if (signature.at(j) == 0x00)
|
||||
continue;
|
||||
|
||||
if (*reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(&data[i + j])) == signature.at(j))
|
||||
{
|
||||
if (j == signature.size() - 1)
|
||||
return this->base_module_.base + i;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
uintptr_t pProcess::FindCodeCave(uint32_t length_in_bytes)
|
||||
{
|
||||
std::vector<uint8_t> cave_pattern = {};
|
||||
|
||||
for (uint32_t i = 0; i < length_in_bytes; i++) {
|
||||
cave_pattern.push_back(0x00);
|
||||
}
|
||||
|
||||
return FindSignature(cave_pattern);
|
||||
}
|
||||
|
||||
void pProcess::Close()
|
||||
{
|
||||
CloseHandle(handle_);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#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 AttachWindow(const char* window_name);
|
||||
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
|
||||
Reference in New Issue
Block a user