yepturkish
Diamond Üye
- Katılım
- 26 Ağu 2022
- Mesajlar
- 454
- Beğeniler
- 113
- Yaş
- 22
C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
namespace CEZA_EXAMPLE
{
public class memory
{
public static class imports
{
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int Process, UInt64 Address, byte[] Buffer, int BufferSize, ref int ByteCount);
[DllImport("kernel32.dll")]
public static extern bool WriteProcessMemory(int Process, Int64 Address, byte[] Buffer, int BufferSize, out int ByteCount);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int DesiredAccess, bool InheritHandle, int ProcessID);
}
public static Process HandleCSGO()
{
rehandle:
Process CS;
if (Process.GetProcessesByName("cs2").Length > 0)
CS = Process.GetProcessesByName("cs2")[0];
else
return null;
foreach (ProcessModule module in CS.Modules)
{
string moduleName = module.ModuleName;
switch (moduleName)
{
case "client.dll":
client = (ulong)module.BaseAddress;
break;
case "engine2.dll":
engine2 = (long)module.BaseAddress;
break;
default:
break;
}
}
processHandle = (int)imports.OpenProcess(0x1F0FFF, false, CS.Id); // 0x1F0FFF for all access rights
if (processHandle > 0 && client != 0 && engine2 != 0)
{
return CS;
}
else
{
goto rehandle;
}
}
public static int processHandle = 0;
public static UInt64 client;
public static Int64 engine2;
public static int byteswritten = 0;
public static int bytesread = 0;
public static T Read<T>(UInt64 Address) where T : struct
{
int ByteSize = Marshal.SizeOf(typeof(T));
byte[] Buffer = new byte[ByteSize];
imports.ReadProcessMemory(processHandle, Address, Buffer, Buffer.Length, ref bytesread);
return ByteArrayToStructure<T>(Buffer);
}
public static float[] ReadMatrix<T>(long Adress, long MatrixSize) where T : struct
{
var ByteSize = Marshal.SizeOf(typeof(T));
byte[] buffer = new byte[ByteSize * MatrixSize];
imports.ReadProcessMemory((int)processHandle, (ulong)Adress, buffer, buffer.Length, ref bytesread);
return ConvertToFloatArray(buffer);
}
public static string ReadString(UInt64 memaddress, int len, bool unicode)
{
byte[] byteinfo = new byte[len];
int read = 0;
imports.ReadProcessMemory(processHandle, memaddress, byteinfo, len, ref read);
if (read == len)
{
int End = 0;
for (int i = 0; i < byteinfo.Length; i++)
{
if (byteinfo[i] == 0)
{
End = i;
break;
}
}
byte[] FinalString = new byte[End];
Buffer.BlockCopy(byteinfo, 0, FinalString, 0, End);
if (unicode)
{
return Encoding.Unicode.GetString(FinalString);
}
else
{
return Encoding.ASCII.GetString(FinalString);
}
}
return "";
}
public static void Write<T>(Int64 Address, object Value) where T : struct
{
byte[] Buffer = StructureToByteArray(Value);
imports.WriteProcessMemory(processHandle, Address, Buffer, Buffer.Length, out byteswritten);
}
private static T ByteArrayToStructure<T>(byte[] Bytes) where T : struct
{
GCHandle var_Handle = GCHandle.Alloc(Bytes, GCHandleType.Pinned);
try { return (T)Marshal.PtrToStructure(var_Handle.AddrOfPinnedObject(), typeof(T)); }
finally { var_Handle.Free(); }
}
private static byte[] StructureToByteArray(object Object)
{
int Length = Marshal.SizeOf(Object);
byte[] Array = new byte[Length];
IntPtr Pointer =
Marshal.AllocHGlobal(Length);
Marshal.StructureToPtr(Object, Pointer, true);
Marshal.Copy(Pointer, Array, 0, Length);
Marshal.FreeHGlobal(Pointer);
return Array;
}
public static float[] ConvertToFloatArray(byte[] bytes)
{
if (bytes.Length % 4 != 0)
throw new ArgumentException();
float[] floats = new float[bytes.Length / 4];
for (var i = 0; i < floats.Length; i++)
floats[i] = BitConverter.ToSingle(bytes, i * 4);
return floats;
}
}
}
Kullanım örneği:
UInt64 LocalPlayer = Read<UInt64>(client + (ulong)offsets.dwLocalPlayer);
UIn32 LocalHealth = Read<UInt32>(local + (ulong)offsets.m_iHealth);
Son düzenleme: