Skip to content

Instantly share code, notes, and snippets.

@krjan02
Created July 11, 2019 21:55
Show Gist options
  • Save krjan02/4a8778c39cce014275e62fba96658802 to your computer and use it in GitHub Desktop.
Save krjan02/4a8778c39cce014275e62fba96658802 to your computer and use it in GitHub Desktop.
#define BLOCK_BEGIN 0x25A46A0
#define CONSTANT1 0x00000001DD5D645B
#define CONSTANT2 0xBF204ABFDD5D645C
#define OFFSET1 0xFFFFFFFFFD420FC0
#define OFFSET2 0x137650
#define OFFSET3 0xFFFFFFFFFFFFFFA0
#define OFFSET4 0x1DED90
namespace filepatching
{
bool isOn = false;
uintptr_t values[11] = { 0 };
bool enable()
{
if (!isOn) {
isOn = true;
for (size_t i = 0; i < 11; i++)
{
values[i] = RPM<uintptr_t>(BaseAddress + BLOCK_BEGIN + i * sizeof(uintptr_t));
}
uintptr_t constant1 = CONSTANT1;
uintptr_t constant2 = CONSTANT2;
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN, constant1);
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + sizeof(uintptr_t), constant2);
uintptr_t value1 = values[2] + OFFSET1;
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 2 * sizeof(uintptr_t), value1);
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 4 * sizeof(uintptr_t), value1);
uintptr_t value2 = BaseAddress + OFFSET2;
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 3 * sizeof(uintptr_t), value2);
uintptr_t value3 = values[8] + OFFSET3;
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 8 * sizeof(uintptr_t), value3);
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 10 * sizeof(uintptr_t), value3);
uintptr_t value4 = BaseAddress + OFFSET4;
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + 9 * sizeof(uintptr_t), value4);
return true;
}
}
void disable()
{
if (isOn) {
isOn = false;
// restoring old values
for (size_t i = 0; i < 11; i++)
{
WPM< uintptr_t>(BaseAddress + BLOCK_BEGIN + i * sizeof(uintptr_t), values[i]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment