mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
* feat(ghidra)!: verify the bridge on Ghidra 12.2 Admit 12.x from minor 2 upward, with 12.2 and JDK 25 as the verified pair. The bridge now calls the four-argument storage API added in 12.2, so 12.1.x cannot compile it and is no longer accepted. BREAKING CHANGE: Ghidra 12.1.x is rejected. Use Ghidra 12.2 or another 12.x build at or above minor 2, and a JDK inside that installation's declared range (25 or newer for the verified 12.2 build). * docs(ghidra): point remaining lanes at Ghidra 12.2 The Windows, 6502, and m68k prerequisites still named 12.1.4 and JDK 21, which the verified-build check now rejects. The bridge compile lane names the 12.2 jars it actually compiles against. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): admit the JDK the verified install declares The Java home framing probe still reported JDK 21 while the verified installation fixture now declares a minimum of 25, so doctor admission failed before the path framing was checked. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): derive admitted install fixtures from the verified release Boundary hosts and assertions still named Ghidra 12.1.4 after admission moved to 12.2, so list_procedures evidence and completed property reads disagreed with the install the provider actually reported. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): record the exact 12.2 Clang switch-recovery defect Ghidra 12.2 stays the verified build. Sessions and decompiler results on that exact version name upstream issue 9996 and the 12.2.1 fix commit. Other version strings, including 12.2.1, do not carry the limitation. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): check switch-defect facts instead of the warning sentence The policy test keeps the structured defect record and checks that the owning formatter delivers its id, commit, release, and scope fields. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): name the Playwright launch boundary the lifecycle catalog checks Main retitled that case with a platform placeholder. The coverage catalog still required the old literal, so the merged full suite reported a missing title. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): point the lifecycle catalog at main's launch title The merged suite uses main's platform-specific Playwright launch test. The coverage catalog now names that title, and this branch keeps main's test body so the merge stays clean. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): cover the platform launch title on this branch The lifecycle catalog names main's platform launch title. This branch now has that quoted test too, so the check passes before and after the merge. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): record the exact 12.2 masked byte-switch defect Ghidra 12.2 leaves an AArch64 and-0xff byte-offset switch unrecovered. Exact 12.2 sessions now cite open upstream issue 10154, and the AArch64 lane expects that jump table to stay unrecovered. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): keep one platform launch environment check The second launch test repeated the selected environment check. The remaining test is the parameterized title, and the launcher forwards SYSTEMROOT on win32 so that assertion holds. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): keep the open switch defect on admitted builds The exact-version check cleared ghidra-10154 on every build except 12.2. That defect stays on admitted releases until one is known to fix it. ghidra-9996 still clears after the exact 12.2 build. Co-authored-by: morluto <morluto@users.noreply.github.com> * style(docs): format the Ghidra testing-lane table The AArch64 jump-table row wrapped past the formatter width and failed static checks. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): give the masked switch its full byte range The unrecovered oracle now uses 256 readable table bytes, and the same object must still recover its compare-bounded switch. Co-authored-by: morluto <morluto@users.noreply.github.com> * docs(website): point Ghidra setup at 12.2 and JDK 25 The public setup pages still told new users to install Ghidra 12.1.4 and JDK 21, which this release rejects. Changed setup sentences are extracted and left untranslated so those editions use the English page. Co-authored-by: morluto <morluto@users.noreply.github.com> * docs(website): keep catalog edits to the changed setup strings The catalog check compares active message ids, not a full rewrite. Restore the previous catalogs and update only the Ghidra 12.2 setup strings, leaving their translations empty. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): apply the closed switch defect from the parsed patch 12.2, 12.2.0, and 12.2.0 with a suffix all precede 12.2.1, so they keep ghidra-9996. The masked-switch table lists all 256 byte entries. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): share the AArch64 switch fixture compiler invocation --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
178 lines
8.5 KiB
Java
178 lines
8.5 KiB
Java
import ghidra.app.script.GhidraScript;
|
|
import ghidra.program.database.SpecExtension;
|
|
import ghidra.program.model.data.AbstractFloatDataType;
|
|
import ghidra.program.model.data.DataType;
|
|
import ghidra.program.model.data.DoubleDataType;
|
|
import ghidra.program.model.data.FloatDataType;
|
|
import ghidra.program.model.data.FunctionDefinition;
|
|
import ghidra.program.model.data.IntegerDataType;
|
|
import ghidra.program.model.data.ParameterDefinition;
|
|
import ghidra.program.model.data.TypeDef;
|
|
import ghidra.program.model.lang.CompilerSpec;
|
|
import ghidra.program.model.lang.PrototypeModel;
|
|
import ghidra.program.model.lang.Register;
|
|
import ghidra.program.model.listing.Function;
|
|
import ghidra.program.model.listing.Parameter;
|
|
import ghidra.program.model.listing.Program;
|
|
import ghidra.program.model.listing.VariableStorage;
|
|
import ghidra.program.model.pcode.XmlEncode;
|
|
import java.io.StringReader;
|
|
import java.io.StringWriter;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.regex.Pattern;
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
import javax.xml.transform.OutputKeys;
|
|
import javax.xml.transform.TransformerFactory;
|
|
import javax.xml.transform.dom.DOMSource;
|
|
import javax.xml.transform.stream.StreamResult;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
import org.xml.sax.InputSource;
|
|
|
|
/**
|
|
* Soft-float o32 passes and returns float/double values exactly where same-size integers go.
|
|
* Ghidra's MIPS32 compiler specifications model only hard-float o32, so every typed float
|
|
* prototype (functions, externals, thunks via their targets, and function-pointer definitions)
|
|
* would otherwise read $f12/$f14/$f0. Derive a program-specific prototype model from the
|
|
* program's own default o32 model with its floating-point entries and rules removed, install it
|
|
* as a specification extension, and assign it to every callable whose formal types use floats.
|
|
*/
|
|
public final class ReaGhidraMipsSoftFloat extends GhidraScript {
|
|
static final String REPORT_KEY = "REA MIPS soft-float storage";
|
|
static final String POLICY = "o32-soft-float-prototype-v1";
|
|
static final String PROTOTYPE = "__rea_soft_float";
|
|
private static final Pattern FPU_REGISTER = Pattern.compile("f\\d+(_\\d+)?");
|
|
|
|
@Override
|
|
public void run() throws Exception {
|
|
String processor = currentProgram.getLanguage().getProcessor().toString();
|
|
if (!processor.equals("MIPS") || currentProgram.getDefaultPointerSize() != 4)
|
|
throw new IllegalStateException(
|
|
"REA soft-float storage requires a 32-bit MIPS program, not " + processor);
|
|
CompilerSpec spec = currentProgram.getCompilerSpec();
|
|
PrototypeModel base = spec.getDefaultCallingConvention();
|
|
new SpecExtension(currentProgram)
|
|
.addReplaceCompilerSpecExtension(softFloatPrototype(base, spec), monitor);
|
|
PrototypeModel soft = currentProgram.getCompilerSpec().getCallingConvention(PROTOTYPE);
|
|
if (soft == null)
|
|
throw new IllegalStateException("REA soft-float prototype was not installed");
|
|
requireIntegerStorage(
|
|
soft.getStorageLocations(
|
|
currentProgram,
|
|
new DataType[] {
|
|
FloatDataType.dataType, IntegerDataType.dataType, DoubleDataType.dataType,
|
|
FloatDataType.dataType, DoubleDataType.dataType
|
|
},
|
|
false,
|
|
false),
|
|
"soft-float prototype self-check");
|
|
int functions = 0;
|
|
List<Function> callables = new ArrayList<>();
|
|
currentProgram.getFunctionManager().getFunctions(true).forEach(callables::add);
|
|
currentProgram.getFunctionManager().getExternalFunctions().forEach(callables::add);
|
|
for (Function function : callables) {
|
|
// A thunk's signature is its target's; the target is in this list.
|
|
if (function.isThunk() || !usesFloat(function)) continue;
|
|
if (function.hasCustomVariableStorage()) function.setCustomVariableStorage(false);
|
|
function.setCallingConvention(PROTOTYPE);
|
|
List<VariableStorage> storage = new ArrayList<>();
|
|
storage.add(function.getReturn().getVariableStorage());
|
|
for (Parameter parameter : function.getParameters()) storage.add(parameter.getVariableStorage());
|
|
requireIntegerStorage(storage.toArray(VariableStorage[]::new), function.getName(true));
|
|
functions += 1;
|
|
}
|
|
int definitions = 0;
|
|
Iterator<DataType> types = currentProgram.getDataTypeManager().getAllDataTypes();
|
|
while (types.hasNext()) {
|
|
if (!(types.next() instanceof FunctionDefinition definition) || !usesFloat(definition))
|
|
continue;
|
|
definition.setCallingConvention(PROTOTYPE);
|
|
definitions += 1;
|
|
}
|
|
// Written last: any failure above leaves no report, and REA refuses the session.
|
|
currentProgram.getOptions(Program.PROGRAM_INFO).setString(
|
|
REPORT_KEY,
|
|
"{\"policy\":\"" + POLICY + "\",\"functions\":" + functions +
|
|
",\"definitions\":" + definitions + "}");
|
|
println("REA MIPS soft-float prototype: functions=" + functions + " definitions=" + definitions);
|
|
}
|
|
|
|
/** The default o32 model without floating-point registers or float-consuming rules. */
|
|
private static String softFloatPrototype(PrototypeModel base, CompilerSpec spec) throws Exception {
|
|
XmlEncode encoder = new XmlEncode();
|
|
base.encode(encoder, spec.getPcodeInjectLibrary());
|
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
Document document =
|
|
factory.newDocumentBuilder().parse(new InputSource(new StringReader(encoder.toString())));
|
|
Element root = document.getDocumentElement();
|
|
if (!root.getTagName().equals("prototype"))
|
|
throw new IllegalStateException("Unexpected default prototype encoding " + root.getTagName());
|
|
root.setAttribute("name", PROTOTYPE);
|
|
List<Node> removed = new ArrayList<>();
|
|
collect(root.getElementsByTagName("pentry"), "metatype", "float", null, removed);
|
|
collect(root.getElementsByTagName("consume"), "storage", "float", "rule", removed);
|
|
if (removed.isEmpty())
|
|
throw new IllegalStateException("Default prototype has no floating-point entries to remove");
|
|
for (Node node : removed) node.getParentNode().removeChild(node);
|
|
StringWriter xml = new StringWriter();
|
|
var transformer = TransformerFactory.newInstance().newTransformer();
|
|
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
|
transformer.transform(new DOMSource(document), new StreamResult(xml));
|
|
return xml.toString();
|
|
}
|
|
|
|
/** Select matching elements, or their nearest `ancestor` element when one is named. */
|
|
private static void collect(
|
|
NodeList nodes, String attribute, String value, String ancestor, List<Node> selected) {
|
|
for (int index = 0; index < nodes.getLength(); index += 1) {
|
|
Element element = (Element) nodes.item(index);
|
|
if (!value.equals(element.getAttribute(attribute))) continue;
|
|
Node target = element;
|
|
while (ancestor != null && target != null && !ancestor.equals(target.getNodeName()))
|
|
target = target.getParentNode();
|
|
if (target != null && !selected.contains(target)) selected.add(target);
|
|
}
|
|
}
|
|
|
|
private static void requireIntegerStorage(VariableStorage[] storage, String owner) {
|
|
for (VariableStorage item : storage) {
|
|
if (item.isBadStorage() || item.isUnassignedStorage())
|
|
throw new IllegalStateException("REA soft-float storage unresolved for " + owner);
|
|
List<Register> registers = item.getRegisters();
|
|
if (registers == null) continue; // stack-only storage
|
|
for (Register register : registers) {
|
|
if (FPU_REGISTER.matcher(register.getName()).matches())
|
|
throw new IllegalStateException(
|
|
"REA soft-float storage still uses " + register.getName() + " for " + owner);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static boolean usesFloat(Function function) {
|
|
if (isFloat(function.getReturn().getFormalDataType())) return true;
|
|
for (Parameter parameter : function.getParameters()) {
|
|
if (isFloat(parameter.getFormalDataType())) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean usesFloat(FunctionDefinition definition) {
|
|
if (isFloat(definition.getReturnType())) return true;
|
|
for (ParameterDefinition argument : definition.getArguments()) {
|
|
if (isFloat(argument.getDataType())) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean isFloat(DataType type) {
|
|
DataType current = type;
|
|
while (current instanceof TypeDef typeDef) current = typeDef.getBaseDataType();
|
|
return current instanceof AbstractFloatDataType;
|
|
}
|
|
}
|