Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2714 fixing bad arm reference to memory on odd external reference offsets

emteere1410ccb6f8ab
diff --git a/Ghidra/Processors/ARM/src/main/java/ghidra/app/plugin/core/analysis/ArmAnalyzer.java b/Ghidra/Processors/ARM/src/main/java/ghidra/app/plugin/core/analysis/ArmAnalyzer.java
index fa15e29965..6585e836cc 100644
--- a/Ghidra/Processors/ARM/src/main/java/ghidra/app/plugin/core/analysis/ArmAnalyzer.java
+++ b/Ghidra/Processors/ARM/src/main/java/ghidra/app/plugin/core/analysis/ArmAnalyzer.java
@@ -186,10 +186,11 @@ public class ArmAnalyzer extends ConstantPropagationAnalyzer {
return false;
}
}
- else if (refType.isCall() && refType.isComputed()) {
+ else if (refType.isCall() && refType.isComputed() && !address.isExternalAddress()) {
// must disassemble right now, because TB flag could get set back at end of blx
doArmThumbDisassembly(program, instr, context, address, instr.getFlowType(),
true, monitor);
+ return false;
}
return super.evaluateReference(context, instr, pcodeop, address, size, refType);
@@ -826,8 +827,7 @@ public class ArmAnalyzer extends ConstantPropagationAnalyzer {
// this is here so the reference gets created, but not - disassembled if it is in a bad part of memory.
// something computed it into the memory
MemoryBlock block = program.getMemory().getBlock(target);
- if (block == null || !block.isExecute() || !block.isInitialized() ||
- block.getName().equals(MemoryBlock.EXTERNAL_BLOCK_NAME)) {
+ if (block == null || !block.isExecute() || !block.isInitialized() || block.isExternalBlock()) {
return;
}
diff --git a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/plugin/core/analysis/MipsAddressAnalyzer.java b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/plugin/core/analysis/MipsAddressAnalyzer.java
index 54240fe063..4ee2b5f281 100644
--- a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/plugin/core/analysis/MipsAddressAnalyzer.java
+++ b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/plugin/core/analysis/MipsAddressAnalyzer.java
@@ -273,7 +273,7 @@ public class MipsAddressAnalyzer extends ConstantPropagationAnalyzer {
if (target == (addr.getOffset() + 1) && !instr.getFlowType().isCall()) {
instr.setFlowOverride(FlowOverride.CALL);
// need to trigger disassembly below! if not already
- MipsExtDisassembly(program, instr, context, addr.add(1), monitor);
+ mipsExtDisassembly(program, instr, context, addr.add(1), monitor);
// need to trigger re-function creation!
Function f = program.getFunctionManager().getFunctionContaining(
@@ -387,7 +387,7 @@ public class MipsAddressAnalyzer extends ConstantPropagationAnalyzer {
if ((refType.isJump() || refType.isCall()) & refType.isComputed()) {
//if (refType.isJump() || refType.isCall()) {
- addr = MipsExtDisassembly(program, instr, context, address, monitor);
+ addr = mipsExtDisassembly(program, instr, context, address, monitor);
//addr = flowISA(program, instr, context, address);
if (addr == null) {
addr = address;
@@ -396,7 +396,7 @@ public class MipsAddressAnalyzer extends ConstantPropagationAnalyzer {
// if this is a call, some processors use the register value
// used in the call for PIC calculations
- if (refType.isCall()) {
+ if (refType.isCall() && !addr.isExternalAddress()) {
// set the called function to have a constant value for this register
// WARNING: This might not always be the case, if called directly or with a different register
// But then it won't matter, because the function won't depend on the registers value.
@@ -501,17 +501,16 @@ public class MipsAddressAnalyzer extends ConstantPropagationAnalyzer {
return resultSet;
}
- Address MipsExtDisassembly(Program program, Instruction instruction, VarnodeContext context,
+ Address mipsExtDisassembly(Program program, Instruction instruction, VarnodeContext context,
Address target, TaskMonitor monitor) {
- if (target == null) {
+ if (target == null || target.isExternalAddress()) {
return null;
}
Address addr = flowISA(program, instruction, context, target);
if (addr != null) {
MemoryBlock block = program.getMemory().getBlock(addr);
- if (block == null || !block.isExecute() || !block.isInitialized() ||
- block.getName().equals(MemoryBlock.EXTERNAL_BLOCK_NAME)) {
+ if (block == null || !block.isExecute() || !block.isInitialized() || block.isExternalBlock()) {
return addr;
}
diff --git a/Ghidra/Processors/PIC/src/main/java/ghidra/app/plugin/core/analysis/Pic16Analyzer.java b/Ghidra/Processors/PIC/src/main/java/ghidra/app/plugin/core/analysis/Pic16Analyzer.java
index d2fcd80e8e..2a097f2b92 100644
--- a/Ghidra/Processors/PIC/src/main/java/ghidra/app/plugin/core/analysis/Pic16Analyzer.java
+++ b/Ghidra/Processors/PIC/src/main/java/ghidra/app/plugin/core/analysis/Pic16Analyzer.java
@@ -86,6 +86,10 @@ public class Pic16Analyzer extends ConstantPropagationAnalyzer {
int size, RefType refType) {
AddressSpace space = address.getAddressSpace();
+ if (address.isExternalAddress()) {
+ return true;
+ }
+
if (space.hasMappedRegisters()) {
return true;
}
diff --git a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4AddressAnalyzer.java b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4AddressAnalyzer.java
index 9c839afb43..7110dc2cff 100644
--- a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4AddressAnalyzer.java
+++ b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4AddressAnalyzer.java
@@ -82,6 +82,10 @@ public class SH4AddressAnalyzer extends ConstantPropagationAnalyzer {
public boolean evaluateReference(VarnodeContext context, Instruction instr, int pcodeop,
Address address, int size, RefType refType) {
+ if (address.isExternalAddress()) {
+ return true;
+ }
+
// if this is a call, some processors use the register value
// used in the call for PIC calculations
if (refType.isCall()) {
diff --git a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4EarlyAddressAnalyzer.java b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4EarlyAddressAnalyzer.java
index 758acf9df2..64703d78e0 100644
--- a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4EarlyAddressAnalyzer.java
+++ b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/plugin/core/analysis/SH4EarlyAddressAnalyzer.java
@@ -54,6 +54,10 @@ public class SH4EarlyAddressAnalyzer extends SH4AddressAnalyzer {
// if this is a call, some processors use the register value
// used in the call for PIC calculations
if (refType.isFlow()) {
+ if (address.isExternalAddress()) {
+ return true;
+ }
+
// set the called function to have a constant value for this register
// WARNING: This might not always be the case, if called directly or with a different register
// But then it won't matter, because the function won't depend on the registers value.