Skip to content

Instantly share code, notes, and snippets.

@Tustin
Created December 26, 2018 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tustin/a377a8539b424d73d049c1554a7f740d to your computer and use it in GitHub Desktop.
Save Tustin/a377a8539b424d73d049c1554a7f740d to your computer and use it in GitHub Desktop.
// bo4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
typedef __int64(__stdcall* _CBuf_AddText)(__int64, const char*);
HANDLE FindProcess(const std::string name)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
// C++ is awful.
auto wideBoy = std::wstring(name.begin(), name.end());
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry))
{
do
{
if (_wcsnicmp(entry.szExeFile, wideBoy.c_str(), wideBoy.size()) == 0)
{
auto handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
CloseHandle(snapshot);
return handle;
}
} while (Process32Next(snapshot, &entry));
}
}
uintptr_t FindProcessBase(HANDLE proc)
{
DWORD id = GetProcessId(proc);
std::cout << "proc id " << id << std::endl;
auto snappy = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, id);
std::cout << snappy << std::endl;
if (snappy == INVALID_HANDLE_VALUE) {
std::cout << "invalid handle value\n";
return NULL;
}
uintptr_t addy = 0;
MODULEENTRY32 data;
data.dwSize = sizeof(MODULEENTRY32);
if (!Module32First(snappy, &data)) {
CloseHandle(snappy);
std::cout << "not first module\n";
return NULL;
}
addy = (uintptr_t)data.modBaseAddr;
CloseHandle(snappy);
return addy;
}
int main()
{
HANDLE handle = FindProcess("blackops4.exe");
if (handle == NULL) {
std::cout << "Failed to find proc for BO4\n";
return 1;
}
std::cout << handle << std::endl;
auto base = FindProcessBase(handle);
if (base == NULL) {
std::cout << "BO4 module base is null\n";
return 1;
}
auto address = base + 0x26CB810;
std::cout << address << std::endl;
_CBuf_AddText CBuf_AddText = (_CBuf_AddText)address;
CBuf_AddText(0, "map zm_zodt8");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment