From fc59d1cfb976c444a49574948f44e961552be8fd Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 12 Nov 2022 14:04:14 +0100 Subject: [PATCH] Add Ghidra 10.2.1 support --- README.md | 2 +- build.gradle | 16 +++++++++++++++- extension.properties | 2 +- src/main/java/cafeloader/RplConverter.java | 19 +++++++++---------- src/main/java/cafeloader/RplHeader.java | 9 +++------ .../util/bin/format/elf/RplSectionHeader.java | 7 +++---- .../ghidra/app/util/opinion/CafeLoader.java | 18 ++++++------------ 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 3a27968..743516a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The loader will fallback to the default PowerPC processor if the Gekko/Broadway # Usage -Install the extension using the `Install Extensions` option inside Ghidra or extract the .zip manually into `[GHIDRA_ROOT]\Ghidra\Extensions`. Make sure to restart the program after installing. +Install the extension using the `Install Extensions` option inside Ghidra. Once the extension is installed, you can import a .rpx/.rpl file via `File->Import File...`. diff --git a/build.gradle b/build.gradle index 22f4810..68ed78e 100644 --- a/build.gradle +++ b/build.gradle @@ -48,4 +48,18 @@ else { //----------------------END "DO NOT MODIFY" SECTION------------------------------- jar { duplicatesStrategy 'exclude' -} \ No newline at end of file +} +repositories { + // Declare dependency repositories here. This is not needed if dependencies are manually + // dropped into the lib/ directory. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html for more info. + // Ex: mavenCentral() +} + +dependencies { + // Any external dependencies added here will automatically be copied to the lib/ directory when + // this extension is built. +} + +// Exclude additional files from the built extension +// Ex: buildExtension.exclude '.idea/**' diff --git a/extension.properties b/extension.properties index 3daff3d..9b88810 100644 --- a/extension.properties +++ b/extension.properties @@ -1,5 +1,5 @@ name=@extname@ description=Simple extension to open Wii U binaries (.rpx/.rpl) author= Maschell -createdOn= 11/10/2019 +createdOn= 12/11/2022 version=@extversion@ diff --git a/src/main/java/cafeloader/RplConverter.java b/src/main/java/cafeloader/RplConverter.java index 38f11b8..8ca3c6a 100644 --- a/src/main/java/cafeloader/RplConverter.java +++ b/src/main/java/cafeloader/RplConverter.java @@ -2,13 +2,12 @@ package cafeloader; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.function.Consumer; import java.util.zip.DataFormatException; import java.util.zip.Inflater; -import generic.continues.RethrowContinuesFactory; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.ByteProvider; -import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader; import ghidra.app.util.bin.format.elf.ElfConstants; import ghidra.app.util.bin.format.elf.ElfException; import ghidra.app.util.bin.format.elf.ElfSectionHeader; @@ -28,10 +27,10 @@ public class RplConverter { public static final byte ELFOSABI_CAFE = (byte) 0xCA; public static final byte ELFOSABI_VERSION_CAFE = (byte) 0xFE; - public static byte[] convertRpl(ByteProvider byteProvider, TaskMonitor monitor) + public static byte[] convertRpl(ByteProvider byteProvider, Consumer errorConsumer) throws ElfException, IOException, DataFormatException { // Read elf header - RplHeader elfHeader = RplHeader.createRplHeader(RethrowContinuesFactory.INSTANCE, byteProvider); + RplHeader elfHeader = new RplHeader(byteProvider, errorConsumer); BinaryReader reader = elfHeader.getReader(); // Write elf header @@ -55,18 +54,18 @@ public class RplConverter { out.write(dc.getBytes((short) 0)); // phentsize out.write(dc.getBytes((short) 0)); // phnum out.write(dc.getBytes(elfHeader.e_shentsize())); - out.write(dc.getBytes(elfHeader.e_shnum())); - out.write(dc.getBytes(elfHeader.e_shstrndx())); + out.write(dc.getBytes((short)elfHeader.getSectionHeaderCount())); + out.write(dc.getBytes((short)elfHeader.e_shstrndx())); out.write(new byte[0x40 - 0x34]); // padding until section headers // Read sections - long sectionDataOffset = elfHeader.e_shoff() + (elfHeader.e_shnum() * elfHeader.e_shentsize()); + long sectionDataOffset = elfHeader.e_shoff() + ((long) elfHeader.getSectionHeaderCount() * elfHeader.e_shentsize()); ByteArrayOutputStream sectionData = new ByteArrayOutputStream(); - for (int i = 0; i < elfHeader.e_shnum(); ++i) { - long index = elfHeader.e_shoff() + (i * elfHeader.e_shentsize()); + for (int i = 0; i < elfHeader.getSectionHeaderCount(); ++i) { + long index = elfHeader.e_shoff() + ((long) i * elfHeader.e_shentsize()); reader.setPointerIndex(index); - ElfSectionHeader sectionHeader = RplSectionHeader.createElfSectionHeader((FactoryBundledWithBinaryReader) reader, elfHeader); + ElfSectionHeader sectionHeader = new RplSectionHeader(reader, elfHeader); long size = sectionHeader.getSize(); reader.setPointerIndex(sectionHeader.getOffset()); diff --git a/src/main/java/cafeloader/RplHeader.java b/src/main/java/cafeloader/RplHeader.java index 0c998ed..477ac43 100644 --- a/src/main/java/cafeloader/RplHeader.java +++ b/src/main/java/cafeloader/RplHeader.java @@ -1,19 +1,16 @@ package cafeloader; import java.lang.Throwable; +import java.util.function.Consumer; -import generic.continues.GenericFactory; import ghidra.app.util.bin.ByteProvider; import ghidra.app.util.bin.format.elf.ElfException; import ghidra.app.util.bin.format.elf.ElfHeader; public class RplHeader extends ElfHeader { - public static RplHeader createRplHeader(GenericFactory factory, ByteProvider provider) - throws ElfException { - RplHeader elfHeader = (RplHeader) factory.create(RplHeader.class); - elfHeader.initElfHeader(factory, provider); - return elfHeader; + public RplHeader(ByteProvider provider, Consumer errorConsumer) throws ElfException { + super(provider, errorConsumer); } @Override diff --git a/src/main/java/ghidra/app/util/bin/format/elf/RplSectionHeader.java b/src/main/java/ghidra/app/util/bin/format/elf/RplSectionHeader.java index e3654ee..60c71d9 100644 --- a/src/main/java/ghidra/app/util/bin/format/elf/RplSectionHeader.java +++ b/src/main/java/ghidra/app/util/bin/format/elf/RplSectionHeader.java @@ -2,11 +2,10 @@ package ghidra.app.util.bin.format.elf; import java.io.IOException; -import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader; +import ghidra.app.util.bin.BinaryReader; public class RplSectionHeader extends ElfSectionHeader { - public static ElfSectionHeader createElfSectionHeader(FactoryBundledWithBinaryReader reader, - ElfHeader header) throws IOException { - return ElfSectionHeader.createElfSectionHeader(reader, header); + public RplSectionHeader(BinaryReader reader, ElfHeader header) throws IOException { + super(reader, header); } } diff --git a/src/main/java/ghidra/app/util/opinion/CafeLoader.java b/src/main/java/ghidra/app/util/opinion/CafeLoader.java index 0f032ad..5ee4aea 100644 --- a/src/main/java/ghidra/app/util/opinion/CafeLoader.java +++ b/src/main/java/ghidra/app/util/opinion/CafeLoader.java @@ -9,13 +9,12 @@ import java.util.Collection; import java.util.List; import java.util.zip.DataFormatException; -import generic.continues.GenericFactory; import ghidra.app.util.Option; import ghidra.app.util.bin.ByteArrayProvider; import ghidra.app.util.bin.ByteProvider; import ghidra.app.util.bin.format.elf.ElfException; +import ghidra.app.util.bin.format.elf.ElfHeader; import ghidra.app.util.importer.MessageLog; -import ghidra.app.util.importer.MessageLogContinuesFactory; import ghidra.program.model.lang.LanguageCompilerSpecPair; import ghidra.program.model.listing.Program; import ghidra.util.exception.CancelledException; @@ -70,18 +69,13 @@ public class CafeLoader extends ElfLoader { @Override public void load(ByteProvider provider, LoadSpec loadSpec, List