From 3eda80f7c561dea3f8814934ca8ceb039a8ae080 Mon Sep 17 00:00:00 2001 From: James Benton Date: Wed, 2 Oct 2019 21:30:57 +0100 Subject: [PATCH] Prefer Gekko processor but fallback to normal PowerPC if not present. --- data/languages/RPX.opinion | 7 +++--- .../ghidra/app/util/opinion/CafeLoader.java | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/data/languages/RPX.opinion b/data/languages/RPX.opinion index e7bdf04..5ec29b7 100644 --- a/data/languages/RPX.opinion +++ b/data/languages/RPX.opinion @@ -1,5 +1,6 @@ - - - + + + + diff --git a/src/main/java/ghidra/app/util/opinion/CafeLoader.java b/src/main/java/ghidra/app/util/opinion/CafeLoader.java index 66a95f6..0f032ad 100644 --- a/src/main/java/ghidra/app/util/opinion/CafeLoader.java +++ b/src/main/java/ghidra/app/util/opinion/CafeLoader.java @@ -28,8 +28,26 @@ public class CafeLoader extends ElfLoader { List loadSpecs = new ArrayList<>(); if (Arrays.equals(provider.readBytes(0, header.length), header)) { - loadSpecs.add(new LoadSpec(this, 0, new LanguageCompilerSpecPair("PowerPC:BE:32:Gekko_Broadway", "default"), true)); - return loadSpecs; + List results = QueryOpinionService.query(getName(), "wiiu", null); + boolean hasGekkoProcessor = false; + + for (QueryResult result : results) { + if (result.pair.languageID.getIdAsString().contains("Gekko")) { + hasGekkoProcessor = true; + } + } + + for (QueryResult result : results) { + if (result.pair.languageID.getIdAsString().contains("Gekko")) { + loadSpecs.add(new LoadSpec(this, 0, new QueryResult(result.pair, true))); + } else { + loadSpecs.add(new LoadSpec(this, 0, new QueryResult(result.pair, hasGekkoProcessor ? false : result.preferred))); + } + } + + if (loadSpecs.isEmpty()) { + loadSpecs.add(new LoadSpec(this, 0, new LanguageCompilerSpecPair("PowerPC:BE:32:default", "default"), true)); + } } return loadSpecs;