Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1497 added external safeguards for inadvertent context

ghidra102e197083778
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
index 91e6ef85af..25b78ea2ff 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
@@ -29,6 +29,7 @@ import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.PrototypeModel;
import ghidra.program.model.listing.*;
+import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.symbol.*;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.Msg;
@@ -346,6 +347,9 @@ public class DemangledFunction extends DemangledObject {
* This method assumes preconditions test has been run.
*/
private boolean shouldDisassemble(Program program, Address address, DemanglerOptions options) {
+ if (!address.isMemoryAddress() || MemoryBlock.isExternalBlockAddress(address, program)) {
+ return false;
+ }
CodeUnit codeUnit = program.getListing().getCodeUnitAt(address);
return (codeUnit instanceof Data); // preconditions check guarantees data is undefined data.
}
@@ -383,9 +387,7 @@ public class DemangledFunction extends DemangledObject {
// sure that the context is correctly set before that happens. Also, be sure to apply
// the function to the correct address.
- //TODO revisit this in terms of external block addresses. Also shoul this check
- // be moved into the PsuedoDisassembler???
- if (!address.isExternalAddress()) {
+ if (address.isMemoryAddress()) {
address = PseudoDisassembler.setTargeContextForDisassembly(program, address);
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/PseudoDisassembler.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/PseudoDisassembler.java
index d676ffc20f..286cd91857 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/PseudoDisassembler.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/PseudoDisassembler.java
@@ -27,6 +27,7 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.mem.*;
import ghidra.program.model.pcode.PcodeOp;
import ghidra.program.model.symbol.*;
+import ghidra.util.Msg;
/**
* PseudoDisassembler.java
@@ -387,6 +388,7 @@ public class PseudoDisassembler {
* The process function can control what flows are followed and when to stop.
*
* @param entryPoint start address
+ * @param maxInstr maximum number of instructions to evaluate
* @param processor processor to use
* @return the address set of instructions that were followed
*/
@@ -402,6 +404,8 @@ public class PseudoDisassembler {
* The process function can control what flows are followed and when to stop.
*
* @param entryPoint start address
+ * @param procContext initial processor context for disassembly
+ * @param maxInstr maximum number of instructions to evaluate
* @param processor processor to use
* @return the address set of instructions that were followed
*/
@@ -579,6 +583,10 @@ public class PseudoDisassembler {
public boolean checkValidSubroutine(Address entryPoint, PseudoDisassemblerContext procContext,
boolean allowExistingInstructions, boolean mustTerminate) {
+
+ if (!entryPoint.isMemoryAddress()) {
+ return false;
+ }
AddressSet body = new AddressSet();
AddressSet instrStarts = new AddressSet();
AddressSetView execSet = memory.getExecuteSet();
@@ -987,6 +995,11 @@ public class PseudoDisassembler {
* @return the correct address to disassemble at if it needs to be aligned
*/
public static Address setTargeContextForDisassembly(Program program, Address addr) {
+ if (!addr.isMemoryAddress()) {
+ Msg.error(PseudoDisassembler.class,
+ "Invalid attempt to adjust disassembler context at " + addr.toString(true));
+ return addr;
+ }
Register lowBitCodeMode = program.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
if (lowBitCodeMode == null) {
return addr;
@@ -1016,6 +1029,11 @@ public class PseudoDisassembler {
public Address setTargeContextForDisassembly(PseudoDisassemblerContext procContext,
Address addr) {
+ if (!addr.isMemoryAddress()) {
+ Msg.error(this,
+ "Invalid attempt to adjust disassembler context at " + addr.toString(true));
+ return addr;
+ }
Register lowBitCodeMode = program.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
if (lowBitCodeMode == null) {
return addr;