Skip to content

Commit

Permalink
Add virtual input fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 14, 2020
1 parent f297b87 commit 9ad1321
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cyberpunk_amd_patch/src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ Options::Options(HMODULE aModule)
this->PatchSMT = config.value("smt", this->PatchSMT);
this->PatchSpectre = config.value("spectre", this->PatchSpectre);
this->PatchMemoryPool = config.value("memory_pool", this->PatchMemoryPool);
this->PatchVirtualInput = config.value("virtual_input", this->PatchVirtualInput);
}

nlohmann::json config;
config["avx"] = this->PatchAVX;
config["smt"] = this->PatchSMT;
config["spectre"] = this->PatchSpectre;
config["memory_pool"] = this->PatchMemoryPool;
config["virtual_input"] = this->PatchVirtualInput;

std::ofstream o(configPath);
o << config.dump(4) << std::endl;
Expand Down
1 change: 1 addition & 0 deletions cyberpunk_amd_patch/src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Options
bool PatchSpectre { true };
bool PatchSMT{ true };
bool PatchAVX{ false };
bool PatchVirtualInput{ true };
bool PatchMemoryPool{ true };
std::filesystem::path Path;
};
4 changes: 4 additions & 0 deletions cyberpunk_amd_patch/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma comment(linker, "/DLL")

void PoolPatch(Image* apImage);
void VirtualInputFix(Image* apImage);
void PatchAmd(Image* apImage);
void PatchAvx(Image* apImage);
void HotPatchFix(Image* apImage);
Expand All @@ -38,6 +39,9 @@ void Initialize(HMODULE mod)
if(options.PatchMemoryPool)
PoolPatch(&image);

if (options.PatchVirtualInput)
VirtualInputFix(&image);

spdlog::default_logger()->flush();
}

Expand Down
35 changes: 35 additions & 0 deletions cyberpunk_amd_patch/src/virtual_input_fix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "Image.h"
#include <spdlog/spdlog.h>

void VirtualInputFix(Image* apImage)
{
const uint8_t payload[] = {
0x8B, 0x44, 0x24, 0x54, 0x85, 0xC0, 0x75, 0x26
};

auto* pMemoryItor = apImage->pTextStart;
auto* pEnd = apImage->pTextEnd;

while (pMemoryItor + std::size(payload) < pEnd)
{
if (memcmp(pMemoryItor, payload, std::size(payload)) == 0)
{
DWORD oldProtect = 0;
VirtualProtect(pMemoryItor, 8, PAGE_EXECUTE_WRITECOPY, &oldProtect);
pMemoryItor[0] = 0x36;
pMemoryItor[1] = 0x8B;
pMemoryItor[2] = 0x07;
pMemoryItor[3] = 0x90;
VirtualProtect(pMemoryItor, 8, oldProtect, nullptr);

spdlog::info("\tVirtual Input Patch: success");

return;
}

pMemoryItor++;
}

spdlog::warn("\tVirtual Input Patch: failed");

}

0 comments on commit 9ad1321

Please sign in to comment.