Skip to content

Instantly share code, notes, and snippets.

@CoolOppo
Created April 28, 2014 08:41
Show Gist options
  • Save CoolOppo/11365691 to your computer and use it in GitHub Desktop.
Save CoolOppo/11365691 to your computer and use it in GitHub Desktop.
Writes data to a specified location in memory
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