diff options
| author | Alexander Taylor <alex@vector35.com> | 2025-02-25 20:32:24 -0500 |
|---|---|---|
| committer | Alexander Taylor <alex@vector35.com> | 2025-03-10 11:12:09 -0400 |
| commit | 1fc3cd833f19ffa534f04caf541e88042124fd91 (patch) | |
| tree | 772b0c73d87d7831dcd94f53bb4b2d4f1e429c98 | |
| parent | 32455f977824cf50ec0049cad16e741f0d050c73 (diff) | |
Remove platform registration API footgun.
Turns out, you can just pass this thing an architecture that is
*completely* different from the one in the platform you are also passing
in and it'll just happily do the wrong thing. While that's pretty wild,
I'm in favor of not having to make this particular mistake again the
next time I copy/paste some code, so we're now deprecating it.
| -rw-r--r-- | binaryninjaapi.h | 8 | ||||
| -rw-r--r-- | binaryviewtype.cpp | 11 | ||||
| -rw-r--r-- | platform/decree/platform_decree.cpp | 2 | ||||
| -rw-r--r-- | platform/freebsd/platform_freebsd.cpp | 8 | ||||
| -rw-r--r-- | platform/linux/platform_linux.cpp | 76 |
5 files changed, 62 insertions, 43 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 08e3feb5..4336febb 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -7205,6 +7205,14 @@ namespace BinaryNinja { \param name Name of the BinaryViewType \param id ID of the platform + \param platform The Platform to register + */ + static void RegisterPlatform(const std::string& name, uint32_t id, Platform* platform); + + /*! Register a Platform for a specific view type (this form is deprecated as of 4.3, please use the form without architecture as an argument instead) + + \param name Name of the BinaryViewType + \param id ID of the platform \param arch Architecture to register this platform with \param platform The Platform to register */ diff --git a/binaryviewtype.cpp b/binaryviewtype.cpp index 2ee8e2ac..d0479a11 100644 --- a/binaryviewtype.cpp +++ b/binaryviewtype.cpp @@ -174,6 +174,17 @@ Ref<Architecture> BinaryViewType::GetArchitecture(uint32_t id, BNEndianness endi } +void BinaryViewType::RegisterPlatform(const string& name, uint32_t id, Platform* platform) +{ + Ref<BinaryViewType> type = BinaryViewType::GetByName(name); + if (!type) + return; + Ref<Architecture> arch = platform->GetArchitecture(); + if (!arch) + return; + type->RegisterPlatform(id, arch, platform); +} + void BinaryViewType::RegisterPlatform(const string& name, uint32_t id, Architecture* arch, Platform* platform) { Ref<BinaryViewType> type = BinaryViewType::GetByName(name); diff --git a/platform/decree/platform_decree.cpp b/platform/decree/platform_decree.cpp index 4d26566c..5c69490c 100644 --- a/platform/decree/platform_decree.cpp +++ b/platform/decree/platform_decree.cpp @@ -58,7 +58,7 @@ extern "C" platform = new DecreeX86Platform(x86); Platform::Register("decree", platform); - BinaryViewType::RegisterPlatform("ELF", 'C', x86, platform); + BinaryViewType::RegisterPlatform("ELF", 'C', platform); } return true; diff --git a/platform/freebsd/platform_freebsd.cpp b/platform/freebsd/platform_freebsd.cpp index 8aa28f7f..d25bbc08 100644 --- a/platform/freebsd/platform_freebsd.cpp +++ b/platform/freebsd/platform_freebsd.cpp @@ -113,7 +113,7 @@ extern "C" platform = new FreeBSDX86Platform(x86); Platform::Register("freebsd", platform); - BinaryViewType::RegisterPlatform("ELF", 9, x86, platform); + BinaryViewType::RegisterPlatform("ELF", 9, platform); } Ref<Architecture> x64 = Architecture::GetByName("x86_64"); @@ -123,7 +123,7 @@ extern "C" platform = new FreeBSDX64Platform(x64); Platform::Register("freebsd", platform); - BinaryViewType::RegisterPlatform("ELF", 9, x64, platform); + BinaryViewType::RegisterPlatform("ELF", 9, platform); } Ref<Architecture> armv7 = Architecture::GetByName("armv7"); @@ -138,7 +138,7 @@ extern "C" thumbPlatform->AddRelatedPlatform(armv7, armPlatform); Platform::Register("freebsd", armPlatform); Platform::Register("freebsd", thumbPlatform); - BinaryViewType::RegisterPlatform("ELF", 9, armv7, armPlatform); + BinaryViewType::RegisterPlatform("ELF", 9, armPlatform); } Ref<Architecture> arm64 = Architecture::GetByName("aarch64"); @@ -148,7 +148,7 @@ extern "C" platform = new FreeBSDArm64Platform(arm64); Platform::Register("freebsd", platform); - BinaryViewType::RegisterPlatform("ELF", 9, arm64, platform); + BinaryViewType::RegisterPlatform("ELF", 9, platform); } return true; diff --git a/platform/linux/platform_linux.cpp b/platform/linux/platform_linux.cpp index 2ba346f8..3bbb7248 100644 --- a/platform/linux/platform_linux.cpp +++ b/platform/linux/platform_linux.cpp @@ -307,8 +307,8 @@ extern "C" platform = new LinuxX86Platform(x86); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, x86, platform); - BinaryViewType::RegisterPlatform("ELF", 3, x86, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } Ref<Architecture> x64 = Architecture::GetByName("x86_64"); @@ -319,8 +319,8 @@ extern "C" platform = new LinuxX64Platform(x64); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, x64, platform); - BinaryViewType::RegisterPlatform("ELF", 3, x64, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } Ref<Architecture> armv7 = Architecture::GetByName("armv7"); @@ -344,10 +344,10 @@ extern "C" Platform::Register("linux", armebPlatform); Platform::Register("linux", thumbebPlatform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, armv7, armPlatform); - BinaryViewType::RegisterPlatform("ELF", 3, armv7, armPlatform); - BinaryViewType::RegisterPlatform("ELF", 0, armv7eb, armebPlatform); - BinaryViewType::RegisterPlatform("ELF", 3, armv7eb, armebPlatform); + BinaryViewType::RegisterPlatform("ELF", 0, armPlatform); + BinaryViewType::RegisterPlatform("ELF", 3, armPlatform); + BinaryViewType::RegisterPlatform("ELF", 0, armebPlatform); + BinaryViewType::RegisterPlatform("ELF", 3, armebPlatform); } Ref<Architecture> arm64 = Architecture::GetByName("aarch64"); @@ -358,8 +358,8 @@ extern "C" platform = new LinuxArm64Platform(arm64); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, arm64, platform); - BinaryViewType::RegisterPlatform("ELF", 3, arm64, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } Ref<Architecture> ppc = Architecture::GetByName("ppc"); @@ -374,10 +374,10 @@ extern "C" Platform::Register("linux", platform); Platform::Register("linux", platformle); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, ppc, platform); - BinaryViewType::RegisterPlatform("ELF", 3, ppc, platform); - BinaryViewType::RegisterPlatform("ELF", 0, ppcle, platformle); - BinaryViewType::RegisterPlatform("ELF", 3, ppcle, platformle); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platformle); + BinaryViewType::RegisterPlatform("ELF", 3, platformle); } Ref<Architecture> ppc64 = Architecture::GetByName("ppc64"); @@ -392,10 +392,10 @@ extern "C" Platform::Register("linux", platform); Platform::Register("linux", platformle); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, ppc64, platform); - BinaryViewType::RegisterPlatform("ELF", 3, ppc64, platform); - BinaryViewType::RegisterPlatform("ELF", 0, ppc64le, platformle); - BinaryViewType::RegisterPlatform("ELF", 3, ppc64le, platformle); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platformle); + BinaryViewType::RegisterPlatform("ELF", 3, platformle); } Ref<Architecture> mipsel = Architecture::GetByName("mipsel32"); @@ -421,18 +421,18 @@ extern "C" Platform::Register("linux", platformBE64); Platform::Register("linux", platformBE64cn); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, mipsel, platformLE); - BinaryViewType::RegisterPlatform("ELF", 0, mipseb, platformBE); - BinaryViewType::RegisterPlatform("ELF", 0, mips3el, platform3LE); - BinaryViewType::RegisterPlatform("ELF", 0, mips3eb, platform3BE); - BinaryViewType::RegisterPlatform("ELF", 0, mips64eb, platformBE64); - BinaryViewType::RegisterPlatform("ELF", 0, cnmips64eb, platformBE64cn); - BinaryViewType::RegisterPlatform("ELF", 3, mipsel, platformLE); - BinaryViewType::RegisterPlatform("ELF", 3, mipseb, platformBE); - BinaryViewType::RegisterPlatform("ELF", 3, mips3el, platform3LE); - BinaryViewType::RegisterPlatform("ELF", 3, mips3eb, platform3BE); - BinaryViewType::RegisterPlatform("ELF", 3, mips64eb, platformBE64); - BinaryViewType::RegisterPlatform("ELF", 3, cnmips64eb, platformBE64cn); + BinaryViewType::RegisterPlatform("ELF", 0, platformLE); + BinaryViewType::RegisterPlatform("ELF", 0, platformBE); + BinaryViewType::RegisterPlatform("ELF", 0, platform3LE); + BinaryViewType::RegisterPlatform("ELF", 0, platform3BE); + BinaryViewType::RegisterPlatform("ELF", 0, platformBE64); + BinaryViewType::RegisterPlatform("ELF", 0, platformBE64cn); + BinaryViewType::RegisterPlatform("ELF", 3, platformLE); + BinaryViewType::RegisterPlatform("ELF", 3, platformBE); + BinaryViewType::RegisterPlatform("ELF", 3, platform3LE); + BinaryViewType::RegisterPlatform("ELF", 3, platform3BE); + BinaryViewType::RegisterPlatform("ELF", 3, platformBE64); + BinaryViewType::RegisterPlatform("ELF", 3, platformBE64cn); } Ref<Architecture> rv32 = Architecture::GetByName("rv32gc"); @@ -443,8 +443,8 @@ extern "C" platform = new LinuxRiscVPlatform(rv32, "linux-rv32gc"); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, rv32, platform); - BinaryViewType::RegisterPlatform("ELF", 3, rv32, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } Ref<Architecture> rv64 = Architecture::GetByName("rv64gc"); @@ -455,8 +455,8 @@ extern "C" platform = new LinuxRiscVPlatform(rv64, "linux-rv64gc"); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, rv64, platform); - BinaryViewType::RegisterPlatform("ELF", 3, rv64, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } #ifdef ULTIMATE_EDITION @@ -468,8 +468,8 @@ extern "C" platform = new LinuxCSkyV1Platform(cskyv1, "linux-csky_le_v1"); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, cskyv1, platform); - BinaryViewType::RegisterPlatform("ELF", 3, cskyv1, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } Ref<Architecture> cskyv2 = Architecture::GetByName("csky_le"); @@ -480,8 +480,8 @@ extern "C" platform = new LinuxCSkyV2Platform(cskyv2, "linux-csky_le"); Platform::Register("linux", platform); // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one - BinaryViewType::RegisterPlatform("ELF", 0, cskyv2, platform); - BinaryViewType::RegisterPlatform("ELF", 3, cskyv2, platform); + BinaryViewType::RegisterPlatform("ELF", 0, platform); + BinaryViewType::RegisterPlatform("ELF", 3, platform); } #endif |
