Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 01:00

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



ReadProcessMemory Break after 3 times.

Discussion on ReadProcessMemory Break after 3 times. within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Aug 2012
Posts: 62
Received Thanks: 39
ReadProcessMemory Break after 3 times.

So this was all working fine before I did something and for the life of me I can't figure out what I did that may have caused this issue to occur, I've been sat here for the past few hours trying to figure it out with no luck. Basically, this will read everything fine the first 3 times then after that it will break. I've managed to narrow down the issue to it being the ReadProcessMemory.

This is the ReadProcessMemory function I've got.
Code:
        [DllImport("kernel32.dll")]
        public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);

This is the function to find the address from multi level pointers.
Code:
        private int findAddress(int[] offsetArray)
        {
            byte[] buffer = new byte[4];
            int arrayPosition = 0;
            IntPtr bytesRead;
            //IntPtr processHandle = Memory.pHandle;
            int address = findBaseAddress();

            foreach (int i in offsetArray)
            {
                if (arrayPosition != offsetArray.Length - 1)
                {
                    Memory.ReadProcessMemory(procHandle, (IntPtr)address+i, buffer, 4, out bytesRead);
                    address = BitConverter.ToInt32(buffer, 0);
                    arrayPosition++;
                }
                else
                {
                    address += i;
                }
            }
            string hexValue = address.ToString("X");
            return address;
        }
This is where I use the function:
Code:
        private string HPValue()
        {
            int pointer = findAddress(new int[] { 0x00B1BC0C, 0x0, 0x190, 0x290 });
            byte[] buffer = new byte[4];
            IntPtr ptrBytesRead;

            Memory.ReadProcessMemory(procHandle, (IntPtr)pointer, buffer, 4, out ptrBytesRead);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }
There is a timer which calls the HPValue function every second or so.
dragonluck4 is offline  
Old 05/19/2015, 00:20   #2
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
use the to get more details about the error
tolio is offline  
Thanks
1 User
Old 05/19/2015, 00:53   #3
 
elite*gold: 0
Join Date: Aug 2012
Posts: 62
Received Thanks: 39
Quote:
Originally Posted by tolio View Post
use the to get more details about the error

Hey thanks for your reply appreciate it. I tried to do this but it seems like there is no error. The value is 0 which when I looked it up means operation completed successfully.

For your information, this is where I placed the checks.

Code:
        private int findAddress(int[] offsetArray)
        {
            int error = Marshal.GetLastWin32Error();
            byte[] buffer = new byte[4];
            int arrayPosition = 0;
            IntPtr bytesRead;
            //IntPtr processHandle = Memory.pHandle;
            int address = findBaseAddress();

            foreach (int i in offsetArray)
            {
                if (arrayPosition != offsetArray.Length - 1)
                {
                    Memory.ReadProcessMemory(procHandle, (IntPtr)address+i, buffer, 4, out bytesRead);
                    address = BitConverter.ToInt32(buffer, 0);
                    arrayPosition++;
                }
                else
                {
                    address += i;
                }
            }
            error = Marshal.GetLastWin32Error();
            MessageBox.Show(error.ToString());
            string hexValue = address.ToString("X");
            r
Code:
        private string HPValue()
        {
            int pointer = findAddress(new int[] { 0x00B1BC0C, 0x0, 0x190, 0x290 });
            byte[] buffer = new byte[4];
            IntPtr ptrBytesRead;

            Memory.ReadProcessMemory(procHandle, (IntPtr)pointer, buffer, 4, out ptrBytesRead);
            string test = BitConverter.ToInt32(buffer, 0).ToString();
            int error = Marshal.GetLastWin32Error();
            MessageBox.Show(error.ToString());
            return test;
        }
dragonluck4 is offline  
Old 05/19/2015, 01:16   #4
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
Did you set the in the import?
tolio is offline  
Thanks
1 User
Old 05/19/2015, 01:28   #5
 
elite*gold: 0
Join Date: Aug 2012
Posts: 62
Received Thanks: 39
Quote:
Originally Posted by tolio View Post
Did you set the in the import?
Ah, I had not no. I just tested it out, I set the last error attribute to true and I got error got 6.

ERROR_INVALID_HANDLE
6 (0x6)
The handle is invalid.

I've no idea what this means though.
dragonluck4 is offline  
Old 05/19/2015, 01:36   #6
 
Biesi's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 182
Received Thanks: 185
Every process has a handle so you can access it. Can you show the part where
Code:
procHandle
is declared and/or defined?
Biesi is offline  
Thanks
1 User
Old 05/19/2015, 01:53   #7
 
elite*gold: 0
Join Date: Aug 2012
Posts: 62
Received Thanks: 39
Defined near the top of the class:
Code:
Process[] myProcess;
Set here:
Code:
        private void timerGame_Tick(object sender, EventArgs e)
        {
            myProcess = Process.GetProcessesByName("Raiderz");
            if (myProcess.Length != 0)
            {
                IsGameAvailable = true;
                procHandle = myProcess[0].Handle;
                Memory.pHandle = myProcess[0].Handle;

                toolText.Text = "Status: Successfully Fused with RaiderZ!";
                timerGame.Stop();

                numericJumpDistance.Value = (decimal)jumpDistance();
                numericZoomDistance.Value = (decimal)zoomDistance();
            }
            else
            {
                IsGameAvailable = false;
                toolText.Text = "Status: Waiting for RaiderZ.";
            }
        }
This is the function which finds the base, it's called everytime a multi-level pointer base address is located:
Code:
        private int findBaseAddress()
        {
            try
            {
                myProcess = Process.GetProcessesByName("Raiderz");

                foreach (ProcessModule M in myProcess[0].Modules)
                {
                    if (M.ModuleName == "Raiderz.exe")
                    {
                        int baseAddress = M.BaseAddress.ToInt32();
                        //string hexValue = baseAddress.ToString("X");
                        return baseAddress;
                    }
                    break;
                }
                return -1;
            }
            catch
            {
                timerUpdate.Stop();
                timerGame.Start();
                return -1;
            }
        }
dragonluck4 is offline  
Old 05/19/2015, 02:15   #8
 
Biesi's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 182
Received Thanks: 185
Are you running your application with administrator privileges or UAC disabled?
Biesi is offline  
Old 05/19/2015, 02:27   #9
 
elite*gold: 0
Join Date: Aug 2012
Posts: 62
Received Thanks: 39
I'm running it with UAC disabled.

Thanks guys, you helped me solve the issue.

Actually the issue isn't solved entirely. The process handle keeps changing for some reason? I don't know if it is meant to keep changing. I don't think it did before?

Alright never mind I fixed it
dragonluck4 is offline  
Old 05/20/2015, 19:26   #10
 
YatoDev's Avatar
 
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
i just want to add that in some cases it helps to reopen the process on every read
YatoDev is offline  
Reply


Similar Threads Similar Threads
ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" Problem
03/06/2012 - .NET Languages - 9 Replies
Deleted



All times are GMT +1. The time now is 01:01.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.