Skip to content

Commit

Permalink
Add Ghidra 10.2.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Nov 12, 2022
1 parent 39fd646 commit fc59d1c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...`.

Expand Down
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ else {
//----------------------END "DO NOT MODIFY" SECTION-------------------------------
jar {
duplicatesStrategy 'exclude'
}
}
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/**'
2 changes: 1 addition & 1 deletion extension.properties
Original file line number Diff line number Diff line change
@@ -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@
19 changes: 9 additions & 10 deletions src/main/java/cafeloader/RplConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

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;
Expand All @@ -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<String> 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
Expand All @@ -55,18 +54,18 @@ public static byte[] convertRpl(ByteProvider byteProvider, TaskMonitor monitor)
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());

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/cafeloader/RplHeader.java
Original file line number Diff line number Diff line change
@@ -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<String> errorConsumer) throws ElfException {
super(provider, errorConsumer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

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);
}
}
18 changes: 6 additions & 12 deletions src/main/java/ghidra/app/util/opinion/CafeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
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;
Expand Down Expand Up @@ -70,18 +69,13 @@ public int getTierPriority() {

@Override
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program,
TaskMonitor monitor, MessageLog log) throws IOException {
TaskMonitor monitor, MessageLog log) throws IOException, CancelledException {
try {
GenericFactory factory = MessageLogContinuesFactory.create(log);
byte[] data = RplConverter.convertRpl(provider, monitor);
RplHeader rpl = RplHeader.createRplHeader(factory, new ByteArrayProvider(data));
byte[] data = RplConverter.convertRpl(provider, log::appendMsg);
RplHeader rpl = new RplHeader(new ByteArrayProvider(data), log::appendMsg);
ElfProgramBuilder.loadElf(rpl, program, options, log, monitor);
} catch (ElfException e) {
throw new IOException(e.getMessage());
} catch (CancelledException e) {
throw new IOException(e.getMessage());
} catch (DataFormatException e) {
throw new IOException(e.getMessage());
} catch (ElfException | DataFormatException var8) {
throw new IOException(var8.getMessage());
}
}
}

0 comments on commit fc59d1c

Please sign in to comment.