Skip to content

Commit 1fc3cd8

Browse files
committed
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.
1 parent 32455f9 commit 1fc3cd8

File tree

5 files changed

+62
-43
lines changed

5 files changed

+62
-43
lines changed

Diff for: binaryninjaapi.h

+8
Original file line numberDiff line numberDiff line change
@@ -7203,6 +7203,14 @@ namespace BinaryNinja {
72037203

72047204
/*! Register a Platform for a specific view type
72057205

7206+
\param name Name of the BinaryViewType
7207+
\param id ID of the platform
7208+
\param platform The Platform to register
7209+
*/
7210+
static void RegisterPlatform(const std::string& name, uint32_t id, Platform* platform);
7211+
7212+
/*! 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)
7213+
72067214
\param name Name of the BinaryViewType
72077215
\param id ID of the platform
72087216
\param arch Architecture to register this platform with

Diff for: binaryviewtype.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ Ref<Architecture> BinaryViewType::GetArchitecture(uint32_t id, BNEndianness endi
174174
}
175175

176176

177+
void BinaryViewType::RegisterPlatform(const string& name, uint32_t id, Platform* platform)
178+
{
179+
Ref<BinaryViewType> type = BinaryViewType::GetByName(name);
180+
if (!type)
181+
return;
182+
Ref<Architecture> arch = platform->GetArchitecture();
183+
if (!arch)
184+
return;
185+
type->RegisterPlatform(id, arch, platform);
186+
}
187+
177188
void BinaryViewType::RegisterPlatform(const string& name, uint32_t id, Architecture* arch, Platform* platform)
178189
{
179190
Ref<BinaryViewType> type = BinaryViewType::GetByName(name);

Diff for: platform/decree/platform_decree.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern "C"
5858

5959
platform = new DecreeX86Platform(x86);
6060
Platform::Register("decree", platform);
61-
BinaryViewType::RegisterPlatform("ELF", 'C', x86, platform);
61+
BinaryViewType::RegisterPlatform("ELF", 'C', platform);
6262
}
6363

6464
return true;

Diff for: platform/freebsd/platform_freebsd.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern "C"
113113

114114
platform = new FreeBSDX86Platform(x86);
115115
Platform::Register("freebsd", platform);
116-
BinaryViewType::RegisterPlatform("ELF", 9, x86, platform);
116+
BinaryViewType::RegisterPlatform("ELF", 9, platform);
117117
}
118118

119119
Ref<Architecture> x64 = Architecture::GetByName("x86_64");
@@ -123,7 +123,7 @@ extern "C"
123123

124124
platform = new FreeBSDX64Platform(x64);
125125
Platform::Register("freebsd", platform);
126-
BinaryViewType::RegisterPlatform("ELF", 9, x64, platform);
126+
BinaryViewType::RegisterPlatform("ELF", 9, platform);
127127
}
128128

129129
Ref<Architecture> armv7 = Architecture::GetByName("armv7");
@@ -138,7 +138,7 @@ extern "C"
138138
thumbPlatform->AddRelatedPlatform(armv7, armPlatform);
139139
Platform::Register("freebsd", armPlatform);
140140
Platform::Register("freebsd", thumbPlatform);
141-
BinaryViewType::RegisterPlatform("ELF", 9, armv7, armPlatform);
141+
BinaryViewType::RegisterPlatform("ELF", 9, armPlatform);
142142
}
143143

144144
Ref<Architecture> arm64 = Architecture::GetByName("aarch64");
@@ -148,7 +148,7 @@ extern "C"
148148

149149
platform = new FreeBSDArm64Platform(arm64);
150150
Platform::Register("freebsd", platform);
151-
BinaryViewType::RegisterPlatform("ELF", 9, arm64, platform);
151+
BinaryViewType::RegisterPlatform("ELF", 9, platform);
152152
}
153153

154154
return true;

Diff for: platform/linux/platform_linux.cpp

+38-38
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ extern "C"
307307
platform = new LinuxX86Platform(x86);
308308
Platform::Register("linux", platform);
309309
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
310-
BinaryViewType::RegisterPlatform("ELF", 0, x86, platform);
311-
BinaryViewType::RegisterPlatform("ELF", 3, x86, platform);
310+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
311+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
312312
}
313313

314314
Ref<Architecture> x64 = Architecture::GetByName("x86_64");
@@ -319,8 +319,8 @@ extern "C"
319319
platform = new LinuxX64Platform(x64);
320320
Platform::Register("linux", platform);
321321
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
322-
BinaryViewType::RegisterPlatform("ELF", 0, x64, platform);
323-
BinaryViewType::RegisterPlatform("ELF", 3, x64, platform);
322+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
323+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
324324
}
325325

326326
Ref<Architecture> armv7 = Architecture::GetByName("armv7");
@@ -344,10 +344,10 @@ extern "C"
344344
Platform::Register("linux", armebPlatform);
345345
Platform::Register("linux", thumbebPlatform);
346346
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
347-
BinaryViewType::RegisterPlatform("ELF", 0, armv7, armPlatform);
348-
BinaryViewType::RegisterPlatform("ELF", 3, armv7, armPlatform);
349-
BinaryViewType::RegisterPlatform("ELF", 0, armv7eb, armebPlatform);
350-
BinaryViewType::RegisterPlatform("ELF", 3, armv7eb, armebPlatform);
347+
BinaryViewType::RegisterPlatform("ELF", 0, armPlatform);
348+
BinaryViewType::RegisterPlatform("ELF", 3, armPlatform);
349+
BinaryViewType::RegisterPlatform("ELF", 0, armebPlatform);
350+
BinaryViewType::RegisterPlatform("ELF", 3, armebPlatform);
351351
}
352352

353353
Ref<Architecture> arm64 = Architecture::GetByName("aarch64");
@@ -358,8 +358,8 @@ extern "C"
358358
platform = new LinuxArm64Platform(arm64);
359359
Platform::Register("linux", platform);
360360
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
361-
BinaryViewType::RegisterPlatform("ELF", 0, arm64, platform);
362-
BinaryViewType::RegisterPlatform("ELF", 3, arm64, platform);
361+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
362+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
363363
}
364364

365365
Ref<Architecture> ppc = Architecture::GetByName("ppc");
@@ -374,10 +374,10 @@ extern "C"
374374
Platform::Register("linux", platform);
375375
Platform::Register("linux", platformle);
376376
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
377-
BinaryViewType::RegisterPlatform("ELF", 0, ppc, platform);
378-
BinaryViewType::RegisterPlatform("ELF", 3, ppc, platform);
379-
BinaryViewType::RegisterPlatform("ELF", 0, ppcle, platformle);
380-
BinaryViewType::RegisterPlatform("ELF", 3, ppcle, platformle);
377+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
378+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
379+
BinaryViewType::RegisterPlatform("ELF", 0, platformle);
380+
BinaryViewType::RegisterPlatform("ELF", 3, platformle);
381381
}
382382

383383
Ref<Architecture> ppc64 = Architecture::GetByName("ppc64");
@@ -392,10 +392,10 @@ extern "C"
392392
Platform::Register("linux", platform);
393393
Platform::Register("linux", platformle);
394394
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
395-
BinaryViewType::RegisterPlatform("ELF", 0, ppc64, platform);
396-
BinaryViewType::RegisterPlatform("ELF", 3, ppc64, platform);
397-
BinaryViewType::RegisterPlatform("ELF", 0, ppc64le, platformle);
398-
BinaryViewType::RegisterPlatform("ELF", 3, ppc64le, platformle);
395+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
396+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
397+
BinaryViewType::RegisterPlatform("ELF", 0, platformle);
398+
BinaryViewType::RegisterPlatform("ELF", 3, platformle);
399399
}
400400

401401
Ref<Architecture> mipsel = Architecture::GetByName("mipsel32");
@@ -421,18 +421,18 @@ extern "C"
421421
Platform::Register("linux", platformBE64);
422422
Platform::Register("linux", platformBE64cn);
423423
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
424-
BinaryViewType::RegisterPlatform("ELF", 0, mipsel, platformLE);
425-
BinaryViewType::RegisterPlatform("ELF", 0, mipseb, platformBE);
426-
BinaryViewType::RegisterPlatform("ELF", 0, mips3el, platform3LE);
427-
BinaryViewType::RegisterPlatform("ELF", 0, mips3eb, platform3BE);
428-
BinaryViewType::RegisterPlatform("ELF", 0, mips64eb, platformBE64);
429-
BinaryViewType::RegisterPlatform("ELF", 0, cnmips64eb, platformBE64cn);
430-
BinaryViewType::RegisterPlatform("ELF", 3, mipsel, platformLE);
431-
BinaryViewType::RegisterPlatform("ELF", 3, mipseb, platformBE);
432-
BinaryViewType::RegisterPlatform("ELF", 3, mips3el, platform3LE);
433-
BinaryViewType::RegisterPlatform("ELF", 3, mips3eb, platform3BE);
434-
BinaryViewType::RegisterPlatform("ELF", 3, mips64eb, platformBE64);
435-
BinaryViewType::RegisterPlatform("ELF", 3, cnmips64eb, platformBE64cn);
424+
BinaryViewType::RegisterPlatform("ELF", 0, platformLE);
425+
BinaryViewType::RegisterPlatform("ELF", 0, platformBE);
426+
BinaryViewType::RegisterPlatform("ELF", 0, platform3LE);
427+
BinaryViewType::RegisterPlatform("ELF", 0, platform3BE);
428+
BinaryViewType::RegisterPlatform("ELF", 0, platformBE64);
429+
BinaryViewType::RegisterPlatform("ELF", 0, platformBE64cn);
430+
BinaryViewType::RegisterPlatform("ELF", 3, platformLE);
431+
BinaryViewType::RegisterPlatform("ELF", 3, platformBE);
432+
BinaryViewType::RegisterPlatform("ELF", 3, platform3LE);
433+
BinaryViewType::RegisterPlatform("ELF", 3, platform3BE);
434+
BinaryViewType::RegisterPlatform("ELF", 3, platformBE64);
435+
BinaryViewType::RegisterPlatform("ELF", 3, platformBE64cn);
436436
}
437437

438438
Ref<Architecture> rv32 = Architecture::GetByName("rv32gc");
@@ -443,8 +443,8 @@ extern "C"
443443
platform = new LinuxRiscVPlatform(rv32, "linux-rv32gc");
444444
Platform::Register("linux", platform);
445445
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
446-
BinaryViewType::RegisterPlatform("ELF", 0, rv32, platform);
447-
BinaryViewType::RegisterPlatform("ELF", 3, rv32, platform);
446+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
447+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
448448
}
449449

450450
Ref<Architecture> rv64 = Architecture::GetByName("rv64gc");
@@ -455,8 +455,8 @@ extern "C"
455455
platform = new LinuxRiscVPlatform(rv64, "linux-rv64gc");
456456
Platform::Register("linux", platform);
457457
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
458-
BinaryViewType::RegisterPlatform("ELF", 0, rv64, platform);
459-
BinaryViewType::RegisterPlatform("ELF", 3, rv64, platform);
458+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
459+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
460460
}
461461

462462
#ifdef ULTIMATE_EDITION
@@ -468,8 +468,8 @@ extern "C"
468468
platform = new LinuxCSkyV1Platform(cskyv1, "linux-csky_le_v1");
469469
Platform::Register("linux", platform);
470470
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
471-
BinaryViewType::RegisterPlatform("ELF", 0, cskyv1, platform);
472-
BinaryViewType::RegisterPlatform("ELF", 3, cskyv1, platform);
471+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
472+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
473473
}
474474

475475
Ref<Architecture> cskyv2 = Architecture::GetByName("csky_le");
@@ -480,8 +480,8 @@ extern "C"
480480
platform = new LinuxCSkyV2Platform(cskyv2, "linux-csky_le");
481481
Platform::Register("linux", platform);
482482
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
483-
BinaryViewType::RegisterPlatform("ELF", 0, cskyv2, platform);
484-
BinaryViewType::RegisterPlatform("ELF", 3, cskyv2, platform);
483+
BinaryViewType::RegisterPlatform("ELF", 0, platform);
484+
BinaryViewType::RegisterPlatform("ELF", 3, platform);
485485
}
486486
#endif
487487

0 commit comments

Comments
 (0)