[C++] - Beginner Tutorial: Creating a Simple Memory Editor

Discussion in 'Tutorials & Source Codes' started by paull40, Sep 14, 2018.

  1. paull40

    paull40 United States Fanatic Hacker

    Post Count:
    Likes Received:
    C++ - Beginner Tutorial: Creating a Simple Memory Editor


    Hello everyone, it's Paull40 here. Because I have a little bit of free time on my hands, I just wanted to post a beginners tutorial on how to create a simple memory editor in c++.


    In this tutorial, I will use no 3rd-party libraries or modules except for the Windows API. The Windows API is needed to overwrite variable memory addresses with new values. it is also worthy to note that you will need a memory reading program (e.g. Cheat engine) to find the exact address of a specific variable you want to change the value of. You may be wondering, what's the point of making a memory editor if we can just use cheat engine to read and overwrite a variable's value? There are multiple answers to this valid question the first being, it is good practice for people who want to get into game hacking. As the title says, this is a beginners tutorial. If you're a professional programmer with a lot of experience, this post probably isn't for you. The second reason being, although we are using cheat engine to find variable addresses, we are not using cheat engine to rewrite the variables we want to change the value of. Therefore, creating this program gives us a sense/feeling of complete ownership which allows us to move out the script kiddie phase and onto a more mature level. And finally, it's fun! Learning how to make programs is what makes me spend days in and days out programming and learning new things about computer science. I hope you have this attitude as well :) Anyways, enough talk! Let's begin.

    P.S. code will be in bold and we will use visual studios to write, compile, and execute our program

    1) Step 1: include both the iostream preprocessor directive as well as the windows api. Also, we will utilize a prototyping like programming methodology for rapid programming via including the std namespace

    #include <iostream>
    #include <windows.h>

    using namespace std;

    // We included the iostream preprocessor directive to perform console I/O (i.e. cout and cin)
    // We included the win32 API or windows API (I believe win32 API is an obsolete term) to utilize
    // specific functions that perform process memory writing features
    // These are the windows API functions we will use
    // 1) FindWindow()
    // 2) GetWindowThreadProcessId()
    // 3) OpenProcess()
    // 4) WriteProcessMemory()

    // These 4 functions are pretty self-explanatory but for those
    // of you who don't have the IQ to understand what a function does base on its name,
    // I'll go over what these functions do later in this tutorial :)

    2) Step 2: Create 5 global variables as shown

    DWORD pid;
    string addr;
    string wndt;
    string addr_with_prefix = "0x";
    int val;

    // DWORD is a data type provided by the Windows API and is simply an unsigned 32-bit integer object
    // pid is the id of the process we will we working with to change the value of some variable (e.g gold, exp, // level, etc)
    // addr is a variable we will use to store the address of the variable we want to change the value of
    // wndt is a variable that will be used to store the window title. (e.g. on Windows 10, the metro calculator app // is called "calculator"
    // addr_with_prefix = "0x" is variable with a defined string literal called 0x. Notice that we already have a
    // variable called addr. The difference between addr and this variable is that this variable will actually // concatenate or append to the end of addr_with_prefix the actual address of addr. I know it sounds
    // confusing right? It will make MUCH more sense when I actually show you the full code and explain as we // go on. But for now, just know that we will use the addr_with_prefix variable as our main variable later on. // addr you can view as a temporary variable that we will throw away (figuratively speaking) to the trash.
    // val is a variable that will capture the new value want to use (e.g. from 10 gold to like 1,000,000 gold)

    3) Step 3 (aka the program input phase): We will need input for all 5 of these globals

    cout << "Enter process window title: ";
    getline(cin, wndt);

    cout << "Enter a new value: ";
    cin >> val;

    cout << "Enter the address of the variable you want to change the value of: ";
    cin >> addr;

    addr_with_prefix += addr;

    // first 3 input instructions are pretty self-explanatory
    // the last instruction concatenates 0x with a variable address.
    // We append the address to 0x because it is the easiest way I can think of adding additional string
    // characters to the end of an already existing string literal. If there is a better method, feel free to leave it in
    // the comment section below :)

    Step 4: (aka the meat of the program!): Utilize the Windows API functions as previously mentioned to
    modify the value of whatever you want to modify!

    DWORD addr_dw = strtol(addr_with_prefix.c_str(), 0, 0);

    // create handle to a window
    // a handle is basically a pointer to a data structure.
    // call the FindWindow() function with the wndt variable as the only parameter
    // notice that wndt calls a function called c_str(). This is just because FindWindow()
    // doesn't actually identify with string data types but only with LPCSTR data types
    // as a result, we converted wndt from a string to a LPCSTR via c_str().
    HWND wHandle = FindWindow(0, (wndt.c_str()));

    // obtain process id of game
    // include the wHandle and &pid as parameters
    GetWindowThreadProcessId(wHandle, &pid);

    // create handle to a process
    // This function allows us to work with the process we want to hack the variable of
    HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

    // and finally let's rewrite the variable address
    // Write new data to process memory
    WriteProcessMemory(pHandle, (LPVOID)addr_dw, &val, sizeof(val), 0);

    // suspend the program and terminate it until your done
    return 0;

    // Wallah! Refresh the process and the value of the variable we want to change (i.e. Gold, exp, level, etc)
    // should now be changed!

    // this essentially the basic concept of how to create a memory editor in c++.
    // ending note: I forgot at the beginning of the tutorial to include the body of the code inside a main
    // function. Make sure to do so. This is important cause if you don't do it, your program will not work!

    Well I hope you guys had fun learning to create your very own memory editor! Thanks so much for your time. If you guys have any questions, feel free to post it below or DM me on gamekiller.net. I will post the source code without comments in this post.

    Bye Bye ~

    Source Code w/o comments:
    Slavy and Flash752 like this.

    Mr. Ad Advertisement

  2. ss3jin

    ss3jin United States Lurker

    Post Count:
    Likes Received:
    thanks for this
  3. Qgrbdudvs

    Qgrbdudvs Canada Lurker

    Post Count:
    Likes Received:
    Comment on hack pixel gun 3d

Share This Page

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies.
    Dismiss Notice
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies.
    Dismiss Notice