|
You last visited: Today at 20:32
Advertisement
Wie mehrere Pointer in C# "nutzen" (float)?
Discussion on Wie mehrere Pointer in C# "nutzen" (float)? within the .NET Languages forum part of the Coders Den category.
02/18/2020, 13:14
|
#1
|
elite*gold: 110
Join Date: May 2010
Posts: 487
Received Thanks: 214
|
Wie mehrere Pointer in C# "nutzen" (float)?
Hi,
habe damit ein paar Probleme
Hier mein Code:
Code:
_mem mem = new _mem();
int[] offsetArr = { 0x684, 0xF4, 0xE0, 0x3C, 0x0, 0x17C, 0xFC };
MessageBox.Show(mem.ReadFloatPtr(0x017293C0, offsetArr).ToString());
_mem Class:
Code:
internal class _mem
{
enum AllocationType
{
Commit = 0x1000,
Reserve = 0x2000,
Decommit = 0x4000,
Release = 0x8000,
Reset = 0x80000,
Physical = 0x400000,
TopDown = 0x100000,
WriteWatch = 0x200000,
LargePages = 0x20000000
}
enum MemoryProtection
{
Proc_All_Access = 2035711,
}
[DllImport("Kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr handle, int address, byte[] bytes, int nsize, ref int op);
[DllImport("Kernel32.dll")]
public static extern bool WriteProcessMemory(IntPtr hwind, int Address, byte[] bytes, int nsize, out int output);
[DllImport("Kernel32.dll")]
public static extern IntPtr OpenProcess(int Token, bool inheritH, int ProcID);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, int lpAddress,
uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
const string ProcessName = "b0sted";
IntPtr rHandle = OpenProcess(0x10, false, Process.GetProcessesByName(ProcessName)[0].Id);
IntPtr wHandle = OpenProcess((int)MemoryProtection.Proc_All_Access, false, Process.GetProcessesByName(ProcessName)[0].Id);
//Reads a value then puts it into the BytesToRead var.
//Reads a string from memory
public string ReadString(int address, int nsize)
{
int Outp = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref Outp);
return System.Text.Encoding.ASCII.GetString(BytesToRead);
}
//Reads a integer value from memory
public int ReadInt(int address, int nsize)
{
int OP = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref OP);
return BitConverter.ToInt32(BytesToRead, 0);
}
//Reads A Float Value
public float ReadFloat(int address, int nsize)
{
int OP = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref OP);
return (float)BitConverter.ToSingle(BytesToRead, 0);
}
public void WriteINT(int address, int value)
{
byte[] Bytes = BitConverter.GetBytes(value);
int bytesWritten = 0;
WriteProcessMemory(wHandle, address, Bytes, Bytes.Length, out bytesWritten);
}
public void WriteFloat(int address, float value)
{
byte[] Bytes = BitConverter.GetBytes(value);
int BR = 0;
WriteProcessMemory(wHandle, address, Bytes, Bytes.Length, out BR);
}
//Read & Write to multi level pointers
public int ReadIntPtr(int address, int[] offsets, int Size = 4)
{
int MainAddress = address;
for (int i = 0; i < offsets.Length; i++)
{
MainAddress = ReadInt(MainAddress, Size) + offsets[i];
}
return MainAddress;
}
public void WriteIntPtr(int address, int[] offsets, int value)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
WriteINT(AddressToWriteToo, value);
}
public float ReadFloatPtr(int address, int[] offsets, int Size = 4)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
float Data = ReadFloat(AddressToWriteToo, 4);
return Data;
}
public void WriteFloatPtr(int address, int[] offsets, float value)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
WriteFloat(AddressToWriteToo, 0.0F);
}
public string ReadStringPtr(int address, int[] offsets, int ExspectedLength)
{
int AddressToRead = ReadIntPtr(address, offsets);
string TheString = ReadString(AddressToRead, ExspectedLength);
return TheString;
}
public void AllocateMemory(uint Amount, int[] offsets, int Address)
{
int AddressToAllocTo = ReadIntPtr(Address, offsets);
VirtualAllocEx(wHandle, AddressToAllocTo, Amount, AllocationType.Commit, MemoryProtection.Proc_All_Access);
}
public void WriteStringPtr(int address, int[] offsets, string value)
{
int BaseAddress = ReadIntPtr(address, offsets);
byte[] Data = System.Text.UnicodeEncoding.ASCII.GetBytes(value);
int o = 0;
WriteProcessMemory(wHandle, address, Data, Data.Length, out o);
}
}
Es kommt als Result immer "0" raus.
Es wäre super wenn mir jemand helfen könnte.
|
|
|
02/18/2020, 22:13
|
#2
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
|
Quote:
Originally Posted by b0sted
Hi,
habe damit ein paar Probleme
Hier mein Code:
Code:
_mem mem = new _mem();
int[] offsetArr = { 0x684, 0xF4, 0xE0, 0x3C, 0x0, 0x17C, 0xFC };
MessageBox.Show(mem.ReadFloatPtr(0x017293C0, offsetArr).ToString());
_mem Class:
Code:
internal class _mem
{
enum AllocationType
{
Commit = 0x1000,
Reserve = 0x2000,
Decommit = 0x4000,
Release = 0x8000,
Reset = 0x80000,
Physical = 0x400000,
TopDown = 0x100000,
WriteWatch = 0x200000,
LargePages = 0x20000000
}
enum MemoryProtection
{
Proc_All_Access = 2035711,
}
[DllImport("Kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr handle, int address, byte[] bytes, int nsize, ref int op);
[DllImport("Kernel32.dll")]
public static extern bool WriteProcessMemory(IntPtr hwind, int Address, byte[] bytes, int nsize, out int output);
[DllImport("Kernel32.dll")]
public static extern IntPtr OpenProcess(int Token, bool inheritH, int ProcID);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, int lpAddress,
uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
const string ProcessName = "b0sted";
IntPtr rHandle = OpenProcess(0x10, false, Process.GetProcessesByName(ProcessName)[0].Id);
IntPtr wHandle = OpenProcess((int)MemoryProtection.Proc_All_Access, false, Process.GetProcessesByName(ProcessName)[0].Id);
//Reads a value then puts it into the BytesToRead var.
//Reads a string from memory
public string ReadString(int address, int nsize)
{
int Outp = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref Outp);
return System.Text.Encoding.ASCII.GetString(BytesToRead);
}
//Reads a integer value from memory
public int ReadInt(int address, int nsize)
{
int OP = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref OP);
return BitConverter.ToInt32(BytesToRead, 0);
}
//Reads A Float Value
public float ReadFloat(int address, int nsize)
{
int OP = 0;
byte[] BytesToRead = new byte[nsize];
ReadProcessMemory(rHandle, address, BytesToRead, BytesToRead.Length, ref OP);
return (float)BitConverter.ToSingle(BytesToRead, 0);
}
public void WriteINT(int address, int value)
{
byte[] Bytes = BitConverter.GetBytes(value);
int bytesWritten = 0;
WriteProcessMemory(wHandle, address, Bytes, Bytes.Length, out bytesWritten);
}
public void WriteFloat(int address, float value)
{
byte[] Bytes = BitConverter.GetBytes(value);
int BR = 0;
WriteProcessMemory(wHandle, address, Bytes, Bytes.Length, out BR);
}
//Read & Write to multi level pointers
public int ReadIntPtr(int address, int[] offsets, int Size = 4)
{
int MainAddress = address;
for (int i = 0; i < offsets.Length; i++)
{
MainAddress = ReadInt(MainAddress, Size) + offsets[i];
}
return MainAddress;
}
public void WriteIntPtr(int address, int[] offsets, int value)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
WriteINT(AddressToWriteToo, value);
}
public float ReadFloatPtr(int address, int[] offsets, int Size = 4)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
float Data = ReadFloat(AddressToWriteToo, 4);
return Data;
}
public void WriteFloatPtr(int address, int[] offsets, float value)
{
int AddressToWriteToo = ReadIntPtr(address, offsets);
WriteFloat(AddressToWriteToo, 0.0F);
}
public string ReadStringPtr(int address, int[] offsets, int ExspectedLength)
{
int AddressToRead = ReadIntPtr(address, offsets);
string TheString = ReadString(AddressToRead, ExspectedLength);
return TheString;
}
public void AllocateMemory(uint Amount, int[] offsets, int Address)
{
int AddressToAllocTo = ReadIntPtr(Address, offsets);
VirtualAllocEx(wHandle, AddressToAllocTo, Amount, AllocationType.Commit, MemoryProtection.Proc_All_Access);
}
public void WriteStringPtr(int address, int[] offsets, string value)
{
int BaseAddress = ReadIntPtr(address, offsets);
byte[] Data = System.Text.UnicodeEncoding.ASCII.GetBytes(value);
int o = 0;
WriteProcessMemory(wHandle, address, Data, Data.Length, out o);
}
}
Es kommt als Result immer "0" raus.
Es wäre super wenn mir jemand helfen könnte.
|
U should pop the last offset before reading the float value
Code:
public float ReadFloatPtr(int address, int[] offsets, int Size = 4)
{
//here goes your code to remove last element from int array
lastOffset = offsets.last //remove last element from pointer map
int AddressToWriteToo = ReadIntPtr(address, offsets);
float Data = ReadFloat(AddressToWriteToo + lastOffset, 4);
return Data;
}
Here is my implementation in python if you want to take a look:
|
|
|
All times are GMT +1. The time now is 20:34.
|
|