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

Method ApplyRelocation

arch/powerpc/arch_ppc.cpp:2378–2433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2376{
2377public:
2378 virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc, uint8_t* dest, size_t len) override
2379 {
2380 (void)view;
2381 (void)len;
2382 auto info = reloc->GetInfo();
2383 uint32_t* dest32 = (uint32_t*)dest;
2384 uint16_t* dest16 = (uint16_t*)dest;
2385 auto swap = [&arch](uint32_t x) { return (arch->GetEndianness() == LittleEndian)? x : bswap32(x); };
2386 auto swap16 = [&arch](uint16_t x) { return (arch->GetEndianness() == LittleEndian)? x : bswap16(x); };
2387 uint64_t target = reloc->GetTarget();
2388 switch (info.nativeType)
2389 {
2390 case R_PPC_ADDR16_LO:
2391 dest16[0] = swap16((uint16_t)((target + info.addend) & 0xffff));
2392 break;
2393 case R_PPC_ADDR16_HA:
2394 dest16[0] = swap16((uint16_t)((target + info.addend) >> 16));
2395 break;
2396 case R_PPC_REL24:
2397 dest32[0] = swap((swap(dest32[0]) & 0xfc000003) |
2398 (uint32_t)((((target + info.addend - reloc->GetAddress()) >> 2) & 0xffffff) << 2));
2399 break;
2400 case R_PPC_REL16_HA:
2401 dest16[0] = swap16(HA(target - reloc->GetAddress() + info.addend));
2402 break;
2403 case R_PPC_REL16_HI:
2404 dest16[0] = swap16((uint16_t)((target - reloc->GetAddress()+ info.addend) >> 16));
2405 break;
2406 case R_PPC_REL16_LO:
2407 dest16[0] = swap16((uint16_t)((target - reloc->GetAddress()+ info.addend) & 0xffff));
2408 break;
2409 case R_PPC_JMP_SLOT:
2410 case R_PPC_GLOB_DAT:
2411 case R_PPC_COPY:
2412 dest32[0] = swap((uint32_t)target);
2413 break;
2414 case R_PPC_PLTREL24:
2415 dest32[0] = swap((swap(dest32[0]) & 0xfc000003) |
2416 (uint32_t)((((target + info.addend - reloc->GetAddress()) >> 2) & 0xffffff) << 2));
2417 break;
2418 case R_PPC_LOCAL24PC:
2419 dest32[0] = swap((swap(dest32[0]) & 0xfc000003) |
2420 (uint32_t)((((target + info.addend - reloc->GetAddress()) >> 2) & 0xffffff) << 2));
2421 break;
2422 case R_PPC_ADDR32:
2423 dest32[0] = swap((uint32_t)(target + info.addend));
2424 break;
2425 case R_PPC_RELATIVE:
2426 dest32[0] = swap((uint32_t)info.base);
2427 break;
2428 case R_PPC_REL32:
2429 dest32[0] = swap((uint32_t)(target - reloc->GetAddress() + info.addend));
2430 break;
2431 }
2432 return true;
2433 }
2434
2435 virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override

Callers

nothing calls this directly

Calls 7

bswap16Function · 0.85
GetInfoMethod · 0.80
bswap32Function · 0.70
swapFunction · 0.50
GetEndiannessMethod · 0.45
GetTargetMethod · 0.45
GetAddressMethod · 0.45

Tested by

no test coverage detected