How to use Pointer + Offset in C#?

Posts 111 of 11 · Page 1 of 1
How to use Pointer + Offset in C#?
Question in title ^_^
If your C# stuff is injected, use the Marshal class, such as:
var basePtr = new IntPtr(0x12345678);
var ptrVal = Marshal.ReadIntPtr(basePointer);
Marshal.WriteByte(new IntPtr(ptrVal.ToInt32() + 0x123), 0x90);
If you are externally reading/writing, then use ReadProcessMemory / WriteProcessMemory.
pinvoke.net: readprocessmemory (kernel32)
pinvoke.net: writeprocessmemory (kernel32)

Read the pointer, convert it to an Int32 using BitConverter, then add the offset, read again etc. for each offset.
Quote Originally Posted by atom0s View Post
If your C# stuff is injected, use the Marshal class, such as:


If you are externally reading/writing, then use ReadProcessMemory / WriteProcessMemory.
pinvoke.net: readprocessmemory (kernel32)
pinvoke.net: writeprocessmemory (kernel32)

Read the pointer, convert it to an Int32 using BitConverter, then add the offset, read again etc. for each offset.
Thanks this will help




But how I can do this?

So?

ReadProcessMemory(bla, bla, bla);
...
// Add ofsset
WriteProcessMemory(bla, bla, bla);

how to add it(offset)?

Oh you mean so

// Read pointer
return (IntPtr)(BitConverter.ToInt32(memory, 0) + Offset);
Quote Originally Posted by _PuRe.LucK* View Post
Thanks this will help




But how I can do this?

So?

ReadProcessMemory(bla, bla, bla);
...
// Add ofsset
WriteProcessMemory(bla, bla, bla);

how to add it(offset)?

Oh you mean so

// Read pointer
return (IntPtr)(BitConverter.ToInt32(memory, 0) + Offset);

As i see you are using External editing...
So:
Pointer + Offset looks like:
Code:
IntPtr Pointer = 0xEACBD
int Offset = 0x555
IntPtr PointTo = ReadMem(Pointer)
WriteMem(
Code:
PointTo + Offset, 999)
Edit: ^ Vbulletion auto-correction fuck up the post -_-
Quote Originally Posted by rabir007 View Post



As i see you are using External editing...
So:
Pointer + Offset looks like:
Code:
IntPtr Pointer = 0xEACBD
int Offset = 0x555
IntPtr PointTo = ReadMem(Pointer)
WriteMem(
Code:
PointTo + Offset, 999)
Edit: ^ Vbulletion auto-correction fuck up the post -_-

Thanks you

And with more Offsets?
Quote Originally Posted by _PuRe.LucK* View Post
Thanks this will help

But how I can do this?

So?

ReadProcessMemory(bla, bla, bla);
...
// Add ofsset
WriteProcessMemory(bla, bla, bla);

how to add it(offset)?

Oh you mean so

// Read pointer
return (IntPtr)(BitConverter.ToInt32(memory, 0) + Offset);

You'd loop each offset and keep reading the pointers. Heres some pseudo code on what you'd do:
Code:
var baseAddress     = new IntPtr(0x12345678);
var offsetList      = new int[] { 0x12, 0x22, 0x033, 0x44, 0x55, 0x67 };
var buffer          = new byte[4];
var lpOutStorage    = IntPtr.Zero;

// Read the base pointer..
ReadProcessMemory( process.Handle, baseAddress, buffer, (uint)buffer.Length, ref lpOutStorage );

// Loop each offset and read the pointers..
for (int x = 0; x < offsetList.Length - 1; x++)
{
    baseAddress = BitConverter.ToInt32(buffer, 0) + offsetList[x];
    ReadProcessMemory( process.Handle, baseAddress, buffer, (uint)buffer.Length, ref lpOutStorage );
}

// Read the last pointer+offset as the main value..
var valueBuffer = new byte[255];
baseAddress = BitConverter.ToInt32(btBuffer, 0) + offsetList[offsetList.Length - 1];
ReadProcessMemory( process.Handle, baseAddress, valueBuffer, (uint)valueBuffer.Length, ref lpOutStorage );
Quote Originally Posted by atom0s View Post
You'd loop each offset and keep reading the pointers. Heres some pseudo code on what you'd do:
Code:
var baseAddress     = new IntPtr(0x12345678);
var offsetList      = new int[] { 0x12, 0x22, 0x033, 0x44, 0x55, 0x67 };
var buffer          = new byte[4];
var lpOutStorage    = IntPtr.Zero;

// Read the base pointer..
ReadProcessMemory( process.Handle, baseAddress, buffer, (uint)buffer.Length, ref lpOutStorage );

// Loop each offset and read the pointers..
for (int x = 0; x < offsetList.Length - 1; x++)
{
    baseAddress = BitConverter.ToInt32(buffer, 0) + offsetList[x];
    ReadProcessMemory( process.Handle, baseAddress, buffer, (uint)buffer.Length, ref lpOutStorage );
}

// Read the last pointer+offset as the main value..
var valueBuffer = new byte[255];
baseAddress = BitConverter.ToInt32(btBuffer, 0) + offsetList[offsetList.Length - 1];
ReadProcessMemory( process.Handle, baseAddress, valueBuffer, (uint)valueBuffer.Length, ref lpOutStorage );
Works this without marshall class like Rabirs method
Quote Originally Posted by _PuRe.LucK* View Post
Works this without marshall class like Rabirs method
With more offset:
Pointer1 = Ptr + Offset1;
Pointer2 = Pointer1 + Offset2;
Pointer3 = Pointer2 + Offset3;
Money = Pointer3 + MoneyOffset;

Etc...
You can use loops, it makes things easier...
Good luck...
Quote Originally Posted by rabir007 View Post


With more offset:
Pointer1 = Ptr + Offset1;
Pointer2 = Pointer1 + Offset2;
Pointer3 = Pointer2 + Offset3;
Money = Pointer3 + MoneyOffset;

Etc...
You can use loops, it makes things easier...
Good luck...
Ah okay thank you
OM me i ll help u
Marshal is only for if your dll is injected. It allows you to directly access the memory without needing 'unsafe' code.
Posts 111 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?