Ghidra is a software reverse engineering (SRE) framework
GT-3165 - Tables - Fixed Ctrl-A conflict between tables and the Listing
dragonmachera87b65b758bb
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ActionDialog.java b/Ghidra/Framework/Docking/src/main/java/docking/ActionDialog.javaindex e1ee05410f..84245ae71f 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/ActionDialog.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/ActionDialog.java@@ -24,7 +24,6 @@ import javax.swing.*;import docking.action.DockingActionIf;import docking.widgets.label.GIconLabel;import docking.widgets.label.GLabel;-import resources.ResourceManager;/*** Dialog to show multiple actions that are mapped to the same keystroke;@@ -39,10 +38,8 @@ public class ActionDialog extends DialogComponentProvider {/*** Constructor- * @param parent parent to this dialog* @param keystrokeName keystroke name- * @param list list of PluginActions- * @param event event to pass the selected action+ * @param list list of actions*/public ActionDialog(String keystrokeName, List<ExecutableKeyActionAdapter> list) {super("Select Action", true);@@ -68,10 +65,8 @@ public class ActionDialog extends DialogComponentProvider {}/**- * Set the list of actions that are enabled.- * @param list list of actions- * @param event event to pass to the action that is- * selected.+ * Set the list of actions that are enabled+ * @param list list of actions selected*/public void setActionList(List<ExecutableKeyActionAdapter> list) {okButton.setEnabled(false);@@ -85,8 +80,6 @@ public class ActionDialog extends DialogComponentProvider {actionList.setSelectedIndex(0);}- /////////////////////////////////////////////////////////////////////////-private void init() {this.addWorkPanel(buildMainPanel());addOKButton();@@ -107,7 +100,9 @@ public class ActionDialog extends DialogComponentProvider {innerPanel.setBorder(BorderFactory.createTitledBorder("Actions"));JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));- panel.add(new GIconLabel(ResourceManager.loadImage("images/warning.png")));++ Icon icon = UIManager.getIcon("OptionPane.warningIcon");+ panel.add(new GIconLabel(icon));panel.add(labelPanel);listModel = new DefaultListModel<>();@@ -139,7 +134,7 @@ public class ActionDialog extends DialogComponentProvider {return mainPanel;}- void addListeners() {+ private void addListeners() {actionList.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {diff --git a/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentBasedDockingAction.java b/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentBasedDockingAction.javanew file mode 100644index 0000000000..2bd0b91f3a--- /dev/null+++ b/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentBasedDockingAction.java@@ -0,0 +1,37 @@+/* ###+ * 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 docking.action;++import java.awt.Component;++import docking.ActionContext;+import docking.ComponentProvider;++/**+ * An interface to signal that the implementing action works with an individual Java+ * {@link Component}. Standard Docking Actions are either global tool-based actions or local+ * {@link ComponentProvider} actions. This interface allows us to have the concept of an+ * action that is effectively local to a specific Java component.+ */+public interface ComponentBasedDockingAction extends DockingActionIf {++ /**+ * Returns true if the given context contains this action's component+ * @param context the context+ * @return true if the given context contains this action's component+ */+ public boolean isValidComponentContext(ActionContext context);+}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/action/MultipleKeyAction.java b/Ghidra/Framework/Docking/src/main/java/docking/action/MultipleKeyAction.javaindex 6fcdcfebf3..66b1fbc3f9 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/action/MultipleKeyAction.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/action/MultipleKeyAction.java@@ -169,9 +169,11 @@ public class MultipleKeyAction extends DockingKeyBindingAction {List<ExecutableKeyActionAdapter> list = new ArrayList<>();boolean hasLocalActionsForKeyBinding = false;- // search for local actions first...+ //+ // 1) Prefer local actions for the active provider+ //for (ActionData actionData : actions) {- if (actionData.isMyProvider(localContext.getComponentProvider())) {+ if (actionData.isMyProvider(localContext)) {hasLocalActionsForKeyBinding = true;if (actionData.action.isEnabledForContext(localContext)) {list.add(new ExecutableKeyActionAdapter(actionData.action, localContext));@@ -185,7 +187,33 @@ public class MultipleKeyAction extends DockingKeyBindingAction {return list;}- // ...no locals, see if we have any global actions+ //+ // 2) Check for actions local to the source component+ //+ for (ActionData actionData : actions) {+ if (!(actionData.action instanceof ComponentBasedDockingAction)) {+ continue;+ }++ ComponentBasedDockingAction componentAction =+ (ComponentBasedDockingAction) actionData.action;+ if (componentAction.isValidComponentContext(localContext)) {+ hasLocalActionsForKeyBinding = true;+ if (actionData.action.isEnabledForContext(localContext)) {+ list.add(new ExecutableKeyActionAdapter(actionData.action, localContext));+ }+ }+ }++ if (hasLocalActionsForKeyBinding) {+ // We have locals, ignore the globals. This prevents global actions from processing+ // the given keybinding when a local action exits, regardless of enablement.+ return list;+ }++ //+ // 3) Check for global actions+ //for (ActionData actionData : actions) {if (actionData.isGlobalAction()) {// When looking for context matches, we prefer local context, even though this@@ -271,7 +299,8 @@ public class MultipleKeyAction extends DockingKeyBindingAction {return provider == null;}- boolean isMyProvider(ComponentProvider otherProvider) {+ boolean isMyProvider(ActionContext localContext) {+ ComponentProvider otherProvider = localContext.getComponentProvider();return provider == otherProvider;}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.javaindex fa5de615a1..d10c177fd2 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java@@ -15,9 +15,9 @@*/package docking.widgets.table;-import static docking.DockingUtils.CONTROL_KEY_MODIFIER_MASK;-import static docking.action.MenuData.NO_MNEMONIC;-import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;+import static docking.DockingUtils.*;+import static docking.action.MenuData.*;+import static java.awt.event.InputEvent.*;import java.awt.*;import java.awt.event.*;@@ -448,8 +448,15 @@ public class GTable extends JTable implements KeyStrokeConsumer {}/**- * Enables the keyboard actions to pass through this table- * and up the component hierarchy.+ * Enables the keyboard actions to pass through this table and up the component hierarchy.+ * Specifically, passing true to this method allows unmodified keystrokes to work+ * in the tool when this table is focused. Modified keystrokes, like <code>+ * Ctrl-C</code>, will work at all times. Finally, if true is passed to this+ * method, then the {@link #setAutoLookupColumn(int) auto lookup} feature is+ * disabled.+ *+ * <p>The default state is for actions to be disabled.+ ** @param b true allows keyboard actions to pass up the component hierarchy.*/public void setActionsEnabled(boolean b) {@@ -1496,7 +1503,8 @@ public class GTable extends JTable implements KeyStrokeConsumer {}}- private abstract static class GTableAction extends DockingAction {+ private abstract static class GTableAction extends DockingAction+ implements ComponentBasedDockingAction {GTableAction(String name, String owner) {super(name, owner);@@ -1516,5 +1524,11 @@ public class GTable extends JTable implements KeyStrokeConsumer {Component sourceComponent = context.getSourceComponent();return sourceComponent instanceof GTable;}++ @Override+ public boolean isValidComponentContext(ActionContext context) {+ Component sourceComponent = context.getSourceComponent();+ return sourceComponent instanceof GTable;+ }}}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/MultEntSubModel.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/MultEntSubModel.javaindex a60525a00b..c820ae7b4e 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/MultEntSubModel.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/MultEntSubModel.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,6 +15,8 @@*/package ghidra.program.model.block;+import java.util.*;+import ghidra.program.model.address.*;import ghidra.program.model.listing.Listing;import ghidra.program.model.listing.Program;@@ -24,8 +25,6 @@ import ghidra.util.Msg;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;-import java.util.*;-/*** <CODE>MultEntSubModel</CODE> (M-model) defines subroutines which do not share code with* any other subroutine and may have one or more entry points. Each entry-@@ -41,160 +40,169 @@ import java.util.*;public class MultEntSubModel implements SubroutineBlockModel {public static final String NAME = "Multiple Entry";-- protected Program program;- protected Listing listing;-- private AddressObjectMap foundMSubs; // used for caching model-M subroutines- private CodeBlockModel bbModel; // basic block model- protected final boolean includeExternals;-- /**- * Construct a <CODE>MultEntSubModel</CODE> for a program.- *- * @param program program to create blocks from.- */- public MultEntSubModel(Program program) {- this(program, false);- }-- /**- * Construct a <CODE>MultEntSubModel</CODE> for a program.- * @param program program to create blocks from.- * @param includeExternals external blocks will be included if true- */- public MultEntSubModel(Program program, boolean includeExternals) {- this.program = program;- this.includeExternals = includeExternals;- listing = program.getListing();- foundMSubs = new AddressObjectMap();- }-- /**- * Get the code block that has an entry point at addr.- *- * @param addr one of the entry points for a Model-M subroutine- * @param monitor task monitor which allows user to cancel operation.- * @return null if there is no subroutine with an entry at addr.- * @throws CancelledException if the monitor cancels the operation.- */- public CodeBlock getCodeBlockAt(Address addr, TaskMonitor monitor) throws CancelledException {-- if (addr == null)- return null;-- CodeBlock block = getSubFromCache(addr);- if (block == null) {- block = getAddressSetContaining(addr, monitor);- }- if (block != null){- Address[] entPts = block.getStartAddresses();- for (int i = 0; i < entPts.length; i++) {- if (entPts[i].equals(addr))- return block;- }- }- return null;- }-- /**- * Get the M-Model subroutine address set which contains the specified address.- * This method also identifies the entry points and caches the resulting CodeBlock.- *- * @param addr Address inside the subroutine that we are seeking- * @param monitor task monitor which allows user to cancel operation.- * @return The <CODE>CodeBlock</CODE> for a- * <CODE>MultEntSubModel</CODE> Subroutine.- * Null is returned if there is no instruction at addr.- * @throws CancelledException if the monitor cancels the operation.- **/- protected CodeBlock getAddressSetContaining(Address addr, TaskMonitor monitor) throws CancelledException {-- if (addr.isExternalAddress()) {- if (includeExternals) {- CodeBlock block = new ExtCodeBlockImpl(this, addr);- foundMSubs.addObject(block, addr, addr);- return block;- }- return null;- }-- // create a holder for the blockSet- AddressSet addrSet = new AddressSet();-- // Use a new block model each time, so that only the current- // function basic blocks will get saved.++ protected Program program;+ protected Listing listing;++ private AddressObjectMap foundMSubs; // used for caching model-M subroutines+ private CodeBlockModel bbModel; // basic block model+ protected final boolean includeExternals;++ /**+ * Construct a <CODE>MultEntSubModel</CODE> for a program.+ *+ * @param program program to create blocks from.+ */+ public MultEntSubModel(Program program) {+ this(program, false);+ }++ /**+ * Construct a <CODE>MultEntSubModel</CODE> for a program.+ * @param program program to create blocks from.+ * @param includeExternals external blocks will be included if true+ */+ public MultEntSubModel(Program program, boolean includeExternals) {+ this.program = program;+ this.includeExternals = includeExternals;+ listing = program.getListing();+ foundMSubs = new AddressObjectMap();+ }++ /**+ * Get the code block that has an entry point at addr.+ *+ * @param addr one of the entry points for a Model-M subroutine+ * @param monitor task monitor which allows user to cancel operation.+ * @return null if there is no subroutine with an entry at addr.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public CodeBlock getCodeBlockAt(Address addr, TaskMonitor monitor) throws CancelledException {++ if (addr == null) {+ return null;+ }++ CodeBlock block = getSubFromCache(addr);+ if (block == null) {+ block = getAddressSetContaining(addr, monitor);+ }+ if (block != null) {+ Address[] entPts = block.getStartAddresses();+ for (Address entPt : entPts) {+ if (entPt.equals(addr)) {+ return block;+ }+ }+ }+ return null;+ }++ /**+ * Get the M-Model subroutine address set which contains the specified address.+ * This method also identifies the entry points and caches the resulting CodeBlock.+ *+ * @param addr Address inside the subroutine that we are seeking+ * @param monitor task monitor which allows user to cancel operation.+ * @return The <CODE>CodeBlock</CODE> for a+ * <CODE>MultEntSubModel</CODE> Subroutine.+ * Null is returned if there is no instruction at addr.+ * @throws CancelledException if the monitor cancels the operation.+ **/+ protected CodeBlock getAddressSetContaining(Address addr, TaskMonitor monitor)+ throws CancelledException {++ if (addr.isExternalAddress()) {+ if (includeExternals) {+ CodeBlock block = new ExtCodeBlockImpl(this, addr);+ foundMSubs.addObject(block, addr, addr);+ return block;+ }+ return null;+ }++ // create a holder for the blockSet+ AddressSet addrSet = new AddressSet();++ // Use a new block model each time, so that only the current+ // function basic blocks will get saved.bbModel = new SimpleBlockModel(program, includeExternals);-- // Create the todoStack and initialize it with instr; also initialize the list for entryPts.- ArrayList<Address> entryPtList = new ArrayList<Address>();- LinkedList<Address> todoList = new LinkedList<Address>(); // list of address destinations to follow- LinkedList<CodeBlock> srcList = new LinkedList<CodeBlock>(); // list of blocks to process for possible sources- todoList.addFirst(addr);-- // Build model-M subroutine from basic blocks- while (!todoList.isEmpty() || !srcList.isEmpty()) {-- if (monitor != null && monitor.isCancelled())- throw new CancelledException();++ // Create the todoStack and initialize it with instr; also initialize the list for entryPts.+ ArrayList<Address> entryPtList = new ArrayList<Address>();+ LinkedList<Address> todoList = new LinkedList<Address>(); // list of address destinations to follow+ LinkedList<CodeBlock> srcList = new LinkedList<CodeBlock>(); // list of blocks to process for possible sources+ todoList.addFirst(addr);++ // Build model-M subroutine from basic blocks+ while (!todoList.isEmpty() || !srcList.isEmpty()) {++ if (monitor != null && monitor.isCancelled()) {+ throw new CancelledException();+ }// if todoList is empty// process any blocks for sources that we put off to analyze later// It is easier/efficient to follow flow in the forward direction.if (todoList.isEmpty()) {- while (todoList.isEmpty() && !srcList.isEmpty()) {- CodeBlock bblock = srcList.removeFirst();+ while (todoList.isEmpty() && !srcList.isEmpty()) {+ CodeBlock bblock = srcList.removeFirst();// Process all block source references- addSources(monitor, entryPtList, todoList, bblock);- }- continue;+ addSources(monitor, entryPtList, todoList, bblock);+ }+ continue;}-+// get the next address to processAddress a = null;a = todoList.removeFirst();-+// Get basic block at the specified address- if (addrSet.contains(a))- continue; // already processed this block-- CodeBlock bblock = bbModel.getFirstCodeBlockContaining(a, monitor);- if (bblock == null)- continue;-- // Verify that the block contains instructions- if (listing.getInstructionAt(bblock.getMinAddress()) == null)- continue;-- // Add basic block to subroutine address set- addrSet.add(bblock);-- // Process all destination references+ if (addrSet.contains(a)) {+ continue; // already processed this block+ }++ CodeBlock bblock = bbModel.getFirstCodeBlockContaining(a, monitor);+ if (bblock == null) {+ continue;+ }++ // Verify that the block contains instructions+ if (listing.getInstructionAt(bblock.getMinAddress()) == null) {+ continue;+ }++ // Add basic block to subroutine address set+ addrSet.add(bblock);++ // Process all destination referencesaddDestinations(monitor, todoList, bblock);-- // add block to list of block to process later- srcList.addLast(bblock);- }- if (addrSet.isEmpty())+ // add block to list of block to process later+ srcList.addLast(bblock);+ }++ if (addrSet.isEmpty()) {return null;-+ }+// Check for failure to find entry pointif (entryPtList.size() == 0) {- Msg.warn(this, "WARNING: failed to find entry point for subroutine containing " + addr);+ Msg.warn(this, "Failed to find entry point for subroutine containing " + addr);entryPtList.add(addrSet.getMinAddress());- }- Address[] entryPts = new Address[entryPtList.size()];- entryPtList.toArray(entryPts);+ }+ Address[] entryPts = new Address[entryPtList.size()];+ entryPtList.toArray(entryPts);- CodeBlock block = new CodeBlockImpl(this, entryPts, addrSet);- foundMSubs.addObject(block, addrSet);+ CodeBlock block = new CodeBlockImpl(this, entryPts, addrSet);+ foundMSubs.addObject(block, addrSet);- return block;- }+ return block;+ }- private void addDestinations(TaskMonitor monitor, LinkedList<Address> todoList, CodeBlock bblock)- throws CancelledException {+ private void addDestinations(TaskMonitor monitor, LinkedList<Address> todoList,+ CodeBlock bblock) throws CancelledException {CodeBlockReferenceIterator destIter = bblock.getDestinations(monitor);while (destIter.hasNext()) {CodeBlockReference destRef = destIter.next();@@ -203,18 +211,17 @@ public class MultEntSubModel implements SubroutineBlockModel {if (destAddr.isMemoryAddress()) {FlowType refFlowType = destRef.getFlowType();if (refFlowType.isJump()) {- todoList.addLast(destAddr);- }+ todoList.addLast(destAddr);+ }else if (refFlowType.isFallthrough()) {- todoList.addFirst(destAddr);+ todoList.addFirst(destAddr);}}}}-- private void addSources(TaskMonitor monitor,- List<Address> entryPtList, LinkedList<Address> todoList, CodeBlock bblock)- throws CancelledException {++ private void addSources(TaskMonitor monitor, List<Address> entryPtList,+ LinkedList<Address> todoList, CodeBlock bblock) throws CancelledException {CodeBlockReferenceIterator srcIter = bblock.getSources(monitor);boolean isSource = true;boolean isEntry = false;@@ -224,8 +231,9 @@ public class MultEntSubModel implements SubroutineBlockModel {FlowType refFlowType = srcRef.getFlowType();if (refFlowType.isJump() || refFlowType.isFallthrough()) {// Add Jump and Fall-through sources to the todoList- todoList.addLast(srcRef.getSourceAddress());- } else if (refFlowType.isCall()) {+ todoList.addLast(srcRef.getSourceAddress());+ }+ else if (refFlowType.isCall()) {// Basic block is a subroutine entry pointisEntry = true;}@@ -234,214 +242,234 @@ public class MultEntSubModel implements SubroutineBlockModel {entryPtList.add(bblock.getMinAddress());}}-- /**- * Get the MultEntSubModel Code Block that contains the address.- *- * @param addr Address to find a containing block.- * @param monitor task monitor which allows user to cancel operation.- * @return A CodeBlock if any block contains the address.- * null otherwise.- * @throws CancelledException if the monitor cancels the operation.- */- public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor) throws CancelledException {-- CodeBlock block = getSubFromCache(addr);- if (block == null) {- block = getAddressSetContaining(addr, monitor);- }++ /**+ * Get the MultEntSubModel Code Block that contains the address.+ *+ * @param addr Address to find a containing block.+ * @param monitor task monitor which allows user to cancel operation.+ * @return A CodeBlock if any block contains the address.+ * null otherwise.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor)+ throws CancelledException {++ CodeBlock block = getSubFromCache(addr);+ if (block == null) {+ block = getAddressSetContaining(addr, monitor);+ }return block;- }--- /**- * Returns the one code block contained by addr (only for- * a model that has shared subroutines would this method- * return more than one code block)- *- * @param addr Address to find a containing block.- * @param monitor task monitor which allows user to cancel operation.- * @return A CodeBlock if any block contains the address.- * empty array otherwise.- * @throws CancelledException if the monitor cancels the operation.- */- public CodeBlock[] getCodeBlocksContaining(Address addr, TaskMonitor monitor) throws CancelledException {- CodeBlock sub = getFirstCodeBlockContaining(addr, monitor);- if (sub == null) {- return emptyBlockArray;- }- CodeBlock[] blocks = new CodeBlock[1];- blocks[0] = sub;- return blocks;- }--- /**- * Get an iterator over the code blocks in the entire program.- * @param monitor task monitor which allows user to cancel operation.- * @throws CancelledException if the monitor cancels the operation.- */- public CodeBlockIterator getCodeBlocks(TaskMonitor monitor) throws CancelledException {- return new MultEntSubIterator(this, monitor);- }-- /**- * Get an iterator over CodeBlocks which overlap the specified address set.- *- * @param addrSet an address set within program- * @param monitor task monitor which allows user to cancel operation.- * @throws CancelledException if the monitor cancels the operation.- */- public CodeBlockIterator getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor) throws CancelledException {- return new MultEntSubIterator(this, addrSet, monitor);- }-- /**- * @see ghidra.program.model.block.CodeBlockModel#getProgram()- */- public Program getProgram() {- return program;- }-- /**- * Returns the listing associated with this block model.- * @return the listing associated with this block model.- */- public Listing getListing() {- return listing;- }-- /**- * @see ghidra.program.model.block.CodeBlockModel#getName(ghidra.program.model.block.CodeBlock)- */- public String getName(CodeBlock block) {-- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();-- // get the start address for the block- // look up the symbol in the symbol table.- // it should have one if anyone calls it.- // if not, make up a label-- Address start = block.getFirstStartAddress();-- Symbol symbol = program.getSymbolTable().getPrimarySymbol(start);- if (symbol != null) {- return symbol.getName();- }-- return "SOURCE_SUB" + start.toString();- }--- /**- * Return in general how things flow out of this node.- * This method exists for the SIMPLEBLOCK model.- *- * <p>- * Since it doesn't make a great deal of sense to ask for this method- * in the case of subroutines, we return FlowType.UNKNOWN- * as long as the block exists.- *- * <p>- * If this block has no valid instructions, it can't flow,- * so FlowType.INVALID is returned.- *- * @return flow type of this node- */- public FlowType getFlowType(CodeBlock block) {-- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();-- /* If there are multiple unique ways out of the node, then we- should return FlowType.UNKNOWN (or FlowType.MULTIFLOW ?).- Possible considerations for the future which are particularly- applicable to model-P subroutines: add FlowType.MULTICALL if- only calls out and FlowType.MULTIJUMP if multiple jumps OUT- (as opposed to jumping within the subroutine).- Might want to consider FlowType.MULTITERMINAL for multiple returns? */-- return RefType.FLOW;- }-- /**- * @see ghidra.program.model.block.CodeBlockModel#getSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)- */- public CodeBlockReferenceIterator getSources(CodeBlock block, TaskMonitor monitor) throws CancelledException {- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();-- return new SubroutineSourceReferenceIterator(block, monitor);- }-- /**- * @see ghidra.program.model.block.CodeBlockModel#getNumSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)- */- public int getNumSources(CodeBlock block, TaskMonitor monitor) throws CancelledException {-- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();-+ }++ /**+ * Returns the one code block contained by addr (only for+ * a model that has shared subroutines would this method+ * return more than one code block)+ *+ * @param addr Address to find a containing block.+ * @param monitor task monitor which allows user to cancel operation.+ * @return A CodeBlock if any block contains the address.+ * empty array otherwise.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public CodeBlock[] getCodeBlocksContaining(Address addr, TaskMonitor monitor)+ throws CancelledException {+ CodeBlock sub = getFirstCodeBlockContaining(addr, monitor);+ if (sub == null) {+ return emptyBlockArray;+ }+ CodeBlock[] blocks = new CodeBlock[1];+ blocks[0] = sub;+ return blocks;+ }++ /**+ * Get an iterator over the code blocks in the entire program.+ * @param monitor task monitor which allows user to cancel operation.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public CodeBlockIterator getCodeBlocks(TaskMonitor monitor) throws CancelledException {+ return new MultEntSubIterator(this, monitor);+ }++ /**+ * Get an iterator over CodeBlocks which overlap the specified address set.+ *+ * @param addrSet an address set within program+ * @param monitor task monitor which allows user to cancel operation.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public CodeBlockIterator getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor)+ throws CancelledException {+ return new MultEntSubIterator(this, addrSet, monitor);+ }++ /**+ * @see ghidra.program.model.block.CodeBlockModel#getProgram()+ */+ @Override+ public Program getProgram() {+ return program;+ }++ /**+ * Returns the listing associated with this block model.+ * @return the listing associated with this block model.+ */+ public Listing getListing() {+ return listing;+ }++ /**+ * @see ghidra.program.model.block.CodeBlockModel#getName(ghidra.program.model.block.CodeBlock)+ */+ @Override+ public String getName(CodeBlock block) {++ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }++ // get the start address for the block+ // look up the symbol in the symbol table.+ // it should have one if anyone calls it.+ // if not, make up a label++ Address start = block.getFirstStartAddress();++ Symbol symbol = program.getSymbolTable().getPrimarySymbol(start);+ if (symbol != null) {+ return symbol.getName();+ }++ return "SOURCE_SUB" + start.toString();+ }++ /**+ * Return in general how things flow out of this node.+ * This method exists for the SIMPLEBLOCK model.+ *+ * <p>+ * Since it doesn't make a great deal of sense to ask for this method+ * in the case of subroutines, we return FlowType.UNKNOWN+ * as long as the block exists.+ *+ * <p>+ * If this block has no valid instructions, it can't flow,+ * so FlowType.INVALID is returned.+ *+ * @return flow type of this node+ */+ @Override+ public FlowType getFlowType(CodeBlock block) {++ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }++ /* If there are multiple unique ways out of the node, then we+ should return FlowType.UNKNOWN (or FlowType.MULTIFLOW ?).+ Possible considerations for the future which are particularly+ applicable to model-P subroutines: add FlowType.MULTICALL if+ only calls out and FlowType.MULTIJUMP if multiple jumps OUT+ (as opposed to jumping within the subroutine).+ Might want to consider FlowType.MULTITERMINAL for multiple returns? */++ return RefType.FLOW;+ }++ /**+ * @see ghidra.program.model.block.CodeBlockModel#getSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)+ */+ @Override+ public CodeBlockReferenceIterator getSources(CodeBlock block, TaskMonitor monitor)+ throws CancelledException {+ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }++ return new SubroutineSourceReferenceIterator(block, monitor);+ }++ /**+ * @see ghidra.program.model.block.CodeBlockModel#getNumSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)+ */+ @Override+ public int getNumSources(CodeBlock block, TaskMonitor monitor) throws CancelledException {++ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }+return SubroutineSourceReferenceIterator.getNumSources(block, monitor);- }+ }- /**- * @see ghidra.program.model.block.CodeBlockModel#getDestinations(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)- */- public CodeBlockReferenceIterator getDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException {+ /**+ * @see ghidra.program.model.block.CodeBlockModel#getDestinations(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)+ */+ @Override+ public CodeBlockReferenceIterator getDestinations(CodeBlock block, TaskMonitor monitor)+ throws CancelledException {- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();+ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }- return new SubroutineDestReferenceIterator(block, monitor);- }+ return new SubroutineDestReferenceIterator(block, monitor);+ }- /**- * Get number of destination references flowing out of this subroutine (block).- * All Calls from this block, and all external FlowType block references- * from this block are counted.- *- * @param block code block to get the number of destination references from.- * @param monitor task monitor which allows user to cancel operation.- * @throws CancelledException if the monitor cancels the operation.- */- public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException {+ /**+ * Get number of destination references flowing out of this subroutine (block).+ * All Calls from this block, and all external FlowType block references+ * from this block are counted.+ *+ * @param block code block to get the number of destination references from.+ * @param monitor task monitor which allows user to cancel operation.+ * @throws CancelledException if the monitor cancels the operation.+ */+ @Override+ public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException {- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();+ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }return SubroutineDestReferenceIterator.getNumDestinations(block, monitor);- }-- /**- * Compute an address set that represents all the addresses contained- * in all instructions that are part of this block- *- * @param block code block to compute address set for.- */- public AddressSetView getAddressSet(CodeBlock block) {-- if (!(block.getModel() instanceof MultEntSubModel))- throw new IllegalArgumentException();-- return new AddressSet(block);- }-- /**- * Gets a subroutine from the cache containing addr. If none there, returns null.- * It is assumed that an address will only occur within a single MSub- */- private CodeBlock getSubFromCache(Address addr){- Object[] mapObjs = this.foundMSubs.getObjects(addr);- return mapObjs.length == 0 ? null : (CodeBlock) mapObjs[0];- }+ }++ /**+ * Compute an address set that represents all the addresses contained+ * in all instructions that are part of this block+ *+ * @param block code block to compute address set for.+ */+ public AddressSetView getAddressSet(CodeBlock block) {+ if (!(block.getModel() instanceof MultEntSubModel)) {+ throw new IllegalArgumentException();+ }++ return new AddressSet(block);+ }++ /**+ * Gets a subroutine from the cache containing addr. If none there, returns null.+ * It is assumed that an address will only occur within a single MSub+ */+ private CodeBlock getSubFromCache(Address addr) {+ Object[] mapObjs = this.foundMSubs.getObjects(addr);+ return mapObjs.length == 0 ? null : (CodeBlock) mapObjs[0];+ }/*** @see ghidra.program.model.block.CodeBlockModel#getBasicBlockModel()*/+ @Overridepublic CodeBlockModel getBasicBlockModel() {if (bbModel == null) {bbModel = new SimpleBlockModel(program);@@ -452,13 +480,15 @@ public class MultEntSubModel implements SubroutineBlockModel {/*** @see ghidra.program.model.block.CodeBlockModel#getName()*/+ @Overridepublic String getName() {return NAME;}-+/*** @see ghidra.program.model.block.SubroutineBlockModel#getBaseSubroutineModel()*/+ @Overridepublic SubroutineBlockModel getBaseSubroutineModel() {return this;}@@ -466,6 +496,7 @@ public class MultEntSubModel implements SubroutineBlockModel {/*** @see ghidra.program.model.block.CodeBlockModel#allowsBlockOverlap()*/+ @Overridepublic boolean allowsBlockOverlap() {return false;}@@ -473,6 +504,7 @@ public class MultEntSubModel implements SubroutineBlockModel {/*** @see ghidra.program.model.block.CodeBlockModel#externalsIncluded()*/+ @Overridepublic boolean externalsIncluded() {return includeExternals;}