Skip to content

Commit 2323afe

Browse files
committed
Add basic linux-ilp32 platform support
1 parent 3afb333 commit 2323afe

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

platform/linux/platform_linux.cpp

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ using namespace BinaryNinja;
44
using namespace std;
55

66
Ref<Platform> g_linuxX32;
7+
Ref<Platform> g_linuxIlp32;
78
#define EM_X86_64 62 // AMD x86-64 architecture
9+
#define EM_AARCH64 183 // ARM64 architecture
810

911
class LinuxX86Platform: public Platform
1012
{
@@ -199,6 +201,50 @@ class LinuxArm64Platform: public Platform
199201
}
200202
};
201203

204+
class LinuxIlp32Platform: public Platform
205+
{
206+
public:
207+
LinuxIlp32Platform(Architecture* arch): Platform(arch, "linux-ilp32")
208+
{
209+
Ref<CallingConvention> cc;
210+
211+
cc = arch->GetCallingConventionByName("cdecl");
212+
if (cc)
213+
{
214+
RegisterDefaultCallingConvention(cc);
215+
RegisterCdeclCallingConvention(cc);
216+
RegisterFastcallCallingConvention(cc);
217+
RegisterStdcallCallingConvention(cc);
218+
}
219+
220+
cc = arch->GetCallingConventionByName("linux-syscall");
221+
if (cc)
222+
SetSystemCallConvention(cc);
223+
}
224+
225+
virtual size_t GetAddressSize() const override
226+
{
227+
return 4;
228+
}
229+
230+
static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata)
231+
{
232+
Ref<Metadata> fileClass = metadata->Get("EI_CLASS");
233+
234+
if (!fileClass || !fileClass->IsUnsignedInteger())
235+
return nullptr;
236+
237+
Ref<Metadata> machine = metadata->Get("e_machine");
238+
if (!machine || !machine->IsUnsignedInteger())
239+
return nullptr;
240+
241+
if (fileClass->GetUnsignedInteger() == 1 && machine->GetUnsignedInteger() == EM_AARCH64)
242+
return g_linuxIlp32;
243+
244+
return nullptr;
245+
}
246+
};
247+
202248

203249
class LinuxMipsPlatform: public Platform
204250
{
@@ -406,13 +452,21 @@ extern "C"
406452
Ref<Architecture> arm64 = Architecture::GetByName("aarch64");
407453
if (arm64)
408454
{
409-
Ref<Platform> platform;
455+
Ref<Platform> arm64_platform = new LinuxArm64Platform(arm64);
456+
g_linuxIlp32 = new LinuxIlp32Platform(arm64);
457+
458+
Platform::Register("linux", arm64_platform);
459+
Platform::Register("linux", g_linuxIlp32);
410460

411-
platform = new LinuxArm64Platform(arm64);
412-
Platform::Register("linux", platform);
413461
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
414-
BinaryViewType::RegisterPlatform("ELF", 0, platform);
415-
BinaryViewType::RegisterPlatform("ELF", 3, platform);
462+
BinaryViewType::RegisterPlatform("ELF", 0, arm64_platform);
463+
BinaryViewType::RegisterPlatform("ELF", 3, arm64_platform);
464+
465+
Ref<BinaryViewType> elf = BinaryViewType::GetByName("ELF");
466+
if (elf) {
467+
elf->RegisterPlatformRecognizer(EM_AARCH64, LittleEndian, LinuxIlp32Platform::Recognize);
468+
elf->RegisterPlatformRecognizer(EM_AARCH64, BigEndian, LinuxIlp32Platform::Recognize);
469+
}
416470
}
417471

418472
Ref<Architecture> ppc = Architecture::GetByName("ppc");

0 commit comments

Comments
 (0)