mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(relinker): exact opcode instead of any rip-relative disp in unused nid filter
This commit is contained in:
@@ -52,6 +52,9 @@ struct DecodedInstructionInfo {
|
||||
std::uint8_t ModRmByte;
|
||||
bool HasBranchTarget;
|
||||
std::int64_t BranchDisp;
|
||||
bool IsTwoByteOpcode;
|
||||
std::uint8_t Opcode;
|
||||
std::uint8_t ModRmRegField;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -356,6 +356,9 @@ DecodedInstructionInfo X64InstructionDecoder::DecodeInstruction(
|
||||
op = data[pos++];
|
||||
}
|
||||
|
||||
info.Opcode = op;
|
||||
info.IsTwoByteOpcode = twoByteOpcode;
|
||||
|
||||
if (!twoByteOpcode) {
|
||||
if (op == OneByteCallRel32) {
|
||||
std::int32_t disp = 0;
|
||||
@@ -400,6 +403,7 @@ DecodedInstructionInfo X64InstructionDecoder::DecodeInstruction(
|
||||
info.HasModRm = true;
|
||||
info.ModRmByte = modrm;
|
||||
std::uint8_t reg = (modrm >> ModRmRegShift) & ModRmRegMask;
|
||||
info.ModRmRegField = reg;
|
||||
std::uint8_t mod = (modrm >> ModRmModShift) & ModRmModMask;
|
||||
std::uint8_t rm = modrm & ModRmRmMask;
|
||||
if (reg == 2) {
|
||||
@@ -493,6 +497,7 @@ DecodedInstructionInfo X64InstructionDecoder::DecodeInstruction(
|
||||
std::uint8_t modrm = data[pos];
|
||||
info.HasModRm = true;
|
||||
info.ModRmByte = modrm;
|
||||
info.ModRmRegField = (modrm >> ModRmRegShift) & ModRmRegMask;
|
||||
std::uint8_t mod = (modrm >> ModRmModShift) & ModRmModMask;
|
||||
std::uint8_t rm = modrm & ModRmRmMask;
|
||||
if (mod == ModRmModIndirect && rm == ModRmRmRipRelative) {
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
#include <relinker/analysis/UnusedNidFilter/IGotAccessIndex.hpp>
|
||||
#include <codegen/x86/X64InstructionDecoder.hpp>
|
||||
#include <codegen/x86/X64OpcodeConstants.hpp>
|
||||
#include <unordered_set>
|
||||
#include <cstring>
|
||||
|
||||
namespace Relinker::UnusedNidFilter {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::uint8_t OneByteMovLoadRm8 = 0x8A;
|
||||
constexpr std::uint8_t OneByteMovLoadRm = 0x8B;
|
||||
constexpr std::uint8_t Grp5RegCallIndirect = 2;
|
||||
constexpr std::uint8_t Grp5RegJmpIndirect = 4;
|
||||
|
||||
bool ReadsMemoryOperandAsPointer(const Codegen::DecodedInstructionInfo& info) {
|
||||
if (info.IsTwoByteOpcode) return false;
|
||||
if (info.Opcode == OneByteMovLoadRm8 || info.Opcode == OneByteMovLoadRm) return true;
|
||||
if (info.Opcode == Codegen::X64OpcodeConstants::OneByteGrp5Rm)
|
||||
return info.ModRmRegField == Grp5RegCallIndirect || info.ModRmRegField == Grp5RegJmpIndirect;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class GotAccessIndex : public IGotAccessIndex {
|
||||
public:
|
||||
explicit GotAccessIndex(std::unordered_set<VirtualAddress> accessed)
|
||||
@@ -35,6 +53,7 @@ std::unique_ptr<IGotAccessIndex> BuildGotAccessIndex(
|
||||
|
||||
Codegen::DecodedInstructionInfo info = decoder.DecodeInstruction(text.data() + bufOff, available);
|
||||
if (!info.HasRipRelativeDisp) continue;
|
||||
if (!ReadsMemoryOperandAsPointer(info)) continue;
|
||||
|
||||
VirtualAddress nextVaddr = va + static_cast<VirtualAddress>(info.Length);
|
||||
std::int32_t disp = 0;
|
||||
|
||||
Reference in New Issue
Block a user