Byte Patching using winrt api (C++)

55 views Asked by At

I want to write a C++ program that will be compiled into a dll and be injected into a C++ uwp app.

This program should patch bytes at certain address. For example We want to patch address 0x12345678 with {0x01, 0x02, 0x03} for certain purposes.

I wrote a simple programm using normal windows apis for it:

void PatchMemory(LPVOID address, BYTE* data, SIZE_T size) {
    DWORD oldProtect;
    int result;

    HANDLE hProcess = GetCurrentProcess();
    if (hProcess == INVALID_HANDLE_VALUE) {
        Log::Warning("Patch unsuccessful...");
        return;
    }

    result = VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &oldProtect);
    if (result != 0) {
        Log::Warning("Patch unsuccessful... code: {}", result);
        return;
    }

    result = WriteProcessMemory(GetCurrentProcess(), address, data, size, nullptr);
    if (result != 0) {
        Log::Warning("Patch unsuccessful... code: {}", result);
        return;
    }

    result = VirtualProtect(address, size, oldProtect, &oldProtect);
    if (result != 0) {
        Log::Warning("Patch unsuccessful... code: {}", result);
        return;
    }

    Log::Info("Patch successful!");
}

But the sad thing now is... I can't use these apis in my dll because they don't work in the sandboxed uwp environment of the program in which the dll will be injected.

Now I wanted to know:

  • Is it possible to do byte patching with winrt apis?
  • If so, how?
  • Might there be other solutions for my problem?

I wish y'all humans a good day and hope this problem can be solved soon...

EDIT:

This is not for malicious purposes. This is for modding Minecraft Bedrock Edition and increasing the building height limit of the nether.

0

There are 0 answers