I'm not trying to do anything ordinary xErath, I would never make a program trying to assign my own memory locations. I am doing it this way to test, and have fun.
Thanks Hunter2, Dev-Cpp did let me get away with typecasting it:
Code:
int* aPointer = new int(5);
//cout << aPointer << endl; //used to find memory address
int* aPointer2 = (int*)0x3e2898; //assign aPointers memory address
cout << *aPointer2; //used to test if it succeeded
Yeah the stack is only accessible by that function, and the free store does persist but its still only accessible by that function.. Its with that I planned on testing. Since the variable is deleted after the function ends on the stack, I could not get the memory address and edit it from a different function, which is why I wanted to put it on the free store, since it would still exist after the function ends.. giving me the option to test if it will let me modify that option from outside the function.. and since the variable would be out of the scope, it was required that I use the memory address.
So hence by using the memory address outside the function where the variable is declared on the free store, I am testing to see if the "cannot be used outside of the function" applies to the variable, or the memory address.
If you understood what I just said.. great!
Anyway finally, I found the result of my experiment. If you define a pointer to point to a memory address, it will try. If the memory address you define already is being used by something that is IN your program, it gives it a different memory address, overriding the memory address you specified. However if the memory address isnt in your program, it will use that address. So I had two programs using the same address for an int. The results were odd.
I would have each program pausing in between printing the value/address and assigning a new value. Sure enough each program was using the same memory address, and setting its own values. They did not seem to share the same values, nor did defining a value on one make the value on the other program change. Almost as if I may have declared the pointer to point to that memory location, but some background routing by windows took place to relocate the address. Which could result in stray memory.
Code:
int aFunction() {
int* aPointer = new int(5);
cout << "aPointer: " << aPointer << endl; //find the memory address
cout << "*aPointer: " << *aPointer << "\n" << endl; //testing the value
}
main()
{
aFunction();
int* aPointer2 = (int*)0x3e2898; //assign aPointer's address here
cout << "*aPointer2: " << *aPointer2 << endl; //returns 0
*aPointer2 = 10;
cout << "*aPointer2: " << *aPointer2 << endl;
cout << "aPointer2: " << aPointer2 << endl;
cin.get();
}
That was the first test, see the memory address 0x3e2898 would have been gone after calling aFunction() if it was not on the free store (because of new keyword). The result of this was aPointer2's pointed to address being relocated.
The entire purpose of this was just to test and see if cracking a program from outside the program by altering memory address' was possible. It appears thats a negative. But maybe that WriteProcessMemory() can do it, I'm sure Microsoft knows how to write functions to bypass their own re-routing techniques used in Windows when reassigning the same memory address.
Edit: BTW, the code I gave you here is the ENTIRE program, I'm just testing around with something... not giving you an error description.