Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5983 - Decompiler - Fixed bug that prevented overlapping functions from being correctly decompiled

dragonmacher5d9904964e4e
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
index 486cb54ac9..75102adc56 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
@@ -30,6 +30,7 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.pcode.HighFunction;
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.ProgramSelection;
+import ghidra.util.UndefinedFunction;
import ghidra.util.bean.field.AnnotatedTextFieldElement;
import utility.function.Callback;
@@ -107,7 +108,8 @@ public class DecompilerController {
* @param viewerPosition the viewer position
*/
public void display(Program program, ProgramLocation location, ViewerPosition viewerPosition) {
- if (!decompilerMgr.isBusy() && decompilerPanel.containsLocation(location)) {
+
+ if (isAlreadyDecompiled(location)) {
decompilerPanel.setLocation(location, viewerPosition);
return;
}
@@ -119,6 +121,35 @@ public class DecompilerController {
decompilerMgr.decompile(program, location, viewerPosition, null, false);
}
+ private boolean isAlreadyDecompiled(ProgramLocation location) {
+ if (decompilerMgr.isBusy()) {
+ return false;
+ }
+
+ if (!decompilerPanel.containsLocation(location)) {
+ return false;
+ }
+
+ Function currentFunction = currentDecompileData.getFunction();
+ if (currentFunction instanceof UndefinedFunction) {
+ //
+ // There is an oddness with some Undefined functions where their body overlaps a normal
+ // function body. If the current function is Undefined, check to see if the location is
+ // also in a defined function. If so, the return false so the new location will get
+ // decompiled.
+ //
+ Program program = location.getProgram();
+ FunctionManager manager = program.getFunctionManager();
+ Address address = location.getAddress();
+ Function function = manager.getFunctionContaining(address);
+ if (!currentFunction.equals(function)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
private boolean loadFromCache(Program program, ProgramLocation location,
ViewerPosition viewerPosition) {
FunctionManager functionManager = program.getFunctionManager();
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java
index 2006ba9c46..4ffc346ec5 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -210,7 +210,7 @@ public class DecompilePlugin extends Plugin {
}
}
- public void selectionChanged(DecompilerProvider provider, ProgramSelection selection) {
+ void selectionChanged(DecompilerProvider provider, ProgramSelection selection) {
if (provider == connectedProvider) {
firePluginEvent(new ProgramSelectionPluginEvent(name, selection, currentProgram));
}
@@ -260,9 +260,9 @@ public class DecompilePlugin extends Plugin {
}
}
currentLocation = location;
- // delay location change to allow immediate location changes to
- // settle down. This happens when switching program tabs in
- // code browser which produces multiple location changes
+ // Delay location change to allow immediate location changes to settle down. This
+ // happens when switching program tabs in code browser which produces multiple location
+ // changes
delayedLocationUpdateMgr.updateLater();
}
else if (event instanceof ProgramSelectionPluginEvent) {