Skip to content

Commit

Permalink
Support Mach-O Rebase Relocation magic
Browse files Browse the repository at this point in the history
  • Loading branch information
0cyn committed Nov 21, 2022
1 parent 15a7ac1 commit 1ab8df4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion arch_armv7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,18 @@ class ArmElfRelocationHandler: public RelocationHandler
class ArmMachORelocationHandler: public RelocationHandler
{
public:
virtual bool ApplyRelocation(Ref<BinaryView> view, Ref<Architecture> arch, Ref<Relocation> reloc,
uint8_t* dest, size_t len) override
{
auto info = reloc->GetInfo();
if (info.nativeType == BINARYNINJA_MANUAL_RELOCATION)
{ // Magic number defined in MachOView.cpp for tagged pointers
*(uint32_t*)dest = (uint32_t)info.target;
}

return true;
}

virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
{
(void)view;
Expand Down Expand Up @@ -3171,8 +3183,10 @@ static void RegisterArmArchitecture(const char* armName, const char* thumbName,
armv7->RegisterRelocationHandler("Mach-O", new ArmMachORelocationHandler());
armv7->RegisterRelocationHandler("PE", new ArmPERelocationHandler());
armv7->RegisterRelocationHandler("COFF", new ArmCOFFRelocationHandler());
thumb2->RegisterRelocationHandler("COFF", new ArmCOFFRelocationHandler());

thumb2->RegisterRelocationHandler("ELF", new ArmElfRelocationHandler());
thumb2->RegisterRelocationHandler("Mach-O", new ArmMachORelocationHandler());
thumb2->RegisterRelocationHandler("COFF", new ArmCOFFRelocationHandler());

armv7->GetStandalonePlatform()->AddRelatedPlatform(thumb2, thumb2->GetStandalonePlatform());
thumb2->GetStandalonePlatform()->AddRelatedPlatform(armv7, armv7->GetStandalonePlatform());
Expand Down
2 changes: 2 additions & 0 deletions arch_armv7.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "binaryninjaapi.h"
#include "armv7.h"

#define BINARYNINJA_MANUAL_RELOCATION ((uint64_t)-2)

class ArmCommonArchitecture: public BinaryNinja::Architecture
{
protected:
Expand Down

0 comments on commit 1ab8df4

Please sign in to comment.