Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


I cannot read the value of a pointer in C#

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AnonTakesOver
How do I cheat?
Reputation: 0

Joined: 12 May 2014
Posts: 2

PostPosted: Mon May 12, 2014 8:00 am    Post subject: I cannot read the value of a pointer in C# Reply with quote

Okay, I have searched this forum, and allot of people post this.. but allot of the answers are specific to their problem. So it's hard for me to mix it up for my goal. I am learning how to use memory etc in C#, I am able to write memory to the game I am hacking, I just need to read the value of a static pointer, I can't really post my code, because well, I don't have any to show, but I am using this I got off a tutorial, I used it to write memory which works:
pastebin*.*com/ZeQ3mqPv

Any help will be gratefully appreciated, I have searched for a few hours now, tried many ways, some ways didn't work, so ways returned a value, which didn't even exist because I would search cheat engine the value it returned and I would get no results.
Back to top
View user's profile Send private message
zm0d
Master Cheater
Reputation: 7

Joined: 06 Nov 2013
Posts: 423

PostPosted: Mon May 12, 2014 9:10 am    Post subject: Reply with quote

P/Invoke for the function you need to use:
http://pinvoke.net/default.aspx/kernel32/ReadProcessMemory.html

MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms680553%28v=vs.85%29.aspx

You can simple read the value of an address with this function provided by the Win-API.
Back to top
View user's profile Send private message
ProjectEz
Newbie cheater
Reputation: 0

Joined: 03 Dec 2011
Posts: 18
Location: Phlippines

PostPosted: Mon May 12, 2014 9:43 am    Post subject: Reply with quote

hello, i am also creating a trainer for a game, and its just 2 weeks since i started studying memory scanning, luckily using C# too...
just to make it clear, you want to read memory from a pointer?
the once with base address and offsets, right?
or you just want to read memory from an address?
coz i got the code for reading values from addresses

edit * here it is, this is in float, so if you want int, just change those floats to int
Code:

        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] float[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);

        public static float[] ReadMemory(Process process, int address, int numOfBytes, out int bytesRead)
        {
            IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);

            float[] buffer = new float[numOfBytes];

            ReadProcessMemory(hProc, new IntPtr(address), buffer, numOfBytes, out bytesRead);
            return buffer;
        }

        public static float ReadValue(string baseAdd, int ProcID)
        {

           //here you call the process ID, you can change by processName
            Process mProc = Process.GetProcessById(ProcID);
            int address = Convert.ToInt32(baseAdd, 16);
            int bytesRead;
            float[] value = ReadMemory(mProc, address, 4, out bytesRead);
            return value[0];
        }



so here is how you call the process
Code:

            txtAddressVal.Text = ReadValue(Address,processID).ToString();


hope this helps Smile
Back to top
View user's profile Send private message
AnonTakesOver
How do I cheat?
Reputation: 0

Joined: 12 May 2014
Posts: 2

PostPosted: Mon May 12, 2014 5:06 pm    Post subject: Reply with quote

Hey, it works! I love you! But.... it's in float form, so it's like 1.25473E-43
That's an example, it's pretty much that.

How do I convert this to it's original form, as a string.
Back to top
View user's profile Send private message
ProjectEz
Newbie cheater
Reputation: 0

Joined: 03 Dec 2011
Posts: 18
Location: Phlippines

PostPosted: Tue May 13, 2014 8:13 am    Post subject: Reply with quote

i dont know how to make it string, but I remember doing it in bytes first, i would be glad if we can discuss about these, for I am doing and studying same topics,
please add me Smile fb(dot)com/kai.ecollidex
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed May 14, 2014 3:48 am    Post subject: Reply with quote

Why are you reading it as a float array?
use that prototype
Code:

        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);

when you get the result, use BitConvert.ToInt32 with the byte array
then use it however you want

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites