MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / ApplyRelocation

Method ApplyRelocation

arch/x86/arch_x86.cpp:4015–4056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4013public:
4014
4015 virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc, uint8_t* dest,
4016 size_t len) override
4017 {
4018 (void)view;
4019 (void)arch;
4020 (void)len;
4021 auto info = reloc->GetInfo();
4022 uint64_t pcRelAddr = info.pcRelative ? reloc->GetAddress() : 0;
4023 // TODO these need tested
4024 // uint8_t* dest8 = (uint8_t*)dest;
4025 // uint16_t* dest16 = (uint16_t*)dest;
4026 uint32_t* dest32 = (uint32_t*)dest;
4027 uint32_t target = (uint32_t)reloc->GetTarget();
4028
4029 switch (info.nativeType)
4030 {
4031 case (uint64_t)-1: // Magic number defined in MachOView.cpp
4032 // We need to write a jump absolute `jmp target`
4033 dest[0] = '\xe9';
4034 ((uint32_t*)&dest[1])[0] = target - (uint32_t)reloc->GetAddress() - 5;
4035 break;
4036 case (uint64_t)-2: // Magic number defined in MachOView.cpp
4037 dest32[0] = target;
4038 break;
4039 case GENERIC_RELOC_VANILLA:
4040 switch (info.size)
4041 {
4042 // TODO these need tested
4043 // case 1: *dest8 = target - pcRelAddr; break;
4044 // case 2: *dest16 = target - pcRelAddr; break;
4045 case 4: *dest32 = (uint32_t)(target - pcRelAddr); break;
4046 default: break;
4047 }
4048 // TODO rebasing
4049 break;
4050
4051 default:
4052 break;
4053 }
4054
4055 return true;
4056 }
4057
4058 virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
4059 {

Callers

nothing calls this directly

Calls 3

GetInfoMethod · 0.80
GetAddressMethod · 0.45
GetTargetMethod · 0.45

Tested by

no test coverage detected