Skip to content

hburn7/SimpleMem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleMem

The best general-purpose memory reader/writer for C#

Prerequisites

Getting Started

📌 Note: Manipulating memory in 64-bit applications requires your source to be compiled in x64.

If not known, find the name of the process you wish to hook into. The name found in this list that matches your target application is what we will refer to as the process name.

using SimpleMem;

// Prints all process names on your system.
Memory.PrintProcessList();

Find the name of the base module, if not known. This is typically the name of the process name and its extension, such as MyApplication.exe. This can also be a .dll module, if present in the Process.Modules list. Unity games do not work with SimpleMem due to mono.dll being external to the process.

Reading and Writing Memory

📌 For all memory examples we will use a made-up game, MyGame.

Open the application, in this case MyGame.exe.

Reading Memory

Create a new Memory object.

var mem = new Memory("MyGame"); // Your process name here

// Or, specify a module too. This module must exist within
// the process's "Modules" property (a ProcessModuleCollection object).
// See https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processmodulecollection?view=net-6.0
var mem = new Memory("MyGame", "mydll.dll");

To read the value located at a pointer in memory, create a pointer to the address and call ReadMemory() or ReadMemory<T>().

const int ADDRESS = 0xABCD123; // Your address here

// Example. Assumes "points" are located at ADDRESS and are stored as an int.
int points = mem.ReadMemory<int>(new IntPtr(ADDRESS));

Writing Memory

Using the same example above, say we want to overwrite the value.

const int ADDRESS = 0xABCD123; // Your address here
const int NEW_VALUE = 500;

var mem = new Memory("MyGame"); // Your process name here
int bytesRead = mem.WriteMemory(new IntPtr(ADDRESS), NEW_VALUE); // Replaces value at ADDRESS with NEW_VALUE

It's that easy!

Multi-Level Pointers

SimpleMem provides full support for reading addresses and values from base addresses and offsets.

First, find the module name - this can easily be found via Cheat Engine. This is almost always a .exe or .dll - make sure this is specified upon construction of Memory.

To identify pointer chains, Cheat Engine's pointer scanner feature can be used. More info can be found here. For this example, our desired value will rest at "MyGame.exe"+0x74DF02 -> 0x04 -> 0x28 where -> represents a pointer from one address to the next, as seen in Cheat Engine. The value read at the end of the pointer chain (...0x28) contains our desired value.

Pointer chain example

static class Offsets
{
    // For this example, "PlayerBase" refers to some arbitrary "player" data structure base address.
    public const int PlayerBase = 0x74DF02;

    // Offsets to locate desired value - "health" which is a float (in this example).
    // PlayerBase and 0x4 are both pointers in memory. 
    // 0xC is the offset at which our health float lays from the previous pointer.
    public static readonly MultiLevelPtr<float> PlayerHealth = new MultiLevelPtr<int>(PlayerBase, 0x4, 0xC);
}

public class Main
{
    private readonly Memory _mem;

    public Main()
    {
        // Don't specify .exe here
        _mem = new Memory("MyGame");
    }

    void ReadValueFromPointerChain()
    {
        // Traditional read
        int desiredValue = _mem.ReadValueFromMlPtr<int>(Offsets.PlayerHealth);
        
        // Using extensions
        int desiredValue = Offsets.PlayerHealth.Value(_mem);
        
        // Work with the value below...
    }

    void WriteValueToPointerChain()
    {
        // Assumes address at the end of the pointer chain is int.
        // This should be known by the programmer already.
        int newValue = 500;
        
        // Traditional write
        int address = _mem.ReadAddressFromMlPtr(Offsets.PlayerHealth);
        _mem.WriteMemory(address, newValue);
        
        // Using extensions
        Offsets.PlayerHealth.WriteValue(_mem, newValue);
    }
}

About

Simple memory manipulator for C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages