| 4162 | { |
| 4163 | public: |
| 4164 | virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc, uint8_t* dest, size_t len) override |
| 4165 | { |
| 4166 | (void)view; |
| 4167 | (void)arch; |
| 4168 | auto info = reloc->GetInfo(); |
| 4169 | uint64_t pcRelAddr = info.pcRelative ? reloc->GetAddress() : 0; |
| 4170 | if (len < info.size) |
| 4171 | return false; |
| 4172 | uint32_t target = (uint32_t)info.target; |
| 4173 | uint32_t* dest32 = (uint32_t*)dest; |
| 4174 | uint64_t* dest64 = (uint64_t*)dest; |
| 4175 | switch (info.nativeType) |
| 4176 | { |
| 4177 | case X86_64_RELOC_BRANCH: |
| 4178 | if (info.size == 4) |
| 4179 | dest32[0] = dest32[0] - 4 + target - (uint32_t)pcRelAddr; |
| 4180 | break; |
| 4181 | case X86_64_RELOC_GOT_LOAD: |
| 4182 | dest32[0] = dest32[0] - 4 + target - (uint32_t)pcRelAddr; |
| 4183 | break; |
| 4184 | case X86_64_RELOC_SIGNED: |
| 4185 | dest32[0] = dest32[0] + target - (uint32_t)pcRelAddr; |
| 4186 | break; |
| 4187 | case X86_64_RELOC_SIGNED_1: |
| 4188 | dest32[0] = dest32[0] + 1 + target - (uint32_t)pcRelAddr; |
| 4189 | break; |
| 4190 | case X86_64_RELOC_SIGNED_2: |
| 4191 | dest32[0] = dest32[0] + 2 + target - (uint32_t)pcRelAddr; |
| 4192 | break; |
| 4193 | case X86_64_RELOC_SIGNED_4: |
| 4194 | dest32[0] = dest32[0] + 4 + target - (uint32_t)pcRelAddr; |
| 4195 | break; |
| 4196 | case X86_64_RELOC_GOT: |
| 4197 | dest32[0] = dest32[0] + target - (uint32_t)pcRelAddr; |
| 4198 | break; |
| 4199 | case X86_64_RELOC_UNSIGNED: |
| 4200 | switch (info.size) |
| 4201 | { |
| 4202 | case 4: *dest32 += target - (uint32_t)pcRelAddr; break; |
| 4203 | case 8: *dest64 += info.target - pcRelAddr; break; |
| 4204 | default: break; |
| 4205 | } |
| 4206 | // TODO rebasing |
| 4207 | break; |
| 4208 | case X86_64_RELOC_SUBTRACTOR: |
| 4209 | if (!info.next) |
| 4210 | break; |
| 4211 | dest64[0] = dest64[0] + info.next->target - target; |
| 4212 | break; |
| 4213 | case (uint64_t) -2: |
| 4214 | dest64[0] = reloc->GetTarget(); |
| 4215 | break; |
| 4216 | } |
| 4217 | return true; |
| 4218 | } |
| 4219 | |
| 4220 | |
| 4221 | virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override |
nothing calls this directly
no test coverage detected