Ghidra is a software reverse engineering (SRE) framework
GP-6346 updated missing javadoc. Replaced old toAddr with superior user-submitted version.
ghidra0074fd51c8b480e
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/DecompilerScriptUtils.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/DecompilerScriptUtils.javaindex 90db9073c3..85692cb6fe 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/DecompilerScriptUtils.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/DecompilerScriptUtils.java@@ -19,9 +19,7 @@ package classrecovery;import ghidra.app.decompiler.*;import ghidra.app.decompiler.component.DecompilerUtils;import ghidra.framework.plugintool.ServiceProvider;-import ghidra.program.model.address.Address;-import ghidra.program.model.address.AddressSpace;-import ghidra.program.model.address.AddressOutOfBoundsException;+import ghidra.program.model.address.*;import ghidra.program.model.data.DataType;import ghidra.program.model.data.ParameterDefinition;import ghidra.program.model.listing.Function;@@ -231,11 +229,13 @@ public class DecompilerScriptUtils {/*** Best-effort extraction of an address candidate from decompiler p-code.* Returns {@code null} if the candidate is invalid or not mapped in program memory.+ * @param storedValue the Varnode containing possible address+ * @return the Address assigned to the Varnode, or null if invalid or not in program memory*/public Address getAssignedAddressFromPcode(Varnode storedValue) {if (storedValue.isConstant()) {- return tryToAddr(storedValue.getOffset());+ return toAddr(storedValue.getOffset());}PcodeOp op = storedValue.getDef();@@ -253,7 +253,7 @@ public class DecompilerScriptUtils {}// PTRSUB input(1) is always a constant offset (but may not represent a valid program address)- return tryToAddr(op.getInput(1).getOffset());+ return toAddr(op.getInput(1).getOffset());}/**@@ -285,15 +285,6 @@ public class DecompilerScriptUtils {return calledAddress;}- /**- * Returns a new address with the specified offset in the default address space.- * @param offset the offset for the new address- * @return a new address with the specified offset in the default address space- */- public final Address toAddr(long offset) {- return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);- }-/*** Attempts to convert the given offset to an {@link Address} in the default address space.* <p>@@ -301,14 +292,12 @@ public class DecompilerScriptUtils {* as addresses; this method performs a best-effort conversion and safely ignores* invalid or unmapped candidates.* <p>- * Unlike {@link #toAddr(long)}, this method returns {@code null} if the resulting address is not- * contained in the program's memory or if the offset is out of bounds.** @param offset the offset to convert* @return the address for the given offset, or {@code null} if the offset cannot be represented* as a valid address in the program's memory*/- public final Address tryToAddr(long offset) {+ public final Address toAddr(long offset) {AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();try {Address addr = space.getAddress(offset);