I'm doing this tutorial so that it is better to understand how it behaves the Pointers in C ++ and so we can discuss and ask questions about it, try to make the tutorial as clear as possible.
Pointers are the foundation of any hack games, since the hacks consist of memory changes, which are made through pointers.
Thus making important learning of it in this forum
Pointers in C + +
Thus we declare two pointers, Ptri which is a pointer to an integer and ptrf that points to a float.int * Ptri;
float * ptrf;
NOTE: As Ptri is not an integer, not a ptrf tbm number of type float, ie, their values are in memory address and the value of these addresses is that they are an integer and a float, respectively.
int var = 5;
int * = VarPtr &var;
Thus the pointer is pointing to VarPtr the value of the variable var.
So if we do,
* VarPtr = 7;
We will be changing the value of var to 7.
It is worth mentioning some incorrect syntax and explains them, lest we confuse:
1) int * = VarPtr var;
2) int * VarPtr = 5;
3) int * = 0x0005 VARPTR;
4) int * = VarPtr &5;
In 1 is flawed because var is of type integer and VarPtr is type pointer to integer.
2 because in 5 is an integer constant, thereby generating the error of the first and second error per 5 can not be assigned to another value.
3 is the same in the case of 2, since it is also an integer 0x0005 (hexadecimal).
In 4 there is an error because 5 is a contact and does not occupy a place in physical memory or a variable
Now we are a few examples:
Example 2:int a, b = 5;
int result = * &a;
a = 10;
cout << * result + b;
15 / / (10 + 5)
int a, b, * ptr1, ptr2 * / / declaration
a = 10 / / initializing "a"
b = 7 / / initializing "b"
ptr1 = &a; / / "ptr1" receives the address of "a"
ptr2 = ptr1; / / "ptr2" gets the value of "ptr1" which is the address of "a" (note that it is allowed to assign a pointer to another, they are of the same type)
ptr1 = &b; / / "ptr1" points to "b" note "ptr2" keeps pointing to "a"
* Ptr2 = 18 / / address value of "ptr2" ("a") receives 18. (A = 18)
b = 15 / / b gets 15;
cout << a << "," << b << "," << * ptr1 << "," << * ptr2;
18, 15, 15, 18
With pointers you can access and manipulate memory regions values, and it is also possible that a single pointer you manipulate multiple variables.
It is a type of data most useful for various applications.
Using pointers - Theory of hacks:
Using the game pinbal example,
Suppose we have the adress (address) that corresponds to the number of balls pinbal.
Well, we know that the number of balls is an integer, then we conclude that the pointer value that interests us is the integer type.
Then we'll make a type cast to make this hexadecimal (which is the adress) in whose region of memory pointer to which it points is the hexadecimal: (int *) 0x010101
Note that if we did int * 0x010101 would be wrong, would the error 3) tutorial.
To access the pointer value we create enough just by the "*": D
Then when we do * (int *) 0x010101 will be accessing the value of the number of balls remaining in pinbal (adopting the example).
Thus we could do the following:
int value = * (int *) 0x010101 / / recording the current value of the number of balls in the variable value.
Or change the value as follows:
* (Int *) 0x010101 = 30 / / Changing the current value of the number of balls to 30
Thus we would have 30 balls, following the example of pinball.