mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Merge remote-tracking branch
'origin/GP-3960_ryanmkurtz_ElfLoader_swift_go--SQUASHED' (Closes #8795)
This commit is contained in:
@@ -1070,7 +1070,7 @@ public class ElfHeader implements StructConverter {
|
|||||||
return offset >= 0 && (offset + length) <= provider.length();
|
return offset >= 0 && (offset + length) <= provider.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseSectionHeaders() throws IOException {
|
public void parseSectionHeaders() throws IOException {
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IOException("ELF binary reader is null!");
|
throw new IOException("ELF binary reader is null!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ import java.util.*;
|
|||||||
|
|
||||||
import ghidra.app.util.Option;
|
import ghidra.app.util.Option;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
import ghidra.app.util.bin.ByteProvider;
|
||||||
import ghidra.app.util.bin.format.elf.ElfException;
|
import ghidra.app.util.bin.format.elf.*;
|
||||||
import ghidra.app.util.bin.format.elf.ElfHeader;
|
import ghidra.app.util.bin.format.golang.GoConstants;
|
||||||
|
import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper;
|
||||||
|
import ghidra.app.util.bin.format.swift.SwiftUtils;
|
||||||
import ghidra.framework.model.DomainObject;
|
import ghidra.framework.model.DomainObject;
|
||||||
import ghidra.framework.model.ProjectData;
|
import ghidra.framework.model.ProjectData;
|
||||||
import ghidra.framework.options.Options;
|
import ghidra.framework.options.Options;
|
||||||
@@ -102,8 +104,13 @@ public class ElfLoader extends AbstractLibrarySupportLoader {
|
|||||||
try {
|
try {
|
||||||
ElfHeader elf = new ElfHeader(provider, null);
|
ElfHeader elf = new ElfHeader(provider, null);
|
||||||
|
|
||||||
List<QueryResult> results =
|
Set<QueryResult> results = new HashSet<>();
|
||||||
QueryOpinionService.query(getName(), elf.getMachineName(), elf.getFlags());
|
String machine = elf.getMachineName();
|
||||||
|
String compiler = detectCompilerName(elf);
|
||||||
|
if (compiler != null) {
|
||||||
|
results.addAll(QueryOpinionService.query(getName(), machine, compiler));
|
||||||
|
}
|
||||||
|
results.addAll(QueryOpinionService.query(getName(), machine, elf.getFlags()));
|
||||||
for (QueryResult result : results) {
|
for (QueryResult result : results) {
|
||||||
boolean add = true;
|
boolean add = true;
|
||||||
// Some languages are defined with sizes smaller than 32
|
// Some languages are defined with sizes smaller than 32
|
||||||
@@ -170,4 +177,25 @@ public class ElfLoader extends AbstractLibrarySupportLoader {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return ELF_NAME;
|
return ELF_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to detect a more specific compiler from the ELF
|
||||||
|
*
|
||||||
|
* @param elf The {@link ElfHeader}
|
||||||
|
* @return The detected compiler name, or {@code null} if one couldn't be detected
|
||||||
|
* @throws IOException if an IO-related error occurred
|
||||||
|
*/
|
||||||
|
private String detectCompilerName(ElfHeader elf) throws IOException {
|
||||||
|
elf.parseSectionHeaders();
|
||||||
|
List<String> sectionNames = Arrays.stream(elf.getSections())
|
||||||
|
.map(ElfSectionHeader::getNameAsString)
|
||||||
|
.toList();
|
||||||
|
if (SwiftUtils.isSwift(sectionNames)) {
|
||||||
|
return SwiftUtils.SWIFT_COMPILER;
|
||||||
|
}
|
||||||
|
if (GoRttiMapper.hasGolangSections(sectionNames)) {
|
||||||
|
return GoConstants.GOLANG_CSPEC_NAME;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ public class MachoLoader extends AbstractLibrarySupportLoader {
|
|||||||
* Attempts to detect a more specific compiler from the Mach-O
|
* Attempts to detect a more specific compiler from the Mach-O
|
||||||
*
|
*
|
||||||
* @param machHeader The {@link MachHeader}
|
* @param machHeader The {@link MachHeader}
|
||||||
* @return The detected compiler name, or {@code null} if one could be detected
|
* @return The detected compiler name, or {@code null} if one couldn't be detected
|
||||||
* @throws IOException if an IO-related error occurred
|
* @throws IOException if an IO-related error occurred
|
||||||
*/
|
*/
|
||||||
private String detectCompilerName(MachHeader machHeader) throws IOException {
|
private String detectCompilerName(MachHeader machHeader) throws IOException {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<compiler name="default" spec="AARCH64.cspec" id="default"/>
|
<compiler name="default" spec="AARCH64.cspec" id="default"/>
|
||||||
<compiler name="Visual Studio" spec="AARCH64_win.cspec" id="windows"/>
|
<compiler name="Visual Studio" spec="AARCH64_win.cspec" id="windows"/>
|
||||||
<compiler name="golang" spec="AARCH64_golang.cspec" id="golang"/>
|
<compiler name="golang" spec="AARCH64_golang.cspec" id="golang"/>
|
||||||
|
<compiler name="Swift" spec="AARCH64_swift.cspec" id="swift"/>
|
||||||
<external_name tool="gnu" name="aarch64"/>
|
<external_name tool="gnu" name="aarch64"/>
|
||||||
<external_name tool="DWARF.register.mapping.file" name="AARCH64.dwarf"/>
|
<external_name tool="DWARF.register.mapping.file" name="AARCH64.dwarf"/>
|
||||||
<external_name tool="Golang.register.info.file" name="AARCH64_golang.register.info"/>
|
<external_name tool="Golang.register.info.file" name="AARCH64_golang.register.info"/>
|
||||||
|
|||||||
@@ -5,6 +5,12 @@
|
|||||||
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="default">
|
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="default">
|
||||||
<constraint primary="183" processor="AARCH64" size="32" variant="ilp32" />
|
<constraint primary="183" processor="AARCH64" size="32" variant="ilp32" />
|
||||||
</constraint>
|
</constraint>
|
||||||
|
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="golang">
|
||||||
|
<constraint primary="183" secondary="golang" processor="AARCH64" endian="little" size="64" variant="v8A" />
|
||||||
|
</constraint>
|
||||||
|
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="swift">
|
||||||
|
<constraint primary="183" secondary="swift" processor="AARCH64" endian="little" size="64" variant="v8A" />
|
||||||
|
</constraint>
|
||||||
<constraint loader="Mac OS X Mach-O" compilerSpecID="default">
|
<constraint loader="Mac OS X Mach-O" compilerSpecID="default">
|
||||||
<constraint primary="16777228" processor="AARCH64" endian="little" size="64" variant="AppleSilicon" />
|
<constraint primary="16777228" processor="AARCH64" endian="little" size="64" variant="AppleSilicon" />
|
||||||
<constraint primary="33554444" processor="AARCH64" endian="little" size="32" variant="ilp32" />
|
<constraint primary="33554444" processor="AARCH64" endian="little" size="32" variant="ilp32" />
|
||||||
|
|||||||
@@ -42,6 +42,12 @@
|
|||||||
<constraint primary="3" processor="x86" endian="little" size="32" />
|
<constraint primary="3" processor="x86" endian="little" size="32" />
|
||||||
<constraint primary="62" processor="x86" endian="little" size="64" variant="default" />
|
<constraint primary="62" processor="x86" endian="little" size="64" variant="default" />
|
||||||
</constraint>
|
</constraint>
|
||||||
|
<constraint compilerSpecID="swift">
|
||||||
|
<constraint primary="62" secondary="swift" processor="x86" endian="little" size="64" variant="default" />
|
||||||
|
</constraint>
|
||||||
|
<constraint compilerSpecID="golang">
|
||||||
|
<constraint primary="62" secondary="golang" processor="x86" endian="little" size="64" variant="default" />
|
||||||
|
</constraint>
|
||||||
</constraint>
|
</constraint>
|
||||||
<constraint loader="Module Definition (DEF)" compilerSpecID="windows">
|
<constraint loader="Module Definition (DEF)" compilerSpecID="windows">
|
||||||
<constraint primary="0" processor="x86" endian="little" size="32" />
|
<constraint primary="0" processor="x86" endian="little" size="32" />
|
||||||
|
|||||||
Reference in New Issue
Block a user