fix: add support for "E9 rel32" for shorter method lengths

This commit is contained in:
nexusverypro
2026-07-05 19:31:46 +01:00
parent edf088f071
commit af6cf37212
4 changed files with 144 additions and 37 deletions

View File

@@ -13,7 +13,7 @@
// versioning
#define RADHOOK_VERSION_MAJOR 1
#define RADHOOK_VERSION_MINOR 1
#define RADHOOK_VERSION_PATCH 0
#define RADHOOK_VERSION_PATCH 1
#if _MSC_VER
# include <sal.h> // for source code annotations
@@ -41,8 +41,12 @@ enum class RadHookResult : int {
InvalidDetour,
InvalidHandle,
TrampolineTooFar,
TargetTooSmall,
UnknownTarget,
BadDecode,
RelativeControlFlow,
TooManyRipFixups,
ExceedsMaxStolen,
InsufficientLength,
Unknown,
};

View File

@@ -15,13 +15,16 @@
#if defined(RADHOOK_ARCH_X64)
struct X64Insn {
size_t length = 0;
bool ripRelative = false;
size_t dispOffset = 0;
bool relativeControlFlow = false;
bool isReturn = false;
bool isPadding = false;
bool valid = false;
size_t length = 0;
bool ripRelative = false;
size_t dispOffset = 0;
bool relativeControlFlow = false;
bool isReturn = false;
bool isPadding = false;
bool branchDisp = false;
size_t branchDispOffset = 0;
uint8_t branchDispSize = 0;
bool valid = false;
};
X64Insn
@@ -30,9 +33,11 @@ DecodeX64(
size_t avail
);
constexpr size_t kX64StubLen = 14; // FF25 00000000 + imm64
constexpr size_t kX64StubLen = 14; // FF25 00000000 + imm64
constexpr size_t kX64StubLenShort = 5; // E9 rel32
constexpr size_t kX64MaxStolen = 32;
constexpr size_t kX64MaxRipFixups = 8;
constexpr size_t kX64MaxBranchFixups = 8;
enum class StolenBytesError {
None,
@@ -43,6 +48,12 @@ enum class StolenBytesError {
InsufficientLength,
};
struct BranchFixup {
size_t offset;
size_t dispOffset;
uint8_t dispSize;
};
StolenBytesError
BuildStolenBytesX64(
const uint8_t* target,
@@ -50,7 +61,9 @@ BuildStolenBytesX64(
uint8_t* outBytes,
size_t& outLen,
size_t* outRipOffsets,
size_t& outRipCount
size_t& outRipCount,
BranchFixup* outBranches,
size_t& outBranchCount
);
#endif // defined(RADHOOK_ARCH_X64)