Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1679 - Consolidated navigation buttons and added an action to invert the search

dragonmacherae37ca2e27fd
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest
index ec24544237..64f1acebf6 100644
--- a/Ghidra/Features/Base/certification.manifest
+++ b/Ghidra/Features/Base/certification.manifest
@@ -940,6 +940,7 @@ src/main/resources/images/Program.gif||GHIDRA||||END|
src/main/resources/images/ThunkFunction.gif||GHIDRA||||END|
src/main/resources/images/U.gif||GHIDRA||||END|
src/main/resources/images/Unpackage.gif||GHIDRA||||END|
+src/main/resources/images/V.png||GHIDRA||||END|
src/main/resources/images/VCRFastForward.gif||GHIDRA||||END|
src/main/resources/images/V_slash.png||GHIDRA||||END|
src/main/resources/images/View.gif||GHIDRA||||END|
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm b/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
index 474889177a..ddc68222d9 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
@@ -415,6 +415,15 @@
<P>Alternatively, holding the <b>SHIFT</b> key when clicking a navigation button will
temporarily invert the direction of the search.</P>
</BLOCKQUOTE>
+
+ <H3><A name="Invert_Search_Logic"></A>Invert Search Logic</H3>
+
+ <BLOCKQUOTE>
+ <P>The <IMG src="images/dialog-cancel.png" alt="down_arrow" border="0"> icon indicates the
+ search logic will be inverted / negated. The exact meaning of this depends upon the type
+ of search performed, as described below.
+ </BLOCKQUOTE>
+
<H3><A name="Next_Instruction"></A>Navigate to Instruction</H3>
@@ -422,6 +431,12 @@
<P>To move the cursor to the next instruction click on the Navigate by Instruction icon,
<IMG src="images/I.gif" alt="I" border="0">. This icon is disabled when no more
instructions exist in the current search direction.</P>
+
+ <P>When inverted, this task, if on an instruction, will attempt to navigate to
+ the next data or undefined data. If not on an instruction, then this task
+ will find the next instruction and then find the data or undefined data after that.
+ </P>
+
</BLOCKQUOTE>
<H3><A name="Next_Data"></A>Navigate to Data</H3>
@@ -430,6 +445,12 @@
<P>To move the cursor to the next data code unit, click on the Navigate by Data icon, <IMG
src="images/D.gif" alt="D" border="0">. This icon is disabled when no more data code units
exist in the current search direction.</P>
+
+ <P>When inverted, this task, if on a data code unit, will attempt to navigate to
+ the next instruction or undefined data. If not on a data, then this task
+ will find the next defined data and then find the instruction or undefined data after that.
+ </P>
+
</BLOCKQUOTE>
<H3><A name="Next_Undefined"></A>Navigate to Undefined</H3>
@@ -438,14 +459,25 @@
<P>To move the cursor to the next undefined code unit, click on the Navigate by Data icon,
<IMG src="images/U.gif" alt="U" border="0">. This icon is disabled when no more undefined
code units exist in the current search direction.</P>
+
+ <P>When inverted, this task, if on an undefined code unit, will attempt to navigate to
+ the next instruction or data. If not on an undefined, then this task
+ will find the next undefined and then find the instruction or data after that.
+ </P>
+
</BLOCKQUOTE>
<H3><A name="Next_Label"></A>Navigate to Label</H3>
<BLOCKQUOTE>
<P>To move the cursor to the next Label, click on the Navigate by Label icon,
- <IMG src="images/L.gif" alt="L" border="0">. This icon is disabled when no more labels
- exist in the current search direction.</P>
+ <IMG src="images/L.gif" alt="L" border="0">.</P>
+
+ <P>When inverted, this task, if on an address with a label, will attempt to navigate to
+ the next code unit without a label. If not on an address with a label, then this task
+ will find the next label and then find the next code unit after that without a label.
+ </P>
+
</BLOCKQUOTE>
<H3><A name="Next_Function"></A>Navigate to Function</H3>
@@ -455,37 +487,49 @@
next function in the current direction. If inside a function and the direction is towards
lower addresses, then this action will go to the current function's entry point.</P>
- </BLOCKQUOTE>
-
- <H3><A name="Next_Non_Function"></A>Navigate to Non-Function</H3>
-
+ <P>When inverted, this task (<IMG src="images/notF.gif" alt="F">) will attempt to
+ the navigate to the next instruction block not contained in a function.
+ This can be useful when manually creating functions and
+ stepping over them to identify potential function candidates.</P>
+ </P>
- <P style="margin-left: 40px;">This task (<IMG src="images/notF.gif" alt="F">) will attempt to
- the navigate to the next instruction block not contained in a function.&nbsp;
- This can be useful when manually creating functions and
- stepping over them to identify potential function candidates.&nbsp;</P>
+ </BLOCKQUOTE>
- <H3><A name="Next_Different_Byte_Value"></A>Navigate to Different Byte Value</H3>
+ <H3><A name="Next_Matching_Byte_Values"></A>Navigate to Matching Byte Values</H3>
- <P style="margin-left: 40px;">This task (<IMG src="images/V_slash.png" alt="V">) will attempt to
+ <BLOCKQUOTE>
+
+ <P>This task (<IMG src="images/V.png" alt="V">) will attempt to navigate to the next matching
+ byte pattern of the code unit under the cursor.
+ </P>
+
+ <P>When inverted, this task will attempt to
the navigate to the first code-unit where the byte value is different from the byte value
- of the first byte of the current code unit.&nbsp; This can be useful when trying to navigate
- past a series of 0s or FFs;</P>
+ of the first byte of the current code unit. This can be useful when trying to navigate
+ past a series of 0s or FFs</P>
+
+ </BLOCKQUOTE>
<H3><A name="Next_Bookmark"></A>Navigate to Bookmark</H3>
<BLOCKQUOTE>
<P>To move the cursor to the next bookmark, click on the Navigate by Bookmark icon,
- <IMG src="images/B.gif" alt="B" border="0">. This icon is disabled when no more bookmarks
- exist in the current search direction. You may use the pull-down menu to choose a specific
- type of bookmark (<IMG src="images/applications-system.png" alt="B" border="0">,
+ <IMG src="images/B.gif" alt="B" border="0">. You may use the pull-down menu to choose a
+ specific type of bookmark (<IMG src="images/applications-system.png" alt="B" border="0">,
<IMG src="images/edit-delete.png" alt="B" border="0">,
<IMG src="images/information.png" alt="B" border="0">,
<IMG src="images/notes.gif" alt="B" border="0">,
<IMG src="images/warning.png" alt="B" border="0">,
<IMG src="images/unknown.gif" alt="B" border="0">)
to navigate to as opposed to all types. </P>
+
+ <P>When inverted, this task will attempt to navigate to then next address with a bookmark
+ different than what is selected in the pull-down menu of the icon. If the 'all bookmarks'
+ state is selected, then this task will simply navigate to the next address that has no
+ bookmark.
+ </P>
+
</BLOCKQUOTE>
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
index ab491610ec..c5700ad5d6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
@@ -23,6 +23,7 @@ import javax.swing.KeyStroke;
import docking.action.KeyBindingData;
import docking.action.ToolBarData;
import docking.tool.ToolConstants;
+import generic.util.image.ImageUtils;
import ghidra.app.context.NavigatableActionContext;
import ghidra.app.context.NavigatableContextAction;
import ghidra.app.nav.Navigatable;
@@ -36,12 +37,19 @@ import ghidra.util.HelpLocation;
import ghidra.util.Swing;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.*;
+import resources.*;
public abstract class AbstractNextPreviousAction extends NavigatableContextAction {
+ private static final Icon INVERTED_OVERLAY_ICON =
+ ImageUtils.makeTransparent(ResourceManager.loadImage("images/dialog-cancel.png"), .5f);
+
private boolean isForward = true;
private PluginTool tool;
+ protected boolean isInverted;
+ private Icon invertedIcon;
+
public AbstractNextPreviousAction(PluginTool tool, String name, String owner, String subGroup) {
super(name, owner);
this.tool = tool;
@@ -55,6 +63,16 @@ public abstract class AbstractNextPreviousAction extends NavigatableContextActio
setHelpLocation(new HelpLocation(HelpTopics.NAVIGATION, name));
setDescription(getDescriptionString());
addToWindowWhen(NavigatableActionContext.class);
+
+ MultiIconBuilder builder = new MultiIconBuilder(getIcon());
+ builder.addIcon(INVERTED_OVERLAY_ICON, 10, 10, QUADRANT.LR);
+ invertedIcon = builder.build();
+ }
+
+ protected void setInverted(boolean isInverted) {
+ this.isInverted = isInverted;
+ getToolBarData().setIcon(isInverted ? invertedIcon : getIcon());
+ setDescription(getDescriptionString());
}
protected abstract Icon getIcon();
@@ -63,13 +81,13 @@ public abstract class AbstractNextPreviousAction extends NavigatableContextActio
@Override
public void actionPerformed(final NavigatableActionContext context) {
- Task t = new Task("Searching for " + getNavigationTypeName() + "...", true, false, true) {
+ Task t = new Task("Searching for " + doGetNavigationTypeName(), true, false, true) {
@Override
public void run(TaskMonitor monitor) {
gotoNextPrevious(monitor, context);
}
};
- new TaskLauncher(t, tool.getToolFrame(), 500);
+ new TaskLauncher(t);
}
void gotoNextPrevious(TaskMonitor monitor, final NavigatableActionContext context) {
@@ -93,7 +111,7 @@ public abstract class AbstractNextPreviousAction extends NavigatableContextActio
private void gotoAddress(NavigatableActionContext actionContext, Address address) {
if (address == null) {
- tool.setStatusInfo("Unable to locate another \"" + getNavigationTypeName() +
+ tool.setStatusInfo("Unable to locate another \"" + doGetNavigationTypeName() +
"\" past the current range, in the current direction.");
return;
}
@@ -119,14 +137,26 @@ public abstract class AbstractNextPreviousAction extends NavigatableContextActio
private String getDescriptionString() {
String prefix = isForward ? "Go To Next " : "Go To Previous ";
- return prefix + getNavigationTypeName() + " (shift-click inverts direction)";
+ return prefix + doGetNavigationTypeName() + " (shift-click inverts direction)";
+ }
+
+ private String doGetNavigationTypeName() {
+ if (isInverted) {
+ return getInvertedNavigationTypeName();
+ }
+ return getNavigationTypeName();
}
abstract protected String getNavigationTypeName();
+ protected String getInvertedNavigationTypeName() {
+ return "Non-" + getNavigationTypeName();
+ }
+
abstract protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException;
abstract protected Address getPreviousAddress(TaskMonitor monitor, Program program,
Address address) throws CancelledException;
+
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPlugin.java
index d9cdcd55e8..f136f996ac 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPlugin.java
@@ -20,8 +20,10 @@ import java.awt.event.KeyEvent;
import javax.swing.Icon;
+import docking.ActionContext;
import docking.action.*;
import docking.tool.ToolConstants;
+import generic.util.image.ImageUtils;
import ghidra.app.CorePluginPackage;
import ghidra.app.context.NavigatableActionContext;
import ghidra.app.context.NavigatableContextAction;
@@ -58,14 +60,14 @@ import resources.ResourceManager;
//@formatter:on
public class NextPrevCodeUnitPlugin extends Plugin {
private DockingAction toggleDirectionAction;
+ private InvertStateAction invertStateAction;
private AbstractNextPreviousAction instructionAction;
private AbstractNextPreviousAction dataAction;
private AbstractNextPreviousAction undefinedAction;
private AbstractNextPreviousAction functionAction;
- private AbstractNextPreviousAction nonFunctionAction;
private AbstractNextPreviousAction labelAction;
private NextPreviousBookmarkAction bookmarkAction;
- private NextPreviousDifferentByteAction differentValueAction;
+ private NextPreviousSameBytesAction sameValueAction;
public NextPrevCodeUnitPlugin(PluginTool tool) {
super(tool);
@@ -73,60 +75,107 @@ public class NextPrevCodeUnitPlugin extends Plugin {
}
private void createActions() {
- // use this index to make sure that the following actions are ordered in the way that
- // they are inserted
- int subGroupIndex = 0;
+ // use this index to ensure the actions are ordered in the way that they are inserted
+ char subGroupChar = 'a';
- toggleDirectionAction = new ToggleDirectionAction("" + subGroupIndex++);
+ toggleDirectionAction = new ToggleDirectionAction(String.valueOf(subGroupChar++));
tool.addAction(toggleDirectionAction);
+ invertStateAction = new InvertStateAction(String.valueOf(subGroupChar++));
+ tool.addAction(invertStateAction);
+
instructionAction =
- new NextPreviousInstructionAction(tool, getName(), "" + subGroupIndex++);
+ new NextPreviousInstructionAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(instructionAction);
- dataAction = new NextPreviousDefinedDataAction(tool, getName(), "" + subGroupIndex++);
+ dataAction =
+ new NextPreviousDefinedDataAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(dataAction);
- undefinedAction = new NextPreviousUndefinedAction(tool, getName(), "" + subGroupIndex++);
+ undefinedAction =
+ new NextPreviousUndefinedAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(undefinedAction);
- labelAction = new NextPreviousLabelAction(tool, getName(), "" + subGroupIndex++);
+ labelAction = new NextPreviousLabelAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(labelAction);
- functionAction = new NextPreviousFunctionAction(tool, getName(), "" + subGroupIndex++);
+ functionAction =
+ new NextPreviousFunctionAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(functionAction);
- nonFunctionAction =
- new NextPreviousNonFunctionAction(tool, getName(), "" + subGroupIndex++);
- tool.addAction(nonFunctionAction);
-
- differentValueAction =
- new NextPreviousDifferentByteAction(tool, getName(), "" + subGroupIndex++);
- tool.addAction(differentValueAction);
+ sameValueAction =
+ new NextPreviousSameBytesAction(tool, getName(), String.valueOf(subGroupChar++));
+ tool.addAction(sameValueAction);
- bookmarkAction = new NextPreviousBookmarkAction(tool, getName(), "" + subGroupIndex++);
+ bookmarkAction =
+ new NextPreviousBookmarkAction(tool, getName(), String.valueOf(subGroupChar++));
tool.addAction(bookmarkAction);
}
- private void updateActions(boolean searchForward) {
+ private void updateActionsDirection(boolean searchForward) {
instructionAction.setDirection(searchForward);
dataAction.setDirection(searchForward);
undefinedAction.setDirection(searchForward);
functionAction.setDirection(searchForward);
- nonFunctionAction.setDirection(searchForward);
labelAction.setDirection(searchForward);
- differentValueAction.setDirection(searchForward);
+ sameValueAction.setDirection(searchForward);
bookmarkAction.setDirection(searchForward);
}
+ private void updatedActionsLogic(boolean isInverted) {
+ instructionAction.setInverted(isInverted);
+ dataAction.setInverted(isInverted);
+ undefinedAction.setInverted(isInverted);
+ functionAction.setInverted(isInverted);
+ labelAction.setInverted(isInverted);
+ sameValueAction.setInverted(isInverted);
+ bookmarkAction.setInverted(isInverted);
+ }
+
+ private class InvertStateAction extends ToggleDockingAction {
+
+ private final Icon INVERTED_ICON_OFF = ImageUtils.makeTransparent(
+ ResourceManager.loadImage("images/dialog-cancel.png"));
+ private final Icon INVERTED_ICON_ON = ImageUtils.makeTransparent(
+ ResourceManager.loadImage("images/dialog-cancel.png"), .8f);
+ private boolean isInverted = false;
+
+ public InvertStateAction(String subGroup) {
+ super("Invert Search Logic", NextPrevCodeUnitPlugin.this.getName());
+
+ setToolBarData(new ToolBarData(INVERTED_ICON_OFF,
+ ToolConstants.TOOLBAR_GROUP_FOUR, subGroup));
+
+ // TODO add help entry
+ setHelpLocation(new HelpLocation(HelpTopics.NAVIGATION, getName()));
+
+ // TODO setDescriptoin("...");
+ setSelected(false);
+
+ addToWindowWhen(NavigatableActionContext.class);
+ }
+
+ @Override
+ public void setSelected(boolean isSelected) {
+ super.setSelected(isSelected);
+ getToolBarData().setIcon(isSelected ? INVERTED_ICON_ON : INVERTED_ICON_OFF);
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ isInverted = isSelected();
+ updatedActionsLogic(isInverted);
+ }
+ }
+
private class ToggleDirectionAction extends NavigatableContextAction {
- Icon forwardIcon = ResourceManager.loadImage("images/down.png");
- Icon backwardIcon = ResourceManager.loadImage("images/up.png");
+ private final Icon FORWARD_ICON = ResourceManager.loadImage("images/down.png");
+ private final Icon BACKWARD_ICON = ResourceManager.loadImage("images/up.png");
private boolean isForward = true;
ToggleDirectionAction(String subGroup) {
super("Toggle Search Direction", NextPrevCodeUnitPlugin.this.getName());
- setToolBarData(new ToolBarData(forwardIcon,
+ setToolBarData(new ToolBarData(FORWARD_ICON,
ToolConstants.TOOLBAR_GROUP_FOUR, subGroup));
setKeyBindingData(new KeyBindingData(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK |
InputEvent.ALT_DOWN_MASK));
@@ -136,14 +185,13 @@ public class NextPrevCodeUnitPlugin extends Plugin {
new HelpLocation(HelpTopics.NAVIGATION, longName));
setDescription(longName);
addToWindowWhen(NavigatableActionContext.class);
-
}
@Override
public void actionPerformed(NavigatableActionContext context) {
isForward = !isForward;
- getToolBarData().setIcon(isForward ? forwardIcon : backwardIcon);
- updateActions(isForward);
+ getToolBarData().setIcon(isForward ? FORWARD_ICON : BACKWARD_ICON);
+ updateActionsDirection(isForward);
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
index 7c2eb6a04c..c72345c884 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
@@ -18,8 +18,7 @@ package ghidra.app.plugin.core.navigation;
import java.awt.event.*;
import java.util.Iterator;
-import javax.swing.ImageIcon;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import docking.ActionContext;
import docking.action.*;
@@ -27,6 +26,7 @@ import docking.menu.ActionState;
import docking.menu.MultiStateDockingAction;
import docking.tool.ToolConstants;
import docking.widgets.EventTrigger;
+import generic.util.image.ImageUtils;
import ghidra.app.context.ListingActionContext;
import ghidra.app.context.NavigatableActionContext;
import ghidra.app.nav.Navigatable;
@@ -38,29 +38,42 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*;
import ghidra.util.HelpLocation;
import ghidra.util.Swing;
-import resources.ResourceManager;
+import resources.*;
public class NextPreviousBookmarkAction extends MultiStateDockingAction<String> {
- private boolean isForward = true;
+
+ public static final String ALL_BOOKMARK_TYPES = "All Bookmark Types";
+
+ private static final Icon INVERTED_OVERLAY_ICON =
+ ImageUtils.makeTransparent(ResourceManager.loadImage("images/dialog-cancel.png"), .5f);
+
private PluginTool tool;
+ private boolean isForward = true;
+ private boolean isInverted;
- private static ImageIcon bookmarkIcon = ResourceManager.loadImage("images/B.gif");
- private static ImageIcon bookmarkAnalysisIcon =
+ private static final ImageIcon BOOKMARK_ICON = ResourceManager.getScaledIcon(
+ ResourceManager.loadImage("images/B.gif"), 16, 16);
+ private static final ImageIcon BOOKMARK_ANALYSIS_ICON =
ResourceManager.loadImage("images/applications-system.png");
- private static ImageIcon bookmarkErrorIcon =
+ private static final ImageIcon BOOKMARK_ERROR_ICON =
ResourceManager.loadImage("images/edit-delete.png");
- private static ImageIcon bookmarkInfoIcon = ResourceManager.loadImage("images/information.png");
- private static ImageIcon bookmarkNoteIcon = ResourceManager.loadImage("images/notes.gif");
- private static ImageIcon bookmarkWarningIcon = ResourceManager.loadImage("images/warning.png");
- private static ImageIcon bookmarkUnknownIcon = ResourceManager.loadImage("images/unknown.gif");
+ private static final ImageIcon BOOKMARK_INFO_ICON =
+ ResourceManager.loadImage("images/information.png");
+ private static final ImageIcon BOOKMARK_NOTE_ICON =
+ ResourceManager.loadImage("images/notes.gif");
+ private static final ImageIcon BOOKMARK_WARNING_ICON =
+ ResourceManager.loadImage("images/warning.png");
+ private static final ImageIcon BOOKMARK_UNKNOWN_ICON =
+ ResourceManager.loadImage("images/unknown.gif");
public NextPreviousBookmarkAction(PluginTool tool, String owner, String subGroup) {
super("Next Bookmark", owner);
this.tool = tool;
+
setSupportsDefaultToolContext(true);
ToolBarData toolBarData =
- new ToolBarData(bookmarkIcon, ToolConstants.TOOLBAR_GROUP_FOUR);
+ new ToolBarData(BOOKMARK_ICON, ToolConstants.TOOLBAR_GROUP_FOUR);
toolBarData.setToolBarSubGroup(subGroup);
setToolBarData(toolBarData);
@@ -71,16 +84,16 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
setDescription("Set bookmark options");
ActionState<String> allBookmarks =
- new ActionState<>("All Types", bookmarkIcon, BookmarkType.ALL_TYPES);
+ new ActionState<>("All Types", BOOKMARK_ICON, ALL_BOOKMARK_TYPES);
ActionState<String> analysis =
- new ActionState<>("Analysis", bookmarkAnalysisIcon, BookmarkType.ANALYSIS);
+ new ActionState<>("Analysis", BOOKMARK_ANALYSIS_ICON, BookmarkType.ANALYSIS);
ActionState<String> error =
- new ActionState<>("Error", bookmarkErrorIcon, BookmarkType.ERROR);
- ActionState<String> info = new ActionState<>("Info", bookmarkInfoIcon, BookmarkType.INFO);
- ActionState<String> note = new ActionState<>("Note", bookmarkNoteIcon, BookmarkType.NOTE);
+ new ActionState<>("Error", BOOKMARK_ERROR_ICON, BookmarkType.ERROR);
+ ActionState<String> info = new ActionState<>("Info", BOOKMARK_INFO_ICON, BookmarkType.INFO);
+ ActionState<String> note = new ActionState<>("Note", BOOKMARK_NOTE_ICON, BookmarkType.NOTE);
ActionState<String> warning =
- new ActionState<>("Warning", bookmarkWarningIcon, BookmarkType.WARNING);
- ActionState<String> custom = new ActionState<>("Custom", bookmarkUnknownIcon, "Custom");
+ new ActionState<>("Warning", BOOKMARK_WARNING_ICON, BookmarkType.WARNING);
+ ActionState<String> custom = new ActionState<>("Custom", BOOKMARK_UNKNOWN_ICON, "Custom");
addActionState(allBookmarks);
addActionState(analysis);
@@ -110,19 +123,122 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
@Override
public void actionStateChanged(ActionState<String> newActionState, EventTrigger trigger) {
- // nothing
+
+ Icon icon = newActionState.getIcon();
+ ToolBarData tbData = getToolBarData();
+ tbData.setIcon(isInverted ? invertIcon(icon) : icon);
}
- // Find the beginning of the next instruction range
private Address getNextAddress(Program program, Address address, String bookmarkType) {
+
+ if (isInverted) {
+ return getNextAddressOfNonBookmark(program, address, bookmarkType);
+ }
+
+ return getAddressOfNextBookmarkAfter(program, address, bookmarkType);
+ }
+
+ private Address getPreviousAddress(Program program, Address address, String bookmarkType) {
+
+ if (isInverted) {
+ return getPreviousAddressOfNonBookmark(program, address, bookmarkType);
+ }
+
+ return getAddressOfPreviousBookmarkBefore(program, address, bookmarkType);
+ }
+
+ private Address getNextAddressOfNonBookmark(Program program, Address address,
+ String bookmarkType) {
+
+ if (ALL_BOOKMARK_TYPES.equals(bookmarkType)) {
+ // special case: when 'all types' is negated, then we skip runs of non-bookmarks to
+ // allow users to quickly jump to areas with any bookmarks
+ address = getAddressOfNextBookmarkAfter(program, address, bookmarkType);
+ }
+
+ return getAdddressOfNextPreviousNonBookmark(program, address, bookmarkType, true);
+ }
+
+ private Address getPreviousAddressOfNonBookmark(Program program, Address address,
+ String bookmarkType) {
+
+ if (ALL_BOOKMARK_TYPES.equals(bookmarkType)) {
+ // special case: when 'all types' is negated, then we skip runs of non-bookmarks to
+ // allow users to quickly jump to areas with any bookmarks
+ address = getAddressOfPreviousBookmarkBefore(program, address, bookmarkType);
+ }
+
+ return getAdddressOfNextPreviousNonBookmark(program, address, bookmarkType, false);
+ }
+
+ private Address getAdddressOfNextPreviousNonBookmark(Program program, Address address,
+ String bookmarkType, boolean forward) {
+
+ if (address == null) {
+ return null;
+ }
+
+ address = forward ? address.next() : address.previous();
+ if (address == null) {
+ return null;
+ }
+
+ //
+ // By default, if we are given a specific bookmark type, then we need only to find the
+ // next bookmark of a different type. However, if the given type is 'all bookmarks', then
+ // do something reasonable, which is to find the next code unit without a bookmark. Users
+ // are not likely to use this option.
+ //
+ if (bookmarkType.equals(ALL_BOOKMARK_TYPES)) {
+ return getNextPreviousCuWithoutBookmarkAddress(program, address, forward);
+ }
+
+ BookmarkManager bm = program.getBookmarkManager();
+ Iterator<Bookmark> it = bm.getBookmarksIterator(address, forward);
+ while (it.hasNext()) {
+ Bookmark nextBookmark = it.next();
+ Address nextAddress = nextBookmark.getAddress();
+ if (nextAddress.isExternalAddress()) {
+ continue;
+ }
+
+ if (!nextBookmark.getTypeString().equals(bookmarkType)) {
+ return nextBookmark.getAddress();
+ }
+
+ }
+ return null;
+ }
+
+ private Address getNextPreviousCuWithoutBookmarkAddress(Program program, Address address,
+ boolean forward) {
+
+ CodeUnitIterator it = program.getListing().getCodeUnits(address, forward);
+ while (it.hasNext()) {
+ CodeUnit cu = it.next();
+ Address minAddress = cu.getMinAddress();
+ BookmarkManager bm = program.getBookmarkManager();
+ Bookmark[] bookmarks = bm.getBookmarks(minAddress);
+ if (bookmarks.length == 0) {
+ return minAddress;
+ }
+ }
+
+ return null;
+ }
+
+ private Address getAddressOfNextBookmarkAfter(Program program, Address address,
+ String bookmarkType) {
Address start = getNextAddressToBeginSearchingForward(program, address);
- Bookmark nextBookmark = getNextBookmark(program, start, true, bookmarkType);
+ Bookmark nextBookmark = getNextPreviousBookmark(program, start, true, bookmarkType);
return nextBookmark == null ? null : nextBookmark.getAddress();
+
}
- private Address getPreviousAddress(Program program, Address address, String bookmarkType) {
+ private Address getAddressOfPreviousBookmarkBefore(Program program, Address address,
+ String bookmarkType) {
Address start = getNextAddressToBeginSearchingBackward(program, address);
- Bookmark nextBookmark = getNextBookmark(program, start, false, bookmarkType);
+ Bookmark nextBookmark = getNextPreviousBookmark(program, start, false, bookmarkType);
return nextBookmark == null ? null : nextBookmark.getAddress();
}
@@ -150,19 +266,19 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
return cu;
}
- private Bookmark getNextBookmark(Program program, Address address, boolean forward,
+ private Bookmark getNextPreviousBookmark(Program program, Address address, boolean forward,
String bookmarkType) {
- BookmarkManager bookmarkManager = program.getBookmarkManager();
- Iterator<Bookmark> bookmarkIterator =
- bookmarkManager.getBookmarksIterator(address, forward);
- while (bookmarkIterator.hasNext()) {
- Bookmark nextBookmark = bookmarkIterator.next();
+
+ BookmarkManager bm = program.getBookmarkManager();
+ Iterator<Bookmark> it = bm.getBookmarksIterator(address, forward);
+ while (it.hasNext()) {
+ Bookmark nextBookmark = it.next();
Address nextAddress = nextBookmark.getAddress();
if (nextAddress.isExternalAddress()) {
continue;
}
- if (bookmarkType.equals(BookmarkType.ALL_TYPES)) {
+ if (bookmarkType.equals(ALL_BOOKMARK_TYPES)) {
return nextBookmark;
}
else if (bookmarkType.equals("Custom") &&
@@ -172,12 +288,10 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
else if (nextBookmark.getTypeString().equals(bookmarkType)) {
return nextBookmark;
}
- }
- if (!bookmarkIterator.hasNext()) {
- return null;
}
- return bookmarkIterator.next();
+
+ return null;
}
private boolean isNotBuiltInType(Address address, Bookmark nextBookmark, Address nextAddress) {
@@ -231,10 +345,31 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
setDescription(getToolTipText());
}
+ public void setInverted(boolean isInverted) {
+ this.isInverted = isInverted;
+
+ ActionState<String> state = getCurrentState();
+ Icon icon = state.getIcon();
+ getToolBarData().setIcon(isInverted ? invertIcon(icon) : icon);
+ setDescription(getToolTipText());
+ }
+
+ private Icon invertIcon(Icon icon) {
+ MultiIconBuilder builder = new MultiIconBuilder(icon);
+ builder.addIcon(INVERTED_OVERLAY_ICON, 10, 10, QUADRANT.LR);
+ return builder.build();
+ }
+
@Override
public String getToolTipText() {
String description = "Go To " + (isForward ? "Next" : "Previous");
- description += " Bookmark: " + getCurrentState().getName();
+ if (isInverted) {
+ description += " Non-Bookmark: ";
+ }
+ else {
+ description += " Bookmark: ";
+ }
+ description += getCurrentState().getName();
description += " (shift-click inverts direction)";
return description;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDefinedDataAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDefinedDataAction.java
index 09bd4c5b89..9e3a4214c2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDefinedDataAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDefinedDataAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +15,17 @@
*/
package ghidra.app.plugin.core.navigation;
-import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.KeyStroke;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
public class NextPreviousDefinedDataAction extends AbstractNextPreviousAction {
@@ -52,28 +50,49 @@ public class NextPreviousDefinedDataAction extends AbstractNextPreviousAction {
InputEvent.ALT_DOWN_MASK);
}
- /**
- * Find the beginning of the next instruction range
- */
@Override
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+
+ if (isInverted) {
+ return getNextNonDataAddress(monitor, program, address);
+ }
+
if (isDefinedDataAt(program, address)) {
- // on an instruction, we have to find a non-instruction before finding the next instruction
+ // on a data, find a non-data before finding the next data
address = getAddressOfNextPreviousNonDefinedData(monitor, program, address, true);
}
// we know address is not an instruction at this point
-
return getAddressOfNextDataAfter(program, address);
}
+ private Address getNextNonDataAddress(TaskMonitor monitor, Program program, Address address)
+ throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on a data, find the next instruction or undefined
+ // -if not on a data, find the next data, then find the next instruction or undefined after
+ // that (this mimics the non-inverted case)
+ //
+ if (!isDefinedDataAt(program, address)) {
+ address = getAddressOfNextDataAfter(program, address);
+ }
+
+ return getAddressOfNextPreviousNonDefinedData(monitor, program, address, true);
+ }
+
@Override
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getPreviousNonDataAddress(monitor, program, address);
+ }
+
if (isDefinedDataAt(program, address)) {
- // on an instruction, we have to find a non-instruction before finding the previous instruction
+ // on an data, find a non-data before finding the previous data
address = getAddressOfNextPreviousNonDefinedData(monitor, program, address, false);
}
@@ -82,6 +101,22 @@ public class NextPreviousDefinedDataAction extends AbstractNextPreviousAction {
return getAddressOfPreviousDataBefore(program, address);
}
+ private Address getPreviousNonDataAddress(TaskMonitor monitor, Program program,
+ Address address) throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on an data, find the previous instruction or undefined
+ // -if not on a data, find the previous data, then find the previous instruction or
+ // undefined before that (this mimics the non-inverted case)
+ //
+ if (!isDefinedDataAt(program, address)) {
+ address = getAddressOfPreviousDataBefore(program, address);
+ }
+
+ return getAddressOfNextPreviousNonDefinedData(monitor, program, address, false);
+ }
+
private boolean isDefinedDataAt(Program program, Address address) {
if (address == null) {
return false;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousFunctionAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousFunctionAction.java
index 94fc7162e8..05ab11ae15 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousFunctionAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousFunctionAction.java
@@ -25,6 +25,7 @@ import ghidra.app.nav.Navigatable;
import ghidra.app.services.GoToService;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*;
import ghidra.program.util.FunctionSignatureFieldLocation;
import ghidra.util.exception.CancelledException;
@@ -53,15 +54,19 @@ public class NextPreviousFunctionAction extends AbstractNextPreviousAction {
return "Function";
}
- /**
- * Find the beginning of the next instruction range
- * @throws CancelledException
- */
+ @Override
+ protected String getInvertedNavigationTypeName() {
+ return "Instruction Not In a Function";
+ }
+
@Override
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
- Function nextFunction = getNextFunction(program, address, true);
+ if (isInverted) {
+ return getNextNonFunctionAddress(monitor, program, address);
+ }
+ Function nextFunction = getNextFunctionNotAtAddress(program, address, true);
return nextFunction == null ? null : nextFunction.getEntryPoint();
}
@@ -69,15 +74,68 @@ public class NextPreviousFunctionAction extends AbstractNextPreviousAction {
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getPreviousNonFunctionAddress(monitor, program, address);
+ }
+
Function function = program.getListing().getFunctionContaining(address);
if (isInsideFunctionNotAtEntry(function, address)) {
return function.getEntryPoint();
}
- Function nextFunction = getNextFunction(program, address, false);
+ Function nextFunction = getNextFunctionNotAtAddress(program, address, false);
return nextFunction == null ? null : nextFunction.getEntryPoint();
}
+ private Address getNextNonFunctionAddress(TaskMonitor monitor, Program program,
+ Address address) throws CancelledException {
+
+ Function function = program.getListing().getFunctionContaining(address);
+ if (function == null) {
+ function = getNextFunction(program, address, true);
+ }
+ if (function == null) {
+ return null;
+ }
+
+ return findNextInstructionAddressNotInFunction(monitor, program, function, true);
+ }
+
+ private Address findNextInstructionAddressNotInFunction(TaskMonitor monitor, Program program,
+ Function startFunction, boolean isForward) throws CancelledException {
+ Function function = startFunction;
+ AddressSetView body = function.getBody();
+ Address address = startFunction.getEntryPoint();
+ InstructionIterator it = program.getListing().getInstructions(address, isForward);
+ while (it.hasNext()) {
+ monitor.checkCanceled();
+ Instruction instruction = it.next();
+ Address instructionAddress = instruction.getMinAddress();
+ if (!body.contains(instructionAddress)) {
+ function = program.getListing().getFunctionContaining(instructionAddress);
+ if (function == null) {
+ return instructionAddress;
+ }
+ body = function.getBody();
+ }
+ }
+ return null;
+ }
+
+ private Address getPreviousNonFunctionAddress(TaskMonitor monitor, Program program,
+ Address address) throws CancelledException {
+
+ Function function = program.getListing().getFunctionContaining(address);
+ if (function == null) {
+ function = getNextFunction(program, address, false);
+ }
+ if (function == null) {
+ return null;
+ }
+
+ return findNextInstructionAddressNotInFunction(monitor, program, function, false);
+ }
+
private boolean isInsideFunctionNotAtEntry(Function function, Address address) {
if (function == null) {
return false;
@@ -90,6 +148,15 @@ public class NextPreviousFunctionAction extends AbstractNextPreviousAction {
if (!functionIterator.hasNext()) {
return null;
}
+ return functionIterator.next();
+ }
+
+ private Function getNextFunctionNotAtAddress(Program program, Address address,
+ boolean forward) {
+ FunctionIterator functionIterator = program.getListing().getFunctions(address, forward);
+ if (!functionIterator.hasNext()) {
+ return null;
+ }
Function nextFunction = functionIterator.next();
if (!nextFunction.getEntryPoint().equals(address)) {
return nextFunction;
@@ -102,6 +169,11 @@ public class NextPreviousFunctionAction extends AbstractNextPreviousAction {
@Override
protected void gotoAddress(GoToService service, Navigatable navigatable, Address address) {
+ if (isInverted) {
+ service.goTo(navigatable, address);
+ return;
+ }
+
Program program = navigatable.getProgram();
Function function = program.getListing().getFunctionAt(address);
FunctionSignatureFieldLocation location = new FunctionSignatureFieldLocation(program,
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousInstructionAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousInstructionAction.java
index d1b195a5ec..62149fd9a1 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousInstructionAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousInstructionAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +15,17 @@
*/
package ghidra.app.plugin.core.navigation;
-import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.KeyStroke;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
public class NextPreviousInstructionAction extends AbstractNextPreviousAction {
@@ -52,21 +50,20 @@ public class NextPreviousInstructionAction extends AbstractNextPreviousAction {
return "Instruction";
}
- /**
- * Find the beginning of the next instruction range
- * @throws CancelledException
- */
@Override
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getNextNonInstructionAddress(monitor, program, address);
+ }
+
if (isInstructionAt(program, address)) {
- // on an instruction, we have to find a non-instruction before finding the next instruction
+ // on an instruction, find a non-instruction before finding the next instruction
address = getAddressOfNextPreviousNonInstruction(monitor, program, address, true);
}
// we know address is not an instruction at this point
-
return getAddressOfNextInstructionAfter(program, address);
}
@@ -74,16 +71,51 @@ public class NextPreviousInstructionAction extends AbstractNextPreviousAction {
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getPreviousNonInstructionAddress(monitor, program, address);
+ }
+
if (isInstructionAt(program, address)) {
- // on an instruction, we have to find a non-instruction before finding the previous instruction
+ // on an instruction, find a non-instruction before finding the previous instruction
address = getAddressOfNextPreviousNonInstruction(monitor, program, address, false);
}
// we know address is not at an instruction at this point
-
return getAddressOfPreviousInstructionBefore(program, address);
}
+ private Address getNextNonInstructionAddress(TaskMonitor monitor, Program program,
+ Address address) throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on an instruction, find the next data or undefined
+ // -if not on an instruction, find the next instruction, then find the next data or
+ // undefined after that (this mimics the non-inverted case)
+ //
+ if (!isInstructionAt(program, address)) {
+ address = getAddressOfNextInstructionAfter(program, address);
+ }
+
+ return getAddressOfNextPreviousNonInstruction(monitor, program, address, true);
+ }
+
+ private Address getPreviousNonInstructionAddress(TaskMonitor monitor, Program program,
+ Address address) throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on an instruction, find the previous data or undefined
+ // -if not on an instruction, find the previous instruction, then find the previous data or
+ // undefined before that (this mimics the non-inverted case)
+ //
+ if (!isInstructionAt(program, address)) {
+ address = getAddressOfPreviousInstructionBefore(program, address);
+ }
+
+ return getAddressOfNextPreviousNonInstruction(monitor, program, address, false);
+ }
+
private boolean isInstructionAt(Program program, Address address) {
if (address == null) {
return false;
@@ -116,6 +148,10 @@ public class NextPreviousInstructionAction extends AbstractNextPreviousAction {
private Address getAddressOfNextPreviousNonInstruction(TaskMonitor monitor, Program program,
Address address, boolean forward) throws CancelledException {
+ if (address == null) {
+ return null;
+ }
+
CodeUnitIterator codeUnits = program.getListing().getCodeUnits(address, forward);
while (codeUnits.hasNext()) {
monitor.checkCanceled();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousLabelAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousLabelAction.java
index 6fa874045c..e73bc6233b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousLabelAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousLabelAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,21 +15,19 @@
*/
package ghidra.app.plugin.core.navigation;
-import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressIterator;
-import ghidra.program.model.listing.CodeUnit;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.KeyStroke;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressIterator;
+import ghidra.program.model.listing.*;
+import ghidra.program.model.symbol.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
public class NextPreviousLabelAction extends AbstractNextPreviousAction {
@@ -59,6 +56,10 @@ public class NextPreviousLabelAction extends AbstractNextPreviousAction {
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getNextNonLabel(monitor, program, address);
+ }
+
address = getAddressOfNextCodeUnit(program, address);
return getAddressOfNextPreviousLabel(program, address, true);
}
@@ -67,10 +68,71 @@ public class NextPreviousLabelAction extends AbstractNextPreviousAction {
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getPreviousNonLabel(monitor, program, address);
+ }
+
address = getAddressOfPreviousCodeUnit(program, address);
return getAddressOfNextPreviousLabel(program, address, false);
}
+ private Address getNextNonLabel(TaskMonitor monitor, Program program, Address address)
+ throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on a label, find the next non-label code unit
+ // -if not on a label, find the next label, then find the next non-label code unit after
+ // that (this mimics the non-inverted case)
+ //
+ if (!hasLabelAt(program, address)) {
+ address = getAddressOfNextPreviousLabel(program, address, true);
+ }
+
+ return getAddressOfNextPreviousNonLabel(monitor, program, address, true);
+ }
+
+ private Address getPreviousNonLabel(TaskMonitor monitor, Program program, Address address)
+ throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on a label, find the previous non-label code unit
+ // -if not on a label, find the previous label, then find the previous non-label code unit
+ // before that (this mimics the non-inverted case)
+ //
+ if (!hasLabelAt(program, address)) {
+ address = getAddressOfNextPreviousLabel(program, address, false);
+ }
+
+ return getAddressOfNextPreviousNonLabel(monitor, program, address, false);
+ }
+
+ private Address getAddressOfNextPreviousNonLabel(TaskMonitor monitor, Program program,
+ Address address, boolean forward) throws CancelledException {
+
+ if (address == null) {
+ return null;
+ }
+
+ SymbolTable symbolTable = program.getSymbolTable();
+ CodeUnitIterator codeUnits = program.getListing().getCodeUnits(address, forward);
+ while (codeUnits.hasNext()) {
+ monitor.checkCanceled();
+ CodeUnit codeUnit = codeUnits.next();
+ Address minAddress = codeUnit.getMinAddress();
+ if (symbolTable.getPrimarySymbol(minAddress) == null) {
+ return minAddress;
+ }
+ }
+ return null;
+ }
+
+ private boolean hasLabelAt(Program program, Address address) {
+ SymbolTable symbolTable = program.getSymbolTable();
+ return symbolTable.getPrimarySymbol(address) != null;
+ }
+
private Address getAddressOfNextCodeUnit(Program program, Address address) {
CodeUnit cu = program.getListing().getCodeUnitAfter(address);
if (cu == null) {
@@ -87,7 +149,8 @@ public class NextPreviousLabelAction extends AbstractNextPreviousAction {
return cu.getAddress();
}
- private Address getAddressOfNextPreviousLabel(Program program, Address address, boolean forward) {
+ private Address getAddressOfNextPreviousLabel(Program program, Address address,
+ boolean forward) {
if (address == null) {
return null;
@@ -95,7 +158,6 @@ public class NextPreviousLabelAction extends AbstractNextPreviousAction {
Address nextDefinedLableAddress = getNextDefinedLableAddress(program, address, forward);
Address nextReferenceToAddress = getNextReferenceToAddress(program, address, forward);
-
if (nextDefinedLableAddress == null) {
return nextReferenceToAddress;
}
@@ -104,11 +166,9 @@ public class NextPreviousLabelAction extends AbstractNextPreviousAction {
}
int compare = nextDefinedLableAddress.compareTo(nextReferenceToAddress);
-
if (forward) {
return compare <= 0 ? nextDefinedLableAddress : nextReferenceToAddress;
}
-
return compare >= 0 ? nextDefinedLableAddress : nextReferenceToAddress;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousNonFunctionAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousNonFunctionAction.java
deleted file mode 100644
index fdf194c85f..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousNonFunctionAction.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.navigation;
-
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-
-import javax.swing.Icon;
-import javax.swing.KeyStroke;
-
-import ghidra.app.nav.Navigatable;
-import ghidra.app.services.GoToService;
-import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressSetView;
-import ghidra.program.model.listing.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-import resources.ResourceManager;
-
-public class NextPreviousNonFunctionAction extends AbstractNextPreviousAction {
-
- public NextPreviousNonFunctionAction(PluginTool tool, String owner, String subGroup) {
- super(tool, "Next Non-Function", owner, subGroup);
- }
-
- @Override
- protected Icon getIcon() {
- return ResourceManager.loadImage("images/notF.gif");
- }
-
- @Override
- protected KeyStroke getKeyStroke() {
- return KeyStroke.getKeyStroke(KeyEvent.VK_N,
- InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
- }
-
- @Override
- protected String getNavigationTypeName() {
- return "Instruction Not In a Function";
- }
-
- /**
- * Find the beginning of the next instruction range
- * @throws CancelledException
- */
- @Override
- protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
- throws CancelledException {
-
- Function function = program.getListing().getFunctionContaining(address);
- if (function == null) {
- function = getNextFunction(program, address, true);
- }
- if (function == null) {
- return null;
- }
- return findNextInstructionAddressNotInFunction(monitor, program, function.getEntryPoint(),
- true);
- }
-
- @Override
- protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
- throws CancelledException {
-
- Function function = program.getListing().getFunctionContaining(address);
- if (function == null) {
- function = getNextFunction(program, address, false);
- }
- if (function == null) {
- return null;
- }
- return findNextInstructionAddressNotInFunction(monitor, program, function.getEntryPoint(),
- false);
- }
-
- private Address findNextInstructionAddressNotInFunction(TaskMonitor monitor, Program program,
- Address address, boolean isForward) throws CancelledException {
- Function function = program.getListing().getFunctionContaining(address);
- AddressSetView body = function.getBody();
- InstructionIterator it = program.getListing().getInstructions(address, isForward);
- while (it.hasNext()) {
- monitor.checkCanceled();
- Instruction instruction = it.next();
- Address instructionAddress = instruction.getMinAddress();
- if (!body.contains(instructionAddress)) {
- function = program.getListing().getFunctionContaining(instructionAddress);
- if (function == null) {
- return instructionAddress;
- }
- body = function.getBody();
- }
- }
- return null;
- }
-
- private Function getNextFunction(Program program, Address address, boolean forward) {
- FunctionIterator functionIterator = program.getListing().getFunctions(address, forward);
- if (!functionIterator.hasNext()) {
- return null;
- }
- return functionIterator.next();
- }
-
- @Override
- protected void gotoAddress(GoToService service, Navigatable navigatable, Address address) {
- service.goTo(navigatable, address);
- }
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDifferentByteAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousSameBytesAction.java
similarity index 55%
rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDifferentByteAction.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousSameBytesAction.java
index 1499c2301f..366dd942bc 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousDifferentByteAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousSameBytesAction.java
@@ -15,6 +15,13 @@
*/
package ghidra.app.plugin.core.navigation;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.util.Iterator;
+
+import javax.swing.Icon;
+import javax.swing.KeyStroke;
+
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView;
@@ -22,33 +29,28 @@ import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
+import ghidra.util.Msg;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
-
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.util.Iterator;
-
-import javax.swing.Icon;
-import javax.swing.KeyStroke;
-
import resources.ResourceManager;
-public class NextPreviousDifferentByteAction extends AbstractNextPreviousAction {
+/**
+ * Navigates to the same byte pattern value under the current code unit. When negated, the search
+ * will only consider a single byte, as it seems more useful to be able to skip runs of a
+ * particular byte.
+ */
+public class NextPreviousSameBytesAction extends AbstractNextPreviousAction {
- public NextPreviousDifferentByteAction(PluginTool tool, String owner, String subGroup) {
- super(tool, "Next Different Byte Value", owner, subGroup);
- }
+ private static final Icon ICON = ResourceManager.loadImage("images/V.png");
- @Override
- protected String getNavigationTypeName() {
- return "Different Byte Value";
+ NextPreviousSameBytesAction(PluginTool tool, String owner, String subGroup) {
+ super(tool, "Next Matching Byte Values", owner, subGroup);
}
@Override
protected Icon getIcon() {
- return ResourceManager.loadImage("images/V_slash.png");
+ return ICON;
}
@Override
@@ -57,13 +59,24 @@ public class NextPreviousDifferentByteAction extends AbstractNextPreviousAction
InputEvent.ALT_DOWN_MASK);
}
- /**
- * Find the beginning of the next instruction range
- */
+ @Override
+ protected String getNavigationTypeName() {
+ return "Same Bytes Value";
+ }
+
+ @Override
+ protected String getInvertedNavigationTypeName() {
+ return "Different Bytes Value";
+ }
+
@Override
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getNextPreviousDifferentByteValueAddress(monitor, program, address, true);
+ }
+
return getNextPreviousAddress(monitor, program, address, true);
}
@@ -71,12 +84,15 @@ public class NextPreviousDifferentByteAction extends AbstractNextPreviousAction
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getNextPreviousDifferentByteValueAddress(monitor, program, address, false);
+ }
+
return getNextPreviousAddress(monitor, program, address, false);
}
- protected Address getNextPreviousAddress(TaskMonitor monitor, Program program, Address address,
- boolean forward) throws CancelledException {
-
+ private Address getNextPreviousDifferentByteValueAddress(TaskMonitor monitor, Program program,
+ Address address, boolean forward) throws CancelledException {
byte value = 0;
try {
value = program.getMemory().getByte(address);
@@ -114,6 +130,55 @@ public class NextPreviousDifferentByteAction extends AbstractNextPreviousAction
return null;
}
+ private Address getNextPreviousAddress(TaskMonitor monitor, Program program,
+ Address address, boolean forward) {
+
+ Address startAddress;
+ byte[] bytes;
+ CodeUnit cu = program.getListing().getCodeUnitContaining(address);
+ if (cu != null) {
+ try {
+ bytes = cu.getBytes();
+ }
+ catch (MemoryAccessException e) {
+ Msg.debug(this, "Exception getting code unit bytes at " + cu.getAddress(), e);
+ return null; // not sure if this can happen
+ }
+
+ startAddress = forward ? cu.getMaxAddress().next() : cu.getMinAddress().previous();
+ }
+ else {
+ try {
+ Memory memory = program.getMemory();
+ bytes = new byte[] { memory.getByte(address) };
+ }
+ catch (MemoryAccessException e) {
+ Msg.debug(this, "Exception getting code unit bytes at " + address, e);
+ return null; // not sure if this can happen
+ }
+
+ startAddress = forward ? address.next() : address.previous();
+ }
+
+ return getNextPreviousSameBytes(monitor, program, startAddress, bytes, forward);
+ }
+
+ private Address getNextPreviousSameBytes(TaskMonitor monitor, Program program,
+ Address startAddress, byte[] bytes, boolean forward) {
+ Memory memory = program.getMemory();
+ byte[] mask = null; // null signals to use a full mask
+ AddressSetView addresses = memory.getAllInitializedAddressSet();
+ if (startAddress == null) {
+ return null;
+ }
+
+ Address endAddress =
+ forward ? addresses.getMaxAddress() : addresses.getMinAddress().previous();
+ Address matchAddress = memory.findBytes(startAddress, endAddress, bytes,
+ mask, forward, monitor);
+ return matchAddress;
+ }
+
private CodeUnit getNextPreviousCodeUnit(Program program, Address address, boolean forward) {
if (forward) {
return program.getListing().getDefinedCodeUnitAfter(address);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousUndefinedAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousUndefinedAction.java
index 026e9df3de..c2c0f5793b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousUndefinedAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousUndefinedAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +15,17 @@
*/
package ghidra.app.plugin.core.navigation;
-import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.KeyStroke;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
public class NextPreviousUndefinedAction extends AbstractNextPreviousAction {
@@ -52,21 +50,20 @@ public class NextPreviousUndefinedAction extends AbstractNextPreviousAction {
return "Undefined";
}
- /**
- * Find the beginning of the next instruction range
- * @throws CancelledException
- */
@Override
protected Address getNextAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getNextNonUndefined(monitor, program, address);
+ }
+
if (isUndefinedAt(program, address)) {
- // on an undefined, we have to find a defined before finding the next undefined
+ // on an undefined, find a defined before finding the next undefined
address = getAddressOfNextDefined(program, address);
}
- // we know address is not an instruction at this point
-
+ // we know address is not an undefined at this point
return getAddressOfNextPreviousUndefined(monitor, program, address, true);
}
@@ -74,16 +71,51 @@ public class NextPreviousUndefinedAction extends AbstractNextPreviousAction {
protected Address getPreviousAddress(TaskMonitor monitor, Program program, Address address)
throws CancelledException {
+ if (isInverted) {
+ return getPreviousNonUndefined(monitor, program, address);
+ }
+
if (isUndefinedAt(program, address)) {
- // on an instruction, we have to find a non-instruction before finding the previous instruction
+ // on an undefined, find a defined before finding the previous undefined
address = getAddressOfPreviousDefined(program, address);
}
- // we know address is not at an instruction at this point
-
+ // we know address is not at an undefined at this point
return getAddressOfNextPreviousUndefined(monitor, program, address, false);
}
+ private Address getNextNonUndefined(TaskMonitor monitor, Program program, Address address)
+ throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on an undefined, find the next instruction or data
+ // -if not on an undefined, find the next undefined, then find the next instruction or
+ // undefined after that (this mimics the non-inverted case)
+ //
+ if (!isUndefinedAt(program, address)) {
+ address = getAddressOfNextPreviousUndefined(monitor, program, address, true);
+ }
+
+ return getAddressOfNextDefined(program, address);
+ }
+
+ private Address getPreviousNonUndefined(TaskMonitor monitor, Program program, Address address)
+ throws CancelledException {
+
+ //
+ // Assumptions:
+ // -if on an undefined, find the previous data or instruction
+ // -if not on an undefined, find the previous undefined, then find the previous data or
+ // instruction before that (this mimics the non-inverted case)
+ //
+ if (!isUndefinedAt(program, address)) {
+ address = getAddressOfNextPreviousUndefined(monitor, program, address, false);
+ }
+
+ return getAddressOfPreviousDefined(program, address);
+ }
+
private boolean isUndefinedAt(Program program, Address address) {
if (address == null) {
return false;
diff --git a/Ghidra/Features/Base/src/main/resources/images/V.png b/Ghidra/Features/Base/src/main/resources/images/V.png
new file mode 100644
index 0000000000..3918e8d774
Binary files /dev/null and b/Ghidra/Features/Base/src/main/resources/images/V.png differ
diff --git a/Ghidra/Features/Base/src/main/resources/images/V_slash.png b/Ghidra/Features/Base/src/main/resources/images/V_slash.png
deleted file mode 100644
index c0d71a7021..0000000000
Binary files a/Ghidra/Features/Base/src/main/resources/images/V_slash.png and /dev/null differ
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java
index 9f5ae523c1..8ef5531737 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java
@@ -659,7 +659,9 @@ public class BookmarkPluginTest extends AbstractGhidraHeadedIntegrationTest {
BookmarkManager bm = program.getBookmarkManager();
tx(program, () -> {
- bm.removeBookmarks(BookmarkType.ALL_TYPES);
+ bm.removeBookmarks("Type1");
+ bm.removeBookmarks("Type2");
+ bm.removeBookmarks("Type3");
});
list = getBookmarks(program.getBookmarkManager());
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
index 8c36150c3a..e2a4b9e0ab 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
@@ -15,8 +15,7 @@
*/
package ghidra.app.plugin.core.navigation;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.awt.Color;
@@ -31,14 +30,12 @@ import docking.menu.MultiStateDockingAction;
import ghidra.app.cmd.data.CreateDataCmd;
import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.app.plugin.core.bookmark.BookmarkEditCmd;
-import ghidra.app.plugin.core.bookmark.BookmarkPlugin;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
-import ghidra.app.services.ProgramManager;
import ghidra.framework.cmd.CompoundCmd;
import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.address.*;
-import ghidra.program.model.data.DWordDataType;
-import ghidra.program.model.data.StructureDataType;
+import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.Memory;
import ghidra.test.*;
@@ -50,47 +47,45 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
private TestEnv env;
private PluginTool tool;
private AddressFactory addrFactory;
+ private ProgramBuilder builder;
private Program program;
private CodeBrowserPlugin cb;
+ private BookmarkManager bookmarkManager;
+
private DockingActionIf direction;
- private DockingActionIf nextInst;
+ private DockingActionIf invert;
+ private DockingActionIf nextInstruction;
private DockingActionIf nextData;
- private DockingActionIf nextUndef;
+ private DockingActionIf nextUndefined;
private DockingActionIf nextLabel;
- private DockingActionIf nextFunc;
- private DockingActionIf nextNonFunc;
+ private DockingActionIf nextFunction;
+ private DockingActionIf nextByteValue;
private MultiStateDockingAction<String> nextBookmark;
- private BookmarkManager bookmarkManager;
private Address addr(String address) {
return addrFactory.getAddress(address);
}
+ @SuppressWarnings("unchecked") // we know that bookmarks is of type String
@Before
public void setUp() throws Exception {
env = new TestEnv();
- tool = env.getTool();
- setupTool(tool);
- cb = env.getPlugin(CodeBrowserPlugin.class);
- }
-
- @SuppressWarnings("unchecked")
- // we know that bookmarks is of type String
- private void setupTool(PluginTool tool) throws Exception {
- tool.addPlugin(CodeBrowserPlugin.class.getName());
- tool.addPlugin(NextPrevAddressPlugin.class.getName());
- tool.addPlugin(NextPrevCodeUnitPlugin.class.getName());
- tool.addPlugin(BookmarkPlugin.class.getName());
+ loadProgram();
+ tool = env.launchDefaultTool(program);
NextPrevCodeUnitPlugin p = getPlugin(tool, NextPrevCodeUnitPlugin.class);
direction = getAction(p, "Toggle Search Direction");
- nextInst = getAction(p, "Next Instruction");
+ invert = getAction(p, "Invert Search Logic");
+ nextInstruction = getAction(p, "Next Instruction");
nextData = getAction(p, "Next Data");
- nextUndef = getAction(p, "Next Undefined");
+ nextUndefined = getAction(p, "Next Undefined");
nextLabel = getAction(p, "Next Label");
- nextFunc = getAction(p, "Next Function");
- nextNonFunc = getAction(p, "Next Non-Function");
+ nextFunction = getAction(p, "Next Function");
+ nextByteValue = getAction(p, "Next Matching Byte Values");
+
nextBookmark = (MultiStateDockingAction<String>) getAction(p, "Next Bookmark");
+
+ cb = env.getPlugin(CodeBrowserPlugin.class);
}
@After
@@ -98,311 +93,547 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
env.dispose();
}
- private void loadProgram(String programName) throws Exception {
+ private void loadProgram() throws Exception {
- ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder();
- builder.setName(programName);
- program = builder.getProgram();
+ // create a grouping of data types to test the Byte Value searching
+
+ builder = new ClassicSampleX86ProgramBuilder();
- ProgramManager pm = tool.getService(ProgramManager.class);
- pm.openProgram(program.getDomainFile());
- builder.dispose();
+ program = builder.getProgram();
addrFactory = program.getAddressFactory();
bookmarkManager = program.getBookmarkManager();
}
+ private void addData() throws Exception {
+ addType("01001010", "52 65 67 69", new DWordDataType());
+ addType("01001016", "64 00 6f 00 77", new DWordDataType());
+ addType("0100101c", "43 68 6f 6f", new DWordDataType());
+ addType("01001020", "43 68 6f 6f", new DWordDataType());
+ addType("01001024", "43 68 6f 6f", new DWordDataType());
+ addType("0100102a", "15 00", new DWordDataType());
+ }
+
+ private void addType(String addrString, String bytes, DataType dt)
+ throws Exception {
+ builder.setBytes(addrString, bytes);
+ builder.applyDataType(addrString, dt);
+ }
+
@Test
public void testToggle() throws Exception {
- loadProgram("notepad");
- showTool(tool);
+
Icon upIcon = ResourceManager.loadImage("images/up.png");
Icon downIcon = ResourceManager.loadImage("images/down.png");
assertEquals(downIcon, direction.getToolBarData().getIcon());
- assertStartsWith("Go To Next Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Next Instruction", nextInstruction.getDescription());
assertStartsWith("Go To Next Data", nextData.getDescription());
- assertStartsWith("Go To Next Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Next Undefined", nextUndefined.getDescription());
assertStartsWith("Go To Next Label", nextLabel.getDescription());
- assertStartsWith("Go To Next Function", nextFunc.getDescription());
- assertStartsWith("Go To Next Instruction Not In a Function", nextNonFunc.getDescription());
+ assertStartsWith("Go To Next Function", nextFunction.getDescription());
assertStartsWith("Go To Next Bookmark: All Types", nextBookmark.getDescription());
- performAction(direction, cb.getProvider(), true);
+ toggleDirection();
assertEquals(upIcon, direction.getToolBarData().getIcon());
- assertStartsWith("Go To Previous Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Previous Instruction", nextInstruction.getDescription());
assertStartsWith("Go To Previous Data", nextData.getDescription());
- assertStartsWith("Go To Previous Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Previous Undefined", nextUndefined.getDescription());
assertStartsWith("Go To Previous Label", nextLabel.getDescription());
- assertStartsWith("Go To Previous Function", nextFunc.getDescription());
- assertStartsWith("Go To Previous Instruction Not In a Function",
- nextNonFunc.getDescription());
+ assertStartsWith("Go To Previous Function", nextFunction.getDescription());
assertStartsWith("Go To Previous Bookmark: All Types", nextBookmark.getDescription());
- performAction(direction, cb.getProvider(), true);
+ toggleDirection();
assertEquals(downIcon, direction.getToolBarData().getIcon());
- assertStartsWith("Go To Next Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Next Instruction", nextInstruction.getDescription());
assertStartsWith("Go To Next Data", nextData.getDescription());
- assertStartsWith("Go To Next Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Next Undefined", nextUndefined.getDescription());
assertStartsWith("Go To Next Label", nextLabel.getDescription());
- assertStartsWith("Go To Next Function", nextFunc.getDescription());
- assertStartsWith("Go To Next Instruction Not In a Function", nextNonFunc.getDescription());
+ assertStartsWith("Go To Next Function", nextFunction.getDescription());
assertStartsWith("Go To Next Bookmark: All Types", nextBookmark.getDescription());
}
- private static void assertStartsWith(String expected, String actual) {
- assertTrue("startsWith expected: \"" + expected + "\", got: \"" + actual + "\"",
- actual.startsWith(expected));
- }
-
@Test
public void testSearchInstruction() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextInst, cb.getProvider(), true);
- assertEquals(addr("0x1002239"), cb.getCurrentAddress());
- performAction(nextInst, cb.getProvider(), true);
- assertEquals(addr("0x1002cf5"), cb.getCurrentAddress());
- performAction(direction, cb.getProvider(), true);
- performAction(nextInst, cb.getProvider(), true);
- assertEquals(addr("0x100294d"), cb.getCurrentAddress());
- performAction(nextInst, cb.getProvider(), true);
+ assertAddress("0x1001000");
+ nextInstruction();
+ assertAddress("0x1002239");
+ nextInstruction();
+ assertAddress("0x1002cf5");
+
+ toggleDirection();
+
+ nextInstruction();
+ assertAddress("0x100294d");
+ nextInstruction();
// no more instructions, this is the last range
- assertEquals(addr("0x100294d"), cb.getCurrentAddress());
+ assertAddress("0x100294d");
+ }
+
+ @Test
+ public void testSearchNotInstruction() throws Exception {
+
+ negateSearch();
+
+ assertAddress("0x1001000");
+ nextInstruction();
+ assertAddress("0x01002950");
+ nextInstruction();
+ assertAddress("0x01002d6e");
+
+ toggleDirection();
+
+ nextInstruction();
+ assertAddress("0x01002cf4");
+ nextInstruction();
+ assertAddress("0x01002238");
}
@Test
public void testSearchData() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextData, cb.getProvider(), true);
- assertEquals(addr("0x1001058"), cb.getCurrentAddress());
- performAction(nextData, cb.getProvider(), true);
- assertEquals(addr("0x1001080"), cb.getCurrentAddress());
- performAction(direction, cb.getProvider(), true);
- performAction(nextData, cb.getProvider(), true);
- assertEquals(addr("0x1001058"), cb.getCurrentAddress());
- performAction(nextData, cb.getProvider(), true);
+ assertAddress("0x1001000");
+ nextData();
+ assertAddress("0x1001058");
+ nextData();
+ assertAddress("0x1001080");
+
+ toggleDirection();
+
+ nextData();
+ assertAddress("0x1001058");
+ nextData();
+ assertAddress("0x01001008");
+ }
+
+ @Test
+ public void testSearchNotData() throws Exception {
+
+ negateSearch();
+
+ assertAddress("0x1001000");
+ nextData();
+ assertAddress("0x0100100c");
+ nextData();
+ assertAddress("0x0100105c");
+ toggleDirection();
+
+ nextData();
+ assertAddress("0x01001057");
+ nextData();
+ // no more undefined data or instructions, this is the last range
+ assertAddress("0x1001057");
}
@Test
public void testSearchUndefined() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextUndef, cb.getProvider(), true);
- assertEquals(addr("0x100100c"), cb.getCurrentAddress());
- performAction(nextUndef, cb.getProvider(), true);
- assertEquals(addr("0x100105c"), cb.getCurrentAddress());
- performAction(direction, cb.getProvider(), true);
- performAction(nextUndef, cb.getProvider(), true);
- assertEquals(addr("0x1001057"), cb.getCurrentAddress());
- performAction(nextUndef, cb.getProvider(), true);
+ assertAddress("0x1001000");
+ nextUndefined();
+ assertAddress("0x100100c");
+ nextUndefined();
+ assertAddress("0x100105c");
+ toggleDirection();
+
+ nextUndefined();
+ assertAddress("0x1001057");
+ nextUndefined();
// no more undefined data, this is the last range
- assertEquals(addr("0x1001057"), cb.getCurrentAddress());
+ assertAddress("0x1001057");
+ }
+
+ @Test
+ public void testSearchNotUndefined() throws Exception {
+
+ negateSearch();
+
+ assertAddress("0x1001000");
+ nextUndefined();
+ assertAddress("0x1001058");
+ nextUndefined();
+ assertAddress("0x1001080");
+
+ toggleDirection();
+
+ nextUndefined();
+ assertAddress("0x1001058");
+ nextUndefined();
+ assertAddress("0x1001008");
}
@Test
public void testSearchLabel() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextLabel, cb.getProvider(), true);
- assertEquals(addr("0x1001004"), cb.getCurrentAddress());
- performAction(nextLabel, cb.getProvider(), true);
- assertEquals(addr("0x1001008"), cb.getCurrentAddress());
- performAction(direction, cb.getProvider(), true);
- performAction(nextLabel, cb.getProvider(), true);
- assertEquals(addr("0x1001004"), cb.getCurrentAddress());
- performAction(nextLabel, cb.getProvider(), true);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextLabel, cb.getProvider(), true);
+ assertAddress("0x1001000");
+ nextLabel();
+ assertAddress("0x1001004");
+ nextLabel();
+ assertAddress("0x1001008");
+
+ toggleDirection();
+
+ nextLabel();
+ assertAddress("0x1001004");
+ nextLabel();
+ assertAddress("0x1001000");
+ nextLabel();
// no more labels, this is the last range
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
+ assertAddress("0x1001000");
+ }
+
+ @Test
+ public void testSearchNotLabel() throws Exception {
+
+ negateSearch();
+
+ assertAddress("0x1001000");
+ nextLabel();
+ assertAddress("0x100100c");
+ nextLabel();
+ assertAddress("0x100105c");
+
+ toggleDirection();
+
+ nextLabel();
+ assertAddress("0x1001057");
+ nextLabel();
+ assertAddress("0x1001057"); // no more non-labels
}
@Test
public void testSearchFunction() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextFunc, cb.getProvider(), true);
- assertEquals(addr("0x100194b"), cb.getCurrentAddress());
- performAction(nextFunc, cb.getProvider(), true);
- assertEquals(addr("0x1001ae3"), cb.getCurrentAddress());
- performAction(direction, cb.getProvider(), true);
- performAction(nextFunc, cb.getProvider(), true);
- assertEquals(addr("0x100194b"), cb.getCurrentAddress());
- performAction(nextFunc, cb.getProvider(), true);
+ assertAddress("0x1001000");
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress("0x100194b");
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress("0x1001ae3");
+
+ toggleDirection();
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress("0x100194b");
+ performAction(nextFunction, cb.getProvider(), true);
// no more functions, this is the last range
- assertEquals(addr("0x100194b"), cb.getCurrentAddress());
+ assertAddress("0x100194b");
}
@Test
- public void testSearchNonFunction() throws Exception {
- loadProgram("notepad");
+ public void testSearchNotFunction() throws Exception {
Address a1 = addInstructions("0x01006600");
Address a2 = addInstructions("0x0100662a");
- showTool(tool);
- assertEquals(addr("0x1001000"), cb.getCurrentAddress());
- performAction(nextNonFunc, cb.getProvider(), true);
- assertEquals(a1, cb.getCurrentAddress());
- performAction(nextNonFunc, cb.getProvider(), true);
- assertEquals(a2, cb.getCurrentAddress());
+ assertAddress("0x1001000");
- performAction(direction, cb.getProvider(), true);
- performAction(nextNonFunc, cb.getProvider(), true);
- assertEquals(addr("0x1006603"), cb.getCurrentAddress());
- performAction(nextNonFunc, cb.getProvider(), true);
+ // search wit the function action in the inverted mode
+ negateSearch();
+
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress(a1);
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress(a2);
+
+ toggleDirection();
+
+ performAction(nextFunction, cb.getProvider(), true);
+ assertAddress("0x1006603");
+ performAction(nextFunction, cb.getProvider(), true);
// no more functions, this is the last range
- assertEquals(addr("0x1006603"), cb.getCurrentAddress());
+ assertAddress("0x1006603");
+ }
+
+ @Test
+ public void testSearchNotBytesValue_SingleByte() throws Exception {
+
+ /*
+ 01005ad5 50 ?? 50h P
+ 01005ad6 56 ?? 56h V
+ 01005ad7 56 ?? 56h V
+ 01005ad8 56 ?? 56h V
+ 01005ad9 53 ?? 53h S
+ */
+
+ negateSearch();
+
+ goTo(tool, program, addr("01005ad5"));
+
+ nextByteValue();
+ assertAddress("01005ad6");
+ nextByteValue();
+ assertAddress("01005ad9");
+
+ toggleDirection();
+
+ nextByteValue();
+ assertAddress("01005ad8");
+ nextByteValue();
+ assertAddress("01005ad5");
+ }
+
+ @Test
+ public void testSearchNotBytesValue_Instruction() throws Exception {
+
+ /*
+ 01005a49 8b 3d 14 MOV EDI,dword ptr [DAT_01001214]
+ 12 00 01
+ 01005a4f 56 PUSH ESI
+ 01005a50 56 PUSH ESI
+ 01005a51 6a 0e PUSH 0xe
+ 01005a53 ff 35 d4 PUSH dword ptr [DAT_010087d4]
+ 87 00 01
+ 01005a59 ff d7 CALL EDI
+ */
+
+ negateSearch();
+
+ goTo(tool, program, addr("01005a49"));
+
+ nextByteValue();
+ assertAddress("01005a4f");
+ nextByteValue();
+ assertAddress("01005a51");
+
+ toggleDirection();
+
+ nextByteValue();
+ assertAddress("01005a50");
+ nextByteValue();
+ assertAddress("01005a49");
+ }
+
+ @Test
+ public void testSearchBytesValue_Data() throws Exception {
+
+ /*
+
+ 01001010 52 65 67 69 ddw 69676552h
+ 01001014 00 ?? 00h
+ 01001015 00 ?? 00h
+ 01001016 64 00 6f 00 ddw 6F0064h
+ 0100101a 77 ?? 77h w
+ 0100101b 00 ?? 00h
+ 0100101c 43 68 6f 6f ddw 6F6F6843h
+ 01001020 43 68 6f 6f ddw 6F6F6843h
+ 01001024 43 68 6f 6f ddw 6F6F6843h
+ 01001028 00 ?? 00h
+ 01001029 00 ?? 00h
+ 0100102a 15 00 00 00 ddw 15h
+
+ */
+
+ addData();
+
+ goTo(tool, program, addr("01001010"));
+
+ nextByteValue();
+ assertAddress("0100750e"); // a far away match
+
+ goTo(tool, program, addr("0100101c"));
+ nextByteValue();
+ assertAddress("01001020");
+ nextByteValue();
+ assertAddress("01001024");
+ nextByteValue();
+ assertAddress("01006a02");
+
+ toggleDirection();
+
+ goTo(tool, program, addr("01001024"));
+ nextByteValue();
+ assertAddress("01001020");
+ nextByteValue();
+ assertAddress("0100101c");
+ nextByteValue();
+ assertAddress("0100101c"); // no more matching bytes
+ }
+
+ @Test
+ public void testSearchNotBytesValue_Data() throws Exception {
+
+ /*
+
+ 01001010 52 65 67 69 ddw 69676552h
+ 01001014 00 ?? 00h
+ 01001015 00 ?? 00h
+ 01001016 64 00 6f 00 ddw 6F0064h
+ 0100101a 77 ?? 77h w
+ 0100101b 00 ?? 00h
+ 0100101c 43 68 6f 6f ddw 6F6F6843h
+ 01001020 43 68 6f 6f ddw 6F6F6843h
+ 01001024 43 68 6f 6f ddw 6F6F6843h
+ 01001028 00 ?? 00h
+ 01001029 00 ?? 00h
+ 0100102a 15 00 00 00 ddw 15h
+
+ */
+
+ addData();
+
+ negateSearch();
+
+ goTo(tool, program, addr("01001010"));
+
+ nextByteValue();
+ assertAddress("01001014");
+ nextByteValue();
+ assertAddress("01001016");
+ nextByteValue();
+ assertAddress("0100101a");
+
+ goTo(tool, program, addr("0100101c"));
+ nextByteValue();
+ assertAddress("01001020");
+
+ goTo(tool, program, addr("01001024"));
+ nextByteValue();
+ assertAddress("01001028");
+ nextByteValue();
+ assertAddress("0100102a");
+
+ toggleDirection();
+
+ nextByteValue();
+ assertAddress("01001029");
+ nextByteValue();
+ assertAddress("01001024");
+ nextByteValue();
+ assertAddress("01001020");
+
+ goTo(tool, program, addr("01001015"));
+ nextByteValue();
+ assertAddress("01001010");
}
@Test
public void testSearchAllTypesBookmark() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("01001000"), cb.getCurrentAddress());
-
- //
- // Setup:
- // 100c - error bookmark
- // 101c - info bookmark
- // 101e - warning bookmark
- //
- CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
- addCmd.add(new BookmarkEditCmd(addr("0100100c"), BookmarkType.ERROR, "Cat1a", "Cmt1A"));
- addCmd.add(new BookmarkEditCmd(addr("0100101c"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
- addCmd.add(new BookmarkEditCmd(addr("0100101e"), BookmarkType.WARNING, "Cat1a", "Cmt1B"));
- applyCmd(program, addCmd);
- selectBookmarkType(BookmarkType.ALL_TYPES);
+ addBookmark("0100100c", BookmarkType.ERROR);
+ addBookmark("0100101c", BookmarkType.INFO);
+ addBookmark("0100101e", BookmarkType.WARNING);
+
+ selectBookmarkType(NextPreviousBookmarkAction.ALL_BOOKMARK_TYPES);
- pressBookmark();
- assertEquals(addr("0100100c"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100101c"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100101e"), cb.getCurrentAddress());
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("0100100c");
+ nextBookmark();
+ assertAddress("0100101c");
+ nextBookmark();
+ assertAddress("0100101e");
toggleDirection();
- pressBookmark();
- assertEquals(addr("0100101c"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100100c"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("0100101c");
+ nextBookmark();
+ assertAddress("0100100c");
+ }
+
+ @Test
+ public void testSearchNotBookmark() throws Exception {
+
+ addBookmark("0100100c", BookmarkType.ERROR);
+ addBookmark("0100101c", BookmarkType.INFO);
+ addBookmark("0100101e", BookmarkType.WARNING);
+
+ selectBookmarkType(NextPreviousBookmarkAction.ALL_BOOKMARK_TYPES);
+
+ negateSearch();
+
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("0100100d");
+ nextBookmark();
+ assertAddress("0100101d");
+ nextBookmark();
+ assertAddress("0100101f");
+
+ toggleDirection();
+
+ nextBookmark();
+ assertAddress("0100101d");
+ nextBookmark();
+ assertAddress("0100101b");
}
@Test
public void testOffcutBookmarkForwardAndBackward() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("01001000"), cb.getCurrentAddress());
-
- //
- // Setup:
- // 1000 - info bookmark
- // 1006 - offcut info bookmark
- // 101e - info bookmark
- //
- CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
- addCmd.add(new BookmarkEditCmd(addr("01001000"), BookmarkType.INFO, "Cat1a", "Cmt1A"));
- addCmd.add(new BookmarkEditCmd(addr("01001004"), BookmarkType.INFO, "Cat1a", "Cmt1BC"));
- addCmd.add(new BookmarkEditCmd(addr("01001006"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
- addCmd.add(new BookmarkEditCmd(addr("0100101e"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
- applyCmd(program, addCmd);
- selectBookmarkType(BookmarkType.ALL_TYPES);
+ addBookmark("01001000", BookmarkType.INFO);
+ addBookmark("01001004", BookmarkType.INFO);
+ addBookmark("01001006", BookmarkType.INFO); // offcut
+ addBookmark("0100101e", BookmarkType.INFO);
- pressBookmark();
- assertEquals(addr("01001004"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100101e"), cb.getCurrentAddress());
+ selectBookmarkType(NextPreviousBookmarkAction.ALL_BOOKMARK_TYPES);
+
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("01001004");
+ nextBookmark();
+ assertAddress("0100101e");
toggleDirection();
- pressBookmark();
- assertEquals(addr("01001004"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001000"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001004");
+ nextBookmark();
+ assertAddress("01001000");
}
@Test
public void testBookmarksOffcutInStructures() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("01001000"), cb.getCurrentAddress());
-
- //
- // Setup:
- // 1000 - info bookmark
- // 1006 - offcut info bookmark
- // 101e - info bookmark
- //
- CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
- addCmd.add(new BookmarkEditCmd(addr("01001000"), BookmarkType.INFO, "Cat1a", "A"));
- addCmd.add(new BookmarkEditCmd(addr("01001004"), BookmarkType.INFO, "Cat1a", "B"));
- addCmd.add(new BookmarkEditCmd(addr("0100100d"), BookmarkType.INFO, "Cat1a", "C"));
- addCmd.add(new BookmarkEditCmd(addr("01001010"), BookmarkType.INFO, "Cat1a", "C"));
- addCmd.add(new BookmarkEditCmd(addr("01001015"), BookmarkType.INFO, "Cat1a", "D"));
- addCmd.add(new BookmarkEditCmd(addr("01001020"), BookmarkType.INFO, "Cat1a", "E"));
+
+ addBookmark("01001000", BookmarkType.INFO);
+ addBookmark("01001004", BookmarkType.INFO);
+ addBookmark("0100100d", BookmarkType.INFO);
+ addBookmark("01001010", BookmarkType.INFO);
+ addBookmark("01001015", BookmarkType.INFO);
+ addBookmark("01001020", BookmarkType.INFO);
StructureDataType struct = new StructureDataType("Test", 0);
struct.add(new DWordDataType());
struct.add(new DWordDataType());
struct.add(new DWordDataType());
assertEquals(12, struct.getLength());
-
- addCmd.add(new CreateDataCmd(addr("0100100c"), struct));
-
- applyCmd(program, addCmd);
-
- selectBookmarkType(BookmarkType.ALL_TYPES);
-
- pressBookmark();
- assertEquals(addr("01001004"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100100c"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001010"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001014"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001020"), cb.getCurrentAddress());
+ applyCmd(program, new CreateDataCmd(addr("0100100c"), struct));
+
+ selectBookmarkType(NextPreviousBookmarkAction.ALL_BOOKMARK_TYPES);
+
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("01001004");
+ nextBookmark();
+ assertAddress("0100100c");
+ nextBookmark();
+ assertAddress("01001010");
+ nextBookmark();
+ assertAddress("01001014");
+ nextBookmark();
+ assertAddress("01001020");
toggleDirection();
- pressBookmark();
- assertEquals(addr("01001014"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001010"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("0100100c"), cb.getCurrentAddress());
- pressBookmark();
- assertEquals(addr("01001004"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001014");
+ nextBookmark();
+ assertAddress("01001010");
+ nextBookmark();
+ assertAddress("0100100c");
+ nextBookmark();
+ assertAddress("01001004");
}
@Test
- public void testErrorBookmark() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("01001000"), cb.getCurrentAddress());
+ public void testSearchErrorBookmark() throws Exception {
+
clearExisingBookmarks();
// add more to our current set
@@ -420,53 +651,88 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
selectBookmarkType(BookmarkType.ERROR);
- pressBookmark();
- assertEquals(addr("01001110"), cb.getCurrentAddress());
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("01001110");
- pressBookmark();
- assertEquals(addr("01001120"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001120");
- pressBookmark();
- assertEquals(addr("01001130"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001130");
- pressBookmark();
- assertEquals(addr("01001140"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001140");
- pressBookmark();
- assertEquals(addr("01001150"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001150");
- pressBookmark();
- assertEquals(addr("01001160"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001160");
- pressBookmark();
- assertEquals(addr("01001160"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001160");
toggleDirection();
- pressBookmark();
- assertEquals(addr("01001150"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001150");
+
+ nextBookmark();
+ assertAddress("01001140");
+
+ nextBookmark();
+ assertAddress("01001130");
+
+ nextBookmark();
+ assertAddress("01001120");
+
+ nextBookmark();
+ assertAddress("01001110");
+
+ nextBookmark();
+ assertAddress("01001110");
+ }
+
+ @Test
+ public void testSearchNotErrorBookmark() throws Exception {
+
+ clearExisingBookmarks();
+
+ addBookmark("01001110", BookmarkType.ERROR);
+ addBookmark("01001118", BookmarkType.NOTE);
+ addBookmark("01001120", BookmarkType.ERROR);
+ addBookmark("01001130", BookmarkType.ERROR);
+ addBookmark("01001140", BookmarkType.WARNING);
+ addBookmark("01001143", BookmarkType.INFO);
+
+ selectBookmarkType(BookmarkType.ERROR);
+
+ negateSearch();
- pressBookmark();
- assertEquals(addr("01001140"), cb.getCurrentAddress());
+ assertAddress("01001000");
+ nextBookmark();
+ assertAddress("01001118");
- pressBookmark();
- assertEquals(addr("01001130"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001140");
- pressBookmark();
- assertEquals(addr("01001120"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001143");
- pressBookmark();
- assertEquals(addr("01001110"), cb.getCurrentAddress());
+ toggleDirection();
+
+ nextBookmark();
+ assertAddress("01001140");
- pressBookmark();
- assertEquals(addr("01001110"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01001118");
}
@Test
- public void testWarningBookmark() throws Exception {
- loadProgram("notepad");
- showTool(tool);
- assertEquals(addr("01001000"), cb.getCurrentAddress());
+ public void testSearchWarningBookmark() throws Exception {
+
+ assertAddress("01001000");
clearExisingBookmarks();
// add more to our current set
@@ -484,54 +750,52 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
selectBookmarkType(BookmarkType.WARNING);
- pressBookmark();
- assertEquals(addr("01003e2c"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e2c");
- pressBookmark();
- assertEquals(addr("01003e30"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e30");
- pressBookmark();
- assertEquals(addr("01003e32"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e32");
- pressBookmark();
- assertEquals(addr("01003e38"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e38");
- pressBookmark();
- assertEquals(addr("01003e3a"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e3a");
- pressBookmark();
- assertEquals(addr("01003e43"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e43");
- pressBookmark();
- assertEquals(addr("01003e43"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e43");
toggleDirection();
- pressBookmark();
- assertEquals(addr("01003e3a"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e3a");
- pressBookmark();
- assertEquals(addr("01003e38"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e38");
- pressBookmark();
- assertEquals(addr("01003e32"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e32");
- pressBookmark();
- assertEquals(addr("01003e30"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e30");
- pressBookmark();
- assertEquals(addr("01003e2c"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e2c");
- pressBookmark();
- assertEquals(addr("01003e2c"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("01003e2c");
}
@Test
- public void testCustomBobBookmark() throws Exception {
- loadProgram("notepad");
- showTool(tool);
+ public void testSearchCustomBobBookmark() throws Exception {
- assertEquals(addr("01001000"), cb.getCurrentAddress());
+ assertAddress("01001000");
ImageIcon bookmarkBobIcon =
ResourceManager.loadImage("images/applications-engineering.png");
@@ -553,52 +817,97 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
selectBookmarkType("Custom");
- pressBookmark();
- assertEquals(addr("0100529b"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("0100529b");
- pressBookmark();
- assertEquals(addr("0100529e"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("0100529e");
- pressBookmark();
- assertEquals(addr("010052a1"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a1");
- pressBookmark();
- assertEquals(addr("010052a4"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a4");
- pressBookmark();
- assertEquals(addr("010052a7"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a7");
- pressBookmark();
- assertEquals(addr("010052a7"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a7");
toggleDirection();
- pressBookmark();
- assertEquals(addr("010052a4"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a4");
- pressBookmark();
- assertEquals(addr("010052a1"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("010052a1");
- pressBookmark();
- assertEquals(addr("0100529e"), cb.getCurrentAddress());
+ nextBookmark();
+ assertAddress("0100529e");
+
+ nextBookmark();
+ assertAddress("0100529b");
+
+ nextBookmark();
+ assertAddress("0100529b");
+ }
- pressBookmark();
- assertEquals(addr("0100529b"), cb.getCurrentAddress());
+//==================================================================================================
+// Private Methods
+//==================================================================================================
- pressBookmark();
- assertEquals(addr("0100529b"), cb.getCurrentAddress());
+ private void addBookmark(String addrString, String type) {
+ applyCmd(program, new BookmarkEditCmd(addr(addrString), type, "Cat1a", "Cmt1A"));
+ }
+
+ private void assertStartsWith(String expected, String actual) {
+ assertTrue("startsWith expected: \"" + expected + "\", got: \"" + actual + "\"",
+ actual.startsWith(expected));
+ }
+
+ private void assertAddress(String addrString) {
+ assertEquals(addr(addrString), cb.getCurrentAddress());
+ }
+
+ private void assertAddress(Address addr) {
+ assertEquals(addr, cb.getCurrentAddress());
}
private void toggleDirection() {
performAction(direction, cb.getProvider(), true);
}
- private void pressBookmark() throws Exception {
+ private void nextInstruction() {
+ performAction(nextInstruction, cb.getProvider(), true);
+ }
+
+ private void nextData() {
+ performAction(nextData, cb.getProvider(), true);
+ }
+
+ private void nextUndefined() {
+ performAction(nextUndefined, cb.getProvider(), true);
+ }
+
+ private void nextLabel() {
+ performAction(nextLabel, cb.getProvider(), true);
+ }
+
+ private void negateSearch() {
+ performAction(invert, cb.getProvider(), true);
+ }
+
+ private void nextBookmark() throws Exception {
performAction(nextBookmark, cb.getProvider(), true);
waitForSwing();
waitForTasks();
}
+ private void nextByteValue() {
+ performAction(nextByteValue, cb.getProvider(), true);
+ }
+
private void selectBookmarkType(final String bookmarkType) {
runSwing(() -> nextBookmark.setCurrentActionStateByUserData(bookmarkType));
@@ -610,9 +919,7 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
private Address addInstructions(String addr) throws Exception {
Address address = program.getAddressFactory().getAddress(addr);
-
- int txID = program.startTransaction("Add Test Instruction");
- try {
+ tx(program, () -> {
// these bytes create a couple instructions in x86
Memory memory = program.getMemory();
memory.setBytes(address, new byte[] { 0x55, (byte) 0x8b, (byte) 0xec });
@@ -620,24 +927,17 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
AddressSet set = new AddressSet(address, address.add(4));
DisassembleCommand cmd = new DisassembleCommand(set, set);
cmd.applyTo(program);
- }
- finally {
- program.endTransaction(txID, true);
- }
+ });
return address;
}
private void clearExisingBookmarks() throws Exception {
- int txID = program.startTransaction("Add Test Instruction");
- try {
+ tx(program, () -> {
BookmarkManager bm = program.getBookmarkManager();
AddressSet set = new AddressSet(program.getMemory());
bm.removeBookmarks(set, TaskMonitor.DUMMY);
- }
- finally {
- program.endTransaction(txID, true);
- }
+ });
}
}
diff --git a/Ghidra/Framework/Generic/src/main/java/resources/icons/TranslateIcon.java b/Ghidra/Framework/Generic/src/main/java/resources/icons/TranslateIcon.java
index a53900932e..52e5ed09e3 100644
--- a/Ghidra/Framework/Generic/src/main/java/resources/icons/TranslateIcon.java
+++ b/Ghidra/Framework/Generic/src/main/java/resources/icons/TranslateIcon.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,24 +27,29 @@ public class TranslateIcon implements Icon {
int translateX;
int translateY;
- /** Where the translate values are offset from the icon's upper corner */
+ /**
+ * Where the translate values are offset from the icon's upper corner
+ * @param icon the icon
+ * @param translateX the x translation
+ * @param translateY the y translation
+ */
public TranslateIcon(Icon icon, int translateX, int translateY) {
this.icon = icon;
this.translateX = translateX;
this.translateY = translateY;
}
- /**
- * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
- */
+ @Override
public void paintIcon(Component c, Graphics g, int x, int y) {
icon.paintIcon(c, g, x + translateX, y + translateY);
}
+ @Override
public int getIconHeight() {
return icon.getIconHeight();
}
+ @Override
public int getIconWidth() {
return icon.getIconWidth();
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ListingDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ListingDB.java
index 6f0d329972..7fe4341940 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ListingDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ListingDB.java
@@ -31,12 +31,9 @@ import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.program.model.util.PropertyMap;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
-import ghidra.util.task.TaskMonitorAdapter;
/**
* Database implementation of Listing.
- *
- *
*/
class ListingDB implements Listing {
@@ -45,9 +42,6 @@ class ListingDB implements Listing {
private TreeManager treeMgr;
private FunctionManager functionMgr;
- /**
- * Set the program.
- */
public void setProgram(ProgramDB program) {
this.program = program;
codeMgr = program.getCodeManager();
@@ -55,261 +49,165 @@ class ListingDB implements Listing {
functionMgr = program.getFunctionManager();
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitAt(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getCodeUnitAt(Address addr) {
return codeMgr.getCodeUnitAt(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitContaining(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getCodeUnitContaining(Address addr) {
return codeMgr.getCodeUnitContaining(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitAfter(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getCodeUnitAfter(Address addr) {
return codeMgr.getCodeUnitAfter(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitBefore(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getCodeUnitBefore(Address addr) {
return codeMgr.getCodeUnitBefore(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String)
- */
@Override
public CodeUnitIterator getCodeUnitIterator(String property, boolean forward) {
return codeMgr.getCodeUnitIterator(property, program.getMinAddress(), forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String, ghidra.program.model.address.Address)
- */
@Override
public CodeUnitIterator getCodeUnitIterator(String property, Address addr, boolean forward) {
return codeMgr.getCodeUnitIterator(property, addr, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String, ghidra.program.model.address.AddressSetView)
- */
@Override
public CodeUnitIterator getCodeUnitIterator(String property, AddressSetView addrSet,
boolean forward) {
return codeMgr.getCodeUnitIterator(property, addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnits()
- */
@Override
public CodeUnitIterator getCodeUnits(boolean forward) {
return codeMgr.getCodeUnits(program.getMemory(), forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnits(ghidra.program.model.address.Address)
- */
@Override
public CodeUnitIterator getCodeUnits(Address addr, boolean forward) {
return codeMgr.getCodeUnits(addr, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCodeUnits(ghidra.program.model.address.AddressSetView)
- */
@Override
public CodeUnitIterator getCodeUnits(AddressSetView addrSet, boolean forward) {
return codeMgr.getCodeUnits(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructionAt(ghidra.program.model.address.Address)
- */
@Override
public Instruction getInstructionAt(Address addr) {
return codeMgr.getInstructionAt(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructionContaining(ghidra.program.model.address.Address)
- */
@Override
public Instruction getInstructionContaining(Address addr) {
return codeMgr.getInstructionContaining(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructionAfter(ghidra.program.model.address.Address)
- */
@Override
public Instruction getInstructionAfter(Address addr) {
return codeMgr.getInstructionAfter(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructionBefore(ghidra.program.model.address.Address)
- */
@Override
public Instruction getInstructionBefore(Address addr) {
return codeMgr.getInstructionBefore(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructions()
- */
@Override
public InstructionIterator getInstructions(boolean forward) {
return codeMgr.getInstructions(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructions(ghidra.program.model.address.Address)
- */
@Override
public InstructionIterator getInstructions(Address addr, boolean forward) {
return codeMgr.getInstructions(addr, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getInstructions(ghidra.program.model.address.AddressSetView)
- */
@Override
public InstructionIterator getInstructions(AddressSetView addrSet, boolean forward) {
return codeMgr.getInstructions(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDataAt(ghidra.program.model.address.Address)
- */
@Override
public Data getDataAt(Address addr) {
return codeMgr.getDataAt(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDataContaining(ghidra.program.model.address.Address)
- */
@Override
public Data getDataContaining(Address addr) {
return codeMgr.getDataContaining(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDataAfter(ghidra.program.model.address.Address)
- */
@Override
public Data getDataAfter(Address addr) {
return codeMgr.getDataAfter(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDataBefore(ghidra.program.model.address.Address)
- */
@Override
public Data getDataBefore(Address addr) {
return codeMgr.getDataBefore(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getData()
- */
@Override
public DataIterator getData(boolean forward) {
return codeMgr.getData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getData(ghidra.program.model.address.Address)
- */
@Override
public DataIterator getData(Address addr, boolean forward) {
return codeMgr.getData(addr, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getData(ghidra.program.model.address.AddressSetView)
- */
@Override
public DataIterator getData(AddressSetView addrSet, boolean forward) {
return codeMgr.getData(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedDataAt(ghidra.program.model.address.Address)
- */
@Override
public Data getDefinedDataAt(Address addr) {
return codeMgr.getDefinedDataAt(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedDataContaining(ghidra.program.model.address.Address)
- */
@Override
public Data getDefinedDataContaining(Address addr) {
return codeMgr.getDefinedDataContaining(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedDataAfter(ghidra.program.model.address.Address)
- */
@Override
public Data getDefinedDataAfter(Address addr) {
return codeMgr.getDefinedDataAfter(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedDataBefore(ghidra.program.model.address.Address)
- */
@Override
public Data getDefinedDataBefore(Address addr) {
return codeMgr.getDefinedDataBefore(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedData()
- */
@Override
public DataIterator getDefinedData(boolean forward) {
return codeMgr.getDefinedData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedData(ghidra.program.model.address.Address)
- */
@Override
public DataIterator getDefinedData(Address addr, boolean forward) {
return codeMgr.getDefinedData(addr, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedData(ghidra.program.model.address.AddressSetView)
- */
@Override
public DataIterator getDefinedData(AddressSetView addrSet, boolean forward) {
return codeMgr.getDefinedData(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getUndefinedDataAt(ghidra.program.model.address.Address)
- */
@Override
public Data getUndefinedDataAt(Address addr) {
return codeMgr.getUndefinedAt(addr);
@@ -321,295 +219,190 @@ class ListingDB implements Listing {
return codeMgr.getUndefinedRanges(set, initializedMemoryOnly, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#getUndefinedDataAfter(ghidra.program.model.address.Address)
- */
@Override
public Data getUndefinedDataAfter(Address addr, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedDataAfter(addr, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#getFirstUndefinedData(ghidra.program.model.address.AddressSetView)
- */
@Override
public Data getFirstUndefinedData(AddressSetView set, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedData(set, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#getUndefinedDataBefore(ghidra.program.model.address.Address)
- */
@Override
public Data getUndefinedDataBefore(Address addr, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedDataBefore(addr, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCompositeData()
- */
@Override
public DataIterator getCompositeData(boolean forward) {
return codeMgr.getCompositeData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCompositeData(ghidra.program.model.address.Address)
- */
@Override
public DataIterator getCompositeData(Address start, boolean forward) {
return codeMgr.getCompositeData(start, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCompositeData(ghidra.program.model.address.AddressSetView)
- */
@Override
public DataIterator getCompositeData(AddressSetView addrSet, boolean forward) {
return codeMgr.getCompositeData(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getUserDefinedProperties()
- */
@Override
public Iterator<String> getUserDefinedProperties() {
return codeMgr.getUserDefinedProperties();
}
- /**
- * @see ghidra.program.model.listing.Listing#removeUserDefinedProperty(java.lang.String)
- */
@Override
public void removeUserDefinedProperty(String propertyName) {
codeMgr.removeUserDefinedProperty(propertyName);
}
- /**
- * @see ghidra.program.model.listing.Listing#getPropertyMap(java.lang.String)
- */
@Override
public PropertyMap getPropertyMap(String propertyName) {
return codeMgr.getPropertyMap(propertyName);
}
- /**
- * @see ghidra.program.model.listing.Listing#createInstruction(ghidra.program.model.address.Address, ghidra.program.model.lang.InstructionPrototype, ghidra.program.model.mem.MemBuffer, ghidra.program.model.lang.ProcessorContext)
- */
@Override
public Instruction createInstruction(Address addr, InstructionPrototype prototype,
MemBuffer memBuf, ProcessorContextView context) throws CodeUnitInsertionException {
return codeMgr.createCodeUnit(addr, prototype, memBuf, context);
}
- /**
- * @see ghidra.program.model.listing.Listing#addInstructions(ghidra.program.model.lang.InstructionSet, boolean)
- */
@Override
public AddressSetView addInstructions(InstructionSet instructionSet, boolean overwrite)
throws CodeUnitInsertionException {
return codeMgr.addInstructions(instructionSet, overwrite);
}
- /**
- *
- * @see ghidra.program.model.listing.Listing#createData(ghidra.program.model.address.Address, ghidra.program.model.data.DataType)
- */
@Override
public Data createData(Address addr, DataType dataType)
throws CodeUnitInsertionException, DataTypeConflictException {
return codeMgr.createCodeUnit(addr, dataType, dataType.getLength());
}
- /**
- * @see ghidra.program.model.listing.Listing#createData(ghidra.program.model.address.Address, ghidra.program.model.data.DataType)
- */
@Override
public Data createData(Address addr, DataType dataType, int length)
throws CodeUnitInsertionException, DataTypeConflictException {
return codeMgr.createCodeUnit(addr, dataType, length);
}
- /**
- * @see ghidra.program.model.listing.Listing#clearCodeUnits(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean)
- */
@Override
public void clearCodeUnits(Address startAddr, Address endAddr, boolean clearContext) {
try {
codeMgr.clearCodeUnits(startAddr, endAddr, clearContext,
- TaskMonitorAdapter.DUMMY_MONITOR);
+ TaskMonitor.DUMMY);
}
catch (CancelledException e) {
+ // can't happen with dummy monitor
}
}
- /**
- * @see ghidra.program.model.listing.Listing#clearCodeUnits(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean, ghidra.util.task.TaskMonitor)
- */
@Override
public void clearCodeUnits(Address startAddr, Address endAddr, boolean clearContext,
TaskMonitor monitor) throws CancelledException {
codeMgr.clearCodeUnits(startAddr, endAddr, clearContext, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#isUndefined(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
- */
@Override
public boolean isUndefined(Address start, Address end) {
return codeMgr.isUndefined(start, end);
}
- /**
- * @see ghidra.program.model.listing.Listing#clearComments(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
- */
@Override
public void clearComments(Address startAddr, Address endAddr) {
codeMgr.clearComments(startAddr, endAddr);
}
- /**
- * @see ghidra.program.model.listing.Listing#clearProperties(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
- */
@Override
public void clearProperties(Address startAddr, Address endAddr, TaskMonitor monitor)
throws CancelledException {
codeMgr.clearProperties(startAddr, endAddr, monitor);
}
- /**
- * @see ghidra.program.model.listing.Listing#clearAll(boolean, TaskMonitor)
- */
@Override
public void clearAll(boolean clearContext, TaskMonitor monitor) {
- codeMgr.clearAll(false, TaskMonitorAdapter.DUMMY_MONITOR);
+ codeMgr.clearAll(false, TaskMonitor.DUMMY);
}
- /**
- * @see ghidra.program.model.listing.Listing#getNumCodeUnits()
- */
@Override
public long getNumCodeUnits() {
return getNumDefinedData() + getNumInstructions();
}
- /**
- * @see ghidra.program.model.listing.Listing#getNumDefinedData()
- */
@Override
public long getNumDefinedData() {
return codeMgr.getNumDefinedData();
}
- /**
- * @see ghidra.program.model.listing.Listing#getNumInstructions()
- */
@Override
public long getNumInstructions() {
return codeMgr.getNumInstructions();
}
- /**
- * @see ghidra.program.model.listing.Listing#getFragment(java.lang.String, ghidra.program.model.address.Address)
- */
@Override
public ProgramFragment getFragment(String treeName, Address addr) {
return treeMgr.getFragment(treeName, addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getModule(java.lang.String, java.lang.String)
- */
@Override
public ProgramModule getModule(String treeName, String name) {
return treeMgr.getModule(treeName, name);
}
- /**
- * @see ghidra.program.model.listing.Listing#getFragment(java.lang.String, java.lang.String)
- */
@Override
public ProgramFragment getFragment(String treeName, String name) {
return treeMgr.getFragment(treeName, name);
}
- /**
- * @see ghidra.program.model.listing.Listing#createRootModule(java.lang.String)
- */
@Override
public ProgramModule createRootModule(String treeName) throws DuplicateNameException {
return treeMgr.createRootModule(treeName);
}
- /**
- * @see ghidra.program.model.listing.Listing#getRootModule(java.lang.String)
- */
@Override
public ProgramModule getRootModule(String treeName) {
return treeMgr.getRootModule(treeName);
}
- /**
- * @see ghidra.program.model.listing.Listing#getRootModule(long)
- */
@Override
public ProgramModule getRootModule(long treeID) {
return treeMgr.getRootModule(treeID);
}
- /**
- * @see ghidra.program.model.listing.Listing#getRootModule(long)
- */
@Override
public ProgramModule getDefaultRootModule() {
return treeMgr.getDefaultRootModule();
}
- /**
- * @see ghidra.program.model.listing.Listing#getTreeNames()
- */
@Override
public String[] getTreeNames() {
return treeMgr.getTreeNames();
}
- /**
- * @see ghidra.program.model.listing.Listing#removeTree(java.lang.String)
- */
@Override
public boolean removeTree(String treeName) {
return treeMgr.removeTree(treeName);
}
- /**
- * @see ghidra.program.model.listing.Listing#renameTree(java.lang.String, java.lang.String)
- */
@Override
public void renameTree(String oldName, String newName) throws DuplicateNameException {
treeMgr.renameTree(oldName, newName);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDataTypeManager()
- */
@Override
public DataTypeManager getDataTypeManager() {
return program.getDataTypeManager();
}
- /* (non-Javadoc)
- * @see ghidra.program.model.listing.Listing#createFunction(java.lang.String, ghidra.program.model.address.Address, ghidra.program.model.address.AddressSetView, int)
- */
@Override
public Function createFunction(String name, Address entryPoint, AddressSetView body,
SourceType source) throws InvalidInputException, OverlappingFunctionException {
return functionMgr.createFunction(name, entryPoint, body, source);
}
- /* (non-Javadoc)
- * @see ghidra.program.model.listing.Listing#createFunction(java.lang.String, ghidra.program.model.symbol.Namespace, ghidra.program.model.address.Address, ghidra.program.model.address.AddressSetView, int)
- */
@Override
public Function createFunction(String name, Namespace nameSpace, Address entryPoint,
AddressSetView body, SourceType source)
@@ -617,17 +410,11 @@ class ListingDB implements Listing {
return functionMgr.createFunction(name, nameSpace, entryPoint, body, source);
}
- /**
- * @see ghidra.program.model.listing.Listing#removeFunction(ghidra.program.model.address.Address)
- */
@Override
public void removeFunction(Address entryPoint) {
functionMgr.removeFunction(entryPoint);
}
- /**
- * @see ghidra.program.model.listing.Listing#getFunctionAt(ghidra.program.model.address.Address)
- */
@Override
public Function getFunctionAt(Address entryPoint) {
return functionMgr.getFunctionAt(entryPoint);
@@ -662,9 +449,6 @@ class ListingDB implements Listing {
return list;
}
- /**
- * @see ghidra.program.model.listing.Listing#getFirstFunctionContaining(ghidra.program.model.address.Address)
- */
@Override
public Function getFunctionContaining(Address addr) {
return functionMgr.getFunctionContaining(addr);
@@ -675,90 +459,57 @@ class ListingDB implements Listing {
return functionMgr.getExternalFunctions();
}
- /**
- * @see ghidra.program.model.listing.Listing#getFunctions(boolean)
- */
@Override
public FunctionIterator getFunctions(boolean forward) {
return functionMgr.getFunctions(forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getFunctions(ghidra.program.model.address.Address, boolean)
- */
@Override
public FunctionIterator getFunctions(Address start, boolean forward) {
return functionMgr.getFunctions(start, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getFunctions(ghidra.program.model.address.AddressSetView, boolean)
- */
@Override
public FunctionIterator getFunctions(AddressSetView asv, boolean forward) {
return functionMgr.getFunctions(asv, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#isInFunction(ghidra.program.model.address.Address)
- */
@Override
public boolean isInFunction(Address addr) {
return functionMgr.isInFunction(addr);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCommentHistory(ghidra.program.model.address.Address, int)
- */
@Override
public CommentHistory[] getCommentHistory(Address addr, int commentType) {
return codeMgr.getCommentHistory(addr, commentType);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCommentCodeUnitIterator(int, ghidra.program.model.address.AddressSetView)
- */
@Override
public CodeUnitIterator getCommentCodeUnitIterator(int commentType, AddressSetView addrSet) {
return codeMgr.getCommentCodeUnitIterator(commentType, addrSet);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCommentAddressIterator(int, ghidra.program.model.address.AddressSetView, boolean)
- */
@Override
public AddressIterator getCommentAddressIterator(int commentType, AddressSetView addrSet,
boolean forward) {
return codeMgr.getCommentAddressIterator(commentType, addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getCommentAddressIterator(ghidra.program.model.address.AddressSetView, boolean)
- */
@Override
public AddressIterator getCommentAddressIterator(AddressSetView addrSet, boolean forward) {
return codeMgr.getCommentAddressIterator(addrSet, forward);
}
- /**
- * @see ghidra.program.model.listing.Listing#getComment(int, ghidra.program.model.address.Address)
- */
@Override
public String getComment(int commentType, Address address) {
return codeMgr.getComment(commentType, address);
}
- /**
- * @see ghidra.program.model.listing.Listing#setComment(ghidra.program.model.address.Address, int, java.lang.String)
- */
@Override
public void setComment(Address address, int commentType, String comment) {
codeMgr.setComment(address, commentType, comment);
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedCodeUnitAfter(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getDefinedCodeUnitAfter(Address addr) {
CodeUnit data = codeMgr.getDefinedDataAfter(addr);
@@ -777,9 +528,6 @@ class ListingDB implements Listing {
return inst;
}
- /**
- * @see ghidra.program.model.listing.Listing#getDefinedCodeUnitBefore(ghidra.program.model.address.Address)
- */
@Override
public CodeUnit getDefinedCodeUnitBefore(Address addr) {
CodeUnit data = codeMgr.getDefinedDataBefore(addr);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/bookmark/BookmarkDBManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/bookmark/BookmarkDBManager.java
index f5529f1e20..e39f2cb999 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/bookmark/BookmarkDBManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/bookmark/BookmarkDBManager.java
@@ -50,7 +50,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
private boolean upgrade = false;
- private Map<String, BookmarkType> typesByName = new TreeMap<String, BookmarkType>();
+ private Map<String, BookmarkType> typesByName = new TreeMap<>();
private ObjectArray typesArray = new ObjectArray();
private Lock lock;
@@ -73,7 +73,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
bookmarkTypeAdapter = BookmarkTypeDBAdapter.getAdapter(handle, openMode);
int[] types = bookmarkTypeAdapter.getTypeIds();
bookmarkAdapter = BookmarkDBAdapter.getAdapter(handle, openMode, types, addrMap, monitor);
- cache = new DBObjectCache<BookmarkDB>(100);
+ cache = new DBObjectCache<>(100);
}
@Override
@@ -388,16 +388,6 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
- boolean isSpecificType = type != null && type != BookmarkType.ALL_TYPES;
- if (!isSpecificType) {
- // no type specified; remove all
- Iterator<String> iter = typesByName.keySet().iterator();
- while (iter.hasNext()) {
- removeBookmarks(iter.next());
- }
- return;
- }
-
try {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesByName.get(type);
if (bmt.hasBookmarks()) {
@@ -474,7 +464,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
int n = typesArray.getLastNonEmptyIndex();
- List<Bookmark> list = new ArrayList<Bookmark>();
+ List<Bookmark> list = new ArrayList<>();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);
if (bmt != null && bmt.hasBookmarks()) {
@@ -512,7 +502,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
Bookmark[] bookmarks = null;
- List<Bookmark> list = new ArrayList<Bookmark>();
+ List<Bookmark> list = new ArrayList<>();
BookmarkType bmt = getBookmarkType(type);
if (bmt != null && bmt.hasBookmarks()) {
getBookmarks(address, bmt.getTypeId(), list);
@@ -681,18 +671,18 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
@Override
public Iterator<Bookmark> getBookmarksIterator(Address startAddress, boolean forward) {
- List<PeekableIterator<Bookmark>> list = new ArrayList<PeekableIterator<Bookmark>>();
+ List<PeekableIterator<Bookmark>> list = new ArrayList<>();
int n = typesArray.getLastNonEmptyIndex();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);
if (bmt != null && bmt.hasBookmarks()) {
Iterator<Bookmark> bookmarksIterator =
getBookmarksIterator(startAddress, bmt, forward);
- list.add(new WrappingPeekableIterator<Bookmark>(bookmarksIterator));
+ list.add(new WrappingPeekableIterator<>(bookmarksIterator));
}
}
- return new MultiIterator<Bookmark>(list, forward);
+ return new MultiIterator<>(list, forward);
}
@Override
@@ -880,7 +870,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
Iterator<Bookmark> bookmarkIt;
TotalIterator() {
- List<BookmarkTypeDB> list = new ArrayList<BookmarkTypeDB>();
+ List<BookmarkTypeDB> list = new ArrayList<>();
int n = typesArray.getLastNonEmptyIndex();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java
index 2c212452bb..b93d85e7a5 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java
@@ -15,9 +15,8 @@
*/
package ghidra.program.database.code;
-import java.util.*;
-
import java.io.IOException;
+import java.util.*;
import db.*;
import db.util.ErrorHandler;
@@ -40,11 +39,9 @@ import ghidra.program.util.ChangeManager;
import ghidra.util.*;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
-import ghidra.util.task.TaskMonitorAdapter;
/**
* Class to manage database tables for data and instructions.
- *
*/
public class CodeManager implements ErrorHandler, ManagerDB {
@@ -83,8 +80,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* @param openMode either READ_ONLY, UPDATE, or UPGRADE
* @param lock the program synchronization lock
* @param monitor the task monitor use while upgrading.
- * @throws VersionException if the database is incompatible with the current
- * schema
+ * @throws VersionException if the database is incompatible with the current schema
* @throws IOException if a database io error occurs
* @throws CancelledException if the user cancels the upgrade operation
*/
@@ -107,15 +103,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Check for old fall-through/fall-from property maps.
- * These maps were never fully supported so we do not support the read-only mode,
- * however we will support an upgrade of this data which is now stored as FALL_THROUGH References.
- * @param handle
- * @param openMode
- * @param monitor
- * @throws VersionException
- * @throws CancelledException
- * @throws IOException
+ * Check for old fall-through/fall-from property maps. These maps were never fully supported
+ * so we do not support the read-only mode, however we will support an upgrade of this data
+ * which is now stored as FALL_THROUGH References.
+ * @param handle handle to database
+ * @param openMode either READ_ONLY, UPDATE, or UPGRADE
+ * @param monitor the task monitor use while upgrading.
+ * @throws VersionException if the database is incompatible with the current schema
+ * @throws IOException if a database io error occurs
+ * @throws CancelledException if the user cancels the upgrade operation
*/
private void checkOldFallThroughMaps(DBHandle handle, int openMode, TaskMonitor monitor)
throws VersionException, CancelledException, IOException {
@@ -132,11 +128,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
- /**
+ /*
* Convert old fall-through overrides into References.
- * @param monitor
- * @throws CancelledException
- * @throws IOException
*/
private void upgradeOldFallThroughMaps(TaskMonitor monitor)
throws CancelledException, IOException {
@@ -231,9 +224,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
protoMgr.setProgram(program);
}
- /**
- * @see ghidra.program.database.ManagerDB#programReady(int, int, ghidra.util.task.TaskMonitor)
- */
@Override
public void programReady(int openMode, int currentRevision, TaskMonitor monitor)
throws IOException, CancelledException {
@@ -248,9 +238,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
- /**
- * @see db.util.ErrorHandler#dbError(java.io.IOException)
- */
@Override
public void dbError(IOException e) {
program.dbError(e);
@@ -337,13 +324,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
if (protoInstr.isInDelaySlot() != inst.isInDelaySlot() &&
inst.getLength() == protoInstr.getLength()) {
if (protoInstr.isInDelaySlot()) {
- // overwrite conflicting instruction in delay slot - ignore conflict and resume,
- // no need to remove context since this will happen when instruction is added
+ // overwrite conflicting instruction in delay slot - ignore
+ // conflict and resume, no need to remove context since this will
+ // happen when instruction is added
clearCodeUnits(inst.getMinAddress(), inst.getMinAddress(), false,
- TaskMonitorAdapter.DUMMY_MONITOR);
+ TaskMonitor.DUMMY);
}
else {
- // Likely caused by odd flow into delay slot - assume OK - skip prototype and resume
+ // Likely caused by odd flow into delay slot - assume OK - skip
+ // prototype and resume
skipDelaySlots.add(startAddr); // keep existing delay slot instruction
}
try {
@@ -392,11 +381,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Creates a complete set of instructions.
- * A preliminary pass will be made checking for code unit conflicts which will be
- * marked within the instructionSet causing dependent blocks to get pruned.
- * @param instructionSet the set of instructions to be added. All code unit conflicts
- * will be marked within the instructionSet and associated blocks.
+ * Creates a complete set of instructions. A preliminary pass will be made checking for code
+ * unit conflicts which will be marked within the instructionSet causing dependent blocks to
+ * get pruned.
+ * @param instructionSet the set of instructions to be added. All code unit conflicts will be
+ * marked within the instructionSet and associated blocks.
+ * @param overwrite if true, overwrites existing code units.
+ * @return the set of addresses over which instructions were actually added to the program.
+ * This may differ from the InstructionSet address set if conflict errors occurred. Such
+ * conflict errors will be recorded within the InstructionSet and its InstructionBlocks.
*/
public AddressSetView addInstructions(InstructionSet instructionSet, boolean overwrite) {
AddressSet set = new AddressSet();
@@ -407,19 +400,17 @@ public class CodeManager implements ErrorHandler, ManagerDB {
HashSet<Address> skipDelaySlots = new HashSet<>();
if (overwrite) {
- // Clear memory which corresponds to all code blocks
- // no need to remove context since this will happen when instruction is added
+ // Clear memory which corresponds to all code blocks. No need to remove context
+ // since this will happen when instruction is added
for (AddressRange range : instructionSet.getAddressSet()) {
clearCodeUnits(range.getMinAddress(), range.getMaxAddress(), false,
- TaskMonitorAdapter.DUMMY_MONITOR);
+ TaskMonitor.DUMMY);
}
}
else {
- // Check for conflicts with existing instructions,
- // Clear locations where delay-slots will be replacing
- // non-delay slot. The skipDelaySlots set will
- // be filled-in with any existing delay slot locations
- // which should not be overwritten
+ // Check for conflicts with existing instructions, clear locations where
+ // delay-slots will be replacing non-delay slot. The skipDelaySlots set will be
+ // filled-in with any existing delay slot locations which should not be overwritten
checkInstructionSet(instructionSet, skipDelaySlots);
}
@@ -497,7 +488,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
// skip instruction if we are attempting to lay down a non-delay slot prototype
// onto an existing delay slot instruction although we need to continue
// processing subsequent instructions
-
if (!skipDelaySlots.contains(startAddr)) {
if (!program.getMemory().contains(startAddr, endAddr)) {
@@ -590,7 +580,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* @param prototype instruction definition object
* @param memBuf the MemBuffer to use to get the bytes from memory
* @param context object that has the state of all the registers.
- *
+ * @return the new instruction
* @exception CodeUnitInsertionException thrown if code unit
* overlaps with an existing code unit
*/
@@ -671,10 +661,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
InstructionDB inst = new InstructionDB(this, cache, address, addr, prototype, flags);
addReferencesForInstruction(inst);
-// if (unlockedContextSet != null) {
-// unlockedContextSet.addRange(address, inst.getMaxAddress());
-// }
-
return inst;
}
@@ -688,19 +674,19 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Removes the block of defined bytes from the listing. All necessary checks will
- * be made by listing before this method is called, so just do the work.
+ * Removes the block of defined bytes from the listing. All necessary checks will be made by
+ * listing before this method is called, so just do the work.
* @param start the first address in the range.
* @param end the last address in the range.
- * @param monitor the TaskMonitor that tracks progress and is used to tell
- * if the user cancels the operation.
+ * @param monitor the TaskMonitor that tracks progress and is used to tell if the user cancels
+ * the operation.
* @throws CancelledException if the user cancels the operation.
*/
@Override
public void deleteAddressRange(Address start, Address end, TaskMonitor monitor)
throws CancelledException {
- // Expand range to include any overlaping or delay-slotted instructions
+ // Expand range to include any overlapping or delay-slotted instructions
CodeUnit cu = getCodeUnitContaining(start);
if (cu != null) {
start = cu.getMinAddress();
@@ -712,13 +698,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Removes the block of defined code units from the listing. All necessary checks will
- * be made by listing before this method is called, so just do the work.
+ * Removes the block of defined code units from the listing. All necessary checks will be made
+ * by listing before this method is called, so just do the work.
* @param start the first address in the range.
* @param end the last address in the range.
* @param keepComments if true comment and comment history will be retained
- * @param monitor the TaskMonitor that tracks progress and is used to tell
- * if the user cancels the operation.
+ * @param monitor the TaskMonitor that tracks progress and is used to tell if the user cancels
+ * the operation.
* @throws CancelledException if the user cancels the operation.
*/
private void deleteAddressRange(Address start, Address end, boolean keepComments,
@@ -757,13 +743,14 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Move a block of code from one address to a new address.
+ * <P>
* Updates all property managers, symbols, and references.
*
* @param fromAddr the first address in the range to be moved.
* @param toAddr the address to move to.
* @param length the number of addresses to move.
- * @param monitor the TaskMonitor that tracks progress and is used to tell
- * if the user cancels the operation.
+ * @param monitor the TaskMonitor that tracks progress and is used to tell if the user cancels
+ * the operation.
* @throws CancelledException if the user cancels the operation.
*/
@Override
@@ -793,24 +780,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
-// private int getOffsetSize(Register[] regs) {
-// int size = 0;
-// for(int i=0;i<regs.length;i++) {
-// if (regs[i].getOffset()+regs[i].getSize() > size) {
-// size = regs[i].getOffset()+regs[i].getSize();
-// }
-// }
-// return size;
-// }
-
/**
- * Returns the code unit whose min address equals
- * the specified address.
+ * Returns the code unit whose min address equals the specified address.
*
- * @param address the min address of the code unit to return
- *
- * @return CodeUnit the code unit at the specified address,
- * or null if a code unit does not exist
+ * @param address the min address of the code unit to return
+ * @return CodeUnit the code unit at the specified address, or null if a code unit does not
+ * exist
*/
public CodeUnit getCodeUnitAt(Address address) {
long addr = addrMap.getKey(address, false);
@@ -869,13 +844,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next code unit whose min address is greater
- * than the specified address.
+ * Returns the next code unit whose min address is greater than the specified address.
*
* @param addr the address to look after
*
- * @return CodeUnit the code unit after the specified address,
- * or null if a code unit does not exist
+ * @return CodeUnit the code unit after the specified address, or null if a code unit does not
+ * exist
*/
public CodeUnit getCodeUnitAfter(Address addr) {
lock.acquire();
@@ -910,8 +884,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Removes the user-defined property with the
- * specified property name.
+ * Removes the user-defined property with the specified property name.
*
* @param propertyName the name of the user-defined property to remove
*/
@@ -920,12 +893,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the property map object that is associated
- * with the specified property name.
+ * Returns the property map object that is associated with the specified property name.
*
- * @param propertyName the name of the property
+ * @param propertyName the name of the property
*
- * @return PropertyMap the property map object associated to the property name
+ * @return the property map object associated to the property name
*/
public PropertyMap getPropertyMap(String propertyName) {
return propertyMapMgr.getPropertyMap(propertyName);
@@ -953,13 +925,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next code unit whose min address is
- * closest to and less than the specified address.
+ * Returns the next code unit whose min address is closest to and less than the specified
+ * address.
*
* @param address the address to look before
- *
- * @return CodeUnit the code unit before the specified address,
- * or null if a code unit does not exist
+ * @return CodeUnit the code unit before the specified address, or null if a code unit does not
+ * exist
*/
public CodeUnit getCodeUnitBefore(Address address) {
lock.acquire();
@@ -992,17 +963,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the code unit whose min address is less than
- * or equal to the specified address and whose max address
- * is greater than or equal to the specified address.
+ * Returns the code unit whose min address is less than or equal to the specified address and
+ * whose max address is greater than or equal to the specified address.
* <pre>{@literal
* codeunit.minAddress() <= addr <= codeunit.maxAddress()
* }</pre>
*
* @param address the address for which to find the code containing it.
- *
- * @return CodeUnit the code unit containing the specified address,
- * or null if a code unit does not exist
+ * @return CodeUnit the code unit containing the specified address, or null if a code unit does
+ * not exist.
*/
public CodeUnit getCodeUnitContaining(Address address) {
lock.acquire();
@@ -1074,13 +1043,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Get an iterator that contains the code units which have the specified
- * property type defined. Only code units at an address greater than or
- * equal to the specified start address will be returned by the iterator.
- * If the start address is null then check the entire program.
- * <br>
- * Standard property types are defined in the CodeUnit class.
- * The property types are:
+ * Get an iterator that contains the code units which have the specified property type defined.
+ * Only code units at an address greater than or equal to the specified start address will be
+ * returned by the iterator. If the start address is null then check the entire program.
+ * <P>
+ * Standard property types are defined in the CodeUnit class. The property types are:
* <ul>
* <li>COMMENT_PROPERTY</li>
* <li>INSTRUCTION_PROPERTY</li>
@@ -1088,12 +1055,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* </ul>
* Property types can also be user defined.
*
- * @param property the name of the user defined property type or special standard name from above.
+ * @param property the name of the user defined property type or special standard name from
+ * above.
* @param address the address to start the iterator, or null to iterator the entire program
* @param forward true means get iterator in the forward direction
*
- * @return a CodeUnitIterator that returns all code units from the indicated
- * start address that have the specified property type defined.
+ * @return a CodeUnitIterator that returns all code units from the indicated start address that
+ * have the specified property type defined.
*/
public CodeUnitIterator getCodeUnitIterator(String property, Address address, boolean forward) {
if (program.getMemory().isEmpty()) {
@@ -1150,13 +1118,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Get an iterator that contains the code units which have the specified
- * property type defined. Only code units starting within the address set
- * specified will be returned by the iterator.
+ * Get an iterator that contains the code units which have the specified property type defined.
+ * Only code units starting within the address set specified will be returned by the iterator.
* If the address set is null then check the entire program.
* <br>
- * Standard property types are defined in the CodeUnit class.
- * The property types are:
+ * Standard property types are defined in the CodeUnit class. The property types are:
* <ul>
* <li>REFERENCE_PROPERTY</li>
* <li>INSTRUCTION_PROPERTY</li>
@@ -1167,8 +1133,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* @param property the name of the property type, or this can be user defined.
* @param addrSetView the address set to iterate, or null to iterate over the entire program
* @param forward true means the iterator is in the forward direction
- * @return a CodeUnitIterator that returns all code units from the indicated
- * address set that have the specified property type defined.
+ * @return a CodeUnitIterator that returns all code units from the indicated address set that
+ * have the specified property type defined.
*/
public CodeUnitIterator getCodeUnitIterator(String property, AddressSetView addrSetView,
boolean forward) {
@@ -1260,6 +1226,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* Get an iterator over addresses that have comments of any type.
* @param addrSet address set containing the comment addresses to iterate over.
* @param forward true to iterate in the direction of increasing addresses.
+ * @return the iterator
*/
public AddressIterator getCommentAddressIterator(AddressSetView addrSet, boolean forward) {
if (addrSet != null && addrSet.isEmpty()) {
@@ -1276,15 +1243,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the instruction whose min address equals
- * the specified address or null if the address is not the beginning address
- * of some codeunit.
+ * Returns the instruction whose min address equals the specified address or null if the
+ * address is not the beginning address of some code unit.
*
* @param address the min address of the instruction to return
*
- * @return CodeUnit the instruction at the specified address,
- * or null if a instruction does not exist starting at the
- * given address.
+ * @return the instruction at the specified address, or null if a instruction does not
+ * exist starting at the given address.
*/
public Instruction getInstructionAt(Address address) {
return getInstructionAt(addrMap.getKey(address, false));
@@ -1314,13 +1279,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the defined data whose min address equals
- * the specified address.
- *
- * @param address the min address of the data defined to return
+ * Returns the defined data whose min address equals the specified address.
*
- * @return CodeUnit the defined data at the specified address,
- * or null if a defined data does not exist
+ * @param address the min address of the data defined to return
+ * @return the defined data at the specified address, or null if a defined data does
+ * not exist
*/
public Data getDefinedDataAt(Address address) {
return getDefinedDataAt(addrMap.getKey(address, false));
@@ -1353,13 +1316,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next instruction whose min address is
- * closest to and less than the specified address.
+ * Returns the next instruction whose min address is closest to and less than the specified
+ * address.
*
- * @param addr the address to look before
- *
- * @return Instruction the instruction before the specified address,
- * or null if a instruction does not exist
+ * @param addr the address to look before
+ * @return the instruction before the specified address, or null if a instruction
+ * does not exist
*/
public Instruction getInstructionBefore(Address addr) {
lock.acquire();
@@ -1377,13 +1339,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next instruction whose min address is greater
- * than the specified address.
+ * Returns the next instruction whose min address is greater than the specified address.
*
* @param addr the address to look after
- *
- * @return Instruction the instruction after the specified address,
- * or null if a instruction does not exist
+ * @return the instruction after the specified address, or null if a instruction
+ * does not exist
*/
public Instruction getInstructionAfter(Address addr) {
lock.acquire();
@@ -1401,17 +1361,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the instruction whose min address is less than
- * or equal to the specified address and whose max address
- * is greater than or equal to the specified address.
+ * Returns the instruction whose min address is less than or equal to the specified address and
+ * whose max address is greater than or equal to the specified address.
* <pre>{@literal
* instruction.minAddress() <= addr <= instruction.maxAddress()
* }</pre>
*
- * @param address the address to be contained
- *
- * @return Instruction the instruction containing the specified address,
- * or null if a instruction does not exist
+ * @param address the address to be contained
+ * @return the instruction containing the specified address, or null if a
+ * instruction does not exist
*/
public Instruction getInstructionContaining(Address address) {
lock.acquire();
@@ -1435,13 +1393,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the data whose min address equals
- * the specified address.
+ * Returns the data whose min address equals the specified address.
*
- * @param address the min address of the data to return
- *
- * @return Data the data at the specified address,
- * or null if data does not exist
+ * @param address the min address of the data to return
+ * @return the data at the specified address, or null if data does not exist
*/
public Data getDataAt(Address address) {
return getDataAt(address, addrMap.getKey(address, false));
@@ -1469,13 +1424,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next data whose min address is
- * closest to and less than the specified address.
+ * Returns the next data whose min address is closest to and less than the specified address.
*
* @param addr the address to look before
- *
- * @return Data the data before the specified address,
- * or null if a data does not exist
+ * @return the data before the specified address, or null if a data does not exist
*/
public Data getDataBefore(Address addr) {
CodeUnitIterator it = getCodeUnits(addr, false);
@@ -1495,13 +1447,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next data whose min address is greater
- * than the specified address.
- *
- * @param addr the address to look after
- *
- * @return Data the data after the specified address,
- * or null if a data does not exist
+ * Returns the next data whose min address is greater than the specified address.
+ *
+ * @param addr the address to look after
+ * @return the data after the specified address, or null if a data does not exist
*/
public Data getDataAfter(Address addr) {
CodeUnitIterator it = getCodeUnits(addr, true);
@@ -1517,30 +1466,16 @@ public class CodeManager implements ErrorHandler, ManagerDB {
return null;
}
-// private int getDataLength(Record rec) {
-// DataType dt = dataManager.getDataType(rec.getLongValue(DataDBAdapter.DATA_TYPE_ID_COL));
-// if (dt.getLength() < 0) {
-// try {
-// return lengthMgr.getInt(addrMap.decodeAddress(rec.getKey()));
-// } catch (NoValueException e) {
-// }
-// }
-// return dt.getLength();
-// }
-
/**
- * Returns the data whose min address is less than
- * or equal to the specified address and whose max address
- * is greater than or equal to the specified address.
+ * Returns the data whose min address is less than or equal to the specified address and whose
+ * max address is greater than or equal to the specified address.
* <pre>{@literal
* data.minAddress() <= addr <= data.maxAddress()
* }</pre>
*
* @param addr the address to be contained
- *
- * @return Data the data containing the specified address,
- * or null if a data does not exist that starts at that
- * address.
+ * @return the data containing the specified address, or null if a data does not exist that
+ * starts at that address.
*/
public Data getDataContaining(Address addr) {
CodeUnit cu = getCodeUnitContaining(addr);
@@ -1551,13 +1486,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next defined data whose min address is greater
- * than the specified address.
+ * Returns the next defined data whose min address is greater than the specified address.
*
* @param addr the address to look after
- *
- * @return Data the defined data after the specified address,
- * or null if a defined data does not exist
+ * @return the defined data after the specified address, null if a defined data does not exist
*/
public Data getDefinedDataAfter(Address addr) {
lock.acquire();
@@ -1576,13 +1508,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next defined data whose min address is
- * closest to and less than the specified address.
+ * Returns the next defined data whose min address is closest to and less than the specified
+ * address.
*
* @param addr the address to look before
- *
- * @return Data the defined data before the specified address,
- * or null if a defined data does not exist
+ * @return the defined data before the specified address, null if a defined data does not exist
*/
public Data getDefinedDataBefore(Address addr) {
lock.acquire();
@@ -1600,17 +1530,14 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the defined data whose min address is less than
- * or equal to the specified address and whose max address
- * is greater than or equal to the specified address.
+ * Returns the defined data whose min address is less than or equal to the specified address
+ * and whose max address is greater than or equal to the specified address.
* <pre>{@literal
* data.minAddress() <= addr <= data.maxAddress()
* }</pre>
*
* @param addr the address to be contained
- *
- * @return Data the defined data containing the specified address,
- * or null if a defined data does not exist
+ * @return the defined data containing the address, null if a defined data does not exist
*/
public Data getDefinedDataContaining(Address addr) {
lock.acquire();
@@ -1637,9 +1564,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
TaskMonitor monitor) throws CancelledException {
lock.acquire();
try {
- if (monitor == null) {
- monitor = TaskMonitorAdapter.DUMMY_MONITOR;
- }
+
+ monitor = TaskMonitor.dummyIfNull(monitor);
Memory mem = program.getMemory();
AddressSet searchSet;
if (set == null) {
@@ -1756,7 +1682,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
nextInstAddr = null; // consumed
}
else {
- nextDataAddr = null; // consumed;
+ nextDataAddr = null; // consumed
}
//
@@ -1782,13 +1708,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the undefined data whose min address equals
- * the specified address.
- *
- * @param address the min address of the undefined data to return
+ * Returns the undefined data whose min address equals the specified address.
*
- * @return Data the undefined data at the specified address,
- * or null if undefined data does not exist
+ * @param address the min address of the undefined data to return
+ * @return Data the undefined data at the address, null if undefined data does not exist
*/
public Data getUndefinedAt(Address address) {
return getUndefinedAt(address, addrMap.getKey(address, false));
@@ -1838,13 +1761,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next undefined data whose min address is greater
- * than the specified address.
+ * Returns the next undefined data whose min address is greater than the specified address.
*
* @param addr the address to look after
- *
- * @return Data the undefined data after the specified address,
- * or null if a undefined data does not exist
+ * @param monitor the task monitor
+ * @return Data the undefined data after the address, null if a undefined data does not exist
*/
public Data getFirstUndefinedDataAfter(Address addr, TaskMonitor monitor) {
if (!addr.isMemoryAddress() || addr.equals(addr.getAddressSpace().getMaxAddress())) {
@@ -1869,12 +1790,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next undefined data whose min address falls within the address set
- * searching in the forward direction {@code (e.g., 0 -> 0xfff).}
+ * Returns the next undefined data whose min address falls within the address set searching in
+ * the forward direction {@code (e.g., 0 -> 0xfff).}
*
* @param set the address set to look within (required).
* @param monitor the current monitor.
- * @return Data the first undefined data within the address set, or null if there is none.
+ * @return the first undefined data within the address set, or null if there is none.
*/
public Data getFirstUndefinedData(AddressSetView set, TaskMonitor monitor) {
if (set.isEmpty()) {
@@ -1901,13 +1822,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns the next undefined data whose min address is
- * closest to and less than the specified address.
+ * Returns the next undefined data whose min address is closest to and less than the specified
+ * address.
*
* @param addr the address to look before
- *
- * @return Data the undefined data before the specified address,
- * or null if a undefined data does not exist
+ * @param monitor the task monitor
+ * @return the undefined data before the address, null if a undefined data does not exist
*/
public Data getFirstUndefinedDataBefore(Address addr, TaskMonitor monitor) {
if (!addr.isMemoryAddress() || addr.getOffset() == 0) {
@@ -1982,12 +1902,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Creates a data at the specified address.
*
- * @param addr
- * Starting address of code unit
- * @param dataType
- * data prototype for the code unit
- * @exception CodeUnitInsertionException
- * thrown if code unit overlaps with an existing code unit
+ * @param addr Starting address of code unit
+ * @param dataType data prototype for the code unit
+ * @param length the data length
+ * @return the data
+ * @exception CodeUnitInsertionException if the code unit overlaps with an existing code unit
*/
public Data createCodeUnit(Address addr, DataType dataType, int length)
throws CodeUnitInsertionException {
@@ -2095,10 +2014,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Update the data references on this data item.
- * Get rid of any references first, then add in any new ones.
+ * Update the data references on this data item. Get rid of any references first, then add in
+ * any new ones.
*
- * @param data the data object to be updated
+ * @param data the data object to be updated
*/
public void updateDataReferences(Data data) {
lock.acquire();
@@ -2112,8 +2031,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Add in any references from pointer data types found in a data item.
- * We don't create refs for 0 or all f's.
+ * Add in any references from pointer data types found in a data item. We don't create refs
+ * for 0 or all f's.
* @param data the data to add references for.
* @param longSegmentAddressList used internally to make sure that, for 64 bit addresses, we
* don't pollute the the addressMap segment table when creating arrays of pointers on arbitrary
@@ -2220,8 +2139,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Clears all comments in the given range (inclusive).
*
- * @param start the start address of the range to clear
- * @param end the end address of the range to clear
+ * @param start the start address of the range to clear
+ * @param end the end address of the range to clear
*/
public void clearComments(Address start, Address end) {
lock.acquire();
@@ -2232,7 +2151,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
catch (IOException e) {
program.dbError(e);
}
- // cache.invalidate(startAddr, endAddr);
+
cache.invalidate();
try {
boolean commentRemoved = commentAdapter.deleteRecords(start, end);
@@ -2253,8 +2172,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Clears the properties in the given range (inclusive).
*
- * @param start the start address of the range to clear
- * @param end the end address of the range to clear
+ * @param start the start address of the range to clear
+ * @param end the end address of the range to clear
+ * @param monitor the task monitor
+ * @throws CancelledException if cancelled
*/
public void clearProperties(Address start, Address end, TaskMonitor monitor)
throws CancelledException {
@@ -2310,29 +2231,29 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Remove code units, symbols, equates, and references to
- * code units in the given range (inclusive). Comments
- * and comment history will be retained.
- * @param start the start address of the range to clear
- * @param end the end address of the range to clear
+ * Remove code units, symbols, equates, and references to code units in the given range
+ * (inclusive). Comments and comment history will be retained.
+ * @param start the start address of the range to clear
+ * @param end the end address of the range to clear
* @param clearContext if true all context-register values will be cleared over range
- * @param monitor the TaskMonitor that tracks progress and is used to tell
- * if the user cancels the operation.
+ * @param monitor the task monitor
+ * @throws CancelledException if cancelled
*/
public void clearCodeUnits(Address start, Address end, boolean clearContext,
TaskMonitor monitor) throws CancelledException {
lock.acquire();
try {
- // Expand range to include any overlaping or delay-slotted instructions
+ // Expand range to include any overlapping or delay-slotted instructions
CodeUnit cu = getCodeUnitContaining(start);
if (cu != null) {
start = cu.getMinAddress();
}
+
start = adjustStartForDelaySlot(start);
end = adjustEndForDelaySlot(end);
refManager.removeAllReferencesFrom(start, end);
-// program.getProgramContext().deleteAddressRange(start, end, monitor);
+
equateTable.deleteAddressRange(start, end, monitor);
dataManager.deleteAddressRange(start, end, monitor);
deleteAddressRange(start, end, true, monitor); // this invalidates the cache
@@ -2355,6 +2276,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Clear all code units in the program.
+ * @param clearContext true to clear the context
+ * @param monitor the task monitor
*/
public void clearAll(boolean clearContext, TaskMonitor monitor) {
Address minAddr = program.getMinAddress();
@@ -2369,6 +2292,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Returns the number of instructions in the program.
+ * @return the number of instructions in the program.
*/
public int getNumInstructions() {
try {
@@ -2382,6 +2306,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Returns the number of defined data in the program.
+ * @return the number of defined data in the program.
*/
public int getNumDefinedData() {
try {
@@ -2394,13 +2319,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns a composite data iterator beginning at the specified
- * start address.
+ * Returns a composite data iterator beginning at the specified start address.
*
* @param start the address to begin iterator
* @param forward true means get iterator in forward direction
- *
- * @return DataIterator the composite data iterator
+ * @return the composite data iterator
*/
public DataIterator getCompositeData(Address start, boolean forward) {
try {
@@ -2414,12 +2337,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns a composite data iterator limited to the addresses
- * in the specified address set.
+ * Returns a composite data iterator limited to the addresses in the specified address set.
*
* @param addrSet the address set to limit the iterator
- * @param forward determines if the iterator will go from the lowest address to
- * the highest or the other way around.
+ * @param forward determines if the iterator will go from the lowest address to the highest or
+ * the other way around.
* @return DataIterator the composite data iterator
*/
public DataIterator getCompositeData(AddressSetView addrSet, boolean forward) {
@@ -2434,13 +2356,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all codeUnits in the program from the given
- * start address to either the end address or the start address, depending if
- * the iterator is forward or not.
+ * Returns an iterator over all codeUnits in the program from the given start address to either
+ * the end address or the start address, depending if the iterator is forward or not.
* @param start the starting address for the iterator.
- * @param forward if true the iterator returns all codeUnits from the given
- * start address to the end of the program, otherwise it returns all codeUnits
- * from the given start address to the start of the program.
+ * @param forward if true the iterator returns all codeUnits from the given start address to
+ * the end of the program, otherwise it returns all codeUnits from the given start address to
+ * the start of the program.
* @return code unit iterator
*/
public CodeUnitIterator getCodeUnits(Address start, boolean forward) {
@@ -2471,12 +2392,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all codeUnits in the given addressSet. The iterator
- * will go from the lowest address to the largest or from the largest to the
- * lowest depending on the forward parameter.
+ * Returns an iterator over all codeUnits in the given addressSet. The iterator will go from
+ * the lowest address to the largest or from the largest to the lowest depending on the forward
+ * parameter.
* @param set the memory address set over which code units should be iterated (required)
- * @param forward determines if the iterator goes from lowest address to highest
- * or the other way around.
+ * @param forward determines if the iterator goes from lowest address to highest or the other
+ * way around.
* @return code unit iterator
*/
public CodeUnitIterator getCodeUnits(AddressSetView set, boolean forward) {
@@ -2488,13 +2409,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all instructions in the program from the given
- * start address to either the end address or the start address, depending if
- * the iterator is forward or not.
+ * Returns an iterator over all instructions in the program from the given start address to
+ * either the end address or the start address, depending if the iterator is forward or not.
* @param address the starting address for the iterator.
- * @param forward if true the iterator returns all instructions from the given
- * start address to the end of the program, otherwise it returns all instructions
- * from the given start address to the start of the program.
+ * @param forward if true the iterator returns all instructions from the given start address to
+ * the end of the program, otherwise it returns all instructions from the given start address
+ * to the start of the program.
+ * @return the iterator
*/
public InstructionIterator getInstructions(Address address, boolean forward) {
try {
@@ -2508,13 +2429,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all defined data in the program from the given
- * start address to either the end address or the start address, depending if
- * the iterator is forward or not.
+ * Returns an iterator over all defined data in the program from the given start address to
+ * either the end address or the start address, depending if the iterator is forward or not.
* @param address the starting address for the iterator.
- * @param forward if true the iterator returns all defined data from the given
- * start address to the end of the program, otherwise it returns all defined data
- * from the given start address to the start of the program.
+ * @param forward if true the iterator returns all defined data from the given start address to
+ * the end of the program, otherwise it returns all defined data from the given start address
+ * to the start of the program.
+ * @return the iterator
*/
public DataIterator getDefinedData(Address address, boolean forward) {
try {
@@ -2528,11 +2449,13 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all instructions in the given addressSet. The iterator
- * will go from the lowest address to the largest or from the largest to the
- * lowest depending on the forward parameter.
- * @param forward determines if the iterator goes from lowest address to highest
- * or the other way around.
+ * Returns an iterator over all instructions in the given addressSet. The iterator will go from
+ * the lowest address to the largest or from the largest to the lowest depending on the forward
+ * parameter.
+ * @param set restrict the returned instructions to these addresses
+ * @param forward determines if the iterator goes from lowest address to highest or the other
+ * way around.
+ * @return the iterator
*/
public InstructionIterator getInstructions(AddressSetView set, boolean forward) {
try {
@@ -2547,39 +2470,43 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Returns an iterator over all data in the program from the given
- * start address to either the end address or the start address, depending if
- * the iterator is forward or not.
+ * Returns an iterator over all data in the program from the given start address to either the
+ * end address or the start address, depending if the iterator is forward or not.
* @param start the starting address for the iterator.
- * @param forward if true the iterator returns all data from the given
- * start address to the end of the program, otherwise it returns all data
- * from the given start address to the start of the program.
+ * @param forward if true the iterator returns all data from the given start address to the end
+ * of the program, otherwise it returns all data from the given start address to the start of
+ * the program.
+ * @return the iterator
*/
public DataIterator getData(Address start, boolean forward) {
return new DataFilteredCodeUnitIterator(getCodeUnits(start, forward));
}
/**
- * Returns an iterator over all data in the given addressSet. The iterator
- * will go from the lowest address to the largest or from the largest to the
- * lowest depending on the forward parameter.
- * @param forward determines if the iterator goes from lowest address to highest
- * or the other way around.
+ * Returns an iterator over all data in the given addressSet. The iterator will go from the
+ * lowest address to the largest or from the largest to the lowest depending on the forward
+ * parameter.
+ * @param set restrict the returned instructions to these addresses
+ * @param forward determines if the iterator goes from lowest address to highest or the other
+ * way around.
+ * @return the iterator
*/
- public DataIterator getData(AddressSetView addrSet, boolean forward) {
- return new DataFilteredCodeUnitIterator(getCodeUnits(addrSet, forward));
+ public DataIterator getData(AddressSetView set, boolean forward) {
+ return new DataFilteredCodeUnitIterator(getCodeUnits(set, forward));
}
/**
- * Returns an iterator over all defined data in the given addressSet. The iterator
- * will go from the lowest address to the largest or from the largest to the
- * lowest depending on the forward parameter.
- * @param forward determines if the iterator goes from lowest address to highest
- * or the other way around.
+ * Returns an iterator over all defined data in the given addressSet. The iterator will go from
+ * the lowest address to the largest or from the largest to the lowest depending on the forward
+ * parameter.
+ * @param set restrict the returned instructions to these addresses
+ * @param forward determines if the iterator goes from lowest address to highest or the other
+ * way around.
+ * @return the iterator
*/
- public DataIterator getDefinedData(AddressSetView addrSet, boolean forward) {
+ public DataIterator getDefinedData(AddressSetView set, boolean forward) {
try {
- return new DataRecordIterator(this, dataAdapter.getRecords(addrSet, forward), forward);
+ return new DataRecordIterator(this, dataAdapter.getRecords(set, forward), forward);
}
catch (IOException e) {
program.dbError(e);
@@ -2591,6 +2518,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* Check if any instruction intersects the specified address range
* @param start start of range
* @param end end of range
+ * @throws ContextChangeException if there is a context register change conflict
*/
public void checkContextWrite(Address start, Address end) throws ContextChangeException {
lock.acquire();
@@ -2690,8 +2618,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Removes any data objects that have dataTypes matching the given dataType ids.
* @param dataTypeIDs the list of ids of dataTypes that have been deleted.
- * @param monitor TaskMonitor used to monitor progress and keeps track if the
- * user cancels the operation.
+ * @param monitor the task monitor.
+ * @throws CancelledException if cancelled
*/
public void clearData(long[] dataTypeIDs, TaskMonitor monitor) throws CancelledException {
lock.acquire();
@@ -2722,40 +2650,27 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
- ////////////////////////////////////////////////////////////////
- /**
- * Get the program.
- */
Program getProgram() {
return program;
}
- /**
- * Get the Symbol table.
- */
SymbolTable getSymbolTable() {
return symbolTable;
}
- /**
- * Get the listing.
- */
Listing getListing() {
return program.getListing();
}
- /**
- * Get the user property manager that manages user-defined
- * properties.
- */
PropertyMapManager getPropertyMapManager() {
return propertyMapMgr;
}
/**
- * Get the InstructionDB object from the cache; if it is not in
- * the cache, create a new DB object and add it.
+ * Get the InstructionDB object from the cache; if it is not in the cache, create a new DB
+ * object and add it.
* @param rec record for the instruction
+ * @return the instruction
*/
InstructionDB getInstructionDB(DBRecord rec) {
lock.acquire();
@@ -2781,9 +2696,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Get the DataDB object from the cache; if it is not in the cache,
- * create a new DB object and add it.
+ * Get the DataDB object from the cache; if it is not in the cache, create a new DB object and
+ * add it.
* @param rec data record
+ * @return the data
*/
DataDB getDataDB(DBRecord rec) {
lock.acquire();
@@ -2808,16 +2724,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
- /**
- * Get the adapter for the Data table.
- */
DataDBAdapter getDataAdapter() {
return dataAdapter;
}
- /**
- * Get the adapter for the Instruction table.
- */
InstDBAdapter getInstructionAdapter() {
return instAdapter;
}
@@ -2856,13 +2766,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
}
- ///////////////////////////////////////////////////////////////////
-
- /**
- * Move all user properties from the given range to the
- * the newStart location.
- */
-
/**
* Move the prototypes in the range to the new start location.
*/
@@ -2889,8 +2792,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * For each instruction in the range being moved, create the
- * symbols and add the references.
+ * For each instruction in the range being moved, create the symbols and add the references.
*/
private void addMovedInstructionReferences(Address start, Address end, TaskMonitor monitor)
throws IOException, CancelledException {
@@ -2904,8 +2806,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * For each instruction in the range being moved, create the
- * symbols and add the references.
+ * For each instruction in the range being moved, create the symbols and add the references.
*/
private void addMovedDataReferences(Address start, Address end, TaskMonitor monitor)
throws IOException, CancelledException {
@@ -3016,15 +2917,15 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Remove the specified reference is from oldRefList if present, otherwise add to instruction as a DEFAULT.
- * Return as preferred primary reference if it previously existed as a primary reference in oldRefList or
- * the specified operandPrimaryRef was null.
+ * Remove the specified reference is from oldRefList if present, otherwise add to instruction
+ * as a DEFAULT. Return as preferred primary reference if it previously existed as a primary
+ * reference in oldRefList or the specified operandPrimaryRef was null.
* @param inst instruction to which references apply
* @param opIndex operand to which reference applies
* @param refAddr default reference to-address
* @param refType default reference type
- * @param oldRefList list of old references which exist on instruction which have
- * yet to be accounted for (may be null).
+ * @param oldRefList list of old references which exist on instruction which have yet to be
+ * accounted for (may be null).
* @param operandPrimaryRef current preferred primary reference for operand
* @return updated preferred primary address for operand (i.e., operandPrimaryRef)
*/
@@ -3049,7 +2950,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Remove matching memory reference from oldRefList (considers toAddr and opIndex only)
* @param oldRefList list of existing DEFAULT memory references (may be null)
- * @param toAddr new reference desination address
+ * @param toAddr new reference destination address
* @param opIndex new reference operand
* @param refType new reference type
* @return existing reference if it already exists in oldRefList with matching refType, else null
@@ -3112,10 +3013,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
return refManager;
}
- /**
- * Method getAddressMap.
- * @return AddressMap
- */
AddressMap getAddressMap() {
return addrMap;
}
@@ -3217,70 +3114,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
-// private class KeyAdapter implements DBKeyAdapter {
-// private InstDBAdapter instAdapter;
-// private DataDBAdapter dataAdapter;
-// private boolean atStart;
-//
-// private KeyAdapter(InstDBAdapter adapter, boolean atStart) {
-// instAdapter = adapter;
-// this.atStart = atStart;
-// }
-// private KeyAdapter(DataDBAdapter adapter, boolean atStart) {
-// dataAdapter = adapter;
-// this.atStart = atStart;
-// }
-// public DBLongIterator getKeys(Address start, Address end)
-// throws IOException {
-// if (instAdapter != null) {
-// return instAdapter.getKeys(start, end, atStart);
-// }
-// else {
-// return dataAdapter.getKeys(start, end, atStart);
-// }
-// }
-// }
-// private class PMKeyAdapter implements DBKeyAdapter {
-// private PropertyMapDB map;
-// private boolean atStart;
-//
-// private PMKeyAdapter(PropertyMapDB map, boolean atStart) {
-// this.map = map;
-// this.atStart = atStart;
-// }
-// public DBLongIterator getKeys(Address start, Address end)
-// throws IOException {
-// return map.getLongAddressIterator(start, end, atStart);
-// }
-// }
-//
-// private class CuAddrIterator implements CodeUnitIterator {
-// private AddressIterator iter;
-//
-// private CuAddrIterator(AddressIterator iter) {
-// this.iter = iter;
-// }
-// /**
-// * @see ghidra.program.model.listing.CodeUnitIterator#hasNext()
-// */
-// public boolean hasNext() {
-// return iter.hasNext();
-// }
-//
-//
-// /**
-// * @see ghidra.program.model.listing.CodeUnitIterator#next()
-// */
-// public CodeUnit next() {
-// if (iter.hasNext()) {
-// return getCodeUnitAt(iter.next());
-// }
-// return null;
-// }
-// }
- /**
- * Invalidates all cached database objects
- */
@Override
public void invalidateCache(boolean all) {
lock.acquire();
@@ -3296,16 +3129,14 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
/**
- * Invalidates the cache for the codeUnits.
- *
+ * Invalidates the cache for the code units.
*/
public void invalidateCodeUnitCache() {
cache.invalidate();
}
/**
- * Notification that memory has changed, so clear the cache for the
- * affected code units.
+ * Notification that memory has changed, so clear the cache for the affected code units.
* @param addr start of change
* @param end end address of change
*/
@@ -3355,13 +3186,12 @@ public class CodeManager implements ErrorHandler, ManagerDB {
/**
* Get the comment for the given type at the specified address.
*
- * @param commentType either EOL_COMMENT, PRE_COMMENT,
- * POST_COMMENT, PLATE_COMMENT, or REPEATABLE_COMMENT
+ * @param commentType either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, PLATE_COMMENT, or
+ * REPEATABLE_COMMENT
* @param address the address of the comment.
- * @return the comment string of the appropriate type or null if no comment of
- * that type exists for this codeunit
- * @throws IllegalArgumentException if type is not one of the
- * types of comments supported
+ * @return the comment string of the appropriate type or null if no comment of that type exists
+ * for this code unit
+ * @throws IllegalArgumentException if type is not one of the types of comments supported
*/
public String getComment(int commentType, Address address) {
try {
@@ -3381,11 +3211,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* Set the comment for the given comment type at the specified address.
*
* @param address the address of the comment.
- * @param commentType either EOL_COMMENT, PRE_COMMENT,
- * POST_COMMENT, PLATE_COMMENT, or REPEATABLE_COMMENT
+ * @param commentType either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, PLATE_COMMENT, or
+ * REPEATABLE_COMMENT
* @param comment comment to set at the address
- * @throws IllegalArgumentException if type is not one of the
- * types of comments supported
+ * @throws IllegalArgumentException if type is not one of the types of comments supported
*/
public void setComment(Address address, int commentType, String comment) {
CodeUnit cu = getCodeUnitAt(address);
@@ -3589,7 +3418,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* Add comment history records for comments being deleted.
* @param start start address
* @param end end address
- * @throws IOException
+ * @throws IOException if there is an exception
*/
private void addCommentHistoryRecords(Address start, Address end) throws IOException {
RecordIterator iter = commentAdapter.getRecords(start, end, true);
@@ -3614,12 +3443,14 @@ public class CodeManager implements ErrorHandler, ManagerDB {
private HashMap<Long, Byte> redisassmblyFlags;
/**
- * Complete language transformation of all instructions. All existing prototypes will
- * be discarded and all instructions redisassembled following flow and adjusting context as needed.
- * Instructions which fail to redisassemble will be marked - since only one byte will be skipped, such bad
- * instruction disassembly may cause subsequent errors due to possible instruction shift.
- * This method is only intended for use by the ProgramDB setLanguage method which must ensure that
- * the context has been properly initialized.
+ * Complete language transformation of all instructions. All existing prototypes will be
+ * discarded and all instructions re-disassembled following flow and adjusting context as
+ * needed. Instructions which fail to re-disassemble will be marked - since only one byte will
+ * be skipped, such bad instruction disassembly may cause subsequent errors due to possible
+ * instruction shift.
+ * <P>
+ * This method is only intended for use by the ProgramDB setLanguage method which must ensure
+ * that the context has been properly initialized.
* @param monitor task monitor
* @throws IOException if IO error occurs
* @throws CancelledException if the operation is canceled.
@@ -3729,10 +3560,6 @@ public class CodeManager implements ErrorHandler, ManagerDB {
}
- /**
- * @param newProtoID
- * @return
- */
InstructionPrototype getInstructionPrototype(int protoID) {
return protoMgr.getPrototype(protoID);
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeUnitRecordIterator.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeUnitRecordIterator.java
index f0c3916fdd..e4b14731d3 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeUnitRecordIterator.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeUnitRecordIterator.java
@@ -21,7 +21,7 @@ import ghidra.program.model.address.*;
import ghidra.program.model.listing.*;
/**
- * Combines an Instruction iterator and Data iterator into a codeunit iterator
+ * Combines an Instruction iterator and Data iterator into a code unit iterator
*/
class CodeUnitRecordIterator implements CodeUnitIterator {
@@ -38,7 +38,7 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
/**
* Constructs a new CodeUnitRecordIterator
- * @param codeMgr the code managaer
+ * @param codeMgr the code manager
* @param instIt the instruction iterator
* @param dataIt the data iterator
* @param set the address set (required)
@@ -57,17 +57,11 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
}
- /**
- * @see java.util.Iterator#remove()
- */
@Override
public void remove() {
throw new UnsupportedOperationException();
}
- /**
- * @see ghidra.program.model.listing.CodeUnitIterator#hasNext()
- */
@Override
public boolean hasNext() {
if (nextCu == null) {
@@ -76,9 +70,6 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
return nextCu != null;
}
- /**
- * @see ghidra.program.model.listing.CodeUnitIterator#next()
- */
@Override
public CodeUnit next() {
if (hasNext()) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
index fafd1d3153..be25802fdc 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
@@ -62,7 +62,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
private LiveMemoryHandler liveMemory;
// lazy hashmap of block names to blocks, must be reloaded if blocks are removed or added
- private HashMap<String, MemoryBlock> nameBlockMap = new HashMap<String, MemoryBlock>();
+ private HashMap<String, MemoryBlock> nameBlockMap = new HashMap<>();
private final static MemoryBlock NoBlock = new MemoryBlockStub(); // placeholder for no block, not given out
Lock lock;
@@ -1257,8 +1257,13 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
* Tests if the memory contains a sequence of contiguous bytes that match the given byte array
* at all bit positions where the mask contains an "on" bit. The test will be something like
*
- * for(int i=0;i<bytes.length;i++) { if (bytes[i] != memory.getByte(addr+i) &amp; masks[i]) {
- * return false; } } return false;
+ * <PRE>
+ * for(int i = 0; i &lt; bytes.length; i++) {
+ * if (bytes[i] != memory.getByte(addr+i) &amp; masks[i]) {
+ * return false;
+ * }
+ * }
+ * </PRE>
*
* @param addr The beginning address in memory to test against.
* @param bytes the array of bytes to test for.
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java
index 7f8f7274d6..044ed5e1eb 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java
@@ -18,23 +18,22 @@ package ghidra.program.model.address;
import java.math.BigInteger;
import ghidra.program.model.data.DataOrganization;
+import ghidra.program.model.lang.Register;
/**
- * An address represents a location in a program. Conceptually, addresses consist
- * of an "address space" and an offset within that space. Many processors have only
- * one "real" address space, but some have several spaces. Also, there are
- * "artificial" address spaces used for analysis and representing other non-memory locations
- * such as a register or an offset on the stack relative to a functions frame pointer.
- *
+ * An address represents a location in a program. Conceptually, addresses consist of an
+ * "address space" and an offset within that space. Many processors have only one "real" address
+ * space, but some have several spaces. Also, there are "artificial" address spaces used for
+ * analysis and representing other non-memory locations such as a register or an offset on the
+ * stack relative to a functions frame pointer.
*/
-
public interface Address extends Comparable<Address> {
/**
* Address object representing an invalid address.
*/
public static final Address NO_ADDRESS = new SpecialAddress("NO ADDRESS");
/**
- * Address object representing an extenal entry address.
+ * Address object representing an external entry address.
*/
public static final Address EXT_FROM_ADDRESS = new SpecialAddress("Entry Point");
/**
@@ -43,14 +42,14 @@ public interface Address extends Comparable<Address> {
public final char SEPARATOR_CHAR = ':';
/**
- * Creates a new Address by parsing a String representation of an address. The
- * string may be either a simple number (just the offset part of an address) or take
- * the form "addressSpaceName:offset". If the latter form is used, the
- * "addressSpaceName" must match the name of the space for this address.
+ * Creates a new Address by parsing a String representation of an address. The string may be
+ * either a simple number (just the offset part of an address) or take the form
+ * "addressSpaceName:offset". If the latter form is used, the "addressSpaceName" must match
+ * the name of the space for this address.
*
* @param addrString the String to parse.
- * @return the new Address if the string is a legally formed address or null
- * if the string contains an address space name that does not match this address's space.
+ * @return the new Address if the string is a legally formed address or null if the string
+ * contains an address space name that does not match this address's space.
* @throws AddressFormatException if the string cannot be parsed or the
* parsed offset is larger than the size for this address' space.
*/
@@ -68,71 +67,70 @@ public interface Address extends Comparable<Address> {
/**
* Returns a new address in this address's space with the given offset.
- * NOTE: for those spaces with an addressable unit size other than 1, the address
- * returned may not correspond to an addressable unit/word boundary if a byte-offset
- * is specified.
+ * <P>NOTE: for those spaces with an addressable unit size other than 1, the address returned
+ * may not correspond to an addressable unit/word boundary if a byte-offset is specified.
+ *
* @param offset the offset for the new address.
- * @param isAddressableWordOffset if true the specified offset is an addressable unit/word offset,
- * otherwise offset is a byte offset. See {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
+ * @param isAddressableWordOffset if true the specified offset is an addressable unit/word
+ * offset, otherwise offset is a byte offset. See
+ * {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* AddressSpace#getAddressableUnitSize()} to understand the distinction
* (i.e., wordOffset = byteOffset * addressableUnitSize).
* @return address with given offset
- * @throws AddressOutOfBoundsException if the offset is less than 0 or greater
- * than the max offset allowed for this space.
+ * @throws AddressOutOfBoundsException if the offset is less than 0 or greater than the max
+ * offset allowed for this space.
*/
Address getNewAddress(long offset, boolean isAddressableWordOffset)
throws AddressOutOfBoundsException;
/**
- * Returns a new address in this address's space with the given offset. The specified
- * offset will be truncated within the space and will not throw an exception.
- * NOTE: for those spaces with an addressable unit size other than 1, the address
- * returned may not correspond to a word boundary (addressable unit) if a byte-offset
- * is specified.
+ * Returns a new address in this address's space with the given offset. The specified offset
+ * will be truncated within the space and will not throw an exception.
+ * <p>NOTE: for those spaces with an addressable unit size other than 1, the address returned
+ * may not correspond to a word boundary (addressable unit) if a byte-offset is specified.
* @param offset the offset for the new address.
- * @param isAddressableWordOffset if true the specified offset is an addressable unit/word offset,
- * otherwise offset is a byte offset. See {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
+ * @param isAddressableWordOffset if true the specified offset is an addressable unit/word
+ * offset, otherwise offset is a byte offset. See
+ * {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* AddressSpace#getAddressableUnitSize()} to understand the distinction
- * (i.e., wordOffset = byteOffset * addressableUnitSize).
+ * (i.e., wordOffset = byteOffset * addressableUnitSize).
* @return address with given byte offset truncated to the physical space size
*/
Address getNewTruncatedAddress(long offset, boolean isAddressableWordOffset);
/**
- * Returns the number of bytes needed to form a pointer to this address. The
- * result will be one of {1,2,4,8}.
- * @see DataOrganization#getPointerSize() for compiler-specific size of pointers stored in memory.
+ * Returns the number of bytes needed to form a pointer to this address. The result will be
+ * one of {1,2,4,8}.
+ * @return the pointer size
+ * @see DataOrganization#getPointerSize() for compiler-specific size of pointers stored in
+ * memory.
*/
public int getPointerSize();
/**
- * Returns the address's successor. In most cases, this is equivalent
- * to addr.add(1), but segmented addresses could span segments. The result
- * of calling this on the highest address will result in a null return value.
- * @return the next higher address, or null if already at the
- * highest address.
+ * Returns the address's successor. In most cases, this is equivalent to addr.add(1), but
+ * segmented addresses could span segments. The result of calling this on the highest address
+ * will result in a null return value.
+ * @return the next higher address, or null if already at the highest address.
*/
public Address next();
/**
- * Returns the address's predecessor. In most cases, this is equivalent to
- * addr.subtract(1), but segmented addresses could span segments. The
- * result of calling this on the lowest address will result in a null return value.
- * @return the next lower address, or null if already at the
- * lowest address.
+ * Returns the address's predecessor. In most cases, this is equivalent to addr.subtract(1),
+ * but segmented addresses could span segments. The result of calling this on the lowest
+ * address will result in a null return value.
+ * @return the next lower address, or null if already at the lowest address.
*/
public Address previous();
/**
- * Get the offset of this Address.
- *
+ * Get the offset of this Address.
* @return the offset of this Address.
*/
public long getOffset();
/**
- * Get the offset of this Address as a BigInteger
- *
+ * Get the offset of this Address as a BigInteger.
* @return the offset of this Address.
*/
public BigInteger getOffsetAsBigInteger();
@@ -152,17 +150,21 @@ public interface Address extends Comparable<Address> {
/**
* Returns the address space associated with this address.
+ * @return the address space
*/
public AddressSpace getAddressSpace();
/**
- * Return true if this address' address space is equal to the
- * address space for addr.
+ * Return true if this address' address space is equal to the address space for addr.
+ * @param addr the address to check
+ * @return true if the same space
*/
public boolean hasSameAddressSpace(Address addr);
- /** Returns the number of bits that are used to form the address. Thus
- * the maximum offset for this address space will be 2^size-1.
+ /**
+ * Returns the number of bits that are used to form the address. Thus the maximum offset for
+ * this address space will be 2^size-1.
+ * @return the size
*/
public int getSize();
@@ -176,10 +178,9 @@ public interface Address extends Comparable<Address> {
public long subtract(Address addr);
/**
- * Creates a new address by subtracting the displacement from the current
- * address. The new address will wrap in a manner that depends on the
- * address space. For a generic address space this will wrap at the
- * extents of the address space. For a segmented address space it will
+ * Creates a new address by subtracting the displacement from the current address. The new
+ * address will wrap in a manner that depends on the address space. For a generic address space
+ * this will wrap at the extents of the address space. For a segmented address space it will
* wrap at the extents of the segment.
*
* @param displacement the displacement to subtract.
@@ -188,43 +189,41 @@ public interface Address extends Comparable<Address> {
public Address subtractWrap(long displacement);
/**
- * Creates a new address by subtracting the displacement from the current
- * address. If the offset is greater than the max offset of the address space, the high
- * order bits are masked off, making the address wrap. For non-segmented addresses this
- * will be the same as subtractWrap(). For segmented addresses, the address will wrap when
- * the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
+ * Creates a new address by subtracting the displacement from the current address. If the
+ * offset is greater than the max offset of the address space, the high order bits are masked
+ * off, making the address wrap. For non-segmented addresses this will be the same as
+ * subtractWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff)
+ * offset is exceeded, as opposed to when the segment offset is exceeded.
* @param displacement the displacement to add.
* @return The new Address formed by subtracting the displacement from this address's offset.
*/
public Address subtractWrapSpace(long displacement);
/**
- * Creates a new Address by subtracting displacement from the
- * Address. The Address will not wrap within the space and in fact will throw
- * an exception if the result is less than the min address in this space or
- * greater than the max address in this space.
+ * Creates a new Address by subtracting displacement from the Address. The Address will not
+ * wrap within the space and in fact will throw an exception if the result is less than the min
+ * address in this space or greater than the max address in this space.
*
* @param displacement the displacement to subtract.
* @return The new Address
- * @throws AddressOverflowException if the offset in this Address would
- * overflow due to this operation.
+ * @throws AddressOverflowException if the offset in this Address would overflow due to this
+ * operation.
*/
public Address subtractNoWrap(long displacement) throws AddressOverflowException;
/**
- * Creates a new address (possibly in a new space) by subtracting the displacement to
- * this address.
+ * Creates a new address (possibly in a new space) by subtracting the displacement to this
+ * address.
* @param displacement the amount to subtract from this offset.
* @return The address using the subtracted offset.
*/
public Address subtract(long displacement);
/**
- * Creates a new address by adding the displacement to the current
- * address. The new address will wrap in a manner that depends on the
- * address space. For a generic address space this will wrap at the
- * extents of the address space. For a segmented address space it will
- * wrap at the extents of the segment.
+ * Creates a new address by adding the displacement to the current address. The new address
+ * will wrap in a manner that depends on the address space. For a generic address space this
+ * will wrap at the extents of the address space. For a segmented address space it will wrap at
+ * the extents of the segment.
*
* @param displacement the displacement to add.
* @return The new Address formed by adding the displacement to this address's offset.
@@ -232,112 +231,110 @@ public interface Address extends Comparable<Address> {
public Address addWrap(long displacement);
/**
- * Creates a new address by adding the displacement to the current
- * address. If the offset is greater than the max offset of the address space, the high
- * order bits are masked off, making the address wrap. For non-segmented addresses this
- * will be the same as addWrap(). For segmented addresses, the address will wrap when
- * the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
+ * Creates a new address by adding the displacement to the current address. If the offset is
+ * greater than the max offset of the address space, the high order bits are masked off, making
+ * the address wrap. For non-segmented addresses this will be the same as addWrap(). For
+ * segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as
+ * opposed to when the segment offset is exceeded.
* @param displacement the displacement to add.
* @return The new Address formed by adding the displacement to this address's offset.
*/
public Address addWrapSpace(long displacement);
/**
- * Creates a new Address with a displacement relative to this
- * Address. The Address will not wrap around! An exception will be
- * throw if the result is not within this address space.
+ * Creates a new Address with a displacement relative to this Address. The Address will not
+ * wrap around! An exception will be throw if the result is not within this address space.
*
- * @param displacement the displacement to add.
- * @return The new Address
- * @throws AddressOverflowException if the offset in this Address would
- * overflow (wrap around) due to this operation.
+ * @param displacement the displacement to add.
+ * @return the new address.
+ * @throws AddressOverflowException if the offset in this Address would overflow (wrap around)
+ * due to this operation.
*/
public Address addNoWrap(long displacement) throws AddressOverflowException;
public Address addNoWrap(BigInteger displacement) throws AddressOverflowException;
/**
- * Creates a new address (possibly in a new space) by adding the displacement to
- * this address.
+ * Creates a new address (possibly in a new space) by adding the displacement to this address.
* @param displacement the amount to add to this offset.
* @return The new address.
- * @throws AddressOutOfBoundsException if wrapping is not supported by the
- * corresponding address space and the addition causes an out-of-bounds
- * error
+ * @throws AddressOutOfBoundsException if wrapping is not supported by the corresponding
+ * address space and the addition causes an out-of-bounds error
*/
public Address add(long displacement) throws AddressOutOfBoundsException;
/**
* Tests whether the given address immediately follows this address.
*
- * @param addr the address to test.
+ * @param addr the address to test.
+ * @return true if the address follows this address.
*/
public boolean isSuccessor(Address addr);
/**
- * Returns a String representation of the address in hex and padded
- * to the appropriate size.
+ * Returns a String representation of the address in hex and padded to the appropriate size.
+ * @return the string
*/
@Override
public String toString();
/**
- * Returns a String representation of the address using the
- * given string as a prefix. Equivalent of prefix + ":" + toString(false)
+ * Returns a String representation of the address using the given string as a prefix.
+ * Equivalent of prefix + ":" + toString(false)
* @param prefix the string to prepend to the address string.
+ * @return the string
*/
public String toString(String prefix);
/**
* Returns a String representation that may include the address space name
- * @param showAddressSpace true if the address space should be included in
- * resulting string.
+ * @param showAddressSpace true if the address space should be included in resulting string.
* @return String the string representation of the address
*/
public String toString(boolean showAddressSpace);
/**
- * Returns a String representation that may include the address space name and may or may
- * not pad the address with leading zeros.
- * @param showAddressSpace if true, the addressSpace name will be prepended to the address string.
+ * Returns a String representation that may include the address space name and may or may not
+ * pad the address with leading zeros.
+ * @param showAddressSpace if true, the addressSpace name will be prepended to the address
+ * string.
* @param pad if true, the address will be prepended with leading zeros to completely fill out
- * the max digits the address could contain. If false, the address will be prepended only to make
- * the number of hex digits at least 4.
+ * the max digits the address could contain. If false, the address will be prepended only to
+ * make the number of hex digits at least 4.
* @return the address as a String.
*/
public String toString(boolean showAddressSpace, boolean pad);
/**
- * Returns a String representation that may include the address space name and may or may
- * not pad the address with leading zeros.
- * @param showAddressSpace if true, the addressSpace name will be prepended to the address string.
- * @param minNumDigits specifies the minimum number of digits to use. If the address space size
- * is less that minNumDigits, the address will be padded to the address space size. If the address
- * space size is larger that minNumDigits, the address will be displayed with as many digits as
- * necessary, but will contain leading zeros to make the address string have at least minNumDigits.
+ * Returns a String representation that may include the address space name and may or may not
+ * pad the address with leading zeros.
+ * @param showAddressSpace if true, the addressSpace name will be prepended to the address
+ * string.
+ * @param minNumDigits specifies the minimum number of digits to use. If the address space
+ * size is less that minNumDigits, the address will be padded to the address space size. If
+ * the address space size is larger that minNumDigits, the address will be displayed with as
+ * many digits as necessary, but will contain leading zeros to make the address string have at
+ * least minNumDigits.
* @return the address as a String.
*/
public String toString(boolean showAddressSpace, int minNumDigits);
/**
- * Compares this Address to the specified object.
- * The result is <code>true</code> if and only if the argument is not
- * <code>null</code> and is a <code>Address</code> object that represents
- * the same address as this object.
+ * Compares this Address to the specified object. The result is <code>true</code> if and only
+ * if the argument is not <code>null</code> and is a <code>Address</code> object that
+ * represents the same address as this object.
*
- * @param o the object to compare this <code>String</code>
- * against.
- * @return <code>true</code> if the <code>Addresses</code>are equal;
- * <code>false</code> otherwise.
+ * @param o the object to compare this <code>String</code> against.
+ * @return <code>true</code> if the <code>Addresses</code>are equal; <code>false</code>
+ * otherwise.
*/
@Override
public boolean equals(Object o);
/**
- * Returns a hashcode for this Address. The hashcode for an
- * <code>Address</code> should be a value such that two Address
- * objects which are equal will return the same hashcode.
- * This method should generally return the same value as getLong().
+ * Returns a hash code for this Address. The hash code for an <code>Address</code> should be a
+ * value such that two Address objects which are equal will return the same hash code. This
+ * method should generally return the same value as getLong().
*
* @return a hash code value for this object.
*/
@@ -347,61 +344,69 @@ public interface Address extends Comparable<Address> {
/**
* Returns the physical Address that corresponds to this Address.
*
- * @return address in a physical space corresponding to this
- * address.
+ * @return address in a physical space corresponding to this address.
*/
public Address getPhysicalAddress();
/**
- * Returns true if this address represents a location in memory
+ * Returns true if this address represents a location in memory.
+ * @return true if this address represents a location in memory.
*/
public boolean isMemoryAddress();
/**
- * Returns true if this address represents an address in a loaded memory block
+ * Returns true if this address represents an address in a loaded memory block.
+ * @return true if this address represents an address in a loaded memory block.
*/
public boolean isLoadedMemoryAddress();
/**
- * Returns true if this address represents an address not loaded in real memory (i.e. OTHER)
+ * Returns true if this address represents an address not loaded in real memory (i.e. OTHER).
+ * @return true if this address represents an address not loaded in real memory (i.e. OTHER).
*/
public boolean isNonLoadedMemoryAddress();
/**
- * Returns true if this address represents a location in stack space
+ * Returns true if this address represents a location in stack space.
+ * @return true if this address represents a location in stack space.
*/
public boolean isStackAddress();
/**
- * Returns true if this address represents a location in unique space
+ * Returns true if this address represents a location in unique space.
+ * @return true if this address represents a location in unique space.
*/
public boolean isUniqueAddress();
/**
- * Returns true if this address represents a location in constant space
+ * Returns true if this address represents a location in constant space.
+ * @return true if this address represents a location in constant space.
*/
public boolean isConstantAddress();
/**
- * Returns true if this address represents a location in the HASH space
+ * Returns true if this address represents a location in the HASH space.
+ * @return true if this address represents a location in the HASH space.
*/
public boolean isHashAddress();
/**
* Returns true if this address represents a location in the register space.
- * <P>NOTE: It is important to note that a {@link Register} could reside within
- * a memory space and not the register space in which case this method would return
- * false for its address.
+ * <P>NOTE: It is important to note that a {@link Register} could reside within a memory space
+ * and not the register space in which case this method would return false for its address.
+ * @return true if a register address
*/
public boolean isRegisterAddress();
/**
- * Returns true if this address represents a location in variable space
+ * Returns true if this address represents a location in variable space.
+ * @return true if this address represents a location in variable space.
*/
public boolean isVariableAddress();
/**
- * Returns true if this address represents an external location in the external address space
+ * Returns true if this address represents an external location in the external address space.
+ * @return true if this address represents an external location in the external address space.
*/
public boolean isExternalAddress();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/BookmarkType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/BookmarkType.java
index 5bfa4fc9cf..b06c9a6ecf 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/BookmarkType.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/BookmarkType.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,38 +29,43 @@ public interface BookmarkType {
public static final String ERROR = "Error";
public static final String WARNING = "Warning";
public static final String ANALYSIS = "Analysis";
- public static final String ALL_TYPES = "All Bookmark Types";
/**
- * Returns the type as a string
+ * Returns the type as a string.
+ * @return the type as a string.
*/
- String getTypeString();
+ public String getTypeString();
/**
* Returns Icon associated with this type or null if one has not been
* set by a plugin.
+ * @return the icon.
*/
- ImageIcon getIcon();
+ public ImageIcon getIcon();
/**
* Returns marker color associated with this type or null if one has not been
* set by a plugin.
+ * @return the color.
*/
- Color getMarkerColor();
+ public Color getMarkerColor();
/**
* Returns marker priority associated with this type or -1 if one has not been
* set by a plugin.
+ * @return the priority.
*/
- int getMarkerPriority();
+ public int getMarkerPriority();
/**
- * Returns true if there is at least one bookmark defined for this type
+ * Returns true if there is at least one bookmark defined for this type.
+ * @return true if there is at least one bookmark defined for this type.
*/
- boolean hasBookmarks();
+ public boolean hasBookmarks();
/**
* Returns the id associated with this bookmark type.
+ * @return the id associated with this bookmark type.
*/
- int getTypeId();
+ public int getTypeId();
}