You last visited: Today at 13:02
Advertisement
[C#] Memory Class
Discussion on [C#] Memory Class within the Coding Snippets forum part of the Coding Releases category.
12/02/2013, 14:10
#1
elite*gold: 0
Join Date: Apr 2010
Posts: 10,289
Received Thanks: 3,613
[C#] Memory Class
Hey, hier mal meine simple xMemory Klasse für Einsteiger was Memory Editing angeht.
Code:
/*
* xMemory Class
* by Shawak
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
class xMemory
{
// Global Variable
public static IntPtr ProcessHandle = IntPtr.Zero;
// Native Functions
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr OpenProcess(int DesiredAccess, bool InheritHandle, int ProcessID);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr Handle);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool ReadProcessMemory(IntPtr ProcessHandle, IntPtr Address, ref byte[] Buffer, int Size, ref int NumberOfBytesRead);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool WriteProcessMemory(IntPtr ProcessHandle, IntPtr Address, byte[] Buffer, int Size, ref int NumberOfBytesWritten);
public static uint DELETE = 0x00010000;
public static uint READ_CONTROL = 0x00020000;
public static uint WRITE_DAC = 0x00040000;
public static uint WRITE_OWNER = 0x00080000;
public static uint SYNCHRONIZE = 0x00100000;
public static uint END = 0xFFF; //if you have Windows XP or Windows Server 2003 you must change this to 0xFFFF
public static uint PROCESS_ALL_ACCESS = (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END);
// API-Implentation
static internal bool OpenProcess(int PID)
{
xMemory.ProcessHandle = xMemory.OpenProcess((int)PROCESS_ALL_ACCESS, false, PID); // 0x1f0fff
return (xMemory.ProcessHandle == IntPtr.Zero ? false : true);
}
static internal bool CloseHandle()
{
if (xMemory.ProcessHandle == IntPtr.Zero)
return false;
return xMemory.CloseHandle(xMemory.ProcessHandle);
}
// Declarations
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemoryByte(IntPtr Handle, int Address, ref byte Value, int Size = 1);
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemoryShort(IntPtr Handle, int Address, ref short Value, int Size = 2);
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemoryInteger(IntPtr Handle, int Address, ref int Value, int Size = 4);
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemoryLong(IntPtr Handle, int Address, ref long Value, int Size = 8);
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemorySingle(IntPtr Handle, int Address, ref float Value, int Size = 4);
[DllImport("KERNEL32", EntryPoint = "ReadProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool ReadMemoryDouble(IntPtr Handle, int Address, ref double Value, int Size = 8);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemoryByte(IntPtr Handle, int Address, ref byte Value, int Size = 1);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemoryShort(IntPtr Handle, int Address, ref short Value, int Size = 2);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemoryInteger(IntPtr Handle, int Address, ref int Value, int Size = 4);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemoryLong(IntPtr Handle, int Address, ref long Value, int Size = 8);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemorySingle(IntPtr Handle, int Address, ref float Value, int Size = 4);
[DllImport("KERNEL32", EntryPoint = "WriteProcessMemory", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool WriteMemoryDouble(IntPtr Handle, int Address, ref double Value, int Size = 8);
// Read Functions
public static byte ReadByte(int Address, int Size = 1)
{
byte value = 0;
ReadMemoryByte(ProcessHandle, Address, ref value, Size);
return value;
}
public static short ReadShort(int Address, int Size = 2)
{
short value = 0;
ReadMemoryShort(ProcessHandle, Address, ref value, Size);
return value;
}
public static int ReadInteger(int Address, int Size = 4)
{
int value = 0;
ReadMemoryInteger(ProcessHandle, Address, ref value, Size);
return value;
}
public static long ReadLong(int Address, int Size = 8)
{
long value = 0;
ReadMemoryLong(ProcessHandle, Address, ref value, Size);
return value;
}
public static float ReadSingle(int Address, int Size = 8)
{
float value = 0;
ReadMemorySingle(ProcessHandle, Address, ref value, Size);
return value;
}
public static double ReadDouble(int Address, int Size = 8)
{
double value = 0;
ReadMemoryDouble(ProcessHandle, Address, ref value, Size);
return value;
}
public static string ReadString(int Address)
{
byte[] b = new byte[] { 0 };
string str = "";
bool ret = false;
do
{
ret = ReadMemoryByte(ProcessHandle, Address, ref b[0]);
Address += 0x1;
if (ret == true)
if (b[0] != 0)
str += System.Text.Encoding.UTF8.GetString(b);
} while (b[0] != 0);
return str;
}
// Write Functions
public static bool WriteByte(int Address, byte Value, int Size = 1)
{
return WriteMemoryByte(ProcessHandle, Address, ref Value, Size);
}
public static bool WriteShort(int Address, short Value, int Size = 2)
{
return WriteMemoryShort(ProcessHandle, Address, ref Value, Size);
}
public static bool WriteInteger(int Address, int Value, int Size = 4)
{
return WriteMemoryInteger(ProcessHandle, Address, ref Value, Size);
}
public static bool WriteLong(int Address, long Value, int Size = 8)
{
return WriteMemoryLong(ProcessHandle, Address, ref Value, Size);
}
public static bool WriteSingle(int Address, float Value, int Size = 8)
{
return WriteMemorySingle(ProcessHandle, Address, ref Value, Size);
}
public static bool WriteDouble(int Address, double Value, int Size = 8)
{
return WriteMemoryDouble(ProcessHandle, Address, ref Value, Size);
}
// Protection
[DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, uint flNewProtect, ref uint lpflOldProtect);
public object GetBytesLength(string str)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] bytes = enc.GetBytes(str);
return bytes.Length;
}
public static uint RemoveProtect(int Address, int BytesLength)
{
uint oldProtection = 0;
VirtualProtectEx(ProcessHandle, new IntPtr(Address), new IntPtr(BytesLength), 0x40, ref oldProtection);
return oldProtection;
}
public static bool AddProtect(int Address, int BytesLength, uint oldProtection)
{
VirtualProtectEx(ProcessHandle, new IntPtr(Address), new IntPtr(BytesLength), oldProtection, ref oldProtection);
return true;
}
}
Have fun =)
Lg
12/18/2013, 18:44
#2
elite*gold: 60
Join Date: Aug 2012
Posts: 227
Received Thanks: 79
Usefull keep going man
Similar Threads
KDMemory (C# 32 & 64 Bit)
08/15/2023 - Coding Releases - 4 Replies
Features:
Full support for 32 and 64 bit applications.
Access all existing processes with the same name (multi clients).
Everything is documented (inline documentation).
Offsets can be used by just adding an array containing all offsets to the constructor.
Possibility to use module names with a static offset (e.g. '"Tutorial-x86_64.exe"+002C7710').
TODO:
[C++] Memory Class
07/29/2011 - CO2 Programming - 2 Replies
.
Quick Memory Editor - Alternative Memory Hacking Software
11/21/2009 - Cabal Hacks, Bots, Cheats, Exploits & Macros - 11 Replies
This might be detected or not by GameGuard, I have not tested this on Official servers however it worked perfectly fine on other private servers.
http://imagenic.net/images/x0jxwzwpg2zxmkdtcf36.p ng
This is just an alternative memory editing tool.
Press thanks if this helps.
Remember, scan before using this.
Cause its 5.5MB.
All times are GMT +2. The time now is 13:02 .