diff --git a/core/elfpatcher/include/elfpatcher/general/ElfConstants.hpp b/core/elfpatcher/include/elfpatcher/general/ElfConstants.hpp index 22f3a7e81..912750476 100644 --- a/core/elfpatcher/include/elfpatcher/general/ElfConstants.hpp +++ b/core/elfpatcher/include/elfpatcher/general/ElfConstants.hpp @@ -121,8 +121,9 @@ inline constexpr std::uint8_t kStubOpMovDwordPtrRsp[] = {0x89, 0x04, 0x24}; inline constexpr std::uint8_t kStubOpMovQwordPtrRsp8Rbx[] = {0x48, 0x89, 0x5c, 0x24, 0x08}; inline constexpr std::uint8_t kStubOpMovRdiRsp[] = {0x48, 0x89, 0xe7}; inline constexpr std::uint8_t kStubOpXorRsiRsi[] = {0x48, 0x31, 0xf6}; -inline constexpr std::uint8_t kStubOpJmpRel32 = 0xe9; -inline constexpr std::size_t kStubJmpInstructionSize = 5; +inline constexpr std::uint8_t kStubOpCallRel32 = 0xe8; +inline constexpr std::size_t kStubCallInstructionSize = 5; +inline constexpr std::uint8_t kStubOpUd2[] = {0x0f, 0x0b}; } diff --git a/core/elfpatcher/src/general/EntryStubBuilder.cpp b/core/elfpatcher/src/general/EntryStubBuilder.cpp index 87f20c730..25acf3ec3 100644 --- a/core/elfpatcher/src/general/EntryStubBuilder.cpp +++ b/core/elfpatcher/src/general/EntryStubBuilder.cpp @@ -23,14 +23,15 @@ std::vector EntryStubBuilder::BuildEntryStub( _appendBytes(s, kStubOpMovQwordPtrRsp8Rbx, sizeof(kStubOpMovQwordPtrRsp8Rbx)); _appendBytes(s, kStubOpMovRdiRsp, sizeof(kStubOpMovRdiRsp)); _appendBytes(s, kStubOpXorRsiRsi, sizeof(kStubOpXorRsiRsi)); - const std::uint64_t jmpInsnVaddr = stubVaddr + s.size(); - const std::uint64_t jmpNextVaddr = jmpInsnVaddr + kStubJmpInstructionSize; - const auto rel32 = static_cast(realEntryVaddr - jmpNextVaddr); - s.push_back(kStubOpJmpRel32); + const std::uint64_t callInsnVaddr = stubVaddr + s.size(); + const std::uint64_t callNextVaddr = callInsnVaddr + kStubCallInstructionSize; + const auto rel32 = static_cast(realEntryVaddr - callNextVaddr); + s.push_back(kStubOpCallRel32); s.push_back(static_cast(rel32 & 0xff)); s.push_back(static_cast((rel32 >> 8) & 0xff)); s.push_back(static_cast((rel32 >> 16) & 0xff)); s.push_back(static_cast((rel32 >> 24) & 0xff)); + _appendBytes(s, kStubOpUd2, sizeof(kStubOpUd2)); return s; }