From 92a68e21fc63e9e0d6e130f1d4b09a9e317206fe Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 10 Mar 2019 03:35:01 +0100 Subject: [PATCH] Imports are now only listed in the import but not export section! --- src/main/java/de/mas/ghidra/wiiu/RPXUtils.java | 13 +++++++++---- .../java/ghidra/app/util/opinion/RPXLoader.java | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/mas/ghidra/wiiu/RPXUtils.java b/src/main/java/de/mas/ghidra/wiiu/RPXUtils.java index f73e532..9726d7c 100644 --- a/src/main/java/de/mas/ghidra/wiiu/RPXUtils.java +++ b/src/main/java/de/mas/ghidra/wiiu/RPXUtils.java @@ -14,6 +14,7 @@ import ghidra.app.util.bin.format.elf.ElfException; import ghidra.app.util.bin.format.elf.ElfHeader; import ghidra.app.util.bin.format.elf.ElfSectionHeader; import ghidra.app.util.bin.format.elf.ElfSectionHeaderConstants; +import ghidra.app.util.bin.format.elf.ElfSymbol; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; @@ -76,8 +77,6 @@ public class RPXUtils { buffer = Utils.checkAndGrowByteBuffer(buffer, newEnd); buffer.position((int) shdr_data_elf_offset); - // System.out.println("Write data " + String.format("%08X", - // shdr_data_elf_offset)); buffer.put(data); offset = shdr_data_elf_offset; shdr_data_elf_offset += curSize; @@ -97,10 +96,14 @@ public class RPXUtils { int type = elfFile.getSections()[sectionIndex].getType(); if (type == SHT_RPL_IMPORTS) { - // Set Value to 0 buffer.position((int) (entry_offset + 4)); + // Set Value to a custom symbol address curSymbolAddress += 4; buffer.putInt((int) curSymbolAddress); + buffer.position((int) (entry_offset + 12)); + // Change type to LOCAL so it won't be in the export list. + // Force FUNC type so the name will be used in the decompiler. + buffer.put((byte) ((ElfSymbol.STB_LOCAL << 4) | ElfSymbol.STT_FUNC)); // 12 } entryPos += h.getEntrySize(); } @@ -132,6 +135,7 @@ public class RPXUtils { buffer.putInt((int) curSize); buffer.putInt(h.getLink()); buffer.putInt(h.getInfo()); + buffer.putInt((int) h.getAddressAlignment()); buffer.putInt((int) h.getEntrySize()); @@ -161,4 +165,5 @@ public class RPXUtils { return buffer.array(); } -} + +} \ No newline at end of file diff --git a/src/main/java/ghidra/app/util/opinion/RPXLoader.java b/src/main/java/ghidra/app/util/opinion/RPXLoader.java index c1d625a..7e57a65 100644 --- a/src/main/java/ghidra/app/util/opinion/RPXLoader.java +++ b/src/main/java/ghidra/app/util/opinion/RPXLoader.java @@ -74,7 +74,9 @@ public class RPXLoader extends ElfLoader { try { GenericFactory factory = MessageLogContinuesFactory.create(log); + byte[] data = RPXUtils.convertRPX(provider, monitor); + ElfHeader elf = ElfHeader.createElfHeader(factory, new ByteArrayProvider(data)); ElfProgramBuilder.loadElf(elf, program, options, log, handler, monitor); @@ -102,8 +104,7 @@ public class RPXLoader extends ElfLoader { Address addr = aspace.getAddress(offset); Reference r = program.getReferenceManager().addExternalReference(addr, rplName, - symbol.getNameAsString(), aspace.getAddress(0), SourceType.USER_DEFINED, 1, - RefType.DATA); + symbol.getNameAsString(), aspace.getAddress(0), SourceType.IMPORTED, 1, RefType.DATA); program.getReferenceManager().setPrimary(r, true); program.getListing().setComment(addr, 0, rplName + "::" + symbol.getNameAsString()); }