|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
nezoic How do I cheat? Reputation: 0
Joined: 25 Jul 2013 Posts: 4
|
Posted: Mon Jul 08, 2019 5:46 pm Post subject: C# A little help with conversions |
|
|
I've been able to get my pointer through 5 offsets in cheat engine and this works great, however it's a 64bit application and I'm running into some strange results when attempting to ReadProcessMemory in C#
When I step through it, the first ReadProcessMemory call sets BaseValue to -968473392. Where I expect it to be the address 1FBC64644D0 as it is in CE. Any help is appreciated.
Code: |
namespace ConsoleApp1
{
public class MemoryManager
{
const int PROCESS_WM_READ = 0x0010;
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess, Int64 lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
public MemoryManager()
{
Process process = Process.GetProcessesByName("XXXXXX_x64").FirstOrDefault();
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
var bytesRead = 0;
byte[] buffer = new byte[4];
Int64 pointer = IntPtr.Add(process.Modules[0].BaseAddress, 0x01DE8B78).ToInt64();
ReadProcessMemory((int)processHandle, pointer, buffer, buffer.Length, ref bytesRead);
Int64 baseValue = BitConverter.ToInt32(buffer, 0); // This is a negative integrer instead of "1FBC64644D0"
Int64 firstAddress = baseValue + 0x18;
ReadProcessMemory((int)processHandle, firstAddress, buffer, buffer.Length, ref bytesRead);
Int64 firstValue = BitConverter.ToInt32(buffer, 0);
|
|
|
Back to top |
|
|
atom0s Moderator Reputation: 199
Joined: 25 Jan 2006 Posts: 8518 Location: 127.0.0.1
|
Posted: Tue Jul 09, 2019 2:37 am Post subject: |
|
|
BitConverter.ToInt32 is wrong for this instance since you are working with 64bit values. You need to convert to 64bit values, not 32bit. Use ToInt64/ToUInt64 instead. _________________
- Retired. |
|
Back to top |
|
|
nezoic How do I cheat? Reputation: 0
Joined: 25 Jul 2013 Posts: 4
|
Posted: Tue Jul 09, 2019 9:25 am Post subject: |
|
|
atom0s wrote: | BitConverter.ToInt32 is wrong for this instance since you are working with 64bit values. You need to convert to 64bit values, not 32bit. Use ToInt64/ToUInt64 instead. |
Thanks, I also needed to change the byte[4] to byte[8], and leave the dwSize at 4. |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Tue Jul 09, 2019 10:26 am Post subject: |
|
|
also lpNumberOfBytesRead is 64 bit in 64-bit processes _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|