Created
April 28, 2014 08:41
-
-
Save CoolOppo/11365691 to your computer and use it in GitHub Desktop.
Writes data to a specified location in memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void WriteToMemory(int address_writing_to, char* value_to_write, int num_of_bytes) | |
{ | |
unsigned long old_protection; // Create a place to store our old protection | |
VirtualProtect((LPVOID)address_writing_to, num_of_bytes, PAGE_EXECUTE_READWRITE, &old_protection); // Give me proper access to the memory (and store the old protection in the variable 'old_protection'). | |
memcpy((LPVOID)address_writing_to, value_to_write, old_protection); // Write our value. | |
VirtualProtect((LPVOID)address_writing_to, num_of_bytes, old_protection, NULL); // Restore the protection back to that of 'old_protection'. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment