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 


[C#] Type trouble, ReadProcessMemory w/pointer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 12:08 pm    Post subject: [C#] Type trouble, ReadProcessMemory w/pointer Reply with quote

I'm trying to read a dynamic address (pointer), but it wont let me due to this error:
You can only take the address of an unfixed expression inside of a fixed statement initializer.
So to my last retort I'm asking you guys, help is very appreciated. Sad

Code:
   //C# Signature for the ReadProcessMemory() API
        [DllImport("kernel32.dll", SetLastError = true)]
        static unsafe extern bool ReadProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            void* lpBuffer,
            int dwSize,
            out IntPtr lpNumberOfBytesRead
        );
   
   public unsafe void checkStatus()
        {
            if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E428, &baseAddress, 4, out bytesout))
            {
                Mana_pool = baseAddress + 0x328;
                textBox1.Text += Mana_pool;
            }
        }



///
/// Outcome:
/// Error   1   You can only take the address of an unfixed expression inside of a fixed statement initializer
///
///


http://pastebin.com/m68cc74f
^ Click there to see the code highlighted.

Thanks.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Wed Dec 24, 2008 12:40 pm    Post subject: Reply with quote

textBox1.Text = Mana_pool.toString();


And I don't think that's how you're suppose to read a pointer with an offset...
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Wed Dec 24, 2008 12:42 pm    Post subject: Reply with quote

first off i dont code C# (i did but it sucked..)

so ignoring this lil fact ill proceed with proper code... ;}
Code:


        public unsafe void checkStatus()
        {
            if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E428, &baseAddress, 4, out bytesout))
            {
                char*Mana_Pool[255];
                if(baseAddress)
               {
                    if(ReadProcessMemory(ProcessHandle,(IntPtr)baseAddress + 0x328, &Mana_Pool,255,out bytesout))
                     {
                            if(strlen(Mana_Pool))
                            {
                                 textBox1.Text += Mana_pool;
                            }
                      }
                }
          }
     }
Back to top
View user's profile Send private message MSN Messenger
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Wed Dec 24, 2008 12:50 pm    Post subject: Reply with quote

BanMe wrote:
first off i dont code C# (i did but it sucked..)

so ignoring this lil fact ill proceed with proper code... ;}
Code:


        public unsafe void checkStatus()
        {
            if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E428, &baseAddress, 4, out bytesout))
            {
                char*Mana_Pool[255];
                if(baseAddress)
               {
                    if(ReadProcessMemory(ProcessHandle,(IntPtr)baseAddress + 0x328, &Mana_Pool,255,out bytesout))
                     {
                            if(strlen(Mana_Pool))
                            {
                                 textBox1.Text += Mana_pool;
                            }
                      }
                }
          }
     }


Wow..eh, no pointers in C#, strlen() doesn't exist in C#.
Back to top
View user's profile Send private message MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 1:19 pm    Post subject: Reply with quote

Wow okay, how does typecasting the Mana_pool variable help me here, the error is at the RPM line.
I already fixed that before, by the way..

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Wed Dec 24, 2008 1:19 pm    Post subject: Reply with quote

This is actually fairly simple.

Google for "C# fixed" for more information.

Code:

   public unsafe void checkStatus()
        {
            fixed( byte *lpBase = &baseAddress ) {
                if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E428, lpBase, 4, out bytesout))
                {
                    Mana_pool = baseAddress + 0x328;
                    textBox1.Text += Mana_pool;
                }
            }
        }


should work. Though, I couldn't recreate the error, so I'm not 100% sure; been a while since I've done C# pointers.

_________________
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
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 1:32 pm    Post subject: Reply with quote

samuri25404 wrote:
This is actually fairly simple.

Google for "C# fixed" for more information.

Code:

   public unsafe void checkStatus()
        {
            fixed( byte *lpBase = &baseAddress ) {
                if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E428, lpBase, 4, out bytesout))
                {
                    Mana_pool = baseAddress + 0x328;
                    textBox1.Text += Mana_pool;
                }
            }
        }


should work. Though, I couldn't recreate the error, so I'm not 100% sure; been a while since I've done C# pointers.


Getting this error
Code:
Error   1   Cannot implicitly convert type 'int*' to 'byte*'. An explicit conversion exists (are you missing a cast?)

At line
Code:
fixed (byte* lpBase = &baseAddress)

specific: &baseAddress

Thanks for the help, still trying to solve it although I'm toying with something else that I will have use for later on while someone breaks this problem. ^^

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Wed Dec 24, 2008 1:55 pm    Post subject: Reply with quote

lol.

Code:

fixed( byte *lpBase = (byte*)&baseAddress )

_________________
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
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 1:57 pm    Post subject: Reply with quote

samuri25404 wrote:
lol.

Code:

fixed( byte *lpBase = (byte*)&baseAddress )


lol
Code:
Error   1   The right hand side of a fixed statement assignment may not be a cast expression

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Wed Dec 24, 2008 2:00 pm    Post subject: Reply with quote

Sigh.

Code:

fixed( void *lpBase = &baseAddress )

_________________
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
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 2:26 pm    Post subject: Reply with quote

samuri25404 wrote:
Sigh.

Code:

fixed( void *lpBase = &baseAddress )


Seems to be working now, but it returns the wrong value.
http://pastebin.com/m586c49c6

Ahhh, I'm so out of the ideas. Also I'm not really familiar with reading pointers so fuck. Confused Thanks for the help though.
Just trying to read address 0x1094e100 with offset 0x328, if you have any better code to do this.. then that'll be fine too. :_:

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Wed Dec 24, 2008 3:45 pm    Post subject: Reply with quote

Code:

int BytesRead = 0;
byte[] Data = new byte[4];
fixed( byte* lpBase = &Data[0] ) {
    if( RPM( ProcessHandle, (IntPtr)0x1094E100, lpBase, 4, out BytesRead ) && BytesRead == 4 ) {
        int Address = BitConverter.ToInt32( Data );
        Address += 0x328;
        fixed( byte* lpData = &Data[0] ) {
            if( RPM( ProcessHandle, (IntPtr)Address, lpData, 4, out BytesRead ) && BytesRead == 4 ) {
                ManaPool = BitConverter.ToInt32( Data );
                textBox1.Text += ManaPool.ToString();
            }
        }
    }
}

_________________
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
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Dec 24, 2008 3:55 pm    Post subject: Reply with quote

samuri25404 wrote:
Code:

int BytesRead = 0;
byte[] Data = new byte[4];
fixed( byte* lpBase = &Data[0] ) {
    if( RPM( ProcessHandle, (IntPtr)0x1094E100, lpBase, 4, out BytesRead ) && BytesRead == 4 ) {
        int Address = BitConverter.ToInt32( Data );
        Address += 0x328;
        fixed( byte* lpData = &Data[0] ) {
            if( RPM( ProcessHandle, (IntPtr)Address, lpData, 4, out BytesRead ) && BytesRead == 4 ) {
                ManaPool = BitConverter.ToInt32( Data );
                textBox1.Text += ManaPool.ToString();
            }
        }
    }
}


Troublesome and a pain in the ass, but this still doesn't return the right value. It returns 622883621 now.
Code:
byte[] Data = new byte[4];
            fixed (byte* lpBase = &Data[0])
            {
                if (ReadProcessMemory(ProcessHandle, (IntPtr)0x1094E100, lpBase, 4, out bytesout))
                {
                    int Address = BitConverter.ToInt32(Data,0);
                    Address += 0x328;
                    fixed (byte* lpData = &Data[0])
                    {
                        if (ReadProcessMemory(ProcessHandle, (IntPtr)Address, lpData, 4, out bytesout))
                        {
                            Manapool = BitConverter.ToInt32(Data,0);
                            textBox1.Text += Manapool.ToString();
                        }
                    }
                }
            }

No error, so shit. Fuck. :<

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Dec 24, 2008 9:35 pm    Post subject: Reply with quote

Code:
        [DllImport("kernel32.dll")]
        static extern bool ReadProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            int dwSize,
            int lpNumberOfBytesWritten
        );

        Process[] p = Process.GetProcessesByName("tutorial");
        byte[] buffer = new byte[4];

        private void button1_Click(object sender, EventArgs e)
        {         
            ReadProcessMemory(p[0].Handle, (IntPtr)0x0045CC34, buffer, buffer.Length, 0);
            uint butts = BitConverter.ToUInt32(buffer, 0);
            butts += 0x00;
            textBox1.Text = Convert.ToString(butts, 16);
        }
    }


what's so hard? i used the CE tutorial, it spits out the right value.
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