Step 4

Reading/writing to and from pointers in external processes.

Pointers are 4 byte values that hold the the address of a memory location instead of a normal value. Thus every time the program is re-run, the address changes but the pointer does not!

First, if you have found the address by searching but every time you restart the game, the address changes. You need a pointer! Here is a good guide to finding them, if you have questions about it...ask me. 

OK, so exactly how to pointers work? The pointer base never changes, that is a 4 byte value. This value is going to be the start of the pointer. The offset adds to it and points to the exact address.

So in order to read pointers in C#, you must find the value of the pointer's base (it will always change, every time you restart the program), then add the offset to it.

I've made a simple demonstration:

int byteswritten;
int bytesread;
int value;
int pointerbase;
byte[] memory;

memory = preader.ReadProcessMemory((IntPtr)0x1009624, 4, out bytesread); //read the base 1009624, this is fake in notepad, just a demonstration!
pointerbase = BitConverter.ToInt32(memory, 0); //make an int with the value of the address read
pointerbase += 0xb14; //add the offset
memory = preader.ReadProcessMemory((IntPtr)pointerbase, 4, out bytesread); //read the pointer!
value = BitConverter.ToInt32(memory, 0); //convert the pointer's value back to int


You read the value from 1009624 offset:b14 and its value has been assigned to the int 'value'!

 

That's for reading, this if for writing:

Enabled (you write a new value to the pointer, in this case 2000):

int byteswritten;
int bytesread;
int value;
int pointerbase;
byte[] memory;

memory = preader.ReadProcessMemory((IntPtr)0x1009624, 4, out bytesread);
pointerbase = BitConverter.ToInt32(memory, 0);
pointerbase += 0xb14;
value = 2000;
memory = BitConverter.GetBytes(value);
preader.WriteProcessMemory((IntPtr)pointerbase,memory,out byteswritten);
//now you are writing the value:2000 to:1009624 offset:b14

 

Disable (you write the original value to the pointer,in this case 4000):

int byteswritten;
int bytesread;
int value;
int pointerbase;
byte[] memory;

memory = preader.ReadProcessMemory((IntPtr)0x1009624, 4, out bytesread);
pointerbase = BitConverter.ToInt32(memory, 0);
pointerbase += 0xb14;
value = 4000;
memory = BitConverter.GetBytes(value);
preader.WriteProcessMemory((IntPtr)pointerbase,memory,out byteswritten);
//you wrote the value:4000 to:1009624 offset:b14


Yes, it's that simple and I know it can be hard to type that all out, so I've made a program that makes it VERY easy!

On to Step 5!