 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 12:08 pm Post subject: [C#] Type trouble, ReadProcessMemory w/pointer |
|
|
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.
| 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 |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Wed Dec 24, 2008 12:40 pm Post subject: |
|
|
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 |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Wed Dec 24, 2008 12:42 pm Post subject: |
|
|
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 |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Wed Dec 24, 2008 12:50 pm Post subject: |
|
|
| 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 |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 1:19 pm Post subject: |
|
|
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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Dec 24, 2008 1:19 pm Post subject: |
|
|
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.
_________________
|
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 1:32 pm Post subject: |
|
|
| 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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Dec 24, 2008 1:55 pm Post subject: |
|
|
lol.
| Code: |
fixed( byte *lpBase = (byte*)&baseAddress )
|
_________________
|
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 1:57 pm Post subject: |
|
|
| 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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Dec 24, 2008 2:00 pm Post subject: |
|
|
Sigh.
| Code: |
fixed( void *lpBase = &baseAddress )
|
_________________
|
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 2:26 pm Post subject: |
|
|
| 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. 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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Dec 24, 2008 3:45 pm Post subject: |
|
|
| 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();
}
}
}
}
|
_________________
|
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Dec 24, 2008 3:55 pm Post subject: |
|
|
| 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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Dec 24, 2008 9:35 pm Post subject: |
|
|
| 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 |
|
 |
|
|
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
|
|