| 4545 | } |
| 4546 | |
| 4547 | virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override |
| 4548 | { |
| 4549 | (void)view; (void)arch; |
| 4550 | set<uint64_t> relocTypes; |
| 4551 | for (auto& reloc : result) |
| 4552 | { |
| 4553 | if (arch->GetName() == "x86_64") |
| 4554 | { |
| 4555 | switch (reloc.nativeType) |
| 4556 | { |
| 4557 | case PE_IMAGE_REL_AMD64_ABSOLUTE: |
| 4558 | reloc.type = IgnoredRelocation; |
| 4559 | break; |
| 4560 | case PE_IMAGE_REL_AMD64_ADDR64: |
| 4561 | reloc.baseRelative = true; |
| 4562 | reloc.size = 8; |
| 4563 | break; |
| 4564 | case PE_IMAGE_REL_AMD64_ADDR32NB: |
| 4565 | reloc.baseRelative = false; |
| 4566 | reloc.size = 4; |
| 4567 | break; |
| 4568 | case PE_IMAGE_REL_AMD64_ADDR32: |
| 4569 | reloc.baseRelative = true; |
| 4570 | reloc.size = 4; |
| 4571 | break; |
| 4572 | case PE_IMAGE_REL_AMD64_REL32_5: |
| 4573 | case PE_IMAGE_REL_AMD64_REL32_4: |
| 4574 | case PE_IMAGE_REL_AMD64_REL32_3: |
| 4575 | case PE_IMAGE_REL_AMD64_REL32_2: |
| 4576 | case PE_IMAGE_REL_AMD64_REL32_1: |
| 4577 | // LogDebug("%s: %#" PRIx64 "(%#" PRIx64 ")->%#" PRIx64 " %s addend: %ld", __func__, reloc.address, reloc.target, reloc.address - reloc.target, GetRelocationString((COFFx64RelocationType)reloc.nativeType), (long) reloc.addend); |
| 4578 | case PE_IMAGE_REL_AMD64_REL32: |
| 4579 | // TODO: treat reloc.addend as offset of target from its section (see llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h:67) |
| 4580 | reloc.addend = -(4 + (reloc.nativeType - PE_IMAGE_REL_AMD64_REL32)); |
| 4581 | reloc.baseRelative = false; |
| 4582 | reloc.pcRelative = true; |
| 4583 | reloc.size = 4; |
| 4584 | break; |
| 4585 | case PE_IMAGE_REL_AMD64_SECTION: |
| 4586 | // The 16-bit section index of the section that contains the target. This is used to support debugging information. |
| 4587 | reloc.baseRelative = false; |
| 4588 | reloc.size = 2; |
| 4589 | reloc.addend = 0; |
| 4590 | case PE_IMAGE_REL_AMD64_SECREL: |
| 4591 | // TODO: implement these, but for now, just don't warn about them |
| 4592 | // The 32-bit offset of the target from the beginning of its section. This is used to support debugging information and static thread local storage. reloc.baseRelative = false; |
| 4593 | reloc.baseRelative = false; |
| 4594 | reloc.size = 4; |
| 4595 | reloc.addend = 0; |
| 4596 | break; |
| 4597 | case PE_IMAGE_REL_AMD64_SECREL7: |
| 4598 | // 7-bit offset from the base of the section that contains the target |
| 4599 | case PE_IMAGE_REL_AMD64_TOKEN: |
| 4600 | case PE_IMAGE_REL_AMD64_SREL32: |
| 4601 | case PE_IMAGE_REL_AMD64_PAIR: |
| 4602 | case PE_IMAGE_REL_AMD64_SSPAN32: |
| 4603 | default: |
| 4604 | // By default, PE relocations are correct when not rebased. |
nothing calls this directly
no test coverage detected