I use the method below to read bytes in memory. I want to read values ββin memory addresses that are very close to each other. I used to make individual calls for each byte in memory and add the result to the array using a for loop. It has become really inefficient, so instead I want to adapt the code below to read a large block of memory, and then try to iterate through the array to pull the desired bytes. I spent a little time trying to figure it out, but really struggling. FYI, this method reads a pointer, and then, if this value is a pointer, it reads that pointer and so on until it reaches a static address and then reads the byte value at that address.
[DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
private static extern byte ReadProcessMemoryByte(int Handle, int Address, ref byte Value, int Size, ref int BytesRead);
public static byte ReadPointerByte(string EXENAME, int Pointer, int[] Offset)
{
byte Value = 0;
checked
{
try
{
Process[] Proc = Process.GetProcessesByName(EXENAME);
if (Proc.Length != 0)
{
int Bytes = 0;
int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
if (Handle != 0)
{
foreach (int i in Offset)
{
ReadProcessMemoryInteger((int)Handle, Pointer, ref Pointer, 4, ref Bytes);
Pointer += i;
}
ReadProcessMemoryByte((int)Handle, Pointer, ref Value, 2, ref Bytes);
CloseHandle(Handle);
}
}
}
catch
{ }
}
return Value;
}
What I still have:
private void label1_Click(object sender, EventArgs e)
{
int[] valuesSeperated[200];
List<byte> PreArray = new List<byte>();
Process[] test = Process.GetProcessesByName("MyProcess");
int baseAddress = test[0].MainModule.BaseAddress.ToInt32();
byte ReadX = MyClass.ReadPointerByte("MyProcess", BaseAddress, new int[] { 0xc, 0x0, 0x2 });
PreArray.Add(ReadX);
byte[] PreArrayToInt = PreArray.ToArray();
int[] MYConvertedBytes = PreArray ToInt.Select(x => (int)x).ToArray();
foreach (int i in MYConvertedBytes)
{
valuesSeperated
}
string TestString = MYConvertedBytes[0].ToString();
label1.Text = TestString;
}
, : , (, 200 ) . , , , . , , - , , / .