From 02b6dd2f19c9ce27c3b02417502756e9051e801f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 12 Feb 2016 00:36:52 +0100 Subject: [PATCH] Optimize far-jump patches --- deps/protobuf | 2 +- premake5.lua | 1 + src/Components/Modules/Network.cpp | 2 +- src/Components/Modules/UIScript.cpp | 2 +- src/Proto/node.proto | 11 ++++++----- src/Utils/Hooking.cpp | 12 ++++++++++++ src/Utils/Hooking.hpp | 3 +++ 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/deps/protobuf b/deps/protobuf index 028d59fc..caf1fb71 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 028d59fccda7a94c3fd39095261caceb77456af3 +Subproject commit caf1fb7197ee94c07108fc7cfbca07432b185a28 diff --git a/premake5.lua b/premake5.lua index 27fac701..c0315400 100644 --- a/premake5.lua +++ b/premake5.lua @@ -110,6 +110,7 @@ workspace "iw4x" } buildoptions { "/wd4100", -- "Unused formal parameter" + "/wd6011", -- "Dereferencing NULL pointer" } defines { "_SCL_SECURE_NO_WARNINGS", diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index b82d6d6a..530088b5 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -242,7 +242,7 @@ namespace Components Utils::Hook(0x5AA709, Network::PacketInterceptionHandler, HOOK_CALL).Install()->Quick(); // Install packet deploy hook - Utils::Hook::Set(0x5AA715, (DWORD)Network::DeployPacketStub - 0x5AA713 - 6); + Utils::Hook::RedirectJump(0x5AA713, Network::DeployPacketStub); } Network::~Network() diff --git a/src/Components/Modules/UIScript.cpp b/src/Components/Modules/UIScript.cpp index 9f72bbc3..b5c1d3d1 100644 --- a/src/Components/Modules/UIScript.cpp +++ b/src/Components/Modules/UIScript.cpp @@ -122,7 +122,7 @@ namespace Components UIScript::UIScript() { // Install handler - Utils::Hook::Set(0x45EC5B, (DWORD)UIScript::RunMenuScriptStub - 0x45EC59 - 6); + Utils::Hook::RedirectJump(0x45EC59, UIScript::RunMenuScriptStub); // Install ownerdraw handler Utils::Hook(0x63D233, UIScript::OwnerDrawHandleKeyStub, HOOK_CALL).Install()->Quick(); diff --git a/src/Proto/node.proto b/src/Proto/node.proto index 1e0c15b6..a320e25c 100644 --- a/src/Proto/node.proto +++ b/src/Proto/node.proto @@ -2,8 +2,9 @@ syntax = "proto3"; package Proto; -message NodePacket { - bytes challenge = 1; - bytes signature = 2; - bytes publicKey = 3; -} \ No newline at end of file +message NodePacket +{ + bytes challenge = 1; + bytes signature = 2; + bytes publicKey = 3; +} diff --git a/src/Utils/Hooking.cpp b/src/Utils/Hooking.cpp index 503b3ce5..67407574 100644 --- a/src/Utils/Hooking.cpp +++ b/src/Utils/Hooking.cpp @@ -131,4 +131,16 @@ namespace Utils { Hook::SetString(reinterpret_cast(place), string); } + + void Hook::RedirectJump(void* place, void* stub) + { + char* operandPtr = static_cast(place) + 2; + int newOperand = reinterpret_cast(stub) - (reinterpret_cast(place) + 6); + Utils::Hook::Set(operandPtr, newOperand); + } + + void Hook::RedirectJump(DWORD place, void* stub) + { + Hook::RedirectJump(reinterpret_cast(place), stub); + } } diff --git a/src/Utils/Hooking.hpp b/src/Utils/Hooking.hpp index bf5e1d10..6c6e352c 100644 --- a/src/Utils/Hooking.hpp +++ b/src/Utils/Hooking.hpp @@ -44,6 +44,9 @@ namespace Utils static void Nop(void* place, size_t length); static void Nop(DWORD place, size_t length); + static void RedirectJump(void* place, void* stub); + static void RedirectJump(DWORD place, void* stub); + template static void Set(void* place, T value) { *static_cast(place) = value;