Step 2
Attaching to and reading a process's memory (NOTE: Not editing memory)
So you've made it this far...I think I'll let you ask me any questions that you want. Hit me up at: mathmuncher11@gmail.com or mathmuncherdude (aim).
Even the stupidest question is worth asking me...even you noobs who just started a few days ago...peace!
This step may be considered useless to many people but I will go over it anyways. Basically, it allows you to read an address's value. So let's say that in your game, every map has a different value for one address. You could use the case statement to convert it to string and then have a label displaying this: You are on the map: Dungeon level 2. It may seem useless, but it's not. You could also use it for directly transferring values between two addresses! Something not possible in ASM...enjoy!
OK! So, you remember Step 1? Well you're going to need to!
Now let me explain the next step. Download this. (And you will find the demo project at the bottom, not needed but you can see full source that way).
Any time you make a trainer, you'll need to add that as an existing item (Project add existing item, then browse to the file you just downloaded). After adding it to your project, make a timer, outside all methods.
Should look SOMETHING like this:
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Timer timer1 = new Timer();
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 100;
timer1.Tick+=new EventHandler(timer1_Tick1);
}
OK, then make a void, doesn't have to be public (or private), with the name timer1_Tick1. Example:
void timer1_Tick1(object o1, EventArgs e)
{
//stuff
}
Ok, now for the proccessmemoryreader function.
Add this line, outside all methods:
ProcessMemoryReaderLib.ProcessMemoryReader preader = new ProcessMemoryReaderLib.ProcessMemoryReader();
THAT IS VERY IMPORTANT REMEMBER IT!
This is just a shortcut to the ProcessMemoryReaderLib class, and you have to do it anyways.
This is something you will also have to memorize!!!
----------------------------------------------
Now, for the actual reading!
You'll need to open the process in read mode so, another memorizing thing, add these lines:
preader.ReadProcess = myprocess[0];
preader.OpenProcess();
Do not forget this, or when you try to read/write...nothing will happen.
Note: If you want to attach to the second instance make it myprocess[1] and then you must change the first part (myprocess != 0) to greater than or equal to. Ignore this if you don't know what I'm talking about.
Now for the reading template!
int bytesread;
int memoryaddress = 0x1009624;
int memoryaddressvalue;
byte[] memory;
memory= preader.ReadProcessMemory((IntPtr)memoryaddress,1,out bytesread);
memoryaddressvalue = memoryvalue[0];
label1.Text = memoryaddressvalue.ToString();
Reading values, other than byte. e.g: double, 4 byte:
This is VERY simple! I use 4 byte for an example, and my variable is called 'valueconvert', but you may use other...just make a varible as an int (or double if you want double, float if you want float, ect!) and do not assign it a value...after assigning a byte array's (byte[]) value to memory, ( the line is: memory=preader.readprocessmemory...ect)...put this:
valueconvert = BitConverter.ToInt32(memory, 0);
or for double:
valueconvert = BitConverter.ToDouble(memory,0);
FOR THIS TO WORK THE LINE:
memory = preader.ReadProcessMemory((IntPtr)0x1009624, 8, out bytesread);
MUST HAVE AN EQUAL TO OR LARGER uintsToRead (in this case it's 8) value than the size of the object you are converting it to.
Byte-1
Short-2
int-4
Long-8
Float,Decimal,Double-8
Ect..you can find them all out pretty easily, the only reason to make it precise is to save memory...but you shouldn't have to worry about that with such small trainers.
Very simple! But it can get confusing...
That's it for Step 2
Demo project notepadreader.zip.
You've now completed Step 2.