107 lines
3.3 KiB
Markdown
107 lines
3.3 KiB
Markdown
# EonaCat.MemoryManager
|
|
|
|
Process and Memory Management Library for .NET using EonaCat.MemoryManager.
|
|
|
|
#### Example Usage:
|
|
```Csharp
|
|
var procManager = new ProcessManager();
|
|
|
|
// Attach to process (e.g. "notepad")
|
|
string targetProcess = "notepad";
|
|
if (!procManager.Attach(targetProcess))
|
|
{
|
|
Console.WriteLine($"Failed to attach to {targetProcess}.");
|
|
return;
|
|
}
|
|
Console.WriteLine($"Attached to {targetProcess} (PID {procManager.Process.Id})");
|
|
|
|
var memManager = new MemoryManager(procManager.ProcessHandle);
|
|
|
|
IntPtr baseAddress = procManager.GetModuleBaseAddress(targetProcess + ".exe");
|
|
Console.WriteLine($"Base address: 0x{baseAddress.ToInt64():X}");
|
|
|
|
// Example offsets for pointer chaining (replace with real offsets)
|
|
int[] offsets = { 0x10, 0x20, 0x8 };
|
|
IntPtr pointerAddress = memManager.ReadPointer(baseAddress, offsets);
|
|
Console.WriteLine($"Pointer resolved to: 0x{pointerAddress.ToInt64():X}");
|
|
|
|
// --- 1. Read/Write unmanaged primitive (int) ---
|
|
int intVal = memManager.ReadValue<int>(pointerAddress);
|
|
Console.WriteLine($"Read int: {intVal}");
|
|
|
|
memManager.WriteValue(pointerAddress, 9999);
|
|
Console.WriteLine("Wrote int: 9999");
|
|
|
|
// --- 2. Read/Write managed struct ---
|
|
var vec3 = memManager.ReadStruct<Vector3>(pointerAddress);
|
|
Console.WriteLine($"Read Vector3: X={vec3.X}, Y={vec3.Y}, Z={vec3.Z}");
|
|
|
|
var newVec = new Vector3 { X = 1.1f, Y = 2.2f, Z = 3.3f };
|
|
memManager.WriteStruct(pointerAddress, newVec);
|
|
Console.WriteLine("Wrote new Vector3");
|
|
|
|
// --- 3. Read/Write strings ---
|
|
string asciiStr = memManager.ReadStringAscii(pointerAddress, 50);
|
|
Console.WriteLine($"Read ASCII string: {asciiStr}");
|
|
|
|
memManager.WriteStringAscii(pointerAddress, "Hello ASCII!");
|
|
Console.WriteLine("Wrote ASCII string: Hello ASCII!");
|
|
|
|
string unicodeStr = memManager.ReadStringUnicode(pointerAddress, 50);
|
|
Console.WriteLine($"Read Unicode string: {unicodeStr}");
|
|
|
|
memManager.WriteStringUnicode(pointerAddress, "Hello Unicode!");
|
|
Console.WriteLine("Wrote Unicode string: Hello Unicode!");
|
|
|
|
// --- 4. Read/Write array of floats ---
|
|
float[] floatArray = memManager.ReadArray<float>(pointerAddress, 5);
|
|
Console.WriteLine("Read float array:");
|
|
foreach (var f in floatArray) Console.WriteLine(f);
|
|
|
|
float[] newArray = { 9.9f, 8.8f, 7.7f, 6.6f, 5.5f };
|
|
memManager.WriteArray(pointerAddress, newArray);
|
|
Console.WriteLine("Wrote float array");
|
|
|
|
// --- 5. Non-generic Read/Write ---
|
|
object objVal = memManager.ReadValue(pointerAddress, typeof(Vector3));
|
|
Vector3 vecFromObj = (Vector3)objVal;
|
|
Console.WriteLine($"Non-generic read Vector3: X={vecFromObj.X}, Y={vecFromObj.Y}, Z={vecFromObj.Z}");
|
|
|
|
memManager.WriteValue(pointerAddress, newVec, typeof(Vector3));
|
|
Console.WriteLine("Non-generic wrote Vector3");
|
|
|
|
// Cleanup
|
|
procManager.Detach();
|
|
Console.WriteLine("Detached from process.");
|
|
}
|
|
|
|
// Example struct (must match memory layout)
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public class Vector3
|
|
{
|
|
public float X;
|
|
public float Y;
|
|
public float Z;
|
|
}
|
|
```
|
|
|
|
#### Notes:
|
|
Run your target process (e.g., Notepad).
|
|
|
|
Adjust the targetProcess variable to match your process name.
|
|
|
|
Replace the pointer offsets with valid ones for your target process.
|
|
|
|
Adjust the read/write addresses or pattern scan results accordingly.
|
|
|
|
#### This example covers:
|
|
|
|
Unmanaged primitive read/write (int)
|
|
|
|
Managed struct read/write (Vector3 class)
|
|
|
|
ASCII and Unicode string read/write
|
|
|
|
Array of unmanaged types (float) read/write
|
|
|
|
Non-generic object-based read/write |