|
|
@ -20,7 +20,6 @@ limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
#include "HidHide.h"
|
|
|
|
#include "HidHide.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <numeric>
|
|
|
|
#include <numeric>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
@ -147,104 +146,29 @@ void HidHide::UnPatchValveHooks()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
spdlog::debug("Unpatching Valve HID hooks...");
|
|
|
|
spdlog::debug("Unpatching Valve HID hooks...");
|
|
|
|
// need to load addresses that way.. Otherwise we land before some jumps...
|
|
|
|
// need to load addresses that way.. Otherwise we land before some jumps...
|
|
|
|
auto setupapidll = GetModuleHandle(L"setupapi.dll");
|
|
|
|
if (const auto setupapidll = GetModuleHandle(L"setupapi.dll")) {
|
|
|
|
if (setupapidll) {
|
|
|
|
UnPatchHook("SetupDiEnumDeviceInfo", setupapidll);
|
|
|
|
BYTE* addr = reinterpret_cast<BYTE*>(GetProcAddress(setupapidll, "SetupDiEnumDeviceInfo"));
|
|
|
|
//UnPatchHook("SetupDiGetClassDevsW", setupapidll);
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, SETUP_DI_ENUM_DEV_INFO_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched SetupDiEnumDeviceInfo");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (const auto hiddll = GetModuleHandle(L"hid.dll")) {
|
|
|
|
spdlog::error("failed to unpatch SetupDiEnumDeviceInfo");
|
|
|
|
for (const auto& name : ORIGINAL_BYTES | std::views::keys) {
|
|
|
|
}
|
|
|
|
if (name.starts_with("Hid")) {
|
|
|
|
//addr = reinterpret_cast<BYTE*>(GetProcAddress(setupapidll, "SetupDiGetClassDevsW"));
|
|
|
|
UnPatchHook(name, hiddll);
|
|
|
|
//if (addr) {
|
|
|
|
|
|
|
|
// UnPatchHook(addr, SETUP_DI_GETCLASSDEVSW_ORIG_BYTES);
|
|
|
|
|
|
|
|
// spdlog::trace("Unpatched SetupDiGetClassDevsW");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//else {
|
|
|
|
|
|
|
|
// spdlog::error("failed to unpatch SetupDiGetClassDevsW");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
auto hiddll = GetModuleHandle(L"hid.dll");
|
|
|
|
|
|
|
|
if (hiddll) {
|
|
|
|
|
|
|
|
BYTE* addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidD_GetPreparsedData"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETPREPARSED_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidD_GetPreparsedData");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidD_GetPreparsedData");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetCaps"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETCAPS_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidD_GetAttributes"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETATTRS_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidD_GetAttributes");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidD_GetAttributes");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidD_GetProductString"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETPRODSTR_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidD_GetProductString");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidD_GetProductString");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetUsages"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETUSAGE_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetUsages");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetUsages");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetData"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETDATA_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetData");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetData");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetValueCaps"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETVALUECAPS_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetValueCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetValueCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetUsageValue"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETUSAGE_VAL_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetUsageValue");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetUsageValue");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = reinterpret_cast<BYTE*>(GetProcAddress(hiddll, "HidP_GetButtonCaps"));
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
|
|
|
|
UnPatchHook(addr, HID_GETBTNCAPS_VAL_ORIG_BYTES);
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched HidP_GetButtonCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch HidP_GetButtonCaps");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HidHide::UnPatchHook(BYTE* address, const std::string& bytes)
|
|
|
|
void HidHide::UnPatchHook(const std::string& name, HMODULE module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
spdlog::trace("Patching \"{}\"...", name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BYTE* address = reinterpret_cast<BYTE*>(GetProcAddress(module, name.c_str()));
|
|
|
|
|
|
|
|
if (!address) {
|
|
|
|
|
|
|
|
spdlog::error("failed to unpatch \"{}\"", name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto bytes = ORIGINAL_BYTES.at(name);
|
|
|
|
DWORD dw_old_protect, dw_bkup;
|
|
|
|
DWORD dw_old_protect, dw_bkup;
|
|
|
|
const auto len = bytes.size();
|
|
|
|
const auto len = bytes.size();
|
|
|
|
VirtualProtect(address, len, PAGE_EXECUTE_READWRITE, &dw_old_protect); // Change permissions of memory..
|
|
|
|
VirtualProtect(address, len, PAGE_EXECUTE_READWRITE, &dw_old_protect); // Change permissions of memory..
|
|
|
@ -253,6 +177,7 @@ void HidHide::UnPatchHook(BYTE* address, const std::string& bytes)
|
|
|
|
*(address + i) = bytes[i];
|
|
|
|
*(address + i) = bytes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VirtualProtect(address, len, dw_old_protect, &dw_bkup); // Revert permission change...
|
|
|
|
VirtualProtect(address, len, dw_old_protect, &dw_bkup); // Revert permission change...
|
|
|
|
|
|
|
|
spdlog::trace("Unpatched \"{}\"", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HidHide::enableOverlayElement()
|
|
|
|
void HidHide::enableOverlayElement()
|
|
|
|