AutoHotkey.Interop.ClassMemory 1.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AutoHotkey.Interop.ClassMemory --version 1.0.1
NuGet\Install-Package AutoHotkey.Interop.ClassMemory -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoHotkey.Interop.ClassMemory" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoHotkey.Interop.ClassMemory --version 1.0.1
#r "nuget: AutoHotkey.Interop.ClassMemory, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AutoHotkey.Interop.ClassMemory as a Cake Addin
#addin nuget:?package=AutoHotkey.Interop.ClassMemory&version=1.0.1

// Install AutoHotkey.Interop.ClassMemory as a Cake Tool
#tool nuget:?package=AutoHotkey.Interop.ClassMemory&version=1.0.1

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.

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 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);

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.
Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated

Updated ClassMemory constructors; added ToString() to output ClassMemory instance name; removed unnecessary Serilog dependency; added AutoHotkey.Interop dependency; updated nuspec minimum version, description, and tags