Giter Club home page Giter Club logo

memory-hacking-class's Introduction

C++ Memory Hacking Class

Very easy to use class to read and modify other processes memory on Windows.
And the best thing is: it supports multi-level-pointers out of the box!

Example usage

#include "Memory.hpp"
using std::string;

int main() {
    SetConsoleTitle("Memory Class Test");
    char* TARGET_PROCESS_NAME = "League of Legends.exe";
    
    HANDLE processHandle;
    int baseAddress;
    
    //////////////////////////////////////////////////////////////////////////////////
    /* Note: These pointers/offsets are probably outdated by the time you read this */
    
    int GAME_VERSION_MODULE_OFFSET = 0x2A1D738;
    
    int PLAYERS_MODULE_OFFSET = 0x1DAAED4;
        int HEALTH_OFFSET = 0x124;
        int MANA_OFFSET = 0x190;
        
    //////////////////////////////////////////////////////////////////////////////////
    
    Memory Memory;
    Memory.GetDebugPrivileges();
    processId = Memory.GetProcessId(TARGET_PROCESS_NAME);
    processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
    
    baseAddress = Memory.GetModuleBase(processHandle, (string)TARGET_PROCESS_NAME);
    std::cout << "Base address for module \"" << TARGET_PROCESS_NAME << "\" is " << baseAddress << " (in dec)..."<< std::endl;
    
    int playersAddress =     baseAddress + PLAYERS_MODULE_OFFSET;
    int gameVersionAddress = baseAddress + GAME_VERSION_MODULE_OFFSET;
    
    int ptrOffset[] = {0x0}; //0x0 offset is for player one. 0x4 would be player 2 etc
    int playerOneAddress = Memory.ReadPointerInt(processHandle, playersAddress, ptrOffset, 1);
    
    float playerOneHealth = Memory.ReadFloat(processHandle, playerOneAddress + HEALTH_OFFSET);
    float playerOneMana =   Memory.ReadFloat(processHandle, playerOneAddress + MANA_OFFSET);
    
    string gameVersion = Memory.ReadText(processHandle, gameVersionAddress);
    
    std::cout << "Game version: " << gameVersionAddress << std::endl;
    std::cout << "Player one has " << playerOneHealth << " health!" std::endl;
    std::cout << "Player one has " << playerOneMana << " mana!" std::endl;
    
    cin.get();
    return 0;
}

memory-hacking-class's People

Contributors

t-vk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memory-hacking-class's Issues

Process Module Base Address not Being Obtained

So I'm trying to use this module, (specifically the GCC branch) and whenever I try to use the GetModuleBase function, it always returns -1. I have tried it with the example2 program, and it still has the same issue. If this is just me being dumb, please let me know, and if you don't feel like fixing it, do you have any other modules that you could recommend to use instead of this one?

System error 998 (ERROR_NOACCESS) when trying to read from memory.

Hi, I wanted to use your library for my purposes and I approached some issues. I figured out how to manage some of them. Mostly, I had to change some types, but the logic hasn't changed. However, when I finally made my code buildable and wanted to test it, I approached another issue which I couldn't manage on my own. I'm receiving system error 998 when trying to read from the memory.

Here's my code.

int main() {
    SetConsoleTitle("Memory Class Test");
    std::string TARGET_PROCESS_NAME = "test_app.exe";
    
    HANDLE processHandle;
    int64_t baseAddress;
    
    Memory Memory;
    Memory.GetDebugPrivileges();
    int processId = Memory.GetProcessId(const_cast<char*>(TARGET_PROCESS_NAME.c_str()));
    processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
    
    baseAddress = Memory.GetModuleBase(processHandle, TARGET_PROCESS_NAME);
    std::cout << "Base address for module \"" << TARGET_PROCESS_NAME << "\" is " << baseAddress << " (in dec)..."<< std::endl;

    std::cout << Memory.ReadInt(processHandle, baseAddress + 0x7FF648CF3000) << std::endl;
    
    return 0;
}

And here's yours with as few changes as possible. In this case, the only change I had to make was changing the dwBase variable type to int64_t. What caused a change in ReadInt function

int64_t Memory::GetModuleBase(HANDLE processHandle, string &sModuleName) 
{ 
    HMODULE *hModules = NULL; 
    char szBuf[50]; 
    DWORD cModules; 
    int64_t dwBase = -1;

    EnumProcessModules(processHandle, hModules, 0, &cModules); 
    hModules = new HMODULE[cModules/sizeof(HMODULE)]; 
    
    if(EnumProcessModules(processHandle, hModules, cModules/sizeof(HMODULE), &cModules)) { 
       for(size_t i = 0; i < cModules/sizeof(HMODULE); i++) { 
          if(GetModuleBaseName(processHandle, hModules[i], szBuf, sizeof(szBuf))) { 
             if(sModuleName.compare(szBuf) == 0) { 
                dwBase = reinterpret_cast<int64_t>(hModules[i]); 
                break; 
             } 
          } 
       } 
    } 
    
    delete[] hModules;
    return dwBase; 
}

int Memory::ReadInt(HANDLE processHandle, int64_t address) {
    if (address == -1)
        return -1;
    int buffer = 0;
    SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
    SIZE_T NumberOfBytesActuallyRead;
    BOOL success = ReadProcessMemory(processHandle, (LPCVOID)address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
    if (!success || NumberOfBytesActuallyRead != NumberOfBytesToRead) {
        std::cout << "Memory Error!" << std::endl;
        return -1;
    }
    //if (err || NumberOfBytesActuallyRead != NumberOfBytesToRead) {
	//	DWORD lastError = GetLastError();
	//	if (lastError != 0)
    //        std::cout << lastError << std::endl;
    //    std::cout << "blub" << std::endl;
	//}
    return buffer; 
}

Here you can see that my hard-coded address makes sense:
obraz

And here you can see the app's output:
obraz

Could you help me, please? I have no idea what am I doing wrong that I have no access to this memory. The test app is an easy app also prepared by me. Almost everything that's there is the initialisation of some variables and an infinite loop.

help me

C:\Users\arminblack\Desktop\Memory>g++ Program.cpp -static -o Program.exe
In file included from Program.cpp:3:0:
Memory.hpp:2:22: fatal error: stdafx.hpp: No such file or directory
#include "stdafx.hpp"
^
compilation terminated.

identifier "PROCESS_ALL_ACCESS" is undefined

Hi, I know this is oudated but i want to use it for something else, but I keep getting errors like this, how can I fix them?
processId is undefined
Process_All_Access is undefined
At line 33 initial value of reference to non-const must be an Ivalue

Different base address then process

This isn't an issue with your code but I had a question on its functionality and wasn't sure how else to ask you, I have a bit of an interesting situation.
My base address isn't the games .exe, since its code loaded through a .dll. So basically
I need to connect to my games .exe like normal, but I need to get the value at address game.dll + 0x4394 for example

Can I do this with your code? Can you provide an example of doing this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.