I am trying desperately to convert this to C# language and I need some help. Here is what I have so far.
Code:
Process process = Process.GetProcessesByName("My Process").FirstOrDefault();
int address = 0x00B5CCB8;
int offset1 = 0x02;
int offset2 = 0xBD;
int bytesRead;
byte[] pointer = ProcessMemoryReaderApi.ReadMemory(process, address, 4, out bytesRead);
Using this works, but I don't know how to add the necessary offsets to the address. If someone could help me out with this one. That would be greatly appreciated.
Here is the class that I am using.
Code:
class ProcessMemoryReaderApi
{
// constants information can be found in <winnt.h>
[Flags]
public enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VMOperation = 0x00000008,
VMRead = 0x00000010,
VMWrite = 0x00000020,
DupHandle = 0x00000040,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
Synchronize = 0x00100000
}
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
[DllImport("kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hProcess);
public static byte[] ReadMemory(Process process, int address, int numOfBytes, out int bytesRead)
{
IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);
byte[] buffer = new byte[numOfBytes];
ReadProcessMemory(hProc, new IntPtr(address), buffer, numOfBytes, out bytesRead);
return buffer;
}
Thanks in advance.
PS. I would also like to have a message box that will show me the value that is returned when the address is read.
Assuming you are using .NET 4 you can use the IntPtr Add() and Subtract() methods. For example:
Code:
IntPtr baseAddr = new IntPrt(0x00B5CCB8);
IntPtr newAddr = IntPtr.Add(baseAddr, 0x02);
Hope that helps! Also, unless doing multiple reads on the same OpenProcess handle, you should probably call CloseHandle() after doing the Read in ReadMemory().
Include this overload method in the "ProcessMemoryReaderApi" class:
Code:
public static byte[] ReadMemory(Process process, IntPtr address, int numOfBytes, out int bytesRead)
{
IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);
byte[] buffer = new byte[numOfBytes];
ReadProcessMemory(hProc, address, buffer, numOfBytes, out bytesRead);
return buffer;
}
Quote:
Originally Posted by iCraziE
I got an error but i fixed it.. Everything is working now, I think.. theres no way for me to see what the returned value is.
Is there anyway to show the value that was read at the address? in a messagebox perhaps?
Sure, the returned value will be a byte array, assuming it was an integer you read from the memory you can use:
Code:
byte[] valueOut = ProcessMemoryReaderApi.ReadMemory(process, address, 4, out bytesRead);
int value = BitConverter.ToInt32(valueOut, 0);
MessageBox.Show("Value of Integer: " + value.ToString());
I hope it will be ill let you know, you've been a GREAT help!!
btw, my applications always say this.. whenever i execute them and then close it.
and lets say i try to rebuild it, rename the exe or delete it, if the target process is still open.
Ill get an error and it says the application is still open in the process execute.
is there anyway to stop this. Like make it so that when i close it, it will not stay attached to the target process?
would a simple application.exit() on the close form event do the trick? or is this just a helpless situation?
also it apparently attaches itself to the process, without me even opening it O_O.
and lastly not sure why, but its not returning the right value..
the value of the address changes everytime i move to a new area in the game. this function is supposed to tell me the value of the area that im in. for instance one place will have a value of 3, then if i move somewhere else it will have a new value, lets say 7. then if i go back to the first area, it will be 3 again. each area has its own value.
I know the address and offsets are correct because if i do this with autoit, it works perfectly fine. =/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace ShowMap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process myProcess = Process.GetProcessesByName("my process").FirstOrDefault();
int bytesRead;
IntPtr pointeraddr = new IntPtr(0x00B5CCB8);
IntPtr newaddr = IntPtr.Add(pointeraddr, 0x02);
IntPtr finalAddr = IntPtr.Add(newaddr, 0xBD);
byte[] valueOut = ProcessMemoryReaderApi.ReadMemory(myProcess, finalAddr, 4, out bytesRead);
int value2 = BitConverter.ToInt32(valueOut, 0);
MessageBox.Show("Value of Integer: " + value2.ToString());
}
}
}
[Help] Reading Pointer 07/31/2012 - C/C++ - 4 Replies recently i was learning to make dll for injection and i found this func code:
unsigned long ReadPointer(unsigned long ulBase, int iOffset)
{
__try { return *(unsigned long*)(*(unsigned long*)ulBase + iOffset); }
__except (EXCEPTION_EXECUTE_HANDLER) { return 0; }
}
for example :
addr = 0x0012345
[Vb.NET] WoW Memory Reading 11/20/2010 - World of Warcraft - 1 Replies Hallo,
Ist es irgendwie möglich mit VB.NET die Memory von WoW auszulesen wie bei C# mit der BlackMagic.dll
Danke m vorraus
[VB.NET] Need help - memory reading from pointer 09/03/2010 - .NET Languages - 2 Replies Hi,
i'm kinda beginner in memory editing, the only experience i got is vb6 and vb.net - and basic CE skills. However i could get the pointer and the offset for a memory address, it works, tested.
Next step is the reading of this value with a vb.net application. I have been googleing for 2 days, got some codes, wrote some by myself, but none of them seems to work.
Could anyone help me a bit?
Thank you,
Regards
Help with memory reading. C++. 06/12/2010 - Aion - 0 Replies Hello people, I'm kinda new to memory reading in c++. Been doing similiar stuff, and done some other stuff like packet hacks etc but anyway, to the issue.
I get weird values from AION when reading. And I'm prolly going about this totally wrong so I'll post you the code and hopefully some kind soul out there will point me in the right direction.
int address = 0xA82424;
int value;
DWORD pid;
if(!GameWindow)
{
VB.Net Memory Reading 11/03/2006 - .NET Languages - 0 Replies Basically I'm doing a course in VB.Net and I'm wondering if theres anyone here who can teach me or show me how to read memory values in my project. My course does not cover this, so I'm stuck with either self-research or asking questions.
If anyone can help then I'd be very grateful.
PS: The target game I'll be testing on is Conquer Online 2