Skip to content

Commit

Permalink
Imports are now only listed in the import but not export section!
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Mar 10, 2019
1 parent 81a082e commit 92a68e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/main/java/de/mas/ghidra/wiiu/RPXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;

Expand Down Expand Up @@ -76,8 +77,6 @@ public static byte[] convertRPX(ByteProvider bProvider, TaskMonitor monitor)

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;
Expand All @@ -97,10 +96,14 @@ public static byte[] convertRPX(ByteProvider bProvider, TaskMonitor monitor)
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();
}
Expand Down Expand Up @@ -132,6 +135,7 @@ public static byte[] convertRPX(ByteProvider bProvider, TaskMonitor monitor)
buffer.putInt((int) curSize);
buffer.putInt(h.getLink());
buffer.putInt(h.getInfo());

buffer.putInt((int) h.getAddressAlignment());
buffer.putInt((int) h.getEntrySize());

Expand Down Expand Up @@ -161,4 +165,5 @@ public static byte[] convertRPX(ByteProvider bProvider, TaskMonitor monitor)

return buffer.array();
}
}

}
5 changes: 3 additions & 2 deletions src/main/java/ghidra/app/util/opinion/RPXLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,

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);
Expand Down Expand Up @@ -102,8 +104,7 @@ public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,

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());
}
Expand Down

0 comments on commit 92a68e2

Please sign in to comment.