Only get the ElfSectionHeader in the RelocationHandler if it's not a special section header index to avoid a ArrayIndexOutOfBoundsException

This commit is contained in:
Maschell 2019-10-11 14:47:48 +02:00
parent 0005907547
commit fb3ec7fe28

View File

@ -44,40 +44,43 @@ public class Cafe_ElfRelocationHandler extends ElfRelocationHandler {
* reference because it will be too far away for the actual relocation to * reference because it will be too far away for the actual relocation to
* be valid itself. * be valid itself.
*/ */
ElfSectionHeader symbolSection = elf.getSections()[sym.getSectionHeaderIndex()];
if (symbolSection.getType() == Cafe_ElfExtension.SHT_RPL_IMPORTS.value) {
String symbolSectionName = symbolSection.getNameAsString();
boolean isDataImport = false;
if (symbolSectionName.startsWith(".dimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.DATA, SourceType.IMPORTED, 0);
isDataImport = true;
} else if (symbolSectionName.startsWith(".fimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.UNCONDITIONAL_CALL, SourceType.IMPORTED, 0);
}
String rplName = symbolSectionName.split("import_")[1]; if (sym.getSectionHeaderIndex() > 0) {
if (!rplName.endsWith(".rpl")) { ElfSectionHeader symbolSection = elf.getSections()[sym.getSectionHeaderIndex()];
rplName += ".rpl"; if (symbolSection.getType() == Cafe_ElfExtension.SHT_RPL_IMPORTS.value) {
} String symbolSectionName = symbolSection.getNameAsString();
boolean isDataImport = false;
if (symbolSectionName.startsWith(".dimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.DATA, SourceType.IMPORTED, 0);
isDataImport = true;
} else if (symbolSectionName.startsWith(".fimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.UNCONDITIONAL_CALL, SourceType.IMPORTED, 0);
}
ExternalLocation location = program.getExternalManager().getUniqueExternalLocation(rplName, sym.getNameAsString()); String rplName = symbolSectionName.split("import_")[1];
if (location != null) { if (!rplName.endsWith(".rpl")) {
try { rplName += ".rpl";
if (isDataImport) { }
program.getReferenceManager().addExternalReference(relocationAddress, 1,
location, SourceType.IMPORTED, RefType.DATA); ExternalLocation location = program.getExternalManager().getUniqueExternalLocation(rplName, sym.getNameAsString());
} else { if (location != null) {
program.getReferenceManager().addExternalReference(relocationAddress, 1, try {
location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL); if (isDataImport) {
} program.getReferenceManager().addExternalReference(relocationAddress, 1,
} catch (InvalidInputException e) { location, SourceType.IMPORTED, RefType.DATA);
Msg.warn(this, "addExternalReference failed with " + e); } else {
} program.getReferenceManager().addExternalReference(relocationAddress, 1,
} else { location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL);
Msg.warn(this, "Failed to find location for " + sym.getNameAsString()); }
} } catch (InvalidInputException e) {
Msg.warn(this, "addExternalReference failed with " + e);
}
} else {
Msg.warn(this, "Failed to find location for " + sym.getNameAsString());
}
}
} }
switch (type) { switch (type) {