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 


[VB.NET] Problem with multi lvl pointers

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

Joined: 20 Jul 2008
Posts: 6

PostPosted: Tue Jul 29, 2008 5:23 pm    Post subject: [VB.NET] Problem with multi lvl pointers Reply with quote

Hello,

i've been hacking games for a little while now and decided to learn
how to find my own addresses. Up until now I used addresses posted
on other forums. I'm now working on a trainer I intend to release here
but I have this problem.

I have no trouble finding addresses or pointers, however when I try to
code a hack that has multi lvl pointers, I don't know what to do. I tried
using base pointer but when I test my hack the game crashes. The first
lvl pointer works but since it's not static my hack won't work after the
game closes.

Could someone help me out?
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jul 29, 2008 11:18 pm    Post subject: Reply with quote

You want to start at the static address you hopefully followed the pointer down to. Then, just ReadProcessMemory on it, do whatever you need to with the offset, and repeat until you're done.
Back to top
View user's profile Send private message
yoodidoo
How do I cheat?
Reputation: 0

Joined: 20 Jul 2008
Posts: 6

PostPosted: Wed Jul 30, 2008 12:34 pm    Post subject: Reply with quote

Sorry if I ask a lot of questions sometimes, I don't like to
but i'm trying my best to understand so I can make projects
on my own.

I've never used the ReadProcessMemory function before, or any
Read function for that matter, so if you or someone could elaborate
for me or point me to a tut I would GREATLY appreciate it.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 30, 2008 5:42 pm    Post subject: Reply with quote

It would help a lot if you had some ground to stand on when it came to the Win32 API, which we're going to have to make use of.

MSDN and pinvoke.net are going to be your best friends here.

Here's some of what MSDN has to say about ReadProcessMemory.

Code:
BOOL WINAPI ReadProcessMemory(
  __in   HANDLE hProcess,
  __in   LPCVOID lpBaseAddress,
  __out  LPVOID lpBuffer,
  __in   SIZE_T nSize,
  __out  SIZE_T *lpNumberOfBytesRead
);


... and the pinvoke signature since we're using .NET:

Code:
<DllImport("kernel32.dll")> _
       Public Shared Function ReadProcessMemory( _
        ByVal hProcess As IntPtr, _
        ByVal lpBaseAddress As IntPtr, _
        ByVal lpBuffer As Byte(), _
        ByVal iSize As UInt32, _
        ByRef lpNumberOfBytesRead As UInt32 _
) As Boolean
    End Function


As you can see, it needs a handle to the process you plan on using. Thankfully .NET has a pretty simple way of doing this.

Take a look at the: System.Diagnostics.Process class
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

Look through the methods, and sure enough we will come across something that looks like just what we need.
http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx

It returns a Process array, so you can just do something like:
Code:
Dim p As Process() = Process.GetProcessesByName("winmine")


Now we can just call ReadProcessMemory.

The end result (which will read the timer on minesweeper):

Code:
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("kernel32.dll")> _
       Public Shared Function ReadProcessMemory( _
        ByVal hProcess As IntPtr, _
        ByVal lpBaseAddress As IntPtr, _
        ByVal lpBuffer As Byte(), _
        ByVal iSize As UInt32, _
        ByRef lpNumberOfBytesRead As UInt32 _
) As Boolean
    End Function

    Dim p As Process() = Process.GetProcessesByName("winmine")
    Dim buffer As Byte() = New Byte(0) {}
    Dim bytesRead As UInt32 = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        ReadProcessMemory(p(0).Handle, &H100579C, buffer, 1, bytesRead)
        textBox1.Text = BitConverter.ToString(buffer)
    End Sub

End Class


... and there you have it. An example as to get setup, and read a value.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Jul 30, 2008 5:46 pm    Post subject: Reply with quote

Uhh, not quite, Slovach.

You're creating a byte[] with size 0, and asking to read 0 bytes. You're just gonna get null from the bit converter.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 30, 2008 5:50 pm    Post subject: Reply with quote

samuri25404 wrote:
Uhh, not quite, Slovach.

You're creating a byte[] with size 0, and asking to read 0 bytes. You're just gonna get null from the bit converter.


edit: that should work fine in VB

in VB.net: 5 = 0 - 5, so 6 bytes.
in C#: 5 = 0 - 4, or 5 bytes.

so yes, that 0 would in fact create a byte array with 1 byte.
Back to top
View user's profile Send private message
yoodidoo
How do I cheat?
Reputation: 0

Joined: 20 Jul 2008
Posts: 6

PostPosted: Wed Jul 30, 2008 7:25 pm    Post subject: Reply with quote

Alright, thank you very much for your replies, I start working
on this as soon as I can. My knowledge on this stuff isn't as
high as I would like it to be, but I have to start somewhere and
i'm taking classes on programming soon.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Jul 30, 2008 8:32 pm    Post subject: Reply with quote

slovach wrote:
samuri25404 wrote:
Uhh, not quite, Slovach.

You're creating a byte[] with size 0, and asking to read 0 bytes. You're just gonna get null from the bit converter.


edit: that should work fine in VB

in VB.net: 5 = 0 - 5, so 6 bytes.
in C#: 5 = 0 - 4, or 5 bytes.

so yes, that 0 would in fact create a byte array with 1 byte.


Ah, my bad.

But the maximum time value goes up to 999 (because of a cmp in the memory); that requires at least 3 bytes (4 when rounded up). The max that a user would get from doing RPM is 255, which won't always be true.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 30, 2008 9:56 pm    Post subject: Reply with quote

Ok fine, I made an oops. Sad


SUPERIOR VERSION
Code:
    Dim p As Process() = Process.GetProcessesByName("winmine")
    Dim buffer As Byte() = New Byte(3) {}
    Dim bytesRead As UInt32 = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        ReadProcessMemory(p(0).Handle, &H100579C, buffer, 4, bytesRead)
        textBox1.Text = Convert.ToString(BitConverter.ToUInt32(buffer, 0))
    End Sub
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