AutoHotkey.Interop.ClassMemory 1.1.0

AutoHotkey.Interop.ClassMemory is a library for reading and writing integer and string values from and to specified addresses in memory.

Install-Package AutoHotkey.Interop.ClassMemory -Version 1.1.0
dotnet add package AutoHotkey.Interop.ClassMemory --version 1.1.0
<PackageReference Include="AutoHotkey.Interop.ClassMemory" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoHotkey.Interop.ClassMemory --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AutoHotkey.Interop.ClassMemory

AutoHotkey.Interop.ClassMemory is a library for reading and writing integer and string values from and to specified addresses in memory. It leverages @Kalamity's classMemory.ahk AutoHotkey library and Andrew Smith's AutoHotkey.Interop .NET library to provide read/write methods that are accurate and configurable yet very simple to implement.

Installation and/or knowledge of AutoHotkey is not required to use this library.

If you are looking for a NuGet package for only AutoHotkey.Interop, such a package does not exist. But since that library is a dependency of this one, installing this one is an easy way to get that functionality via NuGet. There is very little overhead from the additional memory functions, and this even includes some useful extensions for that library.

Usage and Examples

Instantiation

The recommended approach for instantiating ClassMemory is to use the ID of the process that you want to read from and/or write to. IDs can be found dynamically using various Process class methods or manually using Task Manager on the Details tab in the PID column.

var classMemory = new ClassMemory(86753);

Alternatively, you can instantiate ClassMemory using the name of the executable of the target process. This is not generally recommended as it can lead to ambiguous results if multiple instances of the executable are running simultaneously, but it can be a convenient shortcut in certain circumstances.

var classMemory = new ClassMemory("MyProcess.exe"); // Including ".exe" is allowed but not required

Addresses

Memory addresses consisting of a base address and zero or more offsets are required for each function to know where to read from or write to. The library includes an Address class for storing these addresses. Only relative addresses are supported.

var addressWithOffsets = new Address(0x6FE238, new [] { 0x104, 0xF8 });

var addressWithoutOffsets = new Address(0x6DD10C);

var addressWithProcessName = new Address("MyProcess.exe", 0x2FE238, new [] { 0x10C });

Base addresses are sometimes written as the executable name plus a hexidecimal integer (e.g. "MyProcess.exe+0x2FE238") instead of a purely numeric address. Instantiating an Address object with such values as demonstrated above will automatically calculate the required numeric base address for you.

Finding addresses will likely be the most challenging aspect of using this library. Though that is outside of the scope of this project, there are excellent freeware tools for doing so that are easy to find with a simple online search.

Reading

Integer functions are generic and feature a type parameter. Allowable types include byte, char, double, float, int, long, short, uint, and ushort.

// Read an int using an Address object.
var intReadResult = classMemory.Read<int>(myAddress);

// Read a float using individual address components.
var floatReadResult = classMemory.Read<float>(myBaseAddress, myOffsets);

String functions have optional parameters to specify the desired encoding and size of the string in bytes. Default values are "UTF-8" and 0, respectively. Size 0 is used to read the string until a null terminator is found.

// Read a string using individual address components and default settings.
var stringReadResult1 = classMemory.ReadString(0x6FE238, new [] { 0x104, 0xF8 });

// Read an 8-byte string using an Address object and UTF-16 encoding.
var stringReadResult2 = classMemory.ReadString(myAddress, "UTF-16", 8);

Writing

Write functions are very similar to reads but do not return a value and instead add a parameter to specify the value to write.

// Write an integer. The type parameter is inferred from the type of myNewValue.
classMemory.Write(myNewValue, myAddress.BaseAddress, myAddress.Offsets);

// Write a string. Encoding can still be specified but not size.
classMemory.WriteString("My new value", myAddress, myEncoding);

AutoHotkey.Interop Extensions

AutoHotkey Boolean variables are integral to many of the applications of this library. As such, it extends the AutoHotkeyEngine class to make it even easier to work with that specific type of variable:

// Get the value of an AutoHotkey Boolean variable
bool myBool = AutoHotkeyEngine.Instance.GetBool("myBoolInAhk");

// Set the value of an AutoHotkey Boolean variable
AutoHotkeyEngine.Instance.SetBool("myBoolInAhk", true);

Why AutoHotkey?

There are several other NuGets available for performing memory reads and writes that instead use native .NET functions. I tried the most popular few among them and found none that could match the combination of read accuracy, code quality, and implementation simplicity of classMemory.ahk. And AutoHotkey.Interop made it simple to integrate that desired functionality into my preferred development environment. Interoperability with AutoHotkey may seem like an extra complication, but the library takes care of any extra complexity behind the scenes for you to provide a simple but powerful toolset for performing memory operations in .NET.

Special thanks to @Kalamity and Andrew Smith for their contributions to the open source community!

Installation and/or knowledge of AutoHotkey is not required to use this library.

AutoHotkey.Interop.ClassMemory

AutoHotkey.Interop.ClassMemory is a library for reading and writing integer and string values from and to specified addresses in memory. It leverages @Kalamity's classMemory.ahk AutoHotkey library and Andrew Smith's AutoHotkey.Interop .NET library to provide read/write methods that are accurate and configurable yet very simple to implement.

Installation and/or knowledge of AutoHotkey is not required to use this library.

If you are looking for a NuGet package for only AutoHotkey.Interop, such a package does not exist. But since that library is a dependency of this one, installing this one is an easy way to get that functionality via NuGet. There is very little overhead from the additional memory functions, and this even includes some useful extensions for that library.

Usage and Examples

Instantiation

The recommended approach for instantiating ClassMemory is to use the ID of the process that you want to read from and/or write to. IDs can be found dynamically using various Process class methods or manually using Task Manager on the Details tab in the PID column.

var classMemory = new ClassMemory(86753);

Alternatively, you can instantiate ClassMemory using the name of the executable of the target process. This is not generally recommended as it can lead to ambiguous results if multiple instances of the executable are running simultaneously, but it can be a convenient shortcut in certain circumstances.

var classMemory = new ClassMemory("MyProcess.exe"); // Including ".exe" is allowed but not required

Addresses

Memory addresses consisting of a base address and zero or more offsets are required for each function to know where to read from or write to. The library includes an Address class for storing these addresses. Only relative addresses are supported.

var addressWithOffsets = new Address(0x6FE238, new [] { 0x104, 0xF8 });

var addressWithoutOffsets = new Address(0x6DD10C);

var addressWithProcessName = new Address("MyProcess.exe", 0x2FE238, new [] { 0x10C });

Base addresses are sometimes written as the executable name plus a hexidecimal integer (e.g. "MyProcess.exe+0x2FE238") instead of a purely numeric address. Instantiating an Address object with such values as demonstrated above will automatically calculate the required numeric base address for you.

Finding addresses will likely be the most challenging aspect of using this library. Though that is outside of the scope of this project, there are excellent freeware tools for doing so that are easy to find with a simple online search.

Reading

Integer functions are generic and feature a type parameter. Allowable types include byte, char, double, float, int, long, short, uint, and ushort.

// Read an int using an Address object.
var intReadResult = classMemory.Read<int>(myAddress);

// Read a float using individual address components.
var floatReadResult = classMemory.Read<float>(myBaseAddress, myOffsets);

String functions have optional parameters to specify the desired encoding and size of the string in bytes. Default values are "UTF-8" and 0, respectively. Size 0 is used to read the string until a null terminator is found.

// Read a string using individual address components and default settings.
var stringReadResult1 = classMemory.ReadString(0x6FE238, new [] { 0x104, 0xF8 });

// Read an 8-byte string using an Address object and UTF-16 encoding.
var stringReadResult2 = classMemory.ReadString(myAddress, "UTF-16", 8);

Writing

Write functions are very similar to reads but do not return a value and instead add a parameter to specify the value to write.

// Write an integer. The type parameter is inferred from the type of myNewValue.
classMemory.Write(myNewValue, myAddress.BaseAddress, myAddress.Offsets);

// Write a string. Encoding can still be specified but not size.
classMemory.WriteString("My new value", myAddress, myEncoding);

AutoHotkey.Interop Extensions

AutoHotkey Boolean variables are integral to many of the applications of this library. As such, it extends the AutoHotkeyEngine class to make it even easier to work with that specific type of variable:

// Get the value of an AutoHotkey Boolean variable
bool myBool = AutoHotkeyEngine.Instance.GetBool("myBoolInAhk");

// Set the value of an AutoHotkey Boolean variable
AutoHotkeyEngine.Instance.SetBool("myBoolInAhk", true);

Why AutoHotkey?

There are several other NuGets available for performing memory reads and writes that instead use native .NET functions. I tried the most popular few among them and found none that could match the combination of read accuracy, code quality, and implementation simplicity of classMemory.ahk. And AutoHotkey.Interop made it simple to integrate that desired functionality into my preferred development environment. Interoperability with AutoHotkey may seem like an extra complication, but the library takes care of any extra complexity behind the scenes for you to provide a simple but powerful toolset for performing memory operations in .NET.

Special thanks to @Kalamity and Andrew Smith for their contributions to the open source community!

Installation and/or knowledge of AutoHotkey is not required to use this library.

Release Notes

Added AutoHotkeyEngine extension methods for getting/setting AutoHotkey Boolean variables

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.0 52 9/19/2019
1.0.1 76 8/7/2019