Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7111 libraries are no longer namespaces

ghidragon9e18c95305d0
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewReferenceManager.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewReferenceManager.java
index e91535c7ad..a5af1d13e4 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewReferenceManager.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewReferenceManager.java
@@ -15,7 +15,7 @@
*/
package ghidra.trace.database.program;
-import static ghidra.lifecycle.Unfinished.TODO;
+import static ghidra.lifecycle.Unfinished.*;
import java.util.*;
import java.util.function.Function;
@@ -26,6 +26,7 @@ import javax.help.UnsupportedOperationException;
import generic.util.FlattenedIterator;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.Register;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Variable;
import ghidra.program.model.symbol.*;
import ghidra.trace.database.symbol.DBTraceReference;
@@ -129,7 +130,8 @@ public abstract class AbstractDBTraceProgramViewReferenceManager implements Refe
}
@Override
- public Reference addExternalReference(Address fromAddr, Namespace extNamespace, String extLabel,
+ public Reference addExternalReference(Address fromAddr, Library library, Namespace extNamespace,
+ String extLabel,
Address extAddr, SourceType source, int opIndex, RefType type)
throws InvalidInputException, DuplicateNameException {
throw new UnsupportedOperationException();
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java
index 6c151204b6..189c5f3999 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java
@@ -26,7 +26,7 @@ import ghidra.trace.database.DBTraceUtils;
import ghidra.trace.database.symbol.*;
import ghidra.trace.model.Lifespan;
import ghidra.trace.model.symbol.*;
-import ghidra.util.*;
+import ghidra.util.LockHold;
import ghidra.util.exception.*;
public class DBTraceProgramViewSymbolTable implements SymbolTable {
@@ -309,6 +309,12 @@ public class DBTraceProgramViewSymbolTable implements SymbolTable {
symbolManager.allSymbols().getChildren(assertTraceNamespace(namespace)).iterator());
}
+ @Override
+ public SymbolIterator getSymbols(Library library) {
+ // revisit in GP-7207
+ return new SymbolIteratorAdapter(new ArrayList<Symbol>().iterator());
+ }
+
@Override
public SymbolIterator getSymbols(long namespaceID) {
AbstractDBTraceSymbol sym = symbolManager.getSymbolByID(namespaceID);
@@ -400,6 +406,11 @@ public class DBTraceProgramViewSymbolTable implements SymbolTable {
return new SymbolIteratorAdapter(Collections.emptyIterator());
}
+ @Override
+ public SymbolIterator getExternalSymbolByOriginalImportName(Library library, String extLabel) {
+ return new SymbolIteratorAdapter(Collections.emptyIterator());
+ }
+
@Override
public SymbolIterator getSymbolIterator(boolean forward) {
return new SymbolIteratorAdapter(getSymbolIteratorAtMySnap(symbolManager.labels(),
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/symbol/TraceSymbol.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/symbol/TraceSymbol.java
index b3013ced39..975241ecfd 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/symbol/TraceSymbol.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/symbol/TraceSymbol.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,6 +17,7 @@ package ghidra.trace.model.symbol;
import java.util.Collection;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
@@ -96,4 +97,9 @@ public interface TraceSymbol extends Symbol {
*/
@Override
boolean isPinned();
+
+ @Override
+ default Library getLibrary() {
+ return null;
+ }
}
diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/GenSignatures.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/GenSignatures.java
index 36cadc1826..072c503c45 100755
--- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/GenSignatures.java
+++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/GenSignatures.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -333,30 +333,10 @@ public class GenSignatures {
private String extractExternalName(Symbol sym, CallRecord callRecord) {
String fullName = sym.getName(true);
- int ind = fullName.indexOf("::");
- String libraryName;
- if (ind >= 0) {
- libraryName = fullName.substring(0, ind); // First namespace is name of library
- String tmpnm = fullName.substring(ind + 2); // Cut off first namespace
- if (tmpnm.isEmpty()) {
- libraryName = "unknown";
- callRecord.funcname = fullName;
- }
- else if (libraryName.isEmpty()) {
- libraryName = "unknown";
- callRecord.funcname = tmpnm;
- }
- else {
- callRecord.funcname = tmpnm;
- }
- if (libraryName.equals(Library.UNKNOWN)) {
- libraryName = "unknown";
- }
- }
- else {
- libraryName = "unknown";
- callRecord.funcname = fullName;
- }
+ Library library = sym.getLibrary();
+
+ String libraryName = library == null ? "unknown" : library.getName();
+ callRecord.funcname = fullName;
return libraryName;
}
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest
index 7706f188ff..b68a283f7c 100644
--- a/Ghidra/Features/Base/certification.manifest
+++ b/Ghidra/Features/Base/certification.manifest
@@ -735,6 +735,7 @@ src/main/help/help/topics/SymbolTreePlugin/SymbolTree.htm||GHIDRA||||END|
src/main/help/help/topics/SymbolTreePlugin/images/CreateExternalLocation.png||GHIDRA||||END|
src/main/help/help/topics/SymbolTreePlugin/images/EditExternalLocation.png||GHIDRA||||END|
src/main/help/help/topics/SymbolTreePlugin/images/SymbolTree.png||GHIDRA||||END|
+src/main/help/help/topics/SymbolTreePlugin/images/SymbolTreeSettings.png||GHIDRA||||END|
src/main/help/help/topics/Tool/Configure_Tool.htm||GHIDRA||||END|
src/main/help/help/topics/Tool/Ghidra_Tool_Administration.htm||GHIDRA||||END|
src/main/help/help/topics/Tool/ShowLog.htm||GHIDRA|||References wcbiema in screen snapshot|END|
diff --git a/Ghidra/Features/Base/data/base.icons.theme.properties b/Ghidra/Features/Base/data/base.icons.theme.properties
index 5cb285e819..ceb65fc125 100644
--- a/Ghidra/Features/Base/data/base.icons.theme.properties
+++ b/Ghidra/Features/Base/data/base.icons.theme.properties
@@ -309,6 +309,8 @@ icon.plugin.symboltree.node.category.function.closed = closedFolderFunctions.png
icon.plugin.symboltree.node.category.function.open = openFolderFunctions.png
icon.plugin.symboltree.node.category.exports.closed = closedFolder.png
icon.plugin.symboltree.node.category.exports.open = openFolder.png
+icon.plugin.symboltree.node.category.globals.closed = closedFolder.png
+icon.plugin.symboltree.node.category.globals.open = openFolder.png
icon.plugin.symboltree.node.category.imports.closed = closedFolderExternals.png
icon.plugin.symboltree.node.category.imports.open = openFolderExternals.png
icon.plugin.symboltree.node.category.label.closed = closedFolderLabels.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Repository/Merge_Program_Files.htm b/Ghidra/Features/Base/src/main/help/help/topics/Repository/Merge_Program_Files.htm
index ffb09d9b2d..4150b06bb3 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Repository/Merge_Program_Files.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/Repository/Merge_Program_Files.htm
@@ -443,10 +443,8 @@
of the function.</LI>
<LI>If a variable name conflicts with a variable or symbol of the same name in the
- function's <A href=
- "help/topics/SymbolTreePlugin/SymbolTree.htm#Namespace">namespace</A> of the latest
- version, that variable will automatically be renamed to a conflict name. This
- eliminates the name conflict.</LI>
+ function's namespace of the latest
+ version, that variable will automatically be renamed to a conflict name.</LI>
<LI>Making changes to existing parameters such as the name, data type, or description
if the latest version didn't change the same part of the parameter.</LI>
@@ -1635,8 +1633,7 @@
<P>All symbol conflicts that remain after the <A href=
"Merge_Program_Files.htm#SymbolsAuto">auto merge</A> must be resolved.</P>
- <P>The symbol phase of the Listing merge will merge labels, <A href=
- "help/topics/SymbolTreePlugin/SymbolTree.htm#Namespace">namespace</A> symbols, class
+ <P>The symbol phase of the Listing merge will merge labels, namespace symbols, class
symbols, and external symbols.<BR>
The following are the types of symbol conflicts that require manual resolution:</P>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/SymbolTree.htm b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/SymbolTree.htm
index 517496dc42..e1f262a5ac 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/SymbolTree.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/SymbolTree.htm
@@ -16,8 +16,8 @@
<H1><A name="Manage_Symbol_Tree"></A><A name="Symbol_Tree"></A>Symbol Tree</H1>
<P>The Symbol Tree shows symbols from a program in a hierarchical view. The Symbol tree is
- organized by the following categories: <I>Externals</I>, <I>Function</I>, <I>Labels</I>,
- <I>Classes</I>, and <I>Namespaces</I>.</P>
+ organized by the following categories: <I>Imports</I>, <I>Exports</I>, <I>Globals</I>,
+ and <I>Namespaces</I>.</P>
<P align="left">To display the Symbol Tree, select the icon <IMG alt="" src=
"images/sitemap_color.png"> on the tool bar, OR select the option <B>Window</B><IMG alt="" src=
@@ -28,68 +28,49 @@
<H2>Display</H2>
<BLOCKQUOTE>
- <P>The root of the Symbol Tree is the <I>Global</I> <I>namespace</I>. A <I><A name=
- "Namespace"></A>Namespace</I>&nbsp; defines a scope, such that symbol names are unique
- <I>within</I> a namespace. The types of namespaces that Ghidra supports are <B>Global</B>,
- <B>External</B>, <B>Function</B>, <B>Class</B>, and <A name="GenericNamespace"></A> "generic"
- <B>Namespaces</B> that reside in the global namespace. Every namespace has an associated
- symbol.</P>
+ <P>The top level categories within the root symbol tree node each has a specific purpose and
+ are described below:</P>
<UL>
- <LI>The <B><A name="Externals"></A>Imports</B> category contains symbols that represent
- external library namespaces which in turn contain anything considered to be "external" to
- the program such as external locations/functions. The library name "&lt;EXTERNAL&gt;" is
- reserved to hold those external symbols which have not yet been associated with a specific
- library.</LI>
-
- <LI>The <SPAN style="font-style: italic;">exports</SPAN> category contains symbols that
- represent exported entry points into the program.<BR>
- </LI>
-
- <LI>The <B>Functions</B> category contains symbols that represent functions within the
- program (excluding external functions). Expand a function symbol to show its parameter and
- variable symbols.</LI>
-
- <LI>All&nbsp; symbols in the <B>Labels</B> category are in the Global namespace.</LI>
-
- <LI>The <B>Class</B> category contains class namespaces that may contain function
- namespaces or label symbols. Class namespaces reside in the global namespace.</LI>
-
- <LI>
- The <B>Namespace</B> category contains generic namespaces that reside in the Global
- namespace, and may contain class, function, label, or other namespaces.&nbsp;
-
- <UL>
- <LI>The <A href="help/topics/ImporterPlugin/importer.htm">import</A> process creates a
- namespace (under the <I>Namespace</I> category) for each external library it
- encounters. (The name is created as _&lt;library name&gt;, e.g., _USER32.DLL,&nbsp; to
- avoid naming collisions with the external library symbols, under <I>Externals</I>,
- e.g., USER32.DLL.)</LI>
-
- <LI>Based upon the importer capability and/or analysis, external locations or functions
- may be associated with a <I>Library</I> namespace.&nbsp; You will find these external
- location/function symbols under the <I>Imports</I> category node.</LI>
-
- <LI>Any function node (internal or external) may be expanded to show parameters. In
- addition, various popup function actions are available to modify the function. An
- external location may be converted to a function using the <I>Create External
- Function</I> popup action.</LI>
- </UL>
- </LI>
+ <LI><A name="Externals">
+ <B>Imports:</B> This category shows a tree node for each external library defined in this
+ program. Under each library node, all the external labels and functions associated with
+ that library will have corresponding nodes, orgnanized by their namespace. The library name
+ "&lt;EXTERNAL&gt;" is used as a default node to show any external symbols where the library
+ is not known. Note: unlike previous versions of Ghidra, external libraries do not represent
+ a namespace.</LI>
+
+ <LI><B>Exports:</B> This category includes all labels or functions that have been tagged as
+ an exported entry point into the program.</LI>
+
+ <LI><B>Globals:</B> This category shows all labels and Functions that are in the global
+ namespace. If there a more than a handful of global labels, they will be organized by name
+ into groups based on common name prefixes. Note: non-global labels and functions will appear
+ in the Namespaces category under their assigned namespace.</LI>
+
+ <LI><B>Namespaces:</B> This category shows all non-global labels and functions, organized by
+ their namespace/class.</LI>
</UL>
- <P align="left"><A name="GroupNode"></A>When the label or function category has many elements, the
- Symbol Tree will show <I>group nodes</I> that represent groups of symbols in order to reduce
- the "clutter" in the tree. In the sample image above, the <I>Labels</I> category contains a
- group node (indicated by the <IMG alt="" src="images/openFolderGroup.png"> icon). The
- <I>group node</I> shows the common prefix for all the symbols in the group. The tool tip
- will display the total number of nodes in the group.</P>
+ <P>Any function node (internal or external) may be expanded to show parameters. In addition,
+ various popup function actions are available to modify the function. An external location may
+ be converted to a function using the <I>Create External Function</I> popup action.</P>
+
+ <P align="left"><A name="GroupNode"></A>When a top level category has too many
+ elements, the Symbol Tree will show <I>group nodes</I> that represent groups of symbols in
+ order to reduce the "clutter" in the tree. In the sample image above, the <I>Labels</I>
+ category contains a group node (indicated by the <IMG alt="" src=
+ "images/openFolderGroup.png"> icon). The <I>group node</I> shows the common prefix for all
+ the symbols in the group. The tool tip will display the total number of nodes in the
+ group.</P>
+
<P>The group nodes can become out of balance if enough symbols are added/deleted/renamed. The
- entire category can be reorganized by closing and reopening the category node (Functions, Labels).
- Also, the tree will detect if the organization becomes too far out of balance. In this case, the
- category node (Functions, Labels) will automatically close. Typically, this would be caused by
- a long running bulk operation such as analysis. This has the added benefit of
- speeding up the bulk operation as it will no longer have to keep updating the nodes in the tree.</P>
+ entire category can be reorganized by closing and reopening the category node (Functions,
+ Labels). Also, the tree will detect if the organization becomes too far out of balance. In
+ this case, the category node (Functions, Labels) will automatically close. Typically, this
+ would be caused by a long running bulk operation such as analysis. This has the added benefit
+ of speeding up the bulk operation as it will no longer have to keep updating the nodes in the
+ tree.</P>
<BLOCKQUOTE>
<P align="left"><IMG alt="" src="help/shared/note.png"> The Symbol Tree does not show
@@ -99,14 +80,28 @@
"help/topics/SymbolTablePlugin/symbol_table.htm#Set_Filter">filter</A> for user-defined
symbols.</P>
</BLOCKQUOTE>
- </BLOCKQUOTE>
+
+ <H3><A name="Symbol_Tree_Filter"></A>Symbol Tree Filter Settings</H3>
+ <P>The symbol tree can be configured to filter out top level categorires and some symbol
+ types. Press the <IMG alt="" src="Icons.CONFIGURE_FILTER_ICON"> icon on the local
+ toolbar to bring up the filter settings.</P>
+ <P align="center"><IMG alt="" src="images/SymbolTreeSettings.png"></P>
+ <P> The <B>Symbol Categories</B> section in the dialog allows you to pick which top level
+ categories to display in the tree. At least one category must be selected.</P>
+
+ <P> The <B>Symbol Types</B> section allows you to filter out Function or Label symbols from
+ anywhere in the tree. To filter out function or labels, unselect the corresponding
+ checkbox. If you filter out both labels and functions, there won't be much left in the tree
+ other than libraries, namespaces, and classes. You can't filter out libraries, namespaces,
+ or classes because they are container classes and must be there to show other types.</P>
+
- <DIV STYLE="margin-top:50px; margin-bottom:50px">
- <HR width="90%">
+ </BLOCKQUOTE>
+ <DIV style="margin-top:50px; margin-bottom:50px">
+ <HR width="90%">
</DIV>
-
- <P>Each group below lists operations that can be performed via the Symbol Tree.</P>
+ <P>Each group below lists operations that can be performed via the Symbol Tree.</P>
<H2><A name="Create_Library"></A>Create a Library</H2>
@@ -138,22 +133,21 @@
<P>You can create a <I>External Location</I> used to refer to a location or function in a
external library. Right mouse click on the Imports node or on a particular library and choose
the <B>Create External Location</B> option. If invoked from a specific library node, the
- <I>External Program Name</I> will default to that library for the location being created.
- The default library <i>&lt;EXTERNAL&gt;</i> should be used when the library is unknown.
- Otherwise you can type the name in the field or choose it from the combo box list. The
- <I>External Program Path</I>, which is the program in the project which corresponds to the
- named library, will
- be filled in if there is an associated program in the project. Otherwise, it can be selected via the
- <I>Edit</I> button, which displays a chooser dialog. Either a <I>Label</I>, an
- <I>Address</I>, or both must be specified for the External Location. If you check the <I>Make
- External Function</I> box, then an external function will be created. Otherwise, if you don't
- check the box, a non-function external location gets created. The ability to associate a
- data type with the location is not yet supported. Press the <I>Create</I> button to create the
- external location.</P>
+ <I>External Program Name</I> will default to that library for the location being created. The
+ default library <I>&lt;EXTERNAL&gt;</I> should be used when the library is unknown. Otherwise
+ you can type the name in the field or choose it from the combo box list. The <I>External
+ Program Path</I>, which is the program in the project which corresponds to the named library,
+ will be filled in if there is an associated program in the project. Otherwise, it can be
+ selected via the <I>Edit</I> button, which displays a chooser dialog. Either a <I>Label</I>,
+ an <I>Address</I>, or both must be specified for the External Location. If you check the
+ <I>Make External Function</I> box, then an external function will be created. Otherwise, if
+ you don't check the box, a non-function external location gets created. The ability to
+ associate a data type with the location is not yet supported. Press the <I>Create</I> button
+ to create the external location.</P>
<P>The following dialog shows a external function being created. It will be named "Sample"
- and is in "TestLibrary" at address 01001234. The library name, TestLibrary, is
- associated with "libraryA" in the project.</P>
+ and is in "TestLibrary" at address 01001234. The library name, TestLibrary, is associated
+ with "libraryA" in the project.</P>
<P align="center"><IMG alt="" src="images/CreateExternalLocation.png"></P>
</BLOCKQUOTE>
@@ -161,26 +155,28 @@
<H2><A name="Edit_External_Location"></A>Edit External Location</H2>
<BLOCKQUOTE>
- <P>You can edit the external location and associated library details for any <I>External Location</I>
- symbol within the symbol tree (including locations which have been converted to an external function).
- Right mouse click on
- the external location/function node in the symbol tree under Imports and choose the <B>Edit External
- Location</B> action. </P>
- <P>The Edit External Location dialog will default to the current
- values for the location being edited. You can change the <I>External Program Name</I> in the
- field or by selecting a different one from the combo box list. The <I>External Program
- Path</I>, which is the program in the project corresponding to the named library, will be filled in if
- there is an associated program. Otherwise, it can be selected via the <I>Edit</I> button,
- which displays a chooser dialog. You can modify the <I>Label</I> and/or <I>Address</I> for
- the location being edited. Either a <I>Label</I>, an <I>Address</I>, or both must be
- specified for the external location. Press the <I>Update</I> button to apply your edits to
- the external location or function.</P>
- <P>If the location was initially created by the importer, and was subsequently demangled or changed,
- the <I>Original Label</I> will be specified. While you can not change this original name, you can revert
- the location to this label by clicking the <I>Restore</I> button. If the symbol was not an imported symbol
- or has never been demangled or changed the <I>Original Label</I> and <I>Restore</I> button will not be displayed.
-
- <P align="center"><IMG alt="" src="images/EditExternalLocation.png"></P>
+ <P>You can edit the external location and associated library details for any <I>External
+ Location</I> symbol within the symbol tree (including locations which have been converted to
+ an external function). Right mouse click on the external location/function node in the symbol
+ tree under Imports and choose the <B>Edit External Location</B> action.</P>
+
+ <P>The Edit External Location dialog will default to the current values for the location
+ being edited. You can change the <I>External Program Name</I> in the field or by selecting a
+ different one from the combo box list. The <I>External Program Path</I>, which is the program
+ in the project corresponding to the named library, will be filled in if there is an
+ associated program. Otherwise, it can be selected via the <I>Edit</I> button, which displays
+ a chooser dialog. You can modify the <I>Label</I> and/or <I>Address</I> for the location
+ being edited. Either a <I>Label</I>, an <I>Address</I>, or both must be specified for the
+ external location. Press the <I>Update</I> button to apply your edits to the external
+ location or function.</P>
+
+ <P>If the location was initially created by the importer, and was subsequently demangled or
+ changed, the <I>Original Label</I> will be specified. While you can not change this original
+ name, you can revert the location to this label by clicking the <I>Restore</I> button. If the
+ symbol was not an imported symbol or has never been demangled or changed the <I>Original
+ Label</I> and <I>Restore</I> button will not be displayed.</P>
+
+ <P align="center"><IMG alt="" src="images/EditExternalLocation.png"></P>
</BLOCKQUOTE>
<H2><A name="Show_References_to"></A>Show References to</H2>
@@ -192,8 +188,8 @@
<H2><A name="Convert_to_Class"></A>Convert Namespace to Class</H2>
<BLOCKQUOTE>
- <P>You can convert a <I>Namespace</I> to a <I>Class</I>.
- Right mouse click on a namespace and choose the <B>Convert To Class</B> option.</P>
+ <P>You can convert a <I>Namespace</I> to a <I>Class</I>. Right mouse click on a namespace and
+ choose the <B>Convert To Class</B> option.</P>
</BLOCKQUOTE>
<H2><A name="Create_Class"></A>Create a Class</H2>
@@ -295,7 +291,6 @@
<BLOCKQUOTE>
<P>To delete a symbol, make a selection of symbols, right mouse click and choose the
<B>Delete</B> option.</P>
-
</BLOCKQUOTE>
<H2><A name="Make_Selection"></A>Make a Selection</H2>
@@ -307,42 +302,40 @@
you select a <A href="#GroupNode">group node</A> for the <B>Make Selection</B> option, all
symbols in that group are selected in the Code Browser.</P>
</BLOCKQUOTE>
+
+ <H2><A name="Collapse_All"></A>Collapse All <IMG alt="" src="Icons.COLLAPSE_ALL_ICON"></H2>
+ <P>The <B>Collapse All</B> toolbar action closes all open category nodes in the tree,
+ restoring it to its initial display state</P>
<H2><A name="Navigate_To"></A>Navigation <IMG alt="" src="images/locationIn.gif"></H2>
<BLOCKQUOTE>
-
<H3><A name="Navigate_on_Incoming"></A>Navigating on Program Location Changes</H3>
<BLOCKQUOTE>
- <P>The <IMG alt="" src="icon.navigate.in"> button controls whether a symbol is
- selected in the Symbol Tree when you click in the Code Browser. While the <IMG alt=""
- src="icon.navigate.in"> button is selected, if the location from the Code
- Browser can be interpreted as a symbol, the symbol is automatically selected in the Symbol
- Tree. This action is off by default. The state of the
- <IMG alt="" src="icon.navigate.in"> button is
+ <P>The <IMG alt="" src="icon.navigate.in"> button controls whether a symbol is selected in
+ the Symbol Tree when you click in the Code Browser. While the <IMG alt="" src=
+ "icon.navigate.in"> button is selected, if the location from the Code Browser can be
+ interpreted as a symbol, the symbol is automatically selected in the Symbol Tree. This
+ action is off by default. The state of the <IMG alt="" src="icon.navigate.in"> button is
saved when you close the project or exit Ghidra and restored when you reopen the
project.</P>
</BLOCKQUOTE>
-
-
- <H3><A name="Navigate_on_Outgoing"></A>Navigating on Symbol Changes</H3>
-
- <BLOCKQUOTE>
- <P>The <IMG alt="" src="icon.navigate.out"> button controls whether a Code Browser
- navigation happens when symbol is selected. This action is on by default.
- The state of the <IMG alt="" src="icon.navigate.out"> button is saved when you close the
- project or exit Ghidra and restored when you reopen the project.</P>
- </P>
- </BLOCKQUOTE>
-
-
+
+ <H3><A name="Navigate_on_Outgoing"></A>Navigating on Symbol Changes</H3>
+
+ <BLOCKQUOTE>
+ <P>The <IMG alt="" src="icon.navigate.out"> button controls whether a Code Browser
+ navigation happens when symbol is selected. This action is on by default. The state of the
+ <IMG alt="" src="icon.navigate.out"> button is saved when you close the project or exit
+ Ghidra and restored when you reopen the project.</P>
+ </BLOCKQUOTE>
<H3><A name="Go_To_External_Location"></A>Navigating to External Locations</H3>
<BLOCKQUOTE>
- <P>If you select an external symbol (under the <I>Externals</I> folder in the symbol
- tree), you will navigate to an external <I>reference</I> <I>source</I> which has a
+ <P>If you select an external symbol (under the <I>Externals</I> folder in the symbol tree),
+ you will navigate to an external <I>reference</I> <I>source</I> which has a
<I>destination</I> corresponding to the external symbol (i.e., where it is being called
from). To actually <B>go to</B> the external location, right mouse click on the external
symbol and choose <B>Go To External Location</B>.&nbsp;&nbsp;</P>
@@ -358,7 +351,7 @@
</BLOCKQUOTE>
<H2>View Qualified Names in Code Browser</H2>
-
+
<BLOCKQUOTE>
<P>To include namespace names in the display of labels and names within the Code Browser,
select <B>Edit</B> <IMG alt="" src="help/shared/arrow.gif"> <B>Tool Options...</B> from the
@@ -369,57 +362,46 @@
"help/topics/CodeBrowserPlugin/CodeBrowserOptions.htm">CodeBrowser Options</A>).<BR>
</P>
</BLOCKQUOTE>
-
-
- <H2><A NAME="Create_Table"></A>Create Table From Selection</H2>
-
+
+ <H2><A name="Create_Table"></A>Create Table From Selection</H2>
+
<BLOCKQUOTE>
- <P>Create a new temporary
- <A HREF="help/topics/SymbolTablePlugin/symbol_table_transient.htm">Symbol Table</A> with the symbols
- in the current selection. The table's features are similar to the
- <A HREF="help/topics/Search/Query_Results_Dialog.htm">search results table.</A>
- </P>
+ <P>Create a new temporary <A href=
+ "help/topics/SymbolTablePlugin/symbol_table_transient.htm">Symbol Table</A> with the symbols
+ in the current selection. The table's features are similar to the <A href=
+ "help/topics/Search/Query_Results_Dialog.htm">search results table.</A></P>
</BLOCKQUOTE>
-
-
-
+
<H2>Symbol Tree Snapshots</H2>
<BLOCKQUOTE>
- <P>Pressing the <IMG SRC="icon.provider.clone" /> action will create a copy of the current
- Symbol Tree in a new window. The new disconnected Symbol Tree will not respond to program
- activation events. This allows users to keep the new window open while working with various
- programs, without affecting the contents.
- </P>
+ <P>Pressing the <IMG alt="" src="icon.provider.clone"> action will create a copy of the
+ current Symbol Tree in a new window. The new disconnected Symbol Tree will not respond to
+ program activation events. This allows users to keep the new window open while working with
+ various programs, without affecting the contents.</P>
- <H3><A name="Symbol_Tree_Clone"></A>Symbol Tree Clone Action <IMG SRC="icon.provider.clone" /></H3>
-
- <BLOCKQUOTE>
- <P>Creates a new disconnected snapshot (cloned) view of the Symbol Tree. This action is on
- the primary Symbol Tree, as well as any cloned symbol trees.</P>
- </BLOCKQUOTE>
-
- <H3><A name="Disable_Category"></A>Disable Category</H3>
-
- <BLOCKQUOTE>
- <P>When working in a snapshot Symbol Tree, you can choose to disable a root-level folder
- by right-clicking and selected <B>Disable Category</B>. Once disabled, the node will remain
- in the tree with a disabled icon. A disabled node will no longer show any children.
- </P>
- </BLOCKQUOTE>
-
- <H3><A name="Enable_Category"></A>Enable Category</H3>
-
- <BLOCKQUOTE>
- <P>This action is used to re-enable categories that were previously disabled.
- </P>
- </BLOCKQUOTE>
-
- </BLOCKQUOTE>
-
+ <H3><A name="Symbol_Tree_Clone"></A>Symbol Tree Clone Action <IMG alt="" src=
+ "icon.provider.clone"></H3>
+ <BLOCKQUOTE>
+ <P>Creates a new disconnected snapshot (cloned) view of the Symbol Tree. This action is on
+ the primary Symbol Tree, as well as any cloned symbol trees.</P>
+ </BLOCKQUOTE>
+
+ <H3><A name="Disable_Category"></A>Disable Category</H3>
+
+ <BLOCKQUOTE>
+ <P>When working in a snapshot Symbol Tree, you can choose to disable a root-level folder by
+ right-clicking and selected <B>Disable Category</B>. Once disabled, the node will remain in
+ the tree with a disabled icon. A disabled node will no longer show any children.</P>
+ </BLOCKQUOTE>
+ <H3><A name="Enable_Category"></A>Enable Category</H3>
+ <BLOCKQUOTE>
+ <P>This action is used to re-enable categories that were previously disabled.</P>
+ </BLOCKQUOTE>
+ </BLOCKQUOTE>
<P class="providedbyplugin">Provided By: <I>SymbolTreePlugin</I></P>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/CreateExternalLocation.png b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/CreateExternalLocation.png
index 2898e30d88..36e775a11c 100644
Binary files a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/CreateExternalLocation.png and b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/CreateExternalLocation.png differ
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/EditExternalLocation.png b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/EditExternalLocation.png
index 62f57b99af..ec637f6133 100644
Binary files a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/EditExternalLocation.png and b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/EditExternalLocation.png differ
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTree.png b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTree.png
index 8dfcbb502a..1112d5062e 100644
Binary files a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTree.png and b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTree.png differ
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTreeSettings.png b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTreeSettings.png
new file mode 100644
index 0000000000..02ccf37d5e
Binary files /dev/null and b/Ghidra/Features/Base/src/main/help/help/topics/SymbolTreePlugin/images/SymbolTreeSettings.png differ
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateExternalFunctionCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateExternalFunctionCmd.java
index 170d31613b..615c058f06 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateExternalFunctionCmd.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateExternalFunctionCmd.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,12 +27,9 @@ public class CreateExternalFunctionCmd implements Command<Program> {
private Symbol extSymbol;
private String libraryName;
- private Namespace parentNamespace;
private String name;
private Address address;
-
private SourceType source;
-
private String status;
/**
@@ -68,31 +65,6 @@ public class CreateExternalFunctionCmd implements Command<Program> {
this.source = source;
}
- /**
- * Create an external function in the specified external namespace.
- * @param externalParentNamespace the external parent namespace where the named function should be created (required)
- * @param name function name (required)
- * @param address the address of the function's entry point in the external library (optional)
- * @param source the source type for this external function
- */
- public CreateExternalFunctionCmd(Namespace externalParentNamespace, String name,
- Address address, SourceType source) {
- if (externalParentNamespace == null || name.length() == 0) {
- throw new IllegalArgumentException("A parent namespace must be specified.");
- }
- if (!externalParentNamespace.isExternal()) {
- throw new IllegalArgumentException(
- "The parent namespace must be an external namespace.");
- }
- this.parentNamespace = externalParentNamespace;
- this.name = name;
- this.address = address;
- if (source == null) {
- throw new IllegalArgumentException("Source cannot be null");
- }
- this.source = source;
- }
-
@Override
public boolean applyTo(Program program) {
@@ -118,13 +90,7 @@ public class CreateExternalFunctionCmd implements Command<Program> {
private boolean createExternalFunction(Program program) {
try {
ExternalManager extMgr = program.getExternalManager();
- ExternalLocation extLoc;
- if (parentNamespace == null) {
- extLoc = extMgr.addExtFunction(libraryName, name, address, source);
- }
- else {
- extLoc = extMgr.addExtFunction(parentNamespace, name, address, source);
- }
+ ExternalLocation extLoc = extMgr.addExtFunction(libraryName, name, address, source);
extSymbol = extLoc.getSymbol();
return true;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java
index 28ca122bb1..12be380215 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java
@@ -462,7 +462,7 @@ public class CreateThunkFunctionCmd extends BackgroundCommand<Program> {
}
final AtomicInteger foundCount = new AtomicInteger(0);
- SymbolicPropogator prop = new SymbolicPropogator(program,false);
+ SymbolicPropogator prop = new SymbolicPropogator(program, false);
// try to compute the thunk by flowing constants from the start of the block
prop.flowConstants(jumpBlockAt.getFirstStartAddress(), jumpBlockAt,
@@ -702,7 +702,7 @@ public class CreateThunkFunctionCmd extends BackgroundCommand<Program> {
Symbol externalSymbol = null;
for (Symbol symbol : symbolTable.getSymbols(s.getName())) {
// Only consider external symbols directly in a Library root Namespace
- if (!symbol.isExternal() || !symbol.getParentNamespace().isLibrary()) {
+ if (!symbol.isExternal() || !symbol.getParentNamespace().isGlobal()) {
continue;
}
if (externalSymbol != null) {
@@ -766,21 +766,21 @@ public class CreateThunkFunctionCmd extends BackgroundCommand<Program> {
// conditional jumps/call terminators can't be thunks,
// unless not checkingForSideEffects and just trying to get possible thunk address.
-
+
boolean isJump = flowType.isJump();
boolean isCall = flowType.isCall();
boolean isConditional = flowType.isConditional();
-
+
// only jump/call are allowed
if (!(isJump || isCall)) {
return null;
}
-
+
// no conditional jumps allowed
if (isJump && isConditional) {
return null;
}
-
+
if (isCall) {
// Any conditional call considered as having side-effects
if (isConditional && checkForSideEffects) {
@@ -797,7 +797,7 @@ public class CreateThunkFunctionCmd extends BackgroundCommand<Program> {
}
}
}
-
+
// program counter should be assumed to be used
// assume PC is used when considering registers that have been set
Register PC = program.getLanguage().getProgramCounter();
@@ -818,12 +818,12 @@ public class CreateThunkFunctionCmd extends BackgroundCommand<Program> {
}
Address flowingAddr = null;
-
+
// if not checking for sideEffect registers set, or there are no side-effects
if (!checkForSideEffects || setRegisters.size() == 0) {
flowingAddr = getFlowingAddress(program, instr);
}
-
+
return flowingAddr;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalFunctionMerger.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalFunctionMerger.java
index b10aea1e5c..613d3f4c27 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalFunctionMerger.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalFunctionMerger.java
@@ -26,7 +26,6 @@ import ghidra.app.merge.MergeConstants;
import ghidra.app.merge.MergeManager;
import ghidra.app.merge.tool.ListingMergePanel;
import ghidra.app.merge.util.ConflictUtility;
-import ghidra.app.util.NamespaceUtils;
import ghidra.program.model.address.*;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
@@ -63,7 +62,7 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
private final static String INFO_TITLE = CONFLICT_TYPE + " Merge Information";
private final static String ERROR_TITLE = CONFLICT_TYPE + " Merge Errors";
- static protected final int EXTERNAL_NAMESPACE = 0x001;
+ static protected final int EXTERNAL_LIBRARY = 0x001;
static protected final int EXTERNAL_LABEL = 0x002;
static protected final int EXTERNAL_ADDRESS = 0x004;
// Source Type differences have been commented out.
@@ -73,11 +72,8 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
static protected final int EXTERNAL_DATA_TYPE = 0x020;
static protected final int EXTERNAL_FUNCTION = 0x040;
static protected final int HIGHEST_DETAIL_BIT_SHIFT = 6; // 0 based
- static protected final int ALL_EXTERNAL_DIFFERENCES = EXTERNAL_NAMESPACE | EXTERNAL_LABEL |
+ static protected final int ALL_EXTERNAL_DIFFERENCES = EXTERNAL_LIBRARY | EXTERNAL_LABEL |
EXTERNAL_ADDRESS | EXTERNAL_SYMBOL_TYPE | EXTERNAL_DATA_TYPE | EXTERNAL_FUNCTION;
-// static protected final int ALL_EXTERNAL_DIFFERENCES = EXTERNAL_NAMESPACE | EXTERNAL_LABEL |
-// EXTERNAL_ADDRESS | EXTERNAL_SOURCE_TYPE | EXTERNAL_SYMBOL_TYPE | EXTERNAL_DATA_TYPE |
-// EXTERNAL_FUNCTION;
/** Keep the external location added in LATEST to resolve a conflict. */
public static final int KEEP_LATEST_ADD = 1;
@@ -322,9 +318,6 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
}
private void initializeConflictSets() {
- AddressFactory myAddressFactory = programs[MY].getAddressFactory();
-// AddressFactory originalAddressFactory = programs[ORIGINAL].getAddressFactory();
-
externalDataTypeConflicts = new AddressSet();
externalFunctionVersusDataTypeConflicts = new AddressSet();
removeSet = new AddressSet();
@@ -717,28 +710,52 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// See if both changed to same value.
switch (type) {
- case EXTERNAL_NAMESPACE:
- replaceNamespace(resultExternalLocation, fromExternalLocation, monitor);
+ case EXTERNAL_LIBRARY:
+ replaceLibrary(resultExternalLocation, fromExternalLocation, monitor);
return;
case EXTERNAL_LABEL:
// TODO: The order of detail merge could be problematic since we can't set
// default label if EXTERNAL_ADDRESS is currently null.
- String fromLabel = fromExternalLocation.getLabel();
SourceType resultSource = resultExternalLocation.getSource();
SourceType fromSource = fromExternalLocation.getSource();
// If both are DEFAULT then no name to merge.
if (resultSource == SourceType.DEFAULT && fromSource == SourceType.DEFAULT) {
return; // Just return since default names may not match each other by their text.
}
+
+ String fromLabel = fromExternalLocation.getLabel();
+ String fromOrigName = fromExternalLocation.getOriginalImportedName();
try {
- resultExternalLocation.getSymbol().setName(fromLabel, fromSource);
+ Symbol resultSym = resultExternalLocation.getSymbol();
+
+ // Get the namespace we need from result.
+ Namespace fromNamespace = fromExternalLocation.getParentNameSpace();
+
+ if (fromNamespace.isGlobal() && fromOrigName == null &&
+ resultExternalLocation.getOriginalImportedName() != null) {
+ // assume result is in better state and should be retained as-is
+ return;
+ }
+
+ Namespace desiredResultNamespace =
+ resolveNamespace(programs[MY], fromNamespace);
+
+ // Update name w/ namespace and original import name
+ // We must revert result and apply name in proper order to ensure
+ // final result matches from symbol naming
+ resultExternalLocation.restoreOriginalName();
+ if (fromOrigName != null) {
+ resultSym.setNameAndNamespace(fromOrigName, null, SourceType.IMPORTED); // assume mangled name was imported
+ }
+ resultSym.setNameAndNamespace(fromLabel, desiredResultNamespace, fromSource);
}
- catch (DuplicateNameException e) {
- throw new AssertException("Can't happen now that duplicates are allowed");
+ catch (DuplicateNameException | CircularDependencyException e) {
+ throw new AssertException("Unexpected", e);
}
catch (InvalidInputException e) {
Msg.error(this,
- "Couldn't merge external location name '" + fromLabel + "'. " + e);
+ "Couldn't merge external location name '" +
+ fromExternalLocation.getSymbol().getName(true) + "'. " + e);
return;
}
return;
@@ -858,8 +875,10 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// Neither is null so lets compare them.
+ String libName1 = externalLocation1.getLibraryName();
Namespace namespace1 = externalLocation1.getParentNameSpace();
String label1 = externalLocation1.getLabel();
+ String origName1 = externalLocation1.getOriginalImportedName();
DataType dataType1 = getResultDataType(externalLocation1);
Address address1 = externalLocation1.getAddress();
SourceType sourceType1 = externalLocation1.getSource();
@@ -867,8 +886,10 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
SymbolType symbolType1 = symbol1.getSymbolType();
Function function1 = externalLocation1.getFunction();
+ String libName2 = externalLocation2.getLibraryName();
Namespace namespace2 = externalLocation2.getParentNameSpace();
String label2 = externalLocation2.getLabel();
+ String origName2 = externalLocation2.getOriginalImportedName();
DataType dataType2 = getResultDataType(externalLocation2);
Address address2 = externalLocation2.getAddress();
SourceType sourceType2 = externalLocation2.getSource();
@@ -878,10 +899,12 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// TODO: Does not consider original imported name
- if (!equivalentNamespaces(namespace1, namespace2)) {
- conflicts |= EXTERNAL_NAMESPACE;
+ if (!SystemUtilities.isEqual(libName1, libName2)) {
+ conflicts |= EXTERNAL_LIBRARY;
}
- if (!isSameLabel(label1, label2, sourceType1, sourceType2)) {
+ if (!equivalentNamespaces(namespace1, namespace2) ||
+ !isSameLabel(label1, label2, sourceType1, sourceType2) ||
+ !SystemUtilities.isEqual(origName1, origName2)) {
conflicts |= EXTERNAL_LABEL;
}
if (!SystemUtilities.isEqual(address1, address2)) {
@@ -933,6 +956,7 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// Neither is null so lets compare them.
+ String libName1 = externalLocation1.getLibraryName();
Namespace namespace1 = externalLocation1.getParentNameSpace();
String label1 = externalLocation1.getLabel();
boolean label1IsDefault = hasDefaultExternalName(externalLocation1);
@@ -945,7 +969,9 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
Function function1 = externalLocation1.getFunction();
String originalName1 = externalLocation1.getOriginalImportedName();
boolean external1IsFunction = function1 != null;
+ String libraryName1 = externalLocation1.getLibraryName();
+ String libName2 = externalLocation2.getLibraryName();
Namespace namespace2 = externalLocation2.getParentNameSpace();
String label2 = externalLocation2.getLabel();
boolean label2IsDefault = hasDefaultExternalName(externalLocation2);
@@ -958,6 +984,11 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
String originalName2 = externalLocation2.getOriginalImportedName();
Function function2 = externalLocation2.getFunction();
boolean external2IsFunction = function2 != null;
+ String libraryName2 = externalLocation2.getLibraryName();
+
+ if (!SystemUtilities.isEqual(libName1, libName2)) {
+ return true;
+ }
if (!equivalentNamespaces(namespace1, namespace2)) {
return true;
@@ -984,7 +1015,9 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
hasExternalFunctionAddConflicts(function1, function2)) {
return true;
}
-
+ if (!libraryName1.equals(libraryName2)) {
+ return true;
+ }
return false;
}
@@ -1064,9 +1097,11 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
}
// Neither is null so lets compare them.
-
+ boolean label1IsDefault = externalLocation1.getSource() == SourceType.DEFAULT;
+ String libName1 = externalLocation1.getLibraryName();
Namespace namespace1 = externalLocation1.getParentNameSpace();
String label1 = externalLocation1.getLabel();
+ String originalName1 = externalLocation1.getOriginalImportedName();
DataType dataType1 = getResultDataType(externalLocation1);
Address address1 = externalLocation1.getAddress();
// SourceType sourceType1 = externalLocation1.getSource();
@@ -1074,8 +1109,11 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
SymbolType symbolType1 = symbol1.getSymbolType();
Function function1 = externalLocation1.getFunction();
+ boolean label2IsDefault = externalLocation2.getSource() == SourceType.DEFAULT;
+ String libName2 = externalLocation2.getLibraryName();
Namespace namespace2 = externalLocation2.getParentNameSpace();
String label2 = externalLocation2.getLabel();
+ String originalName2 = externalLocation2.getOriginalImportedName();
DataType dataType2 = getResultDataType(externalLocation2);
Address address2 = externalLocation2.getAddress();
// SourceType sourceType2 = externalLocation2.getSource();
@@ -1083,10 +1121,19 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
SymbolType symbolType2 = symbol2.getSymbolType();
Function function2 = externalLocation2.getFunction();
+ if (!SystemUtilities.isEqual(libName1, libName2)) {
+ return false;
+ }
if (!equivalentNamespaces(namespace1, namespace2)) {
return false;
}
- if (!label1.equals(label2)) {
+ if (label1IsDefault) {
+ if (!label2IsDefault) {
+ return false;
+ }
+ }
+ else if (!SystemUtilities.isEqual(label1, label2) ||
+ !SystemUtilities.isEqual(originalName1, originalName2)) {
return false;
}
if (!isSameDataType(dataType1, dataType2)) {
@@ -1298,9 +1345,9 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
getBasicExternalDiffs(externalLocations[ORIGINAL], externalLocations[MY]);
int detailConflictFlags = 0;
- // Check and auto-merge the namespace.
+ // Check and auto-merge the library
detailConflictFlags |=
- determineBasicExternalConflict(externalLocations, EXTERNAL_NAMESPACE,
+ determineBasicExternalConflict(externalLocations, EXTERNAL_LIBRARY,
latestMyChanges, originalLatestChanges, originalMyChanges, monitor);
// Check and auto-merge the name and source type.
@@ -1664,6 +1711,7 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// Latest and My don't match.
// See what pieces can be auto-merged and which are conflicts.
+ String latestLibName = latestExternalLocation.getLibraryName();
Namespace latestNamespace = latestExternalLocation.getParentNameSpace();
String latestLabel = latestExternalLocation.getLabel();
DataType latestDataType = getResultDataType(latestExternalLocation);
@@ -1673,16 +1721,13 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
Function latestFunction = latestExternalLocation.getFunction();
boolean latestExternalIsFunction = (latestFunction != null);
+ String myLibName = myExternalLocation.getLibraryName();
Namespace myNamespace = myExternalLocation.getParentNameSpace();
- boolean myNamespaceIsDefault =
- (myNamespace.getSymbol().getSymbolType() == SymbolType.LIBRARY) &&
- (myNamespace.getName() == Library.UNKNOWN);
String myLabel = myExternalLocation.getLabel();
boolean myLabelIsDefault = hasDefaultExternalName(myExternalLocation);
DataType myDataType = getResultDataType(myExternalLocation);
boolean myDataTypeIsDefined = hasDefinedDataType(myExternalLocation);
Address myAddress = myExternalLocation.getAddress();
- String myOriginalName = myExternalLocation.getOriginalImportedName();
// SourceType mySourceType = myExternalLocation.getSource();
Function myFunction = myExternalLocation.getFunction();
boolean myExternalIsFunction = (myFunction != null);
@@ -1699,23 +1744,20 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
latestExternalLocation, myExternalLocation, originalLocation };
updateAddressTranslators(locations);
-// if (myOriginalName != null && latestOriginalName == null &&
-// myOriginalName.equals(latestLabel)) {
-// mergeExternalDetail(EXTERNAL_LABEL, resultExternalLocation, myExternalLocation,
-// monitor);
-// }
-
- if (!myNamespaceIsDefault && !equivalentNamespaces(latestNamespace, myNamespace)) {
- // Auto-merge MY namespace.
- mergeExternalDetail(EXTERNAL_NAMESPACE, resultExternalLocation, myExternalLocation,
+ if (!SystemUtilities.isEqual(latestLibName, myLibName)) {
+ // Auto-merge MY library.
+ mergeExternalDetail(EXTERNAL_LIBRARY, resultExternalLocation, myExternalLocation,
monitor);
}
- if (!myLabelIsDefault && !SystemUtilities.isEqual(latestLabel, myLabel) &&
- !SystemUtilities.isEqual(latestOriginalName, myLabel)) {
- // Auto-merge MY label.
- mergeExternalDetail(EXTERNAL_LABEL, resultExternalLocation, myExternalLocation,
- monitor);
+ if (!myLabelIsDefault) {
+ if (!equivalentNamespaces(latestNamespace, myNamespace) ||
+ !SystemUtilities.isEqual(latestLabel, myLabel) ||
+ !SystemUtilities.isEqual(latestOriginalName, myLabel)) {
+ // Auto-merge MY label w/ namespace and original import name.
+ mergeExternalDetail(EXTERNAL_LABEL, resultExternalLocation, myExternalLocation,
+ monitor);
+ }
}
if ((myAddress != null) && !SystemUtilities.isEqual(latestAddress, myAddress)) {
@@ -1761,8 +1803,14 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
ExternalLocation resultExternalLocation =
addExternal(myExternalLocation, getMergeMy(), monitor);
- if ((resultExternalLocation != null) &&
- !resultExternalLocation.getLabel().equals(myExternalLocation.getLabel())) {
+ if (resultExternalLocation == null) {
+ return null;
+ }
+ if (!equivalentNamespaces(resultExternalLocation.getParentNameSpace(),
+ myExternalLocation.getParentNameSpace()) ||
+ !resultExternalLocation.getLabel().equals(myExternalLocation.getLabel()) ||
+ !SystemUtilities.isEqual(resultExternalLocation.getOriginalImportedName(),
+ myExternalLocation.getOriginalImportedName())) {
renamedConflictIDs.add(resultExternalLocation.getSymbol().getID());
}
return resultExternalLocation;
@@ -1780,10 +1828,11 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
Namespace namespace = resolvedNamespace;
String name = externalLocation.getLabel();
SourceType sourceType = externalLocation.getSource();
+ Library library = listingMergeManager.resolveLibrary(programMerge.getOriginProgram(),
+ externalLocation.getLibrary());
String originalImportedName = externalLocation.getOriginalImportedName();
if (originalImportedName != null) {
- namespace = NamespaceUtils.getLibrary(namespace);
name = originalImportedName;
sourceType = SourceType.IMPORTED;
}
@@ -1798,16 +1847,18 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
}
// Add the function by creating a simple function.
- resultExternalLocation = externalManagers[RESULT].addExtFunction(namespace, name,
- address, sourceType, false);
+ resultExternalLocation =
+ externalManagers[RESULT].addExtFunction(library, namespace, name,
+ address, sourceType, false);
Function resultFunction = resultExternalLocation.getFunction();
// Now change the simple function to become the one we actually want.
programMerge.replaceExternalFunction(resultFunction, function, monitor);
}
// Add External Label
else {
- resultExternalLocation = externalManagers[RESULT].addExtLocation(namespace, name,
- address, sourceType, false);
+ resultExternalLocation =
+ externalManagers[RESULT].addExtLocation(library, namespace, name,
+ address, sourceType, false);
// Set the data type to match MY.
DataType dataType = getResultDataType(externalLocation);
@@ -2751,8 +2802,8 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
String[] header = getExternalInfo(externalLocations, HEADER);
String[] latest = getExternalInfo(externalLocations, LATEST);
String[] my = getExternalInfo(externalLocations, MY);
- String[] keepBoth = { "Keep Both", "", "", "", "", "", "" };
- String[] mergeBoth = { "Merge Together", "", "", "", "", "", "" };
+ String[] keepBoth = { "Keep Both", "", "", "", "", "", "", "" };
+ String[] mergeBoth = { "Merge Together", "", "", "", "", "", "", "" };
VerticalChoicesPanel panel = getEmptyVerticalPanel();
@@ -2871,18 +2922,16 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
panel.setHeader(text);
panel.addInfoRow("Conflict", new String[] { LATEST_TITLE, MY_TITLE }, true);
- if ((conflicts & EXTERNAL_NAMESPACE) != 0) {
- Namespace latestNamespace = locations[LATEST].getParentNameSpace();
- Namespace myNamespace = locations[MY].getParentNameSpace();
- String latest = latestNamespace.getName(true);
- String my = myNamespace.getName(true);
+ if ((conflicts & EXTERNAL_LIBRARY) != 0) {
+ String latest = locations[LATEST].getLibraryName();
+ String my = locations[MY].getLibraryName();
panel.addSingleChoice("Namespace", new String[] { latest, my },
- new ExternalDetailChangeListener(EXTERNAL_NAMESPACE, locations, panel,
+ new ExternalDetailChangeListener(EXTERNAL_LIBRARY, locations, panel,
monitor));
}
if ((conflicts & EXTERNAL_LABEL) != 0) {
- String latest = locations[LATEST].getLabel();
- String my = locations[MY].getLabel();
+ String latest = locations[LATEST].getSymbol().getName(true);
+ String my = locations[MY].getSymbol().getName(true);
panel.addSingleChoice("Name", new String[] { latest, my },
new ExternalDetailChangeListener(EXTERNAL_LABEL, locations, panel, monitor));
}
@@ -2898,7 +2947,8 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
// if ((conflicts & EXTERNAL_SOURCE_TYPE) != 0) {
// String latest = locations[LATEST].getSource().getDisplayString();
// String my = locations[MY].getSource().getDisplayString();
-//// String original = locations[ORIGINAL].getSource().getDisplayString();
+ //// String original =
+ /// locations[ORIGINAL].getSource().getDisplayString();
// panel.addSingleChoice("Source Type", new String[] { latest, my },
// new ExternalDetailChangeListener(EXTERNAL_SOURCE_TYPE, locations, panel, monitor));
// }
@@ -3252,76 +3302,81 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
return listingMergeManager.resolveNamespace(sourceProgram, sourceNamespace);
}
- public ExternalLocation replaceExternalLocation(ExternalLocation toExternalLocation,
+ private Library resolveLibrary(Program sourceProgram, Library sourceLibrary)
+ throws DuplicateNameException, InvalidInputException {
+ return listingMergeManager.resolveLibrary(sourceProgram, sourceLibrary);
+ }
+
+ public ExternalLocation replaceExternalLocation(ExternalLocation resultExternalLocation,
ExternalLocation fromExternalLocation, ProgramMerge programMerge, TaskMonitor monitor)
throws DuplicateNameException, InvalidInputException, CancelledException {
- // Change the namespace.
- replaceNamespace(toExternalLocation, fromExternalLocation, monitor);
+ // Change the library.
+ replaceLibrary(resultExternalLocation, fromExternalLocation, monitor);
- // Change the label, address and source.
- replaceLocation(toExternalLocation, fromExternalLocation, monitor);
+ // Change the label w/ namespace, original name, address and source.
+ replaceLocation(resultExternalLocation, fromExternalLocation, monitor);
// TODO: replacing data type on a function seems wrong. Do we handle the case
// where we replace a function with a non-function?
// Replace the data type.
- replaceExternalDataType(toExternalLocation, fromExternalLocation, monitor);
+ replaceExternalDataType(resultExternalLocation, fromExternalLocation, monitor);
// Replace the function.
- return replaceFunction(toExternalLocation, fromExternalLocation, programMerge, monitor);
+ return replaceFunction(resultExternalLocation, fromExternalLocation, programMerge, monitor);
}
- private void replaceNamespace(ExternalLocation toExternalLocation,
+ private void replaceLibrary(ExternalLocation toExternalLocation,
ExternalLocation fromExternalLocation, TaskMonitor monitor) {
- Symbol toSymbol = toExternalLocation.getSymbol();
- Symbol fromSymbol = fromExternalLocation.getSymbol();
- Program fromProgram = fromSymbol.getProgram();
+ Library currentLibrary = toExternalLocation.getLibrary();
+ Library fromLibrary = fromExternalLocation.getLibrary();
+ Program fromProgram = fromLibrary.getSymbol().getProgram();
- Namespace currentResultNamespace = toSymbol.getParentNamespace();
- Namespace fromNamespace = fromExternalLocation.getParentNameSpace();
- Exception exc = null;
try {
- // Get the namespace we need from result.
- Namespace desiredResultNamespace = resolveNamespace(fromProgram, fromNamespace);
- if (currentResultNamespace == desiredResultNamespace) {
- return;
- }
- toSymbol.setNamespace(desiredResultNamespace);
- }
- catch (DuplicateNameException | InvalidInputException | CircularDependencyException e) {
- exc = e;
+ Library toLibrary = resolveLibrary(fromProgram, fromLibrary);
+ toExternalLocation.setLibrary(toLibrary);
}
- if (exc != null) {
- Msg.error(this, "Couldn't replace namespace '" + currentResultNamespace.getName(true) +
- "' with '" + fromNamespace.getName(true) + "'." + exc.getMessage());
+ catch (DuplicateNameException | InvalidInputException e) {
+ Msg.error(this, "Couldn't replace library '" + currentLibrary.getName() +
+ "' with '" + fromLibrary.getName() + "'." + e.getMessage());
}
}
- private void replaceLocation(ExternalLocation toExternalLocation,
+ private void replaceLocation(ExternalLocation resultExternalLocation,
ExternalLocation fromExternalLocation, TaskMonitor monitor)
- throws DuplicateNameException, InvalidInputException {
+ throws InvalidInputException, CancelledException {
+
+ Namespace namespace1 = resultExternalLocation.getParentNameSpace();
+ String label1 = resultExternalLocation.getLabel();
+ String origName1 = resultExternalLocation.getOriginalImportedName();
+ SourceType sourceType1 = resultExternalLocation.getSource();
+
+ Namespace namespace2 = fromExternalLocation.getParentNameSpace();
+ String label2 = fromExternalLocation.getLabel();
+ String origName2 = fromExternalLocation.getOriginalImportedName();
+ SourceType sourceType2 = fromExternalLocation.getSource();
Address fromAddress = fromExternalLocation.getAddress();
- Address toAddress = toExternalLocation.getAddress();
- boolean addressChanged = !SystemUtilities.isEqual(fromAddress, toAddress);
-
- String fromLabel = fromExternalLocation.getSource() == SourceType.DEFAULT ? null
- : fromExternalLocation.getLabel();
- String toLabel = toExternalLocation.getSource() == SourceType.DEFAULT ? null
- : toExternalLocation.getLabel();
- if (!SystemUtilities.isEqual(fromLabel, toLabel)) {
- if (fromLabel == null && addressChanged) {
+ Address resultAddress = resultExternalLocation.getAddress();
+ boolean addressChanged = !SystemUtilities.isEqual(fromAddress, resultAddress);
+
+ boolean labelChanged = !equivalentNamespaces(namespace1, namespace2) ||
+ !isSameLabel(label1, label2, sourceType1, sourceType2) ||
+ !SystemUtilities.isEqual(origName1, origName2);
+
+ if (labelChanged) {
+ if (sourceType2 == SourceType.DEFAULT && addressChanged) {
// need to update address first if switching to null/default label
- toExternalLocation.setAddress(fromAddress);
+ resultExternalLocation.setAddress(fromAddress);
addressChanged = false;
}
- SourceType fromSourceType = fromExternalLocation.getSource();
- toExternalLocation.getSymbol().setName(fromLabel, fromSourceType);
+ mergeExternalDetail(EXTERNAL_LABEL, resultExternalLocation, fromExternalLocation,
+ monitor);
}
if (addressChanged) {
- toExternalLocation.setAddress(fromAddress);
+ resultExternalLocation.setAddress(fromAddress);
}
}
@@ -3397,7 +3452,7 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
getBasicExternalDiffs(externalLocations[LATEST], externalLocations[MY]);
int detailConflictFlags =
- latestMyChanges & (EXTERNAL_NAMESPACE | EXTERNAL_LABEL | EXTERNAL_ADDRESS);
+ latestMyChanges & (EXTERNAL_LIBRARY | EXTERNAL_LABEL | EXTERNAL_ADDRESS);
// (EXTERNAL_NAMESPACE | EXTERNAL_LABEL | EXTERNAL_SOURCE_TYPE | EXTERNAL_ADDRESS);
if ((detailConflictFlags & EXTERNAL_ADDRESS) != 0) {
Address latestAddress = externalLocations[LATEST].getAddress();
@@ -4170,7 +4225,7 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
? externalLocations[ORIGINAL].getExternalSpaceAddress()
: null;
- String[] info = new String[] { "", "", "", "", "", "", "" };
+ String[] info = new String[] { "", "", "", "", "", "", "", "" };
String versionName = RESULT_TITLE;
String externalName = "";
@@ -4181,8 +4236,8 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
switch (programVersion) {
case HEADER:
- return new String[] { "Option", "Name", "Type", "Address", "DataType", "Source",
- "Function" };
+ return new String[] { "Option", "Name", "Library", "Type", "Address", "DataType",
+ "Source", "Function" };
case LATEST:
pgm = programs[LATEST];
versionName = LATEST_TITLE;
@@ -4223,16 +4278,18 @@ public class ExternalFunctionMerger extends AbstractFunctionMerger implements Li
DataType dataType = getResultDataType(externalLocation);
SourceType sourceType = externalLocation.getSource();
Function function = externalLocation.getFunction();
+ String library = externalLocation.getLibraryName();
info[1] = externalName;
- info[2] = externalType;
- info[3] = DiffUtility.getUserToAddressString(pgm, externalAddress);
+ info[2] = library;
+ info[3] = externalType;
+ info[4] = DiffUtility.getUserToAddressString(pgm, externalAddress);
if (dataType != null) {
- info[4] = dataType.getDisplayName();
+ info[5] = dataType.getDisplayName();
}
- info[5] = sourceType.getDisplayString();
+ info[6] = sourceType.getDisplayString();
if (function != null) {
- info[6] = function.getPrototypeString(true, true);
+ info[7] = function.getPrototypeString(true, true);
}
}
return info;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ListingMergeManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ListingMergeManager.java
index 8c4fefc47c..88902ba098 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ListingMergeManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ListingMergeManager.java
@@ -22,8 +22,7 @@ import javax.swing.SwingUtilities;
import ghidra.app.merge.*;
import ghidra.app.merge.tool.ListingMergePanel;
import ghidra.program.model.address.*;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.listing.ProgramChangeSet;
+import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.util.*;
@@ -669,6 +668,11 @@ public class ListingMergeManager implements MergeResolver, ListingMergeConstants
return symbolMerger.resolveNamespace(srcProgram, srcNamespace);
}
+ public Library resolveLibrary(Program originProgram, Library libary)
+ throws DuplicateNameException, InvalidInputException {
+ return symbolMerger.resolveLibrary(originProgram, libary);
+ }
+
/**
* This method returns all of the phases of the Listing Merge Manager that will be
* displayed in the Program Merge Manager.
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/SymbolMerger.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/SymbolMerger.java
index 4507247013..0af21c98a5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/SymbolMerger.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/SymbolMerger.java
@@ -254,6 +254,40 @@ class SymbolMerger extends AbstractListingMerger {
return -1;
}
+ /**
+ * This method allows other listing merge managers to resolve a library
+ * via the symbol merge manager. This is because the symbol merge manager
+ * actually merges libraries and best knows how to resolve them.
+ * It also keeps track of how they have been resolved.
+ * @param srcProgram the program version that the namespace to be resolved is coming from.
+ * @param srcLibrary the namespace to be resolved
+ * @return the namespace from the result program version
+ * @throws DuplicateNameException if the name space can't be resolved due
+ * to a name conflict that can't be dealt with.
+ * @throws InvalidInputException if the name space is not validly named
+ * for the result program.
+ */
+ Library resolveLibrary(Program srcProgram, Library srcLibrary) throws DuplicateNameException,
+ InvalidInputException {
+ Library resolvedLibrary = null;
+ SymbolTable resolveSymTab = resultPgm.getSymbolTable();
+ Symbol srcLibSymbol = srcLibrary.getSymbol();
+ String name = srcLibrary.getName();
+ long srcLibID = srcLibSymbol.getID();
+ SourceType sourceType = srcLibrary.getSymbol().getSource();
+ long resolveLibID = resolveSymbolID(srcProgram, srcLibID);
+ if (resolveLibID >= 0) { // Found the corresponding library symbol ID in result program.
+ Symbol resolveSym = resolveSymTab.getSymbol(resolveLibID);
+ resolvedLibrary = (Library) resolveSym.getObject();
+ }
+ else { // Didn't find the corresponding namespace symbol ID in result program.
+ // Try to resolve the parent's ID and use it to get/create a namespace.
+ resolvedLibrary = createLibrary(resultPgm, name, srcProgram, srcLibID, sourceType);
+ }
+ return resolvedLibrary;
+
+ }
+
/**
* This method allows other listing merge managers to resolve a namespace
* via the symbol merge manager. This is because the symbol merge manager
@@ -299,6 +333,13 @@ class SymbolMerger extends AbstractListingMerger {
return resolvedNamespace;
}
+ private Library createLibrary(Program resultProgram, String name, Program srcPgm, long srcSymID,
+ SourceType source) throws DuplicateNameException, InvalidInputException {
+ Symbol symbol =
+ createSymbol(name, SymbolType.LIBRARY, null, null, srcPgm, srcSymID, source);
+ return (Library) symbol.getObject();
+ }
+
/**
* Get/create a uniquely named namespace. If the namespace's name can't
* be created because of a name conflict, it will be given a new conflict name.
@@ -2505,11 +2546,14 @@ class SymbolMerger extends AbstractListingMerger {
SymbolType symType = originalSymbol.getSymbolType();
String symbolName = originalSymbol.getName();
SourceType source = originalSymbol.getSource();
+
if (symType == SymbolType.LABEL) {
if (originalSymbol.isExternal()) {
+ Library library = originalSymbol.getLibrary();
ExternalManager resultExternalManager = resultPgm.getExternalManager();
ExternalLocation resultExtLocation =
- resultExternalManager.addExtLocation(namespace, symbolName, address, source);
+ resultExternalManager.addExtLocation(library, namespace, symbolName, address,
+ source);
resultSymbol = resultExtLocation.getSymbol();
}
else {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AbstractDemanglerAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AbstractDemanglerAnalyzer.java
index 19826222fd..ffd36dd437 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AbstractDemanglerAnalyzer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AbstractDemanglerAnalyzer.java
@@ -22,7 +22,8 @@ import ghidra.app.services.*;
import ghidra.app.util.demangler.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.model.address.*;
-import ghidra.program.model.listing.*;
+import ghidra.program.model.listing.Function;
+import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -213,12 +214,7 @@ public abstract class AbstractDemanglerAnalyzer extends AbstractAnalyzer {
// Only demangle global or external symbols when directly parented to a Library namespace
Namespace parentNamespace = symbol.getParentNamespace();
- if (symbol.isExternal()) {
- if (!(parentNamespace instanceof Library)) {
- return true;
- }
- }
- else if (!parentNamespace.isGlobal()) {
+ if (!parentNamespace.isGlobal()) {
return true;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/NoReturnFunctionAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/NoReturnFunctionAnalyzer.java
index d0cedf1bb0..3bcabe0b95 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/NoReturnFunctionAnalyzer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/NoReturnFunctionAnalyzer.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -123,9 +123,8 @@ public class NoReturnFunctionAnalyzer extends AbstractAnalyzer {
// skip noreturn marking if its namespace is not global, library, or std
// it prevents class methods (e.g. Menu::_exit()) incorrectly marked as noreturn
Namespace parentNamespace = symbol.getParentNamespace();
- if (parentNamespace != null && !parentNamespace.isGlobal() &&
- !parentNamespace.isLibrary()) {
- List<String> pathList = parentNamespace.getPathList(true);
+ if (parentNamespace != null && !parentNamespace.isGlobal()) {
+ List<String> pathList = parentNamespace.getPathList();
if (!(pathList.size() == 1 && pathList.get(0) == "std")) {
return;
}
@@ -148,7 +147,7 @@ public class NoReturnFunctionAnalyzer extends AbstractAnalyzer {
Address address = symbol.getAddress();
if (symbol.getSymbolType() == SymbolType.LABEL) {
- if (!SymbolType.FUNCTION.isValidParent(program, parentNamespace, address, false)) {
+ if (!SymbolType.FUNCTION.isValidParent(program, parentNamespace, address)) {
return; // skip if parent does not permit function creation
}
CreateFunctionCmd fCommand = new CreateFunctionCmd(address);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialog.java
index 8eef81348f..c7f124d5a3 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialog.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,12 +15,14 @@
*/
package ghidra.app.plugin.core.function;
-import java.util.Iterator;
+import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import javax.swing.*;
import docking.DialogComponentProvider;
+import docking.widgets.dialogs.ObjectChooserDialog;
import docking.widgets.label.GLabel;
import ghidra.app.util.*;
import ghidra.framework.plugintool.PluginTool;
@@ -29,7 +31,6 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
-import ghidra.util.exception.NotFoundException;
import ghidra.util.layout.PairLayout;
public class ThunkReferenceAddressDialog extends DialogComponentProvider {
@@ -110,18 +111,9 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
refAddress = program.getAddressFactory().getAddress(text);
if (refAddress == null) {
- try {
- refSymbol = getSymbolForText(text);
- if (refSymbol == null) {
- Msg.showError(this, getComponent(), "Ambiguous Symbol Name",
- "Specified symbol is ambiguous. Try full namespace name, " +
- "mangled name or address.");
- return;
- }
- }
- catch (NotFoundException e) {
- Msg.showError(this, getComponent(), "Invalid Entry Error",
- "Invalid thunk reference address or name specified: " + text);
+ refSymbol = getSymbolForText(text);
+ if (refSymbol == null) {
+ setStatusText("Invalid thunk reference address or name specified");
return;
}
refAddress = refSymbol.getAddress();
@@ -136,12 +128,13 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
}
private boolean isValid(Address addr, Symbol s) {
-
- if (s != null) {
- if (refSymbol.isExternal() || s.getSymbolType() == SymbolType.FUNCTION) {
- // Externals and functions are valid
- return true;
- }
+ if (s == null) {
+ setStatusText("Function not found at address: " + addr);
+ return false;
+ }
+ if (refSymbol.isExternal() || s.getSymbolType() == SymbolType.FUNCTION) {
+ // Externals and functions are valid
+ return true;
}
if (addr == null) {
@@ -184,57 +177,73 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
* text entry which may optionally include a namespace
* @param text symbol name
* @return symbol or null if multiple symbols found
- * @throws NotFoundException if no matching symbols were found
*
*/
- private Symbol getSymbolForText(String text) throws NotFoundException {
-
- SymbolTable symbolTable = program.getSymbolTable();
+ private Symbol getSymbolForText(String text) {
SymbolPath symbolPath = new SymbolPath(text);
Namespace namespace = getNamespace(symbolPath);
- Iterator<Symbol> symbolIterator;
+ List<Symbol> symbols = getSymbols(symbolPath, namespace);
+ symbols = filterSymbols(symbols);
if (namespace == null) {
- symbolIterator = symbolTable.getSymbols(text);
- }
- else {
- symbolIterator = symbolTable.getSymbols(symbolPath.getName(), namespace).iterator();
+ // look for original external symbols not indexed by symbol table
+ symbols.addAll(findOriginalExternalSymbols(text));
}
- Symbol symbol = null;
- try {
- symbol = findRefSymbol(symbolIterator);
- if (symbol == null) {
- return null; // multiple symbols found
- }
+ if (symbols.isEmpty()) {
+ return null;
}
- catch (NotFoundException e) {
- // ignore
+ if (symbols.size() == 1) {
+ return symbols.get(0);
}
+ return pickSymbol(symbols, symbolPath.getName());
- Symbol candidateSymbol2 = null;
- if (namespace == null) {
- // look for original external symbols not indexed by symbol table
- try {
- candidateSymbol2 = findOriginalExternalSymbol(text);
- if (candidateSymbol2 == null) {
- return null; // multiple symbols found
- }
- if (symbol != null) {
- return null;
- }
- symbol = candidateSymbol2;
- }
- catch (NotFoundException e) {
- // ignore
- }
+ }
+
+ private List<Symbol> filterSymbols(List<Symbol> symbols) {
+ return symbols.stream().filter(s -> isValidSymbol(s)).collect(Collectors.toList());
+ }
+
+ private Symbol pickSymbol(List<Symbol> symbols, String name) {
+ List<ThunkSymbolDecorator> list =
+ symbols.stream().map(ThunkSymbolDecorator::new).collect(Collectors.toList());
+ ObjectChooserDialog<ThunkSymbolDecorator> dialog =
+ new ObjectChooserDialog<ThunkSymbolDecorator>("Choose Which \"" + name + "\"",
+ ThunkSymbolDecorator.class, list, "getAddress", "getLibrary", "getNamespace",
+ "getSignature");
+
+ dialog.setPreferredWidth(820);
+ dialog.setPreferredColumnWidths(120, 150, 150, 400);
+ tool.showDialog(dialog);
+ ThunkSymbolDecorator selectedObject = dialog.getSelectedObject();
+ if (selectedObject == null) {
+ close();
+ return null;
}
+ return selectedObject.getSymbol();
+ }
- if (symbol == null) {
- throw new NotFoundException();
+ private List<Symbol> getSymbols(SymbolPath symbolPath, Namespace namespace) {
+ SymbolTable symbolTable = program.getSymbolTable();
+ if (namespace != null) {
+ return symbolTable.getSymbols(symbolPath.getName(), namespace);
}
+ SymbolIterator it = symbolTable.getSymbols(symbolPath.getName());
+ List<Symbol> list = new ArrayList<>();
+ it.forEach(list::add);
+ return list;
+ }
- return symbol;
+ private boolean isValidSymbol(Symbol s) {
+ // valid symbols are function symbols (internal or external) and external labels
+ SymbolType symbolType = s.getSymbolType();
+ if (symbolType == SymbolType.FUNCTION) {
+ return true;
+ }
+ if (symbolType == SymbolType.LABEL) {
+ return s.isExternal();
+ }
+ return false;
}
private Namespace getNamespace(SymbolPath symbolPath) {
@@ -245,18 +254,6 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
List<Namespace> namespaces = NamespaceUtils.getNamespaceByPath(program, null, parentNs);
- if (namespaces.isEmpty()) {
- SymbolTable symbolTable = program.getSymbolTable();
- for (String libraryName : program.getExternalManager().getExternalLibraryNames()) {
- Symbol librarySymbol = symbolTable.getLibrarySymbol(libraryName);
- namespaces = NamespaceUtils.getNamespaceByPath(program,
- (Library) librarySymbol.getObject(), parentNs);
- if (!namespaces.isEmpty()) {
- break; // use first library containing namespace
- }
- }
- }
-
if (namespaces.size() > 1) {
// assume local symbol was specified
Msg.showError(this, getComponent(), "Invalid Namespace",
@@ -266,61 +263,10 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
return namespaces.isEmpty() ? null : namespaces.get(0);
}
- /**
- * Find unique symbol from iterator ignoring related thunks.
- * @param symbolIterator symbol iterator
- * @return unique function or code symbol or null if multiple symbols found
- * @throws NotFoundException if no symbols were found
- */
- private Symbol findRefSymbol(Iterator<Symbol> symbolIterator) throws NotFoundException {
- Symbol candidateSymbol = null;
- Symbol candidateThunkSymbol = null;
- Symbol candidateThunkedSymbol = null; // corresponds to candidateThunkSymbol
- while (symbolIterator.hasNext()) {
- Symbol s = symbolIterator.next();
- SymbolType type = s.getSymbolType();
- if (type == SymbolType.FUNCTION || type == SymbolType.LABEL) {
- Symbol thunkedSymbol = getThunkedSymbol(s);
- if (thunkedSymbol != null) {
- // ignore equivalent thunks
- if (candidateThunkSymbol != null &&
- !thunkedSymbol.equals(candidateThunkedSymbol)) {
- return null;
- }
- candidateThunkedSymbol = thunkedSymbol;
- candidateThunkSymbol = s;
- }
- else { // non-thunk symbol
- if (candidateSymbol != null) {
- return null;
- }
- candidateSymbol = s;
- }
- }
- }
- if (candidateSymbol == null) {
- candidateSymbol = candidateThunkSymbol;
- }
- else if (candidateThunkSymbol != null && !candidateSymbol.equals(candidateThunkedSymbol)) {
- return null;
- }
- if (candidateSymbol == null) {
- throw new NotFoundException();
- }
- return candidateSymbol;
- }
-
- /**
- * Find unique original external symbol with the given name.
- * @param name original external symbol name
- * @return unique external symbol or null if multiple matching external symbols were found
- * @throws NotFoundException if no original external symbols were found
- */
- private Symbol findOriginalExternalSymbol(String name) throws NotFoundException {
-
+ private List<Symbol> findOriginalExternalSymbols(String name) {
+ List<Symbol> list = new ArrayList<>();
// must examine each external since secondary/original name
// is not indexed within symbol table
- Symbol candidateSymbol = null;
SymbolTable symbolTable = program.getSymbolTable();
ExternalManager externalManager = program.getExternalManager();
for (Symbol s : symbolTable.getExternalSymbols()) {
@@ -329,26 +275,11 @@ public class ThunkReferenceAddressDialog extends DialogComponentProvider {
ExternalLocation externalLocation = externalManager.getExternalLocation(s);
String originalName = externalLocation.getOriginalImportedName();
if (name.equals(originalName)) {
- if (candidateSymbol != null) {
- return null;
- }
- candidateSymbol = s;
+ list.add(s);
}
}
}
- if (candidateSymbol == null) {
- throw new NotFoundException();
- }
- return candidateSymbol;
- }
-
- private Symbol getThunkedSymbol(Symbol s) {
- if (s.getSymbolType() != SymbolType.FUNCTION) {
- return null;
- }
- Function f = (Function) s.getObject();
- Function thunkedFunction = f.getThunkedFunction(true);
- return thunkedFunction != null ? thunkedFunction.getSymbol() : null;
+ return list;
}
/**
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkSymbolDecorator.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkSymbolDecorator.java
new file mode 100644
index 0000000000..beb0cd54b6
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ThunkSymbolDecorator.java
@@ -0,0 +1,74 @@
+/* ###
+ * 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.function;
+
+import ghidra.program.model.listing.Function;
+import ghidra.program.model.listing.Library;
+import ghidra.program.model.symbol.*;
+
+/**
+ * Class to wrap a symbol with methods that can be used provide column data to an
+ * ObjectChooserDialog. This dialog is used to pick a function symbol when the
+ * original query in {@link ThunkReferenceAddressDialog} finds multiple hits for a given name.
+ */
+public class ThunkSymbolDecorator {
+ private Symbol symbol;
+
+ public ThunkSymbolDecorator(Symbol s) {
+ this.symbol = s;
+ }
+
+ public String getName() {
+ return symbol.getName(true);
+ }
+
+ public String getNamespace() {
+ Namespace namespace = symbol.getParentNamespace();
+ if (namespace.isGlobal()) {
+ return "";
+ }
+ return namespace.getName(true);
+ }
+
+ public String getLibrary() {
+ Library library = symbol.getLibrary();
+ return library == null ? "" : library.getName();
+ }
+
+ public String getAddress() {
+ if (symbol.isExternal()) {
+ return "<EXTERNAL>";
+ }
+ return symbol.getAddress().toString();
+ }
+
+ public String getSignature() {
+ if (symbol.getSymbolType() == SymbolType.FUNCTION) {
+ Function function = (Function) symbol.getObject();
+ return function.getSignature().toString();
+ }
+ return symbol.getName();
+ }
+
+ public Symbol getSymbol() {
+ return symbol;
+ }
+
+ @Override
+ public String toString() {
+ return symbol.getName();
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/VarnodeLocationCellEditor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/VarnodeLocationCellEditor.java
index 5fbb5fd0d1..38e9217aa2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/VarnodeLocationCellEditor.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/VarnodeLocationCellEditor.java
@@ -241,13 +241,11 @@ class VarnodeLocationCellEditor extends AbstractCellEditor
private static class RegisterComparator implements Comparator<Register> {
- private AlphaNumericComparator alphaNumericComparator = new AlphaNumericComparator();
-
@Override
public int compare(Register r1, Register r2) {
String s1 = r1.getName().toLowerCase();
String s2 = r2.getName().toLowerCase();
- return alphaNumericComparator.compare(s1, s2);
+ return AlphaNumericComparator.CS.compare(s1, s2);
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToHelper.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToHelper.java
index b8e8521161..98b49b4c3b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToHelper.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToHelper.java
@@ -379,10 +379,11 @@ public class GoToHelper {
return null; // default name is not valid for external program
}
Stack<String> nameStack = new Stack<>();
- for (Namespace namespace =
- s.getParentNamespace(); !(namespace instanceof Library); namespace =
- namespace.getParentNamespace()) {
+
+ Namespace namespace = s.getParentNamespace();
+ while (!namespace.isGlobal()) {
nameStack.push(namespace.getName());
+ namespace = namespace.getParentNamespace();
}
return nameStack;
}
@@ -419,7 +420,7 @@ public class GoToHelper {
if (s.getSource() == SourceType.DEFAULT) {
return null; // must rely on address for navigation
}
- symbolPath = new SymbolPath(s, true);
+ symbolPath = new SymbolPath(s);
}
else {
symbolPath = new SymbolPath(label);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/register/RegisterTree.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/register/RegisterTree.java
index 4a3da8c3e6..8f458416d7 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/register/RegisterTree.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/register/RegisterTree.java
@@ -129,14 +129,11 @@ public class RegisterTree extends GTree {
private static class RegisterNodeComparator implements Comparator<GTreeNode> {
- private AlphaNumericComparator alphaNumericComparator =
- new AlphaNumericComparator();
-
@Override
public int compare(GTreeNode n1, GTreeNode n2) {
String s1 = n1.getName().toLowerCase();
String s2 = n2.getName().toLowerCase();
- return alphaNumericComparator.compare(s1, s2);
+ return AlphaNumericComparator.CS.compare(s1, s2);
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/DisconnectedSymbolTreeProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/DisconnectedSymbolTreeProvider.java
index 683ecbd730..5bf764cd92 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/DisconnectedSymbolTreeProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/DisconnectedSymbolTreeProvider.java
@@ -20,9 +20,7 @@ import javax.swing.JPanel;
import docking.WindowPosition;
import docking.action.KeyBindingData;
-import docking.action.builder.ActionBuilder;
import ghidra.app.nav.DecoratorPanel;
-import ghidra.app.plugin.core.symboltree.nodes.*;
import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.listing.Program;
@@ -36,13 +34,11 @@ public class DisconnectedSymbolTreeProvider extends SymbolTreeProvider {
private static final String WINDOW_GROUP = "Disconnected Symbol Tree";
public DisconnectedSymbolTreeProvider(PluginTool tool, SymbolTreePlugin plugin,
- Program program) {
+ Program program, SymbolTreeFilterState filterState) {
super(tool, plugin);
-
+ this.filterState = filterState;
setDefaultWindowPosition(WindowPosition.WINDOW);
- createActions();
-
// Snapshots do not usually respond to incoming location events. But, it seems to make
// sense that users would like to use the snapshot to navigate the tool.
tool.removeLocalAction(this, navigateIncomingAction);
@@ -87,7 +83,7 @@ public class DisconnectedSymbolTreeProvider extends SymbolTreeProvider {
}
@Override
- void setProgram(Program newProgram) {
+ void programActivated(Program newProgram) {
// nothing to do; we maintain our state as the user changes programs
}
@@ -113,30 +109,11 @@ public class DisconnectedSymbolTreeProvider extends SymbolTreeProvider {
return new DecoratorPanel(contentComponent, false);
}
- @Override
- protected SymbolTreeRootNode createRootNode() {
- return new ConfigurableSymbolTreeRootNode(program, getNodeGroupThreshold());
- }
-
@Override
public void closeComponent() {
plugin.closeDisconnectedProvider(this);
}
- @Override
- protected void transferSettings(DisconnectedSymbolTreeProvider newProvider) {
-
- // transfer disabled node settings
- ConfigurableSymbolTreeRootNode myModelRoot =
- (ConfigurableSymbolTreeRootNode) tree.getModelRoot();
-
- ConfigurableSymbolTreeRootNode newModelRoot =
- (ConfigurableSymbolTreeRootNode) newProvider.tree.getModelRoot();
- myModelRoot.transferSettings(newModelRoot);
-
- super.transferSettings(newProvider);
- }
-
@Override
void writeConfigState(SaveState saveState) {
// we have no state we are interested in saving
@@ -146,37 +123,4 @@ public class DisconnectedSymbolTreeProvider extends SymbolTreeProvider {
void readConfigState(SaveState saveState) {
// we have no state we are interested in loading
}
-
- private void createActions() {
-
- //@formatter:off
- new ActionBuilder("Enable Category", plugin.getName())
- .popupMenuPath("Enable Category")
- .withContext(SymbolTreeActionContext.class)
- .enabledWhen(c -> {
- SymbolTreeNode node = c.getSelectedNode();
- return node instanceof SymbolCategoryNode;
- })
- .onAction(c -> {
- SymbolCategoryNode node = (SymbolCategoryNode) c.getSelectedNode();
- node.setEnabled(true);
- })
- .buildAndInstallLocal(this);
- //@formatter:on
-
- //@formatter:off
- new ActionBuilder("Disable Category", plugin.getName())
- .popupMenuPath("Disable Category")
- .withContext(SymbolTreeActionContext.class)
- .enabledWhen(c -> {
- SymbolTreeNode node = c.getSelectedNode();
- return node instanceof SymbolCategoryNode;
- })
- .onAction(c -> {
- SymbolCategoryNode node = (SymbolCategoryNode) c.getSelectedNode();
- node.setEnabled(false);
- })
- .buildAndInstallLocal(this);
- //@formatter:on
- }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationDialog.java
index 122f87f24d..4552de9d1a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationDialog.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,6 +25,7 @@ import javax.swing.border.EmptyBorder;
import docking.DialogComponentProvider;
import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.Symbol;
@@ -146,8 +147,9 @@ public class EditExternalLocationDialog extends DialogComponentProvider {
private String getEditName() {
if (externalLocation != null) {
+ Library library = externalLocation.getLibrary();
Symbol symbol = externalLocation.getSymbol();
- String name = symbol.getName(true);
+ String name = library.getName() + ":" + symbol.getName(true);
Address addr = externalLocation.getAddress();
if (addr != null) {
name += " @ " + addr.toString(true);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationPanel.java
index 8ec68bf5e6..b68a8c9fd5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationPanel.java
@@ -38,11 +38,13 @@ import ghidra.framework.main.ProgramFileChooser;
import ghidra.framework.model.*;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
-import ghidra.program.model.listing.*;
+import ghidra.program.model.listing.Library;
+import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
-import ghidra.util.exception.*;
+import ghidra.util.exception.DuplicateNameException;
+import ghidra.util.exception.InvalidInputException;
import ghidra.util.layout.PairLayout;
import ghidra.util.layout.VerticalLayout;
@@ -91,7 +93,7 @@ class EditExternalLocationPanel extends JPanel {
externalManager.getExternalLibraryPath(startingExternalLibraryName);
Symbol s = externalLocation.getSymbol();
this.startingLocationName = NamespaceUtils.getNamespaceQualifiedName(s.getParentNamespace(),
- externalLocation.getLabel(), true);
+ externalLocation.getLabel());
this.startingLocationAddress = externalLocation.getAddress();
this.startingOriginalName = externalLocation.getOriginalImportedName();
buildPanel();
@@ -511,20 +513,8 @@ class EditExternalLocationPanel extends JPanel {
boolean success = false;
try {
Library library = getOrCreateExternalLibrary(libraryName, libraryProgramPathname);
-
- // If the external location is not in the chosen library then move it.
- Symbol symbol = extLocation.getSymbol();
- Namespace parentNamespace = symbol.getParentNamespace();
- if (parentNamespace != library) {
- try {
- symbol.setNamespace(library);
- }
- catch (CircularDependencyException e) {
- throw new AssertException("Unexpected error", e);
- }
- }
-
// Update the location.
+ extLocation.setLibrary(library);
extLocation.setLocation(label, addr, SourceType.USER_DEFINED);
success = true;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolCategory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolCategory.java
index b5c7893257..d68135f869 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolCategory.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolCategory.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,38 +15,21 @@
*/
package ghidra.app.plugin.core.symboltree;
-import ghidra.program.model.symbol.SymbolType;
-
-public class SymbolCategory {
-
- public static final SymbolCategory FUNCTION_CATEGORY = new SymbolCategory("Functions", SymbolType.FUNCTION);
- public static final SymbolCategory EXPORTS_CATEGORY = new SymbolCategory("Exports", SymbolType.LABEL);
- public static final SymbolCategory IMPORTS_CATEGORY = new SymbolCategory("Imports", SymbolType.LIBRARY);
- public static final SymbolCategory LABEL_CATEGORY = new SymbolCategory("Labels", SymbolType.LABEL);
- public static final SymbolCategory ROOT_CATEGORY = new SymbolCategory("Global", null);
- public static final SymbolCategory NAMESPACE_CATEGORY = new SymbolCategory("Namespaces", SymbolType.NAMESPACE);
- public static final SymbolCategory CLASS_CATEGORY = new SymbolCategory("Classes", SymbolType.CLASS);
+public enum SymbolCategory {
+ IMPORTS("Imports"), EXPORTS("Exports"), GLOBALS("Globals"), NAMESPACES("Namespaces");
private String name;
- private SymbolType type;
- private SymbolCategory(String name, SymbolType type) {
+ private SymbolCategory(String name) {
this.name = name;
- this.type = type;
}
public String getName() {
return name;
}
- public SymbolType getSymbolType() {
- return type;
+ @Override
+ public String toString() {
+ return name;
}
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return name;
- }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTree.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTree.java
index 1fd7de32e5..14444dff0f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTree.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTree.java
@@ -24,11 +24,9 @@ import javax.swing.tree.TreePath;
import docking.widgets.tree.*;
import docking.widgets.tree.support.GTreeRenderer;
import generic.theme.GIcon;
-import ghidra.app.plugin.core.symboltree.nodes.SymbolCategoryNode;
import ghidra.app.plugin.core.symboltree.nodes.SymbolNode;
import ghidra.app.util.SymbolInspector;
import ghidra.program.model.symbol.Symbol;
-import resources.ResourceManager;
public class SymbolGTree extends GTree {
@@ -103,20 +101,6 @@ public class SymbolGTree extends GTree {
return label;
}
-
- @Override
- protected Icon getNodeIcon(GTreeNode node, boolean expanded) {
-
- Icon icon = super.getNodeIcon(node, expanded);
-
- if (node instanceof SymbolCategoryNode symbolNode) {
- if (!symbolNode.isEnabled()) {
- return ResourceManager.getDisabledIcon(icon);
- }
- }
-
- return icon;
- }
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTreeDragNDropHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTreeDragNDropHandler.java
index b4d66c4d80..61e8bea9de 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTreeDragNDropHandler.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolGTreeDragNDropHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -189,6 +189,16 @@ public class SymbolGTreeDragNDropHandler implements GTreeDragNDropHandler {
if (SymbolDataFlavor.DATA_FLAVOR.equals(flavor)) {
return getSymbols(transferNodes);
}
+ /*
+ The generic flavor for the Symbol Tree. This is used to paste all nodes in the list.
+ These nodes will be given to the Symbol Tree provider, which will decide how to process
+ each node.
+
+ Note: symbolNode.getNodeDataFlavor() is used to get the flavor of each node being
+ transfered. But, we do not use those flavors to process the nodes on a drop().
+ Instead, we use the generic SymbolTreeDataFlavor.DATA_FLAVOR and let the provider
+ handle each node separately. (see getSupportedDataFlavors() in this file)
+ */
else if (SymbolTreeDataFlavor.DATA_FLAVOR.equals(flavor)) {
List<GTreeNode> nodes = new ArrayList<>();
for (GTreeNode node : transferNodes) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterDialog.java
new file mode 100644
index 0000000000..2ab81a7fea
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterDialog.java
@@ -0,0 +1,142 @@
+/* ###
+ * 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.symboltree;
+
+import java.awt.Component;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+
+import docking.DialogComponentProvider;
+import docking.widgets.checkbox.GCheckBox;
+import ghidra.util.HelpLocation;
+import ghidra.util.MessageType;
+import ghidra.util.layout.VerticalLayout;
+
+public class SymbolTreeFilterDialog extends DialogComponentProvider {
+
+ private SymbolTreeFilterState filterState;
+ private SymbolTreeFilterState originalFilterState;
+ private SymbolTreeProvider provider;
+
+ protected SymbolTreeFilterDialog(SymbolTreeProvider provider,
+ SymbolTreeFilterState filterState) {
+ super("Configure Symbol Tree");
+ this.provider = provider;
+ this.originalFilterState = filterState;
+ this.filterState = filterState;
+
+ setHelpLocation(new HelpLocation("SymbolTreePlugin", "Symbol_Tree_Settings"));
+ addWorkPanel(buildMainPanel());
+ addOKButton();
+ addDismissButton();
+ setRememberSize(false);
+ updateButtonEnablement();
+ }
+
+ @Override
+ protected void okCallback() {
+ provider.setSymbolTreeSettings(filterState);
+ close();
+ }
+
+ private void updateButtonEnablement() {
+ boolean isChanged = !originalFilterState.equals(filterState);
+ boolean isValid = checkValid();
+ boolean isEnabled = isChanged && isValid;
+ okButton.setEnabled(isEnabled);
+ }
+
+ private boolean checkValid() {
+ clearStatusText();
+ if (!filterState.includesAtLeastOneCateogry()) {
+ setStatusText("You must select at least one category", MessageType.ERROR);
+ return false;
+ }
+ return true;
+ }
+
+ private JComponent buildMainPanel() {
+ JPanel panel = new JPanel(new VerticalLayout(20));
+ panel.setBorder(BorderFactory.createEmptyBorder(20, 60, 20, 60));
+ panel.add(buildColumnPanel());
+ panel.add(buildSymbolTypesPanel());
+ return panel;
+ }
+
+ private Component buildColumnPanel() {
+ JPanel panel = new JPanel(new VerticalLayout(5));
+ Border outerBorder = BorderFactory.createTitledBorder("Symbol Categories");
+ Border innerBorder = BorderFactory.createEmptyBorder(10, 30, 5, 30);
+ panel.setBorder(BorderFactory.createCompoundBorder(outerBorder, innerBorder));
+ JCheckBox importsCb = new GCheckBox("Imports", filterState.showImports());
+ JCheckBox exportsCb = new GCheckBox("Exports", filterState.showExports());
+ JCheckBox globalsCb = new GCheckBox("Globals", filterState.showGlobals());
+ JCheckBox namespacesCb = new GCheckBox("Namespaces", filterState.showNamespaces());
+
+ importsCb.addActionListener(e -> {
+ filterState = filterState.withImports(importsCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ exportsCb.addActionListener(e -> {
+ filterState = filterState.withExports(exportsCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ globalsCb.addActionListener(e -> {
+ filterState = filterState.withGlobals(globalsCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ namespacesCb.addActionListener(e -> {
+ filterState = filterState.withNamespaces(namespacesCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ panel.add(importsCb);
+ panel.add(exportsCb);
+ panel.add(globalsCb);
+ panel.add(namespacesCb);
+
+ return panel;
+ }
+
+ private Component buildSymbolTypesPanel() {
+ JPanel panel = new JPanel(new VerticalLayout(5));
+ Border outerBorder = BorderFactory.createTitledBorder("Symbol Types");
+ Border innerBorder = BorderFactory.createEmptyBorder(10, 30, 5, 30);
+ panel.setBorder(BorderFactory.createCompoundBorder(outerBorder, innerBorder));
+ JCheckBox labelsCb = new GCheckBox("Labels", filterState.includeLabels());
+ JCheckBox functionsCb = new GCheckBox("Functions", filterState.includeFunctions());
+
+ labelsCb.addActionListener(e -> {
+ filterState = filterState.withLabels(labelsCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ functionsCb.addActionListener(e -> {
+ filterState = filterState.withFunctions(functionsCb.isSelected());
+ updateButtonEnablement();
+ });
+
+ panel.add(labelsCb);
+ panel.add(functionsCb);
+
+ return panel;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterState.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterState.java
new file mode 100644
index 0000000000..d24d15d1e0
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeFilterState.java
@@ -0,0 +1,189 @@
+/* ###
+ * 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.symboltree;
+
+import static ghidra.program.model.symbol.SymbolType.*;
+
+import ghidra.framework.options.SaveState;
+import ghidra.program.model.symbol.Symbol;
+import ghidra.program.model.symbol.SymbolType;
+
+/**
+ * Class for recording the filter state for the symbol tree. Includes methods for
+ * for creating a new filter object with just one of the filter states changed.
+ * <P>
+ * @param showImports if true, show the imports category
+ * @param showExports if true, show the exports category
+ * @param showGlobals if true, show global functions and labels
+ * @param showNamespaces if true, show non-global functions and labels, organized by namespaces/class
+ * @param includeLabels if false, filter out all labels symbols from the tree
+ * @param includeFunctions if false, filter out all function symbols from the tree
+ */
+public record SymbolTreeFilterState(boolean showImports, boolean showExports, boolean showGlobals,
+ boolean showNamespaces, boolean includeLabels, boolean includeFunctions) {
+ private static final String INCLUDE_FUNCTIONS = "Include Functions";
+ private static final String INCLUDE_LABELS = "Include Labels";
+ private static final String SHOW_NAMESPACES = "Show Namespaces";
+ private static final String SHOW_GLOBALS = "Show Globals";
+ private static final String SHOW_EXPORTS = "Show Exports";
+ private static final String SHOW_IMPORTS = "Show Imports";
+
+ /**
+ * Default constructor where all symbols categories are displayed and both functions and label
+ * symbols are included.
+ */
+ public SymbolTreeFilterState() {
+ this(true, true, true, true, true, true);
+ }
+
+ /**
+ * Returns true if the given symbol should be included in the symbol tree.
+ * @param s the symbol to test
+ * @return true if the given symbol should be included in the symbol tree
+ */
+ public boolean passesFilter(Symbol s) {
+ SymbolType symbolType = s.getSymbolType();
+
+ if (symbolType == FUNCTION || symbolType == PARAMETER || symbolType == LOCAL_VAR) {
+ return includeFunctions;
+ }
+ if (symbolType == LABEL) {
+ return includeLabels;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for showing the imports category.
+ * @param b if true, show the imports category
+ * @return a new SymbolTreeSettings instance with a new value for showing the imports category
+ */
+ public SymbolTreeFilterState withImports(boolean b) {
+ if (showImports == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(b, showExports, showGlobals, showNamespaces,
+ includeLabels, includeFunctions);
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for showing the exports category.
+ * @param b if true, show the exports category
+ * @return a new SymbolTreeSettings instance with a new value for showing the exports category
+ */
+ public SymbolTreeFilterState withExports(boolean b) {
+ if (showExports == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(showImports, b, showGlobals, showNamespaces,
+ includeLabels, includeFunctions);
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for showing the globals category.
+ * @param b if true, show the globals category
+ * @return a new SymbolTreeSettings instance with a new value for showing the globals category
+ */
+ public SymbolTreeFilterState withGlobals(boolean b) {
+ if (showGlobals == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(showImports, showExports, b, showNamespaces,
+ includeLabels, includeFunctions);
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for showing the namespaces category.
+ * @param b if true, show the namespaces category
+ * @return a new SymbolTreeSettings instance with a new value for showing the namespaces category
+ */
+ public SymbolTreeFilterState withNamespaces(boolean b) {
+ if (showNamespaces == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(showImports, showExports, showGlobals, b,
+ includeLabels, includeFunctions);
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for including label symbols.
+ * @param b if true, include labels in the tree
+ * @return a new SymbolTreeSettings instance with a new value for including label symbols
+ */
+ public SymbolTreeFilterState withLabels(boolean b) {
+ if (includeLabels == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(showImports, showExports, showGlobals, showNamespaces,
+ b, includeFunctions);
+ }
+
+ /**
+ * Returns a new SymbolTreeSettings instance with all the same settings as this instance, except
+ * with a new value for including function symbols.
+ * @param b if true, include function in the tree
+ * @return a new SymbolTreeSettings instance with a new value for including function symbols
+ */
+ public SymbolTreeFilterState withFunctions(boolean b) {
+ if (includeFunctions == b) {
+ return this;
+ }
+ return new SymbolTreeFilterState(showImports, showExports, showGlobals, showNamespaces,
+ includeLabels, b);
+ }
+
+ /**
+ * {@return true if at lease one category is selected to be shown}
+ */
+ public boolean includesAtLeastOneCateogry() {
+ return showImports || showExports || showGlobals || showNamespaces;
+ }
+
+ /**
+ * Saves the current filter state to the given SaveState
+ * @param saveState the SaveState to save to
+ */
+ public void save(SaveState saveState) {
+ saveState.putBoolean(SHOW_IMPORTS, showImports);
+ saveState.putBoolean(SHOW_EXPORTS, showExports);
+ saveState.putBoolean(SHOW_GLOBALS, showGlobals);
+ saveState.putBoolean(SHOW_NAMESPACES, showNamespaces);
+ saveState.putBoolean(INCLUDE_LABELS, includeLabels);
+ saveState.putBoolean(INCLUDE_FUNCTIONS, includeFunctions);
+ }
+
+ /**
+ * Create a new SymbolTreeFilterState using values from the given SaveState.
+ * @param saveState the saveState that has values stored for a SymbolTreeFilterState
+ * @return a new SymbolTreeFilterState using values from the given SaveState
+ */
+ public static SymbolTreeFilterState restore(SaveState saveState) {
+ boolean showImports = saveState.getBoolean(SHOW_IMPORTS, true);
+ boolean showExports = saveState.getBoolean(SHOW_EXPORTS, true);
+ boolean showGlobals = saveState.getBoolean(SHOW_GLOBALS, true);
+ boolean showNamespaces = saveState.getBoolean(SHOW_NAMESPACES, true);
+ boolean includeLabels = saveState.getBoolean(INCLUDE_LABELS, true);
+ boolean includeFunctions = saveState.getBoolean(INCLUDE_FUNCTIONS, true);
+ return new SymbolTreeFilterState(showImports, showExports, showGlobals, showNamespaces,
+ includeLabels, includeFunctions);
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin.java
index 10888e87a4..fbd944cd80 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin.java
@@ -74,8 +74,9 @@ public class SymbolTreePlugin extends Plugin implements SymbolTreeService {
if (oldProgram != null) {
connectedProvider.programDeactivated(oldProgram);
}
-
- connectedProvider.setProgram(program);
+ if (program != null) {
+ connectedProvider.programActivated(program);
+ }
}
else if (event instanceof ProgramClosedPluginEvent) {
programClosed(((ProgramClosedPluginEvent) event).getProgram());
@@ -196,13 +197,13 @@ public class SymbolTreePlugin extends Plugin implements SymbolTreeService {
return program;
}
- SymbolTreeProvider getProvider() {
+ public SymbolTreeProvider getProvider() {
return connectedProvider;
}
public DisconnectedSymbolTreeProvider createNewDisconnectedProvider(Program p) {
- DisconnectedSymbolTreeProvider newProvider =
- new DisconnectedSymbolTreeProvider(tool, this, p);
+ DisconnectedSymbolTreeProvider newProvider = new DisconnectedSymbolTreeProvider(tool, this,
+ p, connectedProvider.getSymbolTreeFilterState());
disconnectedProviders.add(newProvider);
tool.showComponentProvider(newProvider, true);
return newProvider;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
index 6a0716b977..813aa3eb40 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
@@ -34,6 +34,7 @@ import javax.swing.tree.TreePath;
import docking.ActionContext;
import docking.DockingWindowManager;
import docking.action.DockingAction;
+import docking.action.builder.ActionBuilder;
import docking.widgets.tree.*;
import docking.widgets.tree.support.GTreeNodeTransferable;
import docking.widgets.tree.support.GTreeSelectionEvent.EventOrigin;
@@ -50,11 +51,16 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.util.*;
import ghidra.util.*;
+import ghidra.util.datastruct.Counter;
import ghidra.util.exception.*;
import ghidra.util.task.*;
+import resources.Icons;
public class SymbolTreeProvider extends ComponentProviderAdapter {
+ private static final String NAVIGATE_OUTGOING = "NAVIGATE_OUTGOING";
+ private static final String NAVIGATE_INCOMING = "NAVIGATE_INCOMING";
+
private static final Icon ICON = new GIcon("icon.plugin.symboltree.provider");
private static final String NAME = "Symbol Tree";
@@ -70,6 +76,7 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
protected NavigateOnIncomingAction navigateIncomingAction;
protected NavigateOnOutgoingActon navigateOutgoingAction;
+ protected SymbolTreeFilterState filterState = new SymbolTreeFilterState();
/**
* A list into which tasks to be run will accumulated until we put them into the GTree's
@@ -140,7 +147,8 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
}
protected SymbolTreeRootNode createRootNode() {
- return new SymbolTreeRootNode(program, getNodeGroupThreshold());
+ Program rootNodeProgram = isVisible() ? program : null;
+ return new SymbolTreeRootNode(rootNodeProgram, getNodeGroupThreshold(), filterState);
}
private JComponent buildProvider() {
@@ -314,6 +322,38 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
tool.addLocalAction(this, cloneAction);
tool.addLocalAction(this, tableAction);
tool.addLocalAction(this, primaryAction);
+
+ new ActionBuilder("Collapse All", plugin.getName())
+ .toolBarIcon(Icons.COLLAPSE_ALL_ICON)
+ .description("Collapse all categories")
+ .helpLocation(new HelpLocation("SymbolTreePlugin", "Collapse_All"))
+ .onAction(c -> collapseAllCategories())
+ .buildAndInstallLocal(this);
+
+ new ActionBuilder("Filter", plugin.getName())
+ .toolBarIcon(Icons.CONFIGURE_FILTER_ICON)
+ .description("Displays the Symbol Tree Filter dialog")
+ .helpLocation(new HelpLocation("SymbolTreePlugin", "Symbol_Tree_Filter"))
+ .onAction(c -> configureFilter())
+ .buildAndInstallLocal(this);
+
+ }
+
+ private void collapseAllCategories() {
+ GTreeNode rootNode = tree.getViewRoot();
+ List<GTreeNode> children = rootNode.getChildren();
+ for (GTreeNode childNode : children) {
+ tree.collapseAll(childNode);
+ }
+ }
+
+ SymbolTreeFilterState getSymbolTreeFilterState() {
+ return filterState;
+ }
+
+ private void configureFilter() {
+ SymbolTreeFilterDialog dialog = new SymbolTreeFilterDialog(this, filterState);
+ tool.showDialog(dialog);
}
//==================================================================================================
@@ -333,11 +373,6 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
return new SymbolTreeActionContext(this, program, tree, tree.getSelectionPaths());
}
- @Override
- public void componentShown() {
- setProgram(program);
- }
-
//==================================================================================================
// Class Methods
//==================================================================================================
@@ -358,7 +393,6 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
// get set correctly.
JComponent newComponent = newProvider.getComponent();
DockingWindowManager.registerComponentLoadedListener(newComponent, (dwm, provider) -> {
- newProvider.setProgram(program);
transferSettings(newProvider);
});
}
@@ -386,40 +420,49 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
return program;
}
- void setProgram(Program program) {
- this.program = program;
- if (!isVisible()) {
- return;
- }
-
+ void programActivated(Program activatedProgram) {
+ this.program = activatedProgram;
contextChanged();
-
- if (program == null) {
- return;
- }
-
program.addListener(domainObjectListener);
+ initializeTree();
+ }
- rebuildTree();
+ void programDeactivated(Program deactivatedProgram) {
+ program.removeListener(domainObjectListener);
+ unitializeTree();
+ this.program = null;
+ }
- // restore any state that may be saved
- GTreeState treeState = treeStateMap.get(program);
- if (treeState != null) {
- tree.restoreTreeState(treeState);
+ private void initializeTree() {
+ rebuildTree();
+ if (program != null && isVisible()) {
+ // restore any state that may be saved
+ GTreeState treeState = treeStateMap.get(program);
+ if (treeState != null) {
+ tree.restoreTreeState(treeState);
+ }
}
}
- void programDeactivated(Program deactivatedProgram) {
+ private void unitializeTree() {
tree.cancelWork();
- deactivatedProgram.removeListener(domainObjectListener);
+ if (program != null && isVisible()) {
+ // see if the user has a tree state (opened/selected nodes) and save it
+ GTreeState treeState = tree.getTreeState();
+ treeStateMap.put(program, treeState);
+ }
+ clearTree();
+ }
- // see if the user has a tree state (opened/selected nodes) and save it
- GTreeState treeState = tree.getTreeState();
- treeStateMap.put(program, treeState);
+ @Override
+ public void componentShown() {
+ initializeTree();
+ }
- rebuildTree();
- this.program = null;
+ @Override
+ public void componentHidden() {
+ unitializeTree();
}
protected void rebuildTree() {
@@ -429,6 +472,15 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
component.repaint();
}
+ private void clearTree() {
+ component.remove(tree);
+ SymbolTreeRootNode root =
+ new SymbolTreeRootNode(null, getNodeGroupThreshold(), filterState);
+ tree = createTree(root);
+ component.add(tree, BorderLayout.CENTER);
+ component.repaint();
+ }
+
void programClosed(Program closedProgram) {
tree.cancelWork();
treeStateMap.remove(closedProgram);
@@ -442,11 +494,20 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
return localClipboard;
}
+ public void editNode(GTreeNode parent, String childName) {
+
+ // Force all events to go out. Events that arrive after we start the edit may stop/cancel
+ // the in-progress edit.
+ program.flushEvents();
+ domainChangeUpdateManager.updateNow();
+ tree.startEditing(parent, childName);
+ }
+
public int reparentSymbols(Namespace namespace, List<Symbol> symbolList) {
- int count = 0;
+ Counter counter = new Counter();
StringBuffer sb = new StringBuffer();
- int transactionID = program.startTransaction("Change Parent Namespaces");
- try {
+
+ program.withTransaction("Change Parent Namespaces", () -> {
for (Symbol symbol : symbolList) {
if (!canReparentSymbol(symbol) || !canMoveSymbol(namespace, symbol)) {
@@ -455,7 +516,7 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
try {
symbol.setNamespace(namespace);
- ++count;
+ counter.increment();
}
catch (DuplicateNameException e) {
sb.append("Parent namespace " + namespace.getName() +
@@ -466,14 +527,12 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
e.getMessage() + "\n");
}
}
- }
- finally {
- program.endTransaction(transactionID, true);
- }
+ });
+
if (sb.length() > 0) {
Msg.showInfo(getClass(), null, "Change Parent Namespace Failed", sb.toString());
}
- return count;
+ return counter.count();
}
private boolean canMoveSymbol(Namespace destinationNamespace, Symbol symbol) {
@@ -531,13 +590,30 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
}
private void symbolAdded(Symbol symbol) {
+ if (isFilteredType(symbol)) {
+ return;
+ }
addTask(new SymbolAddedTask(tree, symbol));
}
private void symbolRemoved(Symbol symbol) {
+ if (isFilteredType(symbol)) {
+ return;
+ }
addTask(new SymbolRemovedTask(tree, symbol));
}
+ private boolean isFilteredType(Symbol symbol) {
+ SymbolType symbolType = symbol.getSymbolType();
+ if (symbolType == SymbolType.FUNCTION && !filterState.includeFunctions()) {
+ return true;
+ }
+ if (symbolType == SymbolType.LABEL && !filterState.includeLabels()) {
+ return true;
+ }
+ return false;
+ }
+
private void addTask(AbstractSymbolUpdateTask task) {
// Note: if we want to call this method from off the Swing thread, then we have to
// synchronize on the list that we are adding to here.
@@ -607,18 +683,23 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
}
public void selectSymbol(Symbol symbol) {
+ if (isFilteredType(symbol)) {
+ return;
+ }
SymbolTreeRootNode rootNode = (SymbolTreeRootNode) tree.getViewRoot();
tree.runTask(new SearchTask(tree, rootNode, symbol));
}
void readConfigState(SaveState saveState) {
- navigateIncomingAction.setSelected(saveState.getBoolean("NAVIGATE_INCOMING", false));
- navigateOutgoingAction.setSelected(saveState.getBoolean("NAVIGATE_OUTGOING", true));
+ navigateIncomingAction.setSelected(saveState.getBoolean(NAVIGATE_INCOMING, false));
+ navigateOutgoingAction.setSelected(saveState.getBoolean(NAVIGATE_OUTGOING, true));
+ filterState = SymbolTreeFilterState.restore(saveState);
}
void writeConfigState(SaveState saveState) {
- saveState.putBoolean("NAVIGATE_INCOMING", navigateIncomingAction.isSelected());
- saveState.putBoolean("NAVIGATE_OUTGOING", navigateOutgoingAction.isSelected());
+ saveState.putBoolean(NAVIGATE_INCOMING, navigateIncomingAction.isSelected());
+ saveState.putBoolean(NAVIGATE_OUTGOING, navigateOutgoingAction.isSelected());
+ filterState.save(saveState);
}
void dispose() {
@@ -648,7 +729,7 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
.any(RESTORED).terminate(this::reloadTree)
.with(ProgramChangeRecord.class)
.each(SYMBOL_RENAMED).call(this::processSymbolRenamed)
- .each(SYMBOL_DATA_CHANGED, SYMBOL_SCOPE_CHANGED).call(this::processSymbolChanged)
+ .each(SYMBOL_DATA_CHANGED, SYMBOL_SCOPE_CHANGED, SYMBOL_LIBRARY_CHANGED).call(this::processSymbolChanged)
.each(SYMBOL_ADDED).call(this::processSymbolAdded)
.each(SYMBOL_REMOVED).call(this::processSymbolRemoved)
.each(EXTERNAL_ENTRY_ADDED, EXTERNAL_ENTRY_REMOVED)
@@ -739,6 +820,16 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
return true;
}
+ void setSymbolTreeSettings(SymbolTreeFilterState filterState) {
+ GTreeState state = tree.getTreeState();
+ this.filterState = filterState;
+ SymbolTreeRootNode root = (SymbolTreeRootNode) tree.getModelRoot();
+ root.setSymbolTreeFilterState(filterState);
+
+ GTreeRestoreTreeStateTask task = new GTreeRestoreTreeStateTask(tree, state);
+ tree.runTask(task);
+ }
+
//==================================================================================================
// Inner Classes
//==================================================================================================
@@ -758,8 +849,7 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
public void run(TaskMonitor monitor) throws CancelledException {
try {
monitor.setMessage("Searching for " + searchSymbol.getName());
- SymbolNode key = SymbolNode.createNode(searchSymbol, program);
- GTreeNode node = rootNode.findSymbolTreeNode(key, true, monitor);
+ GTreeNode node = rootNode.findSymbolNode(searchSymbol, true, monitor);
if (node != null) {
tree.setSelectedNode(node);
}
@@ -911,4 +1001,5 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
task.run(monitor);
}
}
+
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/ConvertToClassAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/ConvertToClassAction.java
index 046f974bcf..46193c21e4 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/ConvertToClassAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/ConvertToClassAction.java
@@ -24,7 +24,6 @@ import ghidra.app.plugin.core.symboltree.nodes.SymbolNode;
import ghidra.app.util.NamespaceUtils;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
-import ghidra.util.Msg;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.InvalidInputException;
@@ -34,15 +33,24 @@ import ghidra.util.exception.InvalidInputException;
public class ConvertToClassAction extends SymbolTreeContextAction {
private static final String NAME = "Convert to Class";
+ private SymbolTreePlugin plugin;
public ConvertToClassAction(SymbolTreePlugin plugin, String group, String subGroup) {
super(NAME, plugin.getName());
+
+ this.plugin = plugin;
MenuData menuData = new MenuData(new String[] { NAME }, group);
menuData.setMenuSubGroup(subGroup);
setPopupMenuData(menuData);
setEnabled(false);
}
+ @Override
+ public void dispose() {
+ this.plugin = null;
+ super.dispose();
+ }
+
@Override
public boolean isEnabledForContext(SymbolTreeActionContext context) {
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
@@ -62,48 +70,34 @@ public class ConvertToClassAction extends SymbolTreeContextAction {
@Override
protected void actionPerformed(SymbolTreeActionContext context) {
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
-
- Program program = context.getProgram();
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
-
- SymbolGTree tree = context.getSymbolTree();
- GTreeNode root = tree.getViewRoot();
-
Symbol symbol = ((SymbolNode) node).getSymbol();
Namespace namespace = (Namespace) symbol.getObject();
if (namespace == null) {
return;
}
+ GTreeNode parentNode = node.getParent();
String name = namespace.getName();
+ Program program = context.getProgram();
convertToClass(program, namespace);
- program.flushEvents();
-
- GTreeNode classesNode = root.getChild(SymbolCategory.CLASS_CATEGORY.getName());
- if (classesNode == null) {
- Msg.showInfo(this, null, "Classes Filtered Out of View",
- "New class node is filtered out of view");
- return;
- }
- tree.startEditing(classesNode, name);
+ SymbolTreeProvider provider = plugin.getProvider();
+ provider.editNode(parentNode, name);
}
private static void convertToClass(Program program, Namespace ns) {
- int id = program.startTransaction(NAME);
- boolean success = false;
- try {
- NamespaceUtils.convertNamespaceToClass(ns);
- success = true;
- }
- catch (InvalidInputException e) {
- // This is thrown when the provided namespace is a function
- // It was checked in isEnabledForContext and thus cannot occur
- throw new AssertException(e);
- }
- finally {
- program.endTransaction(id, success);
- }
+
+ program.withTransaction(NAME, () -> {
+ try {
+ NamespaceUtils.convertNamespaceToClass(ns);
+ }
+ catch (InvalidInputException e) {
+ // This is thrown when the provided namespace is a function
+ // It was checked in isEnabledForContext and thus cannot occur
+ throw new AssertException(e);
+ }
+ });
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateClassAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateClassAction.java
index a3e09bc546..dc49da280c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateClassAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateClassAction.java
@@ -20,9 +20,8 @@ import javax.swing.tree.TreePath;
import docking.action.MenuData;
import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
-import ghidra.app.plugin.core.symboltree.SymbolTreeActionContext;
-import ghidra.app.plugin.core.symboltree.SymbolTreePlugin;
-import ghidra.app.plugin.core.symboltree.nodes.ClassCategoryNode;
+import ghidra.app.plugin.core.symboltree.*;
+import ghidra.app.plugin.core.symboltree.nodes.NamespaceCategoryNode;
import ghidra.app.plugin.core.symboltree.nodes.SymbolNode;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
@@ -33,14 +32,23 @@ import ghidra.util.exception.InvalidInputException;
public class CreateClassAction extends SymbolTreeContextAction {
+ private SymbolTreePlugin plugin;
+
public CreateClassAction(SymbolTreePlugin plugin, String group, String subGroup) {
super("Create Class", plugin.getName());
+ this.plugin = plugin;
MenuData menuData = new MenuData(new String[] { "Create Class" }, group);
menuData.setMenuSubGroup(subGroup);
setPopupMenuData(menuData);
setEnabled(false);
}
+ @Override
+ public void dispose() {
+ this.plugin = null;
+ super.dispose();
+ }
+
@Override
protected void actionPerformed(SymbolTreeActionContext context) {
GTree tree = (GTree) context.getContextObject();
@@ -61,7 +69,7 @@ public class CreateClassAction extends SymbolTreeContextAction {
}
Object object = selectionPaths[0].getLastPathComponent();
- if (object instanceof ClassCategoryNode) {
+ if (object instanceof NamespaceCategoryNode) {
return true;
}
if (!(object instanceof SymbolNode symbolNode)) {
@@ -69,16 +77,12 @@ public class CreateClassAction extends SymbolTreeContextAction {
}
Symbol symbol = symbolNode.getSymbol();
- SymbolType symbolType = symbol.getSymbolType();
- if (symbolType == SymbolType.NAMESPACE) {
- Namespace parent = (Namespace) symbol.getObject();
- if (parent == null) {
- return false; // the symbol has been deleted, but the tree has not updated
- }
- return SymbolType.CLASS.isValidParent(context.getProgram(), parent,
- Address.NO_ADDRESS, parent.isExternal());
+ Object parent = symbol.getObject();
+ if (parent instanceof Namespace namespace) {
+ return SymbolType.CLASS.isValidParent(context.getProgram(), namespace,
+ Address.NO_ADDRESS);
}
- return (symbolType == SymbolType.CLASS || symbolType == SymbolType.LIBRARY);
+ return false;
}
private void createNewClass(SymbolTreeActionContext context) {
@@ -95,14 +99,14 @@ public class CreateClassAction extends SymbolTreeContextAction {
}
}
- final String newClassName = createClass(program, parent);
+ String newClassName = createClass(program, parent);
if (newClassName == null) {
// error occurred
return;
}
- program.flushEvents();
- context.getSymbolTree().startEditing(node, newClassName);
+ SymbolTreeProvider provider = plugin.getProvider();
+ provider.editNode(node, newClassName);
}
private String createClass(Program program, Namespace parent) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateLibraryAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateLibraryAction.java
index bef1fe2776..fa9f281358 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateLibraryAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/actions/CreateLibraryAction.java
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -16,30 +15,39 @@
*/
package ghidra.app.plugin.core.symboltree.actions;
-import ghidra.app.plugin.core.symboltree.SymbolTreeActionContext;
-import ghidra.app.plugin.core.symboltree.SymbolTreePlugin;
+import javax.swing.tree.TreePath;
+
+import docking.action.MenuData;
+import docking.widgets.tree.GTree;
+import docking.widgets.tree.GTreeNode;
+import ghidra.app.plugin.core.symboltree.*;
import ghidra.app.plugin.core.symboltree.nodes.ImportsCategoryNode;
import ghidra.app.plugin.core.symboltree.nodes.SymbolTreeRootNode;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.*;
+import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.SymbolTable;
import ghidra.util.Msg;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
-import javax.swing.tree.TreePath;
-
-import docking.action.MenuData;
-import docking.widgets.tree.GTree;
-import docking.widgets.tree.GTreeNode;
-
public class CreateLibraryAction extends SymbolTreeContextAction {
+ private SymbolTreePlugin plugin;
+
public CreateLibraryAction(SymbolTreePlugin plugin) {
super("Create Library", plugin.getName());
+ this.plugin = plugin;
setPopupMenuData(new MenuData(new String[] { "Create Library" }, "0External"));
setEnabled(false);
}
+ @Override
+ public void dispose() {
+ this.plugin = null;
+ super.dispose();
+ }
+
@Override
public boolean isEnabledForContext(SymbolTreeActionContext context) {
@@ -69,34 +77,31 @@ public class CreateLibraryAction extends SymbolTreeContextAction {
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
Program program = context.getProgram();
- Namespace parent = program.getGlobalNamespace();
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
if (node instanceof SymbolTreeRootNode) {
node = node.getChild("Imports");
}
- String newExternalLibraryName = createExternalLibrary(program, parent);
+ String newExternalLibraryName = createExternalLibrary(program);
if (newExternalLibraryName == null) {
return;
}
- program.flushEvents();
- context.getSymbolTree().startEditing(node, newExternalLibraryName);
+ SymbolTreeProvider provider = plugin.getProvider();
+ provider.editNode(node, newExternalLibraryName);
}
- private String createExternalLibrary(Program program, Namespace parent) {
+ private String createExternalLibrary(Program program) {
- String importName = "NewLibrary";
- int transactionID = program.startTransaction("Create Library");
- try {
+ return program.withTransaction("Create Library", () -> {
SymbolTable symbolTable = program.getSymbolTable();
int oneUp = 0;
- importName = "NewLibrary";
- Namespace namespace = null;
- while (namespace == null) {
+ String importName = "NewLibrary";
+ Library library = null;
+ while (library == null) {
try {
- namespace =
+ library =
symbolTable.createExternalLibrary(importName, SourceType.USER_DEFINED);
}
catch (DuplicateNameException e) {
@@ -107,11 +112,7 @@ public class CreateLibraryAction extends SymbolTreeContextAction {
return null;
}
}
- }
- finally {
- program.endTransaction(transactionID, true);
- }
-
- return importName;
+ return importName;
+ });
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassCategoryNode.java
deleted file mode 100644
index 2a65cc49b1..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassCategoryNode.java
+++ /dev/null
@@ -1,324 +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.symboltree.nodes;
-
-import java.awt.datatransfer.DataFlavor;
-import java.util.*;
-import java.util.Map.Entry;
-
-import javax.swing.Icon;
-
-import docking.widgets.tree.GTreeNode;
-import generic.theme.GIcon;
-import ghidra.app.plugin.core.symboltree.SymbolCategory;
-import ghidra.app.util.NamespaceUtils;
-import ghidra.program.model.listing.GhidraClass;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.*;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
-public class ClassCategoryNode extends SymbolCategoryNode {
-
- public static final Icon OPEN_FOLDER_CLASSES_ICON =
- new GIcon("icon.plugin.symboltree.node.category.classes.open");
- public static final Icon CLOSED_FOLDER_CLASSES_ICON =
- new GIcon("icon.plugin.symboltree.node.category.classes.closed");
-
- public ClassCategoryNode(Program program) {
- super(SymbolCategory.CLASS_CATEGORY, program);
- }
-
- @Override
- public Icon getIcon(boolean expanded) {
- return expanded ? OPEN_FOLDER_CLASSES_ICON : CLOSED_FOLDER_CLASSES_ICON;
- }
-
- @Override
- public String getToolTip() {
- return "Symbols for Classes";
- }
-
- @Override
- public DataFlavor getNodeDataFlavor() {
- return null;
- }
-
- @Override
- protected boolean supportsSymbol(Symbol symbol) {
- SymbolType symbolType = symbol.getSymbolType();
- if (symbolType == symbolCategory.getSymbolType()) {
- return true;
- }
-
- // must be in a class at some level
- Namespace parentNamespace = symbol.getParentNamespace();
- while (parentNamespace != null && parentNamespace != globalNamespace) {
- if (parentNamespace instanceof GhidraClass) {
- return true;
- }
- parentNamespace = parentNamespace.getParentNamespace();
- }
-
- return false;
- }
-
- @Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
-
- if ((!isLoaded() && !loadChildren) || monitor.isCancelled()) {
- return null;
- }
-
- Symbol symbol = key.getSymbol();
- Namespace parentNs = symbol.getParentNamespace();
- if (parentNs == globalNamespace) {
- // no need to search for the class in the tree; the class only lives at the top
- return findNode(this, key, loadChildren, monitor);
- }
-
- // set getAllClassNodes() for a description of the map
- Map<GTreeNode, List<Namespace>> classNodes =
- getAllClassNodes(symbol, parentNs, loadChildren, monitor);
- if (classNodes.isEmpty()) {
- return null;
- }
-
- // since the symbol lives in all of these paths, just pick one in a consistent way
- List<GTreeNode> keys = new ArrayList<>(classNodes.keySet());
- Collections.sort(keys);
- GTreeNode classNode = keys.get(0);
- List<Namespace> parentPath = classNodes.get(classNode);
- GTreeNode symbolParent =
- getNamespaceNode(classNode, parentPath, loadChildren, monitor);
- return findNode(symbolParent, key, loadChildren, monitor);
- }
-
- @Override
- public void symbolRemoved(Symbol symbol, Namespace oldNamespace, TaskMonitor monitor) {
-
- if (!isLoaded()) {
- return;
- }
-
- if (!supportsSymbol(symbol)) {
- return;
- }
-
- SymbolNode key = SymbolNode.createKeyNode(symbol, symbol.getName(), program);
- Namespace parentNs = symbol.getParentNamespace();
- if (parentNs == globalNamespace) {
- // no need to search for the class in the tree; the class only lives at the top
- GTreeNode symbolNode = findNode(this, key, false, monitor);
- if (symbolNode != null) {
- removeNode(symbolNode);
- }
- return;
- }
-
- // set getAllClassNodes() for a description of the map
- Map<GTreeNode, List<Namespace>> classNodes =
- getAllClassNodes(symbol, oldNamespace, monitor);
- removeSymbol(key, classNodes, monitor);
- }
-
- @Override
- public void symbolRemoved(Symbol symbol, String oldName, TaskMonitor monitor) {
- if (!isLoaded()) {
- return;
- }
-
- if (!supportsSymbol(symbol)) {
- return;
- }
-
- SymbolNode key = SymbolNode.createKeyNode(symbol, oldName, program);
-
- // See if the class lives on this Classes node. This can happen when the class is the child
- // of a non-class namespace.
- GTreeNode symbolNode = findNode(this, key, false, monitor);
- if (symbolNode != null) {
- removeNode(symbolNode);
- return;
- }
-
- // We could not find the node. See if it is under another class node.
- // (See getAllClassNodes() for a description of the map.)
- Namespace parentNs = symbol.getParentNamespace();
- Map<GTreeNode, List<Namespace>> classNodes = getAllClassNodes(symbol, parentNs, monitor);
- removeSymbol(key, classNodes, monitor);
- }
-
- private void removeSymbol(SymbolNode key, Map<GTreeNode, List<Namespace>> classNodes,
- TaskMonitor monitor) {
-
- Set<Entry<GTreeNode, List<Namespace>>> entries = classNodes.entrySet();
- for (Entry<GTreeNode, List<Namespace>> entry : entries) {
-
- if (monitor.isCancelled()) {
- return;
- }
-
- // start with the top-level class node and walk the namespace path to find the
- // parent for the given symbol
- GTreeNode classNode = entry.getKey();
- List<Namespace> parentPath = entry.getValue();
- GTreeNode symbolParent = getNamespaceNode(classNode, parentPath, false, monitor);
- if (symbolParent == null) {
- continue;
- }
- GTreeNode symbolNode = findNode(symbolParent, key, false, monitor);
- symbolParent.removeNode(symbolNode);
- }
- }
-
- @Override
- public SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
- if (!isLoaded()) {
- return null;
- }
-
- if (!supportsSymbol(symbol)) {
- return null;
- }
-
- if (symbol.getSymbolType() == symbolCategory.getSymbolType()) {
- doAddSymbol(symbol, this); // add new flat Class symbol
- }
-
- // set getAllClassNodes() for a description of the map
- SymbolNode lastNode = null;
- Namespace parentNs = symbol.getParentNamespace();
- Map<GTreeNode, List<Namespace>> classNodes = getAllClassNodes(symbol, parentNs, monitor);
- Set<Entry<GTreeNode, List<Namespace>>> entries = classNodes.entrySet();
- for (Entry<GTreeNode, List<Namespace>> entry : entries) {
-
- // start with the top-level class node and walk the namespace path to find the
- // parent for the given symbol
- GTreeNode classNode = entry.getKey();
- List<Namespace> parentPath = entry.getValue();
- GTreeNode symbolParent =
- getNamespaceNode(classNode, parentPath, false, monitor);
- if (symbolParent != null) {
- lastNode = doAddSymbol(symbol, symbolParent);
- }
-
- }
-
- return lastNode;
- }
-
- /*
- Uses the namespace path of the given symbol to create a mapping from this Classes category
- node's top-level child classes to the path from that child node to the given symbol node.
-
- This mapping allows us to find the symbol in multiple tree paths, such as in this example:
-
- Classes
- Class1
- Label1
- BarNs
- Class2
- Label2
- Class2
- Label2
-
-
- In this tree, the Label2 symbol is in the tree twice. The mapping created by this method
- will have as keys both Class1 and Class2. Class1 will be mapped to Class1/BarNs/Class2
- and Class2 will be mapped to Class2 (since it only has one namespace element).
-
- This code is needed because this Classes category node will duplicate class nodes. It puts
- each class at the top-level (as a flattened view) and then also includes each class under
- any other parent class nodes.
-
- */
- private Map<GTreeNode, List<Namespace>> getAllClassNodes(Symbol symbol, Namespace parentNs,
- TaskMonitor monitor) {
- return getAllClassNodes(symbol, parentNs, false, monitor);
- }
-
- private Map<GTreeNode, List<Namespace>> getAllClassNodes(Symbol symbol, Namespace parentNs,
- boolean loadChildren, TaskMonitor monitor) {
- List<Namespace> parents = NamespaceUtils.getNamespaceParts(parentNs);
- Map<GTreeNode, List<Namespace>> classByPath = new HashMap<>();
- findAllClassNodes(this, parents, classByPath, loadChildren, monitor);
- return classByPath;
- }
-
- private void findAllClassNodes(GTreeNode searchNode, List<Namespace> namespaces,
- Map<GTreeNode, List<Namespace>> results, boolean loadChildren, TaskMonitor monitor) {
-
- if ((!searchNode.isLoaded() && !loadChildren) || monitor.isCancelled()) {
- return;
- }
-
- if (namespaces.isEmpty()) {
- return;
- }
-
- Namespace namespace = getNextClass(namespaces);
- if (namespace == null) {
- return;
- }
-
- Symbol nsSymbol = namespace.getSymbol();
- SymbolNode key = SymbolNode.createKeyNode(nsSymbol, nsSymbol.getName(), program);
- GTreeNode namespaceNode = findNode(searchNode, key, loadChildren, monitor);
- if (namespaceNode == null) {
- return; // we hit the last namespace
- }
-
- if (namespaceNode instanceof ClassSymbolNode) {
- List<Namespace> currentPath = new ArrayList<>(namespaces);
- currentPath.add(0, namespace);
- results.put(namespaceNode, currentPath);
- }
-
- // move to the next namespace
- findAllClassNodes(searchNode, namespaces, results, loadChildren, monitor);
- }
-
- private GhidraClass getNextClass(List<Namespace> namespaces) {
- while (namespaces.size() > 0) {
- Namespace ns = namespaces.remove(0);
- if (ns instanceof GhidraClass) {
- return (GhidraClass) ns;
- }
- }
- return null;
- }
-
- @Override
- protected List<GTreeNode> getSymbols(SymbolType type, TaskMonitor monitor)
- throws CancelledException {
- List<GTreeNode> list = new ArrayList<>();
-
- monitor.initialize(symbolTable.getNumSymbols());
- SymbolType symbolType = symbolCategory.getSymbolType();
- SymbolIterator it = symbolTable.getDefinedSymbols();
- while (it.hasNext()) {
- Symbol s = it.next();
- if (s != null && (s.getSymbolType() == symbolType)) {
- monitor.checkCancelled();
- list.add(SymbolNode.createNode(s, program));
- }
- monitor.incrementProgress(1);
- }
- Collections.sort(list, getChildrenComparator());
- return list;
- }
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassSymbolNode.java
index db0315ddc2..ff3af122fe 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ClassSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,10 +27,6 @@ import ghidra.program.model.symbol.Symbol;
import resources.ResourceManager;
public class ClassSymbolNode extends SymbolNode {
- static final DataFlavor LOCAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Local Classes");
- static final DataFlavor GLOBAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Global Classes");
private static final Icon CLASS_ICON = new GIcon("icon.plugin.symboltree.node.class");
private static final Icon DISABLED_CLASS_ICONDISABLED_CLASS_ICON =
@@ -51,17 +47,12 @@ public class ClassSymbolNode extends SymbolNode {
@Override
public DataFlavor getNodeDataFlavor() {
- return symbol.isGlobal() ? GLOBAL_DATA_FLAVOR : LOCAL_DATA_FLAVOR;
+ return CLASS_DATA_FLAVOR;
}
@Override
public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
for (DataFlavor flavor : dataFlavors) {
- if (symbol.isExternal()) {
- if (isExternal(flavor)) {
- return true;
- }
- }
if (isLabelOrFunction(flavor)) {
return true;
}
@@ -78,16 +69,9 @@ public class ClassSymbolNode extends SymbolNode {
return SelectionTransferData.class.equals(clazz);
}
- private boolean isExternal(DataFlavor dataFlavor) {
- return dataFlavor == CodeSymbolNode.EXTERNAL_DATA_FLAVOR ||
- dataFlavor == FunctionSymbolNode.EXTERNAL_DATA_FLAVOR;
- }
-
private boolean isLabelOrFunction(DataFlavor dataFlavor) {
- return dataFlavor == CodeSymbolNode.GLOBAL_DATA_FLAVOR ||
- dataFlavor == CodeSymbolNode.LOCAL_DATA_FLAVOR ||
- dataFlavor == FunctionSymbolNode.GLOBAL_DATA_FLAVOR ||
- dataFlavor == FunctionSymbolNode.LOCAL_DATA_FLAVOR;
+ return dataFlavor == LABEL_DATA_FLAVOR ||
+ dataFlavor == FUNCTION_DATA_FLAVOR;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/CodeSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/CodeSymbolNode.java
index e2d722f2b8..3e12c4dd20 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/CodeSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/CodeSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,12 +27,6 @@ import ghidra.program.model.symbol.Symbol;
import resources.ResourceManager;
public class CodeSymbolNode extends SymbolNode {
- static final DataFlavor LOCAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Local Labels");
- static final DataFlavor GLOBAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Global Labels");
- static final DataFlavor EXTERNAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - External Data");
//@formatter:off
private static final Icon CODE_ICON = new GIcon("icon.plugin.symboltree.node.code");
@@ -89,10 +83,7 @@ public class CodeSymbolNode extends SymbolNode {
@Override
public DataFlavor getNodeDataFlavor() {
- if (isExternal) {
- return EXTERNAL_DATA_FLAVOR;
- }
- return symbol.isGlobal() ? GLOBAL_DATA_FLAVOR : LOCAL_DATA_FLAVOR;
+ return LABEL_DATA_FLAVOR;
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ConfigurableSymbolTreeRootNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ConfigurableSymbolTreeRootNode.java
deleted file mode 100644
index 76ed5172bc..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ConfigurableSymbolTreeRootNode.java
+++ /dev/null
@@ -1,74 +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.symboltree.nodes;
-
-import java.util.List;
-
-import docking.widgets.tree.GTree;
-import docking.widgets.tree.GTreeNode;
-import ghidra.app.plugin.core.symboltree.DisconnectedSymbolTreeProvider;
-import ghidra.program.model.listing.Program;
-
-/**
- * A version of the Symbol Tree's root node that allows users to disable categories. The categories
- * themselves track their enabled state. This class supports the cloning of a
- * {@link DisconnectedSymbolTreeProvider} by copying the categories' enable state.
- */
-public class ConfigurableSymbolTreeRootNode extends SymbolTreeRootNode {
-
- public ConfigurableSymbolTreeRootNode(Program program, int groupThreshold) {
- super(program, groupThreshold);
- }
-
- public void transferSettings(ConfigurableSymbolTreeRootNode otherRoot) {
-
- if (!isLoaded()) {
- return;
- }
-
- List<GTreeNode> myChildren = getChildren();
- List<GTreeNode> otherChildren = otherRoot.getChildren();
- for (GTreeNode node : myChildren) {
- SymbolCategoryNode myCategoryNode = getModelNode((SymbolCategoryNode) node);
- SymbolCategoryNode otherCategoryNode = getMatchingNode(otherChildren, myCategoryNode);
- otherCategoryNode.setEnabled(myCategoryNode.isEnabled());
- }
- }
-
- private SymbolCategoryNode getMatchingNode(List<GTreeNode> nodes,
- SymbolCategoryNode nodeToMatch) {
-
- for (GTreeNode node : nodes) {
- if (nodeToMatch.equals(node)) {
- return getModelNode((SymbolCategoryNode) node);
- }
- }
-
- return null;
- }
-
- private SymbolCategoryNode getModelNode(SymbolCategoryNode node) {
- GTree gTree = node.getTree();
- if (gTree != null) {
- SymbolCategoryNode modelNode = (SymbolCategoryNode) gTree.getModelNode(node);
- if (node != modelNode) {
- return modelNode;
- }
- }
- return node;
- }
-
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ExportsCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ExportsCategoryNode.java
index 48723b0940..8f630584ac 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ExportsCategoryNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ExportsCategoryNode.java
@@ -15,46 +15,36 @@
*/
package ghidra.app.plugin.core.symboltree.nodes;
-import java.util.*;
+import java.awt.datatransfer.DataFlavor;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.Icon;
-import docking.widgets.tree.GTreeNode;
import generic.theme.GIcon;
import ghidra.app.plugin.core.symboltree.SymbolCategory;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.program.model.address.AddressIterator;
import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.Symbol;
-import ghidra.util.task.TaskMonitor;
+import ghidra.program.model.symbol.*;
+import util.CollectionUtils;
+/**
+ * Symbol Tree category node for showing exported symbols. This node displays all functions or
+ * labels that have been tagged as entry points into this program.
+ */
class ExportsCategoryNode extends SymbolCategoryNode {
private static final Icon OPEN_FOLDER =
new GIcon("icon.plugin.symboltree.node.category.exports.open");
private static final Icon CLOSED_FOLDER =
new GIcon("icon.plugin.symboltree.node.category.exports.closed");
- public ExportsCategoryNode(Program program) {
- super(SymbolCategory.EXPORTS_CATEGORY, program);
+ public ExportsCategoryNode(Program program, SymbolTreeFilterState filterState) {
+ super(SymbolCategory.EXPORTS, program, filterState);
}
@Override
- public List<GTreeNode> generateChildren(TaskMonitor monitor) {
- if (!isEnabled) {
- return Collections.emptyList();
- }
-
- List<GTreeNode> list = new ArrayList<>();
- List<Symbol> functionSymbolList = getExportSymbols();
- for (Symbol symbol : functionSymbolList) {
- list.add(SymbolNode.createNode(symbol, program));
- }
-
- Collections.sort(list, getChildrenComparator());
-
- return list;
- }
-
- private List<Symbol> getExportSymbols() {
+ protected SymbolIterator getPotentialSymbols() {
List<Symbol> symbols = new ArrayList<>();
AddressIterator iterator = symbolTable.getExternalEntryPointIterator();
while (iterator.hasNext()) {
@@ -63,7 +53,14 @@ class ExportsCategoryNode extends SymbolCategoryNode {
symbols.add(symbol);
}
}
- return symbols;
+ return new SymbolIteratorAdapter(symbols.iterator());
+
+ }
+
+ @Override
+ protected List<SymbolNode> createSearchKeys(Symbol symbol, String name,
+ Namespace parentNamespace) {
+ return CollectionUtils.asList(SearchNode.create(symbol, name));
}
@Override
@@ -72,7 +69,15 @@ class ExportsCategoryNode extends SymbolCategoryNode {
}
@Override
- protected boolean supportsSymbol(Symbol symbol) {
+ protected boolean supportsSymbolAtCatogryRoot(Symbol symbol) {
+ if (!symbol.isPrimary()) {
+ return false;
+ }
+ return symbol.isExternalEntryPoint();
+ }
+
+ @Override
+ protected boolean supportsSymbol(Symbol symbol, Namespace namespace) {
if (!symbol.isPrimary()) {
return false;
}
@@ -81,7 +86,13 @@ class ExportsCategoryNode extends SymbolCategoryNode {
return true;
}
- Symbol parent = symbol.getParentSymbol();
+ // this allows the GUI to show function params and locals from the exports category
+ Symbol parent = namespace.getSymbol();
return parent != null && parent.isExternalEntryPoint();
}
+
+ @Override
+ public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
+ return false;
+ }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionCategoryNode.java
deleted file mode 100644
index c9b84e7e22..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionCategoryNode.java
+++ /dev/null
@@ -1,240 +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.symboltree.nodes;
-
-import java.awt.datatransfer.DataFlavor;
-import java.util.Comparator;
-import java.util.List;
-
-import javax.swing.Icon;
-
-import docking.widgets.tree.GTreeNode;
-import generic.theme.GIcon;
-import ghidra.app.plugin.core.symboltree.SymbolCategory;
-import ghidra.program.model.listing.Function;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.*;
-import ghidra.util.task.TaskMonitor;
-
-class FunctionCategoryNode extends SymbolCategoryNode {
-
- public static final Icon OPEN_FOLDER_FUNCTIONS_ICON =
- new GIcon("icon.plugin.symboltree.node.category.function.open");
- public static final Icon CLOSED_FOLDER_FUNCTIONS_ICON =
- new GIcon("icon.plugin.symboltree.node.category.function.closed");
-
- public FunctionCategoryNode(Program program) {
- super(SymbolCategory.FUNCTION_CATEGORY, program);
- }
-
-//
-// This code will allow symbols to appear both in the 'Functions' node *and* in the namespaces
-// node, if they have a namespace. We have decided that we only want symbols appearing in one
-// or the other node, as does the LabelCategoryNode. Anywho, if you put this code back in, then
-// you must change supportsSymbol() below to know how to allow symbols to be both in this
-// node and the namespaces node.
-//
-// @Override
-// protected List<GTreeNode> getSymbols(SymbolType type, TaskMonitor monitor) {
-// List<GTreeNode> nodes = new ArrayList<GTreeNode>();
-// SymbolIterator symbols =
-// program.getSymbolTable().getSymbols(program.getMemory(), SymbolType.FUNCTION, true);
-// while (symbols.hasNext()) {
-// Symbol symbol = symbols.next();
-// if (symbol != null) {
-// nodes.add(SymbolNode.createNode(symbol, program));
-// }
-// }
-// Collections.sort(nodes, symbolNodeComparator);
-// return nodes;
-//
-// }
-
- @Override
- public Icon getIcon(boolean expanded) {
- return expanded ? OPEN_FOLDER_FUNCTIONS_ICON : CLOSED_FOLDER_FUNCTIONS_ICON;
- }
-
- @Override
- public String getToolTip() {
- return "Symbols for Functions";
- }
-
- @Override
- public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
- for (DataFlavor flavor : dataFlavors) {
- if (flavor == FunctionSymbolNode.LOCAL_DATA_FLAVOR) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
- for (GTreeNode treeNode : pastedNodes) {
- if (!(treeNode instanceof FunctionCategoryNode) &&
- !(treeNode instanceof LabelCategoryNode)) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public Comparator<GTreeNode> getChildrenComparator() {
- // this category node uses OrganizationNodes
- return OrganizationNode.COMPARATOR;
- }
-
- @Override
- public SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
- if (!isLoaded()) {
- return null;
- }
-
- if (!supportsSymbol(symbol)) {
- return null;
- }
-
- // only allow functions in the global namespace; others live in the Namespaces category
- if (!isGlobalFunction(symbol)) {
- return null;
- }
-
- // variables and parameters will be beneath function nodes, and our parent method
- // will find them
- if (isVariableParameterOrCodeSymbol(symbol)) {
- return super.symbolAdded(symbol, monitor);
- }
-
- // this namespace will be beneath function nodes, and our parent method will find them
- if (isChildNamespaceOfFunction(symbol)) {
- return super.symbolAdded(symbol, monitor);
- }
-
- // ...otherwise, we have a function and we need to add it as a child of our parent node
- SymbolNode newNode = SymbolNode.createNode(symbol, program);
- doAddNode(this, newNode);
- return newNode;
- }
-
- private boolean isGlobalFunction(Symbol symbol) {
- SymbolType type = symbol.getSymbolType();
- if (type != SymbolType.FUNCTION) {
- return false;
- }
- Namespace namespace = symbol.getParentNamespace();
- return namespace == globalNamespace;
- }
-
- private boolean isChildNamespaceOfFunction(Symbol symbol) {
- if (symbol instanceof Function) {
- return false;
- }
-
- Namespace parentNamespace = symbol.getParentNamespace();
- while (parentNamespace != null && parentNamespace != globalNamespace) {
- if (parentNamespace instanceof Function) {
- return true;
- }
- parentNamespace = parentNamespace.getParentNamespace();
- }
- return false;
- }
-
- private boolean isVariableParameterOrCodeSymbol(Symbol symbol) {
- SymbolType symbolType = symbol.getSymbolType();
- return symbolType.equals(SymbolType.LOCAL_VAR) || symbolType.equals(SymbolType.PARAMETER) ||
- symbolType.equals(SymbolType.LABEL);
- }
-
- @Override
- protected boolean supportsSymbol(Symbol symbol) {
- if (symbol.isExternal()) {
- return false;
- }
-
- // Note: we say that we support function symbol types, even though we do not include
- // functions that live in non-global namespaces. This allows functions that are moved to
- // be removed from this category.
- SymbolType type = symbol.getSymbolType();
- if (type == SymbolType.FUNCTION) {
- return true;
- }
-
- // the symbol must have a function parent at some level
- Namespace parentNamespace = symbol.getParentNamespace();
- while (parentNamespace != null && parentNamespace != globalNamespace) {
- if (parentNamespace instanceof Function) {
- return true;
- }
- parentNamespace = parentNamespace.getParentNamespace();
- }
- return false;
- }
-
- @Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
-
- // if we don't have to loadChildren and we are not loaded get out.
- if (!loadChildren && !isLoaded()) {
- return null;
- }
-
- //
- // Special Case: this node uses the OrganizationNode for partitioning child Function
- // nodes. Further, some functions may contain Label symbols whose name
- // is not related to the function name. In this case, the binary search
- // for the label will fail because its name will not match the org node
- // names, which are based on the functions' names. This call will handle
- // the case where a non-function symbol has a function as its parent.
- //
- GTreeNode node = maybeSearchForSymbolInsideOfFunction(key, loadChildren, monitor);
- if (node != null) {
- return node;
- }
-
- return super.findSymbolTreeNode(key, loadChildren, monitor);
- }
-
- private GTreeNode maybeSearchForSymbolInsideOfFunction(SymbolNode key, boolean loadChildren,
- TaskMonitor monitor) {
-
- Symbol symbol = key.getSymbol();
- Symbol parentSymbol = symbol.getParentSymbol();
- if (parentSymbol == null) {
- return null; // not sure if this can happen
- }
-
- SymbolType parentType = parentSymbol.getSymbolType();
- if (parentType != SymbolType.FUNCTION) {
- return null;
- }
-
- SymbolNode parentKey = SymbolNode.createNode(parentSymbol, program);
- GTreeNode parentNode = super.findSymbolTreeNode(parentKey, loadChildren, monitor);
- if (parentNode == null) {
- return null;
- }
-
- // At this point we have a function and we have found the node for that function.
- // Search that node for the symbol. (This bypasses the OrganizationNode's search
- // algorithm.)
- return ((FunctionSymbolNode) parentNode).findSymbolTreeNode(key, loadChildren, monitor);
- }
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionSymbolNode.java
index 3e6d463cc8..9c1ddc9c71 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/FunctionSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,16 +25,11 @@ import generic.theme.GIcon;
import ghidra.app.util.ToolTipUtils;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.Symbol;
-import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
public class FunctionSymbolNode extends SymbolNode {
//@formatter:off
- static final DataFlavor LOCAL_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Local Functions");
- static final DataFlavor GLOBAL_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Global Functions");
- static final DataFlavor EXTERNAL_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - External Functions");
public static final Icon FUNCTION_ICON = new GIcon("icon.plugin.symboltree.node.function");
public static final Icon THUNK_ICON = new GIcon("icon.plugin.symboltree.node.function.thunk");
@@ -48,8 +43,6 @@ public class FunctionSymbolNode extends SymbolNode {
private String tooltip;
- private boolean isExternal;
-
FunctionSymbolNode(Program program, Symbol symbol) {
super(program, symbol);
}
@@ -95,10 +88,7 @@ public class FunctionSymbolNode extends SymbolNode {
@Override
public DataFlavor getNodeDataFlavor() {
- if (isExternal) {
- return EXTERNAL_DATA_FLAVOR;
- }
- return symbol.isGlobal() ? GLOBAL_DATA_FLAVOR : LOCAL_DATA_FLAVOR;
+ return FUNCTION_DATA_FLAVOR;
}
@Override
@@ -111,31 +101,6 @@ public class FunctionSymbolNode extends SymbolNode {
return CHILD_COMPARATOR;
}
- @Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren,
- TaskMonitor taskMonitor) {
-
- Symbol searchSymbol = key.getSymbol();
- if (symbol == searchSymbol) {
- return this;
- }
-
- if (!isChildType(searchSymbol.getSymbolType())) {
- // the symbol is not a child type of a function (like another function or a library)
- return null;
- }
-
- return super.findSymbolTreeNode(key, loadChildren, taskMonitor);
- }
-
- private boolean isChildType(SymbolType type) {
- //@formatter:off
- return type == SymbolType.PARAMETER ||
- type == SymbolType.LOCAL_VAR ||
- type == SymbolType.LABEL || // label function namespace
- type == SymbolType.NAMESPACE; // namespace in function namespace
- //@formatter:on
- }
//==================================================================================================
// Inner Classes
//==================================================================================================
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/GlobalsCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/GlobalsCategoryNode.java
new file mode 100644
index 0000000000..728d7b7524
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/GlobalsCategoryNode.java
@@ -0,0 +1,111 @@
+/* ###
+ * 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.symboltree.nodes;
+
+import static util.CollectionUtils.*;
+
+import java.awt.datatransfer.DataFlavor;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import docking.widgets.tree.GTreeNode;
+import generic.theme.GIcon;
+import ghidra.app.plugin.core.symboltree.SymbolCategory;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.symbol.*;
+
+/**
+ * Symbol Tree category node for showing global label and function symbols. If the number of global
+ * symbols exceeds the organization limit, the are organized in groups based on common prefixes.
+ */
+public class GlobalsCategoryNode extends SymbolCategoryNode {
+
+ public static final Icon OPEN_FOLDER_GLOBALS_ICON =
+ new GIcon("icon.plugin.symboltree.node.category.globals.open");
+ public static final Icon CLOSED_FOLDER_GLOBALS_ICON =
+ new GIcon("icon.plugin.symboltree.node.category.globals.closed");
+
+ public GlobalsCategoryNode(Program program, SymbolTreeFilterState filterState) {
+ super(SymbolCategory.GLOBALS, program, filterState);
+ }
+
+ @Override
+ public Icon getIcon(boolean expanded) {
+ return expanded ? OPEN_FOLDER_GLOBALS_ICON : CLOSED_FOLDER_GLOBALS_ICON;
+ }
+
+ @Override
+ public String getToolTip() {
+ return "Symbols for Global Functions and Labels";
+ }
+
+ @Override
+ public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
+ for (DataFlavor flavor : dataFlavors) {
+ if (flavor == FUNCTION_DATA_FLAVOR || flavor == LABEL_DATA_FLAVOR) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Comparator<GTreeNode> getChildrenComparator() {
+ // this category node uses OrganizationNodes
+ return OrganizationNode.COMPARATOR;
+ }
+
+ @Override
+ protected List<SymbolNode> createSearchKeys(Symbol symbol, String name, Namespace ns) {
+ if (isGlobalLabelOrFunction(symbol, ns)) {
+ return asList(SearchNode.create(symbol, name));
+ }
+
+ // The only other type of symbol we support in this category are symbols that live inside
+ // global functions. Therefore, the symbol must be a function variable and 'ns' must be
+ // a global function (verified by supportsSymbol()).
+ return asList(SearchNode.create(ns), SearchNode.create(symbol, name));
+ }
+
+ @Override
+ protected boolean supportsSymbolAtCatogryRoot(Symbol symbol) {
+ return isGlobalLabelOrFunction(symbol, symbol.getParentNamespace());
+ }
+
+ @Override
+ protected boolean supportsSymbol(Symbol symbol, Namespace namespace) {
+ if (isGlobalLabelOrFunction(symbol, namespace)) {
+ return true;
+ }
+ // also allow symbols that live in a global function
+ if (isGlobalLabelOrFunction(namespace.getSymbol(), namespace.getParentNamespace())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isGlobalLabelOrFunction(Symbol symbol, Namespace namespace) {
+ if (namespace == null || !namespace.isGlobal()) {
+ return false;
+ }
+ SymbolType type = symbol.getSymbolType();
+ return type == SymbolType.FUNCTION || type == SymbolType.LABEL;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsCategoryNode.java
index 88571e92f5..96700981a5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsCategoryNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsCategoryNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,13 +15,28 @@
*/
package ghidra.app.plugin.core.symboltree.nodes;
+import java.awt.datatransfer.DataFlavor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
import javax.swing.Icon;
+import docking.widgets.tree.GTreeNode;
import generic.theme.GIcon;
import ghidra.app.plugin.core.symboltree.SymbolCategory;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.Symbol;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
+import ghidra.app.util.NamespaceUtils;
+import ghidra.program.model.listing.*;
+import ghidra.program.model.symbol.*;
+import ghidra.util.task.TaskMonitor;
+import util.CollectionUtils;
+/**
+ * Symbol Tree category node for showing (external) symbols. This node displays library
+ * nodes as its immediate children. Within each library node, the symbols within that library are
+ * show, organized by namespace.
+ */
public class ImportsCategoryNode extends SymbolCategoryNode {
private static Icon CLOSED_FOLDER_EXTERNALS_ICON =
@@ -29,8 +44,8 @@ public class ImportsCategoryNode extends SymbolCategoryNode {
private static Icon OPEN_FOLDER_EXTERNALS_ICON =
new GIcon("icon.plugin.symboltree.node.category.imports.open");
- public ImportsCategoryNode(Program program) {
- super(SymbolCategory.IMPORTS_CATEGORY, program);
+ public ImportsCategoryNode(Program program, SymbolTreeFilterState filterState) {
+ super(SymbolCategory.IMPORTS, program, filterState);
}
@Override
@@ -44,7 +59,176 @@ public class ImportsCategoryNode extends SymbolCategoryNode {
}
@Override
- protected boolean supportsSymbol(Symbol symbol) {
- return symbol.isExternal();
+ protected boolean supportsSymbol(Symbol symbol, Namespace ns) {
+ if (symbol.isExternal()) {
+ return true;
+ }
+
+ return isInExternalFunction(symbol, ns);
+ }
+
+ @Override
+ protected SymbolIterator getPotentialSymbols() {
+ List<Library> libraries = program.getExternalManager().getLibraries();
+ List<Symbol> symbols =
+ libraries.stream().map(l -> l.getSymbol()).collect(Collectors.toList());
+ return new SymbolIteratorAdapter(symbols.iterator());
+ }
+
+ @Override
+ protected boolean supportsSymbolAtCatogryRoot(Symbol symbol) {
+ return symbol.getSymbolType() == SymbolType.LIBRARY;
+ }
+
+ private boolean isInExternalFunction(Symbol symbol, Namespace ns) {
+ if (ns instanceof Function function) {
+ return function.isExternal();
+ }
+ return false;
+ }
+
+ @Override
+ protected final SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
+ if (!isLoaded()) {
+ return null;
+ }
+
+ if (!supportsSymbol(symbol, symbol.getParentNamespace())) {
+ return null;
+ }
+
+ // global externals will work using the generic symbolAdded
+ if (symbol.getParentNamespace().isGlobal()) {
+ return super.symbolAdded(symbol, monitor);
+ }
+
+ // if this symbol is in a function, then normal added will work
+ if (isInExternalFunction(symbol, symbol.getParentNamespace())) {
+ return super.symbolAdded(symbol, monitor);
+ }
+
+ // only special case is for a new symbol in a namespace
+ String libraryName = symbol.getLibrary().getName();
+ LibrarySymbolNode child = (LibrarySymbolNode) getChild(libraryName);
+ if (child != null) {
+ return child.symbolAdded(symbol);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected final void symbolRemoved(Symbol symbol, Namespace oldNamespace, String oldName,
+ TaskMonitor monitor) {
+
+ if (!isLoaded()) {
+ return;
+ }
+ if (!filterState.passesFilter(symbol)) {
+ return;
+ }
+ if (!supportsSymbol(symbol, oldNamespace)) {
+ return;
+ }
+ super.symbolRemoved(symbol, oldNamespace, oldName, monitor);
+
+ // we still have to remove the symbol from any intermediate namespace nodes
+ Namespace parent = symbol.getParentNamespace();
+ if (parent.isGlobal()) {
+ return;
+ }
+ List<SymbolNode> keys = createSearchKeys(symbol, oldName, oldNamespace);
+ keys.removeLast();
+ // key[0] is the library, all the others are intermediate namespace nodes
+ while (keys.size() > 1) {
+ GTreeNode foundNode = getNodeByPath(keys, false, monitor);
+ if (foundNode instanceof ImportsNamespaceNode namespaceNode) {
+ namespaceNode.removeSymbol(symbol);
+ }
+ keys.removeLast();
+ }
+ }
+
+ @Override
+ protected List<SymbolNode> createSearchKeys(Symbol symbol, String name, Namespace ns) {
+ SymbolType type = symbol.getSymbolType();
+ if (type == SymbolType.LIBRARY) {
+ return CollectionUtils.asList(SearchNode.create(symbol, name));
+ }
+
+ /*
+ The layout of the Imports category node:
+
+ Imports
+ LibraryName
+ Function
+ Variable
+ Label
+ Namespace
+ Function
+ Label
+ */
+ List<SymbolNode> keys = new ArrayList<>();
+ Library library = getLibrary(symbol, ns);
+ SearchNode libraryKey = SearchNode.create(library.getSymbol(), library.getName());
+ keys.add(libraryKey);
+
+ if (isLabelOrFunction(symbol)) {
+ addNamespaceKeys(ns, keys);
+ keys.add(SearchNode.create(symbol, name));
+ return keys;
+ }
+
+ // otherwise we have a function variable
+ Symbol functionSymbol = symbol.getParentSymbol();
+ addNamespaceKeys(functionSymbol.getParentNamespace(), keys);
+
+ SearchNode functionKey = SearchNode.create(functionSymbol, functionSymbol.getName());
+ keys.add(functionKey);
+
+ SearchNode variableKey = SearchNode.create(symbol, name);
+ keys.add(variableKey);
+ return keys;
+ }
+
+ private void addNamespaceKeys(Namespace ns, List<SymbolNode> keys) {
+ List<Namespace> parents = NamespaceUtils.getNamespaceParts(ns);
+ for (Namespace parent : parents) {
+ keys.add(SearchNode.create(parent));
+ }
+
+ }
+
+ private boolean isLabelOrFunction(Symbol symbol) {
+ SymbolType type = symbol.getSymbolType();
+ return type == SymbolType.FUNCTION || type == SymbolType.LABEL;
+ }
+
+ private Library getLibrary(Symbol symbol, Namespace ns) {
+ SymbolType type = symbol.getSymbolType();
+ if (type == SymbolType.LIBRARY) {
+ return (Library) symbol.getObject();
+ }
+ if (type == SymbolType.FUNCTION || type == SymbolType.LABEL) {
+ return symbol.getLibrary();
+ }
+ // assume symbol is a function variable and its parent is an external function
+ return ns.getSymbol().getLibrary();
+ }
+
+ @Override
+ protected SymbolNode doAddSymbol(Symbol symbol, GTreeNode parentNode) {
+ if (!parentNode.isLoaded()) {
+ return null; // the node's not open, we don't care
+ }
+ SymbolNode newNode = SymbolNode.createNode(symbol, program);
+ doAddNode(parentNode, newNode);
+ return newNode;
+ }
+
+ @Override
+ public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
+ return false;
}
+
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsNamespaceNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsNamespaceNode.java
new file mode 100644
index 0000000000..9413a71e51
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ImportsNamespaceNode.java
@@ -0,0 +1,141 @@
+/* ###
+ * 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.symboltree.nodes;
+
+import java.awt.datatransfer.DataFlavor;
+import java.util.*;
+
+import javax.swing.Icon;
+
+import docking.widgets.tree.GTreeNode;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.symbol.Namespace;
+import ghidra.program.model.symbol.Symbol;
+import ghidra.util.task.TaskMonitor;
+
+/**
+ * Special type of Namespace node just for the imports category. This one is special in that it
+ * only includes symbols from the library that it is within or child namespaces that contain
+ * external symbols from the library this node is within.
+ */
+public class ImportsNamespaceNode extends SymbolNode {
+ private static final Icon NAMESPACE_ICON = NamespaceSymbolNode.NAMESPACE_ICON;
+ private static final Icon DISABLED_NAMESPACE_ICON = NamespaceSymbolNode.DISABLED_NAMESPACE_ICON;
+
+ private Set<Symbol> symbols;
+ private Namespace namespace;
+
+ public ImportsNamespaceNode(Namespace namespace, Symbol s, Program program) {
+ // make sure the set is mutable
+ this(namespace, new HashSet<>(Set.of(s)), program);
+ }
+
+ public ImportsNamespaceNode(Namespace namespace, Set<Symbol> set, Program program) {
+ super(program, namespace.getSymbol());
+ this.symbols = new HashSet<>(set); // the set must be mutable
+ this.namespace = namespace;
+ }
+
+ @Override
+ public Icon getIcon(boolean expanded) {
+ if (isCut()) {
+ return DISABLED_NAMESPACE_ICON;
+ }
+ return NAMESPACE_ICON;
+ }
+
+ @Override
+ public DataFlavor getNodeDataFlavor() {
+ return NAMESPACE_DATA_FLAVOR;
+ }
+
+ @Override
+ public Namespace getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
+ return false;
+ }
+
+ @Override
+ public List<GTreeNode> generateChildren(TaskMonitor monitor) {
+ List<GTreeNode> list = new ArrayList<>();
+ Map<Namespace, Set<Symbol>> map = organizeByNamespace(symbols, namespace);
+ Set<Symbol> directChildren = map.computeIfAbsent(namespace, k -> new HashSet<Symbol>());
+ for (Symbol s : directChildren) {
+ list.add(createNode(s, program));
+ }
+ map.remove(namespace);
+ for (Namespace ns : map.keySet()) {
+ list.add(new ImportsNamespaceNode(ns, map.get(ns), program));
+ }
+ sort(list);
+ return list;
+ }
+
+ static Map<Namespace, Set<Symbol>> organizeByNamespace(Set<Symbol> symbols,
+ Namespace root) {
+ Map<Namespace, Set<Symbol>> map = new HashMap<>();
+ for (Symbol s : symbols) {
+ Namespace topNamespace = getTopLevelNamespace(s, root);
+ Set<Symbol> list = map.computeIfAbsent(topNamespace, k -> new HashSet<Symbol>());
+ list.add(s);
+ }
+ return map;
+ }
+
+ static Namespace getTopLevelNamespace(Symbol s, Namespace root) {
+ Namespace parentNamespace = s.getParentNamespace();
+ if (parentNamespace == root) {
+ return root;
+ }
+ while (parentNamespace.getParentNamespace() != root) {
+ parentNamespace = parentNamespace.getParentNamespace();
+ }
+ return parentNamespace;
+ }
+
+ public SymbolNode symbolAdded(Symbol s) {
+ symbols.add(s);
+ if (!isLoaded()) {
+ return null;
+ }
+ Namespace topNamespace = getTopLevelNamespace(s, namespace);
+ if (topNamespace == namespace) {
+ SymbolNode node = createNode(s, program);
+ doInsertNode(node);
+ return node;
+ }
+ GTreeNode child = getChild(topNamespace.getName());
+ if (child instanceof ImportsNamespaceNode namespaceNode) {
+ return namespaceNode.symbolAdded(s);
+ }
+ doInsertNode(new ImportsNamespaceNode(topNamespace, symbol, program));
+
+ // The direct parent namespace node of the symbol is not in the tree. We did add one of
+ // its ancestors above, but did not add the symbol itself.
+ return null;
+ }
+
+ void removeSymbol(Symbol s) {
+ symbols.remove(s);
+ if (symbols.isEmpty()) {
+ getParent().removeNode(this);
+ }
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LabelCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LabelCategoryNode.java
deleted file mode 100644
index 6d3281a546..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LabelCategoryNode.java
+++ /dev/null
@@ -1,115 +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.symboltree.nodes;
-
-import java.awt.datatransfer.DataFlavor;
-import java.util.Comparator;
-import java.util.List;
-
-import javax.swing.Icon;
-
-import docking.widgets.tree.GTreeNode;
-import generic.theme.GIcon;
-import ghidra.app.plugin.core.symboltree.SymbolCategory;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.Symbol;
-import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.task.TaskMonitor;
-
-public class LabelCategoryNode extends SymbolCategoryNode {
-
- public static final Icon OPEN_FOLDER_LABELS_ICON =
- new GIcon("icon.plugin.symboltree.node.category.label.open");
- public static final Icon CLOSED_FOLDER_LABELS_ICON =
- new GIcon("icon.plugin.symboltree.node.category.label.closed");
-
- public LabelCategoryNode(Program program) {
- super(SymbolCategory.LABEL_CATEGORY, program);
- }
-
- @Override
- public Icon getIcon(boolean expanded) {
- return expanded ? OPEN_FOLDER_LABELS_ICON : CLOSED_FOLDER_LABELS_ICON;
- }
-
- @Override
- public String getToolTip() {
- return "Symbols for Global Labels";
- }
-
- @Override
- public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
- for (DataFlavor flavor : dataFlavors) {
- if (flavor == CodeSymbolNode.LOCAL_DATA_FLAVOR) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- protected boolean supportsSymbol(Symbol symbol) {
- if (!symbol.isGlobal() || symbol.isExternal()) {
- return false;
- }
- SymbolType symbolType = symbol.getSymbolType();
- return symbolType == symbolCategory.getSymbolType();
- }
-
- @Override
- protected List<GTreeNode> getSymbols(SymbolType type, TaskMonitor monitor)
- throws CancelledException {
- return getSymbols(type, true, monitor);
- }
-
- @Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
- for (GTreeNode treeNode : pastedNodes) {
- if (!(treeNode instanceof LabelCategoryNode)) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public Comparator<GTreeNode> getChildrenComparator() {
- // this category node uses OrganizationNodes
- return OrganizationNode.COMPARATOR;
- }
-
- @Override
- public SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
- if (!isLoaded()) {
- return null;
- }
-
- // only include global symbols
- if (!symbol.isGlobal()) {
- return null;
- }
-
- if (!supportsSymbol(symbol)) {
- return null;
- }
-
- SymbolNode newNode = SymbolNode.createNode(symbol, program);
- doAddNode(this, newNode);
- return newNode;
- }
-}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LibrarySymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LibrarySymbolNode.java
index bfb656ec45..b2978a1dcb 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LibrarySymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LibrarySymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,64 +16,23 @@
package ghidra.app.plugin.core.symboltree.nodes;
import java.awt.datatransfer.DataFlavor;
-import java.util.Comparator;
+import java.util.*;
import javax.swing.Icon;
import docking.widgets.tree.GTreeNode;
import generic.theme.GIcon;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
public class LibrarySymbolNode extends SymbolNode {
- private static final String ORDINAL_PREFIX = "Ordinal_";
-
private static final Icon LIBRARY_ICON = new GIcon("icon.plugin.symboltree.node.library");
- private static Comparator<GTreeNode> CHILD_COMPARATOR = (o1, o2) -> {
- SymbolNode symbolNode1 = (SymbolNode) o1;
- SymbolNode symbolNode2 = (SymbolNode) o2;
-
- Symbol s1 = symbolNode1.getSymbol();
- Symbol s2 = symbolNode2.getSymbol();
-
- Integer result = tryToCompareExternalLocationsByOrdinal(s1, s2);
- if (result != null) {
- return result;
- }
-
- return o1.compareTo(o2);
- };
-
- private static Integer tryToCompareExternalLocationsByOrdinal(Symbol s1, Symbol s2) {
- Object so1 = s1.getObject();
- if (!(so1 instanceof ExternalLocation)) {
- return null;
- }
-
- Object so2 = s2.getObject();
- if (!(so2 instanceof ExternalLocation)) {
- return null;
- }
-
- String n1 = s1.getName();
- String n2 = s2.getName();
- if (n1.startsWith(ORDINAL_PREFIX) && n2.startsWith(ORDINAL_PREFIX)) {
- try {
- int ordinal1 = Integer.parseInt(n1.substring(ORDINAL_PREFIX.length()));
- int ordinal2 = Integer.parseInt(n2.substring(ORDINAL_PREFIX.length()));
- return ordinal1 - ordinal2;
- }
- catch (NumberFormatException nfe) {
- // just perform default operation below
- }
- }
-
- return null;
- }
-
private String tooltip;
LibrarySymbolNode(Program program, Symbol symbol) {
@@ -88,8 +47,42 @@ public class LibrarySymbolNode extends SymbolNode {
}
@Override
- public Comparator<GTreeNode> getChildrenComparator() {
- return CHILD_COMPARATOR;
+ public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException {
+ List<GTreeNode> list = new ArrayList<>();
+ if (program.isClosed()) {
+ return list;
+ }
+
+ Set<Symbol> symbolsInLibrary = getSymbolsForLibrary(monitor);
+ Namespace global = getGlobalNamespace();
+ Map<Namespace, Set<Symbol>> map =
+ ImportsNamespaceNode.organizeByNamespace(symbolsInLibrary, global);
+ Set<Symbol> globalSymbols = map.computeIfAbsent(global, k -> new HashSet<>());
+ for (Symbol s : globalSymbols) {
+ list.add(createNode(s, program));
+ }
+ map.remove(global);
+ for (Namespace namespace : map.keySet()) {
+ list.add(new ImportsNamespaceNode(namespace, map.get(namespace), program));
+ }
+
+ sort(list);
+ return list;
+ }
+
+ private Set<Symbol> getSymbolsForLibrary(TaskMonitor monitor) throws CancelledException {
+ Set<Symbol> set = new HashSet<>();
+ SymbolTreeFilterState filterState = getFilterState();
+ Library library = (Library) symbol.getObject();
+ SymbolTable symbolTable = program.getSymbolTable();
+ SymbolIterator iter = symbolTable.getSymbols(library);
+ for (Symbol s : iter) {
+ monitor.checkCancelled();
+ if (filterState.passesFilter(s)) {
+ set.add(s);
+ }
+ }
+ return set;
}
@Override
@@ -117,8 +110,29 @@ public class LibrarySymbolNode extends SymbolNode {
return false;
}
- @Override
- public Namespace getNamespace() {
- return (Library) symbol.getObject();
+ SymbolNode symbolAdded(Symbol s) {
+ if (!isLoaded()) {
+ return null;
+ }
+
+ Namespace topLevelNamespace =
+ ImportsNamespaceNode.getTopLevelNamespace(s, getGlobalNamespace());
+ // we already know that this namespace is not global, so we either have a node for it
+ // or we need to add one.
+ GTreeNode child = getChild(topLevelNamespace.getName());
+ if (child instanceof ImportsNamespaceNode namespaceNode) {
+ return namespaceNode.symbolAdded(s);
+ }
+
+ doInsertNode(new ImportsNamespaceNode(topLevelNamespace, s, program));
+
+ // The direct parent namespace node of the symbol is not in the tree. We did add one of
+ // its ancestors above, but did not add the symbol itself.
+ return null;
+ }
+
+ private Namespace getGlobalNamespace() {
+ // the symbol is a library which is always global
+ return symbol.getParentNamespace();
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LocalVariableSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LocalVariableSymbolNode.java
index 41ba219b28..bd7c3b63a2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LocalVariableSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/LocalVariableSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/MoreNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/MoreNode.java
index 1ef7cef511..79341748b1 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/MoreNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/MoreNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -52,11 +52,6 @@ public class MoreNode extends SymbolTreeNode {
return false;
}
- @Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
- return false;
- }
-
@Override
public void setNodeCut(boolean isCut) {
throw new UnsupportedOperationException("Cannot cut an organization node");
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceCategoryNode.java
index 4c9555f71b..9db6941168 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceCategoryNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceCategoryNode.java
@@ -16,27 +16,36 @@
package ghidra.app.plugin.core.symboltree.nodes;
import java.awt.datatransfer.DataFlavor;
-import java.util.List;
+import java.util.*;
import javax.swing.Icon;
-import docking.widgets.tree.GTreeNode;
import generic.theme.GIcon;
import ghidra.app.plugin.core.symboltree.SymbolCategory;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.app.util.NamespaceUtils;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
-import ghidra.util.task.TaskMonitor;
+/**
+ * Symbol Tree category node for showing non-global label and function symbols, classes, and
+ * namespaces. All nodes are organized by namespace.
+ */
public class NamespaceCategoryNode extends SymbolCategoryNode {
- public static final Icon OPEN_FOLDER_NAMESPACES_ICON =
+ private static final Icon OPEN_FOLDER_NAMESPACES_ICON =
new GIcon("icon.plugin.symboltree.node.category.namespace.open");
- public static final Icon CLOSED_FOLDER_NAMESPACES_ICON =
+ private static final Icon CLOSED_FOLDER_NAMESPACES_ICON =
new GIcon("icon.plugin.symboltree.node.category.namespace.closed");
- public NamespaceCategoryNode(Program program) {
- super(SymbolCategory.NAMESPACE_CATEGORY, program);
+ static final Set<DataFlavor> supportedFlavors = Set.of(
+ NAMESPACE_DATA_FLAVOR,
+ CLASS_DATA_FLAVOR,
+ FUNCTION_DATA_FLAVOR,
+ LABEL_DATA_FLAVOR);
+
+ public NamespaceCategoryNode(Program program, SymbolTreeFilterState filterState) {
+ super(SymbolCategory.NAMESPACES, program, filterState);
}
@Override
@@ -45,110 +54,50 @@ public class NamespaceCategoryNode extends SymbolCategoryNode {
}
@Override
- protected boolean supportsSymbol(Symbol symbol) {
-
- if (symbol.isExternal()) {
+ protected boolean supportsSymbolAtCatogryRoot(Symbol symbol) {
+ if (!symbol.getParentNamespace().isGlobal()) {
return false;
}
-
SymbolType symbolType = symbol.getSymbolType();
- if (symbolType == SymbolType.NAMESPACE) {
- return true;
- }
-
- // must be in a non-global namespace
- Namespace parentNamespace = symbol.getParentNamespace();
- return parentNamespace != null && parentNamespace != globalNamespace;
+ return symbolType == SymbolType.NAMESPACE || symbolType == SymbolType.CLASS;
}
@Override
- public void symbolRemoved(Symbol symbol, Namespace oldNamespace, TaskMonitor monitor) {
-
- if (!isLoaded()) {
- return;
- }
-
- if (!supportsSymbol(symbol)) {
- return;
- }
-
- List<Namespace> parents = NamespaceUtils.getNamespaceParts(oldNamespace);
- GTreeNode namespaceNode = getNamespaceNode(this, parents, false, monitor);
- if (namespaceNode == null) {
- return;
- }
-
- SymbolNode key = SymbolNode.createKeyNode(symbol, symbol.getName(), program);
- GTreeNode foundNode = findNode(namespaceNode, key, false, monitor);
- if (foundNode == null) {
- return;
- }
-
- GTreeNode foundParent = foundNode.getParent();
- foundParent.removeNode(foundNode);
- }
+ protected boolean supportsSymbol(Symbol symbol, Namespace namespace) {
- @Override
- public SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
-
- if (!isLoaded()) {
- return null;
- }
-
- if (!supportsSymbol(symbol)) {
- return null;
- }
-
- GTreeNode parentNode = this;
- if (symbol.isGlobal()) {
- return doAddSymbol(symbol, parentNode);
+ if (symbol.isExternal()) {
+ return false;
}
- Namespace parentNamespace = symbol.getParentNamespace();
- List<Namespace> parents = NamespaceUtils.getNamespaceParts(parentNamespace);
- GTreeNode namespaceNode = getNamespaceNode(this, parents, false, monitor);
- if (namespaceNode == null) {
- return null;
+ SymbolType symbolType = symbol.getSymbolType();
+ if (symbolType == SymbolType.NAMESPACE || symbolType == SymbolType.CLASS) {
+ return true;
}
- return doAddSymbol(symbol, namespaceNode);
+ // symbols in the global namespace are under other categories (Functions, Labels, Classes)
+ return namespace != null && !namespace.isGlobal();
}
@Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
-
- if ((!isLoaded() && !loadChildren) || monitor.isCancelled()) {
- return null;
- }
-
- Symbol symbol = key.getSymbol();
- Namespace parent = symbol.getParentNamespace();
- List<Namespace> parents = NamespaceUtils.getNamespaceParts(parent);
- GTreeNode namespaceNode = getNamespaceNode(this, parents, loadChildren, monitor);
- if (namespaceNode != null) {
- return findNode(namespaceNode, key, loadChildren, monitor);
+ protected List<SymbolNode> createSearchKeys(Symbol symbol, String name, Namespace ns) {
+ List<SymbolNode> keys = new ArrayList<>();
+ List<Namespace> parents = NamespaceUtils.getNamespaceParts(ns);
+ for (Namespace parent : parents) {
+ keys.add(SearchNode.create(parent));
}
+ keys.add(SearchNode.create(symbol, name));
- // look in the namespace node for the given symbol
- return findNode(this, key, loadChildren, monitor);
+ return keys;
}
@Override
public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
for (DataFlavor flavor : dataFlavors) {
- if (isSupportedLocalFlavor(flavor)) {
+ if (supportedFlavors.contains(flavor)) {
return true;
}
}
return false;
}
- public boolean isSupportedLocalFlavor(DataFlavor flavor) {
- if (!isLocalDataFlavor(flavor)) {
- return false;
- }
-
- // we don't know how to add a class to the top-level category node
- return flavor != ClassSymbolNode.LOCAL_DATA_FLAVOR;
- }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceSymbolNode.java
index ff17bc325e..495702578d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/NamespaceSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,13 +27,9 @@ import ghidra.program.model.symbol.Symbol;
import resources.ResourceManager;
public class NamespaceSymbolNode extends SymbolNode {
- static final DataFlavor LOCAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Local Namespaces");
- static final DataFlavor GLOBAL_DATA_FLAVOR =
- new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Global Namespaces");
- public static final Icon NAMESPACE_ICON = new GIcon("icon.plugin.symboltree.node.namespace");
- public static final Icon DISABLED_NAMESPACE_ICON =
+ static final Icon NAMESPACE_ICON = new GIcon("icon.plugin.symboltree.node.namespace");
+ static final Icon DISABLED_NAMESPACE_ICON =
ResourceManager.getDisabledIcon(NAMESPACE_ICON);
NamespaceSymbolNode(Program program, Symbol symbol) {
@@ -50,7 +46,7 @@ public class NamespaceSymbolNode extends SymbolNode {
@Override
public DataFlavor getNodeDataFlavor() {
- return symbol.isGlobal() ? GLOBAL_DATA_FLAVOR : LOCAL_DATA_FLAVOR;
+ return NAMESPACE_DATA_FLAVOR;
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNode.java
index c56abe314b..3c8e7a5174 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNode.java
@@ -160,11 +160,6 @@ public class OrganizationNode extends SymbolTreeNode {
return false;
}
- @Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
- return false;
- }
-
@Override
public boolean isCut() {
return false;
@@ -270,43 +265,6 @@ public class OrganizationNode extends SymbolTreeNode {
}
}
- @Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren,
- TaskMonitor taskMonitor) {
-
- String symbolName = key.getName();
- if (!symbolName.startsWith(baseName)) {
- // the given name does not start with the base name; it cannot be in this node
- return null;
- }
-
- // special case: all symbols in this group have the same name.
- if (moreNode != null) {
- if (!symbolName.equals(baseName)) {
- return null;
- }
- // The node either belongs to this node's children or it is represented by the
- // 'more' node
- for (GTreeNode child : children()) {
- SymbolTreeNode symbolTreeNode = (SymbolTreeNode) child;
- if (symbolTreeNode.getSymbol() == key.getSymbol()) {
- return child;
- }
- }
-
- return moreNode;
- }
-
- //
- // Note: The 'key' node used for searching will find us the parent node of the symbol
- // that has changed if it is an org node (this is because the org node searches
- // using the old name). So, org nodes are different than normal nodes in that
- // the old name will find the right parent, but not the actual current node, as
- // it has a new name.
- //
- return super.findSymbolTreeNode(key, loadChildren, taskMonitor);
- }
-
@Override
public int compareTo(GTreeNode node) {
if (!(node instanceof OrganizationNode)) {
@@ -437,6 +395,32 @@ public class OrganizationNode extends SymbolTreeNode {
}
+ @Override
+ public SymbolTreeNode getMatchingChild(SymbolNode key, boolean loadChildren) {
+ // We only have 'more' nodes when every node in this Organization node have the same
+ // identical name. In this case, the name of this node (baseName) will have the same
+ // name as every childNode contained in this node. Also, only the first handful of symbols
+ // with that name will have nodes and the rest are represented by the 'more' node.
+ //
+ // So the search node will either be one of the few child nodes or is is represented by the
+ // 'more' node. In the case where the more node was returned in response to a symbol deleted
+ // notification, the subsequent call back to the organization node's removeNode(child) will
+ // recognize the 'more' node and decrement the count instead of deleting it.
+ if (moreNode != null) {
+ if (!key.getName().equals(baseName)) {
+ return null;
+ }
+ for (GTreeNode child : children()) {
+ SymbolTreeNode symbolTreeNode = (SymbolTreeNode) child;
+ if (symbolTreeNode.getSymbol() == key.getSymbol()) {
+ return symbolTreeNode;
+ }
+ }
+ return moreNode;
+ }
+ return super.getMatchingChild(key, loadChildren);
+ }
+
static class OrganizationNodeComparator implements Comparator<GTreeNode> {
@Override
public int compare(GTreeNode g1, GTreeNode g2) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ParameterSymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ParameterSymbolNode.java
index 43799aa56a..89f966ad58 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ParameterSymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/ParameterSymbolNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchKeySymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchNode.java
similarity index 69%
rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchKeySymbolNode.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchNode.java
index dc6cde9c53..13c315b7b7 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchKeySymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SearchNode.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,7 @@ package ghidra.app.plugin.core.symboltree.nodes;
import java.util.Objects;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
/**
@@ -25,14 +25,21 @@ import ghidra.program.model.symbol.Symbol;
* symbol nodes. This class allows us to search for another symbol node using whatever
* name is desired.
*/
-public class SearchKeySymbolNode extends SymbolNode {
+public class SearchNode extends SymbolNode {
private String searchName;
- SearchKeySymbolNode(Program program, Symbol symbol, String searchName) {
- super(program, symbol);
- Objects.requireNonNull(searchName);
- this.searchName = getNameFromBaseName(searchName);
+ public static SearchNode create(Namespace ns) {
+ return new SearchNode(ns.getSymbol(), ns.getName());
+ }
+
+ public static SearchNode create(Symbol s, String name) {
+ return new SearchNode(s, name);
+ }
+
+ SearchNode(Symbol symbol, String searchName) {
+ super(symbol.getProgram(), symbol);
+ this.searchName = Objects.requireNonNull(searchName);
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolCategoryNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolCategoryNode.java
index d973c59974..075897ab0f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolCategoryNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolCategoryNode.java
@@ -22,6 +22,7 @@ import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.tasks.GTreeCollapseAllTask;
import ghidra.app.plugin.core.symboltree.SymbolCategory;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.program.model.address.GlobalNamespace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
@@ -34,42 +35,19 @@ public abstract class SymbolCategoryNode extends SymbolTreeNode {
protected SymbolTable symbolTable;
protected GlobalNamespace globalNamespace;
protected Program program;
+ protected SymbolTreeFilterState filterState;
- protected boolean isEnabled = true;
-
- public SymbolCategoryNode(SymbolCategory symbolCategory, Program p) {
- this.symbolCategory = symbolCategory;
+ public SymbolCategoryNode(SymbolCategory category, Program p,
+ SymbolTreeFilterState filterState) {
+ this.symbolCategory = category;
this.program = p;
+ this.filterState = filterState;
this.symbolTable = p == null ? null : p.getSymbolTable();
this.globalNamespace = p == null ? null : (GlobalNamespace) p.getGlobalNamespace();
}
- public void setEnabled(boolean enabled) {
- if (isEnabled == enabled) {
- return;
- }
-
- isEnabled = enabled;
- unloadChildren();
-
- GTree gTree = getTree();
- if (gTree != null) {
- SymbolCategoryNode modelNode = (SymbolCategoryNode) gTree.getModelNode(this);
- if (this != modelNode) {
- modelNode.setEnabled(enabled);
- }
- }
- }
-
- public boolean isEnabled() {
- return isEnabled;
- }
-
@Override
- public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException {
- if (!isEnabled) {
- return List.of();
- }
+ public final List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException {
SymbolTreeRootNode root = (SymbolTreeRootNode) getRoot();
if (root == null) {
@@ -77,49 +55,44 @@ public abstract class SymbolCategoryNode extends SymbolTreeNode {
return List.of();
}
- SymbolType symbolType = symbolCategory.getSymbolType();
- List<GTreeNode> list = getSymbols(symbolType, monitor);
+ List<GTreeNode> list = getSymbolNodes(monitor);
monitor.checkCancelled();
int groupThreshold = root.getNodeGroupThreshold();
return OrganizationNode.organize(list, groupThreshold, monitor);
}
- public Program getProgram() {
- return program;
- }
-
- protected List<GTreeNode> getSymbols(SymbolType type, TaskMonitor monitor)
- throws CancelledException {
- return getSymbols(type, true, monitor);
- }
-
- protected List<GTreeNode> getSymbols(SymbolType type, boolean globalOnly, TaskMonitor monitor)
- throws CancelledException {
+ private List<GTreeNode> getSymbolNodes(TaskMonitor monitor) {
List<GTreeNode> list = new ArrayList<>();
-
- SymbolType symbolType = symbolCategory.getSymbolType();
- monitor.initialize(symbolTable.getNumSymbols());
- SymbolIterator it =
- globalOnly ? symbolTable.getSymbols(globalNamespace) : symbolTable.getSymbolIterator();
- while (it.hasNext()) {
- Symbol s = it.next();
- monitor.incrementProgress(1);
- monitor.checkCancelled();
- if (s != null && (s.getSymbolType() == symbolType)) {
- list.add(SymbolNode.createNode(s, program));
+ SymbolIterator symbols = getPotentialSymbols();
+ for (Symbol symbol : symbols) {
+ if (!filterState.passesFilter(symbol)) {
+ continue;
+ }
+ if (supportsSymbolAtCatogryRoot(symbol)) {
+ list.add(SymbolNode.createNode(symbol, program));
}
}
+
Collections.sort(list, getChildrenComparator());
return list;
}
- @Override
- public boolean canCut() {
- return false;
+ /**
+ * Return an iterator over all symbols that could potentially be at the root of this
+ * category. Generally, the best we can do is iterate over all global symbols and then
+ * those will be further filtered by the supportsSymbol() method.
+ * @return an iterator over all possible symbols for this category.
+ */
+ protected SymbolIterator getPotentialSymbols() {
+ return symbolTable.getSymbols(globalNamespace);
+ }
+
+ public Program getProgram() {
+ return program;
}
@Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
+ public boolean canCut() {
return false;
}
@@ -161,51 +134,109 @@ public abstract class SymbolCategoryNode extends SymbolTreeNode {
return null;
}
- @Override
- public boolean supportsDataFlavors(DataFlavor[] dataFlavors) {
- for (DataFlavor flavor : dataFlavors) {
- if (isLocalDataFlavor(flavor)) {
- return true;
- }
- }
- return false;
- }
-
- protected boolean isLocalDataFlavor(DataFlavor dataFlavor) {
- return dataFlavor == CodeSymbolNode.LOCAL_DATA_FLAVOR ||
- dataFlavor == FunctionSymbolNode.LOCAL_DATA_FLAVOR ||
- dataFlavor == NamespaceSymbolNode.LOCAL_DATA_FLAVOR ||
- dataFlavor == ClassSymbolNode.LOCAL_DATA_FLAVOR;
- }
+ /**
+ * Returns true if this symbol is applicable for this category. This is used when symbols
+ * are added, changed, or deleted.
+ * @param symbol the symbol to test
+ * @param parentNamespace this is the current namespace of the symbol for adds or
+ * renames, but will be the old namespace when the namespace was changed
+ * @return true if this symbol is applicable for this category
+ */
+ protected abstract boolean supportsSymbol(Symbol symbol, Namespace parentNamespace);
- protected abstract boolean supportsSymbol(Symbol symbol);
+ /**
+ * Returns true if this symbol is applicable for this categories root level. It is used when
+ * generating the children for the category node.
+ * @param symbol the symbol to test
+ * @return true if this symbol should be included in this categories root children.
+ */
+ protected abstract boolean supportsSymbolAtCatogryRoot(Symbol symbol);
- public SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
+ /**
+ * Create a list of SymbolNodes to be used to find a specific symbol within the symbol tree.
+ * <P>
+ * Each category has specific knowledge on how symbols are organized within that category, so
+ * for any symbol, it knows what search nodes to generate that will match nodes at each level
+ * down in the tree that lead to that symbol.
+ * <P>
+ * Generally, each search node will handle one level in the tree. However, Organization nodes
+ * are handled a bit differently since they add artificial layers, so they don't get a specific
+ * search key for any levels they generate. Instead, the organization node has overridden logic
+ * that uses special comparators to recurse down through its own unique layering structure.
+ * @param symbol the symbol being searched for
+ * @param name the name of the symbol being searched for (can be different than the symbol's
+ * current name in the case of a rename)
+ * @param namespace the parent namespace of the symbol being searched for (can be different
+ * that the symbol's parent namespace if it was changed)
+ * @return a list of symbol search nodes that can be used to find the desired symbol.
+ */
+ protected abstract List<SymbolNode> createSearchKeys(Symbol symbol, String name,
+ Namespace namespace);
+ protected SymbolNode symbolAdded(Symbol symbol, TaskMonitor monitor) {
if (!isLoaded()) {
return null;
}
-
- if (!supportsSymbol(symbol)) {
+ if (!filterState.passesFilter(symbol)) {
return null;
}
- GTreeNode parentNode = this;
- if (symbol.isGlobal()) {
- return doAddSymbol(symbol, parentNode);
+ if (!supportsSymbol(symbol, symbol.getParentNamespace())) {
+ return null;
}
- Namespace parentNamespace = symbol.getParentNamespace();
- Symbol namespaceSymbol = parentNamespace.getSymbol();
- SymbolNode key = SymbolNode.createNode(namespaceSymbol, program);
- parentNode = findSymbolTreeNode(key, false, monitor);
+ List<SymbolNode> keys =
+ createSearchKeys(symbol, symbol.getName(), symbol.getParentNamespace());
+ // we want to find the parent, so remove the last key
+ keys.removeLast();
+ GTreeNode parentNode = getNodeByPath(keys, false, monitor);
if (parentNode == null) {
return null;
}
-
return doAddSymbol(symbol, parentNode);
}
+ protected void symbolRemoved(Symbol symbol, Namespace oldNamespace, String oldName,
+ TaskMonitor monitor) {
+
+ if (!isLoaded()) {
+ return;
+ }
+ if (!filterState.passesFilter(symbol)) {
+ return;
+ }
+ if (!supportsSymbol(symbol, oldNamespace)) {
+ return;
+ }
+
+ List<SymbolNode> keys = createSearchKeys(symbol, oldName, oldNamespace);
+ GTreeNode foundNode = getNodeByPath(keys, false, monitor);
+ if (foundNode == null) {
+ foundNode = findNodeBruteForce(symbol, monitor);
+ }
+ if (foundNode != null) {
+ GTreeNode foundParent = foundNode.getParent();
+ foundParent.removeNode(foundNode);
+ }
+ }
+
+ protected final GTreeNode getNodeByPath(List<SymbolNode> keys, boolean loadChildren,
+ TaskMonitor monitor) {
+
+ SymbolTreeNode parent = this;
+ for (SymbolNode key : keys) {
+ if (monitor.isCancelled()) {
+ return null;
+ }
+ SymbolTreeNode foundMatch = parent.getMatchingChild(key, loadChildren);
+ if (foundMatch == null) {
+ return null;
+ }
+ parent = foundMatch;
+ }
+ return parent;
+ }
+
protected SymbolNode doAddSymbol(Symbol symbol, GTreeNode parentNode) {
if (!parentNode.isLoaded()) {
return null; // the node's not open, we don't care
@@ -237,9 +268,6 @@ public abstract class SymbolCategoryNode extends SymbolTreeNode {
}
parentNode.addNode(index, newNode);
- if (!parentNode.isLoaded()) {
- return;
- }
SymbolTreeRootNode root = (SymbolTreeRootNode) getRoot();
int reOrgLimit = root.getReorganizeLimit();
@@ -253,68 +281,31 @@ public abstract class SymbolCategoryNode extends SymbolTreeNode {
}
}
- public void symbolRemoved(Symbol symbol, TaskMonitor monitor) {
- symbolRemoved(symbol, symbol.getName(), monitor);
- }
-
- public void symbolRemoved(Symbol symbol, String oldName, TaskMonitor monitor) {
- if (!isLoaded()) {
- return;
- }
-
- if (!supportsSymbol(symbol)) {
- return;
- }
-
- SymbolNode key = SymbolNode.createKeyNode(symbol, oldName, program);
- GTreeNode foundNode = findSymbolTreeNode(key, false, monitor);
- if (foundNode == null) {
- return;
- }
-
- GTreeNode foundParent = foundNode.getParent();
- foundParent.removeNode(foundNode);
- }
-
- public void symbolRemoved(Symbol symbol, Namespace oldNamespace, TaskMonitor monitor) {
- // Most categories will treat a symbol moved as a remove; symbolAdded() will get called
- // after this to restore the symbol. Subclasses that depend on scope will override this
- // method.
- symbolRemoved(symbol, monitor);
- }
-
/**
- * Returns the last Namespace tree node in the given path of namespaces. Each Namespace in the
- * list from 0 to n will be used to find the last tree node, starting at the given parent
- * node.
- *
- * @param parentNode the node at which to start the search
- * @param namespaces the list of namespaces to traverse.
- * @param loadChildren true to load children if they have not been loaded
- * @param monitor the task monitor
- * @return the namespace node or null if it is not open in the tree
+ * Searches for the given symbol within this symbol category node
+ * @param symbol the symbol to search for
+ * @param loadChildren if true, will load children nodes in the tree as it searches down
+ * @param monitor the TaskMonitor that can be used to cancel the operation
+ * @return The GTreeNode that contains the symbol or null if the symbol was not found in the
+ * tree. Note: there is a special case where an {@link MoreNode} can be returned if there
+ * are many symbols with the same name and they were represented by the MoreNode. So in cases
+ * where it is important that the node actually contains the symbol, it should be checked for.
*/
- protected GTreeNode getNamespaceNode(GTreeNode parentNode, List<Namespace> namespaces,
- boolean loadChildren, TaskMonitor monitor) {
-
- if (!loadChildren && !parentNode.isLoaded() || monitor.isCancelled()) {
+ public GTreeNode findSymbolNode(Symbol symbol, boolean loadChildren, TaskMonitor monitor) {
+ if ((!isLoaded() && !loadChildren) || monitor.isCancelled()) {
return null;
}
-
- if (namespaces.isEmpty()) {
+ if (!filterState.passesFilter(symbol)) {
return null;
}
-
- Namespace namespace = namespaces.remove(0);
- Symbol nsSymbol = namespace.getSymbol();
- SymbolNode key = SymbolNode.createKeyNode(nsSymbol, nsSymbol.getName(), program);
- GTreeNode namespaceNode = findNode(parentNode, key, loadChildren, monitor);
- if (namespaceNode == null || namespaces.isEmpty()) {
- return namespaceNode; // we hit the last namespace
+ Namespace namespace = symbol.getParentNamespace();
+ if (!supportsSymbol(symbol, namespace)) {
+ return null;
}
- // move to the next namespace
- return getNamespaceNode(namespaceNode, namespaces, loadChildren, monitor);
+ String name = symbol.getName();
+ List<SymbolNode> keys = createSearchKeys(symbol, name, namespace);
+ return getNodeByPath(keys, loadChildren, monitor);
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
index 68797e39d1..aaa7bb0c1b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolNode.java
@@ -22,6 +22,7 @@ import javax.swing.Icon;
import docking.widgets.tree.GTreeNode;
import ghidra.app.cmd.label.CreateNamespacesCmd;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.app.util.SymbolPath;
import ghidra.program.model.address.GlobalNamespace;
import ghidra.program.model.listing.CircularDependencyException;
@@ -29,8 +30,8 @@ import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.util.HTMLUtilities;
import ghidra.util.Msg;
-import ghidra.util.exception.DuplicateNameException;
-import ghidra.util.exception.InvalidInputException;
+import ghidra.util.datastruct.AlphaNumericComparator;
+import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
public class SymbolNode extends SymbolTreeNode {
@@ -38,8 +39,7 @@ public class SymbolNode extends SymbolTreeNode {
protected final Program program;
protected final Symbol symbol;
- private String cachedName;
-
+ private String cachedDisplayName;
private boolean isCut;
SymbolNode(Program program, Symbol symbol) {
@@ -49,19 +49,24 @@ public class SymbolNode extends SymbolTreeNode {
}
@Override
- public List<GTreeNode> generateChildren(TaskMonitor monitor) {
+ public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException {
List<GTreeNode> list = new ArrayList<>();
if (program.isClosed()) {
return list;
}
+ SymbolTreeFilterState filterState = getFilterState();
SymbolTable symbolTable = program.getSymbolTable();
SymbolIterator iter = symbolTable.getChildren(symbol);
while (iter.hasNext()) {
if (monitor.isCancelled()) {
return Collections.emptyList();
}
- list.add(createNode(iter.next(), program));
+
+ Symbol s = iter.next();
+ if (filterState.passesFilter(s)) {
+ list.add(createNode(s, program));
+ }
}
sort(list);
@@ -78,11 +83,6 @@ public class SymbolNode extends SymbolTreeNode {
return false;
}
- @Override
- public boolean canPaste(List<GTreeNode> pastedNodes) {
- return false;
- }
-
@Override
public boolean isCut() {
return isCut;
@@ -115,14 +115,18 @@ public class SymbolNode extends SymbolTreeNode {
@Override
public String getName() {
- if (cachedName == null) {
- String baseName = symbol.getName();
- cachedName = getNameFromBaseName(baseName);
+ return symbol.getName();
+ }
+
+ @Override
+ public String getDisplayText() {
+ if (cachedDisplayName == null) {
+ cachedDisplayName = computeDisplayName(getName());
}
- return cachedName;
+ return cachedDisplayName;
}
- protected String getNameFromBaseName(String baseName) {
+ private String computeDisplayName(String baseName) {
if (symbol.isExternal()) {
ExternalLocation external =
symbol.getProgram().getExternalManager().getExternalLocation(symbol);
@@ -167,26 +171,21 @@ public class SymbolNode extends SymbolTreeNode {
return null;
}
- @Override
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren,
- TaskMonitor taskMonitor) {
+ protected void doInsertNode(GTreeNode newNode) {
- Symbol searchSymbol = key.getSymbol();
- if (symbol == searchSymbol) {
- return this;
+ Comparator<GTreeNode> comparator = getChildrenComparator();
+ List<GTreeNode> children = getChildren();
+ int index = Collections.binarySearch(children, newNode, comparator);
+ if (index >= 0) { // already a child
+ return;
}
- return super.findSymbolTreeNode(key, loadChildren, taskMonitor);
- }
-
- public static SymbolNode createKeyNode(Symbol symbol, String searchSymbolName,
- Program program) {
-
- SymbolNode newNode = new SearchKeySymbolNode(program, symbol, searchSymbolName);
- return newNode;
+ index = -index - 1;
+ addNode(index, newNode);
}
public static SymbolNode createNode(Symbol symbol, Program program) {
+
SymbolType symbolType = symbol.getSymbolType();
if (symbolType.equals(SymbolType.CLASS)) {
return new ClassSymbolNode(program, symbol);
@@ -296,26 +295,25 @@ public class SymbolNode extends SymbolTreeNode {
// overridden to handle duplicate symbols
@Override
public int compareTo(GTreeNode node) {
- int nameCompare = getName().compareToIgnoreCase(node.getName());
- if (!(node instanceof SymbolNode)) {
- return nameCompare;
- }
+ String dt1 = getDisplayText();
+ String dt2 = node.getDisplayText();
- // sort alphabetically first
+ int nameCompare = AlphaNumericComparator.CI.compare(dt1, dt2);
if (nameCompare != 0) {
return nameCompare;
}
- // next, handle the case where the names are the same, but with different case--be consistent
- nameCompare = getName().compareTo(node.getName());
+ // next, use case sensitive to tie-break
+ nameCompare = AlphaNumericComparator.CS.compare(dt1, dt2);
if (nameCompare != 0) {
- // negate the result so that lower comes first
- return -nameCompare;
+ return -nameCompare; // negate the result so that lower comes first
+ }
+
+ if (node instanceof SymbolNode other) {
+ // when two symbol nodes have exactly the same name, use a tie-breaker
+ return SYMBOL_COMPARATOR.compare(symbol, other.symbol);
}
- // next, when the names are the same, provide a consistent order via address and symbol
- SymbolNode other = (SymbolNode) node;
- int result = SYMBOL_COMPARATOR.compare(symbol, other.symbol);
- return result;
+ return 0;
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeNode.java
index 2c4cd7c013..0b5ece1fd5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeNode.java
@@ -20,9 +20,9 @@ import java.util.*;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.GTreeSlowLoadingNode;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.app.plugin.core.symboltree.SymbolTreeProvider;
import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
import ghidra.util.task.TaskMonitor;
@@ -40,6 +40,12 @@ import ghidra.util.task.TaskMonitor;
* parent node to sort its children differently.
*/
public abstract class SymbolTreeNode extends GTreeSlowLoadingNode {
+ //@formatter:off
+ static final DataFlavor LABEL_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Labels");
+ static final DataFlavor FUNCTION_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Functions");
+ static final DataFlavor CLASS_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Classes");
+ static final DataFlavor NAMESPACE_DATA_FLAVOR = new SymbolTreeDataFlavor("Symbol Tree Data Flavor - Namespaces");
+ //@formatter:on
public static final Comparator<Symbol> SYMBOL_COMPARATOR = (s1, s2) -> {
// note: not really sure if we care about the cases where 'symbol' is null, as that
@@ -95,13 +101,6 @@ public abstract class SymbolTreeNode extends GTreeSlowLoadingNode {
*/
public abstract boolean canCut();
- /**
- * Returns true if this nodes handles paste operations
- * @param pastedNodes the nodes to be pasted
- * @return true if this nodes handles paste operations
- */
- public abstract boolean canPaste(List<GTreeNode> pastedNodes);
-
/**
* Signals to this node that it has been cut during a cut operation, for example, like during
* a cut/paste operation.
@@ -159,55 +158,36 @@ public abstract class SymbolTreeNode extends GTreeSlowLoadingNode {
return null;
}
+ protected SymbolTreeFilterState getFilterState() {
+ SymbolTreeRootNode root = (SymbolTreeRootNode) getRoot();
+ return root.getSymbolTreeFilterState();
+ }
+
/**
- * Locates the node that contains the given symbol.
+ * Last resort method to find a symbol in the tree when the more direct approaches have failed.
+ * This method will visit each node in a depth first traversal, looking for the given symbol.
+ * Note that this method only searches the nodes that are currently loaded, it will not trigger
+ * any lazy node loading.
+ * The main use of this method is to find a node whose symbol was removed and the corresponding
+ * tree node needs to be deleted. The direct approach will fail if both the name and namespace
+ * where changed at same time since the event system sends two events and neither have the
+ * all the necessary information to find the symbol efficiently.
*
- * <p><b>Note: </b>This can degenerate into a brute-force search algorithm, but works in
- * all normal cases using a binary search.
- *
- * @param key the node used to find an existing node. This node is a node created that is
- * used by the Comparators to perform binary searches. These can be fabricated
- * by using {@link SymbolNode#createNode(Symbol, Program)}
- * @param loadChildren if true then children should be loaded, else quit early if
- * children are not loaded.
- * @param monitor the task monitor
- * @return the node that contains the given symbol.
+ * @param symbol the symbol to search for
+ * @param monitor the TaskMonitor that can be used to cancel the operation
+ * @return the GTreeNode containing the symbol or null if not found
*/
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
-
- // if we don't have to loadChildren and we are not loaded get out.
- if ((!isLoaded() && !loadChildren) || monitor.isCancelled()) {
- return null;
- }
+ protected final GTreeNode findNodeBruteForce(Symbol symbol, TaskMonitor monitor) {
- // see if the given node is the node we want
- Symbol searchSymbol = key.getSymbol();
- if (getSymbol() == searchSymbol) {
+ if (getSymbol() == symbol) {
return this;
}
- List<GTreeNode> children = getChildren();
- int index = Collections.binarySearch(children, key, getChildrenComparator());
- if (index >= 0) {
- GTreeNode node = children.get(index);
- SymbolTreeNode symbolNode = (SymbolTreeNode) node;
- if (symbolNode.getSymbol() == searchSymbol) {
- return symbolNode;
- }
-
- // At this point we know that the given child is not itself a symbol node, but it
- // may contain a child that contains the symbol node (some symbol nodes will
- // themselves contain more symbol nodes).
- // Ask that child to search. Leave this method regardless, as if this child does
- // not have it, then none of the others will.
- node = symbolNode.findSymbolTreeNode(key, loadChildren, monitor);
- return node;
+ if (!isLoaded() || monitor.isCancelled()) {
+ return null;
}
- // Brute-force lookup in each child. This will not typically be called. Category nodes
- // that support large numbers of children have overridden this method to perform smarter
- // searching.
- for (GTreeNode childNode : children) {
+ for (GTreeNode childNode : getChildren()) {
if (monitor.isCancelled()) {
return null;
}
@@ -216,7 +196,7 @@ public abstract class SymbolTreeNode extends GTreeSlowLoadingNode {
}
SymbolTreeNode symbolNode = (SymbolTreeNode) childNode;
- GTreeNode foundNode = symbolNode.findSymbolTreeNode(key, loadChildren, monitor);
+ GTreeNode foundNode = symbolNode.findNodeBruteForce(symbol, monitor);
if (foundNode != null) {
return foundNode;
}
@@ -226,49 +206,81 @@ public abstract class SymbolTreeNode extends GTreeSlowLoadingNode {
}
/**
- * Searches for the given node 'key' inside of the given parent. This method performs an
- * efficient search and does not recurse below the given node.
+ * Finds the child node in this node that matches the given search key. The search key node
+ * will contain the symbol being searched for, but the name may not be the current symbol's
+ * name. This is to facilitate finding symbols in the tree whose name has been changed, but
+ * we know the old name.
+ * <P>
+ * This method normally just searches the immediate children of a node. However, if the node
+ * is an organization node, it will recursively descend into organization nodes to find the
+ * target symbol. It will never recurse into non-organization nodes.
*
- * @param parent the node whose children will be searched
- * @param key the token node to search for
- * @param loadChildren true to load children; false signals to search only if already loaded
- * @param monitor the monitor
- * @return the node or null
+ * @param key a special node used to search for a symbol. It allows for a different name than
+ * the actual symbol name.
+ * @param loadChildren if true, the node will load its children before searching. Otherwise,
+ * if loadChildren is false and the node is not currently loaded, it will just return null.
+ * @return returns the node containing the searched for symbol if it is found; otherwise it
+ * returns null
*/
- protected GTreeNode findNode(GTreeNode parent, SymbolNode key, boolean loadChildren,
- TaskMonitor monitor) {
+ public SymbolTreeNode getMatchingChild(SymbolNode key, boolean loadChildren) {
+ if (!loadChildren && !isLoaded()) {
+ return null;
+ }
+ List<GTreeNode> children = getChildren();
- if ((!isLoaded() && !loadChildren) || monitor.isCancelled()) {
+ Comparator<GTreeNode> comparator = getChildrenComparator();
+ int index = Collections.binarySearch(children, key, comparator);
+ if (index < 0) {
return null;
}
- // see if the given node is the node we want
- Symbol searchSymbol = key.getSymbol();
- if (parent instanceof SymbolTreeNode symbolNode) {
- if (symbolNode.getSymbol() == searchSymbol) {
- return symbolNode;
- }
+ // We may have duplicate symbols, so our binary search may have resulted in the middle
+ // of a run of duplicate names, so we must search around the found index.
+ //
+ // However, if the node at the index is an organization node, then we know that any
+ // duplicates will also be in the organization node.
+ // Normally, this search is only one level, but organization nodes have to be handled
+ // specially. Since organization nodes add artificial layers to break up what would have
+ // been a very large list of child nodes, the algorithm needs to recurse down through all
+ // organization nodes to find the node that conceptually lives at this level.
+
+ SymbolTreeNode node = (SymbolTreeNode) children.get(index);
+ if (node instanceof OrganizationNode orgNode) {
+ return orgNode.getMatchingChild(key, loadChildren);
}
- Comparator<GTreeNode> comparator = ((SymbolTreeNode) parent).getChildrenComparator();
- List<GTreeNode> children = parent.getChildren();
- int index = Collections.binarySearch(children, key, comparator);
- if (index >= 0) {
- GTreeNode node = children.get(index);
- SymbolTreeNode symbolNode = (SymbolTreeNode) node;
-
- // Some parent nodes may contain OrganizationNodes, which will return as a match when
- // the symbol does not match. We expect the symbol to always match for clients of this
- // method.
- if (symbolNode.getSymbol() == searchSymbol) {
- return symbolNode;
- }
- else if (symbolNode instanceof OrganizationNode) {
- return findNode(symbolNode, key, loadChildren, monitor);
+ int start = getStart(index, key, children, comparator);
+ int end = getEnd(index, key, children, comparator);
+ for (int i = start; i < end; i++) {
+ node = (SymbolNode) children.get(i);
+ if (node.getSymbol() == key.getSymbol()) {
+ return node;
}
}
-
return null;
+ }
+ private static int getStart(int index, SymbolNode key, List<GTreeNode> children,
+ Comparator<GTreeNode> comparator) {
+ for (int i = index - 1; i >= 0; i--) {
+ GTreeNode node = children.get(i);
+ int result = comparator.compare(key, node);
+ if (result != 0) {
+ return i + 1;
+ }
+ }
+ return 0;
+ }
+
+ private static int getEnd(int index, SymbolNode key, List<GTreeNode> children,
+ Comparator<GTreeNode> comparator) {
+ for (int i = index + 1; i < children.size(); i++) {
+ GTreeNode node = children.get(i);
+ int result = comparator.compare(key, node);
+ if (result != 0) {
+ return i; // the end is exclusive so don't subtract 1
+ }
+ }
+ return children.size();
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeRootNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeRootNode.java
index d1811d9630..5acc9dcd17 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeRootNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/nodes/SymbolTreeRootNode.java
@@ -15,6 +15,7 @@
*/
package ghidra.app.plugin.core.symboltree.nodes;
+import static ghidra.app.plugin.core.symboltree.SymbolCategory.*;
import static ghidra.program.model.symbol.SymbolType.*;
import java.util.*;
@@ -24,6 +25,7 @@ import javax.swing.Icon;
import docking.widgets.tree.GTreeNode;
import generic.theme.GIcon;
import ghidra.app.plugin.core.symboltree.SymbolCategory;
+import ghidra.app.plugin.core.symboltree.SymbolTreeFilterState;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.util.task.TaskMonitor;
@@ -32,20 +34,21 @@ public class SymbolTreeRootNode extends GTreeNode {
private static Icon GLOBAL_ICON = new GIcon("icon.plugin.symboltree.node.root");
private final String name;
- protected SymbolCategory symbolCategory;
protected Program program;
private int groupThreshold;
+ private SymbolTreeFilterState filterState;
- public SymbolTreeRootNode(Program program, int groupThreshold) {
+ public SymbolTreeRootNode(Program program, int groupThreshold,
+ SymbolTreeFilterState filterState) {
this.groupThreshold = groupThreshold;
- this.symbolCategory = SymbolCategory.ROOT_CATEGORY;
this.program = program;
+ this.filterState = filterState;
if (program == null) {
name = "No Symbol Tree";
}
else {
- name = "Global";
+ name = "Root";
}
}
@@ -72,17 +75,32 @@ public class SymbolTreeRootNode extends GTreeNode {
List<GTreeNode> list = new ArrayList<>();
- list.add(new ImportsCategoryNode(program));
- list.add(new ExportsCategoryNode(program));
- list.add(new FunctionCategoryNode(program));
- list.add(new LabelCategoryNode(program));
- list.add(new ClassCategoryNode(program));
- list.add(new NamespaceCategoryNode(program));
+ if (filterState.showImports()) {
+ list.add(new ImportsCategoryNode(program, filterState));
+ }
+ if (filterState.showExports()) {
+ list.add(new ExportsCategoryNode(program, filterState));
+ }
+ if (filterState.showGlobals()) {
+ list.add(new GlobalsCategoryNode(program, filterState));
+ }
+ if (filterState.showNamespaces()) {
+ list.add(new NamespaceCategoryNode(program, filterState));
+ }
return list;
}
- public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
+ /**
+ * Finds the given symbol in the tree.
+ * @param symbol the symbol to search for
+ * @param loadChildren if true, then lazy nodes will be loaded before searching. Otherwise,
+ * unloaded nodes will not be searched.
+ * @param monitor a TaskMonitor that can be used to cancel the search
+ * @return the GTreeNode corresponding to the given symbol or null if the symbol is not found in
+ * the tree.
+ */
+ public GTreeNode findSymbolNode(Symbol symbol, boolean loadChildren, TaskMonitor monitor) {
//
// The finding of nodes starts here, at the root. Optimize searching by using the
@@ -94,92 +112,68 @@ public class SymbolTreeRootNode extends GTreeNode {
// -Namespaces - search the namespaces node, need recursive searching
//
- Symbol searchSymbol = key.getSymbol();
- SymbolType type = searchSymbol.getSymbolType();
+ SymbolType type = symbol.getSymbolType();
if (type == FUNCTION) {
- return findFunctionSymbolNode(key, loadChildren, monitor);
+ return findFunctionRelatedSymbol(symbol, loadChildren, monitor);
}
else if (type == PARAMETER || type == LOCAL_VAR) {
- return findVariableSymbolNode(key, loadChildren, monitor);
+ return findFunctionRelatedSymbol(symbol, loadChildren, monitor);
}
else if (type == CLASS) {
- return findClassSymbol(key, loadChildren, monitor);
+ return findClassSymbol(symbol, loadChildren, monitor);
}
- else if (type == LIBRARY || type == NAMESPACE) {
- return findNamespaceSymbol(key, loadChildren, monitor);
+ else if (type == NAMESPACE) {
+ return findNamespaceSymbol(symbol, loadChildren, monitor);
+ }
+ else if (type == LIBRARY) {
+ return findLibrarySymbol(symbol, loadChildren, monitor);
}
else if (type == LABEL) {
- return findCodeSymbol(key, loadChildren, monitor);
+ return findCodeSymbol(symbol, loadChildren, monitor);
}
//else { GLOBAL, GLOBAL_VAR } // not sure where these end up
return null;
}
- private GTreeNode findCodeSymbol(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
-
- //@formatter:off
- List<SymbolCategoryNode> categories = Arrays.asList(
- getLabelsNode(),
- getNamespacesNode(),
- getClassesNode(),
- getFunctionsNode()
- );
- //@formatter:on
- GTreeNode node = searchCategories(categories, key, loadChildren, monitor);
+ private GTreeNode findCodeSymbol(Symbol symbol, boolean loadChildren, TaskMonitor monitor) {
+
+ GTreeNode node =
+ searchCategories(symbol, loadChildren, monitor, IMPORTS, GLOBALS, NAMESPACES);
return node;
}
- private GTreeNode findNamespaceSymbol(SymbolNode key, boolean loadChildren,
+ private GTreeNode findNamespaceSymbol(Symbol symbol, boolean loadChildren,
TaskMonitor monitor) {
-
- SymbolCategoryNode category = getNamespacesNode();
- return category.findSymbolTreeNode(key, loadChildren, monitor);
+ GTreeNode node = searchCategories(symbol, loadChildren, monitor, NAMESPACES);
+ return node;
}
- private GTreeNode findClassSymbol(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {
- SymbolCategoryNode category = getClassesNode();
- return category.findSymbolTreeNode(key, loadChildren, monitor);
+ private GTreeNode findLibrarySymbol(Symbol symbol, boolean loadChildren, TaskMonitor monitor) {
+ GTreeNode node = searchCategories(symbol, loadChildren, monitor, IMPORTS);
+ return node;
}
- private GTreeNode findVariableSymbolNode(SymbolNode key, boolean loadChildren,
- TaskMonitor monitor) {
-
- Symbol searchSymbol = key.getSymbol();
- Symbol functionSymbol = searchSymbol.getParentSymbol();
- SymbolNode parentKey = SymbolNode.createNode(functionSymbol, program);
- GTreeNode functionNode = findFunctionSymbolNode(parentKey, loadChildren, monitor);
- if (functionNode != null) {
- return ((SymbolTreeNode) functionNode).findSymbolTreeNode(key, loadChildren, monitor);
- }
- return null;
+ private GTreeNode findClassSymbol(Symbol symbol, boolean loadChildren, TaskMonitor monitor) {
+ GTreeNode node = searchCategories(symbol, loadChildren, monitor, NAMESPACES);
+ return node;
}
- private GTreeNode findFunctionSymbolNode(SymbolNode key, boolean loadChildren,
+ private GTreeNode findFunctionRelatedSymbol(Symbol symbol, boolean loadChildren,
TaskMonitor monitor) {
-
- Symbol searchSymbol = key.getSymbol();
- if (searchSymbol.isExternal()) {
- // assumption: externals will always be in the Externals category
- return searchCategory(getExternalsNode(), key, loadChildren, monitor);
- }
-
- //@formatter:off
- List<SymbolCategoryNode> categories = Arrays.asList(
- getFunctionsNode(),
- getClassesNode(),
- getNamespacesNode()
- );
- //@formatter:on
- GTreeNode node = searchCategories(categories, key, loadChildren, monitor);
+ GTreeNode node =
+ searchCategories(symbol, loadChildren, monitor, IMPORTS, GLOBALS, NAMESPACES);
return node;
}
- private GTreeNode searchCategories(List<SymbolCategoryNode> categories, SymbolNode key,
- boolean loadChildren, TaskMonitor monitor) {
-
- for (SymbolCategoryNode category : categories) {
- GTreeNode node = searchCategory(category, key, loadChildren, monitor);
+ private GTreeNode searchCategories(Symbol symbol, boolean loadChildren, TaskMonitor monitor,
+ SymbolCategory... categories) {
+ for (SymbolCategory category : categories) {
+ SymbolCategoryNode categoryNode = getCategoryNode(category);
+ if (categoryNode == null) {
+ continue;
+ }
+ GTreeNode node = categoryNode.findSymbolNode(symbol, loadChildren, monitor);
if (node != null) {
return node;
}
@@ -188,62 +182,13 @@ public class SymbolTreeRootNode extends GTreeNode {
return null;
}
- private GTreeNode searchCategory(SymbolCategoryNode category, SymbolNode key,
- boolean loadChildren, TaskMonitor monitor) {
-
- if (category == null) {
- return null; // assume category is filtered out
- }
-
- GTreeNode node = category.findSymbolTreeNode(key, loadChildren, monitor);
- return node;
- }
-
- private SymbolCategoryNode getLabelsNode() {
- List<GTreeNode> children = getChildren();
- for (GTreeNode child : children) {
- if (child instanceof LabelCategoryNode) {
- return (SymbolCategoryNode) child;
- }
- }
- return null; // must be filtered out
- }
-
- private SymbolCategoryNode getFunctionsNode() {
- List<GTreeNode> children = getChildren();
- for (GTreeNode child : children) {
- if (child instanceof FunctionCategoryNode) {
- return (SymbolCategoryNode) child;
- }
- }
- return null; // must be filtered out
- }
-
- private SymbolCategoryNode getExternalsNode() {
+ private SymbolCategoryNode getCategoryNode(SymbolCategory category) {
List<GTreeNode> children = getChildren();
for (GTreeNode child : children) {
- if (child instanceof FunctionCategoryNode) {
- return (SymbolCategoryNode) child;
- }
- }
- return null; // must be filtered out
- }
-
- private SymbolCategoryNode getClassesNode() {
- List<GTreeNode> children = getChildren();
- for (GTreeNode child : children) {
- if (child instanceof ClassCategoryNode) {
- return (SymbolCategoryNode) child;
- }
- }
- return null; // must be filtered out
- }
-
- private SymbolCategoryNode getNamespacesNode() {
- List<GTreeNode> children = getChildren();
- for (GTreeNode child : children) {
- if (child instanceof NamespaceCategoryNode) {
- return (SymbolCategoryNode) child;
+ if (child instanceof SymbolCategoryNode categoryNode) {
+ if (categoryNode.getSymbolCategory() == category) {
+ return categoryNode;
+ }
}
}
return null; // must be filtered out
@@ -267,18 +212,17 @@ public class SymbolTreeRootNode extends GTreeNode {
// we have to loop--the symbol may exist in more than one category
List<GTreeNode> allChildren = getChildren();
for (GTreeNode gNode : allChildren) {
- SymbolCategoryNode symbolNode = (SymbolCategoryNode) gNode;
- symbolNode.symbolRemoved(symbol, oldName, monitor);
+ SymbolCategoryNode categoryNode = (SymbolCategoryNode) gNode;
+ categoryNode.symbolRemoved(symbol, symbol.getParentNamespace(), oldName, monitor);
}
}
public void symbolRemoved(Symbol symbol, Namespace oldNamespace, TaskMonitor monitor) {
-
// we have to loop--the symbol may exist in more than one category
List<GTreeNode> allChildren = getChildren();
for (GTreeNode gNode : allChildren) {
- SymbolCategoryNode symbolNode = (SymbolCategoryNode) gNode;
- symbolNode.symbolRemoved(symbol, oldNamespace, monitor);
+ SymbolCategoryNode categoryNode = (SymbolCategoryNode) gNode;
+ categoryNode.symbolRemoved(symbol, oldNamespace, symbol.getName(), monitor);
}
}
@@ -317,4 +261,17 @@ public class SymbolTreeRootNode extends GTreeNode {
SymbolTreeRootNode node = (SymbolTreeRootNode) o;
return getName().equals(node.getName());
}
+
+ public void setSymbolTreeFilterState(SymbolTreeFilterState filterState) {
+ this.filterState = filterState;
+ reloadChildren();
+ }
+
+ private void reloadChildren() {
+ setChildren(null); // this will trigger generateChildren next time someone asks.
+ }
+
+ public SymbolTreeFilterState getSymbolTreeFilterState() {
+ return filterState;
+ }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/SymbolTablePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/SymbolTablePlugin.java
index d09aa41262..157f4ccb58 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/SymbolTablePlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/SymbolTablePlugin.java
@@ -249,7 +249,7 @@ public class SymbolTablePlugin extends Plugin implements SymbolTableService {
.call(this::symbolAdded)
.each(SYMBOL_REMOVED)
.call(this::symbolRemoved)
- .each(SYMBOL_RENAMED, SYMBOL_SCOPE_CHANGED, SYMBOL_DATA_CHANGED)
+ .each(SYMBOL_RENAMED, SYMBOL_SCOPE_CHANGED, SYMBOL_DATA_CHANGED, SYMBOL_LIBRARY_CHANGED)
.call(this::symbolChanged)
.each(SYMBOL_SOURCE_CHANGED)
.call(this::symbolSourceChanged)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/TransientSymbolTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/TransientSymbolTableModel.java
index e02a4b8bb1..289e85407d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/TransientSymbolTableModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symtable/TransientSymbolTableModel.java
@@ -60,7 +60,9 @@ public class TransientSymbolTableModel extends AbstractSymbolTableModel {
.any(SYMBOL_REMOVED)
.call(() -> symbolChanged())
.any(CODE_ADDED, CODE_REMOVED,
- SYMBOL_RENAMED, SYMBOL_SCOPE_CHANGED, SYMBOL_DATA_CHANGED,
+ SYMBOL_RENAMED, SYMBOL_SCOPE_CHANGED,
+ SYMBOL_LIBRARY_CHANGED,
+ SYMBOL_DATA_CHANGED,
SYMBOL_SOURCE_CHANGED,
SYMBOL_PRIMARY_STATE_CHANGED,
REFERENCE_ADDED, REFERENCE_REMOVED,
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/MatchSymbol.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/MatchSymbol.java
index 0b6a88e6c7..ac54311ef0 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/MatchSymbol.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/MatchSymbol.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -117,7 +117,8 @@ public class MatchSymbol {
SymbolPath namespacePath = aSymbolPath.getParent();
if (!aSymbolIdentifier.isExternalSymbol() && namespacePath != null &&
!aSymbolPath.equals(bSymbolIdentifier.symbolPath) &&
- NamespaceUtils.getNonFunctionNamespace(bProgram, namespacePath) != null) {
+ NamespaceUtils.getNonFunctionNamespace(bProgram,
+ namespacePath) != null) {
// skip match with namespace mismatch when source namespace exists in destination
continue;
}
@@ -248,7 +249,7 @@ public class MatchSymbol {
if (originalImportedName != null) {
Symbol s = externalLocation.getSymbol();
// original name associated with library namespace only
- Library lib = NamespaceUtils.getLibrary(s.getParentNamespace());
+ Library lib = s.getLibrary();
SymbolPath libPath = new SymbolPath(lib.getSymbol());
SymbolPath symbolPath = new SymbolPath(libPath, originalImportedName);
updateUniqueSymbolPathMap(uniqueSymbolPathMap, symbolPath);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/SymbolInspector.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/SymbolInspector.java
index d184457125..2e4b75bb62 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/SymbolInspector.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/SymbolInspector.java
@@ -489,14 +489,8 @@ public class SymbolInspector implements OptionsChangeListener {
if (s.getSymbolType() == SymbolType.LIBRARY) {
return s.getName();
}
- Symbol parent = s.getParentSymbol();
- while (parent.getSymbolType() != SymbolType.GLOBAL) {
- if (parent.getSymbolType() == SymbolType.LIBRARY) {
- return parent.getName();
- }
- parent = parent.getParentSymbol();
- }
- return null;
+ Library library = s.getLibrary();
+ return library != null ? library.getName() : null;
}
private static ToolOptions getOptions(ServiceProvider serviceProvider) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/ExternalDebugFileSymbolImporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/ExternalDebugFileSymbolImporter.java
index d7b799572a..e696f341c5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/ExternalDebugFileSymbolImporter.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/ExternalDebugFileSymbolImporter.java
@@ -76,8 +76,8 @@ public class ExternalDebugFileSymbolImporter {
for (Symbol extSym : extSymTable.getPrimarySymbolIterator(true)) {
monitor.increment();
totalSymbolCount++;
- if (shouldCopyExtSymbol(extSym)) {
- copyExtSymbol(extSym);
+ if (!extSym.isExternal()) {
+ copyDebugSymbol(extSym);
}
}
}
@@ -94,7 +94,7 @@ public class ExternalDebugFileSymbolImporter {
}
}
- private void copyExtSymbol(Symbol extSym)
+ private void copyDebugSymbol(Symbol extSym)
throws InvalidInputException, OverlappingFunctionException, CodeUnitInsertionException {
Address extAddr = extSym.getAddress();
Address localAddr = DiffUtility.getCompatibleMemoryAddress(extAddr, program);
@@ -145,10 +145,6 @@ public class ExternalDebugFileSymbolImporter {
symTable.createLabel(addr, name, SourceType.IMPORTED);
}
- private boolean shouldCopyExtSymbol(Symbol extSym) {
- return !extSym.getParentNamespace().isLibrary();
- }
-
private boolean isCommonMemblock(MemoryBlock memBlk) {
return memBlk.isExecute();
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
index fbfd35b3fb..a480545aa9 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledFunction.java
@@ -550,7 +550,7 @@ public class DemangledFunction extends DemangledObject {
return true;
}
if (thunkedFunction.isExternal()) {
- if (thunkedFunction.getParentNamespace() instanceof Library) {
+ if (thunkedFunction.getParentNamespace().isGlobal()) {
// Thunked function does not have mangled name, if it did it would have
// matched name check above or now reside in a different namespace
return false;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java
index 538ec9abc6..9d20d66a8a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java
@@ -641,7 +641,7 @@ public abstract class DemangledObject implements Demangled {
catch (DuplicateNameException e) {
Msg.error(DemangledObject.class,
"Failed to create namespace due to name conflict: " +
- NamespaceUtils.getNamespaceQualifiedName(namespace, namespaceName, false));
+ NamespaceUtils.getNamespaceQualifiedName(namespace, namespaceName));
break;
}
catch (InvalidInputException e) {
@@ -659,7 +659,7 @@ public abstract class DemangledObject implements Demangled {
Msg.error(DemangledObject.class,
"Bad namespace type - must be one of: " + allowedTypes +
- NamespaceUtils.getNamespaceQualifiedName(namespace, namespaceName, false));
+ NamespaceUtils.getNamespaceQualifiedName(namespace, namespaceName));
break;
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/ProgramTextWriter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/ProgramTextWriter.java
index 70738eae46..544228c50b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/ProgramTextWriter.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/ProgramTextWriter.java
@@ -94,14 +94,14 @@ class ProgramTextWriter {
true, // include inferred register variable markup
true, // include extended reference markup
true, // include scalar adjustment
- true, // include library names in namespace
+ true, // include library names
true, // follow referenced pointers
simplifier // disabled simplifier
);
CodeUnitFormat cuFormat = new CodeUnitFormat(formatOptions);
- //// M A I N L O O P //////////////////////////////////////////
+ //// M A I N L O O P
Address bytesRemovedRangeStart = null;
Address bytesRemovedRangeEnd = null;
@@ -122,7 +122,7 @@ class ProgramTextWriter {
time = currTime;
}
- //// Undefined Data Area ///////////////////////////////////////
+ //// Undefined Data Area
if ((!options.isShowUndefinedData()) && (currentCodeUnit instanceof Data) &&
!((Data) currentCodeUnit).isDefined()) {
@@ -153,7 +153,7 @@ class ProgramTextWriter {
boolean isFunctionEntryPoint =
currentFunction != null && currentFunction.getEntryPoint().equals(currentAddress);
- //// Plate Property ////////////////////////////////////////////
+ //// Plate Property
boolean cuHasPlate = false;
if (options.isShowProperties()) {
String[] plate = currentCodeUnit.getCommentAsArray(CommentType.PLATE);
@@ -166,7 +166,7 @@ class ProgramTextWriter {
}
}
- //// Function Signature and Header /////////////////////////////
+ //// Function Signature and Header
if (isFunctionEntryPoint) {
String fill = genFill(options.getAddrWidth() + options.getBytesWidth());
@@ -248,7 +248,7 @@ class ProgramTextWriter {
? new ReferenceLineDispenser(true, currentCodeUnit, program, options)
: new ReferenceLineDispenser());
- //// Process the labels and refs... ///////////////////
+ //// Process the labels and refs...
String emptySymbolLine = genFill(options.getLabelWidth());
@@ -279,7 +279,7 @@ class ProgramTextWriter {
backRLD.dispose();
fwdRLD.dispose();
- //// Line of Disassembled Code /////////////////////////////////
+ //// Line of Disassembled Code
buffy = new StringBuilder();
@@ -288,7 +288,7 @@ class ProgramTextWriter {
processMnemonic(currentCodeUnit);
processOperands(currentCodeUnit, cuFormat);
- //// End of Line Area //////////////////////////////////////////
+ //// End of Line Area
if (options.isShowComments()) {
addComments(currentCodeUnit);
@@ -299,7 +299,7 @@ class ProgramTextWriter {
}
buffy = new StringBuilder();
- //// Post Comment //////////////////////////////////////////////
+ //// Post Comment
if (options.isShowComments()) {
String[] post = currentCodeUnit.getCommentAsArray(CommentType.POST);
if (post != null) {
@@ -321,7 +321,7 @@ class ProgramTextWriter {
}
}
- //// Space Property ////////////////////////////////////////////
+ //// Space Property
if (options.isShowProperties() && currentCodeUnit.hasProperty("Space")) {
try {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
index 7e8813a346..5f78c0be9a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java
@@ -264,7 +264,8 @@ public class MachoProgramBuilder {
segment.getSegmentName(), segment.getVMaddress(), segment.getVMsize()));
}
else {
- segmentOverlayMap.put(segment.getSegmentName(), overlayBlock.getStart().getAddressSpace());
+ segmentOverlayMap.put(segment.getSegmentName(),
+ overlayBlock.getStart().getAddressSpace());
overlaySections.addAll(segment.getSections());
}
}
@@ -1840,7 +1841,7 @@ public class MachoProgramBuilder {
extManager.getUniqueExternalLocation(Library.UNKNOWN, symbol);
if (loc != null) {
try {
- loc.setName(library, symbol, SourceType.IMPORTED);
+ loc.setName(null, symbol, SourceType.IMPORTED);
}
catch (InvalidInputException e) {
throw new Exception(e.getMessage());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/BrowserCodeUnitFormatOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/BrowserCodeUnitFormatOptions.java
index b8817a2203..176316eaa5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/BrowserCodeUnitFormatOptions.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/BrowserCodeUnitFormatOptions.java
@@ -206,7 +206,7 @@ public class BrowserCodeUnitFormatOptions extends CodeUnitFormatOptions
showNamespace = CodeUnitFormatOptions.ShowNamespace.NON_LOCAL;
}
- showLibraryInNamespace = namespaceOption.isShowLibraryInNamespace();
+ showLibrary = namespaceOption.isShowLibrary();
doRegVariableMarkup = fieldOptions.getBoolean(REGISTER_VARIABLE_MARKUP_OPTION, true);
doStackVariableMarkup = fieldOptions.getBoolean(STACK_VARIABLE_MARKUP_OPTION, true);
includeInferredVariableMarkup =
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionSignatureFieldFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionSignatureFieldFactory.java
index 970295269f..5851f17a0e 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionSignatureFieldFactory.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionSignatureFieldFactory.java
@@ -46,10 +46,13 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
public final static String GROUP_TITLE = "Function Signature Field";
public final static String DISPLAY_NAMESPACE =
GROUP_TITLE + Options.DELIMITER + GhidraOptions.DISPLAY_NAMESPACE;
+ public final static String DISPLAY_LIBRARY =
+ GROUP_TITLE + Options.DELIMITER + "Display Library";
private SymbolInspector inspector;
- private boolean displayFunctionScope;
+ private boolean displayNamespace;
+ private boolean displayLibrary;
public FunctionSignatureFieldFactory() {
super(FIELD_NAME);
@@ -69,10 +72,13 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
fieldOptions.registerOption(DISPLAY_NAMESPACE, false, null,
"Prepends namespaces to labels that are not in the global namespace.");
+ fieldOptions.registerOption(DISPLAY_LIBRARY, false, null,
+ "Prepends the library to labels that are in an external library.");
inspector = new SymbolInspector(displayOptions, null);
- displayFunctionScope = fieldOptions.getBoolean(DISPLAY_NAMESPACE, false);
+ displayNamespace = fieldOptions.getBoolean(DISPLAY_NAMESPACE, false);
+ displayLibrary = fieldOptions.getBoolean(DISPLAY_LIBRARY, false);
}
@Override
@@ -140,7 +146,8 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
}
// function name
- String functionName = simplifyTemplates(function.getName(displayFunctionScope));
+ String functionName = simplifyTemplates(function.getName(displayNamespace));
+ functionName = addLibrary(functionName, function);
as = new AttributedString(functionName, getFunctionNameColor(function), getMetrics());
textElements.add(new FunctionNameFieldElement(as, elementIndex, 0, startCol));
startCol += as.length();
@@ -224,6 +231,20 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
new CompositeFieldElement(textElements), startX + varWidth, width, hlProvider);
}
+ private String addLibrary(String functionName, Function function) {
+ if (function == null) {
+ return functionName;
+ }
+ if (!displayLibrary || !function.isExternal()) {
+ return functionName;
+ }
+ Library library = function.getSymbol().getLibrary();
+ if (library == null) {
+ return functionName;
+ }
+ return library.getName() + CodeUnitFormat.LIBRARY_DELIMITER + functionName;
+ }
+
private Color getFunctionNameColor(Function function) {
Symbol s = function.getSymbol();
return inspector.getColor(s);
@@ -371,7 +392,11 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
public void fieldOptionsChanged(Options options, String optionName, Object oldValue,
Object newValue) {
if (optionName.equals(DISPLAY_NAMESPACE)) {
- displayFunctionScope = ((Boolean) newValue).booleanValue();
+ displayNamespace = ((Boolean) newValue).booleanValue();
+ model.update();
+ }
+ if (optionName.equals(DISPLAY_LIBRARY)) {
+ displayLibrary = ((Boolean) newValue).booleanValue();
model.update();
}
}
@@ -574,7 +599,7 @@ public class FunctionSignatureFieldFactory extends FieldFactory {
getCharacterIndexForDataLocation(rowInField, columnInRow) + functionSigIndex;
return new FunctionNameFieldLocation(function.getProgram(),
functionProxy.getLocationAddress(), functionProxy.getFunctionAddress(),
- signatureIndex, signature, function.getName(displayFunctionScope));
+ signatureIndex, signature, function.getName(displayNamespace));
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/LabelFieldFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/LabelFieldFactory.java
index 28c02ead3b..09534d6eb5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/LabelFieldFactory.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/LabelFieldFactory.java
@@ -259,25 +259,25 @@ public class LabelFieldFactory extends FieldFactory {
return null;
}
- StringBuilder externalLocationDetails = new StringBuilder();
- Address addr = extLoc.getAddress();
- if (addr != null) {
- externalLocationDetails.append(addr.toString());
- }
+ StringBuilder buf = new StringBuilder();
+ buf.append(symbol.getName(true));
String origImportedName = extLoc.getOriginalImportedName();
if (origImportedName != null) {
- if (!externalLocationDetails.isEmpty()) {
- externalLocationDetails.append(": ");
- }
- externalLocationDetails.append(origImportedName);
+ buf.append(" (");
+ buf.append(origImportedName);
+ buf.append(")");
}
-
- if (externalLocationDetails.isEmpty()) {
- return null;
+ buf.append(" [");
+ buf.append(extLoc.getLibraryName());
+ Address addr = extLoc.getAddress();
+ if (addr != null) {
+ buf.append("@");
+ buf.append(addr.toString());
}
+ buf.append("]");
FontMetrics fm = getMetrics(OptionsGui.LABELS_NON_PRIMARY.getStyle());
- String text = externalLocationDetails.toString();
+ String text = buf.toString();
Color color = OptionsGui.LABELS_NON_PRIMARY.getColor();
AttributedString as = new AttributedString(EMPTY_ICON, text, color, fm, false, null);
return new TextFieldElement(as, 0, 0);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespacePropertyEditor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespacePropertyEditor.java
index a94ad0f93c..2806dbe78a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespacePropertyEditor.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespacePropertyEditor.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,11 +34,11 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
private static final String DISPLAY_LOCAL_NAMESPACE_LABEL = "Display Local Namespace";
private static final String DISPLAY_NON_LOCAL_NAMESPACE_LABEL = "Display Non-local Namespace";
private static final String LOCAL_NAMESPACE_PREFIX_LABEL = "Local Namespace Prefix";
- private static final String DISPLAY_LIBRARY_IN_NAMESPACE_LABEL = "Display library in Namespace";
+ private static final String DISPLAY_LIBRARY_LABEL = "Display library Name";
private static final String[] NAMES =
{ DISPLAY_LOCAL_NAMESPACE_LABEL, DISPLAY_NON_LOCAL_NAMESPACE_LABEL,
- LOCAL_NAMESPACE_PREFIX_LABEL, DISPLAY_LIBRARY_IN_NAMESPACE_LABEL };
+ LOCAL_NAMESPACE_PREFIX_LABEL, DISPLAY_LIBRARY_LABEL };
// help tooltips
private static final String SHOW_NON_LOCAL_NAMESPACE_TOOLTIP = HTMLUtilities.toWrappedHTML(
@@ -62,7 +62,7 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
private JCheckBox showLocalCheckBox;
private JCheckBox useLocalPrefixCheckBox;
private JTextField localPrefixField;
- private JCheckBox showLibraryInNamespaceCheckBox;
+ private JCheckBox showLibraryCheckBox;
public NamespacePropertyEditor() {
editorComponent = buildEditor();
@@ -81,12 +81,12 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
showLocalCheckBox.setSelected(false);
showLocalCheckBox.setToolTipText(SHOW_LOCAL_NAMESPACE_TOOLTIP);
- showLibraryInNamespaceCheckBox = new GCheckBox(DISPLAY_LIBRARY_IN_NAMESPACE_LABEL);
- showLibraryInNamespaceCheckBox.setSelected(true);
- showLibraryInNamespaceCheckBox.setToolTipText(SHOW_LIBRARY_IN_NAMESPACE_TOOLTIP);
+ showLibraryCheckBox = new GCheckBox(DISPLAY_LIBRARY_LABEL);
+ showLibraryCheckBox.setSelected(true);
+ showLibraryCheckBox.setToolTipText(SHOW_LIBRARY_IN_NAMESPACE_TOOLTIP);
panel.add(showNonLocalCheckBox);
- panel.add(showLibraryInNamespaceCheckBox);
+ panel.add(showLibraryCheckBox);
panel.add(showLocalCheckBox);
localPrefixField =
@@ -101,7 +101,7 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
firePropertyChange();
});
showNonLocalCheckBox.addItemListener(e -> firePropertyChange());
- showLibraryInNamespaceCheckBox.addItemListener(e -> firePropertyChange());
+ showLibraryCheckBox.addItemListener(e -> firePropertyChange());
panel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(10, 0, 10, 0), new TitledBorder("Namespace Options")));
@@ -169,9 +169,9 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
if (namespaceOption.isShowLocalNamespace() != showLocalCheckBox.isSelected()) {
showLocalCheckBox.setSelected(namespaceOption.isShowLocalNamespace());
}
- if (namespaceOption.isShowLibraryInNamespace() != showLibraryInNamespaceCheckBox
+ if (namespaceOption.isShowLibrary() != showLibraryCheckBox
.isSelected()) {
- showLibraryInNamespaceCheckBox.setSelected(namespaceOption.isShowLibraryInNamespace());
+ showLibraryCheckBox.setSelected(namespaceOption.isShowLibrary());
}
if (namespaceOption.isUseLocalPrefixOverride() != useLocalPrefixCheckBox.isSelected()) {
useLocalPrefixCheckBox.setSelected(namespaceOption.isUseLocalPrefixOverride());
@@ -183,14 +183,14 @@ public class NamespacePropertyEditor extends PropertyEditorSupport implements Cu
useLocalPrefixCheckBox.setEnabled(localNamespaceEnabled);
localPrefixField.setEnabled(localNamespaceEnabled && useLocalPrefixCheckBox.isSelected());
boolean nonLocalNamespaceEnabled = showNonLocalCheckBox.isSelected();
- showLibraryInNamespaceCheckBox.setEnabled(nonLocalNamespaceEnabled);
+ showLibraryCheckBox.setEnabled(nonLocalNamespaceEnabled);
}
private NamespaceWrappedOption cloneNamespaceValues() {
NamespaceWrappedOption newOption = new NamespaceWrappedOption();
newOption.setShowLocalNamespace(showLocalCheckBox.isSelected());
newOption.setShowNonLocalNamespace(showNonLocalCheckBox.isSelected());
- newOption.setShowLibraryInNamespace(showLibraryInNamespaceCheckBox.isSelected());
+ newOption.setShowLibrary(showLibraryCheckBox.isSelected());
newOption.setUseLocalPrefixOverride(useLocalPrefixCheckBox.isSelected());
newOption.setLocalPrefixText(localPrefixField.getText());
return newOption;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespaceWrappedOption.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespaceWrappedOption.java
index 3d5eda2083..adcb26baa2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespaceWrappedOption.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/NamespaceWrappedOption.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,20 +27,20 @@ public class NamespaceWrappedOption implements CustomOption {
private static final String SHOW_NON_LOCAL_NAMESPACE = "showNonLocalNamespace";
private static final String USE_LOCAL_PREFIX_OVERRIDE = "useLocalPrefixOverride";
private static final String LOCAL_PREFIX = "localPrefix";
- private static final String SHOW_LIBRARY_IN_NAMESPACE = "showLibraryInNamespace";
+ private static final String SHOW_LIBRARY = "showLibrary";
private static boolean DEFAULT_SHOW_LOCAL_NAMESPACE = false;
private static boolean DEFAULT_SHOW_NONLOCAL_NAMESPACE = true;
private static boolean DEFAULT_USE_LOCAL_PREFIX_OVERRIDE = false;
private static String DEFAULT_LOCAL_PREFIX_TEXT = "local::";
- private static boolean DEFAULT_SHOW_LIBRARY_IN_NAMESPACE = true;
+ private static boolean DEFAULT_SHOW_LIBRARY = true;
// init with default values
private boolean showLocalNamespace = DEFAULT_SHOW_LOCAL_NAMESPACE;
private boolean showNonLocalNamespace = DEFAULT_SHOW_NONLOCAL_NAMESPACE;
private boolean useLocalPrefixOverride = DEFAULT_USE_LOCAL_PREFIX_OVERRIDE;
private String localPrefixText = DEFAULT_LOCAL_PREFIX_TEXT;
- private boolean showLibraryInNamespace = DEFAULT_SHOW_LIBRARY_IN_NAMESPACE;
+ private boolean showLibrary = DEFAULT_SHOW_LIBRARY;
public NamespaceWrappedOption() {
// required for persistence
@@ -78,12 +78,12 @@ public class NamespaceWrappedOption implements CustomOption {
this.localPrefixText = localPrefixText;
}
- public boolean isShowLibraryInNamespace() {
- return showLibraryInNamespace;
+ public boolean isShowLibrary() {
+ return showLibrary;
}
- public void setShowLibraryInNamespace(boolean showLibraryInNamespace) {
- this.showLibraryInNamespace = showLibraryInNamespace;
+ public void setShowLibrary(boolean showLibrary) {
+ this.showLibrary = showLibrary;
}
@Override
@@ -101,7 +101,7 @@ public class NamespaceWrappedOption implements CustomOption {
showNonLocalNamespace == otherOption.showNonLocalNamespace &&
useLocalPrefixOverride == otherOption.useLocalPrefixOverride &&
localPrefixText.equals(otherOption.localPrefixText) &&
- showLibraryInNamespace == otherOption.showLibraryInNamespace;
+ showLibrary == otherOption.showLibrary;
}
@Override
@@ -112,7 +112,7 @@ public class NamespaceWrappedOption implements CustomOption {
result = prime * result + (showNonLocalNamespace ? 1 : 0);
result = prime * result + (useLocalPrefixOverride ? 1 : 0);
result = prime * result + (localPrefixText == null ? 0 : localPrefixText.hashCode());
- result = prime * result + (showLibraryInNamespace ? 1 : 0);
+ result = prime * result + (showLibrary ? 1 : 0);
return result;
}
@@ -127,8 +127,8 @@ public class NamespaceWrappedOption implements CustomOption {
useLocalPrefixOverride =
properties.getBoolean(USE_LOCAL_PREFIX_OVERRIDE, useLocalPrefixOverride);
localPrefixText = properties.getString(LOCAL_PREFIX, localPrefixText);
- showLibraryInNamespace =
- properties.getBoolean(SHOW_LIBRARY_IN_NAMESPACE, DEFAULT_SHOW_LIBRARY_IN_NAMESPACE);
+ showLibrary =
+ properties.getBoolean(SHOW_LIBRARY, DEFAULT_SHOW_LIBRARY);
}
@Override
@@ -137,6 +137,6 @@ public class NamespaceWrappedOption implements CustomOption {
properties.putBoolean(SHOW_NON_LOCAL_NAMESPACE, showNonLocalNamespace);
properties.putBoolean(USE_LOCAL_PREFIX_OVERRIDE, useLocalPrefixOverride);
properties.putString(LOCAL_PREFIX, localPrefixText);
- properties.putBoolean(SHOW_LIBRARY_IN_NAMESPACE, showLibraryInNamespace);
+ properties.putBoolean(SHOW_LIBRARY, showLibrary);
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java
index 5394825d9f..f3d9bc3c36 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java
@@ -1088,8 +1088,7 @@ public class ProgramBuilder {
SymbolTable symTable = program.getSymbolTable();
ExternalManager extMgr = program.getExternalManager();
- Namespace namespace = extMgr.addExternalLibraryName(libraryName, sourceType);
-
+ Namespace namespace = null;
String myExternalLabel = externalLabel;
if (myExternalLabel != null && myExternalLabel.indexOf(Namespace.DELIMITER) > 0) {
// External manager API does not yet support creation of namespaces within
@@ -1103,7 +1102,7 @@ public class ProgramBuilder {
Reference ref = refMgr.addExternalReference(addr(fromAddress), libraryName,
myExternalLabel, eAddress, sourceType, opIndex, refType);
- if (!(namespace instanceof Library)) {
+ if (namespace != null) {
Symbol s = symTable.getSymbol(ref);
s.setNamespace(namespace);
}
@@ -1127,7 +1126,8 @@ public class ProgramBuilder {
ExternalLocation extLoc =
em.addExtFunction(Library.UNKNOWN, originalName, eAddress, SourceType.IMPORTED);
Library lib = em.addExternalLibraryName(libName, SourceType.IMPORTED);
- extLoc.setName(lib, functionName, SourceType.IMPORTED);
+ extLoc.setName(null, functionName, SourceType.IMPORTED);
+ extLoc.setLibrary(lib);
return extLoc;
});
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
index 5976b4d848..e0e1452b54 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
@@ -17,7 +17,6 @@ package ghidra.program.model.listing;
import java.util.*;
-import ghidra.app.util.NamespaceUtils;
import ghidra.app.util.viewer.field.CommentUtils;
import ghidra.program.model.address.*;
import ghidra.program.model.data.*;
@@ -51,6 +50,7 @@ public class CodeUnitFormat {
* Supported memory address mask cases (mask value)
*/
private static final long[] MASK_CASES = new long[] { 0x0ffff, 0x0ffffffff };
+ public static final String LIBRARY_DELIMITER = ":";
/**
* Default code unit format
@@ -1315,6 +1315,16 @@ public class CodeUnitFormat {
return name;
}
+ private String addLibrary(String name, Library library) {
+ if (library == null) {
+ return name;
+ }
+ if (options.showLibrary) {
+ return library.getName() + LIBRARY_DELIMITER + name;
+ }
+ return name;
+ }
+
private String addNamespace(Program program, Namespace parentNamespace, String name,
Address markupAddress) {
if (parentNamespace == null) {
@@ -1346,12 +1356,7 @@ public class CodeUnitFormat {
namespaceName = options.localPrefixOverride;
}
if (namespaceName == null) {
- if (!options.showLibraryInNamespace) {
- namespaceName = NamespaceUtils.getNamespacePathWithoutLibrary(parentNamespace);
- }
- else {
- namespaceName = parentNamespace.getName(true);
- }
+ namespaceName = parentNamespace.getName(true);
}
if (namespaceName.length() != 0 && !namespaceName.endsWith(Namespace.DELIMITER)) {
namespaceName += Namespace.DELIMITER;
@@ -1376,6 +1381,7 @@ public class CodeUnitFormat {
String name = symbol.getName();
String displayName =
addNamespace(program, symbol.getParentNamespace(), name, markupAddress);
+ displayName = addLibrary(displayName, symbol.getLibrary());
return simplifyTemplate(displayName);
}
@@ -1483,6 +1489,7 @@ public class CodeUnitFormat {
if (markupAddress != null) {
displayName = addNamespace(program, containingSymbol.getParentNamespace(),
displayName, markupAddress);
+ displayName = addLibrary(displayName, symbol.getLibrary());
}
return simplifyTemplate(displayName) + PLUS + SymbolUtilities.getDiffString(diff);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormatOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormatOptions.java
index b7b118ac80..1c3800a054 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormatOptions.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormatOptions.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -70,7 +70,7 @@ public class CodeUnitFormatOptions {
protected volatile ShowBlockName showBlockName = ShowBlockName.NEVER;
protected volatile ShowNamespace showNamespace = ShowNamespace.NEVER;
protected volatile String localPrefixOverride = null;
- protected volatile boolean showLibraryInNamespace = true;
+ protected volatile boolean showLibrary = true;
protected volatile boolean doRegVariableMarkup = true;
protected volatile boolean doStackVariableMarkup = true;
protected volatile boolean includeInferredVariableMarkup = false;
@@ -122,11 +122,11 @@ public class CodeUnitFormatOptions {
public CodeUnitFormatOptions(ShowBlockName showBlockName, ShowNamespace showNamespace,
String localPrefixOverride, boolean doRegVariableMarkup, boolean doStackVariableMarkup,
boolean includeInferredVariableMarkup, boolean alwaysShowPrimaryReference,
- boolean includeScalarReferenceAdjustment, boolean showLibraryInNamespace,
+ boolean includeScalarReferenceAdjustment, boolean showLibrary,
boolean followReferencedPointers, TemplateSimplifier templateSimplifier) {
this.showBlockName = showBlockName;
this.showNamespace = showNamespace;
- this.showLibraryInNamespace = showLibraryInNamespace;
+ this.showLibrary = showLibrary;
this.localPrefixOverride = localPrefixOverride;
this.doRegVariableMarkup = doRegVariableMarkup;
this.doStackVariableMarkup = doStackVariableMarkup;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/DiffUtility.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/DiffUtility.java
index 5f3e8a754a..70bb901bb6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/DiffUtility.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/DiffUtility.java
@@ -169,10 +169,7 @@ public class DiffUtility extends SimpleDiffUtility {
Namespace parentNamespace = namespace.getParentNamespace();
Namespace otherParentNamespace = createNamespace(program, parentNamespace, otherProgram);
SourceType source = namespace.getSymbol().getSource();
- if (namespace instanceof Library) {
- return otherProgram.getSymbolTable().createExternalLibrary(namespace.getName(), source);
- }
- else if (namespace instanceof GhidraClass) {
+ if (namespace instanceof GhidraClass) {
return otherProgram.getSymbolTable()
.createClass(otherParentNamespace, namespace.getName(), source);
}
@@ -180,6 +177,24 @@ public class DiffUtility extends SimpleDiffUtility {
.createNameSpace(otherParentNamespace, namespace.getName(), source);
}
+ /**
+ * Create a library in the other program that corresponds to the given library in the given
+ * program.
+ * @param program the program containing the existing library
+ * @param library the existing library in the program
+ * @param otherProgram the program where an equivalent library is to be created
+ * @return A library in the other program with the same name as the given library
+ * @throws DuplicateNameException if a library with that name already exists in the other
+ * program
+ * @throws InvalidInputException if the library name is invalid (Should never happen since
+ * the name came from an existing library)
+ */
+ public static Library createLibrary(Program program, Library library, Program otherProgram)
+ throws DuplicateNameException, InvalidInputException {
+ return otherProgram.getSymbolTable()
+ .createExternalLibrary(library.getName(), library.getSymbol().getSource());
+ }
+
/**
* Determine if the specified variables have overlapping storage.
* Variable storage check includes dynamically mapped storage for parameters. This method
@@ -326,6 +341,12 @@ public class DiffUtility extends SimpleDiffUtility {
public static Reference createReference(final Program program, final Reference ref,
final Program otherProgram) {
+ Address otherFromAddress =
+ getCompatibleAddress(program, ref.getFromAddress(), otherProgram);
+ if (otherFromAddress == null) {
+ return null;
+ }
+
ReferenceManager otherRefMgr = otherProgram.getReferenceManager();
if (ref.isExternalReference()) {
@@ -346,7 +367,7 @@ public class DiffUtility extends SimpleDiffUtility {
otherExtLoc =
otherProgram.getExternalManager().getExternalLocation(otherExtSym);
}
- return otherRefMgr.addExternalReference(ref.getFromAddress(), ref.getOperandIndex(),
+ return otherRefMgr.addExternalReference(otherFromAddress, ref.getOperandIndex(),
otherExtLoc, ref.getSource(), ref.getReferenceType());
}
catch (DuplicateNameException e) {
@@ -357,11 +378,6 @@ public class DiffUtility extends SimpleDiffUtility {
}
}
- Address otherFromAddress =
- getCompatibleAddress(program, ref.getFromAddress(), otherProgram);
- if (otherFromAddress == null) {
- return null;
- }
Address otherToAddress = getCompatibleAddress(program, ref.getToAddress(), otherProgram);
if (otherToAddress == null && !ref.isStackReference()) {
return null;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ExternalSymbolResolver.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ExternalSymbolResolver.java
index 58503ed9b7..fbda24ea14 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ExternalSymbolResolver.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ExternalSymbolResolver.java
@@ -23,10 +23,13 @@ import java.util.function.Consumer;
import db.Transaction;
import ghidra.app.util.opinion.Loaded;
import ghidra.framework.model.*;
-import ghidra.program.model.listing.*;
+import ghidra.program.database.symbol.MemorySymbol;
+import ghidra.program.model.listing.Library;
+import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.util.Msg;
-import ghidra.util.exception.*;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.exception.VersionException;
import ghidra.util.task.TaskMonitor;
/**
@@ -224,7 +227,7 @@ public class ExternalSymbolResolver implements Closeable {
else if (libPath != null) {
logger.accept(
"\t[%s] -> %s, %d new symbols resolved".formatted(extLib.getName(),
- loggedLibPath, extLib.resolvedSymbols.size()));
+ loggedLibPath, extLib.resolvedSymbols.size()));
}
else {
logger.accept("\t[%s] -> %s".formatted(extLib.getName(), loggedLibPath));
@@ -301,7 +304,7 @@ public class ExternalSymbolResolver implements Closeable {
}
return result;
}
-
+
/**
* Moves unresolved functions from the EXTERNAL/UNKNOWN namespace to the namespace of the
* external library if the extLib publishes a symbol with a matching name.
@@ -328,16 +331,9 @@ public class ExternalSymbolResolver implements Closeable {
String extLocName =
Objects.requireNonNullElse(extLoc.getOriginalImportedName(), extLoc.getLabel());
if (isExportedSymbol(extLib.libProgram, extLocName)) {
- try {
- s.setNamespace(extLib.lib);
- idIterator.remove();
- extLib.resolvedSymbols.add(s.getName());
- }
- catch (DuplicateNameException | InvalidInputException
- | CircularDependencyException e) {
- Msg.error(ExternalSymbolResolver.class,
- "Error setting external symbol namespace for " + extLoc.getLabel(), e);
- }
+ ((MemorySymbol) s).setLibrary(extLib.lib);
+ idIterator.remove();
+ extLib.resolvedSymbols.add(s.getName());
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java
index 7a60365e42..db9d7dd1b6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java
@@ -524,9 +524,6 @@ public class FunctionUtility {
if (otherNamespace instanceof GhidraClass) {
return symbolTable.createClass(parent, otherName, source);
}
- else if (otherNamespace instanceof Library) {
- return symbolTable.createExternalLibrary(otherName, source);
- }
return symbolTable.createNameSpace(parent, otherName, source);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java
index 11fed712fa..eb2cb8264a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java
@@ -1311,6 +1311,7 @@ public class ProgramMerge {
String fromExtLabel = fromExtLoc.getLabel();
Address fromExtAddr = fromExtLoc.getAddress();
SourceType fromSourceType = fromExtLoc.getSource();
+ Library fromLibrary = fromExtLoc.getLibrary();
ExternalManager toExtMgr = toPgm.getExternalManager();
try {
@@ -1319,7 +1320,9 @@ public class ProgramMerge {
ExternalLocation toExternalLocation =
SimpleDiffUtility.getMatchingExternalLocation(fromPgm, fromExtLoc, toPgm, false);
if (toExternalLocation == null) {
- toExtMgr.addExtLocation(toNamespace, fromExtLabel, fromExtAddr, fromSourceType);
+ Library toLibrary = DiffUtility.createLibrary(fromPgm, fromLibrary, toPgm);
+ toExtMgr.addExtLocation(toLibrary, toNamespace, fromExtLabel, fromExtAddr,
+ fromSourceType);
}
else {
String toExtLabel = toExternalLocation.getLabel();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/AbstractExternalMergerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/AbstractExternalMergerTest.java
index fdabba6295..1ee4df8f79 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/AbstractExternalMergerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/AbstractExternalMergerTest.java
@@ -95,13 +95,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
return externalLocation;
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- */
void removeExternalLabel(ProgramDB program, String transactionDescription, String library,
String label) {
int txId = program.startTransaction(transactionDescription);
@@ -128,16 +121,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertNull(externalLocation);
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- * @param sourceType
- * @return
- */
ExternalLocation createExternalFunction(ProgramDB program, String transactionDescription,
String library, String label, String addressAsString, SourceType sourceType) {
Address address = (addressAsString != null) ? addr(program, addressAsString) : null;
@@ -176,22 +159,14 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
return externalLocation;
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- */
void removeExternalFunctionLocation(ProgramDB program, String transactionDescription,
- String library, String label, String addressAsString) {
+ String libraryName, String label, String addressAsString) {
int txId = program.startTransaction(transactionDescription);
boolean commit = false;
ExternalManager externalManager = program.getExternalManager();
try {
ExternalLocation externalLocation =
- externalManager.getUniqueExternalLocation(library, label);
+ externalManager.getUniqueExternalLocation(libraryName, label);
assertNotNull(externalLocation);
if (!externalLocation.isFunction()) {
Assert.fail(externalLocation.getLabel() + " is not a function.");
@@ -200,11 +175,13 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
boolean delete = externalSymbol.delete();
assertTrue(delete);
commit = true;
-
- Symbol s = getUniqueSymbol(program, library, program.getGlobalNamespace());
+ Symbol s = getUniqueSymbol(program, libraryName, program.getGlobalNamespace());
if (s instanceof LibrarySymbol) {
- Symbol symbol = getUniqueSymbol(program, label, (Namespace) s.getObject());
- symbol.delete();
+ Library library = (Library) s.getObject();
+ Symbol symbol = getUniqueSymbol(program, label, null);
+ if (library.equals(symbol.getLibrary())) {
+ symbol.delete();
+ }
}
commit = true;
}
@@ -215,31 +192,19 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
program.endTransaction(txId, commit);
}
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol s = symbolTable.getLibrarySymbol(library);
- if (s instanceof LibrarySymbol) {
- Symbol symbol = getUniqueSymbol(program, label, (Namespace) s.getObject());
- assertNull(symbol);
- }
+ Symbol symbol = getUniqueSymbol(program, label, null);
+ assertNull(symbol);
- assertTrue(externalManager.contains(library));
+ assertTrue(externalManager.contains(libraryName));
ExternalLocation externalLocation =
- externalManager.getUniqueExternalLocation(library, label);
+ externalManager.getUniqueExternalLocation(libraryName, label);
assertNull(externalLocation);
FunctionIterator externalFunctions = program.getFunctionManager().getExternalFunctions();
assertEquals(false, externalFunctions.hasNext());
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- */
- void changeExternalFunctionIntoExternalLabel(Program program, String[] path) {
- Function externalFunction = getExternalFunction(program, path);
+ void changeExternalFunctionIntoExternalLabel(Program program, String library, String[] path) {
+ Function externalFunction = getExternalFunction(program, library, path);
int txId = program.startTransaction("Changing external function into an external label.");
boolean commit = false;
@@ -256,19 +221,11 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
program.endTransaction(txId, commit);
}
- ExternalLocation externalLocation = getExternalLocation(program, path);
+ ExternalLocation externalLocation = getExternalLocation(program, library, path);
assertNotNull(externalLocation);
assertFalse(externalLocation.isFunction());
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- */
void setAddressForExternalLabel(ProgramDB program, String transactionDescription,
String library, String label, String addressAsString) {
int txId = program.startTransaction(transactionDescription);
@@ -300,13 +257,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertEquals(addressAsString, (address != null) ? address.toString() : null);
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- */
void removeAddressFromExternalLabel(ProgramDB program, String transactionDescription,
String library, String label) {
int txId = program.startTransaction(transactionDescription);
@@ -336,13 +286,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertNull(externalLocation.getAddress());
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- */
void changeMemAddressForExternalLabel(ProgramDB program, String transactionDescription,
String library, String label, String changeAddressAsString) {
Address changeAddress =
@@ -375,15 +318,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertEquals(changeAddress, externalLocation.getAddress());
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- * @param externalDataType
- */
void setDataTypeForExternalLabel(ProgramDB program, String transactionDescription,
String library, String label, String addressAsString, DataType externalDataType) {
Address address = (addressAsString != null) ? addr(program, addressAsString) : null;
@@ -415,14 +349,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertTrue(dataType.isEquivalent(externalDataType));
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param addressAsString
- */
void removeDataTypeFromExternalLabel(ProgramDB program, String transactionDescription,
String library, String label, String addressAsString) {
Address address = (addressAsString != null) ? addr(program, addressAsString) : null;
@@ -454,14 +380,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertNull(dataType);
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- * @param externalSourceType
- */
void setSourceTypeForExternalLabel(ProgramDB program, String transactionDescription,
String library, String label, SourceType externalSourceType) {
int txId = program.startTransaction(transactionDescription);
@@ -491,13 +409,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertTrue(sourceType == externalSourceType);
}
- /**
- *
- * @param program
- * @param transactionDescription
- * @param library
- * @param label
- */
void changeExternalLabelIntoFunction(ProgramDB program, String transactionDescription,
String library, String label) {
int txId = program.startTransaction(transactionDescription);
@@ -528,11 +439,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertNotNull(function);
}
- /**
- *
- * @param externalLocation
- * @param expectedAddress
- */
void checkExternalAddress(ExternalLocation externalLocation, String expectedAddress) {
Address address = externalLocation.getAddress();
String addressString = (address != null) ? address.toString() : null;
@@ -541,11 +447,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertEquals(failureMessage, expectedAddress, addressString);
}
- /**
- *
- * @param externalLocation
- * @param expectedSourceType
- */
void checkExternalSourceType(ExternalLocation externalLocation, SourceType expectedSourceType) {
SourceType sourceType = externalLocation.getSource();
String failureMessage =
@@ -554,11 +455,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertEquals(failureMessage, expectedSourceType, sourceType);
}
- /**
- *
- * @param externalLocation
- * @param expectedDataType
- */
void checkExternalDataType(ExternalLocation externalLocation, DataType expectedDataType) {
DataType dataType = externalLocation.getDataType();
String failureMessage = "Expected external data type '" + expectedDataType.getName() +
@@ -572,11 +468,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertTrue(failureMessage, expectedDataType.isEquivalent(actualDataType));
}
- /**
- *
- * @param function
- * @param expectedDataType
- */
void checkFunctionReturnType(Function function, DataType expectedDataType) {
DataType functionReturnType = function.getReturnType();
String failureMessage = "Expected return type '" + expectedDataType.getName() +
@@ -584,11 +475,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertTrue(failureMessage, expectedDataType.isEquivalent(functionReturnType));
}
- /**
- *
- * @param parameter
- * @param expectedDataType
- */
void checkParameterDataType(Parameter parameter, DataType expectedDataType) {
DataType parameterDataType = parameter.getDataType();
String failureMessage =
@@ -597,14 +483,6 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
assertTrue(failureMessage, expectedDataType.isEquivalent(parameterDataType));
}
- /**
- *
- * @param programVersion
- * @param externalLocationPathName
- * @param conflictNumber
- * @param totalNumberOfConflicts
- * @throws Exception
- */
void checkExternalPanelInfo(final String programVersion, final String externalLocationPathName,
final int conflictNumber, final int totalNumberOfConflicts) throws Exception {
waitForPrompting();
@@ -714,22 +592,24 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
}
}
- Function createExternalFunction(final Program program, final String[] path)
+ Function createExternalFunction(Program program, String library, String[] path)
throws DuplicateNameException, InvalidInputException {
- return createExternalFunction(program, path, null, null, SourceType.USER_DEFINED);
+ return createExternalFunction(program, library, path, null, null, SourceType.USER_DEFINED);
}
- Function createExternalFunction(final Program program, final String[] path,
+ Function createExternalFunction(Program program, String library, String[] path,
final Address address) throws DuplicateNameException, InvalidInputException {
- return createExternalFunction(program, path, address, null, SourceType.USER_DEFINED);
+ return createExternalFunction(program, library, path, address, null,
+ SourceType.USER_DEFINED);
}
- Function createExternalFunction(final Program program, final String[] path,
+ Function createExternalFunction(Program program, String library, String[] path,
final DataType returnType) throws DuplicateNameException, InvalidInputException {
- return createExternalFunction(program, path, null, returnType, SourceType.USER_DEFINED);
+ return createExternalFunction(program, library, path, null, returnType,
+ SourceType.USER_DEFINED);
}
- Function createExternalFunction(final Program program, final String[] path,
+ Function createExternalFunction(Program program, String libraryName, String[] path,
final Address memoryAddress, final DataType returnType, final SourceType sourceType)
throws DuplicateNameException, InvalidInputException {
@@ -737,17 +617,9 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
ExternalManager externalManager = program.getExternalManager();
int nameIndex = path.length - 1;
- Library externalLibrary;
- Symbol librarySymbol = symbolTable.getLibrarySymbol(path[0]);
- if (librarySymbol != null) {
- externalLibrary = (Library) librarySymbol.getObject();
- }
- else {
- externalLibrary = symbolTable.createExternalLibrary(path[0], sourceType);
- }
-
- Namespace currentNamespace = externalLibrary;
- for (int i = 1; i < nameIndex; i++) {
+ Library library = getLibrary(symbolTable, libraryName, sourceType);
+ Namespace currentNamespace = program.getGlobalNamespace();
+ for (int i = 0; i < nameIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
if (nextNamespaceSymbol != null) {
currentNamespace = (Namespace) nextNamespaceSymbol.getObject();
@@ -758,8 +630,9 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
}
}
- ExternalLocation externalLocation = externalManager.addExtFunction(currentNamespace,
- path[nameIndex], memoryAddress, sourceType);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(library, currentNamespace,
+ path[nameIndex], memoryAddress, sourceType);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -771,7 +644,16 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
return function;
}
- ExternalLocation createExternalLabel(final Program program, final String[] path,
+ private Library getLibrary(SymbolTable symbolTable, String libraryName, SourceType source)
+ throws DuplicateNameException, InvalidInputException {
+ Symbol librarySymbol = symbolTable.getLibrarySymbol(libraryName);
+ if (librarySymbol != null) {
+ return (Library) librarySymbol.getObject();
+ }
+ return symbolTable.createExternalLibrary(libraryName, source);
+ }
+
+ ExternalLocation createExternalLabel(Program program, String libraryName, String[] path,
final Address memoryAddress, final SourceType sourceType)
throws DuplicateNameException, InvalidInputException {
@@ -779,17 +661,10 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
ExternalManager externalManager = program.getExternalManager();
int nameIndex = path.length - 1;
- Library externalLibrary;
- Symbol librarySymbol = getUniqueSymbol(program, path[0], program.getGlobalNamespace());
- if (librarySymbol != null) {
- externalLibrary = (Library) librarySymbol.getObject();
- }
- else {
- externalLibrary = symbolTable.createExternalLibrary(path[0], sourceType);
- }
+ Library library = getLibrary(symbolTable, libraryName, sourceType);
- Namespace currentNamespace = externalLibrary;
- for (int i = 1; i < nameIndex; i++) {
+ Namespace currentNamespace = program.getGlobalNamespace();
+ for (int i = 0; i < nameIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
if (nextNamespaceSymbol != null) {
currentNamespace = (Namespace) nextNamespaceSymbol.getObject();
@@ -800,29 +675,21 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
}
}
- ExternalLocation externalLocation = externalManager.addExtLocation(currentNamespace,
- path[nameIndex], memoryAddress, sourceType);
+ ExternalLocation externalLocation =
+ externalManager.addExtLocation(library, currentNamespace,
+ path[nameIndex], memoryAddress, sourceType);
return externalLocation;
}
- Namespace createExternalNamespace(final Program program, final String[] path,
- final SourceType sourceType) throws DuplicateNameException, InvalidInputException {
+ Namespace createNamespace(Program program, String[] path, final SourceType sourceType)
+ throws DuplicateNameException, InvalidInputException {
SymbolTable symbolTable = program.getSymbolTable();
int namespaceIndex = path.length;
- Library externalLibrary;
- Symbol librarySymbol = getUniqueSymbol(program, path[0], program.getGlobalNamespace());
- if (librarySymbol != null) {
- externalLibrary = (Library) librarySymbol.getObject();
- }
- else {
- externalLibrary = symbolTable.createExternalLibrary(path[0], sourceType);
- }
-
- Namespace currentNamespace = externalLibrary;
- for (int i = 1; i < namespaceIndex; i++) {
+ Namespace currentNamespace = null;
+ for (int i = 0; i < namespaceIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
if (nextNamespaceSymbol != null) {
currentNamespace = (Namespace) nextNamespaceSymbol.getObject();
@@ -852,18 +719,18 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
return function.addParameter(parameter1, sourceType);
}
- Function getExternalFunction(Program program, String[] path) {
-
+ Function getExternalFunction(Program program, String libraryName, String[] path) {
+ // the first name is the library. the other names form the namespace path
SymbolTable symbolTable = program.getSymbolTable();
int nameIndex = path.length - 1;
- Symbol librarySymbol = symbolTable.getLibrarySymbol(path[0]);
+ Symbol librarySymbol = symbolTable.getLibrarySymbol(libraryName);
SymbolType librarySymbolType = librarySymbol.getSymbolType();
assertEquals(SymbolType.LIBRARY, librarySymbolType);
- Library externalLibrary = (Library) librarySymbol.getObject();
+ Library library = (Library) librarySymbol.getObject();
- Namespace currentNamespace = externalLibrary;
- for (int i = 1; i < nameIndex; i++) {
+ Namespace currentNamespace = null;
+ for (int i = 0; i < nameIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
currentNamespace = (Namespace) nextNamespaceSymbol.getObject();
}
@@ -872,40 +739,37 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
if (functionSymbol == null) {
return null;
}
+ assertEquals(library, functionSymbol.getLibrary());
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
return function;
}
- ExternalLocation getExternalLocation(Program program, String[] path) {
+ ExternalLocation getExternalLocation(Program program, String library, String[] path) {
int nameIndex = path.length - 1;
- Namespace namespace = getExternalNamespace(program, path, path.length - 1);
+ Namespace namespace = getNamespace(program, path, path.length - 1);
List<Symbol> symbols = program.getSymbolTable().getSymbols(path[nameIndex], namespace);
if (symbols.size() != 1) {
return null;
}
+ Symbol symbol = symbols.get(0);
+ assertEquals(library, symbol.getLibrary().getName());
ExternalManager externalManager = program.getExternalManager();
- return externalManager.getExternalLocation(symbols.get(0));
+ return externalManager.getExternalLocation(symbol);
}
- Namespace getExternalNamespace(Program program, String[] path) {
- return getExternalNamespace(program, path, path.length);
+ Namespace getNamespace(Program program, String[] path) {
+ return getNamespace(program, path, path.length);
}
- Namespace getExternalNamespace(Program program, String[] path, int pathLength) {
+ Namespace getNamespace(Program program, String[] path, int pathLength) {
SymbolTable symbolTable = program.getSymbolTable();
-
- Symbol librarySymbol = symbolTable.getLibrarySymbol(path[0]);
- SymbolType librarySymbolType = librarySymbol.getSymbolType();
- assertEquals(SymbolType.LIBRARY, librarySymbolType);
- Library externalLibrary = (Library) librarySymbol.getObject();
-
- Namespace currentNamespace = externalLibrary;
- for (int i = 1; i < pathLength; i++) {
- currentNamespace = findExternalNamespaceSymbol(symbolTable, path[i], currentNamespace);
+ Namespace currentNamespace = null;
+ for (int i = 0; i < pathLength; i++) {
+ currentNamespace = findNamespaceSymbol(symbolTable, path[i], currentNamespace);
if (currentNamespace == null) {
return null;
}
@@ -913,16 +777,13 @@ public abstract class AbstractExternalMergerTest extends AbstractListingMergeMan
return currentNamespace;
}
- private Namespace findExternalNamespaceSymbol(SymbolTable symbolTable, String name,
+ private Namespace findNamespaceSymbol(SymbolTable symbolTable, String name,
Namespace currentNamespace) {
List<Symbol> symbols = symbolTable.getSymbols(name, currentNamespace);
for (Symbol symbol : symbols) {
Object object = symbol.getObject();
- if (object instanceof Namespace) {
- Namespace namespace = (Namespace) object;
- if (namespace.isExternal()) {
- return namespace;
- }
+ if (object instanceof Namespace namespace) {
+ return namespace;
}
}
return null;
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMergeManagerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMergeManagerTest.java
index 15f19431b3..c109153669 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMergeManagerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMergeManagerTest.java
@@ -50,7 +50,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -62,7 +62,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -103,7 +103,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -134,10 +134,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -192,9 +192,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
executeMerge(ASK_USER);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
Function function =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(function);
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
@@ -250,7 +250,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -262,7 +262,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -308,7 +308,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -339,10 +339,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -392,9 +392,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
executeMerge(ASK_USER);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
Function function =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(function);
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
@@ -450,7 +450,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -462,7 +462,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -503,7 +503,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -534,10 +534,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -587,7 +587,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function externalFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
externalFunction.getSymbol().delete();
}
catch (Exception e) {
@@ -600,9 +600,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton("Resolve External Function Remove Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
Function function =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(function);
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
@@ -658,7 +658,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -670,7 +670,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -711,7 +711,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -742,10 +742,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -795,7 +795,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function externalFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
externalFunction.getSymbol().delete();
}
catch (Exception e) {
@@ -808,9 +808,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton("Resolve External Function Remove Conflict", MY_BUTTON);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
ExternalLocation location =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalLocation(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(location);
}
@@ -823,7 +823,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -835,7 +835,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -876,7 +876,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function externalFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
externalFunction.getSymbol().delete();
}
catch (Exception e) {
@@ -888,7 +888,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -919,10 +919,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -973,9 +973,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton("Resolve External Function Remove Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
ExternalLocation location =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalLocation(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(location);
}
@@ -988,7 +988,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addStackParameter(applesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(applesFunction, "P2", SourceType.USER_DEFINED,
@@ -1000,7 +1000,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -1041,7 +1041,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function externalFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
externalFunction.getSymbol().delete();
}
catch (Exception e) {
@@ -1053,7 +1053,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -1084,10 +1084,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -1138,9 +1138,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton("Resolve External Function Remove Conflict", MY_BUTTON);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
Function function =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(function);
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
@@ -1196,7 +1196,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addParameter(applesFunction, "P1", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
addParameter(applesFunction, "P2", SourceType.USER_DEFINED, new DWordDataType(),
@@ -1208,7 +1208,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just created.
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertEquals("apples", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(DataType.DEFAULT, function.getReturnType());
@@ -1250,7 +1250,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
// Set the external Mem Address
ExternalLocation externalLocation =
- getExternalLocation(program, new String[] { "user32.dll", "apples" });
+ getExternalLocation(program, "user32.dll", new String[] { "apples" });
try {
externalLocation.setLocation(externalLocation.getLabel(),
@@ -1273,7 +1273,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
// Set the external Mem Address
ExternalLocation externalLocation =
- getExternalLocation(program, new String[] { "user32.dll", "apples" });
+ getExternalLocation(program, "user32.dll", new String[] { "apples" });
try {
externalLocation.setLocation(externalLocation.getLabel(),
@@ -1287,7 +1287,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
}
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("FRED", SourceType.USER_DEFINED);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -1318,10 +1318,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
// Check the function just changed.
Function applesFunction =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNull(applesFunction);
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(program, "user32.dll", new String[] { "FRED" });
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
checkDataType(new FloatDataType(), function.getReturnType());
@@ -1373,14 +1373,14 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
new int[] { INFO_ROW, KEEP_LATEST });// Memory Address conflict
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
ExternalLocation externalLocation =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalLocation(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(externalLocation);
assertEquals("70db1234", externalLocation.getAddress().toString());
Function function =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" });
assertNotNull(function);
assertEquals("FRED", function.getName());
assertEquals(SourceType.USER_DEFINED, function.getSymbol().getSource());
@@ -1436,12 +1436,12 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addParameter(applesFunction, "P1", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
}
@@ -1454,7 +1454,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
function.setName("BARNEY", SourceType.USER_DEFINED);
}
@@ -1462,33 +1462,33 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Assert.fail(e.getMessage());
}
assertNotNull(
- getExternalFunction(program, new String[] { "user32.dll", "BARNEY" }));
- assertNull(getExternalFunction(program, new String[] { "user32.dll", "apples" }));
+ getExternalFunction(program, "user32.dll", new String[] { "BARNEY" }));
+ assertNull(getExternalFunction(program, "user32.dll", new String[] { "apples" }));
}
@Override
public void modifyPrivate(ProgramDB program) {
try {
Function function =
- getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ getExternalFunction(program, "user32.dll", new String[] { "oranges" });
function.setName("FRED", SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- assertNotNull(getExternalFunction(program, new String[] { "user32.dll", "FRED" }));
- assertNull(getExternalFunction(program, new String[] { "user32.dll", "oranges" }));
+ assertNotNull(getExternalFunction(program, "user32.dll", new String[] { "FRED" }));
+ assertNull(getExternalFunction(program, "user32.dll", new String[] { "oranges" }));
}
});
executeMerge(ASK_USER);
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" }));
- assertNotNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "BARNEY" }));
- assertNotNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" }));
+ assertNotNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "BARNEY" }));
+ assertNotNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" }));
}
@Test
@@ -1500,12 +1500,12 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" });
+ createExternalFunction(program, "user32.dll", new String[] { "apples" });
addParameter(applesFunction, "P1", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "P1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
}
@@ -1518,9 +1518,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setName("BARNEY", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setName("BETTY", SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1532,9 +1532,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setName("FRED", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setName("WILMA", SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1544,20 +1544,20 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
});
executeMerge(ASK_USER);
- checkExternalPanelInfo(MY_TITLE, "user32.dll::FRED", 1, 2);
+ checkExternalPanelInfo(MY_TITLE, "FRED", 1, 2);
chooseVariousOptionsForConflictType("Resolve External Detail Conflict",
new int[] { INFO_ROW, KEEP_LATEST });
- checkExternalPanelInfo(MY_TITLE, "user32.dll::WILMA", 2, 2);
+ checkExternalPanelInfo(MY_TITLE, "WILMA", 2, 2);
chooseVariousOptionsForConflictType("Resolve External Detail Conflict",
new int[] { INFO_ROW, KEEP_MY });
waitForMergeCompletion();
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" }));
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" }));
- assertNotNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "BARNEY" }));
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "BETTY" }));
- assertNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "FRED" }));
- assertNotNull(getExternalFunction(resultProgram, new String[] { "user32.dll", "WILMA" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" }));
+ assertNotNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "BARNEY" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "BETTY" }));
+ assertNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "FRED" }));
+ assertNotNull(getExternalFunction(resultProgram, "user32.dll", new String[] { "WILMA" }));
}
@Test
@@ -1568,9 +1568,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
@Override
public void modifyLatest(ProgramDB program) {
try {
- createExternalFunction(program, new String[] { "user32.dll", "BETTY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BETTY" },
addr(program, "1002239"), null, SourceType.USER_DEFINED);
- createExternalFunction(program, new String[] { "user32.dll", "BARNEY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BARNEY" },
addr(program, "77db1020"), null, SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1581,9 +1581,9 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
@Override
public void modifyPrivate(ProgramDB program) {
try {
- createExternalFunction(program, new String[] { "user32.dll", "BETTY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BETTY" },
addr(program, "10063b4"));
- createExternalFunction(program, new String[] { "user32.dll", "BARNEY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BARNEY" },
addr(program, "77db1130"));
}
catch (Exception e) {
@@ -1623,10 +1623,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
@Override
public void modifyLatest(ProgramDB program) {
try {
- createExternalFunction(program, new String[] { "user32.dll", "BETTY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BETTY" },
addr(program, "1002239"));
- createExternalFunction(program, new String[] { "user32.dll", "BARNEY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BARNEY" },
addr(program, "77db1020"));
}
catch (Exception e) {
@@ -1637,10 +1637,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
@Override
public void modifyPrivate(ProgramDB program) {
try {
- createExternalFunction(program, new String[] { "user32.dll", "BETTY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BETTY" },
addr(program, "77db1020"));
- createExternalFunction(program, new String[] { "user32.dll", "BARNEY" },
+ createExternalFunction(program, "user32.dll", new String[] { "BARNEY" },
addr(program, "1002239"));
}
catch (Exception e) {
@@ -1675,7 +1675,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1691,7 +1691,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
}
catch (Exception e) {
@@ -1704,7 +1704,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.getParameter(0).setComment("New my comment.");
}
catch (Exception e) {
@@ -1718,7 +1718,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(LATEST_BUTTON);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
assertEquals(0, func.getParameterCount());
assertSameDataType(new ByteDataType(), func.getReturnType());
}
@@ -1732,7 +1732,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1748,7 +1748,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
}
catch (Exception e) {
@@ -1761,7 +1761,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.getParameter(0).setComment("New my comment.");
}
catch (Exception e) {
@@ -1775,7 +1775,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(MY_BUTTON);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
assertEquals(1, func.getParameterCount());
Parameter parameter = func.getParameter(0);
assertSameDataType(new DWordDataType(), parameter.getDataType());
@@ -1793,7 +1793,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -1809,7 +1809,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
}
catch (Exception e) {
@@ -1822,7 +1822,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.getParameter(0).setName("NewMyName", SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1836,7 +1836,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(LATEST_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
assertEquals(0, func.getParameterCount());
}
@@ -1850,7 +1850,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -1866,7 +1866,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
}
catch (Exception e) {
@@ -1879,7 +1879,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.getParameter(0).setName("NewMyName", SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1893,7 +1893,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(CHECKED_OUT_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter parm = func.getParameter(0);
assertEquals("NewMyName", parm.getName());
}
@@ -1907,7 +1907,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -1917,7 +1917,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
addParameter(orangesFunction, "A2", SourceType.USER_DEFINED,
@@ -1932,13 +1932,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNotNull(func);
Parameter parameter0 = func.getParameter(0);
assertNotNull(parameter0);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
Parameter parameter1 = func.getParameter(1);
parameter1.setName("NewLatestName", SourceType.USER_DEFINED);
}
@@ -1952,13 +1952,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
assertNotNull(func);
Parameter parameter0 = func.getParameter(0);
assertNotNull(parameter0);
parameter0.setName("NewMyName", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
Parameter parameter1 = func.getParameter(1);
assertNotNull(parameter1);
func.removeParameter(1);
@@ -1979,7 +1979,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Register r12Reg = context.getRegister("r12");
Register r11Reg = context.getRegister("r11");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("NewMyName", parameters[0].getName());
@@ -1991,7 +1991,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2010,7 +2010,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2018,7 +2018,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addStackParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
addStackParameter(orangesFunction, "A2", SourceType.USER_DEFINED,
@@ -2037,13 +2037,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
AddRegisterParameterCommand cmd;
Register regR5 = program.getProgramContext().getRegister("r5");
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR5, null,
new Undefined4DataType(), 1, SourceType.USER_DEFINED);
cmd.applyTo(program);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
param0 = func.getParameter(0);
assertNotNull(param0);
@@ -2063,13 +2063,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
AddRegisterParameterCommand cmd;
Register regR6 = program.getProgramContext().getRegister("r6");
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
param0 = func.getParameter(0);
assertNotNull(param0);
param0.setName("NewParamName1", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR6, null,
new Undefined4DataType(), 1, SourceType.USER_DEFINED);
@@ -2092,7 +2092,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Register r11Reg = context.getRegister("r11");
Register r6Reg = context.getRegister("r6");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("NewParamName1", parameters[0].getName());
@@ -2101,7 +2101,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(3, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2126,7 +2126,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2134,7 +2134,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
assertNotNull(orangesFunction);
parameter1 = new ParameterImpl("A1", new DWordDataType(), program);
parameter1.setComment("Test Parameter Comment");
@@ -2153,13 +2153,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Register regR1 = program.getProgramContext().getRegister("r1");
Register regR3 = program.getProgramContext().getRegister("r3");
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR1, "Latest_1",
new FloatDataType(), 1, SourceType.USER_DEFINED);
cmd.applyTo(program);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR3, "Latest_3",
new FloatDataType(), 1, SourceType.USER_DEFINED);
@@ -2179,13 +2179,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Register regR4 = program.getProgramContext().getRegister("r4");
Register regR6 = program.getProgramContext().getRegister("r6");
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR4, "My_4",
new Undefined4DataType(), 1, SourceType.USER_DEFINED);
cmd.applyTo(program);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
cmd = new AddRegisterParameterCommand(func, regR6, "My_6",
new Undefined4DataType(), 1, SourceType.USER_DEFINED);
@@ -2208,7 +2208,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Register r4Reg = context.getRegister("r4");
Register r3Reg = context.getRegister("r3");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("P1", parameters[0].getName());
@@ -2220,7 +2220,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2242,21 +2242,21 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
addParameter(orangesFunction, "A2", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
Function pearsFunction =
- createExternalFunction(program, new String[] { "user32.dll", "pears" });
+ createExternalFunction(program, "user32.dll", new String[] { "pears" });
addParameter(pearsFunction, "B1", SourceType.USER_DEFINED, new DWordDataType(),
"Test B1");
addParameter(pearsFunction, "B2", SourceType.USER_DEFINED, new DWordDataType(),
@@ -2271,10 +2271,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.removeParameter(1);
}
catch (Exception e) {
@@ -2287,10 +2287,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "pears" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "pears" });
func.removeParameter(0);
}
catch (Exception e) {
@@ -2306,13 +2306,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
ProgramContext context = resultProgram.getProgramContext();
Register r12Reg = context.getRegister("r12");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(0, parameters.length);
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2321,7 +2321,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "pears" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "pears" });
parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("B2", parameters[0].getName());
@@ -2334,7 +2334,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
/**
* Remove a register parameter vs change the register on a register parameter.
*
- * @throws Exception
+ * @throws Exception if exception occurs
*/
@Test
public void testRemoveVsChangeRegParam() throws Exception {
@@ -2345,7 +2345,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2353,7 +2353,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test A1 Comment");
}
@@ -2367,11 +2367,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
ProgramContext context = program.getProgramContext();
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
changeToRegisterParameter(func, 0, context.getRegister("r2"));
}
@@ -2386,11 +2386,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
ProgramContext context = program.getProgramContext();
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
changeToRegisterParameter(func, 0, context.getRegister("r3"));
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
}
@@ -2409,7 +2409,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
ProgramContext context = resultProgram.getProgramContext();
Register r3Reg = context.getRegister("r3");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("P1", parameters[0].getName());
@@ -2418,7 +2418,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(0, parameters.length);
localVariables = func.getLocalVariables();
@@ -2440,7 +2440,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2448,7 +2448,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test A1 Comment");
}
@@ -2461,11 +2461,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.getParameter(0).setName("X1", SourceType.USER_DEFINED);
}
@@ -2479,11 +2479,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.getParameter(0).setName("Y1", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
}
@@ -2499,7 +2499,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(CHECKED_OUT_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("Y1", parameters[0].getName());
@@ -2508,7 +2508,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(0, parameters.length);
localVariables = func.getLocalVariables();
@@ -2530,7 +2530,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2538,7 +2538,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test A1 Comment");
}
@@ -2551,11 +2551,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.getParameter(0).setDataType(new FloatDataType(), SourceType.USER_DEFINED);
}
@@ -2569,11 +2569,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.getParameter(0).setDataType(new FloatDataType(), SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
}
@@ -2589,7 +2589,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(CHECKED_OUT_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("P1", parameters[0].getName());
@@ -2598,7 +2598,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(0, parameters.length);
localVariables = func.getLocalVariables();
@@ -2620,7 +2620,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2628,7 +2628,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test A1 Comment");
}
@@ -2641,11 +2641,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.getParameter(0).setComment("LATEST Comment");
}
@@ -2659,11 +2659,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.getParameter(0).setComment("MY Comment");
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
}
@@ -2679,7 +2679,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(CHECKED_OUT_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("P1", parameters[0].getName());
@@ -2689,7 +2689,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(0, parameters.length);
localVariables = func.getLocalVariables();
@@ -2710,7 +2710,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2718,7 +2718,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
assertNotNull(orangesFunction);
parameter1 = new ParameterImpl("A1", new DWordDataType(), program);
parameter1.setComment("Test A1 Comment");
@@ -2733,11 +2733,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
changeToStackParameter(func, 0, 0x8);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
}
@@ -2751,11 +2751,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
func.removeParameter(0);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
changeToStackParameter(func, 0, 0x8);
}
@@ -2771,13 +2771,13 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseRadioButton(CHECKED_OUT_BUTTON_NAME);
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(0, parameters.length);
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2796,7 +2796,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2804,7 +2804,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
orangesFunction.setCustomVariableStorage(true);
addStackParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), 4, "Test Parameter Comment");
@@ -2821,11 +2821,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
parameters[0].setName("Foo", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
parameters[1].setComment("This is a different test comment.");
}
@@ -2840,11 +2840,11 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
try {
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
parameters[0].setName("Foo", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
parameters[1].setDataType(new IntegerDataType(), SourceType.USER_DEFINED);
}
@@ -2861,7 +2861,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
ProgramContext context = resultProgram.getProgramContext();
Register r12Reg = context.getRegister("r12");
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("Foo", parameters[0].getName());
@@ -2870,7 +2870,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -2892,7 +2892,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -2900,28 +2900,28 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll", new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
addParameter(orangesFunction, "A2", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
Function pearsFunction =
- createExternalFunction(program, new String[] { "user32.dll", "pears" });
+ createExternalFunction(program, "user32.dll", new String[] { "pears" });
addParameter(pearsFunction, "B1", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
addParameter(pearsFunction, "B2", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
Function grapesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "grapes" });
+ createExternalFunction(program, "user32.dll", new String[] { "grapes" });
addParameter(grapesFunction, "C1", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
addParameter(grapesFunction, "C2", SourceType.USER_DEFINED, new DWordDataType(),
"Test Parameter Comment");
Function berriesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "berries" });
+ createExternalFunction(program, "user32.dll", new String[] { "berries" });
addParameter(berriesFunction, "D1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
addParameter(berriesFunction, "D2", SourceType.USER_DEFINED,
@@ -2938,21 +2938,21 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
ProgramContext context = program.getProgramContext();
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
changeToRegisterParameter(func, 0, context.getRegister("R1"));
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
changeToStackParameter(func, 1, 0x4);
- func = getExternalFunction(program, new String[] { "user32.dll", "pears" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "pears" });
func.getParameter(0).setName("LatestName_0", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "grapes" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "grapes" });
func.getParameter(1).setDataType(new WordDataType(), SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "berries" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "berries" });
func.getParameter(0).setComment("test comment.");
}
catch (Exception e) {
@@ -2967,23 +2967,23 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
ProgramContext context = program.getProgramContext();
Function func;
- func = getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setCustomVariableStorage(true);
changeToStackParameter(func, 0, 0x4);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setCustomVariableStorage(true);
changeToRegisterParameter(func, 1, context.getRegister("r2"));
- func = getExternalFunction(program, new String[] { "user32.dll", "pears" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "pears" });
func.getParameter(0).setName("NewName_0", SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "grapes" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "grapes" });
func.getParameter(1)
.setDataType(new ArrayDataType(new ByteDataType(), 2, 1),
SourceType.USER_DEFINED);
- func = getExternalFunction(program, new String[] { "user32.dll", "berries" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "berries" });
func.getParameter(0).setComment("My sample comment.");
}
catch (Exception e) {
@@ -3001,7 +3001,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
chooseVariousOptions(new int[] { INFO_ROW, KEEP_MY });// Comment change for user32.dll::berries
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter[] parameters = func.getParameters();
assertEquals(1, parameters.length);
assertEquals("P1", parameters[0].getName());
@@ -3010,7 +3010,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
Variable[] localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("A1", parameters[0].getName());
@@ -3022,7 +3022,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "pears" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "pears" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("NewName_0", parameters[0].getName());
@@ -3034,7 +3034,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "grapes" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "grapes" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("C1", parameters[0].getName());
@@ -3047,7 +3047,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
localVariables = func.getLocalVariables();
assertEquals(0, localVariables.length);
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "berries" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "berries" });
parameters = func.getParameters();
assertEquals(2, parameters.length);
assertEquals("D1", parameters[0].getName());
@@ -3070,7 +3070,7 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyOriginal(ProgramDB program) {
try {
Function applesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "apples" },
+ createExternalFunction(program, "user32.dll", new String[] { "apples" },
addr(program, "77db1020"), new ByteDataType(), SourceType.USER_DEFINED);
assertNotNull(applesFunction);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), program);
@@ -3078,7 +3078,8 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
applesFunction.addParameter(parameter1, SourceType.USER_DEFINED);
Function orangesFunction =
- createExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ createExternalFunction(program, "user32.dll",
+ new String[] { "oranges" });
addParameter(orangesFunction, "A1", SourceType.USER_DEFINED,
new DWordDataType(), "Test Parameter Comment");
addParameter(orangesFunction, "A2", SourceType.USER_DEFINED,
@@ -3093,10 +3094,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyLatest(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setStackPurgeSize(5);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setStackPurgeSize(3);
}
catch (Exception e) {
@@ -3108,10 +3109,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
public void modifyPrivate(ProgramDB program) {
try {
Function func =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
func.setStackPurgeSize(8);
- func = getExternalFunction(program, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(program, "user32.dll", new String[] { "oranges" });
func.setStackPurgeSize(2);
}
catch (Exception e) {
@@ -3127,10 +3128,10 @@ public class ExternalFunctionMergeManagerTest extends AbstractExternalMergerTest
new int[] { INFO_ROW, KEEP_MY });
waitForMergeCompletion();
- Function func = getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ Function func = getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
assertEquals(5, func.getStackPurgeSize());
- func = getExternalFunction(resultProgram, new String[] { "user32.dll", "oranges" });
+ func = getExternalFunction(resultProgram, "user32.dll", new String[] { "oranges" });
assertEquals(2, func.getStackPurgeSize());
}
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger1Test.java
index 61b521ca1e..77cd3f7dd2 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger1Test.java
@@ -17,10 +17,14 @@ package ghidra.app.merge.listing;
import static org.junit.Assert.*;
+import java.util.Iterator;
+import java.util.Set;
+
import org.junit.Assert;
import org.junit.Test;
import ghidra.program.database.*;
+import ghidra.program.database.references.ReferenceDBManager;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
@@ -64,10 +68,6 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
protected static final Reference ExternalReference = null;
- /**
- *
- * @param arg0
- */
public ExternalFunctionMerger1Test() {
super();
}
@@ -103,7 +103,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
ExternalManager externalManager = program.getExternalManager();
ExternalLocation externalLocation = externalManager.addExtFunction(
externalLibrary, "mangled", addr(program, "77db1020"), SourceType.IMPORTED);
- externalLocation.setName(externalLibrary, "apples", SourceType.USER_DEFINED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+ externalLocation.setLibrary(externalLibrary);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -114,12 +115,12 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
// Symbol mangled = getUniqueSymbol(resultProgram, "mangled", externalLibrary);
// assertNotNull(mangled);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertNotNull(apples);
ExternalLocation externalLocation =
resultProgram.getExternalManager().getExternalLocation(apples);
@@ -140,7 +141,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
ExternalManager externalManager = program.getExternalManager();
ExternalLocation externalLocation = externalManager.addExtFunction(
externalLibrary, "mangled", addr(program, "77db1020"), SourceType.IMPORTED);
- externalLocation.setName(externalLibrary, "apples", SourceType.USER_DEFINED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+ externalLocation.setLibrary(externalLibrary);
}
catch (Exception e) {
@@ -168,11 +170,11 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertNotNull(apples);
ExternalLocation externalLocation =
resultProgram.getExternalManager().getExternalLocation(apples);
@@ -180,7 +182,68 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
}
@Test
- public void testAddDifferentNamedExternalFunctionInBothDemangleBoth() throws Exception {
+ public void testExternalFunctionAddDiffAddrConflictPickMy() throws Exception {
+ mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
+
+ @Override
+ public void modifyLatest(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1020"), SourceType.IMPORTED);
+
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void modifyPrivate(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.IMPORTED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1022"), SourceType.IMPORTED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+ });
+
+ executeMerge(ASK_USER);
+ chooseButtonAndApply("Resolve External Add Conflict",
+ ExternalFunctionMerger.CHECKED_OUT_BUTTON_NAME);
+
+ waitForMergeCompletion();
+
+ SymbolTable symbolTable = resultProgram.getSymbolTable();
+ Library externalLibrary =
+ (Library) symbolTable.getLibrarySymbol("user32.dll").getObject();
+ assertNotNull(externalLibrary);
+
+ Set<ExternalLocation> extLocations =
+ resultProgram.getExternalManager().getExternalLocations("user32.dll", "apples");
+ assertEquals(1, extLocations.size());
+
+ ExternalLocation extLoc = extLocations.iterator().next();
+
+ assertEquals("mangled1", extLoc.getOriginalImportedName());
+ assertEquals(addr("77db1022"), extLoc.getAddress());
+ }
+
+ @Test
+ public void testExternalFunctionAddDiffAddrConflictPickLatest() throws Exception {
mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
@Override
@@ -194,7 +257,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
ExternalLocation externalLocation =
externalManager.addExtFunction(externalLibrary, "mangled1",
addr(program, "77db1020"), SourceType.IMPORTED);
- externalLocation.setName(externalLibrary, "apples", SourceType.USER_DEFINED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -209,11 +272,70 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Library externalLibrary =
symbolTable.createExternalLibrary("user32.dll", SourceType.IMPORTED);
+ ExternalManager externalManager = program.getExternalManager();
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1022"), SourceType.IMPORTED);
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+ });
+
+ executeMerge(ASK_USER);
+ chooseButtonAndApply("Resolve External Add Conflict",
+ ExternalFunctionMerger.LATEST_BUTTON_NAME);
+
+ waitForMergeCompletion();
+
+ SymbolTable symbolTable = resultProgram.getSymbolTable();
+ Library externalLibrary =
+ (Library) symbolTable.getLibrarySymbol("user32.dll").getObject();
+ assertNotNull(externalLibrary);
+
+ Set<ExternalLocation> extLocations =
+ resultProgram.getExternalManager().getExternalLocations("user32.dll", "apples");
+ assertEquals(1, extLocations.size());
+
+ ExternalLocation extLoc = extLocations.iterator().next();
+
+ assertEquals("mangled1", extLoc.getOriginalImportedName());
+ assertEquals(addr("77db1020"), extLoc.getAddress());
+ }
+
+ @Test
+ public void testExternalFunctionAddDiffAddrConflictPickBoth() throws Exception {
+ mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
+
+ @Override
+ public void modifyLatest(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
+
ExternalManager externalManager = program.getExternalManager();
ExternalLocation externalLocation =
- externalManager.addExtFunction(externalLibrary, "mangled2",
+ externalManager.addExtFunction(externalLibrary, "mangled1",
addr(program, "77db1020"), SourceType.IMPORTED);
- externalLocation.setName(externalLibrary, "oranges", SourceType.USER_DEFINED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void modifyPrivate(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.IMPORTED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1022"), SourceType.IMPORTED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -227,41 +349,200 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ SymbolTable symbolTable = resultProgram.getSymbolTable();
+ Library externalLibrary =
+ (Library) symbolTable.getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ ExternalManager extMgr = resultProgram.getExternalManager();
+ Set<ExternalLocation> extLocations =
+ extMgr.getExternalLocations("user32.dll", "mangled1");
+ assertEquals(2, extLocations.size());
+
+ Iterator<ExternalLocation> extLocIt = extLocations.iterator();
+ ExternalLocation extLoc = extLocIt.next();
+
+ assertEquals("apples", extLoc.getLabel());
+ assertEquals("mangled1", extLoc.getOriginalImportedName());
+ assertEquals(addr("77db1020"), extLoc.getAddress());
+
+ extLoc = extLocIt.next();
+
+ assertEquals("mangled1", extLoc.getLabel());
+ assertNull(extLoc.getOriginalImportedName());
+ assertEquals(addr("77db1022"), extLoc.getAddress());
+ }
+
+ @Test
+ public void testAddExternalFunctionOneDemangled() throws Exception {
+ mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
+
+ @Override
+ public void modifyLatest(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1020"), SourceType.IMPORTED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+ externalManager.addExtFunction(externalLibrary, "mangled2",
+ addr(program, "77db1022"), SourceType.IMPORTED);
+
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void modifyPrivate(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.IMPORTED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1020"), SourceType.IMPORTED);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(externalLibrary, "mangled2",
+ addr(program, "77db1022"), SourceType.IMPORTED);
+ externalLocation.setName(null, "oranges", SourceType.ANALYSIS);
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+ });
+
+ executeMerge(ASK_USER); // no conflict expected
+
+ waitForMergeCompletion();
+
+ SymbolTable symbolTable = resultProgram.getSymbolTable();
+ Library externalLibrary =
+ (Library) symbolTable.getLibrarySymbol("user32.dll").getObject();
+ assertNotNull(externalLibrary);
+
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertNotNull(apples);
- Symbol oranges = getUniqueSymbol(resultProgram, "oranges", externalLibrary);
+ Symbol oranges = getUniqueSymbol(resultProgram, "oranges", null);
assertNotNull(oranges);
ExternalLocation externalLoc1 =
resultProgram.getExternalManager().getExternalLocation(apples);
assertEquals("mangled1", externalLoc1.getOriginalImportedName());
+ assertEquals(addr("77db1020"), externalLoc1.getAddress());
ExternalLocation externalLoc2 =
resultProgram.getExternalManager().getExternalLocation(oranges);
assertEquals("mangled2", externalLoc2.getOriginalImportedName());
+ assertEquals(addr("77db1022"), externalLoc2.getAddress());
}
@Test
- public void testAddDiffExternalFunctionChooseLatest() throws Exception {
+ public void testAddExternalFunctionOneHasAddressOnly() throws Exception {
mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
+ private ReferenceDBManager refManager;
+
@Override
public void modifyLatest(ProgramDB program) {
try {
SymbolTable symbolTable = program.getSymbolTable();
Library externalLibrary =
symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
- Namespace myNamespace = symbolTable.createNameSpace(externalLibrary,
+
+ ExternalManager externalManager = program.getExternalManager();
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(externalLibrary, "mangled1",
+ addr(program, "77db1020"), SourceType.IMPORTED);
+ externalLocation.setName(null, "apples", SourceType.USER_DEFINED);
+ externalManager.addExtFunction(externalLibrary, null,
+ addr(program, "77db1022"), SourceType.IMPORTED);
+
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void modifyPrivate(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library externalLibrary =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.IMPORTED);
+
+ ExternalManager externalManager = program.getExternalManager();
+ ExternalLocation externalLocation1 =
+ externalManager.addExtFunction(externalLibrary, null,
+ addr(program, "77db1020"), SourceType.IMPORTED);
+ ExternalLocation externalLocation2 =
+ externalManager.addExtFunction(externalLibrary, "mangled2",
+ addr(program, "77db1022"), SourceType.IMPORTED);
+ externalLocation2.setName(null, "oranges", SourceType.ANALYSIS);
+
+ refManager = program.getReferenceManager();
+ refManager.addExternalReference(addr(program, "0x1234"), 0, externalLocation1,
+ SourceType.USER_DEFINED, RefType.DATA);
+ refManager.addExternalReference(addr(program, "0x2345"), 0, externalLocation2,
+ SourceType.USER_DEFINED, RefType.DATA);
+
+ }
+ catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+ });
+
+ executeMerge(ASK_USER); // no conflict expected
+
+ waitForMergeCompletion();
+
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ assertNotNull(externalLibrary);
+
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
+ assertNotNull(apples);
+
+ Symbol oranges = getUniqueSymbol(resultProgram, "oranges", null);
+ assertNotNull(oranges);
+
+ ExternalLocation externalLoc1 =
+ resultProgram.getExternalManager().getExternalLocation(apples);
+ assertEquals("mangled1", externalLoc1.getOriginalImportedName());
+ assertEquals(addr("77db1020"), externalLoc1.getAddress());
+
+ ExternalLocation externalLoc2 =
+ resultProgram.getExternalManager().getExternalLocation(oranges);
+ assertEquals("mangled2", externalLoc2.getOriginalImportedName());
+ assertEquals(addr("77db1022"), externalLoc2.getAddress());
+ }
+
+ @Test
+ public void testAddDiffExternalFunctionChooseLatest() throws Exception {
+ mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
+
+ @Override
+ public void modifyLatest(ProgramDB program) {
+ try {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Library library =
+ symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
+ Namespace myNamespace = symbolTable.createNameSpace(null,
"MyNamespace", SourceType.USER_DEFINED);
ExternalManager externalManager = program.getExternalManager();
- ExternalLocation externalLocation = externalManager.addExtFunction(myNamespace,
- "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(library, myNamespace,
+ "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -278,14 +559,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
public void modifyPrivate(ProgramDB program) {
try {
SymbolTable symbolTable = program.getSymbolTable();
- Library externalLibrary =
+ Library library =
symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
- Namespace myNamespace = symbolTable.createNameSpace(externalLibrary,
+ Namespace myNamespace = symbolTable.createNameSpace(null,
"MyNamespace", SourceType.USER_DEFINED);
ExternalManager externalManager = program.getExternalManager();
- ExternalLocation externalLocation = externalManager.addExtFunction(myNamespace,
- "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(library, myNamespace,
+ "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -303,11 +585,11 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", externalLibrary).getObject();
+ (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, "apples", myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, "apples_conflict1", myNamespace);
@@ -325,15 +607,16 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionChangeVsRemoveConflict() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.ll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -343,7 +626,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
parameter2.setComment("Other Comment");
applesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -354,11 +637,11 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setComment("Once upon a time...");
applesFunction.setNoReturn(true);
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -368,14 +651,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
assertEquals(2, applesFunction.getParameterCount());
assertEquals("Once upon a time...", applesFunction.getComment());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -386,19 +670,20 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.getSymbol().delete();// Remove the function, but not the external location.
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.getSymbol().delete();// Remove the function, but not the external location.
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertEquals(false, applesLocation.isFunction());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(false, orangesLocation.isFunction());
}
@@ -409,7 +694,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton(MY_BUTTON);
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -427,21 +712,22 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
assertEquals("P2", parameter2.getName());
assertEquals(8, parameter2.getStackOffset());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(false, orangesLocation.isFunction());
}
@Test
public void testExternalFunctionChangeParameterDetailsConflictPickLatest() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -459,7 +745,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setComment("Once upon a time...");
}
@@ -467,7 +753,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -479,7 +765,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setComment("This is a sample parameter comment.");
}
@@ -487,7 +773,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -503,7 +789,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST });
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -524,14 +810,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionChangeParameterDetailsConflictPickMy() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -549,7 +836,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setComment("Once upon a time...");
}
@@ -557,7 +844,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -569,7 +856,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setComment("This is a sample parameter comment.");
}
@@ -577,7 +864,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -593,7 +880,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY });
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -614,14 +901,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddDiffParameterConflictPickLatest() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -632,7 +920,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -642,7 +930,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -653,7 +942,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("value",
new PointerDataType(new ByteDataType()), 4, program);
parameter1.setComment("Four score and seven years ago...");
@@ -663,7 +952,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -679,7 +969,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST, KEEP_LATEST, KEEP_LATEST });
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -695,14 +985,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddDiffParameterConflictPickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -713,7 +1004,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -723,7 +1014,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -734,7 +1026,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("value",
new PointerDataType(new ByteDataType()), 4, program);
parameter1.setComment("Four score and seven years ago...");
@@ -744,7 +1036,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -760,7 +1053,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY, KEEP_LATEST, KEEP_MY });
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -776,14 +1069,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddDiffParameterDetailsConflictPickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -794,7 +1088,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -804,7 +1098,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -815,7 +1110,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("value", new ByteDataType(), 4, program);
parameter1.setComment("Four score and seven years ago...");
@@ -825,7 +1120,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -841,7 +1137,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY, KEEP_MY });// Name, comment
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -857,14 +1153,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddDiffRegParameterSigConflictPickLatest() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -875,7 +1172,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -890,7 +1187,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -900,7 +1198,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -915,7 +1213,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -927,7 +1226,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -947,14 +1246,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddDiffRegParameterSigConflictPickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -965,7 +1265,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -980,7 +1280,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -990,7 +1291,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1005,7 +1306,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1017,7 +1319,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", MY_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1037,14 +1339,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionChangeNonVsCustomStorageConflictPickLatest() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1055,7 +1358,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1070,7 +1373,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1080,7 +1384,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
new VariableStorage(program, program.getRegister("r0l")), program);
@@ -1094,7 +1398,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1106,7 +1411,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1126,14 +1431,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionChangeNonVsCustomStorageConflictPickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1144,7 +1450,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1159,7 +1465,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1169,7 +1476,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
new VariableStorage(program, program.getRegister("r0l")), program);
@@ -1183,7 +1490,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1195,7 +1503,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", MY_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1213,14 +1521,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddSameStackParamsNoConflict() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1231,7 +1540,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
new VariableStorage(program, program.getRegister("r0l")), program);
@@ -1245,7 +1554,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1255,7 +1565,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
new VariableStorage(program, program.getRegister("r0l")), program);
@@ -1269,7 +1579,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1280,7 +1591,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1298,14 +1609,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddNonVsCustomStoragePickLatest() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1316,7 +1628,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1331,7 +1643,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1341,7 +1654,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1356,7 +1669,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1368,7 +1682,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1386,14 +1700,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddNonVsCustomStoragePickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1404,7 +1719,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1419,7 +1734,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1429,7 +1745,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1444,7 +1760,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1456,7 +1773,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", MY_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1477,14 +1794,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddNonVsCustomStorage() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest_X86", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1496,7 +1814,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
AddressSpace stackSpace = program.getAddressFactory().getStackSpace();
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1511,7 +1829,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1522,7 +1841,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
public void modifyPrivate(ProgramDB program) {
AddressSpace stackSpace = program.getAddressFactory().getStackSpace();
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1537,7 +1856,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1548,7 +1868,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1570,14 +1890,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionAddSameCustomParamsNoConflict() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1588,7 +1909,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1603,7 +1924,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1613,7 +1935,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1628,7 +1950,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1639,7 +1962,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1659,14 +1982,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionDynamicVsCustomStorageChangePickLatest() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest_X86", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function fun = createExternalFunction(program, orangesPath,
+ Function fun = createExternalFunction(program, library, orangesPath,
addr(program, "00cc5566"), new DWordDataType(), SourceType.USER_DEFINED);
fun.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1681,14 +2005,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1698,7 +2023,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter = orangesFunction.getParameter(0);
parameter.setDataType(new WordDataType(),
new VariableStorage(program, program.getRegister("BX")), true,
@@ -1708,7 +2033,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1720,7 +2046,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1736,14 +2062,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionDynamicVsCustomStorageChangePickMy() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest_X86", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function fun = createExternalFunction(program, orangesPath,
+ Function fun = createExternalFunction(program, library, orangesPath,
addr(program, "00cc5566"), new DWordDataType(), SourceType.USER_DEFINED);
fun.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -1758,14 +2085,15 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1775,7 +2103,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter = orangesFunction.getParameter(0);
parameter.setDataType(new WordDataType(),
new VariableStorage(program, program.getRegister("BX")), true,
@@ -1785,7 +2113,8 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1797,7 +2126,7 @@ public class ExternalFunctionMerger1Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Parameters Conflict", MY_BUTTON);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger2Test.java
index 7d7c37aa4c..1c592c58c9 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalFunctionMerger2Test.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -101,11 +101,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
-
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples");
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -121,11 +117,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -142,10 +138,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -187,11 +183,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -209,11 +205,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -234,10 +230,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST, KEEP_MY, KEEP_LATEST });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -279,11 +275,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -300,11 +296,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -324,10 +320,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -369,11 +365,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -390,11 +386,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -414,10 +410,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY, KEEP_LATEST });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -460,11 +456,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -482,11 +478,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -508,10 +504,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST, KEEP_MY, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -554,11 +550,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -576,11 +572,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -602,10 +598,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY, KEEP_LATEST, KEEP_LATEST });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -647,11 +643,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
-
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
+//
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -669,11 +665,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -694,10 +690,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY, KEEP_MY, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -771,14 +767,16 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformLabelIntoFunctionNoConflict() throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
+ String library = "user32.dll";
+ String[] grapesPath = new String[] { "Fruit", "grapes" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -788,7 +786,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
parameter1.setComment("Test Parameter Comment");
@@ -802,7 +801,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
parameter1.setComment("Test Parameter Comment");
@@ -817,7 +817,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Function function = getExternalFunction(resultProgram, grapesPath);
+ Function function = getExternalFunction(resultProgram, library, grapesPath);
checkDataType(DataType.DEFAULT, function.getReturnType());
assertEquals(1, function.getParameterCount());
Parameter parameter1 = function.getParameter(0);
@@ -829,7 +829,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformFunctionIntoLabelIntoFunctionNoConflict() throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
+ String library = "user32.dll";
+ String[] grapesPath = new String[] { "Fruit", "grapes" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@@ -837,7 +838,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
ExternalLocation externalLocation =
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
Function function = externalLocation.createFunction();
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
parameter1.setComment("Test Parameter Comment");
@@ -851,10 +853,12 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.getSymbol().delete();
externalLocation =
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
externalLocation.setDataType(ByteDataType.dataType);
}
catch (Exception e) {
@@ -865,10 +869,12 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.getSymbol().delete();
externalLocation =
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
externalLocation.setDataType(ByteDataType.dataType);
}
catch (Exception e) {
@@ -880,7 +886,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation externalLocation = getExternalLocation(resultProgram, grapesPath);
+ ExternalLocation externalLocation = getExternalLocation(resultProgram, library, grapesPath);
assertTrue("Did not find external label location",
externalLocation != null && !externalLocation.isFunction());
checkDataType(ByteDataType.dataType, externalLocation.getDataType());
@@ -888,15 +894,17 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformLabelIntoFunctionVsLabelNameChangeNoConflict() throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
- final String[] countPath = new String[] { "user32.dll", "Fruit", "count" };
+ String library = "user32.dll";
+ final String[] grapesPath = new String[] { "Fruit", "grapes" };
+ final String[] countPath = new String[] { "Fruit", "count" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -906,7 +914,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
parameter1.setComment("Test Parameter Comment");
@@ -920,7 +929,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.setLocation("count", externalLocation.getAddress(),
SourceType.ANALYSIS);
}
@@ -933,9 +943,9 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation grapesLocation = getExternalLocation(resultProgram, grapesPath);
+ ExternalLocation grapesLocation = getExternalLocation(resultProgram, library, grapesPath);
assertNull(grapesLocation);
- Function function = getExternalFunction(resultProgram, countPath);
+ Function function = getExternalFunction(resultProgram, library, countPath);
checkDataType(DataType.DEFAULT, function.getReturnType());
assertEquals(1, function.getParameterCount());
Parameter parameter1 = function.getParameter(0);
@@ -947,16 +957,18 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformLabelIntoFunctionNoAddressVsLabelNameConflict() throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
- final String[] berriesPath = new String[] { "user32.dll", "Fruit", "berries" };
- final String[] countPath = new String[] { "user32.dll", "Fruit", "count" };
+ String library = "user32.dll";
+ String[] grapesPath = new String[] { "Fruit", "grapes" };
+ String[] berriesPath = new String[] { "Fruit", "berries" };
+ String[] countPath = new String[] { "Fruit", "count" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, grapesPath, null, SourceType.USER_DEFINED);
+ createExternalLabel(program, library, grapesPath, null,
+ SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -966,7 +978,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
function.setName("berries", SourceType.USER_DEFINED);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -981,7 +994,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.setLocation("count", externalLocation.getAddress(),
SourceType.ANALYSIS);
}
@@ -995,11 +1009,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve External Remove Conflict", MY_BUTTON);// Keep count vs remove.
waitForMergeCompletion();
- ExternalLocation grapesLocation = getExternalLocation(resultProgram, grapesPath);
+ ExternalLocation grapesLocation = getExternalLocation(resultProgram, library, grapesPath);
assertNull(grapesLocation);
- ExternalLocation berriesLocation = getExternalLocation(resultProgram, berriesPath);
+ ExternalLocation berriesLocation = getExternalLocation(resultProgram, library, berriesPath);
assertNotNull(berriesLocation);
- ExternalLocation countLocation = getExternalLocation(resultProgram, countPath);
+ ExternalLocation countLocation = getExternalLocation(resultProgram, library, countPath);
assertNotNull(countLocation);
Function berriesFunction = berriesLocation.getFunction();
assertNotNull(berriesLocation.getFunction());
@@ -1016,16 +1030,17 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformLabelIntoFunctionWithAddressVsLabelNameConflictPickLatest()
throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
- final String[] berriesPath = new String[] { "user32.dll", "Fruit", "berries" };
- final String[] countPath = new String[] { "user32.dll", "Fruit", "count" };
+ String library = "user32.dll";
+ String[] grapesPath = new String[] { "Fruit", "grapes" };
+ String[] berriesPath = new String[] { "Fruit", "berries" };
+ String[] countPath = new String[] { "Fruit", "count" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, grapesPath, addr(program, "77db4321"),
+ createExternalLabel(program, library, grapesPath, addr(program, "77db4321"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1036,7 +1051,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
function.setName("berries", SourceType.USER_DEFINED);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1051,7 +1067,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.setLocation("count", externalLocation.getAddress(),
SourceType.ANALYSIS);
}
@@ -1066,11 +1083,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_LATEST });// Name Conflict
waitForMergeCompletion();
- ExternalLocation grapesLocation = getExternalLocation(resultProgram, grapesPath);
+ ExternalLocation grapesLocation = getExternalLocation(resultProgram, library, grapesPath);
assertNull(grapesLocation);
- ExternalLocation berriesLocation = getExternalLocation(resultProgram, berriesPath);
+ ExternalLocation berriesLocation = getExternalLocation(resultProgram, library, berriesPath);
assertNotNull(berriesLocation);
- ExternalLocation countLocation = getExternalLocation(resultProgram, countPath);
+ ExternalLocation countLocation = getExternalLocation(resultProgram, library, countPath);
assertNull(countLocation);
Function berriesFunction = berriesLocation.getFunction();
assertNotNull(berriesLocation.getFunction());
@@ -1086,16 +1103,17 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testTransformLabelIntoFunctionWithAddressVsLabelNameConflictPickMy()
throws Exception {
- final String[] grapesPath = new String[] { "user32.dll", "Fruit", "grapes" };
- final String[] berriesPath = new String[] { "user32.dll", "Fruit", "berries" };
- final String[] countPath = new String[] { "user32.dll", "Fruit", "count" };
+ String library = "user32.dll";
+ String[] grapesPath = new String[] { "Fruit", "grapes" };
+ String[] berriesPath = new String[] { "Fruit", "berries" };
+ String[] countPath = new String[] { "Fruit", "count" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, grapesPath, addr(program, "77db4321"),
+ createExternalLabel(program, library, grapesPath, addr(program, "77db4321"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1106,7 +1124,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ // Function transformation is produces a delete and an add change
+ // Merge requires special logic which matches on the address to
+ // identify a match in the absence of a name match.
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
Function function = externalLocation.createFunction();
function.setName("berries", SourceType.USER_DEFINED);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1121,7 +1143,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- ExternalLocation externalLocation = getExternalLocation(program, grapesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, grapesPath);
externalLocation.setLocation("count", externalLocation.getAddress(),
SourceType.ANALYSIS);
}
@@ -1136,11 +1159,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
new int[] { INFO_ROW, KEEP_MY });// Name Conflict
waitForMergeCompletion();
- ExternalLocation grapesLocation = getExternalLocation(resultProgram, grapesPath);
+ ExternalLocation grapesLocation = getExternalLocation(resultProgram, library, grapesPath);
assertNull(grapesLocation);
- ExternalLocation berriesLocation = getExternalLocation(resultProgram, berriesPath);
+ ExternalLocation berriesLocation = getExternalLocation(resultProgram, library, berriesPath);
assertNull(berriesLocation);
- ExternalLocation countLocation = getExternalLocation(resultProgram, countPath);
+ ExternalLocation countLocation = getExternalLocation(resultProgram, library, countPath);
assertNotNull(countLocation);
Function countFunction = countLocation.getFunction();
assertNotNull(countLocation.getFunction());
@@ -1180,11 +1203,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -1200,7 +1223,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
Function function1 =
- getExternalFunction(program, new String[] { "user32.dll", "apples" });
+ getExternalFunction(program, "user32.dll", new String[] { "apples" });
Parameter p1 = function1.getParameter(0);
Parameter p2 = function1.getParameter(1);
assertEquals("Test Parameter Comment", p1.getComment());
@@ -1210,11 +1233,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
- Symbol functionSymbol = getUniqueSymbol(program, "apples", externalLibrary);
+ Symbol functionSymbol = getUniqueSymbol(program, "apples", null);
SymbolType functionSymbolType = functionSymbol.getSymbolType();
assertEquals(SymbolType.FUNCTION, functionSymbolType);
Function function = (Function) functionSymbol.getObject();
@@ -1235,7 +1258,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
resultProgram = mtf.getResultProgram();// destination program
Function function1 =
- getExternalFunction(resultProgram, new String[] { "user32.dll", "apples" });
+ getExternalFunction(resultProgram, "user32.dll", new String[] { "apples" });
Parameter p1 = function1.getParameter(0);
Parameter p2 = function1.getParameter(1);
assertEquals("Test Parameter Comment", p1.getComment());
@@ -1245,10 +1268,10 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
chooseRadioButton(MY_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(resultProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(resultProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function function = (Function) apples.getObject();
checkDataType(new ByteDataType(), function.getReturnType());
@@ -1269,15 +1292,15 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testFunctionChangeReturnTypeConflictPickLatest() throws Exception {
-
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function function = createExternalFunction(program, applesPath,
+ Function function = createExternalFunction(program, library, applesPath,
addr(program, "77db1020"), new FloatDataType(), SourceType.ANALYSIS);
assertNotNull(function);
}
@@ -1289,13 +1312,13 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(new WordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(new WordDataType(), function1.getReturnType());
}
@@ -1303,14 +1326,14 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(new PointerDataType(new ByteDataType()),
SourceType.IMPORTED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(new PointerDataType(new ByteDataType()), function1.getReturnType());
}
@@ -1320,7 +1343,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Return Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- Function function = getExternalFunction(resultProgram, applesPath);
+ Function function = getExternalFunction(resultProgram, library, applesPath);
assertEquals(0, function.getParameterCount());
checkDataType(new WordDataType(), function.getReturnType());
}
@@ -1328,14 +1351,15 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testFunctionChangeReturnTypeToTypedefConflictPickMy() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function function = createExternalFunction(program, applesPath,
+ Function function = createExternalFunction(program, library, applesPath,
addr(program, "77db1020"), new FloatDataType(), SourceType.ANALYSIS);
assertNotNull(function);
}
@@ -1347,13 +1371,13 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(new LongDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(new LongDataType(), function1.getReturnType());
}
@@ -1364,13 +1388,13 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
DataType typedefDT = new TypedefDataType(path, "long", new LongDataType(),
program.getDataTypeManager());
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(typedefDT, SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(typedefDT, function1.getReturnType());
}
@@ -1380,7 +1404,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Return Conflict", MY_BUTTON);
waitForMergeCompletion();
- Function function = getExternalFunction(resultProgram, applesPath);
+ Function function = getExternalFunction(resultProgram, library, applesPath);
assertEquals(0, function.getParameterCount());
CategoryPath path = new CategoryPath("/");
DataType typedefDT = new TypedefDataType(path, "long.conflict", new LongDataType(),
@@ -1391,14 +1415,15 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testFunctionChangeReturnTypeConflictPickMy() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function function = createExternalFunction(program, applesPath,
+ Function function = createExternalFunction(program, library, applesPath,
addr(program, "77db1020"), new FloatDataType(), SourceType.ANALYSIS);
assertNotNull(function);
}
@@ -1410,13 +1435,13 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(new WordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(new WordDataType(), function1.getReturnType());
}
@@ -1424,14 +1449,14 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function function = getExternalFunction(program, applesPath);
+ Function function = getExternalFunction(program, library, applesPath);
function.setReturnType(new PointerDataType(new ByteDataType()),
SourceType.IMPORTED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- Function function1 = getExternalFunction(program, applesPath);
+ Function function1 = getExternalFunction(program, library, applesPath);
assertEquals(0, function1.getParameterCount());
checkDataType(new PointerDataType(new ByteDataType()), function1.getReturnType());
}
@@ -1441,22 +1466,23 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
chooseRadioButton("Resolve Function Return Conflict", MY_BUTTON);
waitForMergeCompletion();
- Function function = getExternalFunction(resultProgram, applesPath);
+ Function function = getExternalFunction(resultProgram, library, applesPath);
assertEquals(0, function.getParameterCount());
checkDataType(new PointerDataType(new ByteDataType()), function.getReturnType());
}
@Test
public void testExternalFunctionRemoveVsChangeConflict() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ final String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1466,7 +1492,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
parameter2.setComment("Other Comment");
applesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1477,19 +1503,20 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.getSymbol().delete();// Remove the function, but not the external location.
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.getSymbol().delete();// Remove the function, but not the external location.
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertEquals(false, applesLocation.isFunction());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(false, orangesLocation.isFunction());
}
@@ -1497,11 +1524,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setComment("Once upon a time...");
applesFunction.setNoReturn(true);
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -1510,8 +1537,9 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(applesLocation);
assertNotNull(orangesLocation);
assertTrue(applesLocation.isFunction());
@@ -1531,11 +1559,11 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertEquals(false, applesLocation.isFunction());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1550,7 +1578,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionSignatureSourceChangeConflict() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@@ -1558,7 +1587,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"));
+ createExternalFunction(program, library, orangesPath,
+ addr(program, "00cc5566"));
assertEquals(SourceType.DEFAULT, function.getSignatureSource());
}
catch (Exception e) {
@@ -1569,14 +1599,15 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
// Function orangesFunction = orangesLocation.getFunction();
@@ -1586,14 +1617,15 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.ANALYSIS);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
// Function orangesFunction = orangesLocation.getFunction();
@@ -1604,7 +1636,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1615,7 +1647,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionSigSourceAndParamsNoConflict() throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest_X86", new OriginalProgramModifierListener() {
@@ -1623,7 +1656,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"));
+ createExternalFunction(program, library, orangesPath,
+ addr(program, "00cc5566"));
assertEquals(SourceType.DEFAULT, function.getSignatureSource());
}
catch (Exception e) {
@@ -1634,7 +1668,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.USER_DEFINED);
orangesFunction.setCustomVariableStorage(true);
@@ -1650,7 +1684,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1660,7 +1695,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.ANALYSIS);
orangesFunction.setCustomVariableStorage(true);
@@ -1676,7 +1711,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1687,7 +1723,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1709,7 +1745,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionParamChangeSignatureSourceConflictChooseHighestPriority()
throws Exception {
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ final String[] orangesPath = new String[] { "NamespaceA", "oranges" };
mtf.initialize("NotepadMergeListingTest_X86", new OriginalProgramModifierListener() {
@@ -1717,7 +1754,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
Function function =
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"));
+ createExternalFunction(program, library, orangesPath,
+ addr(program, "00cc5566"));
assertEquals(SourceType.DEFAULT, function.getSignatureSource());
}
catch (Exception e) {
@@ -1728,7 +1766,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.USER_DEFINED);
orangesFunction.setCustomVariableStorage(true);
@@ -1744,7 +1782,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1754,7 +1793,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setSignatureSource(SourceType.ANALYSIS);
orangesFunction.setCustomVariableStorage(true);
@@ -1770,7 +1809,8 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1781,7 +1821,7 @@ public class ExternalFunctionMerger2Test extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerAddTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerAddTest.java
index c56d5259ea..e4ef929f74 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerAddTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerAddTest.java
@@ -492,15 +492,15 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
- Library library =
- mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
- mergeProgram.createNamespace(library, label, SourceType.USER_DEFINED);
+
+ mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(label, SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- Symbol namespaceSymbol = getUniqueSymbol(program, label, library);
+ Symbol namespaceSymbol = getUniqueSymbol(program, label, null);
assertNotNull(namespaceSymbol);
assertEquals(SymbolType.NAMESPACE, namespaceSymbol.getSymbolType());
@@ -522,11 +522,9 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
SymbolTable symtab = resultProgram.getSymbolTable();
- assertNotNull(symtab.getNamespace(label, externalLibrary));
+ assertNotNull(symtab.getNamespace(label, null));
assertEquals(libname, externalLocation.getLibraryName());
assertEquals(label, externalLocation.getLabel());
@@ -549,14 +547,13 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- Library library =
- mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
- mergeProgram.createNamespace(library, label, SourceType.USER_DEFINED);
+ mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(label, SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- assertNotNull(program.getSymbolTable().getNamespace(label, library));
+ assertNotNull(program.getSymbolTable().getNamespace(label, null));
}
@Override
@@ -594,13 +591,6 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertNotNull(externalLocation.getAddress());
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
-
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- SymbolTable symtab = resultProgram.getSymbolTable();
-
- Namespace blue = symtab.getNamespace(label, externalLibrary);
- assertTrue(blue.isExternal());
}
@Test
@@ -674,10 +664,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(true, externalLocation.isFunction());
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.FUNCTION, blue.getSymbolType());
@@ -758,10 +746,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(true, externalLocation.isFunction());
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.FUNCTION, blue.getSymbolType());
@@ -844,10 +830,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(true, externalLocation.isFunction());
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.FUNCTION, blue.getSymbolType());
@@ -929,10 +913,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.LABEL, blue.getSymbolType());
@@ -1004,10 +986,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains(libname));
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.LABEL, blue.getSymbolType());
@@ -1085,10 +1065,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains(libname));
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, label, externalLibrary);
- Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", externalLibrary);
+ Symbol blue = getUniqueSymbol(resultProgram, label, null);
+ Symbol blueConflict = getUniqueSymbol(resultProgram, label + "_conflict1", null);
assertNotNull(blue);
assertNull(blueConflict);
assertEquals(SymbolType.FUNCTION, blue.getSymbolType());
@@ -1936,36 +1914,33 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
- mergeProgram.createNamespace(library, namespace, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(namespace, SourceType.USER_DEFINED);
}
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
- mergeProgram.createNamespace(library, namespace, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(namespace, SourceType.USER_DEFINED);
}
});
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
-
- Symbol myNamespaceSymbol = getUniqueSymbol(resultProgram, namespace, externalLibrary);
+ Symbol myNamespaceSymbol = getUniqueSymbol(resultProgram, namespace, null);
assertNotNull(myNamespaceSymbol);
assertEquals(SymbolType.NAMESPACE, myNamespaceSymbol.getSymbolType());
Symbol conflictSymbol =
- getUniqueSymbol(resultProgram, "MyNamespace_conflict1", externalLibrary);
+ getUniqueSymbol(resultProgram, "MyNamespace_conflict1", null);
assertNull(conflictSymbol);
}
@Test
public void testSimpleAddSubClassAddSubNamespaceConflict1() throws Exception {
- final String libname = "user32.dll";
+ final String namespace = "colors";
final String namespace1 = "blue";
final String namespace2 = "green";
final String class1 = "red";
@@ -1975,37 +1950,37 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- Library library =
- mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
+ Namespace colors =
+ mergeProgram.createNamespace(namespace, SourceType.USER_DEFINED);
Namespace ns =
- mergeProgram.createNamespace(library, namespace1, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(colors, namespace1, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createNamespace(library, namespace2, SourceType.USER_DEFINED);
+ ns = mergeProgram.createNamespace(colors, namespace2, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createClass(library, class1, SourceType.USER_DEFINED);
+ ns = mergeProgram.createClass(colors, class1, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createClass(library, class2, SourceType.USER_DEFINED);
+ ns = mergeProgram.createClass(colors, class2, SourceType.USER_DEFINED);
assertNotNull(ns);
}
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
- Library library =
- mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
+ Namespace colors =
+ mergeProgram.createNamespace(namespace, SourceType.USER_DEFINED);
Namespace ns =
- mergeProgram.createClass(library, namespace1, SourceType.USER_DEFINED);
+ mergeProgram.createClass(colors, namespace1, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createClass(library, namespace2, SourceType.USER_DEFINED);
+ ns = mergeProgram.createClass(colors, namespace2, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createNamespace(library, class1, SourceType.USER_DEFINED);
+ ns = mergeProgram.createNamespace(colors, class1, SourceType.USER_DEFINED);
assertNotNull(ns);
- ns = mergeProgram.createNamespace(library, class2, SourceType.USER_DEFINED);
+ ns = mergeProgram.createNamespace(colors, class2, SourceType.USER_DEFINED);
assertNotNull(ns);
}
});
@@ -2015,19 +1990,18 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
4000);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- Symbol blue = getUniqueSymbol(resultProgram, namespace1, externalLibrary);
+ Namespace colors = resultProgram.getSymbolTable().getNamespace(namespace, null);
+ Symbol blue = getUniqueSymbol(resultProgram, namespace1, colors);
Symbol blueConflict =
- getUniqueSymbol(resultProgram, namespace1 + "_conflict1", externalLibrary);
- Symbol green = getUniqueSymbol(resultProgram, namespace2, externalLibrary);
+ getUniqueSymbol(resultProgram, namespace1 + "_conflict1", colors);
+ Symbol green = getUniqueSymbol(resultProgram, namespace2, colors);
Symbol greenConflict =
- getUniqueSymbol(resultProgram, namespace2 + "_conflict1", externalLibrary);
- Symbol red = getUniqueSymbol(resultProgram, class1, externalLibrary);
- Symbol redConflict = getUniqueSymbol(resultProgram, class1 + "_conflict1", externalLibrary);
- Symbol yellow = getUniqueSymbol(resultProgram, class2, externalLibrary);
+ getUniqueSymbol(resultProgram, namespace2 + "_conflict1", colors);
+ Symbol red = getUniqueSymbol(resultProgram, class1, colors);
+ Symbol redConflict = getUniqueSymbol(resultProgram, class1 + "_conflict1", colors);
+ Symbol yellow = getUniqueSymbol(resultProgram, class2, colors);
Symbol yellowConflict =
- getUniqueSymbol(resultProgram, class2 + "_conflict1", externalLibrary);
+ getUniqueSymbol(resultProgram, class2 + "_conflict1", colors);
assertEquals(SymbolType.NAMESPACE, blue.getSymbolType());
assertEquals(SymbolType.CLASS, blueConflict.getSymbolType());
assertEquals(SymbolType.NAMESPACE, green.getSymbolType());
@@ -2052,10 +2026,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- Library library =
- mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
+
+ mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace parentNS =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
Namespace ns =
mergeProgram.createNamespace(parentNS, namespace1, SourceType.USER_DEFINED);
@@ -2076,7 +2050,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace parentNS =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
Namespace ns =
mergeProgram.createClass(parentNS, namespace1, SourceType.USER_DEFINED);
@@ -2098,11 +2072,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
4000);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
Symbol blue = getUniqueSymbol(resultProgram, namespace1, myNamespace);
Symbol blueConflict =
getUniqueSymbol(resultProgram, namespace1 + "_conflict1", myNamespace);
@@ -2143,8 +2114,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalFunction(namespace, label, address,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalFunction(library, namespace, label, address,
SourceType.USER_DEFINED);
}
@@ -2153,8 +2124,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalFunction(namespace, label, address,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalFunction(library, namespace, label, address,
SourceType.USER_DEFINED);
}
});
@@ -2162,12 +2133,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, label + "_conflict1", myNamespace);
@@ -2197,8 +2164,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label1, address1,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label1, address1,
SourceType.USER_DEFINED);
}
@@ -2208,8 +2175,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label2, address2,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label2, address2,
SourceType.USER_DEFINED);
}
});
@@ -2217,12 +2184,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label1, myNamespace);
Symbol oranges = getUniqueSymbol(resultProgram, label2, myNamespace);
@@ -2232,10 +2195,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertEquals(label1, externalLocation.getLabel());
assertEquals(libname, externalLocation.getLibraryName());
assertEquals(parentNamespace, externalLocation.getParentName());
- assertEquals(libname + "::" + parentNamespace,
+ assertEquals(parentNamespace,
externalLocation.getParentNameSpace().getName(true));
assertEquals(null, externalLocation.getFunction());
- assertEquals(libname + "::" + parentNamespace + "::" + label1,
+ assertEquals(parentNamespace + "::" + label1,
externalLocation.getSymbol().getName(true));
assertEquals(SourceType.USER_DEFINED, externalLocation.getSource());
assertEquals(addr(resultProgram, address1), externalLocation.getAddress());
@@ -2243,10 +2206,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertEquals(label2, orangesExternalLocation.getLabel());
assertEquals(libname, orangesExternalLocation.getLibraryName());
assertEquals(parentNamespace, orangesExternalLocation.getParentName());
- assertEquals(libname + "::" + parentNamespace,
+ assertEquals(parentNamespace,
orangesExternalLocation.getParentNameSpace().getName(true));
assertEquals(null, orangesExternalLocation.getFunction());
- assertEquals(libname + "::" + parentNamespace + "::" + label2,
+ assertEquals(parentNamespace + "::" + label2,
orangesExternalLocation.getSymbol().getName(true));
assertEquals(SourceType.USER_DEFINED, orangesExternalLocation.getSource());
assertEquals(addr(resultProgram, address2), orangesExternalLocation.getAddress());
@@ -2272,8 +2235,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address1,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address1,
SourceType.USER_DEFINED);
}
@@ -2283,8 +2246,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address2,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address2,
SourceType.USER_DEFINED);
}
});
@@ -2293,11 +2256,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null)
.getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
@@ -2308,10 +2268,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertEquals(label, externalLocation.getLabel());
assertEquals(libname, externalLocation.getLibraryName());
assertEquals(parentNamespace, externalLocation.getParentName());
- assertEquals(libname + "::" + parentNamespace,
+ assertEquals(parentNamespace,
externalLocation.getParentNameSpace().getName(true));
assertEquals(null, externalLocation.getFunction());
- assertEquals(libname + "::" + parentNamespace + "::" + label,
+ assertEquals(parentNamespace + "::" + label,
externalLocation.getSymbol().getName(true));
assertEquals(SourceType.USER_DEFINED, externalLocation.getSource());
assertEquals(addr(resultProgram, address1), externalLocation.getAddress());
@@ -2338,8 +2298,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address1,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address1,
SourceType.USER_DEFINED);
}
@@ -2349,8 +2309,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address2,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address2,
SourceType.USER_DEFINED);
}
});
@@ -2359,11 +2319,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", MY_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null)
.getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
@@ -2374,10 +2331,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertEquals(label, externalLocation.getLabel());
assertEquals(libname, externalLocation.getLibraryName());
assertEquals(parentNamespace, externalLocation.getParentName());
- assertEquals(libname + "::" + parentNamespace,
+ assertEquals(parentNamespace,
externalLocation.getParentNameSpace().getName(true));
assertEquals(null, externalLocation.getFunction());
- assertEquals(libname + "::" + parentNamespace + "::" + label,
+ assertEquals(parentNamespace + "::" + label,
externalLocation.getSymbol().getName(true));
assertEquals(SourceType.USER_DEFINED, externalLocation.getSource());
assertEquals(addr(resultProgram, address2), externalLocation.getAddress());
@@ -2403,8 +2360,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address1,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address1,
SourceType.USER_DEFINED);
}
@@ -2414,8 +2371,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalLocation(namespace, label, address2,
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalLocation(library, namespace, label, address2,
SourceType.USER_DEFINED);
}
});
@@ -2424,11 +2381,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", KEEP_BOTH_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- resultProgram.getSymbolTable().getNamespace(parentNamespace, externalLibrary);
+ resultProgram.getSymbolTable().getNamespace(parentNamespace, null);
assertNotNull(myNamespace);
SymbolTable symtab = resultProgram.getSymbolTable();
@@ -2460,9 +2414,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2479,9 +2434,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace, label, address,
+ SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2500,12 +2456,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", LATEST_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, label + "_conflict1", myNamespace);
@@ -2545,9 +2497,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2564,9 +2517,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2585,11 +2539,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", MY_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null)
.getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
@@ -2634,11 +2585,12 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- mergeProgram.addExternalFunction(namespace, label1, "0x120",
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ mergeProgram.addExternalFunction(library, namespace, label1, "0x120",
SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label2, address, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label2, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2655,9 +2607,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label2, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label2, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2677,9 +2630,9 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
SymbolTable symbolTable = resultProgram.getSymbolTable();
- Namespace externalLibrary = (Namespace) symbolTable.getLibrarySymbol(libname).getObject();
+ Library externalLibrary = (Library) symbolTable.getLibrarySymbol(libname).getObject();
assertNotNull(externalLibrary);
- Namespace myNamespace = symbolTable.getNamespace(parentNamespace, externalLibrary);
+ Namespace myNamespace = symbolTable.getNamespace(parentNamespace, null);
assertNotNull(myNamespace);
Symbol oranges = getUniqueSymbol(resultProgram, label1, myNamespace);
@@ -2741,9 +2694,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2760,9 +2714,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2780,14 +2735,9 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve External Add Conflict", LATEST_BUTTON);
waitForMergeCompletion();
-
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
- assertNotNull(myNamespace);
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
+
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, label + "_conflict1", myNamespace);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
@@ -2825,9 +2775,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2844,9 +2795,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2865,12 +2817,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
chooseButtonAndApply("Resolve External Add Conflict", MY_BUTTON);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, label, myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, label + "_conflict1", myNamespace);
@@ -2910,9 +2858,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2929,9 +2878,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, parentNamespace, SourceType.USER_DEFINED);
- ExternalLocation externalLocation = mergeProgram.addExternalFunction(namespace,
- label, address, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(parentNamespace, SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ mergeProgram.addExternalFunction(library, namespace,
+ label, address, SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
@@ -2951,12 +2901,8 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
SymbolTable symbolTable = resultProgram.getSymbolTable();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, parentNamespace, externalLibrary)
- .getObject();
+ (Namespace) getUniqueSymbol(resultProgram, parentNamespace, null).getObject();
List<Symbol> symbols = symbolTable.getSymbols(label, myNamespace);
assertEquals(2, symbols.size());
@@ -3049,7 +2995,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
Library library =
mergeProgram.createExternalLibrary(libname, SourceType.USER_DEFINED);
Namespace namespace =
- mergeProgram.createNamespace(library, label, SourceType.USER_DEFINED);
+ mergeProgram.createNamespace(label, SourceType.USER_DEFINED);
assertNotNull(namespace);
}
});
@@ -3057,15 +3003,11 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
- assertNotNull(externalLibrary);
-
Symbol namespaceSymbol =
- resultProgram.getSymbolTable().getNamespaceSymbol(label, externalLibrary);
+ resultProgram.getSymbolTable().getNamespaceSymbol(label, null);
assertNotNull(namespaceSymbol);
- List<Symbol> symbols = resultProgram.getSymbolTable().getSymbols(label, externalLibrary);
+ List<Symbol> symbols = resultProgram.getSymbolTable().getSymbols(label, null);
assertEquals(2, symbols.size());
Symbol otherSymbol = symbols.get(0) == namespaceSymbol ? symbols.get(1) : symbols.get(0);
Object object = otherSymbol.getObject();
@@ -3080,7 +3022,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
final String libname = "MyLibrary";
final String label = "blue";
final String address = null;
- final String[] BLUE_PATH = new String[] { libname, label };
+ final String[] BLUE_PATH = new String[] { label };
final CategoryPath catPath = new CategoryPath("/cat1");
final Structure myStruct = new StructureDataType(catPath, "MyStruct", 0);
myStruct.add(new WordDataType());
@@ -3096,13 +3038,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myStruct,
+ createExternalLabel(mergeProgram, libname, label, address, myStruct,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3113,13 +3056,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myTypedef,
+ createExternalLabel(mergeProgram, libname, label, address, myTypedef,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3135,11 +3079,9 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains(libname));
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
SymbolTable symtab = resultProgram.getSymbolTable();
- List<Symbol> symbols = symtab.getSymbols(label, externalLibrary);
+ List<Symbol> symbols = symtab.getSymbols(label, null);
assertEquals(2, symbols.size());
ExternalLocation loc1 = (ExternalLocation) symbols.get(0).getObject();
ExternalLocation loc2 = (ExternalLocation) symbols.get(1).getObject();
@@ -3161,7 +3103,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
final String libname = "MyLibrary";
final String label = "blue";
final String address = "0x100";
- final String[] BLUE_PATH = new String[] { libname, label };
+ final String[] BLUE_PATH = new String[] { label };
final CategoryPath catPath = new CategoryPath("/cat1");
final Structure myStruct = new StructureDataType(catPath, "MyStruct", 0);
myStruct.add(new WordDataType());
@@ -3177,13 +3119,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myStruct,
+ createExternalLabel(mergeProgram, libname, label, address, myStruct,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3195,13 +3138,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myTypedef,
+ createExternalLabel(mergeProgram, libname, label, address, myTypedef,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3218,12 +3162,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains(libname));
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
SymbolTable symtab = resultProgram.getSymbolTable();
- List<Symbol> symbols = symtab.getSymbols(label, externalLibrary);
+ List<Symbol> symbols = symtab.getSymbols(label, null);
assertEquals(1, symbols.size());
Symbol blue = symbols.get(0);
assertEquals(SymbolType.LABEL, blue.getSymbolType());
@@ -3243,7 +3185,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
final String libname = "MyLibrary";
final String label = "blue";
final String address = "0x100";
- final String[] BLUE_PATH = new String[] { libname, label };
+ final String[] BLUE_PATH = new String[] { label };
final CategoryPath catPath = new CategoryPath("/cat1");
final Structure myStruct = new StructureDataType(catPath, "MyStruct", 0);
myStruct.add(new WordDataType());
@@ -3259,13 +3201,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myStruct,
+ createExternalLabel(mergeProgram, libname, label, address, myStruct,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3277,13 +3220,14 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(MergeProgram mergeProgram) throws Exception {
- createExternalLabel(mergeProgram, BLUE_PATH, address, myTypedef,
+ createExternalLabel(mergeProgram, libname, label, address, myTypedef,
SourceType.USER_DEFINED);
Program program = mergeProgram.getProgram();
ExternalManager externalManager = program.getExternalManager();
assertTrue(externalManager.contains(libname));
- ExternalLocation externalLocation = getExternalLocation(program, BLUE_PATH);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, libname, BLUE_PATH);
assertNotNull(externalLocation);
assertEquals(false, externalLocation.isFunction());
@@ -3300,12 +3244,10 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains(libname));
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol(libname).getObject();
SymbolTable symtab = resultProgram.getSymbolTable();
- List<Symbol> symbols = symtab.getSymbols(label, externalLibrary);
+ List<Symbol> symbols = symtab.getSymbols(label, null);
assertEquals(1, symbols.size());
Symbol blue = symbols.get(0);
assertEquals(SymbolType.LABEL, blue.getSymbolType());
@@ -3319,16 +3261,11 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
checkDataType(myTypedef, externalLocation.getDataType());
}
- void createExternalLabel(MergeProgram mergeProgram, String[] path, String memoryAddress,
- DataType dt, SourceType sourceType) {
-
- int nameIndex = path.length - 1;
- Library currentLibrary = null;
- for (int i = 0; i < nameIndex; i++) {
- currentLibrary = mergeProgram.createExternalLibrary(path[i], sourceType);
- }
+ void createExternalLabel(MergeProgram mergeProgram, String libraryName, String label,
+ String memoryAddress, DataType dt, SourceType sourceType) {
- mergeProgram.addExternalLocation(currentLibrary, path[nameIndex], memoryAddress, dt,
+ Library library = mergeProgram.createExternalLibrary(libraryName, sourceType);
+ mergeProgram.addExternalLocation(library, label, memoryAddress, dt,
sourceType);
}
@@ -3341,7 +3278,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
final String address2 = "0x110";
final String libnameA = "MyLibrary";
final String labelA = "blue";
- final String[] BLUE_PATH = new String[] { libnameA, labelA };
+ final String[] BLUE_PATH = new String[] { label };
final CategoryPath catPath = new CategoryPath("/cat1");
final Structure myStruct = new StructureDataType(catPath, "MyStruct", 0);
myStruct.add(new WordDataType());
@@ -3371,7 +3308,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- createExternalLabel(mergeProgram, BLUE_PATH, null, myStruct,
+ createExternalLabel(mergeProgram, libnameA, labelA, null, myStruct,
SourceType.USER_DEFINED);
}
@@ -3391,7 +3328,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- createExternalLabel(mergeProgram, BLUE_PATH, null, myTypedef,
+ createExternalLabel(mergeProgram, libnameA, labelA, null, myTypedef,
SourceType.USER_DEFINED);
}
});
@@ -3413,7 +3350,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertHasExtAddresses(externalLocations, "00000100", "00000110");
Set<ExternalLocation> externalLocations2 =
- externalManager.getExternalLocations(BLUE_PATH[0], BLUE_PATH[1]);
+ externalManager.getExternalLocations(libname, BLUE_PATH[0]);
assertEquals(2, externalLocations2.size());
assertHasExtAddresses(externalLocations, "00000100", "00000110");
@@ -3427,7 +3364,6 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
final String address2 = "0x110";
final String libnameA = "MyLibrary";
final String labelA = "blue";
- final String[] BLUE_PATH = new String[] { libnameA, labelA };
final CategoryPath catPath = new CategoryPath("/cat1");
final Structure myStruct = new StructureDataType(catPath, "MyStruct", 0);
myStruct.add(new WordDataType());
@@ -3457,7 +3393,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- createExternalLabel(mergeProgram, BLUE_PATH, null, myStruct,
+ createExternalLabel(mergeProgram, libnameA, labelA, null, myStruct,
SourceType.USER_DEFINED);
}
@@ -3477,7 +3413,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSource() == SourceType.USER_DEFINED);
assertEquals(false, externalLocation.isFunction());
- createExternalLabel(mergeProgram, BLUE_PATH, null, myTypedef,
+ createExternalLabel(mergeProgram, libnameA, labelA, null, myTypedef,
SourceType.USER_DEFINED);
}
});
@@ -3497,7 +3433,7 @@ public class ExternalMergerAddTest extends AbstractExternalMergerTest {
assertHasExtAddresses(externalLocations, "00000100", "00000110");
Set<ExternalLocation> externalLocations2 =
- externalManager.getExternalLocations(BLUE_PATH[0], BLUE_PATH[1]);
+ externalManager.getExternalLocations(libnameA, labelA);
assertEquals(2, externalLocations2.size());
assertHasExtAddresses(externalLocations, "00000100", "00000110");
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerChangeTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerChangeTest.java
index 3e70311723..7ff85e1bc4 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerChangeTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerChangeTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -1300,8 +1300,8 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program,
- new String[] { "user32.dll", "OriginalNamespace", "Foo" },
+ createExternalFunction(program, "user32.dll",
+ new String[] { "OriginalNamespace", "Foo" },
addr(program, "77db1020"));
}
catch (Exception e) {
@@ -1312,10 +1312,11 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Namespace externalNamespace = getExternalNamespace(program,
- new String[] { "user32.dll", "OriginalNamespace" });
- externalNamespace.getSymbol().setName("ChangedNamespace",
- SourceType.USER_DEFINED);
+ Namespace externalNamespace =
+ getNamespace(program, new String[] { "OriginalNamespace" });
+ externalNamespace.getSymbol()
+ .setName("ChangedNamespace",
+ SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
@@ -1325,8 +1326,8 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- createExternalFunction(program,
- new String[] { "user32.dll", "ChangedNamespace" },
+ createExternalFunction(program, "user32.dll",
+ new String[] { "ChangedNamespace" },
addr(program, "77db1130"));
}
catch (Exception e) {
@@ -1346,23 +1347,23 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
assertTrue(externalLocation.getSymbol() instanceof FunctionSymbol);
assertEquals("ChangedNamespace", externalLocation.getLabel());
Namespace namespace =
- getExternalNamespace(resultProgram, new String[] { "user32.dll", "ChangedNamespace" });
+ getNamespace(resultProgram, new String[] { "ChangedNamespace" });
assertNotNull(namespace);
}
@Test
public void testExternalLabelChangeVersusNamespaceRename() throws Exception {
-
- final String[] applesPath = new String[] { "user32.dll", "Class1", "Blue" };
- final String[] namespacePath = new String[] { "user32.dll", "Class1" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "Blue" };
+ String[] namespacePath = new String[] { "Class1" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, applesPath, addr(program, "77db1020"),
+ createExternalLabel(program, library, applesPath, addr(program, "77db1020"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1373,7 +1374,8 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
externalLocation.setLocation("pink", externalLocation.getAddress(),
SourceType.USER_DEFINED);
}
@@ -1381,22 +1383,22 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
ExternalLocation externalLocation =
- getExternalLocation(program, new String[] { "user32.dll", "Class1", "pink" });
+ getExternalLocation(program, "user32.dll", new String[] { "Class1", "pink" });
assertNotNull(externalLocation);
}
@Override
public void modifyPrivate(ProgramDB program) throws Exception {
try {
- Namespace externalNamespace = getExternalNamespace(program, namespacePath);
- externalNamespace.getSymbol().setName("OtherNamespace",
- SourceType.USER_DEFINED);
+ Namespace externalNamespace = getNamespace(program, namespacePath);
+ externalNamespace.getSymbol()
+ .setName("OtherNamespace", SourceType.USER_DEFINED);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "OtherNamespace", "Blue" });
+ ExternalLocation externalLocation = getExternalLocation(program, "user32.dll",
+ new String[] { "OtherNamespace", "Blue" });
assertNotNull(externalLocation);
}
});
@@ -1404,22 +1406,22 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- ExternalLocation externalLocation = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "OtherNamespace", "pink" });
+ ExternalLocation externalLocation = getExternalLocation(resultProgram, "user32.dll",
+ new String[] { "OtherNamespace", "pink" });
assertNotNull(externalLocation);
}
@Test
public void testExternalLabelMoveToDifferentNamespacesPickLatest() throws Exception {
-
- final String[] applesPath = new String[] { "user32.dll", "Class1", "Blue" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "Blue" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, applesPath, addr(program, "77db1020"),
+ createExternalLabel(program, library, applesPath, addr(program, "77db1020"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1430,34 +1432,36 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "NamespaceAA" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "NamespaceAA" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "NamespaceAA", "Blue" });
+ ExternalLocation externalLocation = getExternalLocation(program, library,
+ new String[] { "NamespaceAA", "Blue" });
assertNotNull(externalLocation);
}
@Override
public void modifyPrivate(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "NamespaceBB" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "NamespaceBB" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ ExternalLocation externalLocation = getExternalLocation(program, library,
+ new String[] { "NamespaceBB", "Blue" });
assertNotNull(externalLocation);
}
});
@@ -1468,13 +1472,13 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
ExternalLocation externalLocation1 =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "Class1", "Blue" });
+ getExternalLocation(resultProgram, library, new String[] { "Class1", "Blue" });
assertNull(externalLocation1);
- ExternalLocation externalLocationAA = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "NamespaceAA", "Blue" });
+ ExternalLocation externalLocationAA = getExternalLocation(resultProgram, library,
+ new String[] { "NamespaceAA", "Blue" });
assertNotNull(externalLocationAA);
- ExternalLocation externalLocationBB = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ ExternalLocation externalLocationBB = getExternalLocation(resultProgram, library,
+ new String[] { "NamespaceBB", "Blue" });
assertNull(externalLocationBB);
assertEquals(addr(resultProgram, "77db1020"), externalLocationAA.getAddress());
assertEquals(SourceType.USER_DEFINED, externalLocationAA.getSource());
@@ -1482,15 +1486,15 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Test
public void testExternalLabelMoveToDifferentNamespacesPickMy() throws Exception {
-
- final String[] applesPath = new String[] { "user32.dll", "Class1", "Blue" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "Blue" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, applesPath, addr(program, "77db1020"),
+ createExternalLabel(program, library, applesPath, addr(program, "77db1020"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1501,34 +1505,36 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "NamespaceAA" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "NamespaceAA" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "NamespaceAA", "Blue" });
+ ExternalLocation externalLocation = getExternalLocation(program, library,
+ new String[] { "NamespaceAA", "Blue" });
assertNotNull(externalLocation);
}
@Override
public void modifyPrivate(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "NamespaceBB" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "NamespaceBB" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ ExternalLocation externalLocation = getExternalLocation(program, library,
+ new String[] { "NamespaceBB", "Blue" });
assertNotNull(externalLocation);
}
});
@@ -1539,13 +1545,13 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
ExternalLocation externalLocation1 =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "Class1", "Blue" });
+ getExternalLocation(resultProgram, library, new String[] { "Class1", "Blue" });
assertNull(externalLocation1);
- ExternalLocation externalLocationAA = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "NamespaceAA", "Blue" });
+ ExternalLocation externalLocationAA = getExternalLocation(resultProgram, library,
+ new String[] { "NamespaceAA", "Blue" });
assertNull(externalLocationAA);
- ExternalLocation externalLocationBB = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ ExternalLocation externalLocationBB = getExternalLocation(resultProgram, library,
+ new String[] { "NamespaceBB", "Blue" });
assertNotNull(externalLocationBB);
assertEquals(addr(resultProgram, "77db1020"), externalLocationBB.getAddress());
assertEquals(SourceType.USER_DEFINED, externalLocationBB.getSource());
@@ -1555,14 +1561,15 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
public void testExternalLabelMoveToDifferentNamespacesAndLocationConflictsWithNamespacePickMy()
throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "Blue" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "Blue" };
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, applesPath, addr(program, "77db1020"),
+ createExternalLabel(program, library, applesPath, addr(program, "77db1020"),
SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -1573,39 +1580,41 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) throws Exception {
try {
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "AA" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "AA" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
ExternalLocation externalLocation =
- getExternalLocation(program, new String[] { "user32.dll", "AA", "Blue" });
+ getExternalLocation(program, library, new String[] { "AA", "Blue" });
assertNotNull(externalLocation);
}
@Override
public void modifyPrivate(ProgramDB program) throws Exception {
try {
- createExternalLabel(program, new String[] { "user32.dll", "AA" }, null,
+ createExternalLabel(program, library, new String[] { "AA" }, null,
SourceType.USER_DEFINED);
- ExternalLocation externalLocation = getExternalLocation(program, applesPath);
+ ExternalLocation externalLocation =
+ getExternalLocation(program, library, applesPath);
Symbol symbol = externalLocation.getSymbol();
- Namespace namespaceAA = createExternalNamespace(program,
- new String[] { "user32.dll", "NamespaceBB" }, SourceType.USER_DEFINED);
+ Namespace namespaceAA = createNamespace(program, new String[] { "NamespaceBB" },
+ SourceType.USER_DEFINED);
symbol.setNamespace(namespaceAA);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
ExternalLocation externalLocationAA =
- getExternalLocation(program, new String[] { "user32.dll", "AA" });
+ getExternalLocation(program, library, new String[] { "AA" });
assertNotNull(externalLocationAA);
ExternalLocation externalLocation = getExternalLocation(program,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ library, new String[] { "NamespaceBB", "Blue" });
assertNotNull(externalLocation);
}
});
@@ -1616,16 +1625,16 @@ public class ExternalMergerChangeTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
ExternalLocation externalLocation1 =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "Class1", "Blue" });
+ getExternalLocation(resultProgram, library, new String[] { "Class1", "Blue" });
assertNull(externalLocation1);
ExternalLocation externalLocationAA =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "AA" });
+ getExternalLocation(resultProgram, library, new String[] { "AA" });
assertNull(externalLocationAA);
ExternalLocation externalLocationAABlue =
- getExternalLocation(resultProgram, new String[] { "user32.dll", "AA", "Blue" });
+ getExternalLocation(resultProgram, library, new String[] { "AA", "Blue" });
assertNull(externalLocationAABlue);
- ExternalLocation externalLocationBB = getExternalLocation(resultProgram,
- new String[] { "user32.dll", "NamespaceBB", "Blue" });
+ ExternalLocation externalLocationBB = getExternalLocation(resultProgram, library,
+ new String[] { "NamespaceBB", "Blue" });
assertNotNull(externalLocationBB);
assertEquals(addr(resultProgram, "77db1020"), externalLocationBB.getAddress());
assertEquals(SourceType.USER_DEFINED, externalLocationBB.getSource());
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerRemoveTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerRemoveTest.java
index e3ab0b6470..6813521411 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerRemoveTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerRemoveTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -463,12 +463,8 @@ public class ExternalMergerRemoveTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
waitForMergeCompletion();
- SymbolTable symbolTable = resultProgram.getSymbolTable();
- Symbol s = symbolTable.getLibrarySymbol("user32.dll");
- if (s != null) {
- Symbol symbol = getUniqueSymbol(resultProgram, "Blue", (Namespace) s.getObject());
- assertNull(symbol);
- }
+ Symbol symbol = getUniqueSymbol(resultProgram, "Blue", null);
+ assertNull(symbol);
ExternalManager externalManager = resultProgram.getExternalManager();
assertTrue(externalManager.contains("user32.dll"));
@@ -997,8 +993,8 @@ public class ExternalMergerRemoveTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
- changeExternalFunctionIntoExternalLabel(program,
- new String[] { "user32.dll", "Blue" });
+ changeExternalFunctionIntoExternalLabel(program, "user32.dll",
+ new String[] { "Blue" });
}
@Override
@@ -1054,12 +1050,12 @@ public class ExternalMergerRemoveTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
- changeExternalFunctionIntoExternalLabel(program,
- new String[] { "user32.dll", "Blue" });
+ changeExternalFunctionIntoExternalLabel(program, "user32.dll",
+ new String[] { "Blue" });
try {
Function externalLocation =
- createExternalFunction(program, new String[] { "user32.dll", "Red" },
+ createExternalFunction(program, "user32.dll", new String[] { "Red" },
addr(program, "77db1450"), null, SourceType.USER_DEFINED);
assertNotNull(externalLocation);
}
@@ -1152,7 +1148,7 @@ public class ExternalMergerRemoveTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
changeExternalFunctionIntoExternalLabel(program,
- new String[] { "user32.dll", "Blue" });
+ "user32.dll", new String[] { "Blue" });
}
});
@@ -1214,8 +1210,8 @@ public class ExternalMergerRemoveTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
- changeExternalFunctionIntoExternalLabel(program,
- new String[] { "user32.dll", "Blue" });
+ changeExternalFunctionIntoExternalLabel(program, "user32.dll",
+ new String[] { "Blue" });
}
});
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerTest.java
index 22d2bcbd77..2258b6a49f 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalMergerTest.java
@@ -1519,6 +1519,7 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
assertTrue(refs[0].getSource() == SourceType.USER_DEFINED);
ExternalManager externalManager = resultProgram.getExternalManager();
+
ExternalLocation latestExtLoc =
externalManager.getUniqueExternalLocation("advapi32.dll", "oranges");
assertNotNull(latestExtLoc);
@@ -2255,8 +2256,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function function = createExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" },
+ Function function = createExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" },
addr(program, "77db1020"), new DWordDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -2271,8 +2272,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function function = getExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" });
+ Function function = getExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" });
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -2288,8 +2289,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function function = getExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" });
+ Function function = getExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" });
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -2311,11 +2312,11 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
chooseVariousOptions(new int[] { INFO_ROW, KEEP_LATEST, KEEP_MY, KEEP_LATEST });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", externalLibrary).getObject();
+ (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, "apples", myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, "apples_conflict1", myNamespace);
@@ -2341,8 +2342,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function function = createExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" },
+ Function function = createExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" },
addr(program, "77db1020"), new DWordDataType(), SourceType.USER_DEFINED);
assertNotNull(function);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -2357,8 +2358,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function function = getExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" });
+ Function function = getExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" });
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -2374,8 +2375,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function function = getExternalFunction(program,
- new String[] { "user32.dll", "MyNamespace", "apples" });
+ Function function = getExternalFunction(program, "user32.dll",
+ new String[] { "MyNamespace", "apples" });
assertNotNull(function);
function.setReturnType(new FloatDataType(), SourceType.ANALYSIS);
@@ -2396,11 +2397,11 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
chooseVariousOptions(new int[] { INFO_ROW, KEEP_MY, KEEP_LATEST, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", externalLibrary).getObject();
+ (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, "apples", myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, "apples_conflict1", myNamespace);
@@ -2427,14 +2428,15 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
SymbolTable symbolTable = program.getSymbolTable();
- Library externalLibrary =
+ Library library =
symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
- Namespace myNamespace = symbolTable.createNameSpace(externalLibrary,
+ Namespace myNamespace = symbolTable.createNameSpace(null,
"MyNamespace", SourceType.USER_DEFINED);
ExternalManager externalManager = program.getExternalManager();
- ExternalLocation externalLocation = externalManager.addExtFunction(myNamespace,
- "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(library, myNamespace,
+ "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -2454,10 +2456,10 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
SymbolType librarySymbolType = librarySymbol.getSymbolType();
assertEquals(SymbolType.LIBRARY, librarySymbolType);
- Library externalLibrary = (Library) librarySymbol.getObject();
+// Library externalLibrary = (Library) librarySymbol.getObject();
Symbol namespaceSymbol =
- getUniqueSymbol(program, "MyNamespace", externalLibrary);
+ getUniqueSymbol(program, "MyNamespace", null);
SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
@@ -2483,10 +2485,10 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
SymbolType librarySymbolType = librarySymbol.getSymbolType();
assertEquals(SymbolType.LIBRARY, librarySymbolType);
- Library externalLibrary = (Library) librarySymbol.getObject();
+// Library externalLibrary = (Library) librarySymbol.getObject();
Symbol namespaceSymbol =
- getUniqueSymbol(program, "MyNamespace", externalLibrary);
+ getUniqueSymbol(program, "MyNamespace", null);
SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
@@ -2510,11 +2512,11 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
chooseVariousOptions(new int[] { INFO_ROW, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", externalLibrary).getObject();
+ (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, "apples", myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, "apples_conflict1", myNamespace);
@@ -2537,14 +2539,15 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
SymbolTable symbolTable = program.getSymbolTable();
- Library externalLibrary =
+ Library library =
symbolTable.createExternalLibrary("user32.dll", SourceType.USER_DEFINED);
- Namespace myNamespace = symbolTable.createNameSpace(externalLibrary,
+ Namespace myNamespace = symbolTable.createNameSpace(null,
"MyNamespace", SourceType.USER_DEFINED);
ExternalManager externalManager = program.getExternalManager();
- ExternalLocation externalLocation = externalManager.addExtFunction(myNamespace,
- "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
+ ExternalLocation externalLocation =
+ externalManager.addExtFunction(library, myNamespace,
+ "apples", addr(program, "77db1020"), SourceType.USER_DEFINED);
Function function = externalLocation.getFunction();
assertNotNull(function);
function.setReturnType(new ByteDataType(), SourceType.ANALYSIS);
@@ -2560,12 +2563,12 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- SymbolTable symbolTable = program.getSymbolTable();
- Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
- Library externalLibrary = (Library) librarySymbol.getObject();
+// SymbolTable symbolTable = program.getSymbolTable();
+// Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
+// Library externalLibrary = (Library) librarySymbol.getObject();
Symbol namespaceSymbol =
- getUniqueSymbol(program, "MyNamespace", externalLibrary);
+ getUniqueSymbol(program, "MyNamespace", null);
SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
@@ -2591,10 +2594,10 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
Symbol librarySymbol = symbolTable.getLibrarySymbol("user32.dll");
SymbolType librarySymbolType = librarySymbol.getSymbolType();
assertEquals(SymbolType.LIBRARY, librarySymbolType);
- Library externalLibrary = (Library) librarySymbol.getObject();
+ // Library externalLibrary = (Library) librarySymbol.getObject();
Symbol namespaceSymbol =
- getUniqueSymbol(program, "MyNamespace", externalLibrary);
+ getUniqueSymbol(program, "MyNamespace", null);
SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
@@ -2618,11 +2621,11 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
chooseVariousOptions(new int[] { INFO_ROW, KEEP_MY });
waitForMergeCompletion();
- Namespace externalLibrary =
- (Namespace) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
+ Library externalLibrary =
+ (Library) resultProgram.getSymbolTable().getLibrarySymbol("user32.dll").getObject();
assertNotNull(externalLibrary);
Namespace myNamespace =
- (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", externalLibrary).getObject();
+ (Namespace) getUniqueSymbol(resultProgram, "MyNamespace", null).getObject();
assertNotNull(myNamespace);
Symbol apples = getUniqueSymbol(resultProgram, "apples", myNamespace);
Symbol applesConflict = getUniqueSymbol(resultProgram, "apples_conflict1", myNamespace);
@@ -2651,8 +2654,8 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
// try {
// Function applesFunction =
// program.getFunctionManager().getFunctionAt(addr(program, "01003250"));
-//// createFunction(program, new String[] { "user32.dll", "MyNamespace",
-//// "apples" });
+ //// createFunction(program, new String[] { "user32.dll", "MyNamespace", /
+ /// "apples" });
//
// Function orangesFunction =
// createExternalFunction(program, new String[] { "user32.dll", "MyNamespace",
@@ -2663,11 +2666,10 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
//
// applesFunction.setThunkedFunction(orangesFunction);
//
-//// function.setReturnType(new ByteDataType());
-//// Parameter parameter1 =
-//// new StackParameterImpl("P1", new DWordDataType(), 4,
-//// "Test Parameter Comment", 0, SourceType.USER_DEFINED);
-//// function.addParameter(parameter1, SourceType.USER_DEFINED);
+ //// function.setReturnType(new ByteDataType()); / Parameter parameter1 = /
+ /// new StackParameterImpl("P1", new DWordDataType(), 4, / "Test Parameter
+ /// Comment", 0, SourceType.USER_DEFINED); /
+ /// function.addParameter(parameter1, SourceType.USER_DEFINED);
// String applesName = applesFunction.getName(true);
// String orangesName = orangesFunction.getName(true);
// System.out.println("apples=" + applesName + " oranges=" + orangesName);
@@ -2700,40 +2702,29 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
// */
// @Override
// public void modifyLatest(ProgramDB program) {
-//// int txId = program.startTransaction("Modify Latest Program");
-//// boolean commit = false;
-//// try {
-//// SymbolTable symbolTable = program.getSymbolTable();
-//// Symbol librarySymbol =
-//// symbolTable.getLibrarySymbol("user32.dll");
-//// SymbolType librarySymbolType = librarySymbol.getSymbolType();
-//// assertEquals(SymbolType.LIBRARY, librarySymbolType);
-//// Library externalLibrary = (Library) librarySymbol.getObject();
-////
-//// Symbol namespaceSymbol = symbolTable.getUniqueSymbol("MyNamespace", externalLibrary);
-//// SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
-//// assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
-//// Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
-////
-//// Symbol functionSymbol = symbolTable.getUniqueSymbol("apples", myNamespace);
-//// SymbolType functionSymbolType = functionSymbol.getSymbolType();
-//// assertEquals(SymbolType.FUNCTION, functionSymbolType);
-//// Function function = (Function) functionSymbol.getObject();
-////
-//// assertNotNull(function);
-//// function.setReturnType(new ByteDataType());
-//// Parameter parameter1 =
-//// new StackParameterImpl("P1", new DWordDataType(), 4,
-//// "Test Parameter Comment", 0, SourceType.USER_DEFINED);
-//// function.addParameter(parameter1, SourceType.USER_DEFINED);
-//// commit = true;
-//// }
-//// catch (Exception e) {
-//// Assert.fail(e.getMessage());
-//// }
-//// finally {
-//// program.endTransaction(txId, commit);
-//// }
+ //// int txId = program.startTransaction("Modify Latest Program"); / boolean
+ /// commit = false; / try { / SymbolTable symbolTable =
+ /// program.getSymbolTable(); / Symbol librarySymbol = /
+ /// symbolTable.getLibrarySymbol("user32.dll"); / SymbolType
+ /// librarySymbolType = librarySymbol.getSymbolType(); /
+ /// assertEquals(SymbolType.LIBRARY, librarySymbolType); / Library
+ /// externalLibrary = (Library) librarySymbol.getObject(); / / Symbol
+ /// namespaceSymbol = symbolTable.getUniqueSymbol("MyNamespace",
+ /// externalLibrary); / SymbolType namespaceSymbolType =
+ /// namespaceSymbol.getSymbolType(); / assertEquals(SymbolType.NAMESPACE,
+ /// namespaceSymbolType); / Namespace myNamespace = (Namespace)
+ /// namespaceSymbol.getObject(); / / Symbol functionSymbol =
+ /// symbolTable.getUniqueSymbol("apples", myNamespace); / SymbolType
+ /// functionSymbolType = functionSymbol.getSymbolType(); /
+ /// assertEquals(SymbolType.FUNCTION, functionSymbolType); / Function
+ /// function = (Function) functionSymbol.getObject(); / /
+ /// assertNotNull(function); / function.setReturnType(new ByteDataType()); /
+ /// Parameter parameter1 = / new StackParameterImpl("P1", new
+ /// DWordDataType(), 4, / "Test Parameter Comment", 0,
+ /// SourceType.USER_DEFINED); / function.addParameter(parameter1,
+ /// SourceType.USER_DEFINED); / commit = true; / } / catch (Exception e) { /
+ /// Assert.fail(e.getMessage()); / } / finally { /
+ /// program.endTransaction(txId, commit); / }
// }
//
// /* (non-Javadoc)
@@ -2741,88 +2732,68 @@ public class ExternalMergerTest extends AbstractExternalMergerTest {
// */
// @Override
// public void modifyPrivate(ProgramDB program) {
-//// int txId = program.startTransaction("Modify My Program");
-//// boolean commit = false;
-//// try {
-//// SymbolTable symbolTable = program.getSymbolTable();
-//// Symbol librarySymbol =
-//// symbolTable.getLibrarySymbol("user32.dll");
-//// SymbolType librarySymbolType = librarySymbol.getSymbolType();
-//// assertEquals(SymbolType.LIBRARY, librarySymbolType);
-//// Library externalLibrary = (Library) librarySymbol.getObject();
-////
-//// Symbol namespaceSymbol = symbolTable.getUniqueSymbol("MyNamespace", externalLibrary);
-//// SymbolType namespaceSymbolType = namespaceSymbol.getSymbolType();
-//// assertEquals(SymbolType.NAMESPACE, namespaceSymbolType);
-//// Namespace myNamespace = (Namespace) namespaceSymbol.getObject();
-////
-//// Symbol functionSymbol = symbolTable.getUniqueSymbol("apples", myNamespace);
-//// SymbolType functionSymbolType = functionSymbol.getSymbolType();
-//// assertEquals(SymbolType.FUNCTION, functionSymbolType);
-//// Function function = (Function) functionSymbol.getObject();
-////
-//// assertNotNull(function);
-//// function.setReturnType(new ByteDataType());
-//// function.setReturnType(new FloatDataType());
-//// Register register = program.getRegister("AX");
-//// Parameter parameter1 =
-//// new RegisterParameterImpl(register, "Length", new AsciiDataType(),
-//// "My Parameter Comment", 0, SourceType.USER_DEFINED);
-//// function.addParameter(parameter1, SourceType.USER_DEFINED);
-//// commit = true;
-//// }
-//// catch (Exception e) {
-//// Assert.fail(e.getMessage());
-//// }
-//// finally {
-//// program.endTransaction(txId, commit);
-//// }
+ //// int txId = program.startTransaction("Modify My Program"); / boolean
+ /// commit = false; / try { / SymbolTable symbolTable =
+ /// program.getSymbolTable(); / Symbol librarySymbol = /
+ /// symbolTable.getLibrarySymbol("user32.dll"); / SymbolType
+ /// librarySymbolType = librarySymbol.getSymbolType(); /
+ /// assertEquals(SymbolType.LIBRARY, librarySymbolType); / Library
+ /// externalLibrary = (Library) librarySymbol.getObject(); / / Symbol
+ /// namespaceSymbol = symbolTable.getUniqueSymbol("MyNamespace",
+ /// externalLibrary); / SymbolType namespaceSymbolType =
+ /// namespaceSymbol.getSymbolType(); / assertEquals(SymbolType.NAMESPACE,
+ /// namespaceSymbolType); / Namespace myNamespace = (Namespace)
+ /// namespaceSymbol.getObject(); / / Symbol functionSymbol =
+ /// symbolTable.getUniqueSymbol("apples", myNamespace); / SymbolType
+ /// functionSymbolType = functionSymbol.getSymbolType(); /
+ /// assertEquals(SymbolType.FUNCTION, functionSymbolType); / Function
+ /// function = (Function) functionSymbol.getObject(); / /
+ /// assertNotNull(function); / function.setReturnType(new ByteDataType()); /
+ /// function.setReturnType(new FloatDataType()); / Register register =
+ /// program.getRegister("AX"); / Parameter parameter1 = / new
+ /// RegisterParameterImpl(register, "Length", new AsciiDataType(), / "My
+ /// Parameter Comment", 0, SourceType.USER_DEFINED); /
+ /// function.addParameter(parameter1, SourceType.USER_DEFINED); / commit =
+ /// true; / } / catch (Exception e) { / Assert.fail(e.getMessage()); / } /
+ /// finally { / program.endTransaction(txId, commit); / }
// }
// });
//
// executeMerge(ASK_USER);
-//// chooseRadioButton(MY_BUTTON);
-//// chooseVariousOptions(new int[] { INFO_ROW, KEEP_MY });
+ //// chooseRadioButton(MY_BUTTON); / chooseVariousOptions(new int[] {
+ /// INFO_ROW, KEEP_MY });
// waitForMergeCompletion(5000);
//
-//// Namespace externalLibrary =
-//// (Namespace) resultProgram.getSymbolTable().getUniqueSymbol("user32.dll",
-//// resultProgram.getGlobalNamespace()).getObject();
-//// assertNotNull(externalLibrary);
-//// Namespace myNamespace =
-//// (Namespace) resultProgram.getSymbolTable().getUniqueSymbol("MyNamespace", externalLibrary).getObject();
-//// assertNotNull(myNamespace);
-//// SymbolTable symtab = resultProgram.getSymbolTable();
-//// Symbol apples = symtab.getUniqueSymbol("thunk_oranges", myNamespace);
-//// Symbol oranges = symtab.getUniqueSymbol("oranges", myNamespace);
-//// assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
-//// assertEquals(SymbolType.FUNCTION, oranges.getSymbolType());
-//// Function function = (Function) apples.getObject();
-//// assertEquals(true, function.isThunk());
-//// checkFunctionReturnType(function, new FloatDataType());
-//// assertEquals(1, function.getParameterCount());
-//// Parameter parameter = function.getParameter(0);
-//// assertEquals("Length", parameter.getName());
-//// assertEquals("My Parameter Comment", parameter.getComment());
-//// checkParameterDataType(parameter, new AsciiDataType());
-//// assertTrue(parameter.isRegisterVariable());
+ //// Namespace externalLibrary = / (Namespace)
+ /// resultProgram.getSymbolTable().getUniqueSymbol("user32.dll", /
+ /// resultProgram.getGlobalNamespace()).getObject(); /
+ /// assertNotNull(externalLibrary); / Namespace myNamespace = / (Namespace)
+ /// resultProgram.getSymbolTable().getUniqueSymbol("MyNamespace",
+ /// externalLibrary).getObject(); / assertNotNull(myNamespace); / SymbolTable
+ /// symtab = resultProgram.getSymbolTable(); / Symbol apples =
+ /// symtab.getUniqueSymbol("thunk_oranges", myNamespace); / Symbol oranges =
+ /// symtab.getUniqueSymbol("oranges", myNamespace); /
+ /// assertEquals(SymbolType.FUNCTION, apples.getSymbolType()); /
+ /// assertEquals(SymbolType.FUNCTION, oranges.getSymbolType()); / Function
+ /// function = (Function) apples.getObject(); / assertEquals(true,
+ /// function.isThunk()); / checkFunctionReturnType(function, new
+ /// FloatDataType()); / assertEquals(1, function.getParameterCount()); /
+ /// Parameter parameter = function.getParameter(0); / assertEquals("Length",
+ /// parameter.getName()); / assertEquals("My Parameter Comment",
+ /// parameter.getComment()); / checkParameterDataType(parameter, new
+ /// AsciiDataType()); / assertTrue(parameter.isRegisterVariable());
// }
-/// public void testExtRefRemoveNoConflict() throws Exception {
-// // External Refs
-// // 01001000: op1 to ADVAPI32.DLL IsTextUnicode 77dc4f85
-// // 01001004: op1 to ADVAPI32.DLL RegCreateKeyW 77db90b0
-// // 01001008: op1 to ADVAPI32.DLL RegQueryValueExW 77db8078
-// // 0100100c: op1 to ADVAPI32.DLL RegSetValueExW 77db9348
-// // 01001010: op1 to ADVAPI32.DLL RegOpenKeyExA 77db82ac
-// // 01001014: op1 to ADVAPI32.DLL RegQueryValueExA 77db858e
-// // 01001018: op1 to ADVAPI32.DLL RegCloseKey 77db7d4d
-// // 0100101c: no ref
-// // 010010c0: op1 to KERNEL32.DLL LocalFree 77e9499c
-// // 010010c4: op1 to KERNEL32.DLL GetProcAddress 77e9564b
-// // 010013cc: no ref (has string)
-// // 010013d8: no ref (has string)
-// // 010013f0: no ref (has string)
+ /// public void testExtRefRemoveNoConflict() throws Exception { // External
+ /// Refs // 01001000: op1 to ADVAPI32.DLL IsTextUnicode 77dc4f85 // 01001004:
+ /// op1 to ADVAPI32.DLL RegCreateKeyW 77db90b0 // 01001008: op1 to
+ /// ADVAPI32.DLL RegQueryValueExW 77db8078 // 0100100c: op1 to ADVAPI32.DLL
+ /// RegSetValueExW 77db9348 // 01001010: op1 to ADVAPI32.DLL RegOpenKeyExA
+ /// 77db82ac // 01001014: op1 to ADVAPI32.DLL RegQueryValueExA 77db858e //
+ /// 01001018: op1 to ADVAPI32.DLL RegCloseKey 77db7d4d // 0100101c: no ref //
+ /// 010010c0: op1 to KERNEL32.DLL LocalFree 77e9499c // 010010c4: op1 to
+ /// KERNEL32.DLL GetProcAddress 77e9564b // 010013cc: no ref (has string) //
+ /// 010013d8: no ref (has string) // 010013f0: no ref (has string)
//
// mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
//
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalProgramMergerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalProgramMergerTest.java
index 8e71eec575..b548d1bc2a 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalProgramMergerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalProgramMergerTest.java
@@ -562,12 +562,9 @@ public class ExternalProgramMergerTest extends AbstractListingMergeManagerTest {
// assertNotNull(window);
// try {
// pressButtonByName(comp, componentName, false);
-//// if (componentName.equals(LATEST_BUTTON)) {
-//// sleep(1000);
-//// pressButtonByName(comp, MY_BUTTON, false);
-//// sleep(1000);
-//// pressButtonByName(comp, LATEST_BUTTON, false);
-//// }
+ //// if (componentName.equals(LATEST_BUTTON)) { / sleep(1000); /
+ /// pressButtonByName(comp, MY_BUTTON, false); / sleep(1000); /
+ /// pressButtonByName(comp, LATEST_BUTTON, false); / }
// waitForApply(window, true, 2000);
// pressButtonByText(window, "Apply");
// waitForSwing();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalUseForAllTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalUseForAllTest.java
index 798ee25fa5..6ae0fcb308 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalUseForAllTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/ExternalUseForAllTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -310,7 +310,6 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
"77db1120", SourceType.USER_DEFINED);
}
-
@Override
public void modifyLatest(ProgramDB program) {
try {
@@ -611,10 +610,10 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
checkConflictPanelTitle("Resolve External Detail Conflict", VariousChoicesPanel.class);
- chooseVariousExternalOptions("user32.dll::Blue", new int[] { INFO_ROW, KEEP_MY }, false);
+ chooseVariousExternalOptions("Blue", new int[] { INFO_ROW, KEEP_MY }, false);
checkConflictPanelTitle("Resolve External Detail Conflict", VariousChoicesPanel.class);
- chooseVariousExternalOptions("user32.dll::Oranges", new int[] { INFO_ROW, KEEP_LATEST },
+ chooseVariousExternalOptions("Oranges", new int[] { INFO_ROW, KEEP_LATEST },
false);
waitForMergeCompletion();
@@ -640,7 +639,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
executeMerge(ASK_USER);
checkConflictPanelTitle("Resolve External Detail Conflict", VariousChoicesPanel.class);
- chooseVariousExternalOptions("user32.dll::Blue", new int[] { INFO_ROW, KEEP_MY }, true);
+ chooseVariousExternalOptions("Blue", new int[] { INFO_ROW, KEEP_MY }, true);
// checkConflictPanelTitle("Resolve External Detail Conflict", VariousChoicesPanel.class);
// chooseVariousExternalOptions("user32.dll::Oranges", new int[] { INFO_ROW, KEEP_MY }, false); // handled by Use For All
@@ -660,14 +659,14 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
checkExternalAddress(externalLocation2, "77db1080");
}
- private void setupExternalFunctionRemoveUseForAll(final String[] applesPath,
- final String[] orangesPath) throws Exception {
+ private void setupExternalFunctionRemoveUseForAll(String library, String[] applesPath,
+ String[] orangesPath) throws Exception {
mtf.initialize("WallaceSrc", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -677,7 +676,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
parameter2.setComment("Other Comment");
applesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -688,11 +687,11 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setComment("Once upon a time...");
applesFunction.setNoReturn(true);
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter1 =
new ParameterImpl("stuff", new ByteDataType(), 4, program);
parameter1.setComment("Long ago in a land far, far away");
@@ -702,14 +701,15 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
assertEquals(2, applesFunction.getParameterCount());
assertEquals("Once upon a time...", applesFunction.getComment());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -720,19 +720,20 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.getSymbol().delete();// Remove the function, but not the external location.
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.getSymbol().delete();// Remove the function, but not the external location.
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertEquals(false, applesLocation.isFunction());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(false, orangesLocation.isFunction());
}
@@ -741,17 +742,18 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionRemoveConflictDontUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ final String[] applesPath = new String[] { "Class1", "apples" };
+ final String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupExternalFunctionRemoveUseForAll(applesPath, orangesPath);
+ setupExternalFunctionRemoveUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve External Function Remove Conflict", LATEST_BUTTON, false);
chooseButtonAndApply("Resolve External Function Remove Conflict", LATEST_BUTTON, false);
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -770,7 +772,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals("P2", parameter2.getName());
assertEquals(8, parameter2.getStackOffset());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(true, orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -786,36 +788,37 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionRemoveConflictUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupExternalFunctionRemoveUseForAll(applesPath, orangesPath);
+ setupExternalFunctionRemoveUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve External Function Remove Conflict", MY_BUTTON, true);
// chooseButtonAndApply("Resolve External Function Remove Conflict", MY_BUTTON, false);
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertFalse(applesLocation.isFunction());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertEquals(false, orangesLocation.isFunction());
}
- private void setupParameterSignatureUseForAll(final String[] applesPath,
- final String[] orangesPath) throws Exception {
+ private void setupParameterSignatureUseForAll(String library, String[] applesPath,
+ String[] orangesPath) throws Exception {
mtf.initialize("WallaceSrc", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalFunction(program, orangesPath, addr(program, "00cc5566"),
+ createExternalFunction(program, library, orangesPath, addr(program, "00cc5566"),
new DWordDataType(), SourceType.USER_DEFINED);
- createExternalFunction(program, applesPath, addr(program, "00cc7788"),
+ createExternalFunction(program, library, applesPath, addr(program, "00cc7788"),
new FloatDataType(), SourceType.USER_DEFINED);
}
catch (Exception e) {
@@ -826,7 +829,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(false);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -837,7 +840,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
new VariableStorage(program, program.getRegister("BX")), program);
orangesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setCustomVariableStorage(false);
Parameter parameterA = new ParameterImpl("type", new WordDataType(), program);
applesFunction.addParameter(parameterA, SourceType.USER_DEFINED);
@@ -849,7 +852,8 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -859,7 +863,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("junk", new WordDataType(),
@@ -870,7 +874,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
new VariableStorage(program, program.getRegister("BX")), program);
orangesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setCustomVariableStorage(true);
Parameter parameterA = new ParameterImpl("type", new WordDataType(), program);
applesFunction.addParameter(parameterA, SourceType.USER_DEFINED);
@@ -882,13 +886,15 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
assertEquals(2, orangesFunction.getParameterCount());
- ExternalLocation applesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation applesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -899,17 +905,18 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionParameterSignatureConflictDontUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupParameterSignatureUseForAll(applesPath, orangesPath);
+ setupParameterSignatureUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve Function Parameters Conflict", MY_BUTTON, false);
chooseButtonAndApply("Resolve Function Parameters Conflict", LATEST_BUTTON, false);
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -928,7 +935,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals(resultProgram.getRegister("BX"), parameter2.getRegister());
assertFalse(parameter2.isStackVariable());
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -963,17 +970,18 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionParameterSignatureConflictUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ final String[] applesPath = new String[] { "Class1", "apples" };
+ final String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupParameterSignatureUseForAll(applesPath, orangesPath);
+ setupParameterSignatureUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve Function Parameters Conflict", MY_BUTTON, true);
// chooseButtonAndApply("Resolve Function Parameters Conflict", MY_BUTTON, false); // Handled by Use For All
waitForMergeCompletion();
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -992,7 +1000,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals(resultProgram.getRegister("BX"), parameter2.getRegister());
assertFalse(parameter2.isStackVariable());
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -1023,14 +1031,14 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals(VariableStorage.UNASSIGNED_STORAGE, parameterB.getVariableStorage());
}
- private void setupExternalParameterInfoUseForAll(final String[] applesPath,
+ private void setupExternalParameterInfoUseForAll(String library, String[] applesPath,
final String[] orangesPath) throws Exception {
mtf.initialize("WallaceSrc", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
applesFunction.setCustomVariableStorage(true);
Parameter parameter1 = new ParameterImpl("P1", new DWordDataType(), 4, program);
@@ -1040,7 +1048,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
parameter2.setComment("Other Comment");
applesFunction.addParameter(parameter2, SourceType.USER_DEFINED);
- Function orangesFunction = createExternalFunction(program, orangesPath,
+ Function orangesFunction = createExternalFunction(program, library, orangesPath,
addr(program, "77db1234"), new FloatDataType(), SourceType.IMPORTED);
orangesFunction.setCustomVariableStorage(true);
Parameter parameterA = new ParameterImpl("A1", new DWordDataType(), 4, program);
@@ -1055,12 +1063,12 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setName("LatestP1", SourceType.USER_DEFINED);
applesParameter1.setComment("Once upon a time...");
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter = orangesFunction.getParameter(0);
parameter.setName("B1", SourceType.USER_DEFINED);
parameter.setComment("Latest comment.");
@@ -1069,7 +1077,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -1077,7 +1085,8 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Parameter applesParameter1 = applesFunction.getParameter(0);
assertEquals("Once upon a time...", applesParameter1.getComment());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1090,12 +1099,12 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
Parameter applesParameter1 = applesFunction.getParameter(0);
applesParameter1.setName("MyP1", SourceType.USER_DEFINED);
applesParameter1.setComment("This is a sample parameter comment.");
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
Parameter parameter = orangesFunction.getParameter(0);
parameter.setName("C1", SourceType.USER_DEFINED);
parameter.setComment("My comment.");
@@ -1104,7 +1113,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- ExternalLocation applesLocation = getExternalLocation(program, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(program, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -1116,7 +1125,8 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals("Other Comment", applesParameter2.getComment());
assertEquals("P2", applesParameter2.getName());
- ExternalLocation orangesLocation = getExternalLocation(program, orangesPath);
+ ExternalLocation orangesLocation =
+ getExternalLocation(program, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1130,10 +1140,11 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalParameterInfoConflictDontUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupExternalParameterInfoUseForAll(applesPath, orangesPath);
+ setupExternalParameterInfoUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
@@ -1145,7 +1156,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -1164,7 +1175,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals("Other Comment", parameter2.getComment());
assertEquals(8, parameter2.getStackOffset());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1180,10 +1191,11 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalParameterInfoConflictUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupExternalParameterInfoUseForAll(applesPath, orangesPath);
+ setupExternalParameterInfoUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
@@ -1195,7 +1207,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
- ExternalLocation applesLocation = getExternalLocation(resultProgram, applesPath);
+ ExternalLocation applesLocation = getExternalLocation(resultProgram, library, applesPath);
assertNotNull(applesLocation);
assertTrue(applesLocation.isFunction());
Function applesFunction = applesLocation.getFunction();
@@ -1214,7 +1226,7 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals("Other Comment", parameter2.getComment());
assertEquals(8, parameter2.getStackOffset());
- ExternalLocation orangesLocation = getExternalLocation(resultProgram, orangesPath);
+ ExternalLocation orangesLocation = getExternalLocation(resultProgram, library, orangesPath);
assertNotNull(orangesLocation);
assertTrue(orangesLocation.isFunction());
Function orangesFunction = orangesLocation.getFunction();
@@ -1228,19 +1240,20 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
assertEquals(4, parameterA.getStackOffset());
}
- private void setupExternalReturnTypeUseForAll(final String[] applesPath,
+ private void setupExternalReturnTypeUseForAll(String library, String[] applesPath,
final String[] orangesPath) throws Exception {
mtf.initialize("NotepadMergeListingTest", new OriginalProgramModifierListener() {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- Function applesFunction = createExternalFunction(program, applesPath,
+ Function applesFunction = createExternalFunction(program, library, applesPath,
addr(program, "77db1020"), new FloatDataType(), SourceType.ANALYSIS);
assertNotNull(applesFunction);
Function orangesFunction =
- createExternalFunction(program, orangesPath, addr(program, "77db1270"),
+ createExternalFunction(program, library, orangesPath,
+ addr(program, "77db1270"),
new PointerDataType(new StringDataType()), SourceType.ANALYSIS);
assertNotNull(orangesFunction);
}
@@ -1252,10 +1265,10 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Override
public void modifyLatest(ProgramDB program) {
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setReturnType(new LongDataType(), SourceType.USER_DEFINED);
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setReturnType(new PointerDataType(new LongDataType()),
SourceType.USER_DEFINED);
}
@@ -1263,11 +1276,11 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
assertEquals(0, applesFunction.getParameterCount());
checkDataType(new LongDataType(), applesFunction.getReturnType());
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
assertEquals(0, orangesFunction.getParameterCount());
checkDataType(new PointerDataType(new LongDataType()),
orangesFunction.getReturnType());
@@ -1279,10 +1292,10 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
DataType typedefDT = new TypedefDataType(path, "long", new LongDataType(),
program.getDataTypeManager());
try {
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
applesFunction.setReturnType(typedefDT, SourceType.USER_DEFINED);
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
orangesFunction.setReturnType(new PointerDataType(new ByteDataType()),
SourceType.USER_DEFINED);
}
@@ -1290,11 +1303,11 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
- Function applesFunction = getExternalFunction(program, applesPath);
+ Function applesFunction = getExternalFunction(program, library, applesPath);
assertEquals(0, applesFunction.getParameterCount());
checkDataType(typedefDT, applesFunction.getReturnType());
- Function orangesFunction = getExternalFunction(program, orangesPath);
+ Function orangesFunction = getExternalFunction(program, library, orangesPath);
assertEquals(0, orangesFunction.getParameterCount());
checkDataType(new PointerDataType(new ByteDataType()),
orangesFunction.getReturnType());
@@ -1304,25 +1317,25 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionReturnTypeDontUseForAll() throws Exception {
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
-
- setupExternalReturnTypeUseForAll(applesPath, orangesPath);
+ setupExternalReturnTypeUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve Function Return Conflict", MY_BUTTON, false);
chooseButtonAndApply("Resolve Function Return Conflict", LATEST_BUTTON, false);
waitForMergeCompletion();
- Function applesFunction = getExternalFunction(resultProgram, applesPath);
+ Function applesFunction = getExternalFunction(resultProgram, library, applesPath);
assertEquals(0, applesFunction.getParameterCount());
CategoryPath path = new CategoryPath("/");
DataType typedefDT = new TypedefDataType(path, "long.conflict", new LongDataType(),
resultProgram.getDataTypeManager());
checkDataType(typedefDT, applesFunction.getReturnType());
- Function orangesFunction = getExternalFunction(resultProgram, orangesPath);
+ Function orangesFunction = getExternalFunction(resultProgram, library, orangesPath);
assertEquals(0, orangesFunction.getParameterCount());
checkDataType(new PointerDataType(new LongDataType()), orangesFunction.getReturnType());
}
@@ -1330,24 +1343,25 @@ public class ExternalUseForAllTest extends AbstractExternalMergerTest {
@Test
public void testExternalFunctionReturnTypeUseForAll() throws Exception {
- final String[] applesPath = new String[] { "user32.dll", "Class1", "apples" };
- final String[] orangesPath = new String[] { "user32.dll", "NamespaceA", "oranges" };
+ String library = "user32.dll";
+ String[] applesPath = new String[] { "Class1", "apples" };
+ String[] orangesPath = new String[] { "NamespaceA", "oranges" };
- setupExternalReturnTypeUseForAll(applesPath, orangesPath);
+ setupExternalReturnTypeUseForAll(library, applesPath, orangesPath);
executeMerge(ASK_USER);
chooseButtonAndApply("Resolve Function Return Conflict", MY_BUTTON, true);
// chooseButtonAndApply("Resolve Function Return Conflict", MY_BUTTON, false); // Handled by Use For All.
waitForMergeCompletion();
- Function applesFunction = getExternalFunction(resultProgram, applesPath);
+ Function applesFunction = getExternalFunction(resultProgram, library, applesPath);
assertEquals(0, applesFunction.getParameterCount());
CategoryPath path = new CategoryPath("/");
DataType typedefDT = new TypedefDataType(path, "long.conflict", new LongDataType(),
resultProgram.getDataTypeManager());
checkDataType(typedefDT, applesFunction.getReturnType());
- Function orangesFunction = getExternalFunction(resultProgram, orangesPath);
+ Function orangesFunction = getExternalFunction(resultProgram, library, orangesPath);
assertEquals(0, orangesFunction.getParameterCount());
checkDataType(new PointerDataType(new ByteDataType()), orangesFunction.getReturnType());
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunk2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunk2Test.java
index 4150ad2a26..a87959aecd 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunk2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunk2Test.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -84,8 +84,8 @@ public class FunctionMergerThunk2Test extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, new DWordDataType());
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, new DWordDataType());
// Create a thunk to the function with no params.
AddressSet body =
@@ -114,7 +114,7 @@ public class FunctionMergerThunk2Test extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
}
@Test
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunkTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunkTest.java
index 6eb549428f..264cb595ae 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunkTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/FunctionMergerThunkTest.java
@@ -200,8 +200,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, new DWordDataType());
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, new DWordDataType());
// Create a thunk to the function with no params.
AddressSet body =
@@ -682,8 +682,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -705,8 +705,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, new DWordDataType());
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, new DWordDataType());
// Create a thunk to the function with no params.
AddressSet body =
@@ -734,7 +734,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1130"), externalLocation.getAddress());
}
@@ -748,8 +749,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1020"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1020"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -771,8 +772,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -802,7 +803,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1020"), externalLocation.getAddress());
}
@@ -816,8 +818,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1020"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1020"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -839,8 +841,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -870,7 +872,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1130"), externalLocation.getAddress());
}
@@ -884,8 +887,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1020"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1020"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -907,8 +910,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -940,7 +943,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1020"), externalLocation.getAddress());
@@ -959,8 +963,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1020"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1020"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -982,8 +986,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -1014,7 +1018,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1020"), externalLocation.getAddress());
}
@@ -1028,8 +1033,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1020"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1020"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -1051,8 +1056,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -1083,7 +1088,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1130"), externalLocation.getAddress());
}
@@ -1097,8 +1103,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -1120,8 +1126,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "scanf" }, new DWordDataType());
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "scanf" }, new DWordDataType());
// Create a thunk to the function with no params.
AddressSet body =
@@ -1150,7 +1156,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::printf", thunkedFunction.getName(true));
+ assertEquals("printf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertEquals(addr(resultProgram, "77db1130"), externalLocation.getAddress());
}
@@ -1164,8 +1171,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
public void modifyLatest(ProgramDB program) {
// Change the Latest program which will also be used for Result program.
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "printf" }, addr(program, "77db1130"),
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "printf" }, addr(program, "77db1130"),
new DWordDataType(), SourceType.USER_DEFINED);
// Create a thunk to the function with no params.
@@ -1187,8 +1194,8 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
@Override
public void modifyPrivate(ProgramDB program) {
try {
- Function externalFunction = createExternalFunction(program,
- new String[] { "user32.dll", "scanf" }, new DWordDataType());
+ Function externalFunction = createExternalFunction(program, "user32.dll",
+ new String[] { "scanf" }, new DWordDataType());
// Create a thunk to the function with no params.
AddressSet body =
@@ -1217,7 +1224,9 @@ public class FunctionMergerThunkTest extends AbstractExternalMergerTest {
Function thunkedFunction = thunkFunction.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("user32.dll::scanf", thunkedFunction.getName(true));
+ assertEquals("scanf", thunkedFunction.getName(true));
+ assertEquals("user32.dll", thunkedFunction.getSymbol().getLibrary().getName());
+
ExternalLocation externalLocation = thunkedFunction.getExternalLocation();
assertNull(externalLocation.getAddress());
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/RefMergerExtTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/RefMergerExtTest.java
index f88d00fac1..7a2aa9c945 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/RefMergerExtTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/merge/listing/RefMergerExtTest.java
@@ -323,16 +323,16 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, new String[] { "Library", "Namespace", "Label1" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Label1" },
addr(program, "77db1020"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Label2" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Label2" },
addr(program, "77db1130"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Foo" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Foo" },
addr(program, "77db1020"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Bar" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Bar" },
addr(program, "77db1130"), SourceType.ANALYSIS);
}
catch (Exception e) {
@@ -346,10 +346,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
ReferenceManager refMgr = program.getReferenceManager();
Reference[] refs;
- ExternalLocation extLoc1 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label1" });
- ExternalLocation extLoc2 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label2" });
+ ExternalLocation extLoc1 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label1" });
+ ExternalLocation extLoc2 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label2" });
refs = refMgr.getReferencesFrom(addr(program, "0x1001000"), 0);
assertEquals(1, refs.length);
@@ -380,10 +380,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
ReferenceManager refMgr = program.getReferenceManager();
Reference[] refs;
- ExternalLocation extLoc1 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Foo" });
- ExternalLocation extLoc2 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Bar" });
+ ExternalLocation extLoc1 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Foo" });
+ ExternalLocation extLoc2 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Bar" });
refs = refMgr.getReferencesFrom(addr(program, "0x1001000"), 0);
assertEquals(1, refs.length);
@@ -449,16 +449,16 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
@Override
public void modifyOriginal(ProgramDB program) {
try {
- createExternalLabel(program, new String[] { "Library", "Namespace", "Label1" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Label1" },
addr(program, "77db1020"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Label2" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Label2" },
addr(program, "77db1130"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Foo" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Foo" },
addr(program, "77db1020"), SourceType.ANALYSIS);
- createExternalLabel(program, new String[] { "Library", "Namespace", "Bar" },
+ createExternalLabel(program, "Library", new String[] { "Namespace", "Bar" },
addr(program, "77db1130"), SourceType.ANALYSIS);
}
catch (Exception e) {
@@ -472,10 +472,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
ReferenceManager refMgr = program.getReferenceManager();
Reference[] refs;
- ExternalLocation extLoc1 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label1" });
- ExternalLocation extLoc2 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label2" });
+ ExternalLocation extLoc1 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label1" });
+ ExternalLocation extLoc2 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label2" });
refs = refMgr.getReferencesFrom(addr(program, "0x1001000"), 0);
assertEquals(1, refs.length);
@@ -506,10 +506,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
ReferenceManager refMgr = program.getReferenceManager();
Reference[] refs;
- ExternalLocation extLoc1 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Foo" });
- ExternalLocation extLoc2 = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Bar" });
+ ExternalLocation extLoc1 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Foo" });
+ ExternalLocation extLoc2 = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Bar" });
refs = refMgr.getReferencesFrom(addr(program, "0x1001000"), 0);
assertEquals(1, refs.length);
@@ -562,7 +562,7 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
public void modifyOriginal(ProgramDB program) {
try {
ExternalLocation extLoc = createExternalLabel(program,
- new String[] { "Library", "Namespace", "Label1" },
+ "Library", new String[] { "Namespace", "Label1" },
addr(program, "77db1020"), SourceType.ANALYSIS);
ReferenceManager refMgr = program.getReferenceManager();
@@ -586,8 +586,8 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
try {
ReferenceManager refMgr = program.getReferenceManager();
- ExternalLocation extLoc = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label1" });
+ ExternalLocation extLoc = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label1" });
refMgr.addExternalReference(addr(program, "0x1001000"), 0, extLoc,
extLoc.getSource(), RefType.COMPUTED_CALL);
@@ -602,8 +602,8 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
try {
ReferenceManager refMgr = program.getReferenceManager();
- ExternalLocation extLoc = getExternalLocation(program,
- new String[] { "Library", "Namespace", "Label1" });
+ ExternalLocation extLoc = getExternalLocation(program, "Library",
+ new String[] { "Namespace", "Label1" });
refMgr.addExternalReference(addr(program, "0x1001000"), 0, extLoc,
extLoc.getSource(), RefType.COMPUTED_CALL_TERMINATOR);
@@ -1090,10 +1090,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
}
ExternalLocation externalLocation1 =
- getExternalLocation(program, new String[] { "USER32.DLL", "printf" });
+ getExternalLocation(program, "USER32.DLL", new String[] { "printf" });
assertNotNull(externalLocation1);
ExternalLocation externalLocation2 =
- getExternalLocation(program, new String[] { "ADVAPI32.DLL", "EXT_77db2233" });
+ getExternalLocation(program, "ADVAPI32.DLL", new String[] { "EXT_77db2233" });
assertNotNull(externalLocation2);
}
@@ -1117,7 +1117,7 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
ExternalLocation externalLocation2 =
- getExternalLocation(program, new String[] { "USER32.DLL", "getName" });
+ getExternalLocation(program, "USER32.DLL", new String[] { "getName" });
assertNotNull(externalLocation2);
}
});
@@ -1127,10 +1127,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
ExternalLocation externalLocation1 =
- getExternalLocation(resultProgram, new String[] { "ADVAPI32.DLL", "EXT_77db2233" });
+ getExternalLocation(resultProgram, "ADVAPI32.DLL", new String[] { "EXT_77db2233" });
assertNotNull(externalLocation1);
ExternalLocation externalLocation2 =
- getExternalLocation(resultProgram, new String[] { "USER32.DLL", "getName" });
+ getExternalLocation(resultProgram, "USER32.DLL", new String[] { "getName" });
assertNotNull(externalLocation2);
ReferenceManager refMgr = resultProgram.getReferenceManager();
@@ -1192,10 +1192,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
}
ExternalLocation externalLocation1 =
- getExternalLocation(program, new String[] { "USER32.DLL", "printf" });
+ getExternalLocation(program, "USER32.DLL", new String[] { "printf" });
assertNotNull(externalLocation1);
ExternalLocation externalLocation2 =
- getExternalLocation(program, new String[] { "ADVAPI32.DLL", "EXT_77db2233" });
+ getExternalLocation(program, "ADVAPI32.DLL", new String[] { "EXT_77db2233" });
assertNotNull(externalLocation2);
}
@@ -1219,7 +1219,7 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
Assert.fail(e.getMessage());
}
ExternalLocation externalLocation2 =
- getExternalLocation(program, new String[] { "USER32.DLL", "getName" });
+ getExternalLocation(program, "USER32.DLL", new String[] { "getName" });
assertNotNull(externalLocation2);
}
});
@@ -1229,10 +1229,10 @@ public class RefMergerExtTest extends AbstractExternalMergerTest {
waitForMergeCompletion();
ExternalLocation externalLocation1 =
- getExternalLocation(resultProgram, new String[] { "ADVAPI32.DLL", "EXT_77db2233" });
+ getExternalLocation(resultProgram, "ADVAPI32.DLL", new String[] { "EXT_77db2233" });
assertNotNull(externalLocation1);
ExternalLocation externalLocation2 =
- getExternalLocation(resultProgram, new String[] { "USER32.DLL", "getName" });
+ getExternalLocation(resultProgram, "USER32.DLL", new String[] { "getName" });
assertNotNull(externalLocation2);
ReferenceManager refMgr = resultProgram.getReferenceManager();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/codebrowser/CodeBrowserOptionsTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/codebrowser/CodeBrowserOptionsTest.java
index 97bbbc5c6c..d804d07688 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/codebrowser/CodeBrowserOptionsTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/codebrowser/CodeBrowserOptionsTest.java
@@ -862,13 +862,13 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
cb.goToField(addr("0x1003daa"), "Operands", 0, 0);
btf = (ListingTextField) cb.getCurrentField();
- assertEquals("TestLib::ExtNS::ExtLab", btf.getText());
+ assertEquals("TestLib:ExtNS::ExtLab", btf.getText());
cb.goToField(addr("0x1001012"), "Operands", 0, 0);
btf = (ListingTextField) cb.getCurrentField();
- assertEquals("->TestLib::ExtNS::ExtLab", btf.getText());
+ assertEquals("->TestLib:ExtNS::ExtLab", btf.getText());
- namespaceOption.setShowLibraryInNamespace(false);
+ namespaceOption.setShowLibrary(false);
options.setCustomOption(names.get(3), namespaceOption);
cb.updateNow();
@@ -880,7 +880,7 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
btf = (ListingTextField) cb.getCurrentField();
assertEquals("->ExtNS::ExtLab", btf.getText());
- namespaceOption.setShowLibraryInNamespace(true);
+ namespaceOption.setShowLibrary(false);
namespaceOption.setShowNonLocalNamespace(false);
options.setCustomOption(names.get(3), namespaceOption);
cb.updateNow();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java
index 21df9e1294..58222932dd 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java
@@ -212,10 +212,9 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe
// select "New Category" action
DataTypeTestUtils.performAction(action, tree, false);
+ waitForEditing();
runSwing(() -> jTree.stopEditing());
- waitForSwing();
-
waitForTree();
// verify that the tree opens a new node with the default
@@ -1702,6 +1701,14 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe
waitForTree(tree);
}
+ private void waitForEditing() throws Exception {
+ int cnt = 0;
+ while (!tree.isEditing()) {
+ Thread.sleep(100);
+ assertTrue("Timed-out waiting for tree to edit", ++cnt < 50);
+ }
+ }
+
private class SpyAction extends AbstractAction {
private Action defaultAction;
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java
index b78035a9bc..d081ef0f21 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java
@@ -163,7 +163,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
assertTrue(editComment.isEnabledForContext(actionContext));
assertFalse(deleteComment.isEnabledForContext(actionContext));
- createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
assertTrue(cb.goToField(addr("0x10030d2"), "Function Signature", 0, 0));
actionContext = cb.getProvider().getActionContext(null);
@@ -207,7 +207,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
assertNull(program.getListing().getFunctionAt(addr("0x1006420")));
- Function thunk = createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ Function thunk = createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
cb.goToField(addr("0x10030d2"), "Function Signature", 0, 0);
assertEquals("thunk undefined CommDlgExtendedError()", cb.getCurrentFieldText());
@@ -243,7 +243,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
createLabel(addr("0x10030d2"), "Foo");
- Function thunk = createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ Function thunk = createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
cb.goToField(addr("0x10030d2"), "Function Signature", 0, 0);
assertEquals("thunk undefined Foo()", cb.getCurrentFieldText());
@@ -315,7 +315,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
env.showTool();
loadProgram("notepad");
- createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
assertTrue(cb.goToField(addr("0x10030d2"), "Function Signature", 0, 0));
@@ -325,8 +325,8 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
waitForDialogComponent(ThunkReferenceAddressDialog.class);
assertNotNull(thunkDlg);
JTextField thunkedEntryField = findComponent(thunkDlg, JTextField.class);
- assertEquals("comdlg32.dll::CommDlgExtendedError", thunkedEntryField.getText());
- setText(thunkedEntryField, "ADVAPI32.dll::RegQueryValueExW");
+ assertEquals("CommDlgExtendedError", thunkedEntryField.getText());
+ setText(thunkedEntryField, "RegQueryValueExW");
pressButtonByText(thunkDlg, "OK");
waitForSwing();
waitForBusyTool();
@@ -352,7 +352,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
env.showTool();
loadProgram("notepad");
- Function func = createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ Function func = createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
assertTrue(cb.goToField(addr("0x10030d2"), "Function Signature", 0, 0));
assertTrue(func.isThunk());
@@ -415,7 +415,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
assertNotNull(thunkDlg);
JTextField thunkedEntryField = findComponent(thunkDlg, JTextField.class);
assertEquals("", thunkedEntryField.getText());
- setText(thunkedEntryField, "ADVAPI32.dll::RegQueryValueExW");
+ setText(thunkedEntryField, "RegQueryValueExW");
pressButtonByText(thunkDlg, "OK");
waitForSwing();
waitForBusyTool();
@@ -444,7 +444,7 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {
env.showTool();
loadProgram("notepad");
- createThunk(addr("0x10030d2"), "comdlg32.dll::CommDlgExtendedError", true);
+ createThunk(addr("0x10030d2"), "CommDlgExtendedError", true);
assertTrue(cb.goToField(addr("0x10030d2"), "Address", 0, 0));
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialogTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialogTest.java
index 33a664779d..f51841f1bf 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialogTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/ThunkReferenceAddressDialogTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,20 +17,23 @@ package ghidra.app.plugin.core.function;
import static org.junit.Assert.*;
+import java.util.List;
+
import javax.swing.JTextField;
import org.junit.*;
-import docking.AbstractErrDialog;
import docking.ActionContext;
import docking.action.DockingActionIf;
+import docking.widgets.dialogs.ObjectChooserDialog;
+import docking.widgets.table.GTableWidget;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.util.viewer.field.FunctionSignatureFieldFactory;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.*;
import ghidra.test.*;
public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegrationTest {
@@ -44,12 +47,13 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
private DockingActionIf revertThunk;
private Program program;
+ private ClassicSampleX86ProgramBuilder builder;
@Before
public void setUp() throws Exception {
env = new TestEnv();
- ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder();
+ builder = new ClassicSampleX86ProgramBuilder();
builder.createExternalFunction(null, "LibFoo", "xyz", "_Zxyz");
program = builder.getProgram();
tool = env.launchDefaultTool(program);
@@ -78,16 +82,12 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
setText(textEntryField, "bar");
pressButtonByText(dialog, "OK", false);
+ waitForSwing();
- AbstractErrDialog errorDialog = waitForErrorDialog();
- assertEquals("Invalid Entry Error", errorDialog.getTitle());
- assertEquals(
- "Invalid thunk reference address or name specified: bar",
- errorDialog.getMessage());
- pressButtonByText(errorDialog, "OK");
+ assertEquals("Invalid thunk reference address or name specified", dialog.getStatusText());
// Try again
- setText(textEntryField, "IsTextUnicode");
+ setText(textEntryField, "RegQueryValueExW");
pressButtonByText(dialog, "OK");
waitForBusyTool(tool);
@@ -97,19 +97,25 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
Function thunkedFunction = f.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("ADVAPI32.dll::IsTextUnicode", thunkedFunction.getName(true));
+ assertEquals("RegQueryValueExW", thunkedFunction.getName(true));
}
@Test
public void testSetThunkedFunctionWithNamespace() throws Exception {
-
+ program.withTransaction("test", () -> {
+ Namespace namespace =
+ program.getSymbolTable().createNameSpace(null, "foo", SourceType.USER_DEFINED);
+ SymbolIterator symbols = program.getSymbolTable().getSymbols("RegQueryValueExW");
+ Symbol s = symbols.next();
+ s.setNamespace(namespace);
+ });
ThunkReferenceAddressDialog dialog = showThunkDialog(addr(0x100194b));
JTextField textEntryField = findComponent(dialog, JTextField.class);
assertNotNull(textEntryField);
- setText(textEntryField, "ADVAPI32.dll::IsTextUnicode");
+ setText(textEntryField, "foo::RegQueryValueExW");
pressButtonByText(dialog, "OK");
waitForBusyTool(tool);
@@ -120,7 +126,7 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
Function thunkedFunction = f.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("ADVAPI32.dll::IsTextUnicode", thunkedFunction.getName(true));
+ assertEquals("foo::RegQueryValueExW", thunkedFunction.getName(true));
}
@@ -144,12 +150,12 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
Function thunkedFunction = f.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("LibFoo::xyz", thunkedFunction.getName(true));
+ assertEquals("xyz", thunkedFunction.getName(true));
}
@Test
- public void testSetThunkedFunctionWithOriginalNameConflict() throws Exception {
+ public void testSetThunkedFunctionWithOriginalNameSameAsLabel() throws Exception {
tx(program, () -> {
program.getSymbolTable().createLabel(addr(0x1001900), "_Zxyz", SourceType.USER_DEFINED);
@@ -160,26 +166,58 @@ public class ThunkReferenceAddressDialogTest extends AbstractGhidraHeadedIntegra
assertNotNull(textEntryField);
setText(textEntryField, "_Zxyz");
pressButtonByText(dialog, "OK", false);
-
- AbstractErrDialog errorDialog = waitForErrorDialog();
- assertEquals("Ambiguous Symbol Name", errorDialog.getTitle());
- assertEquals(
- "Specified symbol is ambiguous. Try full namespace name, mangled name or address.",
- errorDialog.getMessage());
- pressButtonByText(errorDialog, "OK");
waitForBusyTool(tool);
Function f = program.getFunctionManager().getFunctionAt(addr(0x100194b));
- assertFalse(f.isThunk());
+ assertTrue(f.isThunk());
+
+ Function thunkedFunction = f.getThunkedFunction(false);
+ assertNotNull(thunkedFunction);
+ assertTrue(thunkedFunction.isExternal());
+ assertEquals("xyz", thunkedFunction.getName(true));
+ }
+
+ @Test
+ public void testSetThunkedFunctionWithMultipleHits() throws Exception {
- setText(textEntryField, "LibFoo::xyz");
+ tx(program, () -> {
+ builder.createExternalFunction(null, "LibFoo", "_Zxyz", "abc");
+ });
+
+ ThunkReferenceAddressDialog dialog = showThunkDialog(addr(0x100194b));
+ JTextField textEntryField = findComponent(dialog, JTextField.class);
+ assertNotNull(textEntryField);
+ setText(textEntryField, "_Zxyz");
pressButtonByText(dialog, "OK", false);
+ ObjectChooserDialog<?> chooserDialog = waitForDialogComponent(ObjectChooserDialog.class);
+ GTableWidget<?> table = chooserDialog.getTable();
+ List<?> data = table.getData();
+ assertEquals(2, data.size());
+ int ZxyzRow = getRow(data, "_Zxyz");
+ getRow(data, "xyz"); // this will fail if xyz not in the data
+
+ runSwing(() -> table.selectRow(ZxyzRow));
+ pressButtonByText(chooserDialog, "OK", false);
+
waitForBusyTool(tool);
+ Function f = program.getFunctionManager().getFunctionAt(addr(0x100194b));
+ assertTrue(f.isThunk());
+
Function thunkedFunction = f.getThunkedFunction(false);
assertNotNull(thunkedFunction);
assertTrue(thunkedFunction.isExternal());
- assertEquals("LibFoo::xyz", thunkedFunction.getName(true));
+ assertEquals("_Zxyz", thunkedFunction.getName(true));
+ }
+
+ private int getRow(List<?> data, String name) {
+ for (int i = 0; i < data.size(); i++) {
+ if (name.equals(data.get(i).toString())) {
+ return i;
+ }
+ }
+ fail("Dialog table does not contain expected symbol name: " + name);
+ return -1;
}
private ThunkReferenceAddressDialog showThunkDialog(Address address) {
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/editor/FunctionEditorDialogTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/editor/FunctionEditorDialogTest.java
index f4b102c42d..dbb65143f8 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/editor/FunctionEditorDialogTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/editor/FunctionEditorDialogTest.java
@@ -151,7 +151,7 @@ public class FunctionEditorDialogTest extends AbstractGhidraHeadedIntegrationTes
Function f = getFunction("0x1006420");
Namespace actualNamespace = f.getParentNamespace();
SymbolPath expectedPath = new SymbolPath(newNamespacePath);
- SymbolPath actualPath = new SymbolPath(actualNamespace.getPathList(true));
+ SymbolPath actualPath = new SymbolPath(actualNamespace.getPathList());
assertEquals(expectedPath, actualPath);
}
@@ -174,7 +174,7 @@ public class FunctionEditorDialogTest extends AbstractGhidraHeadedIntegrationTes
Function f = getFunction("0x1006420");
Namespace actualNamespace = f.getParentNamespace();
SymbolPath expectedPath = new SymbolPath(newNamespacePath);
- SymbolPath actualPath = new SymbolPath(actualNamespace.getPathList(true));
+ SymbolPath actualPath = new SymbolPath(actualNamespace.getPathList());
assertEquals(expectedPath, actualPath);
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/locationreferences/SymbolTreeLocationReferencesTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/locationreferences/SymbolTreeLocationReferencesTest.java
index 6c73a65515..00a68bb97a 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/locationreferences/SymbolTreeLocationReferencesTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/locationreferences/SymbolTreeLocationReferencesTest.java
@@ -63,7 +63,7 @@ public class SymbolTreeLocationReferencesTest extends AbstractLocationReferences
addThunk(thunkAddr, externalFunction);
waitForTree(symbolTree);
- selectPath(symbolTree, "Global", "Imports", "ADVAPI32.dll", "IsTextUnicode");
+ selectPath(symbolTree, "Root", "Imports", "ADVAPI32.dll", "IsTextUnicode");
ActionContext actionContext = treeProvider.getActionContext(null);
assertTrue("showSymbolReferencesAction not properly enabled",
@@ -91,7 +91,7 @@ public class SymbolTreeLocationReferencesTest extends AbstractLocationReferences
addExternalFunctionReference(otherRefAddr, "ADVAPI32.dll", "IsTextUnicode",
RefType.COMPUTED_CALL);
- selectPath(symbolTree, "Global", "Labels", "ADVAPI32.dll_IsTextUnicode"); // label on IAT entry
+ selectPath(symbolTree, "Root", "Globals", "ADVAPI32.dll_IsTextUnicode"); // label on IAT entry
ActionContext actionContext = treeProvider.getActionContext(null);
assertTrue("showSymbolReferencesAction not properly enabled",
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/AbstractSymbolTreePluginExternalsTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/AbstractSymbolTreePluginExternalsTest.java
index a6ead3ecfe..ce01cb5798 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/AbstractSymbolTreePluginExternalsTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/AbstractSymbolTreePluginExternalsTest.java
@@ -47,8 +47,7 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.program.database.symbol.LibrarySymbol;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
-import ghidra.program.model.listing.Function;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.symbol.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
@@ -156,17 +155,18 @@ public abstract class AbstractSymbolTreePluginExternalsTest
functionCheckBox.setSelected(isFunction);
}
- protected ExternalLocation setupExternalLocation(String library, String label, Address address,
+ protected ExternalLocation setupExternalLocation(String libraryName, String label,
+ Address address,
SourceType sourceType, boolean isFunction)
throws Exception {
boolean success = false;
int transactionID =
- program.startTransaction("Setting Up External Location " + library + "::" + label);
+ program.startTransaction("Setting Up External Location " + libraryName + "::" + label);
try {
ExternalManager externalManager = program.getExternalManager();
- Namespace libraryScope = getLibraryScope("ADVAPI32.dll");
+ Library library = getLibrary("ADVAPI32.dll");
ExternalLocation extLocation =
- externalManager.addExtLocation(libraryScope, label, address, sourceType);
+ externalManager.addExtLocation(library, label, address, sourceType);
assertNotNull(extLocation);
if (isFunction) {
Function function = extLocation.createFunction();
@@ -190,15 +190,14 @@ public abstract class AbstractSymbolTreePluginExternalsTest
return setupExternalLocation(library, label, address, sourceType, true);
}
- protected Namespace addNamespace(String libraryName, String namespace)
+ protected Namespace addNamespace(String namespace)
throws InvalidInputException {
boolean success = false;
int transactionID = program.startTransaction(
- "Added namespace " + namespace + " to library " + libraryName + ".");
+ "Added namespace " + namespace + ".");
try {
- Namespace libraryScope = getLibraryScope(libraryName);
Namespace namespaceInLibrary = NamespaceUtils.createNamespaceHierarchy(namespace,
- libraryScope, program, SourceType.USER_DEFINED);
+ null, program, SourceType.USER_DEFINED);
assertNotNull(namespaceInLibrary);
success = true;
return namespaceInLibrary;
@@ -208,10 +207,10 @@ public abstract class AbstractSymbolTreePluginExternalsTest
}
}
- protected Namespace getLibraryScope(String libraryName) {
+ protected Library getLibrary(String libraryName) {
Symbol s = program.getSymbolTable().getLibrarySymbol(libraryName);
if (s instanceof LibrarySymbol) {
- return (Namespace) s.getObject();
+ return (Library) s.getObject();
}
return null;
}
@@ -240,7 +239,7 @@ public abstract class AbstractSymbolTreePluginExternalsTest
flushAndWaitForTree();
GTreeNode selectedNode = util.getSelectedNode();
assertEquals(advapiNode, selectedNode);
- assertEquals("[Global, Imports, " + libraryName + "]",
+ assertEquals("[Root, Imports, " + libraryName + "]",
selectedNode.getTreePath().toString());
return advapiNode;
}
@@ -268,7 +267,7 @@ public abstract class AbstractSymbolTreePluginExternalsTest
flushAndWaitForTree();
GTreeNode selectedNode = util.getSelectedNode();
assertEquals(locationNode, selectedNode);
- assertEquals("[Global, Imports, ADVAPI32.dll, " + externalLocation + "]",
+ assertEquals("[Root, Imports, ADVAPI32.dll, " + externalLocation + "]",
selectedNode.getTreePath().toString());
return locationNode;
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeNavigationTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeNavigationTest.java
index 97e6e708f3..3883dfd6bf 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeNavigationTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeNavigationTest.java
@@ -438,9 +438,8 @@ public class SymbolTreeNavigationTest extends AbstractProgramBasedTest {
private void assertNodeExists(Symbol symbol) {
- SymbolNode key = SymbolNode.createNode(symbol, program);
SymbolTreeRootNode rootNode = util.getRootNode();
- GTreeNode node = rootNode.findSymbolTreeNode(key, true, TaskMonitor.DUMMY);
+ GTreeNode node = rootNode.findSymbolNode(symbol, true, TaskMonitor.DUMMY);
assertNotNull("Could not find node: " + symbol.getName(true), node);
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin1Test.java
index f9079857c6..be832cd88d 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin1Test.java
@@ -21,6 +21,7 @@ import java.awt.Container;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
import javax.swing.*;
import javax.swing.tree.DefaultTreeCellEditor;
@@ -45,11 +46,13 @@ import ghidra.app.services.ProgramManager;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
-import ghidra.program.model.listing.GhidraClass;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.data.DWordDataType;
+import ghidra.program.model.data.WordDataType;
+import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
+import ghidra.util.exception.UsrException;
import ghidra.util.task.TaskMonitor;
/**
@@ -81,6 +84,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
private DockingActionIf createExternalLocationAction;
private DockingActionIf editExternalLocationAction;
private SymbolTreeTestUtils util;
+ private SymbolTreeProvider provider;
@Before
public void setUp() throws Exception {
@@ -92,6 +96,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
tool.addPlugin(MarkerManagerPlugin.class.getName());
tool.addPlugin(SymbolTreePlugin.class.getName());
plugin = env.getPlugin(SymbolTreePlugin.class);
+ provider = plugin.getProvider();
cbPlugin = env.getPlugin(CodeBrowserPlugin.class);
@@ -116,79 +121,343 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
runSwing(() -> plugin.setNodeGroupThreshold(20));
showSymbolTree();
- GTreeNode functionsNode = rootNode.getChild("Functions");
- assertFalse(functionsNode.isLoaded());
- functionsNode.expand();
+
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ assertFalse(globalsNode.isLoaded());
+ globalsNode.expand();
waitForTree(tree);
- assertTrue(functionsNode.isLoaded());
+ assertTrue(globalsNode.isLoaded());
- // add lots of nodes to cause functionsNode to close
+ // add function to exceed limit to trigger organization of the nodes
int reorganizeLimit = ((SymbolTreeRootNode) rootNode).getReorganizeLimit();
addFunctions(reorganizeLimit);
waitForTree(tree);
- assertFalse(functionsNode.isLoaded());
+ assertFalse(globalsNode.isLoaded());
- functionsNode.expand();
+ globalsNode.expand();
waitForTree(tree);
- // should have 4 nodes, one for each of the original 3 functions and a org node with
- // all new "FUNCTION*" named functions
- assertEquals(4, functionsNode.getChildCount());
+ assertEquals(8, globalsNode.getChildCount());
+ assertEquals("ADVAPI32.dll_", globalsNode.getChild(0).getName());
+ assertEquals("doStuff", globalsNode.getChild(1).getName());
+ assertEquals("entry", globalsNode.getChild(2).getName());
+ assertEquals("FUNCTION_", globalsNode.getChild(3).getName());
+ assertEquals("ghidra", globalsNode.getChild(4).getName());
+ assertEquals("IsTextUnicode", globalsNode.getChild(5).getName());
+ assertEquals("Reg", globalsNode.getChild(6).getName());
+ assertEquals("sscanf", globalsNode.getChild(7).getName());
}
@Test
public void testShowDisplay() throws Exception {
showSymbolTree();
- assertEquals(6, rootNode.getChildCount());
+ assertEquals(4, rootNode.getChildCount());
GTreeNode node = rootNode.getChild(0);
assertEquals("Imports", node.getName());
node = rootNode.getChild(1);
assertEquals("Exports", node.getName());
node = rootNode.getChild(2);
- assertEquals("Functions", node.getName());
+ assertEquals("Globals", node.getName());
node = rootNode.getChild(3);
- assertEquals("Labels", node.getName());
- node = rootNode.getChild(4);
- assertEquals("Classes", node.getName());
- node = rootNode.getChild(5);
assertEquals("Namespaces", node.getName());
}
@Test
public void testExternals() throws Exception {
showSymbolTree();
- List<?> list =
- getChildren(globalNamespace, SymbolCategory.IMPORTS_CATEGORY.getSymbolType());
+ List<?> list = getChildren(globalNamespace, SymbolType.LIBRARY);
- GTreeNode extNode = rootNode.getChild(0);
- util.expandNode(extNode);
- assertEquals(list.size(), extNode.getChildCount());
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ assertEquals(list.size(), importsNode.getChildCount());
- checkGTreeNodes(list, extNode);
+ checkLabelNodes(list, importsNode);
- GTreeNode node = extNode.getChild(0);
- util.expandNode(node);
- GTreeNode fNode = node.getChild(0);
+ GTreeNode libraryNode = importsNode.getChild(0);
+ util.expandNode(libraryNode);
+ GTreeNode fNode = libraryNode.getChild(0);
util.selectNode(fNode);
assertTrue(goToExtLocAction.isEnabledForContext(util.getSymbolTreeContext()));
}
@Test
- public void testGoToExternal() throws Exception {
+ public void testExternalInNamespace() throws Exception {
showSymbolTree();
- GTreeNode extNode = rootNode.getChild(0);
- util.expandNode(extNode);
+ createExternalFooInNamespaceBob();
+
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ GTreeNode user32 = importsNode.getChild("USER32.dll");
+ util.expandNode(user32);
+ assertEquals(1, user32.getChildCount());
+ GTreeNode bobNs = user32.getChild(0);
+ assertEquals("bob", bobNs.getName());
+ util.expandNode(bobNs);
+ assertEquals("foo", bobNs.getChild(0).getName());
+
+ createExternalBar();
+ setBarNamespace("bob");
+
+ user32 = importsNode.getChild("USER32.dll");
+ assertEquals(1, user32.getChildCount());
+ bobNs = user32.getChild(0);
+ assertEquals("bob", bobNs.getName());
+ assertEquals(2, bobNs.getChildCount());
+ assertEquals("bar", bobNs.getChild(0).getName());
+ assertEquals("foo", bobNs.getChild(1).getName());
+
+ setBarNamespace(null);
+ assertEquals(2, user32.getChildCount());
+ assertEquals("bar", user32.getChild(0).getName());
+ assertEquals("bob", user32.getChild(1).getName());
+ }
+
+ @Test
+ public void testDeleteExternalSymbolInNamespace() throws Exception {
+ showSymbolTree();
+
+ Symbol fooSym = createExternalFooInNamespaceBob();
+ createExternalBar();
+
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ GTreeNode user32 = importsNode.getChild("USER32.dll");
+ util.expandNode(user32);
+ assertEquals(2, user32.getChildCount());
+ assertEquals("bar", user32.getChild(0).getName());
+ assertEquals("bob", user32.getChild(1).getName());
+
+ deleteSymbol(fooSym);
+
+ user32 = importsNode.getChild("USER32.dll");
+ assertEquals(1, user32.getChildCount());
+ assertEquals("bar", user32.getChild(0).getName());
+ }
+
+ @Test
+ public void testExternalParameter() throws Exception {
+ showSymbolTree();
+
+ createExternalFunctionFoo();
- GTreeNode node = extNode.getChild(0);
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ GTreeNode user32 = importsNode.getChild("USER32.dll");
+ util.expandNode(user32);
+ assertEquals(1, user32.getChildCount());
+ assertEquals("foo", user32.getChild(0).getName());
+ GTreeNode foo = user32.getChild(0);
+ util.expandNode(foo);
+
+ addParameterToFunctionFoo();
+
+ foo = user32.getChild(0);
+ assertEquals(1, foo.getChildCount());
+ assertEquals("param1", foo.getChild(0).getName());
+
+ removeParametersForFunctionFoo();
+ }
+
+ @Test
+ public void testAddExternalFunction() throws Exception {
+ showSymbolTree();
+ List<?> list = getChildren(globalNamespace, SymbolType.LIBRARY);
+
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ assertEquals(list.size(), importsNode.getChildCount());
+ checkLabelNodes(list, importsNode);
+
+ GTreeNode advapi32 = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapi32);
+ assertEquals(7, advapi32.getChildCount());
+ GTreeNode node = advapi32.getChild("IsTextUnicode");
+ assertNotNull(node);
+
+ createExternaFunction();
+ assertEquals(8, advapi32.getChildCount());
+
+ node = advapi32.getChild(0);
+ assertEquals("doFoo", node.getName());
util.expandNode(node);
- GTreeNode fNode = node.getChild(0);
- util.selectNode(fNode);
+ assertEquals(1, node.getChildCount());
+ assertEquals("p1", node.getChild(0).getName());
+
+ addAnotherParameter(node);
+ node = advapi32.getChild(0); // have to re-aquiire node since it got removed/added
+ assertEquals(2, node.getChildCount());
+ assertEquals("p1", node.getChild(0).getName());
+ assertEquals("p2", node.getChild(1).getName());
+
+ }
+
+ @Test
+ public void testAddExternalLabelInNamespace() throws Exception {
+ showSymbolTree();
+ GTreeNode importsNode = rootNode.getChild(SymbolCategory.IMPORTS.getName());
+ util.expandNode(importsNode);
+ GTreeNode advapiNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapiNode);
+ assertNull(advapiNode.getChild("fooNs"));
+ createExternaLabelInNamespace("bob", "fooNs");
+ GTreeNode fooNs = advapiNode.getChild("fooNs");
+ assertNotNull(fooNs);
+ assertFalse(fooNs.isLoaded());
+ util.expandNode(fooNs);
+ assertNotNull(fooNs.getChild("bob"));
+ }
+
+ @Test
+ public void testAddExternalLabelInNamespaceDeeper() throws Exception {
+ showSymbolTree();
+ GTreeNode importsNode = rootNode.getChild(SymbolCategory.IMPORTS.getName());
+ util.expandNode(importsNode);
+ GTreeNode advapiNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapiNode);
+ assertNull(advapiNode.getChild("fooNs"));
+ createExternaLabelInNamespace("bob", "fooNs", "barNs");
+ GTreeNode fooNs = advapiNode.getChild("fooNs");
+ assertNotNull(fooNs);
+ assertFalse(fooNs.isLoaded());
+ util.expandNode(fooNs);
+ GTreeNode barNs = fooNs.getChild("barNs");
+ assertNotNull(barNs);
+ util.expandNode(barNs);
+ assertNotNull(barNs.getChild("bob"));
+ }
+
+ @Test
+ public void testAddExternalLabelInNamespaceAlreadyOpen() throws Exception {
+ showSymbolTree();
+ GTreeNode importsNode = rootNode.getChild(SymbolCategory.IMPORTS.getName());
+ util.expandNode(importsNode);
+ GTreeNode advapiNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapiNode);
+ assertNull(advapiNode.getChild("fooNs"));
+ createExternaLabelInNamespace("bob", "fooNs");
+
+ GTreeNode fooNs = advapiNode.getChild("fooNs");
+ assertNotNull(fooNs);
+ assertFalse(fooNs.isLoaded());
+ util.expandNode(fooNs);
+ assertNotNull(fooNs.getChild("bob"));
+ createExternaLabelInNamespace("joe", "fooNs");
+
+ assertNotNull(fooNs.getChild("joe"));
+ }
+
+ @Test
+ public void testRemoveExternalLabelInNamespaceRemovesEmptyNamespace() throws Exception {
+ showSymbolTree();
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ GTreeNode advapiNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapiNode);
+ assertNull(advapiNode.getChild("fooNs"));
+
+ createExternaLabelInNamespace("bob", "fooNs");
+ createExternaLabelInNamespace("joe", "fooNs");
+
+ GTreeNode fooNs = advapiNode.getChild("fooNs");
+ util.expandNode(fooNs);
+ assertNotNull(fooNs.getChild("bob"));
+ assertNotNull(fooNs.getChild("joe"));
+
+ removeSymbol("bob", "fooNs");
+
+ assertNull(fooNs.getChild("bob"));
+ assertNotNull(fooNs.getChild("joe"));
+
+ removeSymbol("joe", "fooNs");
+
+ assertNull(fooNs.getParent()); // fooNs should be disposed
+ assertNull(advapiNode.getChild("fooNs"));
+ }
+
+ @Test
+ public void testRemoveExternalLabelInNamespaceRemovesEmptyNamespaceDownOneLevel()
+ throws Exception {
+ showSymbolTree();
+ GTreeNode importsNode = rootNode.getChild(SymbolCategory.IMPORTS.getName());
+ util.expandNode(importsNode);
+ GTreeNode advapiNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(advapiNode);
+ assertNull(advapiNode.getChild("fooNs"));
+ createExternaLabelInNamespace("bob", "fooNs", "barNs");
+ createExternaLabelInNamespace("joe", "fooNs", "barNs");
+ GTreeNode fooNs = advapiNode.getChild("fooNs");
+ util.expandNode(fooNs);
+ GTreeNode barNs = fooNs.getChild("barNs");
+ assertNotNull(barNs.getChild("bob"));
+ assertNotNull(barNs.getChild("joe"));
+
+ removeSymbol("bob", "fooNs", "barNs");
+
+ assertNull(barNs.getChild("bob"));
+ assertNotNull(barNs.getChild("joe"));
+
+ removeSymbol("joe", "fooNs", "barNs");
+
+ assertNull(barNs.getParent()); // barNs should be disposed
+ assertNull(fooNs.getParent()); // fooNs should be disposed
+ assertNull(advapiNode.getChild("fooNs"));
+ }
+
+ private void removeSymbol(String symbolName, String... namespaceNames) throws Exception {
+ program.withTransaction("test", () -> {
+ SymbolTable symbolMgr = program.getSymbolTable();
+ Namespace namespace = getNamespace(namespaceNames);
+ List<Symbol> symbols = symbolMgr.getSymbols(symbolName, namespace);
+ Symbol s = symbols.get(0);
+ s.delete();
+ });
+ waitForTree(tree);
+
+ }
+
+ private void createExternaLabelInNamespace(String labelName, String... namespaceNames)
+ throws Exception {
+ program.withTransaction("test", () -> {
+ ExternalManager extMgr = program.getExternalManager();
+ SymbolTable symbolMgr = program.getSymbolTable();
+ Library advapi32 = (Library) symbolMgr.getLibrarySymbol("ADVAPI32.dll").getObject();
+ Namespace namespace = getNamespace(namespaceNames);
+ extMgr.addExtLocation(advapi32, namespace, labelName, null, SourceType.USER_DEFINED);
+ });
+ waitForSwing();
+ waitForTree(tree);
+ }
+
+ private Namespace getNamespace(String[] namespaceNames) throws Exception {
+ SymbolTable symbolMgr = program.getSymbolTable();
+ Namespace namespace = program.getGlobalNamespace();
+ for (String namespaceName : namespaceNames) {
+ Namespace ns = symbolMgr.getNamespace(namespaceName, namespace);
+ if (ns == null) {
+ ns = symbolMgr.createNameSpace(namespace, namespaceName, SourceType.USER_DEFINED);
+ }
+ namespace = ns;
+ }
+ return namespace;
+ }
+
+ @Test
+ public void testGoToExternal() throws Exception {
+ showSymbolTree();
- Symbol extSym = ((SymbolNode) fNode).getSymbol();
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+
+ GTreeNode libraryNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(libraryNode);
+ GTreeNode node = libraryNode.getChild("IsTextUnicode");
+ util.selectNode(node);
+
+ Symbol extSym = ((SymbolNode) node).getSymbol();
assertEquals(SymbolType.LABEL, extSym.getSymbolType());
assertTrue(extSym.isExternal());
assertNotNull(extSym);
@@ -207,18 +476,17 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
cbPlugin.updateNow();
// reselect - setting path rebuilt tree
- extNode = rootNode.getChild(0);
- node = extNode.getChild(0);
- util.expandNode(node);
- node = extNode.getChild(0);
- fNode = node.getChild(0);
- assertEquals("IsTextUnicode", fNode.getName());
- util.selectNode(fNode);
+ importsNode = rootNode.getChild("Imports");
+ libraryNode = importsNode.getChild("ADVAPI32.dll");
+ util.expandNode(libraryNode);
+ node = libraryNode.getChild("IsTextUnicode");
+ assertEquals("IsTextUnicode", node.getName());
+ util.selectNode(node);
TreePath selectionPath = tree.getSelectionPath();
assertNotNull(selectionPath);
Object selectedObject = selectionPath.getLastPathComponent();
- assertEquals(fNode, selectedObject);
+ assertEquals(node, selectedObject);
waitForSwing();
@@ -231,29 +499,16 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
}
@Test
- public void testFunctions() throws Exception {
- showSymbolTree();
- List<?> list =
- getChildren(globalNamespace, SymbolCategory.FUNCTION_CATEGORY.getSymbolType());
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
-
- assertEquals(list.size(), fNode.getChildCount());
- checkGTreeNodes(list, fNode);
- }
-
- @Test
- public void testLabels() throws Exception {
+ public void testGlobals() throws Exception {
showSymbolTree();
- List<?> list = getChildren(globalNamespace, SymbolCategory.LABEL_CATEGORY.getSymbolType());
- GTreeNode labelNode = rootNode.getChild(3);
- util.expandNode(labelNode);
+ List<Symbol> list = getChildren(globalNamespace, SymbolType.FUNCTION);
+ list.addAll(getChildren(globalNamespace, SymbolType.LABEL));
+ Collections.sort(list, util.getSymbolComparator());
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- for (int i = 0; i < labelNode.getChildCount(); i++) {
- GTreeNode node = labelNode.getChild(i);
- util.expandNode(node);
- }
- checkLabelNodes(list, labelNode);
+ assertEquals(list.size(), globalsNode.getChildCount());
+ checkGTreeNodes(list, globalsNode);
}
@Test
@@ -279,40 +534,40 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
showSymbolTree();
// cut label from a function
// select Global; paste should be enabled
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
- GTreeNode gNode = fNode.getChild(1);
- util.expandNode(gNode);
- GTreeNode node = gNode.getChild(9);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
+ GTreeNode ghidraNode = globalsNode.getChild("ghidra");
+ util.expandNode(ghidraNode);
+ GTreeNode node = ghidraNode.getChild("AnotherLocal");
util.selectNode(node);
performAction(cutAction, util.getSymbolTreeContext(), true);
// move a function to a namespace
// cut a function; select global; paste should be enabled
- GTreeNode nsParentNode = rootNode.getChild(5);
- GTreeNode nsNode = util.createObject(nsParentNode, "MyNamespace", createNamespaceAction);
- doDrag(nsNode, gNode, DnDConstants.ACTION_MOVE);
+
+ GTreeNode nsNode = util.createObject(namespacesNode, "MyNamespace", createNamespaceAction);
+ doDrag(nsNode, ghidraNode, DnDConstants.ACTION_MOVE);
util.waitForTree();
flushAndWaitForTree();
- nsParentNode = rootNode.getChild(5);
- nsNode = nsParentNode.getChild(0);
+ namespacesNode = rootNode.getChild("Namespaces");
+ nsNode = namespacesNode.getChild(0);
util.expandNode(nsNode);
util.waitForTree();
waitForSwing();
util.waitForTree();
- gNode = nsNode.getChild(0);
+ ghidraNode = nsNode.getChild(0);
- if (gNode == null) {
+ if (ghidraNode == null) {
if (tree.isExpanded(nsNode.getTreePath())) {
- gNode = nsNode.getChild(0);
+ ghidraNode = nsNode.getChild(0);
}
}
- assertNotNull(gNode);
+ assertNotNull(ghidraNode);
- gNode = nsNode.getChild(0);
- util.selectNode(gNode);
+ ghidraNode = nsNode.getChild(0);
+ util.selectNode(ghidraNode);
assertTrue(cutAction.isEnabledForContext(util.getSymbolTreeContext()));
performAction(cutAction, util.getSymbolTreeContext(), true);
}
@@ -331,17 +586,13 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
flushAndWaitForTree();
- // Functions node
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
-
- GTreeNode labelsNode = rootNode.getChild("Labels");
+ GTreeNode globalsNode = rootNode.getChild("Globals");
GTreeNode namespaceNode = rootNode.getChild("Namespaces");
util.selectNode(namespaceNode);
performAction(createNamespaceAction, util.getSymbolTreeContext(), true);
util.waitForTree();
runSwing(() -> tree.stopEditing());
- GTreeNode fredNode = labelsNode.getChild("fred");
+ GTreeNode fredNode = globalsNode.getChild("fred");
util.selectNode(fredNode);
waitForSwing();
@@ -355,7 +606,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
// doStuff function node
waitForSwing();
- GTreeNode dNode = fNode.getChild(0);
+ GTreeNode dNode = globalsNode.getChild(0);
util.selectNode(dNode);
assertFalse(pasteAction.isEnabledForContext(util.getSymbolTreeContext()));
}
@@ -408,11 +659,11 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
// select the external symbol category;
// no actions should be applicable
showSymbolTree();
- GTreeNode extNode = rootNode.getChild(0);
- util.selectNode(extNode);
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.selectNode(importsNode);
ActionContext context = util.getSymbolTreeContext();
boolean createLibraryIsEnabled = createLibraryAction.isEnabledForContext(context);
- if (extNode.getName().equals("Imports")) {
+ if (importsNode.getName().equals("Imports")) {
assertTrue(createLibraryIsEnabled);
}
else {
@@ -443,9 +694,9 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testParameterActionEnablement() throws Exception {
showSymbolTree();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
GTreeNode pNode = gNode.getChild(0);
util.selectNode(pNode);
@@ -462,9 +713,9 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testFunctionActionEnablement() throws Exception {
showSymbolTree();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
util.selectNode(gNode);
ActionContext context = util.getSymbolTreeContext();
@@ -480,9 +731,9 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testLocalSymbolActionEnablement() throws Exception {
showSymbolTree();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
GTreeNode pNode = gNode.getChild(9);
util.selectNode(pNode);
@@ -541,14 +792,14 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testCreateClass() throws Exception {
showSymbolTree();
- util.selectNode(rootNode.getChild("Classes"));
+ namespacesNode = rootNode.getChild("Namespaces");
+ util.selectNode(namespacesNode);
performAction(createClassAction, util.getSymbolTreeContext(), true);
- GTreeNode cnode = rootNode.getChild(4);
- util.expandNode(cnode);
+ util.expandNode(namespacesNode);
// wait until NewClass gets added
- GTreeNode newNode = waitForValue(() -> cnode.getChild(0));
+ GTreeNode newNode = waitForValue(() -> namespacesNode.getChild(0));
assertNotNull(newNode);
Symbol s = ((SymbolNode) newNode).getSymbol();
@@ -572,7 +823,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateClassInNamespace() throws Exception {
showSymbolTree();
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
util.selectNode(nsParentNode);
GTreeNode nsNode = util.createObject(nsParentNode, "MyNamespace", createNamespaceAction);
GTreeNode cNode = util.createObject(nsNode, "MyClass", createClassAction);
@@ -584,9 +835,9 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testRenameExternalLib() throws Exception {
showSymbolTree();
- GTreeNode extNode = rootNode.getChild(0);
- util.expandNode(extNode);
- GTreeNode advNode = extNode.getChild(0);
+ GTreeNode importsNode = rootNode.getChild("Imports");
+ util.expandNode(importsNode);
+ GTreeNode advNode = importsNode.getChild(0);
util.rename(advNode, "MyADVAI32.dll");
Symbol s = ((SymbolNode) advNode).getSymbol();
@@ -615,7 +866,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testRenameLabel() throws Exception {
showSymbolTree();
- GTreeNode labelNode = rootNode.getChild(3);
+ GTreeNode labelNode = rootNode.getChild("Globals");
util.expandNode(labelNode);
GTreeNode isTextUnicodeNode = labelNode.getChild("ADVAPI32.dll_IsTextUnicode");
@@ -634,7 +885,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
undo(program);
util.waitForTree();
- labelNode = rootNode.getChild(3);
+ labelNode = rootNode.getChild("Globals");
isTextUnicodeNode = labelNode.getChild("ADVAPI32.dll_IsTextUnicode");
s = ((SymbolNode) isTextUnicodeNode).getSymbol();
assertEquals(oldName, s.getName());
@@ -642,7 +893,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
redo(program);
util.waitForTree();
- labelNode = rootNode.getChild(3);
+ labelNode = rootNode.getChild("Globals");
renamedNode = labelNode.getChild("MYADVAPI32.dll_IsTextUnicode");
s = ((SymbolNode) renamedNode).getSymbol();
assertEquals(newName, s.getName());
@@ -658,11 +909,11 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
//
showSymbolTree();
- GTreeNode labelNode = rootNode.getChild(3);
- util.expandNode(labelNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
String advapiName = "ADVAPI32.dll_IsTextUnicode";
- GTreeNode advapi32Node = labelNode.getChild(advapiName);
+ GTreeNode advapi32Node = globalsNode.getChild(advapiName);
Symbol s = ((SymbolNode) advapi32Node).getSymbol();
String newNamespace = "bob";
@@ -716,13 +967,13 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
showSymbolTree();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
- GTreeNode pNode = gNode.getChild(2);
+ GTreeNode pNode = gNode.getChild("param_2");
Symbol s = ((SymbolNode) pNode).getSymbol();
String newName = "MY" + s.getName();
@@ -734,13 +985,13 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
public void testRenameLocalLabel() throws Exception {
showSymbolTree();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
- GTreeNode node = gNode.getChild(5);
+ GTreeNode node = gNode.getChild("AnotherLocal");
Symbol s = ((SymbolNode) node).getSymbol();
String newName = "MY" + s.getName();
util.rename(node, newName);
@@ -767,15 +1018,15 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
// triggering the exception before the fix.
//
showSymbolTree();
- GTreeNode classesNode = rootNode.getChild("Classes");
- assertFalse(classesNode.isLoaded());
- classesNode.expand();
+ namespacesNode = rootNode.getChild("Namespaces");
+ assertFalse(namespacesNode.isLoaded());
+ namespacesNode.expand();
waitForTree(tree);
- assertTrue(classesNode.isLoaded());
+ assertTrue(namespacesNode.isLoaded());
addFunctionInClass(100);
waitForTree(tree);
- GTreeNode parentClassNode = classesNode.getChild("PARENT_CLASS");
+ GTreeNode parentClassNode = namespacesNode.getChild("PARENT_CLASS");
parentClassNode.expand();
waitForTree(tree);
@@ -788,6 +1039,9 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
symbolRootNode.symbolAdded(symbol, TaskMonitor.DUMMY);
}
+//==================================================================================================
+// Private Methods
+//==================================================================================================
private void addFunctions(int count) throws Exception {
tx(program, () -> {
for (int i = 0; i < count; i++) {
@@ -815,10 +1069,6 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
});
}
-//==================================================================================================
-// Private Methods
-//==================================================================================================
-
private void doDrag(final GTreeNode destinationNode, GTreeNode dragNode, final int dragAction) {
final GTreeDragNDropHandler dragNDropHandler = tree.getDragNDropHandler();
List<GTreeNode> dropList = new ArrayList<>();
@@ -923,7 +1173,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
assertNotNull(goToExtLocAction);
}
- private List<?> getChildren(Namespace namespace, SymbolType type) {
+ private List<Symbol> getChildren(Namespace namespace, SymbolType type) {
List<Symbol> list = new ArrayList<>();
SymbolIterator it = program.getSymbolTable().getSymbols(namespace);
@@ -993,4 +1243,104 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
waitForSwing();
util.waitForTree();
}
+
+ @SuppressWarnings("deprecation")
+ private void removeParametersForFunctionFoo() {
+ ExternalManager extMgr = program.getExternalManager();
+ ExternalLocation extLoc = extMgr.getUniqueExternalLocation("USER32.dll", "foo");
+ Function function = extLoc.getFunction();
+
+ tx(program, () -> {
+ function.removeParameter(0);
+ });
+ waitForTree(tree);
+ }
+
+ private void deleteSymbol(Symbol s) {
+ tx(program, () -> {
+ s.delete();
+ });
+ waitForTree(tree);
+ }
+
+ @SuppressWarnings("deprecation")
+ private void addParameterToFunctionFoo() {
+ ExternalManager extMgr = program.getExternalManager();
+ ExternalLocation extLoc = extMgr.getUniqueExternalLocation("USER32.dll", "foo");
+ Function function = extLoc.getFunction();
+
+ tx(program, () -> {
+ ParameterImpl p = new ParameterImpl("param1", new WordDataType(), program);
+ function.addParameter(p, SourceType.USER_DEFINED);
+ });
+ waitForTree(tree);
+ }
+
+ private void setBarNamespace(String namespaceName) {
+ tx(program, () -> {
+ SymbolTable symbolTable = program.getSymbolTable();
+ Namespace ns = namespaceName == null ? program.getGlobalNamespace()
+ : symbolTable.getNamespace(namespaceName, null);
+ symbolTable.getSymbols("bar").next().setNamespace(ns);
+ });
+ waitForTree(tree);
+ }
+
+ private void createExternalBar() throws UsrException {
+ ExternalManager extMgr = program.getExternalManager();
+ Library library = extMgr.getExternalLibrary("USER32.dll");
+ program.withTransaction("test", () -> {
+ extMgr.addExtLocation(library, "bar", null, SourceType.USER_DEFINED);
+ });
+ waitForTree(tree);
+ }
+
+ private Symbol createExternalFooInNamespaceBob() throws UsrException {
+ ExternalManager extMgr = program.getExternalManager();
+ Library library = extMgr.getExternalLibrary("USER32.dll");
+ AtomicReference<Symbol> fooSym = new AtomicReference<Symbol>();
+ program.withTransaction("test", () -> {
+ Namespace bob =
+ program.getSymbolTable().createNameSpace(null, "bob", SourceType.USER_DEFINED);
+ ExternalLocation extLoc =
+ extMgr.addExtLocation(library, "foo", null, SourceType.USER_DEFINED);
+ Symbol s = extLoc.getSymbol();
+ s.setNamespace(bob);
+ fooSym.set(s);
+ });
+ waitForTree(tree);
+ return fooSym.get();
+ }
+
+ private void createExternalFunctionFoo() throws UsrException {
+ ExternalManager extMgr = program.getExternalManager();
+ Library library = extMgr.getExternalLibrary("USER32.dll");
+ program.withTransaction("test", () -> {
+ extMgr.addExtFunction(library, "foo", null, SourceType.USER_DEFINED);
+ });
+ waitForTree(tree);
+ }
+
+ private void addAnotherParameter(GTreeNode node) throws UsrException {
+ Symbol symbol = ((SymbolNode) node).getSymbol();
+ Function function = (Function) symbol.getObject();
+ program.withTransaction("test", () -> {
+ Parameter param = new ParameterImpl("p2", new DWordDataType(), 4, program);
+ function.addParameter(param, SourceType.USER_DEFINED);
+ });
+ waitForSwing();
+ }
+
+ private void createExternaFunction() throws UsrException {
+ program.withTransaction("test", () -> {
+ ExternalManager extMgr = program.getExternalManager();
+ ExternalLocation extLoc =
+ extMgr.addExtFunction("ADVAPI32.dll", "doFoo", null, SourceType.USER_DEFINED);
+ Function function = extLoc.getFunction();
+ Parameter parameter1 = new ParameterImpl("p1", new DWordDataType(), 4, program);
+ function.addParameter(parameter1, SourceType.USER_DEFINED);
+ });
+ waitForSwing();
+ }
+
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin2Test.java
index c796c04fa3..68cdc3aed5 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin2Test.java
@@ -48,6 +48,7 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
+import ghidra.util.task.TaskMonitor;
/**
* Tests for the symbol tree plugin.
@@ -108,10 +109,10 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
assertTrue(navigateIncomingAction.isSelected());
- GTreeNode fNode = getFunctionsNode();
- util.expandNode(fNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
GTreeNode node = gNode.getChild(5);
@@ -125,10 +126,10 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testNavigateToFunction() throws Exception {
// select a node; code browser should go there
- GTreeNode fNode = getFunctionsNode();
- util.expandNode(fNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
Symbol s = ((SymbolNode) gNode).getSymbol();
Function f = (Function) s.getObject();
@@ -142,13 +143,13 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testNavigateToParameter() throws Exception {
- GTreeNode fNode = getFunctionsNode();
- util.expandNode(fNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
- GTreeNode pNode = gNode.getChild(0);
+ GTreeNode pNode = gNode.getChild("param_1");
clickOnNode(pNode);
Symbol s = ((SymbolNode) pNode).getSymbol();
@@ -165,9 +166,9 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
GTreeNode node = extNode.getChild(0);
util.expandNode(node);
- GTreeNode fNode = node.getChild(0);
+ GTreeNode globalsNode = node.getChild(0);
- Symbol extSym = ((SymbolNode) fNode).getSymbol();
+ Symbol extSym = ((SymbolNode) globalsNode).getSymbol();
assertNotNull(extSym);
Address addr = null;
ExternalLocation extLoc = (ExternalLocation) extSym.getObject();
@@ -181,7 +182,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
}
}
assertNotNull(addr);
- clickOnNode(fNode);
+ clickOnNode(globalsNode);
cbPlugin.updateNow();
assertEquals(addr, cbPlugin.getCurrentAddress());
}
@@ -201,10 +202,10 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
util.waitForTree();
// parm_1 should be selected in the symbol tree
- GTreeNode fNode = getFunctionsNode();
- GTreeNode doStuffNode = fNode.getChild(0);
+ GTreeNode globalsNode = getGlobalsNode();
+ GTreeNode doStufglobalsNode = globalsNode.getChild("doStuff");
- GTreeNode param_1Node = doStuffNode.getChild(0);
+ GTreeNode param_1Node = doStufglobalsNode.getChild("param_1");
TreePath path = param_1Node.getTreePath();
TreePath selectedPath = runSwing(() -> tree.getSelectionPath());
@@ -214,13 +215,13 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testDeleteLocalVariable() throws Exception {
- GTreeNode functionsNode = getFunctionsNode();
- util.expandNode(functionsNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- GTreeNode ghidraNode = functionsNode.getChild(1);
+ GTreeNode ghidraNode = globalsNode.getChild("ghidra");
util.expandNode(ghidraNode);
- GTreeNode node = ghidraNode.getChild(9);
+ GTreeNode node = ghidraNode.getChild("AnotherLocal");
util.selectNode(node);
int count = ghidraNode.getChildCount();
@@ -238,8 +239,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
undo(program);
util.waitForTree();
- functionsNode = getFunctionsNode();
- ghidraNode = functionsNode.getChild(1);
+ globalsNode = getGlobalsNode();
+ ghidraNode = globalsNode.getChild("ghidra");
boolean found = false;
for (int i = 0; i < count - 1; i++) {
GTreeNode n = ghidraNode.getChild(i);
@@ -254,8 +255,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
redo(program);
util.waitForTree();
- functionsNode = getFunctionsNode();
- ghidraNode = functionsNode.getChild(1);
+ globalsNode = getGlobalsNode();
+ ghidraNode = globalsNode.getChild("ghidra");
for (int i = 0; i < count - 1; i++) {
GTreeNode n = ghidraNode.getChild(i);
@@ -266,24 +267,25 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testDeleteFunction() throws Exception {
- GTreeNode functionsNode = getFunctionsNode();
- util.expandNode(functionsNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
+ assertEquals(18, globalsNode.getChildCount());
- GTreeNode doStuffNode = functionsNode.getChild(0);
+ GTreeNode doStuffNode = globalsNode.getChild("doStuff");
util.expandNode(doStuffNode);
util.selectNode(doStuffNode);
ActionContext context = util.getSymbolTreeContext();
performTreeAction(deleteAction, context);
- functionsNode = getFunctionsNode();
- assertEquals(2, functionsNode.getChildCount());
+ globalsNode = getGlobalsNode();
+ assertEquals(18, globalsNode.getChildCount());
}
@Test
public void testDeleteNamespace() throws Exception {
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild(SymbolCategory.NAMESPACES.getName());
GTreeNode nsNode = util.createObject(nsParentNode, "MyNamespace", createNamespaceAction);
util.createObject(nsNode, "MyClass", createClassAction);
@@ -291,12 +293,11 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
ActionContext context = util.getSymbolTreeContext();
performTreeAction(deleteAction, context);
- nsParentNode = rootNode.getChild(4);
for (int i = 0; i < nsParentNode.getChildCount(); i++) {
GTreeNode n = rootNode.getChild(i);
- assertTrue(n instanceof SymbolCategoryNode);
- SymbolCategory cat = ((SymbolCategoryNode) n).getSymbolCategory();
- assertTrue(cat.getSymbolType() != SymbolType.NAMESPACE);
+ if (n.getName().equals("MyNamespace")) {
+ fail("Expected MyNamespace node to be deleted");
+ }
}
}
@@ -304,7 +305,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testConvertNamespaceToClass() throws Exception {
String classNodeName = "MyClass";
- GTreeNode nsNode = rootNode.getChild(SymbolCategory.NAMESPACE_CATEGORY.getName());
+ GTreeNode nsNode = rootNode.getChild(SymbolCategory.NAMESPACES.getName());
GTreeNode classNode = util.createObject(
nsNode, classNodeName, createNamespaceAction);
@@ -312,10 +313,14 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
ActionContext context = util.getSymbolTreeContext();
performTreeAction(convertToClassAction, context);
- GTreeNode classRootNode = rootNode.getChild(SymbolCategory.CLASS_CATEGORY.getName());
- classNode = classRootNode.getChild(classNodeName);
+ GTreeNode namespacesNode = rootNode.getChild(SymbolCategory.NAMESPACES.getName());
+ classNode = namespacesNode.getChild(classNodeName);
+ assertTrue(classNode instanceof ClassSymbolNode);
assertNotNull(classNode);
waitForCondition(tree::isEditing);
+
+ tree.cancelEditing();
+ waitForSwing();
}
@Test
@@ -323,12 +328,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
/*
- The Classes folder flattens classes so every class appears at the top level. Because
- users can expand classes, top level classes may also appear nested under other classes.
-
- Classes
- Class1
-
Namespaces
FooNs
Class1
@@ -337,7 +336,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
Namespace fooNs = createNamespace("FooNs");
GhidraClass class1 = createClass(fooNs, "Class1");
- expandClasses();
expandNamesapces();
//@formatter:off
@@ -346,12 +344,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1"
- );
- //@formatter:on
-
renameSymbol(class1.getSymbol(), "Class1.renamed");
//@formatter:off
@@ -360,29 +352,13 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1.renamed"
- );
- //@formatter:on
}
@Test
public void testClassCategoryDuplicates_NestedClass_RenameLabel() throws Exception {
/*
-
- The Classes folder flattens classes so every class appears at the top level. Because
- users can expand classes, top level classes may also appear nested under other classes.
-
Classes
- Class1
- Label1
- BarNs
- Class2
- Label2
- Class2
- Label2
Namespaces
FooNs
@@ -399,8 +375,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
createLabel(class1, "Label1", "0x1001100");
GhidraClass class2 = createClass(barNs, "Class2");
Symbol lable2 = createLabel(class2, "Label2", "0x1001104");
-
- expandClasses();
expandNamesapces();
// verify all leaf nodes
@@ -411,14 +385,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1::Label1",
- "Class1::BarNs::Class2::Label2",
- "Class2::Label2"
- );
- //@formatter:on
-
renameSymbol(lable2, "Label2.renamed");
//@formatter:off
@@ -428,31 +394,14 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1::Label1",
- "Class1::BarNs::Class2::Label2.renamed",
- "Class2::Label2.renamed"
- );
- //@formatter:on
}
@Test
public void testClassCategoryDuplicates_NestedClass_ChangeNamespace() throws Exception {
/*
-
- The Classes folder flattens classes so every class appears at the top level. Because
- users can expand classes, top level classes may also appear nested under other classes.
-
+
Classes
- Class1
- Label1
- BarNs
- Class2
- Label2
- Class2
- Label2
Namespaces
FooNs
@@ -470,7 +419,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
GhidraClass class2 = createClass(barNs, "Class2");
createLabel(class2, "Label2", "0x1001104");
- expandClasses();
expandNamesapces();
// verify all leaf nodes
@@ -481,14 +429,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1::Label1",
- "Class1::BarNs::Class2::Label2",
- "Class2::Label2"
- );
- //@formatter:on
-
moveLabel(label1, barNs);
//@formatter:off
@@ -498,33 +438,15 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1",
- "Class1::BarNs::Label1",
- "Class1::BarNs::Class2::Label2",
- "Class2::Label2"
- );
- //@formatter:on
}
@Test
public void testClassCategoryDuplicates_NestedClass_RenameNamespace() throws Exception {
/*
-
- The Classes folder flattens classes so every class appears at the top level. Because
- users can expand classes, top level classes may also appear nested under other classes.
-
+
Classes
- Class1
- Label1
- BarNs
- Class2
- Label2
- Class2
- Label2
-
+
Namespaces
FooNs
Class1
@@ -541,7 +463,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
GhidraClass class2 = createClass(barNs, "Class2");
createLabel(class2, "Label2", "0x1001104");
- expandClasses();
expandNamesapces();
// verify all leaf nodes
@@ -552,14 +473,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1::Label1",
- "Class1::BarNs::Class2::Label2",
- "Class2::Label2"
- );
- //@formatter:on
-
renameNamespace(barNs, "BarNs.renamed");
//@formatter:off
@@ -569,13 +482,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
);
//@formatter:on
- //@formatter:off
- assertClassNodes(
- "Class1::Label1",
- "Class1::BarNs.renamed::Class2::Label2",
- "Class2::Label2"
- );
- //@formatter:on
}
@Test
@@ -583,10 +489,10 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
// select a group node; only cut, delete, make selection should be
// on the popup
- GTreeNode lNode = rootNode.getChild(3);
- util.expandNode(lNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- util.selectNode(lNode);
+ util.selectNode(globalsNode);
ActionContext context = util.getSymbolTreeContext();
assertFalse(renameAction.isEnabledForContext(context));
@@ -601,8 +507,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testUpdate() throws Exception {
// create a new label; verify that it shows up in the tree
- GTreeNode lNode = rootNode.getChild(3);
- util.expandNode(lNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
// add a label
tx(program, () -> {
@@ -612,12 +518,11 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
util.waitForTree();
- lNode = rootNode.getChild(3);
+ globalsNode = rootNode.getChild("Globals");
util.waitForTree();
- GTreeNode node = lNode.getChild(0);
+ GTreeNode node = globalsNode.getChild("abcdefg");
assertNotNull(node);
- assertEquals("abcdefg", node.toString());
}
@Test
@@ -635,10 +540,10 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
util.waitForTree();
- GTreeNode fNode = getFunctionsNode();
- util.expandNode(fNode);
+ GTreeNode globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
GTreeNode node = gNode.getChild(9);
@@ -648,20 +553,20 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
undo(program);
util.waitForTree();
- fNode = getFunctionsNode();
- util.expandNode(fNode);
+ globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- gNode = fNode.getChild(1);
+ gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
node = gNode.getChild(9);
assertEquals("AnotherLocal", (((SymbolNode) node).getSymbol()).getName());
redo(program);
- fNode = getFunctionsNode();
- util.expandNode(fNode);
+ globalsNode = getGlobalsNode();
+ util.expandNode(globalsNode);
- gNode = fNode.getChild(1);
+ gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
node = gNode.getChild(9);
@@ -697,36 +602,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
assertNamespaceNodes("NsGroup1::NsGroup10::NsGroup100::NewNamespace");
}
- @Test
- public void testOrgNode_Classes() throws Exception {
-
- // set org node threshold to a low value
- ToolOptions options = tool.getOptions(SymbolTreePlugin.OPTIONS_CATEGORY);
- int newThreshold = 4;
- options.setInt(SymbolTreePlugin.OPTION_NAME_GROUP_THRESHOLD, newThreshold);
-
- /*
- Create enough nodes to trigger an org node.
-
- Classes
- ClassGroup1
- ClassGroup10
- ClassGroup100
- ClassGroup2
- ClassGroup3
- */
- createOrgClasses(newThreshold);
-
- // create a new namespace node that would appear under an org node
- ClassSymbolNode parentNode =
- openClassNodes("ClassGroup1::ClassGroup10::ClassGroup100");
- Namespace parentNs = parentNode.getNamespace();
- createClass(parentNs, "NewClass");
-
- // verify node is in the tree
- assertClassNodes("ClassGroup1::ClassGroup10::ClassGroup100::NewClass");
- }
-
@Test
public void testDeleteOrgNode() throws Exception {
@@ -752,7 +627,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
createOrgNamespaces(newThreshold);
openNamespaceNodes("NsGroup1::NsGroup10::NsGroup100");
- GTreeNode group10 = getNode(tree, "Global", "Namespaces", "NsGroup1", "NsGroup10");
+ GTreeNode group10 = getNode(tree, "Root", "Namespaces", "NsGroup1", "NsGroup10");
List<GTreeNode> children = group10.getChildren();
List<SymbolNode> symbols =
@@ -763,7 +638,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
ActionContext context = util.getSymbolTreeContext();
performTreeAction(deleteAction, context);
- GTreeNode group1 = getNode(tree, "Global", "Namespaces", "NsGroup1");
+ GTreeNode group1 = getNode(tree, "Root", "Namespaces", "NsGroup1");
group10 = group1.getChild("NsGroup10");
assertNull(group10);
@@ -773,6 +648,24 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
}
}
+ @Test
+ public void testFindClassInNamespace() throws Exception {
+
+ Namespace namespace = createNamespace(null, "namespace");
+ GhidraClass myClass = createClass(namespace, "myClass");
+ SymbolTreeRootNode root = (SymbolTreeRootNode) tree.getModelRoot();
+ GTreeNode result = root.findSymbolNode(myClass.getSymbol(), true, TaskMonitor.DUMMY);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testFindNamespaceInClass() throws Exception {
+ GhidraClass myClass = createClass(null, "myClass");
+ Namespace namespace = createNamespace(myClass, "subNamespace");
+ SymbolTreeRootNode root = (SymbolTreeRootNode) tree.getModelRoot();
+ GTreeNode result = root.findSymbolNode(namespace.getSymbol(), true, TaskMonitor.DUMMY);
+ assertNotNull(result);
+ }
//=================================================================================================
// Private Methods
//=================================================================================================
@@ -782,11 +675,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
return (NamespaceCategoryNode) root.getChild("Namespaces");
}
- private ClassCategoryNode getClassesNode() {
- GTreeNode root = tree.getViewRoot();
- return (ClassCategoryNode) root.getChild("Classes");
- }
-
private NamespaceSymbolNode openNamespaceNodes(String path) {
GTreeNode parent = getNamespacesNode();
@@ -805,24 +693,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
return (NamespaceSymbolNode) parent;
}
- private ClassSymbolNode openClassNodes(String path) {
-
- GTreeNode parent = getClassesNode();
- String[] parts = path.split("::");
- for (String name : parts) {
- GTreeNode child = parent.getChild(name);
- String message =
- "Child '%s' not found in parent '%s' \n\tfor path '%s'"
- .formatted(name, parent, path);
- assertNotNull(message, child);
- tree.expandPath(child);
- parent = child;
- }
- waitForTree(tree);
-
- return (ClassSymbolNode) parent;
- }
-
private void createOrgNamespaces(int threshold) throws Exception {
int groupCount = 3;
for (int i = 0; i < groupCount; i++) {
@@ -840,29 +710,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
}
}
- private void createOrgClasses(int threshold) throws Exception {
- int groupCount = 3;
- for (int i = 0; i < groupCount; i++) {
- // groups need to share a common prefix
- String groupName = "Group" + (i + 1); // 1-based for readability
- int childCount = (threshold + 1);
- for (int j = 0; j < childCount; j++) {
-
- String subGroupName = groupName + j;
- for (int k = 0; k < childCount; k++) {
-
- createClass("Class" + subGroupName + k);
- }
- }
- }
- }
-
- private void expandClasses() {
- GTreeNode node = rootNode.getChild("Classes");
- tree.expandTree(node);
- waitForTree(tree);
- }
-
private void expandNamesapces() {
GTreeNode node = rootNode.getChild("Namespaces");
tree.expandTree(node);
@@ -895,12 +742,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
assertNodes(parent, paths);
}
- private void assertClassNodes(String... paths) {
- GTreeNode root = tree.getViewRoot();
- GTreeNode parent = root.getChild("Classes");
- assertNodes(parent, paths);
- }
-
private void assertNodes(GTreeNode category, String... paths) {
for (String path : paths) {
@@ -927,10 +768,6 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
return cmd.getNamespace();
}
- private void createClass(String name) throws Exception {
- createClass(program.getGlobalNamespace(), name);
- }
-
private GhidraClass createClass(Namespace parent, String name) throws Exception {
GhidraClass c = tx(program, () -> {
SymbolTable symbolTable = program.getSymbolTable();
@@ -951,8 +788,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
return s;
}
- private GTreeNode getFunctionsNode() {
- return runSwing(() -> rootNode.getChild(2));
+ private GTreeNode getGlobalsNode() {
+ return runSwing(() -> rootNode.getChild("Globals"));
}
private void getActions() {
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
index 8eb06534b5..3c9294b23c 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
@@ -23,14 +23,11 @@ import java.awt.dnd.DnDConstants;
import java.util.*;
import java.util.stream.Collectors;
-import javax.swing.tree.TreePath;
-
import org.junit.*;
import docking.DefaultActionContext;
import docking.action.DockingActionIf;
import docking.action.ToggleDockingAction;
-import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.support.GTreeDragNDropHandler;
import docking.widgets.tree.support.GTreeNodeTransferable;
@@ -39,7 +36,6 @@ import ghidra.app.plugin.core.marker.MarkerManagerPlugin;
import ghidra.app.plugin.core.programtree.ProgramTreePlugin;
import ghidra.app.plugin.core.symboltree.actions.NavigateOnIncomingAction;
import ghidra.app.plugin.core.symboltree.nodes.*;
-import ghidra.app.util.viewer.field.LabelFieldFactory;
import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginException;
@@ -98,7 +94,7 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testDropSiteOK() throws Exception {
// verify that a function is not a valid drop site
- GTreeNode nsNode = rootNode.getChild(5);
+ GTreeNode nsNode = rootNode.getChild("Namespaces");
util.createObject(nsNode, "MyNamespace", createNamespaceAction);
GTreeNode fNode = rootNode.getChild(2);
util.expandNode(fNode);
@@ -117,7 +113,7 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testDropSiteOK2() throws Exception {
// verify that a SymbolCategory is not a valid drop site
- GTreeNode nsNode = rootNode.getChild(5);
+ GTreeNode nsNode = rootNode.getChild("Namespaces");
util.createObject(nsNode, "MyNamespace", createNamespaceAction);
GTreeNode fNode = rootNode.getChild(2);
util.expandNode(fNode);
@@ -138,7 +134,7 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testDragDrop() throws Exception {
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
assertTrue(nsParentNode instanceof SymbolCategoryNode);
SymbolCategory namespaceCategory = ((SymbolCategoryNode) nsParentNode).getSymbolCategory();
@@ -160,7 +156,7 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
doDrag(nsNode, DnDConstants.ACTION_MOVE, gNode, sNode);
util.waitForTree();
- nsParentNode = rootNode.getChild(5);
+ nsParentNode = rootNode.getChild("Namespaces");
nsNode = nsParentNode.getChild(index);
util.expandNode(nsNode);
assertEquals(2, nsNode.getChildCount());
@@ -186,58 +182,6 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
waitForSwing();
}
- @Test
- public void testDragDropLabelOnClass() throws Exception {
- final ToggleDockingAction navigateIncomingAction =
- (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
-
- runSwing(() -> navigateIncomingAction.setSelected(true));
- GTreeNode cNode = rootNode.getChild(4);
- GTreeNode nsNode = util.createObject(cNode, "MyClass", createClassAction);
- assertNotNull(nsNode);
- int index = nsNode.getIndexInParent();
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
-
- GTreeNode gNode = fNode.getChild(1);
- GTreeNode sNode = fNode.getChild(2);
- String gNodeName = gNode.getName();
- String sNodeName = sNode.getName();
- util.selectNodes(new GTreeNode[] { gNode, sNode });
- doDrag(nsNode, DnDConstants.ACTION_MOVE, gNode, sNode);
-
- util.waitForTree();
- cNode = rootNode.getChild(4);
- nsNode = cNode.getChild(index);
- Symbol classSymbol = ((SymbolNode) nsNode).getSymbol();
-
- util.expandNode(nsNode);
- assertEquals(2, nsNode.getChildCount());
- gNode = nsNode.getChild(0);
- assertEquals(gNodeName, gNode.getName());
- sNode = nsNode.getChild(1);
- assertEquals(sNodeName, sNode.getName());
-
- Symbol symbol = getUniqueSymbol(program, "entry");
- assertTrue(cbPlugin.goToField(symbol.getAddress(), LabelFieldFactory.FIELD_NAME, 0, 0));
-
- Thread.sleep(1000);
- cbPlugin.updateNow();
-
- GTree tree = util.getTree();
- TreePath path = tree.getSelectionPath();
- assertNotNull(path);
- GTreeNode eNode = (GTreeNode) path.getLastPathComponent();
- util.selectNodes(new GTreeNode[] { eNode });
-
- doDrag(nsNode, DnDConstants.ACTION_MOVE, eNode);
-
- Symbol s = ((SymbolNode) eNode).getSymbol();
-
- // parent namespace should be MyClass.
- assertEquals(classSymbol.getObject(), s.getParentNamespace());
- }
-
@Test
public void testSortNamespaces() throws Exception {
SymbolTable symTable = program.getSymbolTable();
@@ -260,7 +204,7 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
List<Symbol> symbolList = new ArrayList<>();
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
util.expandNode(nsParentNode);
for (int i = 0; i < nsParentNode.getChildCount(); i++) {
GTreeNode node = nsParentNode.getChild(i);
@@ -311,8 +255,8 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
program.flushEvents();
util.waitForTree();
- GTreeNode cnode = rootNode.getChild(4);
- List<GTreeNode> children = cnode.getChildren();
+ GTreeNode nsNode = rootNode.getChild("Namespaces");
+ List<GTreeNode> children = nsNode.getChildren();
//@formatter:off
List<String> symbolNames =
@@ -378,39 +322,31 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
runSwing(() -> util.getTree().stopEditing());
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
util.expandNode(nsParentNode);
assertEquals(1, nsParentNode.getChildCount());
}
@Test
- public void testCreateClassAtClassesNode() throws Exception {
- GTreeNode classesRoot = rootNode.getChild("Classes");
- util.selectNode(classesRoot);
+ public void testCreateClassOnNamespacesNode() throws Exception {
+ GTreeNode namespacesNode = rootNode.getChild("Namespaces");
+ util.selectNode(namespacesNode);
assertTrue(createClassAction.isEnabledForContext(util.getSymbolTreeContext()));
performAction(createClassAction, util.getSymbolTreeContext(), true);
program.flushEvents();
util.waitForTree();
runSwing(() -> util.getTree().stopEditing());
- GTreeNode cParentNode = rootNode.getChild(4);
- util.expandNode(cParentNode);
- assertEquals(1, cParentNode.getChildCount());
- }
-
- @Test
- public void testActionsEnabledOnClassNode() throws Exception {
- GTreeNode cNode = rootNode.getChild(4);
- util.selectNode(cNode);
- assertTrue(createClassAction.isEnabledForContext(util.getSymbolTreeContext()));
- assertFalse(createNamespaceAction.isEnabledForContext(util.getSymbolTreeContext()));
+ namespacesNode = rootNode.getChild("Namespaces");
+ util.expandNode(namespacesNode);
+ assertEquals(1, namespacesNode.getChildCount());
}
@Test
public void testActionsEnabledOnNamespaceNode() throws Exception {
- GTreeNode nsParentNode = rootNode.getChild(5);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
util.selectNode(nsParentNode);
- assertFalse(createClassAction.isEnabledForContext(util.getSymbolTreeContext()));
+ assertTrue(createClassAction.isEnabledForContext(util.getSymbolTreeContext()));
assertTrue(createNamespaceAction.isEnabledForContext(util.getSymbolTreeContext()));
}
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin4Test.java
index a2324c24aa..11b67aeda9 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin4Test.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -79,18 +79,18 @@ public class SymbolTreePlugin4Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCutPasteAtNamespace() throws Exception {
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
// create a new namespace;
// cut and paste a function at the new namespace
- GTreeNode nsParentNode = rootNode.getChild(5);
- GTreeNode nsNode = util.createObject(nsParentNode, "MYNamespace", createNamespaceAction);
+ GTreeNode nsParentNode = rootNode.getChild("Namespaces");
+ GTreeNode nsNode = util.createObject(nsParentNode, "MyNamespace", createNamespaceAction);
util.waitForTree();
- fNode = rootNode.getChild(2);
- gNode = fNode.getChild(1);
+ globalsNode = rootNode.getChild("Globals");
+ gNode = globalsNode.getChild("ghidra");
util.selectNode(gNode);
performAction(cutAction, util.getSymbolTreeContext(), true);
@@ -104,70 +104,26 @@ public class SymbolTreePlugin4Test extends AbstractGhidraHeadedIntegrationTest {
waitForSwing();
// re-acquire nsNode
- nsParentNode = rootNode.getChild(5);
- nsNode = nsParentNode.getChild(0);
+ nsParentNode = rootNode.getChild("Namespaces");
+ nsNode = nsParentNode.getChild("MyNamespace");
util.expandNode(nsNode);
util.waitForTree();
- gNode = nsNode.getChild(0);
-
- Symbol s = ((SymbolNode) gNode).getSymbol();
- assertEquals("ghidra", s.getName());
-
- fNode = rootNode.getChild(2);
- util.expandNode(fNode);
- assertEquals(2, fNode.getChildCount());
- }
-
- @Test
- public void testCutPasteAtClass() throws Exception {
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
-
- GTreeNode gNode = fNode.getChild(1);
-
- // create a new namespace;
- // cut and paste a function at the new class
- GTreeNode cParentNode = rootNode.getChild(4);
- GTreeNode cNode = util.createObject(cParentNode, "MYClass", createClassAction);
- int index = cNode.getIndexInParent();
- util.waitForTree();
- fNode = rootNode.getChild(2);
- gNode = fNode.getChild(1);
-
- util.selectNode(gNode);
-
- performAction(cutAction, util.getSymbolTreeContext(), true);
- util.selectNode(cNode);
+ gNode = nsNode.getChild("ghidra");
- SymbolTreeProvider provider = plugin.getProvider();
- assertTrue(pasteAction.isEnabledForContext(provider.getActionContext(null)));
- performAction(pasteAction, util.getSymbolTreeContext(), true);
- program.flushEvents();
- waitForSwing();
-
- // re-acquire cNode
- cParentNode = rootNode.getChild(4);
- cNode = cParentNode.getChild(index);
- util.expandNode(cNode);
- util.waitForTree();
- waitForSwing();
- gNode = cNode.getChild(0);
Symbol s = ((SymbolNode) gNode).getSymbol();
assertEquals("ghidra", s.getName());
- fNode = rootNode.getChild(2);
- assertNotNull(fNode);
- util.expandNode(fNode);
- assertEquals(2, fNode.getChildCount());
+ globalsNode = rootNode.getChild("Globals");
+ assertNull(globalsNode.getChild("ghidra"));
}
@Test
public void testMakeSelection() throws Exception {
// select the ghidra function; make selection
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
util.selectNode(gNode);
@@ -178,11 +134,11 @@ public class SymbolTreePlugin4Test extends AbstractGhidraHeadedIntegrationTest {
performAction(selectionAction, util.getSymbolTreeContext(), true);
assertTrue(f.getBody().hasSameAddresses(cbPlugin.getCurrentSelection()));
- GTreeNode dNode = fNode.getChild(0);
+ GTreeNode dNode = globalsNode.getChild("doStuff");
util.expandNode(dNode);
- GTreeNode pNode = dNode.getChild(0);
+ GTreeNode pNode = dNode.getChild("param_1");
- GTreeNode sNode = fNode.getChild(2);
+ GTreeNode sNode = globalsNode.getChild("sscanf");
s = ((SymbolNode) sNode).getSymbol();
f = (Function) s.getObject();
util.selectNodes(new GTreeNode[] { pNode, sNode });
@@ -291,10 +247,10 @@ public class SymbolTreePlugin4Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testClone_WithFilter() throws Exception {
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
util.selectNode(gNode);
@@ -329,10 +285,10 @@ public class SymbolTreePlugin4Test extends AbstractGhidraHeadedIntegrationTest {
setFilterOptions(gTree, TextFilterStrategy.MATCHES_EXACTLY, false);
filter(gTree, "param_1");
- GTreeNode fNode = rootNode.getChild(2);
- util.expandNode(fNode);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
+ util.expandNode(globalsNode);
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.expandNode(gNode);
util.selectNode(gNode);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePluginX86Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePluginX86Test.java
index 490c8351b7..2516fb1c9b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePluginX86Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePluginX86Test.java
@@ -94,10 +94,10 @@ public class SymbolTreePluginX86Test extends AbstractGhidraHeadedIntegrationTest
cbPlugin.goToField(util.addr(0x01002d06L), OperandFieldFactory.FIELD_NAME, 0, 0));
util.waitForTree();
- GTreeNode fNode = rootNode.getChild(2);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
util.waitForTree();
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.waitForTree();
GTreeNode pNode = gNode.getChild("param_8");
@@ -130,11 +130,11 @@ public class SymbolTreePluginX86Test extends AbstractGhidraHeadedIntegrationTest
util.waitForTree();
// param_14 should be selected in the symbol tree
- GTreeNode fNode = rootNode.getChild(2);
+ GTreeNode globalsNode = rootNode.getChild("Globals");
util.waitForTree();
- GTreeNode gNode = fNode.getChild(1);
+ GTreeNode gNode = globalsNode.getChild("ghidra");
util.waitForTree();
GTreeNode pNode = gNode.getChild("param_8");
@@ -150,8 +150,8 @@ public class SymbolTreePluginX86Test extends AbstractGhidraHeadedIntegrationTest
util.waitForTree();
- fNode = rootNode.getChild(2);
- gNode = fNode.getChild(1);
+ globalsNode = rootNode.getChild("Globals");
+ gNode = globalsNode.getChild("ghidra");
assertEquals(count - 1, gNode.getChildCount());
for (int i = 0; i < count - 1; i++) {
@@ -210,7 +210,8 @@ public class SymbolTreePluginX86Test extends AbstractGhidraHeadedIntegrationTest
createNamespaceAction = getAction(plugin, "Create Namespace");
assertNotNull(createNamespaceAction);
- navigateIncomingAction = (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
+ navigateIncomingAction =
+ (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
assertNotNull(navigateIncomingAction);
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeTestUtils.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeTestUtils.java
index 7a0e173d12..771ca9b617 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeTestUtils.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeTestUtils.java
@@ -301,7 +301,7 @@ class SymbolTreeTestUtils {
void selectNode(GTreeNode node) throws Exception {
GTreeNode parent = node.getParent();
if (parent != null) {
- tree.expandTree(node.getParent());
+ tree.expandPath(node);
}
tree.setSelectedNode(node);
waitForTree();
@@ -400,7 +400,8 @@ class SymbolTreeTestUtils {
createNamespaceAction = getAction(plugin, "Create Namespace");
assertNotNull(createNamespaceAction);
- navigateIncomingAction = (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
+ navigateIncomingAction =
+ (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
assertNotNull(navigateIncomingAction);
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symtable/SymbolTablePluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symtable/SymbolTablePluginTest.java
index 35bb972701..658627bd08 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symtable/SymbolTablePluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symtable/SymbolTablePluginTest.java
@@ -640,9 +640,8 @@ public class SymbolTablePluginTest extends AbstractGhidraHeadedIntegrationTest {
public void testSetPinnedActionNotEnabledForExternalSymbols() throws Exception {
openProgram("sample");
- int row1 = findRow("CharLowerW", "USER32.dll");
- int row2 = findRow("CharLowerZ", "USER32.dll");
- selectRows(row1, row2);
+ int row = findRow("CharLowerZ");
+ selectRows(row, row);
ActionContext actionContext = provider.getActionContext(null);
int[] selectedRows = symbolTable.getSelectedRows();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/listingpanel/ListingPanelTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/listingpanel/ListingPanelTest.java
index c86f691e43..e2ea141f74 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/listingpanel/ListingPanelTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/listingpanel/ListingPanelTest.java
@@ -132,7 +132,7 @@ public class ListingPanelTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("01001008", l.getField(3).getText());
assertEquals("01 02 03 04", l.getField(4).getText());
assertEquals("addr", l.getField(5).getText());
- assertEquals("ADVAPI32.dll::RegQueryValueExW", l.getField(6).getText());
+ assertEquals("ADVAPI32.dll:RegQueryValueExW", l.getField(6).getText());
}
@Test
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/external/ExternalManagerDBTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/external/ExternalManagerDBTest.java
index c9e720080a..a3eee89811 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/external/ExternalManagerDBTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/external/ExternalManagerDBTest.java
@@ -205,11 +205,15 @@ public class ExternalManagerDBTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue("ext2 library not found", s != null && s.getSymbolType() == SymbolType.LIBRARY);
Library ext2 = (Library) s.getObject();
- assertEquals(loc2, extMgr.getUniqueExternalLocation(ext1, "label1"));
- assertEquals(loc3, extMgr.getUniqueExternalLocation(ext2, "label1"));
- assertEquals(loc4, extMgr.getUniqueExternalLocation(ext2, "label2"));
- assertEquals(loc5, extMgr.getUniqueExternalLocation(ext2, loc5.getLabel()));
-
+ assertEquals(loc2, extMgr.getUniqueExternalLocation(ext1, null, "label1"));
+ assertEquals(loc3, extMgr.getUniqueExternalLocation(ext2, null, "label1"));
+ assertEquals(loc4, extMgr.getUniqueExternalLocation(ext2, null, "label2"));
+ assertEquals(loc5, extMgr.getUniqueExternalLocation(ext2, null, loc5.getLabel()));
+
+ assertEquals(loc2, extMgr.getUniqueExternalLocation("ext1", "label1"));
+ assertEquals(loc3, extMgr.getUniqueExternalLocation("ext2", "label1"));
+ assertEquals(loc4, extMgr.getUniqueExternalLocation("ext2", "label2"));
+ assertEquals(loc5, extMgr.getUniqueExternalLocation("ext2", loc5.getLabel()));
}
@Test
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/function/ExternalFunctionDBTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/function/ExternalFunctionDBTest.java
index 02b4a09329..86f8e43666 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/function/ExternalFunctionDBTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/function/ExternalFunctionDBTest.java
@@ -76,8 +76,8 @@ public class ExternalFunctionDBTest extends AbstractGhidraHeadedIntegrationTest
assertNull(extLoc.getFunction());
Namespace parentNamespace = extLoc.getParentNameSpace();
- assertEquals(SymbolType.LIBRARY, parentNamespace.getSymbol().getSymbolType());
- assertTrue(parentNamespace.isExternal());
+ assertTrue(parentNamespace.isGlobal());
+ assertTrue(extSym.isExternal());
assertNull(functionManager.getFunction(extSym.getID()));
@@ -225,11 +225,10 @@ public class ExternalFunctionDBTest extends AbstractGhidraHeadedIntegrationTest
@Test
public void testCodeSymbolRestore() throws Exception {
Function f = createExternalFunction("foo");
- Namespace parentNamespace = f.getSymbol().getParentNamespace();
-
+ Library library = f.getSymbol().getLibrary();
program.getFunctionManager().removeFunction(f.getEntryPoint());
ExternalLocation externalLocation =
- program.getExternalManager().getUniqueExternalLocation(parentNamespace, "foo");
+ program.getExternalManager().getUniqueExternalLocation(library, null, "foo");
assertNotNull(externalLocation);
assertTrue(!externalLocation.isFunction());
assertEquals(SymbolType.LABEL, externalLocation.getSymbol().getSymbolType());
@@ -241,11 +240,11 @@ public class ExternalFunctionDBTest extends AbstractGhidraHeadedIntegrationTest
extMgr.addExtLocation("TestLibrary", null, addr(0x1000), SourceType.USER_DEFINED);
Function f = extLoc.createFunction();
- Namespace parentNamespace = f.getSymbol().getParentNamespace();
+ Library library = f.getSymbol().getLibrary();
program.getFunctionManager().removeFunction(f.getEntryPoint());
ExternalLocation externalLocation =
- program.getExternalManager().getUniqueExternalLocation(parentNamespace, "EXT_00001000");
+ program.getExternalManager().getUniqueExternalLocation(library, null, "EXT_00001000");
assertNotNull(externalLocation);
assertTrue(!externalLocation.isFunction());
assertEquals(SymbolType.LABEL, externalLocation.getSymbol().getSymbolType());
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/symbol/SymbolManagerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/symbol/SymbolManagerTest.java
index f9d9406f88..c40a81ec43 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/symbol/SymbolManagerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/symbol/SymbolManagerTest.java
@@ -25,6 +25,7 @@ import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.app.cmd.function.CreateFunctionCmd;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
+import ghidra.program.database.external.ExternalManagerDB;
import ghidra.program.database.function.OverlappingFunctionException;
import ghidra.program.model.address.*;
import ghidra.program.model.data.*;
@@ -1113,6 +1114,45 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(3, sym1.getReferenceCount());
}
+ @Test
+ public void testGetSymbolsByLibrary() throws Exception {
+ ExternalManagerDB extMgr = program.getExternalManager();
+ extMgr.addExtLocation("lib1", "bob", null, SourceType.USER_DEFINED);
+ extMgr.addExtLocation("lib1", "joe", null, SourceType.USER_DEFINED);
+ extMgr.addExtFunction("lib2", "alpha", null, SourceType.USER_DEFINED);
+ extMgr.addExtLocation("lib2", "beta", null, SourceType.USER_DEFINED);
+
+ Symbol librarySymbol = st.getLibrarySymbol("lib1");
+ Library lib1 = (Library) librarySymbol.getObject();
+ SymbolIterator it = st.getSymbols(lib1);
+ assertTrue(it.hasNext());
+ assertEquals("bob", it.next().getName());
+ assertTrue(it.hasNext());
+ assertEquals("joe", it.next().getName());
+ assertFalse(it.hasNext());
+
+ librarySymbol = st.getLibrarySymbol("lib2");
+ Library lib2 = (Library) librarySymbol.getObject();
+ it = st.getSymbols(lib2);
+ assertTrue(it.hasNext());
+ assertEquals("alpha", it.next().getName());
+ assertTrue(it.hasNext());
+ assertEquals("beta", it.next().getName());
+ assertFalse(it.hasNext());
+
+ }
+
+ @Test
+ public void testGetExtSymbolByNameNamespaceAddress() throws Exception {
+ ExternalManagerDB extMgr = program.getExternalManager();
+ ExternalLocation extFunction =
+ extMgr.addExtFunction((Library) null, null, addr(0), SourceType.IMPORTED);
+
+ Symbol symbol =
+ st.getSymbol("EXT_FUN_00000000", extFunction.getExternalSpaceAddress(), null);
+ assertEquals(extFunction.getSymbol(), symbol);
+ }
+
@Test
public void testSymbolSearcherIterator() throws Exception {
createLabel(addr(100), "Four");
@@ -1276,11 +1316,11 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
// External space before memory space
Symbol s = it.next();
assertNotNull(s);
- assertEquals("Test::7", s.getName(true));
+ assertEquals("7", s.getName(true));
assertEquals(extAddr(1), s.getAddress());
s = it.next();
assertNotNull(s);
- assertEquals("Test::8", s.getName(true));
+ assertEquals("8", s.getName(true));
assertEquals(extAddr(2), s.getAddress());
s = it.next();
@@ -1301,12 +1341,12 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue(it.hasNext());
s = it.next();
assertNotNull(s);
- assertEquals("Test::7", s.getName(true));
+ assertEquals("7", s.getName(true));
assertTrue(it.hasNext());
s = it.next();
assertNotNull(s);
- assertEquals("Test::8", s.getName(true));
+ assertEquals("8", s.getName(true));
for (int i = 1; i <= 6; i++) {
assertTrue(it.hasNext());
@@ -1839,15 +1879,12 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateLibScope() throws Exception {
- Namespace scope = st.createExternalLibrary("TestScope", SourceType.USER_DEFINED);
- assertNotNull(scope);
- assertEquals("TestScope", scope.getName());
- assertTrue(scope.getBody().isEmpty());
- assertTrue(scope instanceof Library);
- assertEquals(globalScope, scope.getParentNamespace());
+ Library library = st.createExternalLibrary("TestScope", SourceType.USER_DEFINED);
+ assertNotNull(library);
+ assertEquals("TestScope", library.getName());
- Symbol symbol = scope.getSymbol();
- assertEquals(scope.getName(), symbol.getName());
+ Symbol symbol = library.getSymbol();
+ assertEquals(library.getName(), symbol.getName());
assertEquals(globalScope, symbol.getParentNamespace());
}
@@ -2286,9 +2323,6 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
Namespace scope = st.createClass(null, "TestScope", SourceType.USER_DEFINED);
assertTrue(s.isValidParent(scope));
-
- scope = st.createExternalLibrary("ExtLib", SourceType.USER_DEFINED);
- assertTrue(!s.isValidParent(scope));
}
@Test
@@ -2382,7 +2416,7 @@ public class SymbolManagerTest extends AbstractGhidraHeadedIntegrationTest {
// good
}
- Namespace scope = st.createClass(lib, "TestClass", SourceType.USER_DEFINED);
+ Namespace scope = st.createClass(null, "TestClass", SourceType.USER_DEFINED);
assertTrue(extSym.isValidParent(scope));
extFunc.setParentNamespace(scope);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/util/ThunkFunctionDiffTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/util/ThunkFunctionDiffTest.java
index 71ff9eec03..5e9659577d 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/util/ThunkFunctionDiffTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/util/ThunkFunctionDiffTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -757,10 +757,10 @@ public class ThunkFunctionDiffTest extends AbstractGhidraHeadedIntegrationTest {
FunctionManager latestFM = latestProgram.getFunctionManager();
FunctionManager myFM = myProgram.getFunctionManager();
- Namespace externalLibrary = (Namespace) getUniqueSymbol(myProgram, "user32.dll",
+ Library externalLibrary = (Library) getUniqueSymbol(myProgram, "user32.dll",
myProgram.getGlobalNamespace()).getObject();
assertNotNull(externalLibrary);
- Symbol apples = getUniqueSymbol(myProgram, "apples", externalLibrary);
+ Symbol apples = getUniqueSymbol(myProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, apples.getSymbolType());
Function myExternalFunction = (Function) apples.getObject();
Function latestThunked = latestFM.getFunctionAt(addr(latestProgram, FUNCTION_3));
@@ -855,18 +855,17 @@ public class ThunkFunctionDiffTest extends AbstractGhidraHeadedIntegrationTest {
FunctionManager latestFM = latestProgram.getFunctionManager();
FunctionManager myFM = myProgram.getFunctionManager();
- Namespace latestExternalLibrary = (Namespace) getUniqueSymbol(latestProgram, "user32.dll",
+ Library latestExternalLibrary = (Library) getUniqueSymbol(latestProgram, "user32.dll",
latestProgram.getGlobalNamespace()).getObject();
assertNotNull(latestExternalLibrary);
- Symbol latestExternalApples =
- getUniqueSymbol(latestProgram, "apples", latestExternalLibrary);
+ Symbol latestExternalApples = getUniqueSymbol(latestProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, latestExternalApples.getSymbolType());
Function latestExternalFunction = (Function) latestExternalApples.getObject();
- Namespace myExternalLibrary = (Namespace) getUniqueSymbol(myProgram, "user32.dll",
+ Library myExternalLibrary = (Library) getUniqueSymbol(myProgram, "user32.dll",
myProgram.getGlobalNamespace()).getObject();
assertNotNull(myExternalLibrary);
- Symbol myExternalApples = getUniqueSymbol(myProgram, "apples", myExternalLibrary);
+ Symbol myExternalApples = getUniqueSymbol(myProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, myExternalApples.getSymbolType());
Function myExternalFunction = (Function) myExternalApples.getObject();
@@ -959,19 +958,18 @@ public class ThunkFunctionDiffTest extends AbstractGhidraHeadedIntegrationTest {
FunctionManager latestFM = latestProgram.getFunctionManager();
FunctionManager myFM = myProgram.getFunctionManager();
- Namespace latestExternalLibrary = (Namespace) getUniqueSymbol(latestProgram, "user32.dll",
+ Library latestExternalLibrary = (Library) getUniqueSymbol(latestProgram, "user32.dll",
latestProgram.getGlobalNamespace()).getObject();
assertNotNull(latestExternalLibrary);
- Symbol latestExternalApples =
- getUniqueSymbol(latestProgram, "apples", latestExternalLibrary);
+ Symbol latestExternalApples = getUniqueSymbol(latestProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, latestExternalApples.getSymbolType());
Function latestExternalFunction = (Function) latestExternalApples.getObject();
- Namespace myExternalLibrary = (Namespace) getUniqueSymbol(myProgram, "user32.dll",
+ Library myExternalLibrary = (Library) getUniqueSymbol(myProgram, "user32.dll",
myProgram.getGlobalNamespace()).getObject();
assertNotNull(myExternalLibrary);
SymbolTable mySymTab = myProgram.getSymbolTable();
- Symbol myExternalApples = getUniqueSymbol(myProgram, "apples", myExternalLibrary);
+ Symbol myExternalApples = getUniqueSymbol(myProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, myExternalApples.getSymbolType());
Function myExternalFunction = (Function) myExternalApples.getObject();
@@ -1065,18 +1063,17 @@ public class ThunkFunctionDiffTest extends AbstractGhidraHeadedIntegrationTest {
FunctionManager latestFM = latestProgram.getFunctionManager();
FunctionManager myFM = myProgram.getFunctionManager();
- Namespace latestExternalLibrary = (Namespace) getUniqueSymbol(latestProgram, "user32.dll",
+ Library latestExternalLibrary = (Library) getUniqueSymbol(latestProgram, "user32.dll",
latestProgram.getGlobalNamespace()).getObject();
assertNotNull(latestExternalLibrary);
- Symbol latestExternalApples =
- getUniqueSymbol(latestProgram, "apples", latestExternalLibrary);
+ Symbol latestExternalApples = getUniqueSymbol(latestProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, latestExternalApples.getSymbolType());
Function latestExternalFunction = (Function) latestExternalApples.getObject();
- Namespace myExternalLibrary = (Namespace) getUniqueSymbol(myProgram, "user32.dll",
+ Library myExternalLibrary = (Library) getUniqueSymbol(myProgram, "user32.dll",
myProgram.getGlobalNamespace()).getObject();
assertNotNull(myExternalLibrary);
- Symbol myExternalApples = getUniqueSymbol(myProgram, "oranges", myExternalLibrary);
+ Symbol myExternalApples = getUniqueSymbol(myProgram, "oranges", null);
assertEquals(SymbolType.FUNCTION, myExternalApples.getSymbolType());
Function myExternalFunction = (Function) myExternalApples.getObject();
@@ -1170,18 +1167,17 @@ public class ThunkFunctionDiffTest extends AbstractGhidraHeadedIntegrationTest {
FunctionManager latestFM = latestProgram.getFunctionManager();
FunctionManager myFM = myProgram.getFunctionManager();
- Namespace latestExternalLibrary = (Namespace) getUniqueSymbol(latestProgram, "user32.dll",
+ Library latestExternalLibrary = (Library) getUniqueSymbol(latestProgram, "user32.dll",
latestProgram.getGlobalNamespace()).getObject();
assertNotNull(latestExternalLibrary);
- Symbol latestExternalApples =
- getUniqueSymbol(latestProgram, "apples", latestExternalLibrary);
+ Symbol latestExternalApples = getUniqueSymbol(latestProgram, "apples", null);
assertEquals(SymbolType.FUNCTION, latestExternalApples.getSymbolType());
Function latestExternalFunction = (Function) latestExternalApples.getObject();
- Namespace myExternalLibrary = (Namespace) getUniqueSymbol(myProgram, "user32.dll",
+ Library myExternalLibrary = (Library) getUniqueSymbol(myProgram, "user32.dll",
myProgram.getGlobalNamespace()).getObject();
assertNotNull(myExternalLibrary);
- Symbol myExternalApples = getUniqueSymbol(myProgram, "oranges", myExternalLibrary);
+ Symbol myExternalApples = getUniqueSymbol(myProgram, "oranges", null);
assertEquals(SymbolType.FUNCTION, myExternalApples.getSymbolType());
Function myExternalFunction = (Function) myExternalApples.getObject();
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNodeTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNodeTest.java
index be4066f335..272cc0ff73 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNodeTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/symboltree/nodes/OrganizationNodeTest.java
@@ -147,7 +147,7 @@ public class OrganizationNodeTest extends AbstractDockingTest {
assertEquals("11 more...", dupNode.getChild(OrganizationNode.MAX_SAME_NAME).getName());
SymbolTreeNode node = (SymbolTreeNode) nodeList.get(nodeList.size() - 1);
- simulateSmbolDeleted(dNode, node.getSymbol());
+ simulateSymbolDeleted(dNode, node.getSymbol());
assertEquals("10 more...", dupNode.getChild(dupNode.getChildCount() - 1).getName());
}
@@ -167,7 +167,7 @@ public class OrganizationNodeTest extends AbstractDockingTest {
assertEquals("11 more...", dupNode.getChild(OrganizationNode.MAX_SAME_NAME).getName());
SymbolTreeNode node = (SymbolTreeNode) nodeList.get(4);
- simulateSmbolDeleted(dNode, node.getSymbol());
+ simulateSymbolDeleted(dNode, node.getSymbol());
assertEquals(OrganizationNode.MAX_SAME_NAME, dupNode.getChildCount());
assertEquals("11 more...", dupNode.getChild(dupNode.getChildCount() - 1).getName());
@@ -227,9 +227,9 @@ public class OrganizationNodeTest extends AbstractDockingTest {
assertEquals("AB", nodeA.getChild(0).getName());
}
- private void simulateSmbolDeleted(SymbolTreeNode root, Symbol symbolToDelete) {
- SymbolNode key = SymbolNode.createKeyNode(symbolToDelete, symbolToDelete.getName(), null);
- GTreeNode found = root.findSymbolTreeNode(key, false, TaskMonitor.DUMMY);
+ private void simulateSymbolDeleted(SymbolTreeNode node, Symbol symbolToDelete) {
+ SearchNode key = SearchNode.create(symbolToDelete, symbolToDelete.getName());
+ GTreeNode found = node.getMatchingChild(key, false);
Swing.runNow(() -> found.getParent().removeNode(found));
}
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/program/database/MergeProgram.java b/Ghidra/Features/Base/src/test/java/ghidra/program/database/MergeProgram.java
index 72c27c77c0..eded90f15b 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/program/database/MergeProgram.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/program/database/MergeProgram.java
@@ -125,6 +125,10 @@ public class MergeProgram {
}
}
+ public Namespace createNamespace(String name, SourceType type) {
+ return createNamespace(null, name, type);
+ }
+
public Namespace createNamespace(Namespace parent, String name, SourceType type) {
Namespace result = null;
@@ -135,9 +139,9 @@ public class MergeProgram {
try {
// make sure we get the equivalent namespace for the given program
- Namespace parentNamespace = findMatchingNamespace(p, parent);
+ parent = findMatchingNamespace(p, parent);
- Namespace ns = symbolTable.createNameSpace(parentNamespace, name, type);
+ Namespace ns = symbolTable.createNameSpace(parent, name, type);
if (result == null) {
result = ns; // always use the first program for consistency
}
@@ -249,8 +253,13 @@ public class MergeProgram {
}
}
- public void addExternalLocation(Namespace namespace, String label, String address,
- SourceType type) {
+ public void addExternalLocation(Library library, String label,
+ String address, SourceType type) {
+ addExternalLocation(library, null, label, address, type);
+ }
+
+ public void addExternalLocation(Library library, Namespace namespace, String label,
+ String address, SourceType type) {
startTransactions();
try {
@@ -258,14 +267,14 @@ public class MergeProgram {
// make sure we get the equivalent namespace for the given program
Namespace parentNamespace = findMatchingNamespace(p, namespace);
-
+ library = findMatchingLibrary(p, library);
ExternalManager externalManager = p.getExternalManager();
Address addr = null;
if (address != null) {
addr = addr(p, address);
}
try {
- externalManager.addExtLocation(parentNamespace, label, addr, type);
+ externalManager.addExtLocation(library, parentNamespace, label, addr, type);
}
catch (Exception e) {
throw new RuntimeException("Exception adding extenal location", e);
@@ -277,8 +286,13 @@ public class MergeProgram {
}
}
- public void addExternalLocation(Namespace namespace, String label, String address, DataType dt,
- SourceType type) {
+ public void addExternalLocation(Library library, String label,
+ String address, DataType dt, SourceType type) {
+ addExternalLocation(library, null, label, address, dt, type);
+ }
+
+ public void addExternalLocation(Library library, Namespace namespace, String label,
+ String address, DataType dt, SourceType type) {
startTransactions();
try {
@@ -286,15 +300,15 @@ public class MergeProgram {
// make sure we get the equivalent namespace for the given program
Namespace parentNamespace = findMatchingNamespace(p, namespace);
-
+ Library myLibrary = findMatchingLibrary(p, library);
ExternalManager externalManager = p.getExternalManager();
Address addr = null;
if (address != null) {
addr = addr(p, address);
}
try {
- ExternalLocation loc =
- externalManager.addExtLocation(parentNamespace, label, addr, type);
+ ExternalLocation loc = externalManager.addExtLocation(myLibrary,
+ parentNamespace, label, addr, type);
loc.setDataType(dt);
}
catch (Exception e) {
@@ -307,7 +321,13 @@ public class MergeProgram {
}
}
- public ExternalLocation addExternalFunction(Namespace namespace, String name, String address,
+ public ExternalLocation addExternalFunction(Library library, String name, String address,
+ SourceType type) {
+ return addExternalFunction(library, null, name, address, type);
+ }
+
+ public ExternalLocation addExternalFunction(Library library, Namespace namespace, String name,
+ String address,
SourceType type) {
ExternalLocation result = null;
@@ -318,6 +338,7 @@ public class MergeProgram {
// make sure we get the equivalent namespace for the given program
Namespace parentNamespace = findMatchingNamespace(p, namespace);
+ library = findMatchingLibrary(p, library);
ExternalManager externalManager = p.getExternalManager();
Address addr = null;
@@ -326,7 +347,7 @@ public class MergeProgram {
}
try {
ExternalLocation loc =
- externalManager.addExtFunction(parentNamespace, name, addr, type);
+ externalManager.addExtFunction(library, parentNamespace, name, addr, type);
if (result == null) {
result = loc;
}
@@ -406,28 +427,45 @@ public class MergeProgram {
return functionManager.getFunctionAt(f.getEntryPoint());
}
+ private Library findMatchingLibrary(Program program, Library otherLibrary) {
+ if (otherLibrary == null) {
+ return null;
+ }
+ Program otherProgram = otherLibrary.getSymbol().getProgram();
+ if (otherProgram == program) {
+ return otherLibrary;
+ }
+ return getCorrespondingLibrary(program, otherLibrary, otherProgram);
+ }
+
private Namespace findMatchingNamespace(Program program, Namespace otherNamespace) {
if (otherNamespace == null) {
return program.getGlobalNamespace();
}
- Program source = otherNamespace.getSymbol().getProgram();
- if (source == program) {
+ Program otherProgram = otherNamespace.getSymbol().getProgram();
+ if (otherProgram == program) {
return otherNamespace;
}
- return getCorrespondingNamespace(source, otherNamespace, program);
+ return getCorrespondingNamespace(program, otherNamespace, otherProgram);
}
- private Namespace getCorrespondingNamespace(Program source, Namespace ns,
+ private Library getCorrespondingLibrary(Program program, Library library,
Program otherProgram) {
- if (ns == source.getGlobalNamespace()) {
- return otherProgram.getGlobalNamespace();
+ Symbol librarySymbol = program.getSymbolTable().getLibrarySymbol(library.getName());
+ return librarySymbol == null ? null : (Library) librarySymbol.getObject();
+ }
+
+ private Namespace getCorrespondingNamespace(Program program, Namespace ns,
+ Program otherProgram) {
+ if (ns == otherProgram.getGlobalNamespace()) {
+ return program.getGlobalNamespace();
}
Namespace parent = ns.getParentNamespace();
- Namespace otherNamespace = getCorrespondingNamespace(source, parent, otherProgram);
- SymbolTable symbolTable = otherProgram.getSymbolTable();
- return symbolTable.getNamespace(ns.getName(), otherNamespace);
+ Namespace namespace = getCorrespondingNamespace(program, parent, otherProgram);
+ SymbolTable symbolTable = program.getSymbolTable();
+ return symbolTable.getNamespace(ns.getName(), namespace);
}
private void startTransactions() {
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java
index f812b15946..ed83c4fa57 100644
--- a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java
+++ b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java
@@ -426,7 +426,7 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {
// then check to see if the special typeinfo namespace is in external space
// if so then relocations are present and have not been fixed up because when fixed up
// the namespace gets moved to inside program space
- if (isExternalNamespace("__cxxabiv1::__class_type_info")) {
+ if (isExternalSpecialVtable("__cxxabiv1::__class_type_info::vtable")) {
return ("This program's relocations were not correctly fixed so the script cannot " +
"continue. If this program is mingw this is a known issue and " +
"will be fixed in a later release. For all other gcc programs please " +
@@ -1627,19 +1627,15 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {
}
- private boolean isExternalNamespace(String path) throws CancelledException {
+ private boolean isExternalSpecialVtable(String path)
+ throws CancelledException {
// try exact namespace path if there is one
- List<Symbol> symbols = NamespaceUtils.getSymbols(path, currentProgram, false);
-
- // if not, try to find path in another namespace
- if (symbols.isEmpty()) {
- symbols = NamespaceUtils.getSymbols(path, currentProgram, true);
- }
+ List<Symbol> symbols = NamespaceUtils.getSymbols(path, currentProgram);
for (Symbol symbol : symbols) {
monitor.checkCancelled();
- if (symbol.isExternal() && symbol.getSymbolType().isNamespace()) {
+ if (symbol.isExternal()) {
return true;
}
}
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java
index df00960644..5b0b31af9a 100644
--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java
+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java
@@ -1161,7 +1161,7 @@ public class ExtendedFlatProgramAPI extends FlatProgramAPI {
CategoryPath dataTypePath = parent;
- for (String name : namespace.getPathList(true)) {
+ for (String name : namespace.getPathList()) {
monitor.checkCancelled();
dataTypePath = new CategoryPath(dataTypePath, name);
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
index aebe32d811..46a0f59ec9 100644
--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
@@ -8471,10 +8471,8 @@ public class RecoveredClassHelper {
List<Namespace> namespaceByPath = NamespaceUtils.getNamespaceByPath(program, null, path);
// ignore namespaces contained within libraries
- for (Namespace namespace : namespaceByPath) {
- if (!namespace.isExternal()) {
- return namespace;
- }
+ if (!namespaceByPath.isEmpty()) {
+ return namespaceByPath.get(0);
}
Msg.debug(this, "Expected clas namespace not found: " + path);
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java
index fc4e4df4e4..567d2dbf34 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java
@@ -492,7 +492,7 @@ public class DecompileCallback {
int pathSize = 0;
Namespace curspace = namespace;
long curId = namespace.getID();
- while (curId != stopId && curId != 0 && !HighFunction.collapseToGlobal(curspace)) {
+ while (curId != stopId && curId != 0) {
pathSize += 1;
curspace = curspace.getParentNamespace();
curId = curspace.getID();
@@ -809,7 +809,7 @@ public class DecompileCallback {
private void encodeResult(Encoder encoder, HighSymbol highSymbol, Namespace namespc)
throws IOException {
long namespaceId;
- if (namespc == null || namespc instanceof Library) {
+ if (namespc == null) {
namespaceId = Namespace.GLOBAL_NAMESPACE_ID;
}
else {
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileDebug.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileDebug.java
index 93bd14f568..98e9fb8fd6 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileDebug.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileDebug.java
@@ -523,12 +523,7 @@ public class DecompileDebug {
if (parent == null) {
break;
}
- if (HighFunction.collapseToGlobal(parent)) {
- key = Long.valueOf(Namespace.GLOBAL_NAMESPACE_ID);
- }
- else {
- key = Long.valueOf(parent.getID());
- }
+ key = Long.valueOf(parent.getID());
parent = namespaceMap.get(key);
if (parent == null) {
break;
@@ -565,9 +560,7 @@ public class DecompileDebug {
}
datahead.append(">\n");
if (parentNamespace != null) {
- long parentId =
- HighFunction.collapseToGlobal(parentNamespace) ? Namespace.GLOBAL_NAMESPACE_ID
- : parentNamespace.getID();
+ long parentId = parentNamespace.getID();
datahead.append("<parent");
SpecXmlUtils.encodeUnsignedIntegerAttribute(datahead, "id", parentId);
datahead.append("/>\n");
@@ -700,9 +693,6 @@ public class DecompileDebug {
public void getNamespacePath(Namespace namespace) {
while (namespace != null) {
- if (HighFunction.collapseToGlobal(namespace)) {
- break; // Treat library namespace as root
- }
dbscope.add(namespace); // Add namespace to guarantee <scope> tag
database.add(null); // Even if there isn't necessarily any symbols
namespace = namespace.getParentNamespace();
@@ -710,7 +700,7 @@ public class DecompileDebug {
}
public void getMapped(Namespace namespc, String res) {
- if (namespc == null || HighFunction.collapseToGlobal(namespc)) {
+ if (namespc == null) {
dbscope.add(globalnamespace);
}
else {
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
index c2687dddcf..6d30271b7e 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
@@ -416,11 +416,10 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
ExternalManager em = program.getExternalManager();
// "ADVAPI32.dll", "externalFunctionXyz", "_Zxyz"
- ExternalLocation externalLocation =
- em.addExtFunction(Library.UNKNOWN, "_Zxyz", addr(extAddress), SourceType.IMPORTED);
Library lib = em.addExternalLibraryName("ADVAPI32.dll", SourceType.IMPORTED);
- externalLocation.setName(lib, "externalFunctionXyz", SourceType.IMPORTED);
-
+ ExternalLocation externalLocation =
+ em.addExtFunction(lib, "_Zxyz", addr(extAddress), SourceType.IMPORTED);
+ externalLocation.setName(null, "externalFunctionXyz", SourceType.IMPORTED);
Function function = program.getFunctionManager().getFunctionAt(addr(addressString));
function.setThunkedFunction(externalLocation.getFunction());
});
diff --git a/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java
index 2498b0a1fb..86a36c25bd 100644
--- a/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java
+++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java
@@ -391,7 +391,7 @@ public class ObjcMessageAnalyzer extends AbstractAnalyzer {
setCommentAndReference(program, msg, parameters, log);
}
}
-
+
private synchronized void updateExternalBlock(Program program, Message msg, MessageLog log) {
Memory mem = program.getMemory();
FunctionManager funcMgr = program.getFunctionManager();
@@ -439,8 +439,10 @@ public class ObjcMessageAnalyzer extends AbstractAnalyzer {
new AddressSet(funcAddr), SourceType.ANALYSIS);
Symbol externalSymbol = symbolTable.getExternalSymbol(objcClassName);
if (externalSymbol != null) {
- ExternalLocation loc = extMgr.addExtLocation(externalSymbol.getParentNamespace(),
- currentMethodName, null, SourceType.IMPORTED);
+ Library library = externalSymbol.getLibrary();
+ ExternalLocation loc =
+ extMgr.addExtLocation(library, externalSymbol.getParentNamespace(),
+ currentMethodName, null, SourceType.IMPORTED);
func.setThunkedFunction(loc.createFunction());
}
List<Parameter> params = List.of(new ParameterImpl("self", dataTypes.id, program),
@@ -1088,7 +1090,7 @@ public class ObjcMessageAnalyzer extends AbstractAnalyzer {
if (block != null && block.getName().equals(SectionNames.TEXT)) {
ret.add(function);
}
-
+
}
return ret;
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplySymbols.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplySymbols.java
index a7243003ee..2e97067dcf 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplySymbols.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplySymbols.java
@@ -101,7 +101,7 @@ class ApplySymbols {
if (name.startsWith("$") && !name.contains(Namespace.DELIMITER)) {
Function f = functionManager.getFunctionContaining(address);
if (f != null && !f.getName().equals(name)) {
- name = NamespaceUtils.getNamespaceQualifiedName(f, name, true);
+ name = NamespaceUtils.getNamespaceQualifiedName(f, name);
}
}
@@ -117,14 +117,15 @@ class ApplySymbols {
pdbParser.createSymbol(address, name, forcePrimary, log);
}
- ////////////
+ ///////////
// Commented out the following for now, because it appears to be doing things it
// shouldn't. Many of the things are very loosely speculative.
// TODO Someone needs to determine if the attempted functionality can be properly refined.
- ////////////
+ ///////////
// if (name.startsWith(MS_VF_TABLE_PREFIX)) {
-//// TODO: Should this be handled by the demangler instead of here?
-// //MemBuffer mbuf = new MemoryBufferImpl(program.getMemory(), address);
+ //// TODO: Should this be handled by the demangler instead of here?
+ // //MemBuffer mbuf = new
+ /// MemoryBufferImpl(program.getMemory(), address);
// PointerDataType pointer = new PointerDataType(program.getDataTypeManager());
// int nPtrs = length / pointer.getLength();
// for (int i = 0; i < nPtrs; ++i) {
@@ -133,7 +134,7 @@ class ApplySymbols {
// }
// }
// else if (name.startsWith(MS_VB_TABLE_PREFIX)) {
-//// TODO: Should this be handled by the demangler instead of here?
+ //// TODO: Should this be handled by the demangler instead of here?
// DWordDataType dword = DWordDataType.dataType;
// int nDwords = length / dword.getLength();
// for (int i = 0; i < nDwords; ++i) {
@@ -147,11 +148,11 @@ class ApplySymbols {
// boolean isUnicode = isUnicode(name);
// pdbParser.createString(isUnicode, address, log);
// }
- ////////////
+ ///////////
// Commented out the following for now, because it appears to be doing things it
// shouldn't. Many of the things are very loosely speculative.
// TODO Someone needs to determine if the attempted functionality can be properly refined.
- ////////////
+ ///////////
// else if (PdbUtil.isFunction(program, name, address, length)) {
// disassembleSet.add(new AddressRangeImpl(address, address));
// }
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
index 413827357b..76c0a5c37d 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
@@ -104,7 +104,7 @@ public class LabelSymbolApplier extends MsSymbolApplier
if (applyToApplier instanceof FunctionSymbolApplier functionSymbolApplier) {
Function f = functionSymbolApplier.getFunction();
if (f != null && !f.getName().equals(label)) {
- label = NamespaceUtils.getNamespaceQualifiedName(f, label, true);
+ label = NamespaceUtils.getNamespaceQualifiedName(f, label);
}
}
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/ExtLibraryLocation.java b/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/ExtLibraryLocation.java
index eca75b3b6c..769cec34bd 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/ExtLibraryLocation.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/ExtLibraryLocation.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,11 +17,13 @@ package sarif.export.extlib;
import ghidra.program.model.data.ISF.IsfObject;
import ghidra.program.model.symbol.ExternalLocation;
+import ghidra.program.model.symbol.Namespace;
public class ExtLibraryLocation implements IsfObject {
String name;
- String location;
+ String libraryName;
+ String location; // this is really the namespace path
String originalImportedName;
String externalAddress;
String symbol;
@@ -31,11 +33,13 @@ public class ExtLibraryLocation implements IsfObject {
public ExtLibraryLocation(ExternalLocation extLoc) {
name = extLoc.getLabel();
+ libraryName = extLoc.getLibraryName();
originalImportedName = extLoc.getOriginalImportedName();
- location = extLoc.getParentNameSpace().getName(true);
+ Namespace parentNameSpace = extLoc.getParentNameSpace();
+ location = parentNameSpace.isGlobal() ? "" : parentNameSpace.getName(true);
externalAddress = extLoc.getExternalSpaceAddress().toString();
isFunction = extLoc.getFunction() != null;
- isClass = extLoc.getClass() != null;
+ isClass = false;
source = extLoc.getSource().toString();
symbol = extLoc.getSymbol().getName();
}
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/SarifClassesNamespaceWriter.java b/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/SarifClassesNamespaceWriter.java
index e331b35d8b..4993c3a47c 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/SarifClassesNamespaceWriter.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/export/extlib/SarifClassesNamespaceWriter.java
@@ -70,20 +70,6 @@ public class SarifClassesNamespaceWriter extends AbstractExtWriter {
SarifObject sarif = new SarifObject(ExternalLibSarifMgr.SUBKEY0, ExternalLibSarifMgr.KEY,
getTree(lib), null);
objects.add(getTree(sarif));
-
- if (cls.isExternal()) {
- SymbolIterator symbols = symbolTable.getSymbols(cls);
- while (symbols.hasNext()) {
- Symbol sym = symbols.next();
- ExternalLocation loc = externalManager.getExternalLocation(sym);
- if (loc != null) {
- ExtLibraryLocation obj = new ExtLibraryLocation(loc);
- SarifObject sarif2 = new SarifObject(ExternalLibSarifMgr.SUBKEY1,
- ExternalLibSarifMgr.KEY, getTree(obj), loc.getAddress(), loc.getAddress());
- objects.add(getTree(sarif2));
- }
- }
- }
}
@Override
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/export/func/ExtFunction.java b/Ghidra/Features/Sarif/src/main/java/sarif/export/func/ExtFunction.java
index b8b56b6f7c..539cd060ff 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/export/func/ExtFunction.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/export/func/ExtFunction.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,9 +21,7 @@ import java.util.List;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.GlobalNamespace;
import ghidra.program.model.data.ISF.IsfObject;
-import ghidra.program.model.listing.Function;
-import ghidra.program.model.listing.GhidraClass;
-import ghidra.program.model.listing.Parameter;
+import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.SourceType;
import ghidra.util.task.TaskMonitor;
@@ -37,37 +35,36 @@ public class ExtFunction implements IsfObject {
String comment;
String repeatableComment;
String value;
-
+
String callingConvention;
String callFixup;
String signatureSource;
String sourceType;
-
+
boolean hasVarArgs;
boolean isInline;
boolean hasNoReturn;
boolean hasCustomStorage;
boolean isStackPurgeSizeValid;
- boolean isLibrary;
boolean isGlobal;
boolean isExternal;
-
+
boolean isThunk;
String thunkAddress;
-
+
ExtFunctionStack stack;
List<ExtFunctionRegVar> regVars = new ArrayList<>();
-
+
ExtFunctionParam ret;
List<ExtFunctionParam> params = new ArrayList<>();
-
+
public ExtFunction(Function func, TaskMonitor monitor) {
super();
name = func.getName(true);
- location = func.getEntryPoint().toString();
+ location = func.getEntryPoint().toString();
comment = func.getComment();
repeatableComment = func.getRepeatableComment();
-
+
signatureSource = func.getSignatureSource().toString();
SourceType srcType = func.getSymbol().getSource();
sourceType = srcType.toString();
@@ -86,13 +83,12 @@ public class ExtFunction implements IsfObject {
}
callingConvention = func.getCallingConventionName();
callFixup = func.getCallFixup();
-
+
hasVarArgs = func.hasVarArgs();
isInline = func.isInline();
hasNoReturn = func.hasNoReturn();
hasCustomStorage = func.hasCustomVariableStorage();
isStackPurgeSizeValid = func.isStackPurgeSizeValid();
- isLibrary = func.isLibrary();
isGlobal = func.isGlobal();
isExternal = func.isExternal();
isThunk = func.isThunk();
@@ -100,12 +96,12 @@ public class ExtFunction implements IsfObject {
Address thunkAddr = func.getThunkedFunction(false).getEntryPoint();
thunkAddress = thunkAddr.toString();
}
-
+
stack = new ExtFunctionStack(func.getStackFrame(), hasCustomStorage);
if (func.isStackPurgeSizeValid()) {
stack.setPurgeSize(func.getStackPurgeSize());
}
-
+
Parameter rp = func.getReturn();
ret = new ExtFunctionParam(rp);
Parameter[] fnParams = func.getParameters();
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/export/ref/ExtExternalReference.java b/Ghidra/Features/Sarif/src/main/java/sarif/export/ref/ExtExternalReference.java
index f76b677ec4..bcc0b68783 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/export/ref/ExtExternalReference.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/export/ref/ExtExternalReference.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,12 +20,13 @@ import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.ExternalReference;
public class ExtExternalReference extends ExtReference {
-
+
String name;
+ String libraryName;
String origImport;
boolean isClass;
boolean isFunction;
-
+
String libLabel;
String libAddr;
String libExtAddr;
@@ -36,8 +37,9 @@ public class ExtExternalReference extends ExtReference {
String label = extLoc.getLabel();
Address addr = extLoc.getAddress();
Address extAddr = extLoc.getExternalSpaceAddress();
-
+
name = extLoc.getParentNameSpace().getName(true);
+ libraryName = extLoc.getLibraryName();
origImport = extLoc.getOriginalImportedName();
isClass = extLoc.getClass() != null;
isFunction = extLoc.getFunction() != null;
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/export/symbols/ExtSymbol.java b/Ghidra/Features/Sarif/src/main/java/sarif/export/symbols/ExtSymbol.java
index 1bad5a7183..f2387a5283 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/export/symbols/ExtSymbol.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/export/symbols/ExtSymbol.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,12 +15,9 @@
*/
package sarif.export.symbols;
-import ghidra.program.database.symbol.ClassSymbol;
-import ghidra.program.database.symbol.LibrarySymbol;
-import ghidra.program.database.symbol.NamespaceSymbol;
+import ghidra.program.database.symbol.*;
import ghidra.program.model.data.ISF.IsfObject;
import ghidra.program.model.listing.GhidraClass;
-import ghidra.program.model.listing.Library;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
@@ -44,9 +41,11 @@ public class ExtSymbol implements IsfObject {
pinned = symbol.isPinned();
if (symbol instanceof ClassSymbol) {
type = "class";
- } else if (symbol instanceof LibrarySymbol) {
+ }
+ else if (symbol instanceof LibrarySymbol) {
type = "library";
- } else if (symbol instanceof NamespaceSymbol) {
+ }
+ else if (symbol instanceof NamespaceSymbol) {
type = "namespace";
}
// NB: DO NOT add type==function, as this will affect the execution order
@@ -77,10 +76,7 @@ public class ExtSymbol implements IsfObject {
return true;
}
Namespace parent = symbol.getParentNamespace();
- if (parent instanceof Library) {
- return true;
- }
- return false;
+ return parent.isGlobal();
}
}
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/ExternalLibSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/ExternalLibSarifMgr.java
index 224684326d..33a88763ce 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/ExternalLibSarifMgr.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/ExternalLibSarifMgr.java
@@ -50,12 +50,13 @@ public class ExternalLibSarifMgr extends SarifMgr {
externalMap = new HashMap<>();
}
- ////////////////////////////
+ /////////////////
// SARIF READ CURRENT DTD //
- ////////////////////////////
+ /////////////////
@Override
- protected void readResults(List<Map<String, Object>> list, SarifProgramOptions options, TaskMonitor monitor)
+ protected void readResults(List<Map<String, Object>> list, SarifProgramOptions options,
+ TaskMonitor monitor)
throws AddressFormatException, CancelledException {
if (list != null) {
monitor.setMessage("Processing " + key + "...");
@@ -73,7 +74,8 @@ public class ExternalLibSarifMgr extends SarifMgr {
monitor.increment();
}
- } else {
+ }
+ else {
monitor.setMessage("Skipping over " + key + " ...");
}
}
@@ -85,7 +87,8 @@ public class ExternalLibSarifMgr extends SarifMgr {
* @param monitor monitor that can be canceled
*/
@Override
- public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
+ public boolean read(Map<String, Object> result, SarifProgramOptions options,
+ TaskMonitor monitor)
throws CancelledException {
try {
String symbol = (String) result.get("symbol");
@@ -98,13 +101,15 @@ public class ExternalLibSarifMgr extends SarifMgr {
return true;
}
return false;
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
return false;
}
- private void processExternalLib(Map<String, Object> result) throws InvalidInputException, DuplicateNameException {
+ private void processExternalLib(Map<String, Object> result)
+ throws InvalidInputException, DuplicateNameException {
String progName = (String) result.get("name");
// check to make sure that we do not clear any
@@ -135,6 +140,7 @@ public class ExternalLibSarifMgr extends SarifMgr {
try {
String name = (String) result.get("name");
+ String libraryName = (String) result.get("libraryName");
String location = (String) result.get("location");
Address address = getLocation(result);
String extern = (String) result.get("externalAddress");
@@ -144,49 +150,55 @@ public class ExternalLibSarifMgr extends SarifMgr {
sourceType = SourceType.IMPORTED;
}
boolean isClass = (boolean) result.get("isClass");
- Namespace p = walkNamespace(program.getGlobalNamespace(), location + "::", address, sourceType, isClass);
+ Namespace namespace = walkNamespace(program.getGlobalNamespace(), location + "::",
+ address, sourceType, isClass);
String name0 = (String) result.get("originalImportedName");
- ExternalLocation loc = addExternal(result, name, address, sourceType, p, name0);
+ ExternalLocation loc =
+ addExternal(result, name, libraryName, address, sourceType, namespace, name0);
externalMap.put(extern, loc);
- } catch (InvalidInputException | AddressOverflowException e) {
+ }
+ catch (InvalidInputException | AddressOverflowException e) {
log.appendException(e);
}
}
- private ExternalLocation addExternal(Map<String, Object> result, String name, Address address, SourceType sourceType,
- Namespace p, String name0) throws InvalidInputException {
- Library lib = getLibrary(p);
+ private ExternalLocation addExternal(Map<String, Object> result, String name,
+ String libraryName, Address address,
+ SourceType sourceType,
+ Namespace namespace, String name0) throws InvalidInputException {
+ Library library = getLibrary(libraryName);
ExternalLocation loc;
if ((boolean) result.get("isFunction")) {
if (name0 != null) {
- loc = extManager.addExtFunction(lib == null ? p : lib, name0, address, sourceType, false);
- loc.setName(p, name, sourceType);
- } else {
- loc = extManager.addExtFunction(p, name, address, sourceType, true);
+ loc = extManager.addExtFunction(library, namespace, name0, address, sourceType,
+ false);
+ }
+ else {
+ loc = extManager.addExtFunction(library, name, address, sourceType, true);
}
- } else {
+ }
+ else {
if (name0 != null) {
- loc = extManager.addExtLocation(lib == null ? p : lib, name0, address, sourceType, false);
- loc.setName(p, name, sourceType);
- } else {
- loc = extManager.addExtLocation(p, name, address, sourceType, true);
+ loc = extManager.addExtLocation(library, namespace, name0, address, sourceType,
+ false);
+ }
+ else {
+ loc =
+ extManager.addExtLocation(library, namespace, name, address, sourceType, true);
}
}
return loc;
}
- private Library getLibrary(Namespace p) {
- if (p instanceof Library lib) {
- return lib;
- }
- Namespace parent = p.getParentNamespace();
- return parent == null ? null : getLibrary(parent);
+ private Library getLibrary(String libraryName) {
+ Symbol librarySymbol = program.getSymbolTable().getLibrarySymbol(libraryName);
+ return librarySymbol == null ? null : (Library) librarySymbol.getObject();
}
- /////////////////////////////
+ //////////////////
// SARIF WRITE CURRENT DTD //
- /////////////////////////////
+ //////////////////
/**
* Write out the SARIF for the external library table.
@@ -205,7 +217,7 @@ public class ExternalLibSarifMgr extends SarifMgr {
}
writeExtAsSARIF(program, request0, results);
-
+
Iterator<GhidraClass> classNamespaces = program.getSymbolTable().getClassNamespaces();
List<GhidraClass> request1 = new ArrayList<>();
while (classNamespaces.hasNext()) {
@@ -216,13 +228,17 @@ public class ExternalLibSarifMgr extends SarifMgr {
}
- public static void writeExtAsSARIF(Program program, List<String> request, JsonArray results) throws IOException {
- SarifExternalLibraryWriter writer = new SarifExternalLibraryWriter(program.getExternalManager(), request, null);
+ public static void writeExtAsSARIF(Program program, List<String> request, JsonArray results)
+ throws IOException {
+ SarifExternalLibraryWriter writer =
+ new SarifExternalLibraryWriter(program.getExternalManager(), request, null);
new TaskLauncher(new SarifWriterTask("Libraries", writer, results), null);
}
- public static void writeNamespaceAsSARIF(Program program, List<GhidraClass> request, JsonArray results) throws IOException {
- SarifClassesNamespaceWriter writer = new SarifClassesNamespaceWriter(program.getExternalManager(), program.getSymbolTable(), request, null);
+ public static void writeNamespaceAsSARIF(Program program, List<GhidraClass> request,
+ JsonArray results) throws IOException {
+ SarifClassesNamespaceWriter writer = new SarifClassesNamespaceWriter(
+ program.getExternalManager(), program.getSymbolTable(), request, null);
new TaskLauncher(new SarifWriterTask("Libraries", writer, results), null);
}
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/FunctionsSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/FunctionsSarifMgr.java
index d1002947f5..834f1cf5ac 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/FunctionsSarifMgr.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/FunctionsSarifMgr.java
@@ -18,12 +18,8 @@ package sarif.managers;
import java.io.IOException;
import java.util.*;
-import javax.swing.Icon;
-
import com.google.gson.JsonArray;
-import generic.theme.GIcon;
-import generic.theme.GThemeDefaults.Colors.Palette;
import ghidra.app.cmd.function.CreateFunctionCmd;
import ghidra.app.util.NamespaceUtils;
import ghidra.app.util.SymbolPath;
@@ -60,9 +56,9 @@ public class FunctionsSarifMgr extends SarifMgr {
super(KEY, program, log);
}
- ////////////////////////////
+ //////////////////////////
// SARIF READ CURRENT DTD //
- ////////////////////////////
+ //////////////////////////
@Override
protected void readResults(List<Map<String, Object>> list, SarifProgramOptions options,
@@ -279,9 +275,6 @@ public class FunctionsSarifMgr extends SarifMgr {
return;
}
}
- if (path.getName().contains(Library.UNKNOWN)) {
- ns = getExternalNamespace();
- }
if (ns.getParentNamespace() == null) {
symbol.setName(name, getSourceType("DEFAULT"));
}
@@ -296,16 +289,6 @@ public class FunctionsSarifMgr extends SarifMgr {
private String setProperties(Map<String, Object> result, Function func, Address entryPoint)
throws InvalidInputException {
- boolean isLibrary = (boolean) result.get("isLibrary");
- if (isLibrary) {
- BookmarkManager bm = program.getBookmarkManager();
- BookmarkType bt = bm.getBookmarkType("IMPORTED");
- if (bt == null) {
- Icon icon = new GIcon("icon.base.util.xml.functions.bookmark");
- bt = bm.defineType("IMPORTED", icon, Palette.DARK_GRAY, 0);
- }
- bm.setBookmark(entryPoint, "IMPORTED", LIB_BOOKMARK_CATEGORY, "Library function");
- }
String callingConvention = (String) result.get("callingConvention");
if (callingConvention != null) {
@@ -654,9 +637,9 @@ public class FunctionsSarifMgr extends SarifMgr {
return results;
}
- /////////////////////////////
+ ///////////////////////////
// SARIF WRITE CURRENT DTD //
- /////////////////////////////
+ ///////////////////////////
void write(JsonArray results, AddressSetView addrs, TaskMonitor monitor)
throws IOException, CancelledException {
diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/MarkupSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/MarkupSarifMgr.java
index 4bd9d6b518..2d39b7c714 100644
--- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/MarkupSarifMgr.java
+++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/MarkupSarifMgr.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,40 +16,18 @@
package sarif.managers;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import com.google.gson.JsonArray;
import ghidra.app.util.importer.MessageLog;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressFormatException;
-import ghidra.program.model.address.AddressIterator;
-import ghidra.program.model.address.AddressSetView;
+import ghidra.program.model.address.*;
import ghidra.program.model.lang.Register;
-import ghidra.program.model.listing.CodeUnit;
-import ghidra.program.model.listing.Instruction;
-import ghidra.program.model.listing.Library;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.program.model.scalar.Scalar;
-import ghidra.program.model.symbol.Equate;
-import ghidra.program.model.symbol.EquateTable;
-import ghidra.program.model.symbol.ExternalLocation;
-import ghidra.program.model.symbol.ExternalManager;
-import ghidra.program.model.symbol.Namespace;
-import ghidra.program.model.symbol.RefType;
-import ghidra.program.model.symbol.RefTypeFactory;
-import ghidra.program.model.symbol.Reference;
-import ghidra.program.model.symbol.ReferenceManager;
-import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.*;
import ghidra.util.Msg;
-import ghidra.util.exception.AssertException;
-import ghidra.util.exception.CancelledException;
-import ghidra.util.exception.DuplicateNameException;
-import ghidra.util.exception.InvalidInputException;
+import ghidra.util.exception.*;
import ghidra.util.task.TaskLauncher;
import ghidra.util.task.TaskMonitor;
import sarif.SarifProgramOptions;
@@ -73,30 +51,36 @@ public class MarkupSarifMgr extends SarifMgr {
equateTable = program.getEquateTable();
}
- ////////////////////////////
+ //////////////////
// SARIF READ CURRENT DTD //
- ////////////////////////////
+ //////////////////
@Override
- public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
+ public boolean read(Map<String, Object> result, SarifProgramOptions options,
+ TaskMonitor monitor)
throws CancelledException {
String tagName = (String) result.get("Message");
boolean overwrite = options == null || options.isOverwriteReferenceConflicts();
if (tagName.equals("Ref.Memory")) {
processMemoryReference(result, overwrite);
- } else if (tagName.equals("Ref.Shifted")) {
+ }
+ else if (tagName.equals("Ref.Shifted")) {
processShiftedReference(result, overwrite);
- } else if (tagName.equals("Ref.Register")) {
+ }
+ else if (tagName.equals("Ref.Register")) {
processRegisterReference(result, overwrite);
- } else if (tagName.equals("Ref.Stack")) {
+ }
+ else if (tagName.equals("Ref.Stack")) {
if (options == null || options.isFunctions()) { // TODO && !ignoreStackReferences) {
processStackReference(result, overwrite);
}
- } else if (tagName.equals("Ref.External")) {
+ }
+ else if (tagName.equals("Ref.External")) {
if (options == null || options.isExternalLibraries()) {
processExtLibraryReference(result, overwrite);
}
- } else if (tagName.equals("Ref.Equate")) {
+ }
+ else if (tagName.equals("Ref.Equate")) {
processEquateReference(result, overwrite);
}
return true;
@@ -120,11 +104,13 @@ public class MarkupSarifMgr extends SarifMgr {
String toAddrStr = (String) result.get("to");
if (toAddrStr == null) {
- throw new RuntimeException("TO_ADDRESS attribute missing for MEMORY_REFERENCE element");
+ throw new RuntimeException(
+ "TO_ADDRESS attribute missing for MEMORY_REFERENCE element");
}
Address toAddr = parseAddress(factory, toAddrStr);
if (toAddr == null) {
- throw new AddressFormatException("Incompatible Memory Reference TO Address: " + toAddrStr);
+ throw new AddressFormatException(
+ "Incompatible Memory Reference TO Address: " + toAddrStr);
}
int opIndex = CodeUnit.MNEMONIC;
@@ -144,9 +130,10 @@ public class MarkupSarifMgr extends SarifMgr {
if (!overwrite) {
Reference[] existingMemRefs = refManager.getReferencesFrom(fromAddr, opIndex);
- if (existingMemRefs != null && existingMemRefs.length != 0 && !existingMemRefs[0].isMemoryReference()) {
- log.appendMsg("Reference already exists from [" + fromAddr + "] to [" + toAddr
- + "] on operand [" + opIndex + "]");
+ if (existingMemRefs != null && existingMemRefs.length != 0 &&
+ !existingMemRefs[0].isMemoryReference()) {
+ log.appendMsg("Reference already exists from [" + fromAddr + "] to [" + toAddr +
+ "] on operand [" + opIndex + "]");
return;
}
}
@@ -160,14 +147,17 @@ public class MarkupSarifMgr extends SarifMgr {
if (baseAddr != null) {
long offset = (long) (double) result.get("offset");
// long offset = toAddr.subtract(baseAddr);
- ref = refMgr.addOffsetMemReference(fromAddr, toAddr, toAddr.equals(baseAddr), offset, refType,
- sourceType, opIndex);
- } else {
+ ref = refMgr.addOffsetMemReference(fromAddr, toAddr, toAddr.equals(baseAddr),
+ offset, refType,
+ sourceType, opIndex);
+ }
+ else {
ref = refMgr.addMemoryReference(fromAddr, toAddr, refType, sourceType, opIndex);
}
refMgr.setPrimary(ref, primary);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
@@ -186,11 +176,13 @@ public class MarkupSarifMgr extends SarifMgr {
String toAddrStr = (String) result.get("to");
if (toAddrStr == null) {
- throw new RuntimeException("TO_ADDRESS attribute missing for REGISTER_REFERENCE element");
+ throw new RuntimeException(
+ "TO_ADDRESS attribute missing for REGISTER_REFERENCE element");
}
Address toAddr = parseAddress(factory, toAddrStr);
if (toAddr == null) {
- throw new AddressFormatException("Incompatible Register Reference TO Address: " + toAddrStr);
+ throw new AddressFormatException(
+ "Incompatible Register Reference TO Address: " + toAddrStr);
}
Register[] registers = program.getLanguage().getRegisters(toAddr);
Register reg = registers[0];
@@ -208,8 +200,8 @@ public class MarkupSarifMgr extends SarifMgr {
if (!overwrite) {
Reference[] existingRefs = refManager.getReferencesFrom(fromAddr, opIndex);
if (existingRefs != null && existingRefs.length != 0) {
- log.appendMsg("Memory reference already existed from [" + fromAddr + "] to [" + toAddr
- + "] on operand [" + opIndex + "]");
+ log.appendMsg("Memory reference already existed from [" + fromAddr + "] to [" +
+ toAddr + "] on operand [" + opIndex + "]");
return;
}
}
@@ -219,10 +211,12 @@ public class MarkupSarifMgr extends SarifMgr {
SourceType sourceType = getSourceType((String) result.get("sourceType"));
ReferenceManager refMgr = program.getReferenceManager();
- Reference ref = refMgr.addRegisterReference(fromAddr, opIndex, reg, refType, sourceType);
+ Reference ref =
+ refMgr.addRegisterReference(fromAddr, opIndex, reg, refType, sourceType);
refMgr.setPrimary(ref, primary);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
@@ -245,7 +239,8 @@ public class MarkupSarifMgr extends SarifMgr {
if (!overwrite) {
Reference[] existingRefs = refManager.getReferencesFrom(addr, opIndex);
if (existingRefs != null && existingRefs.length != 0) {
- log.appendMsg("Reference already exists from [" + addr + "] on operand [" + opIndex + "]");
+ log.appendMsg("Reference already exists from [" + addr + "] on operand [" +
+ opIndex + "]");
return;
}
}
@@ -263,7 +258,8 @@ public class MarkupSarifMgr extends SarifMgr {
SourceType sourceType = getSourceType((String) result.get("sourceType"));
refManager.addStackReference(addr, opIndex, offset, refType, sourceType);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
@@ -286,7 +282,8 @@ public class MarkupSarifMgr extends SarifMgr {
if (!overwrite) {
Reference[] existingRefs = refManager.getReferencesFrom(addr, opIndex);
if (existingRefs != null && existingRefs.length != 0) {
- log.appendMsg("Reference already exists from [" + addr + "] on operand [" + opIndex + "]");
+ log.appendMsg("Reference already exists from [" + addr + "] on operand [" +
+ opIndex + "]");
return;
}
}
@@ -306,7 +303,8 @@ public class MarkupSarifMgr extends SarifMgr {
SourceType sourceType = getSourceType((String) result.get("sourceType"));
refManager.addShiftedMemReference(addr, toAddr, shift, refType, sourceType, opIndex);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
@@ -324,6 +322,7 @@ public class MarkupSarifMgr extends SarifMgr {
String namespacePath = (String) result.get("name");
String label = (String) result.get("libLabel");
+ String libraryName = (String) result.get("libraryName");
String libAddress = (String) result.get("libAddr");
Address libAddr = libAddress != null ? factory.getAddress(libAddress) : null;
String libExtAddress = (String) result.get("libExtAddr");
@@ -332,8 +331,8 @@ public class MarkupSarifMgr extends SarifMgr {
boolean isFunction = (boolean) result.get("isFunction");
if (label == null && libAddr == null) {
- log.appendMsg("External library reference for address " + addr
- + " does not have a label or an external address specified. External reference will not be created");
+ log.appendMsg("External library reference for address " + addr +
+ " does not have a label or an external address specified. External reference will not be created");
return;
}
CodeUnit cu = listing.getCodeUnitContaining(addr);
@@ -354,21 +353,25 @@ public class MarkupSarifMgr extends SarifMgr {
if (rt != null) {
int index = Integer.parseInt((String) result.get("index"));
refType = getRefType(index);
- } else {
+ }
+ else {
refType = RefType.EXTERNAL_REF;
}
SourceType sourceType = getSourceType((String) result.get("sourceType"));
ExternalLocation extLoc = externalMap.get(libExtAddress);
if (extLoc == null) {
- extLoc = addExternal(label, namespacePath, libAddr, sourceType, origImport, isFunction);
+ extLoc =
+ addExternal(label, libraryName, namespacePath, libAddr, sourceType, origImport,
+ isFunction);
externalMap.put(libExtAddress, extLoc);
}
if (origImport != null && !origImport.equals(extLoc.getOriginalImportedName())) {
log.appendMsg("Retrieving incorrect external location - known bug");
}
refManager.addExternalReference(addr, opIndex, extLoc, sourceType, refType);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
@@ -377,36 +380,40 @@ public class MarkupSarifMgr extends SarifMgr {
// listen under ExternalLocations
// (Possible forcing locations to be written per-reference means this is no
// longer called, but...
- private ExternalLocation addExternal(String name, String namespacePath, Address address, SourceType sourceType,
+ private ExternalLocation addExternal(String name, String libraryName, String namespacePath,
+ Address address,
+ SourceType sourceType,
String name0, boolean isFunction) throws InvalidInputException, IOException {
- Namespace p = walkNamespace(program.getGlobalNamespace(), namespacePath + "::", address, sourceType, true);
- Library lib = getLibrary(p);
+ Namespace namespace =
+ walkNamespace(program.getGlobalNamespace(), namespacePath + "::", address,
+ sourceType, true);
+ Library lib = getLibrary(libraryName);
ExternalLocation loc;
ExternalManager extManager = program.getExternalManager();
if (isFunction) {
if (name0 != null) {
- loc = extManager.addExtFunction(lib == null ? p : lib, name0, address, sourceType, false);
- loc.setName(p, name, sourceType);
- } else {
- loc = extManager.addExtFunction(p, name, address, sourceType, true);
+ loc = extManager.addExtFunction(lib, namespace, name0, address, sourceType,
+ false);
+ }
+ else {
+ loc = extManager.addExtFunction(lib, namespace, name, address, sourceType, true);
}
- } else {
+ }
+ else {
if (name0 != null) {
- loc = extManager.addExtLocation(lib == null ? p : lib, name0, address, sourceType, false);
- loc.setName(p, name, sourceType);
- } else {
- loc = extManager.addExtLocation(p, name, address, sourceType, true);
+ loc = extManager.addExtLocation(lib, namespace, name0, address, sourceType,
+ false);
+ }
+ else {
+ loc = extManager.addExtLocation(lib, namespace, name, address, sourceType, true);
}
}
return loc;
}
- private Library getLibrary(Namespace p) {
- if (p instanceof Library lib) {
- return lib;
- }
- Namespace parent = p.getParentNamespace();
- return parent == null ? null : getLibrary(parent);
+ private Library getLibrary(String libraryName) {
+ Symbol librarySymbol = program.getSymbolTable().getLibrarySymbol(libraryName);
+ return librarySymbol == null ? null : (Library) librarySymbol.getObject();
}
/**
@@ -443,7 +450,8 @@ public class MarkupSarifMgr extends SarifMgr {
Scalar tempScalar = cu.getScalar(opIndex);
if (tempScalar != null) {
instrScalars.add(tempScalar);
- } else if (cu instanceof Instruction) {
+ }
+ else if (cu instanceof Instruction) {
Instruction instr = (Instruction) cu;
Object[] opObjects = instr.getOpObjects(opIndex);
for (int i = 0; i < opObjects.length; i++) {
@@ -453,8 +461,8 @@ public class MarkupSarifMgr extends SarifMgr {
}
if (instrScalars.size() == 0) {
- log.appendMsg("BAD EQUATE REFERENCE: operand " + "[" + opIndex + "] at address " + "["
- + addr + "] is not a scalar.");
+ log.appendMsg("BAD EQUATE REFERENCE: operand " + "[" + opIndex +
+ "] at address " + "[" + addr + "] is not a scalar.");
return;
}
}
@@ -474,34 +482,41 @@ public class MarkupSarifMgr extends SarifMgr {
}
if (matchingScalar == null) {
- log.appendMsg("BAD EQUATE REFERENCE: equate [" + equateName + "] value [0x"
- + Long.toHexString(value) + "]" + " does not match scalar on operand [" + opIndex
- + "] at address [" + addr + "]");
+ log.appendMsg("BAD EQUATE REFERENCE: equate [" + equateName + "] value [0x" +
+ Long.toHexString(value) + "]" + " does not match scalar on operand [" +
+ opIndex + "] at address [" + addr + "]");
return;
}
- } else if (instrScalars.size() > 0) {
+ }
+ else if (instrScalars.size() > 0) {
// use scalar value as default - seems like a bad idea
Msg.warn(this, "NO VALUE SPECIFIED");
value = instrScalars.get(0).getSignedValue();
- } else {
- log.appendMsg("BAD EQUATE REFERENCE: either the VALUE or OPERAND_INDEX must be specified");
+ }
+ else {
+ log.appendMsg(
+ "BAD EQUATE REFERENCE: either the VALUE or OPERAND_INDEX must be specified");
return;
}
Equate equate = equateTable.getEquate(equateName);
if (equate != null) {
if (value != equate.getValue()) {
- log.appendMsg("BAD EQUATE REFERENCE: equate [" + equateName + "] value [0x"
- + Long.toHexString(value) + "] conflicts with existing equate value [0x"
- + Long.toHexString(equate.getValue()) + "].");
+ log.appendMsg("BAD EQUATE REFERENCE: equate [" + equateName + "] value [0x" +
+ Long.toHexString(value) + "] conflicts with existing equate value [0x" +
+ Long.toHexString(equate.getValue()) + "].");
return;
}
- } else {
+ }
+ else {
try {
equate = equateTable.createEquate(equateName, value);
- } catch (DuplicateNameException e) {
- throw new AssertException("Got duplicate name while creating equate " + equateName);
- } catch (InvalidInputException e) {
+ }
+ catch (DuplicateNameException e) {
+ throw new AssertException(
+ "Got duplicate name while creating equate " + equateName);
+ }
+ catch (InvalidInputException e) {
log.appendMsg("Invalid name for equate " + equateName);
return;
}
@@ -512,16 +527,18 @@ public class MarkupSarifMgr extends SarifMgr {
existingEquate.removeReference(addr, opIndex);
}
equate.addReference(addr, opIndex);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.appendException(e);
}
}
- /////////////////////////////
+ ///////////////////
// SARIF WRITE CURRENT DTD //
- /////////////////////////////
+ ///////////////////
- void write(JsonArray results, AddressSetView set, TaskMonitor monitor) throws IOException, CancelledException {
+ void write(JsonArray results, AddressSetView set, TaskMonitor monitor)
+ throws IOException, CancelledException {
if (set == null) {
set = program.getMemory();
}
@@ -536,13 +553,17 @@ public class MarkupSarifMgr extends SarifMgr {
writeAsSARIF(program, set, results);
}
- public static void writeAsSARIF(Program program, List<Address> request, JsonArray results) throws IOException {
- SarifReferenceWriter writer = new SarifReferenceWriter(program.getReferenceManager(), request, null);
+ public static void writeAsSARIF(Program program, List<Address> request, JsonArray results)
+ throws IOException {
+ SarifReferenceWriter writer =
+ new SarifReferenceWriter(program.getReferenceManager(), request, null);
new TaskLauncher(new SarifWriterTask("References", writer, results), null);
}
- public static void writeAsSARIF(Program program, AddressSetView set, JsonArray results) throws IOException {
- SarifEquateRefWriter ewriter = new SarifEquateRefWriter(program.getEquateTable(), set, null);
+ public static void writeAsSARIF(Program program, AddressSetView set, JsonArray results)
+ throws IOException {
+ SarifEquateRefWriter ewriter =
+ new SarifEquateRefWriter(program.getEquateTable(), set, null);
new TaskLauncher(new SarifWriterTask("References", ewriter, results), null);
}
diff --git a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/FunctionNameStringable.java b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/FunctionNameStringable.java
index 270a2f73a2..a11bbcbb56 100644
--- a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/FunctionNameStringable.java
+++ b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/FunctionNameStringable.java
@@ -167,10 +167,6 @@ public class FunctionNameStringable extends Stringable {
namespace = createNamespace(destProgram, info, namespace);
continue;
}
-
- if (destFunction.isExternal() != ns.isExternal()) {
- throw new DuplicateNameException("Conflicting namespace: " + info.name);
- }
if (info.symbolType == SymbolType.CLASS &&
ns.getSymbol().getSymbolType() == SymbolType.NAMESPACE) {
// Promote existing namespace to class
@@ -290,10 +286,7 @@ public class FunctionNameStringable extends Stringable {
SymbolType type = info.symbolType;
SourceType namespaceSourceType = info.sourceType;
- if (type == SymbolType.LIBRARY) {
- return symbolTable.createExternalLibrary(name, namespaceSourceType);
- }
- else if (type == SymbolType.CLASS) {
+ if (type == SymbolType.CLASS) {
return symbolTable.createClass(namespace, name, namespaceSourceType);
}
return symbolTable.createNameSpace(namespace, name, namespaceSourceType);
diff --git a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/MultipleSymbolStringable.java b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/MultipleSymbolStringable.java
index cc182d2b37..0a2675e6dc 100644
--- a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/MultipleSymbolStringable.java
+++ b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/stringable/MultipleSymbolStringable.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -143,8 +143,9 @@ public class MultipleSymbolStringable extends Stringable {
private Symbol createSymbol(Program program, Address address, SymbolInfo symbolInfo)
throws DuplicateNameException, InvalidInputException {
Namespace namespace = getNamespaceForNewLabel(program, symbolInfo, address);
- return program.getSymbolTable().createLabel(address, symbolInfo.getName(), namespace,
- symbolInfo.sourceType);
+ return program.getSymbolTable()
+ .createLabel(address, symbolInfo.getName(), namespace,
+ symbolInfo.sourceType);
}
private Namespace getNamespaceForNewLabel(Program program, SymbolInfo symbolInfo,
@@ -181,10 +182,7 @@ public class MultipleSymbolStringable extends Stringable {
SymbolType type = info.symbolType;
SourceType sourceType = info.sourceType;
- if (type == SymbolType.LIBRARY) {
- return symbolTable.createExternalLibrary(name, sourceType);
- }
- else if (type == SymbolType.CLASS) {
+ if (type == SymbolType.CLASS) {
return symbolTable.createClass(namespace, name, sourceType);
}
return symbolTable.createNameSpace(namespace, name, sourceType);
diff --git a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionNameMarkupItemTest.java b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionNameMarkupItemTest.java
index 3112d5f529..904907ebb1 100644
--- a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionNameMarkupItemTest.java
+++ b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/markupitem/FunctionNameMarkupItemTest.java
@@ -651,7 +651,7 @@ public class FunctionNameMarkupItemTest extends AbstractVTMarkupItemTest {
Symbol librarySymbol = symbolTable.getLibrarySymbol(path[0]);
Library externalLibrary = (Library) librarySymbol.getObject();
- Namespace currentNamespace = externalLibrary;
+ Namespace currentNamespace = null;
for (int i = 1; i < nameIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
currentNamespace = (Namespace) nextNamespaceSymbol.getObject();
@@ -691,16 +691,16 @@ public class FunctionNameMarkupItemTest extends AbstractVTMarkupItemTest {
ExternalManager externalManager = program.getExternalManager();
int nameIndex = path.length - 1;
- Library externalLibrary;
+ Library library;
Symbol librarySymbol = symbolTable.getLibrarySymbol(path[0]);
if (librarySymbol != null) {
- externalLibrary = (Library) librarySymbol.getObject();
+ library = (Library) librarySymbol.getObject();
}
else {
- externalLibrary = symbolTable.createExternalLibrary(path[0], sourceType);
+ library = symbolTable.createExternalLibrary(path[0], sourceType);
}
- Namespace currentNamespace = externalLibrary;
+ Namespace currentNamespace = null;
for (int i = 1; i < nameIndex; i++) {
Symbol nextNamespaceSymbol = getUniqueSymbol(program, path[i], currentNamespace);
if (nextNamespaceSymbol != null) {
@@ -714,15 +714,16 @@ public class FunctionNameMarkupItemTest extends AbstractVTMarkupItemTest {
ExternalLocation externalLocation = null;
if (originalName != null) {
- externalLocation = externalManager.addExtFunction(externalLibrary, originalName,
+ externalLocation = externalManager.addExtFunction(library, originalName,
memoryAddress, SourceType.IMPORTED);
}
if (externalLocation != null) {
externalLocation.setName(currentNamespace, path[nameIndex], sourceType);
}
else {
- externalLocation = externalManager.addExtFunction(currentNamespace, path[nameIndex],
- memoryAddress, sourceType);
+ externalLocation =
+ externalManager.addExtFunction(library, currentNamespace, path[nameIndex],
+ memoryAddress, sourceType);
}
Function function = externalLocation.getFunction();
assertNotNull(function);
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/dialogs/ObjectChooserDialog.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/dialogs/ObjectChooserDialog.java
index 905f7c46d3..fc611e0a94 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/dialogs/ObjectChooserDialog.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/dialogs/ObjectChooserDialog.java
@@ -15,13 +15,22 @@
*/
package docking.widgets.dialogs;
+import java.awt.Dimension;
import java.util.List;
import javax.swing.JComponent;
import docking.DialogComponentProvider;
+import docking.widgets.table.GTable;
import docking.widgets.table.GTableWidget;
+/**
+ * Dialog for choosing from a list of objects. The dialog uses a list of specified methods on the
+ * objects to form the columns of a display table, where each row in the table represents one of the
+ * object to pick from.
+ *
+ * @param <T> the object type of the object to choose from
+ */
public class ObjectChooserDialog<T> extends DialogComponentProvider {
private T selectedObject;
@@ -39,8 +48,10 @@ public class ObjectChooserDialog<T> extends DialogComponentProvider {
setTransient(true);
addWorkPanel(buildWorkPanel());
+ table.addSelectionListener(t -> setOkEnabled(t != null));
addOKButton();
addCancelButton();
+ setOkEnabled(false);
}
@Override
@@ -96,6 +107,26 @@ public class ObjectChooserDialog<T> extends DialogComponentProvider {
table.setFilterText(text);
}
+ public void setPreferredColumnWidths(int... widths) {
+ table.setColumnPreferredWidths(widths);
+ }
+
+ public void setPreferredWidth(int width) {
+ GTable gTable = table.getTable();
+ Dimension vpSize = gTable.getPreferredScrollableViewportSize();
+ int height = (int) vpSize.getHeight();
+ Dimension newVpSize = new Dimension(width, height);
+ gTable.setPreferredScrollableViewportSize(newVpSize);
+ }
+
+ public void setPreferredHeight(int height) {
+ GTable gTable = table.getTable();
+ Dimension vpSize = gTable.getPreferredScrollableViewportSize();
+ int width = (int) vpSize.getWidth();
+ Dimension newVpSize = new Dimension(width, height);
+ gTable.setPreferredScrollableViewportSize(newVpSize);
+ }
+
@Override
public void close() {
table.dispose();
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
index 676fcab74a..d5d798fd8c 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
@@ -1145,6 +1145,9 @@ public class GTree extends JPanel implements BusyListener {
int expireMs = 3000;
Supplier<GTreeNode> supplier = () -> {
+ if (isBusy()) {
+ return null;
+ }
GTreeNode modelParent = getModelNode(parent);
if (modelParent == null) {
return null;
@@ -1173,6 +1176,9 @@ public class GTree extends JPanel implements BusyListener {
int expireMs = 3000;
Supplier<GTreeNode> supplier = () -> {
+ if (isBusy()) {
+ return null;
+ }
GTreeNode viewParent = getViewNode(parent);
if (viewParent == null) {
return null;
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/AlphaNumericComparator.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/AlphaNumericComparator.java
index fee1aac39a..150cca1660 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/AlphaNumericComparator.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/AlphaNumericComparator.java
@@ -22,14 +22,12 @@ import java.util.Comparator;
* based on their parsed value, not their ASCII value.
*/
public class AlphaNumericComparator implements Comparator<String> {
+ public static Comparator<String> CI = new AlphaNumericComparator(false);
+ public static Comparator<String> CS = new AlphaNumericComparator(true);
private boolean caseSensitive;
- public AlphaNumericComparator() {
- this.caseSensitive = true;
- }
-
- public AlphaNumericComparator(boolean caseSensitive) {
+ private AlphaNumericComparator(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
@@ -106,7 +104,11 @@ public class AlphaNumericComparator implements Comparator<String> {
return lengthCompare;
}
- // Default to a string compare
+ // The algorithm above ignores spaces. If they are the same in that case, use the full text
+ // as a tie-breaker.
+ if (!caseSensitive) {
+ return s1.compareToIgnoreCase(s2);
+ }
return s1.compareTo(s2);
}
diff --git a/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/AlphaNumericComparatorTest.java b/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/AlphaNumericComparatorTest.java
index afac377c4b..8004a5b62a 100644
--- a/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/AlphaNumericComparatorTest.java
+++ b/Ghidra/Framework/Generic/src/test/java/ghidra/util/datastruct/AlphaNumericComparatorTest.java
@@ -77,7 +77,7 @@ public class AlphaNumericComparatorTest extends AbstractGenericTest {
Collections.shuffle(unsorted);
List<String> copy = new ArrayList<>(unsorted);
- Collections.sort(copy, new AlphaNumericComparator());
+ Collections.sort(copy, AlphaNumericComparator.CS);
assertEquals(sorted, copy);
}
@@ -121,8 +121,8 @@ public class AlphaNumericComparatorTest extends AbstractGenericTest {
" alphabet",
"app",
" apple",
- "Apple ",
"ap ple",
+ "Apple ",
"ba nana",
"file1",
"file 01",
@@ -134,7 +134,7 @@ public class AlphaNumericComparatorTest extends AbstractGenericTest {
Collections.shuffle(unsorted);
List<String> copy = new ArrayList<>(unsorted);
- Collections.sort(copy, new AlphaNumericComparator(false));
+ Collections.sort(copy, AlphaNumericComparator.CI);
assertEquals(sorted, copy);
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableModel.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableModel.java
index 6d65634e7c..fb5dbff39e 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableModel.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableModel.java
@@ -196,9 +196,6 @@ public class ProjectDataTableModel extends ThreadedTableModel<DomainFileInfo, Pr
private class DomainFileNameColumn
extends AbstractDynamicTableColumn<DomainFileInfo, String, ProjectData> {
- private static AlphaNumericComparator alphaNumericComparator =
- new AlphaNumericComparator(false);
-
@Override
public String getColumnName() {
return "Name";
@@ -219,7 +216,7 @@ public class ProjectDataTableModel extends ThreadedTableModel<DomainFileInfo, Pr
@Override
public Comparator<String> getComparator() {
if (useNaturalSort) {
- return alphaNumericComparator;
+ return AlphaNumericComparator.CI;
}
return super.getComparator();
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
index 726ecb4dec..314050c733 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
@@ -257,9 +257,6 @@ public abstract class DataTreeNode extends GTreeSlowLoadingNode implements Cutta
private static class DataNodeSortComparator implements Comparator<GTreeNode> {
- private static AlphaNumericComparator alphaNumericComparator =
- new AlphaNumericComparator(false);
-
@Override
public int compare(GTreeNode o1, GTreeNode o2) {
@@ -290,7 +287,7 @@ public abstract class DataTreeNode extends GTreeSlowLoadingNode implements Cutta
private int compareNames(String n1, String n2) {
if (useNaturalSort) {
- return alphaNumericComparator.compare(n1, n2);
+ return AlphaNumericComparator.CI.compare(n1, n2);
}
int result = n1.compareToIgnoreCase(n2);
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/util/Lock.java b/Ghidra/Framework/Project/src/main/java/ghidra/util/Lock.java
index 6ed2a49f35..b388b8d299 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/util/Lock.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/util/Lock.java
@@ -142,4 +142,16 @@ public class Lock extends ReentrantReadWriteLock {
@Override
public void close();
}
+
+ /**
+ * Checks that the current thread already has the write lock and throws an
+ * IllegalStateException if it doesn't.
+ * @throws IllegalStateException if the current thread does not have the write lock.
+ */
+ public void expectWriteLock() {
+ if (!isWriteLockedByCurrentThread()) {
+ throw new IllegalStateException(
+ "write lock is expected to be aquired before this method is called.");
+ }
+ }
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java
index 6ba53ea9bd..e9d611e3fd 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java
@@ -58,60 +58,22 @@ public class NamespaceUtils {
// singleton utils class--no public construction
}
- /**
- * Get the normal namespace path excluding any library name. Global namespace will be
- * returned as empty string, while other namespace paths will be returned with trailing ::
- * suffix.
- * @param namespace namespace
- * @return namespace path excluding any library name
- */
- public static String getNamespacePathWithoutLibrary(Namespace namespace) {
- String str = new String();
- while (namespace != null && !(namespace instanceof GlobalNamespace) &&
- !(namespace instanceof Library)) {
- str = namespace.getName() + Namespace.DELIMITER + str;
- namespace = namespace.getParentNamespace();
- }
- return str;
- }
-
/**
* Get namespace qualified symbol name
* @param namespace namespace object
* @param symbolName name of symbol
- * @param excludeLibraryName if true any library name will be excluded from path returned,
* otherwise it will be included
* @return namespace qualified symbol name
*/
- public static String getNamespaceQualifiedName(Namespace namespace, String symbolName,
- boolean excludeLibraryName) {
+ public static String getNamespaceQualifiedName(Namespace namespace, String symbolName) {
String str = "";
- if (excludeLibraryName && namespace.isExternal()) {
- str = getNamespacePathWithoutLibrary(namespace);
- }
- else if (namespace != null && !(namespace instanceof GlobalNamespace)) {
+ if (namespace != null && !(namespace instanceof GlobalNamespace)) {
str = namespace.getName(true) + Namespace.DELIMITER;
}
str += symbolName;
return str;
}
- /**
- * Get the library associated with the specified namespace
- * @param namespace namespace
- * @return associated library or null if not associated with a library
- */
- public static Library getLibrary(Namespace namespace) {
- Namespace ns = namespace;
- while (ns.isExternal()) {
- if (ns instanceof Library) {
- return (Library) ns;
- }
- ns = ns.getParentNamespace();
- }
- return null;
- }
-
/**
* Returns a list of all namespaces with the given name in the parent namespace
*
@@ -166,12 +128,12 @@ public class NamespaceUtils {
}
List<String> namespaceNames = path.asList();
- List<Namespace> namespaces = doGetNamespaces(namespaceNames, parent, program, false);
+ List<Namespace> namespaces = doGetNamespaces(namespaceNames, parent, program);
return namespaces;
}
- private static List<Namespace> doGetNamespaces(List<String> namespaceNames,
- Namespace root, Program program, boolean searchWithinAllLibraries) {
+ private static List<Namespace> doGetNamespaces(List<String> namespaceNames, Namespace root,
+ Program program) {
if (root == null) {
root = program.getGlobalNamespace();
@@ -179,18 +141,6 @@ public class NamespaceUtils {
List<Namespace> parents = Arrays.asList(root);
- if (searchWithinAllLibraries && root.isGlobal() && !namespaceNames.isEmpty()) {
- ExternalManager extMgr = program.getExternalManager();
- String ns = namespaceNames.get(0); // only consider if first namespace is not Library
- if (extMgr.getExternalLibrary(ns) == null) {
- parents = new ArrayList<>();
- parents.add(root);
- for (String libraryName : extMgr.getExternalLibraryNames()) {
- parents.add(extMgr.getExternalLibrary(libraryName));
- }
- }
- }
-
for (String name : namespaceNames) {
List<Namespace> matches = getMatchingNamespaces(name, parents, program);
parents = matches;
@@ -251,23 +201,6 @@ public class NamespaceUtils {
* if none found.
*/
public static List<Symbol> getSymbols(String symbolPath, Program program) {
- return getSymbols(symbolPath, program, false);
- }
-
- /**
- * Returns a list of all symbols that match the given path. The path consists of a series
- * of namespaces names separated by "::" followed by a label or function name.
- *
- * @param symbolPath the names of namespaces and symbol separated by "::".
- * @param program the program to search
- * @param searchWithinAllLibraries if true all libraries will be searched provided first element
- * of symbolPath is not a library name, else search symbolPath within global namespace only.
- * @return the list of symbols that match the given symbolPath. An empty list is returned
- * if none found.
- */
- public static List<Symbol> getSymbols(String symbolPath, Program program,
- boolean searchWithinAllLibraries) {
-
List<String> namespaceNames = new SymbolPath(symbolPath).asList();
if (namespaceNames.isEmpty()) {
return Collections.emptyList();
@@ -275,8 +208,7 @@ public class NamespaceUtils {
String symbolName = namespaceNames.remove(namespaceNames.size() - 1);
List<Namespace> parents =
- doGetNamespaces(namespaceNames, program.getGlobalNamespace(), program,
- searchWithinAllLibraries);
+ doGetNamespaces(namespaceNames, program.getGlobalNamespace(), program);
return searchForAllSymbolsInAnyOfTheseNamespaces(parents, symbolName, program);
}
@@ -289,27 +221,11 @@ public class NamespaceUtils {
* if none found.
*/
public static List<Symbol> getSymbols(SymbolPath symbolPath, Program program) {
- return getSymbols(symbolPath, program, false);
- }
-
- /**
- * Returns a list of Symbol that match the given symbolPath.
- *
- * @param symbolPath the symbol path that specifies a series of namespace and symbol names.
- * @param program the program to search for symbols with the given path.
- * @param searchWithinAllLibraries if true all libraries will be searched provided first element
- * of symbolPath is not a library name, else search symbolPath within global namespace only.
- * @return a list of Symbol that match the given symbolPath. An empty list is returned
- * if none found.
- */
- public static List<Symbol> getSymbols(SymbolPath symbolPath, Program program,
- boolean searchWithinAllLibraries) {
SymbolPath parentPath = symbolPath.getParent();
if (parentPath == null) {
return program.getSymbolTable().getGlobalSymbols(symbolPath.getName());
}
- List<Namespace> parents =
- doGetNamespaces(parentPath.asList(), null, program, searchWithinAllLibraries);
+ List<Namespace> parents = doGetNamespaces(parentPath.asList(), null, program);
return searchForAllSymbolsInAnyOfTheseNamespaces(parents, symbolPath.getName(), program);
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/SymbolPath.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/SymbolPath.java
index ad4ce3db2c..80a19b08ed 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/SymbolPath.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/SymbolPath.java
@@ -18,7 +18,6 @@ package ghidra.app.util;
import java.util.*;
import ghidra.program.model.address.GlobalNamespace;
-import ghidra.program.model.listing.Library;
import ghidra.program.model.symbol.*;
/**
@@ -86,25 +85,11 @@ public class SymbolPath implements Comparable<SymbolPath> {
* @param symbol the symbol to get a SymbolPath for.
*/
public SymbolPath(Symbol symbol) {
- this(symbol, false);
- }
-
- /**
- * Constructs a new SymbolPath for the given symbol with the option to exclude a beginning
- * library name.
- *
- * @param symbol the symbol to get a SymbolPath for.
- * @param excludeLibrary if true, any library name at the front of the path will be removed.
- */
- public SymbolPath(Symbol symbol, boolean excludeLibrary) {
symbolName = symbol.getName();
Namespace parentNamespace = symbol.getParentNamespace();
if (parentNamespace == null || parentNamespace.isGlobal()) {
parentPath = null;
}
- else if (excludeLibrary && (parentNamespace instanceof Library)) {
- parentPath = null;
- }
else {
parentPath = new SymbolPath(parentNamespace.getSymbol());
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
index 97e5ed387b..6a538fa275 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
@@ -124,8 +124,9 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
* 19-Sep-2025 - version 32 Expanded number of SourceType values and record storage affecting
* SymbolDB, FunctionDB and RefListFlagsV0
* 14-Apr-2026 - version 33 Introduced Library symbol ordinal assignment.
+ * 1-Oct-2026 - version 34 Change where Libraries are no longer represent a namespace.
*/
- static final int DB_VERSION = 33;
+ static final int DB_VERSION = 34;
/**
* UPGRADE_REQUIRED_BFORE_VERSION should be changed to DB_VERSION anytime the
@@ -2132,7 +2133,8 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
// Force function manager to reconcile calling conventions
managers[FUNCTION_MGR].setDomainObject(this);
- managers[FUNCTION_MGR].domainObjectReady(OpenMode.UPDATE, getStoredVersion(), monitor);
+ managers[FUNCTION_MGR].domainObjectReady(OpenMode.UPDATE, getStoredVersion(),
+ monitor);
if (translator != null) {
// allow complex language upgrades to transform instructions/context
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
index 7cb59e0d09..e089d3b4aa 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
@@ -200,7 +200,7 @@ public class DataTypeUtilities {
*/
private static DataType getValidReplacement(TypeDef typedef, boolean enforceSizeMatch,
DataTypeManager dtm) {
-
+
DataType replacementDt = cTypedefBuiltInNameRemap.get(typedef.getName());
if (replacementDt == null) {
return null;
@@ -662,9 +662,6 @@ public class DataTypeUtilities {
Namespace namespace) {
List<String> categoryPathParts = new ArrayList<>();
for (Namespace ns : NamespaceUtils.getNamespaceParts(namespace)) {
- if (ns instanceof Library) {
- break; // assume the Library is a root and no other categories are above it
- }
categoryPathParts.add(ns.getName());
}
return categoryPathParts.isEmpty() ? baseCategory
@@ -794,12 +791,12 @@ public class DataTypeUtilities {
* A null is returned if namespace is null or the root/global namespace.
*/
private static String[] getRelativeCategoryPaths(Namespace namespace) {
- if (namespace == null || namespace.isGlobal() || namespace.isLibrary()) {
+ if (namespace == null || namespace.isGlobal()) {
return null;
}
String[] paths = new String[2];
StringBuilder buf = new StringBuilder();
- for (String n : namespace.getParentNamespace().getPathList(true)) {
+ for (String n : namespace.getParentNamespace().getPathList()) {
buf.append(CategoryPath.DELIMITER_STRING);
buf.append(CategoryPath.escapeString(n));
}
@@ -970,19 +967,19 @@ public class DataTypeUtilities {
return null;
}
- if (namespace == null || namespace.isGlobal() || namespace.isLibrary()) {
+ if (namespace == null || namespace.isGlobal()) {
return getAssignableDataType(dataTypeManager, rootPath, null, dtName, classConstraint);
}
if (parentNamespacePreferred) {
T dt = getAssignableDataType(dataTypeManager, rootPath,
- namespace.getParentNamespace().getPathList(true), dtName, classConstraint);
+ namespace.getParentNamespace().getPathList(), dtName, classConstraint);
if (dt != null) {
return dt;
}
}
- return getAssignableDataType(dataTypeManager, rootPath, namespace.getPathList(true), dtName,
+ return getAssignableDataType(dataTypeManager, rootPath, namespace.getPathList(), dtName,
classConstraint);
}
@@ -1259,7 +1256,6 @@ public class DataTypeUtilities {
public static boolean equalsIgnoreConflict(String name1, String name2) {
return getNameWithoutConflict(name1).equals(getNameWithoutConflict(name2));
}
-
/**
* Returns true if there is a {@link DataTypeMerger} that can handle the given datatype. Currently, only structures
@@ -1270,6 +1266,7 @@ public class DataTypeUtilities {
public static boolean supportsMerge(DataType dataType) {
return dataType instanceof Composite || dataType instanceof Enum;
}
+
/**
* Convenience method for getting the appropriate datatype merger or throwing an exception
* if the two datatypes are not eligible to be merged.
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalLocationDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalLocationDB.java
index aea5b01f93..b225756176 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalLocationDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalLocationDB.java
@@ -60,14 +60,10 @@ public class ExternalLocationDB implements ExternalLocation {
Library library = getLibrary();
return library != null ? library.getAssociatedProgramPath() : null;
}
-
- private Library getLibrary() {
- Namespace parent = symbol.getParentNamespace();
- while (parent != null && !(parent instanceof Library)) {
- parent = parent.getParentNamespace();
- }
- return (Library) parent;
+ @Override
+ public Library getLibrary() {
+ return symbol.getLibrary();
}
@Override
@@ -111,7 +107,11 @@ public class ExternalLocationDB implements ExternalLocation {
@Override
public String toString() {
- StringBuilder builder = new StringBuilder(symbol.getName(true));
+
+ StringBuilder builder = new StringBuilder(getLibraryName());
+ builder.append("::");
+ builder.append(symbol.getName(true));
+
if (getOriginalImportedName() != null) {
builder.append(" (").append(getOriginalImportedName()).append(")");
}
@@ -151,6 +151,7 @@ public class ExternalLocationDB implements ExternalLocation {
if (symbol.getSymbolType() == SymbolType.FUNCTION) {
return getFunction();
}
+
Function function = extMgr.createFunction(this);
symbol = (FunctionSymbol) function.getSymbol();
return function;
@@ -169,7 +170,7 @@ public class ExternalLocationDB implements ExternalLocation {
*/
void setLabel(String label, SourceType source) throws InvalidInputException {
if (label == null) {
- setName(getLibrary(), null, SourceType.DEFAULT);
+ setName(null, null, SourceType.DEFAULT);
}
else if (label.indexOf(Namespace.DELIMITER) < 0) {
// if label does not include namespace keep current namespace
@@ -178,7 +179,7 @@ public class ExternalLocationDB implements ExternalLocation {
else {
SymbolPath symbolPath = new SymbolPath(label);
Namespace namespace = NamespaceUtils.createNamespaceHierarchy(
- symbolPath.getParentPath(), getLibrary(), extMgr.getProgram(), source);
+ symbolPath.getParentPath(), null, extMgr.getProgram(), source);
setName(namespace, symbolPath.getName(), source);
}
}
@@ -199,6 +200,11 @@ public class ExternalLocationDB implements ExternalLocation {
setAddress(addr);
}
+ @Override
+ public void setLibrary(Library library) {
+ symbol.setLibrary(library);
+ }
+
@Override
public void setAddress(Address address) throws InvalidInputException {
if (address == null && getSource() == SourceType.DEFAULT) {
@@ -207,17 +213,14 @@ public class ExternalLocationDB implements ExternalLocation {
symbol.setExternalProgramAddress(address, true);
}
- public void saveOriginalNameIfNeeded(Namespace oldNamespace, String oldName,
- SourceType oldSource) {
-
- boolean wasInLibrary = (oldNamespace instanceof Library);
+ public void saveOriginalNameIfNeeded(String oldName, SourceType oldSource) {
// if we don't have an original already set and it is an imported symbol, save it
String originalImportedName = getOriginalImportedName();
if (getLabel().equals(originalImportedName)) {
symbol.setExternalOriginalImportedName(null, false);
}
- else if (wasInLibrary && getSource() != SourceType.DEFAULT &&
+ else if (getSource() != SourceType.DEFAULT &&
oldSource == SourceType.IMPORTED && originalImportedName == null) {
symbol.setExternalOriginalImportedName(oldName, false);
}
@@ -228,15 +231,12 @@ public class ExternalLocationDB implements ExternalLocation {
throws InvalidInputException {
try {
- if (!namespace.isExternal()) {
- throw new IllegalArgumentException("external namespace required");
- }
if (newName == null || newName.length() == 0) {
sourceType = SourceType.DEFAULT;
String originalName = getOriginalImportedName();
if (originalName != null) {
newName = originalName;
- namespace = NamespaceUtils.getLibrary(namespace);
+ namespace = null;
sourceType = SourceType.IMPORTED;
}
else if (getAddress() == null) {
@@ -244,14 +244,18 @@ public class ExternalLocationDB implements ExternalLocation {
"Either an external label or address is required");
}
}
- else if (namespace instanceof Library && newName.equals(getOriginalImportedName())) {
+ else if ((namespace == null || namespace.isGlobal()) &&
+ newName.equals(getOriginalImportedName())) {
// preserve imported source if new name matches original imported name
sourceType = SourceType.IMPORTED;
}
+ if (namespace == null) {
+ namespace = symbol.getProgram().getGlobalNamespace();
+ }
symbol.setNameAndNamespace(newName, namespace, sourceType);
}
catch (DuplicateNameException | CircularDependencyException e) {
- // Duplicate names are permitted and external locations do not support namespace behavior
+ // Duplicate names are permitted
throw new AssertException("Unexpected exception", e);
}
}
@@ -263,9 +267,8 @@ public class ExternalLocationDB implements ExternalLocation {
return;
}
try {
- Library library = NamespaceUtils.getLibrary(symbol.getParentNamespace());
symbol.setExternalOriginalImportedName(null, false); // clear orig imported name
- symbol.setNameAndNamespace(originalName, library, SourceType.IMPORTED);
+ symbol.setNameAndNamespace(originalName, null, SourceType.IMPORTED);
}
catch (CircularDependencyException | DuplicateNameException | InvalidInputException e) {
throw new AssertException("Can't happen here", e);
@@ -310,6 +313,11 @@ public class ExternalLocationDB implements ExternalLocation {
String originalImportName = getOriginalImportedName();
String otherName = other.getLabel();
String otherOriginalImportName = other.getOriginalImportedName();
+ String libraryName = getLibraryName();
+ String otherLibraryName = other.getLibraryName();
+ if (!libraryName.equals(otherLibraryName)) {
+ return false;
+ }
// if the original import names are not null and they match, this is probably the one since
// the original import names are most likely mangled names and should be unique.
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalManagerDB.java
index ba7a4267cb..d17603dfcd 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalManagerDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/external/ExternalManagerDB.java
@@ -22,10 +22,8 @@ import org.apache.commons.lang3.StringUtils;
import db.*;
import ghidra.framework.data.OpenMode;
-import ghidra.program.database.ProgramDBModule;
import ghidra.program.database.ProgramDB;
-import ghidra.program.database.function.FunctionDB;
-import ghidra.program.database.function.FunctionManagerDB;
+import ghidra.program.database.ProgramDBModule;
import ghidra.program.database.map.AddressMap;
import ghidra.program.database.symbol.*;
import ghidra.program.model.address.Address;
@@ -47,7 +45,6 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
private AddressMap addrMap;
private SymbolManager symbolMgr;
- private FunctionManagerDB functionMgr;
private ProgramDB program;
private Lock lock;
@@ -93,7 +90,6 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
public void setDomainObject(ProgramDB program) {
this.program = program;
symbolMgr = program.getSymbolTable();
- functionMgr = program.getFunctionManager();
}
@Override
@@ -195,57 +191,43 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
}
@Override
- public ExternalLocation addExtLocation(String extLibraryName, String extLabel, Address extAddr,
+ public ExternalLocation addExtLocation(String libraryName, String extLabel, Address extAddr,
SourceType sourceType) throws InvalidInputException, DuplicateNameException {
SourceType locSourceType = checkExternalLabel(extLabel, extAddr, sourceType);
try (Closeable c = lock.write()) {
- Library library = addExternalLibraryName(extLibraryName, sourceType);
- return addExtLocation(library, extLabel, extAddr, false, locSourceType, true);
- }
- }
-
- @Override
- public ExternalLocation addExtLocation(Namespace extParentNamespace, String extLabel,
- Address extAddr, SourceType sourceType) throws InvalidInputException {
- try (Closeable c = lock.write()) {
- return addExtLocation(extParentNamespace, extLabel, extAddr, false, sourceType, true);
+ Library library = addExternalLibraryName(libraryName, sourceType);
+ return addExtLocation(library, null, extLabel, extAddr, false, locSourceType, true);
}
}
@Override
- public ExternalLocation addExtLocation(Namespace extParentNamespace, String extLabel,
+ public ExternalLocation addExtLocation(Library library, Namespace namespace, String extLabel,
Address extAddr, SourceType sourceType, boolean reuseExisting)
throws InvalidInputException {
try (Closeable c = lock.write()) {
- return addExtLocation(extParentNamespace, extLabel, extAddr, false, sourceType,
+ return addExtLocation(library, namespace, extLabel, extAddr, false, sourceType,
reuseExisting);
}
}
@Override
- public ExternalLocation addExtFunction(String extLibraryName, String extLabel, Address extAddr,
+ public ExternalLocation addExtFunction(String libraryName, String extLabel, Address extAddr,
SourceType sourceType) throws InvalidInputException, DuplicateNameException {
SourceType locSourceType = checkExternalLabel(extLabel, extAddr, sourceType);
try (Closeable c = lock.write()) {
- Library library = addExternalLibraryName(extLibraryName,
- sourceType != SourceType.DEFAULT ? sourceType : SourceType.ANALYSIS);
- return addExtLocation(library, extLabel, extAddr, true, locSourceType, true);
- }
- }
-
- @Override
- public ExternalLocation addExtFunction(Namespace extParentNamespace, String extLabel,
- Address extAddr, SourceType sourceType) throws InvalidInputException {
- try (Closeable c = lock.write()) {
- return addExtLocation(extParentNamespace, extLabel, extAddr, true, sourceType, true);
+ Library library = addExternalLibraryName(libraryName,
+ sourceType != SourceType.DEFAULT ? sourceType : SourceType.ANALYSIS);
+ return addExtLocation(library, null, extLabel, extAddr, true, locSourceType, true);
}
}
@Override
- public ExternalLocation addExtFunction(Namespace extNamespace, String extLabel, Address extAddr,
- SourceType sourceType, boolean reuseExisting) throws InvalidInputException {
+ public ExternalLocation addExtFunction(Library library, Namespace extNamespace, String extLabel,
+ Address extAddr, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException {
try (Closeable c = lock.write()) {
- return addExtLocation(extNamespace, extLabel, extAddr, true, sourceType, reuseExisting);
+ return addExtLocation(library, extNamespace, extLabel, extAddr, true, sourceType,
+ reuseExisting);
}
}
@@ -261,94 +243,116 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
return extLabel == null ? SourceType.DEFAULT : source;
}
- private ExternalLocation addExtLocation(Namespace extNamespace, String extLabel,
- Address extAddr, boolean isFunction, SourceType sourceType, boolean reuseExisting)
- throws InvalidInputException {
- if (extNamespace == null) {
- try {
- extNamespace = addExternalLibraryName(Library.UNKNOWN, SourceType.ANALYSIS);
- }
- catch (InvalidInputException | DuplicateNameException e) {
- throw new AssertionError(e); // reserved name should be OK
- }
- }
- else if (!extNamespace.isExternal()) {
- throw new InvalidInputException("The namespace must be an external namespace.");
+ private ExternalLocation addExtLocation(Library library, Namespace namespace,
+ String extLabel, Address extAddr, boolean isFunction, SourceType sourceType,
+ boolean reuseExisting) throws InvalidInputException {
+
+ if (library == null) {
+ library = getDefaultLibrary();
}
+ symbolMgr.checkValidLibrary(library);
+
sourceType = checkExternalLabel(extLabel, extAddr, sourceType);
- if (extAddr != null) {
- if (!extAddr.isLoadedMemoryAddress()) {
- throw new InvalidInputException("Invalid memory address: " + extAddr);
- }
- AddressSpace space = extAddr.getAddressSpace();
- if (!space.equals(program.getAddressFactory().getAddressSpace(space.getName()))) {
- throw new InvalidInputException(
- "Memory address not defined for program: " + extAddr);
+ symbolMgr.checkExternalAddress(extAddr);
+
+ try {
+ extLabel = cleanupLabel(extLabel, sourceType);
+ ExternalLocation loc =
+ getAndUpdateForExisting(library, namespace, extLabel, extAddr, isFunction,
+ sourceType, reuseExisting);
+ if (loc != null) {
+ return loc;
}
+ MemorySymbol s =
+ createNewExternalSymbol(library, namespace, extLabel, extAddr, isFunction,
+ sourceType);
+ return new ExternalLocationDB(this, s);
+
}
- try (Closeable c = lock.write()) {
- if (sourceType == SourceType.DEFAULT) {
- extLabel = null;
- }
- else if (StringUtils.isBlank(extLabel) || SymbolUtilities
- .isReservedExternalDefaultName(extLabel, addrMap.getAddressFactory())) {
- extLabel = null; // force use of address
- }
- if (extAddr != null || reuseExisting) {
+ catch (IOException e) {
+ program.dbError(e); // will not return
+ return null;
+ }
+ }
- ExternalLocationDB extLoc = (ExternalLocationDB) getExtLocation(extNamespace,
- extLabel, extAddr, reuseExisting);
+ private MemorySymbol createNewExternalSymbol(Library library, Namespace namespace,
+ String extLabel, Address extAddr, boolean isFunction,
+ SourceType sourceType) throws InvalidInputException, IOException {
- if (extLoc != null) {
+ if (isFunction) {
+ return symbolMgr.createExternalFunctionSymbol(library, extLabel, namespace, sourceType,
+ null, extAddr);
+ }
+ return symbolMgr.createExternalCodeSymbol(library, extLabel, namespace, sourceType,
+ null, extAddr);
- // if there is already a location with the address, then we must use it
- if (extLabel != null && !extLabel.equals(extLoc.getLabel())) {
- extLoc.setLabel(extLabel, sourceType);
- }
- if (isFunction) {
- // transform to a function if needed
- extLoc = (ExternalLocationDB) createFunction(extLoc).getExternalLocation();
- }
- return extLoc;
+ }
+
+ private ExternalLocation getAndUpdateForExisting(Library library, Namespace namespace,
+ String extLabel,
+ Address extAddr, boolean isFunction, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException {
+
+ if (extLabel == null || reuseExisting) {
+
+ ExternalLocationDB extLoc = (ExternalLocationDB) getExtLocation(library,
+ namespace, extLabel, extAddr, reuseExisting);
+
+ if (extLoc != null) {
+
+ // if there is already a location with the address, then we must use it
+ if (extLabel != null && !extLabel.equals(extLoc.getLabel())) {
+ extLoc.setLabel(extLabel, sourceType);
+ }
+ if (isFunction) {
+ // transform to a function if needed
+ extLoc = (ExternalLocationDB) createFunction(extLoc).getExternalLocation();
}
+ return extLoc;
}
+ }
+ return null;
+ }
- // ok can't or don't want to reuse an existing one, so make a new one.
- MemorySymbol s;
- Address externalSpaceAddress = symbolMgr.getNextExternalSymbolAddress();
- if (isFunction) {
- FunctionDB function = functionMgr.createExternalFunction(externalSpaceAddress,
- extLabel, extNamespace, null, extAddr, sourceType);
- s = (FunctionSymbol) function.getSymbol();
- }
- else {
- s = symbolMgr.createExternalCodeSymbol(externalSpaceAddress, extLabel, extNamespace,
- sourceType, null, extAddr);
- }
- return new ExternalLocationDB(this, s);
+ private String cleanupLabel(String extLabel, SourceType sourceType) {
+ if (sourceType == SourceType.DEFAULT) {
+ extLabel = null;
}
- catch (IOException e) {
- program.dbError(e); // will not return
- return null;
+ else if (StringUtils.isBlank(extLabel) || SymbolUtilities
+ .isReservedExternalDefaultName(extLabel, addrMap.getAddressFactory())) {
+ // force use of address since name is empty or default (in this case the address
+ // can't be null (you have to specify at least one or the other)
+ extLabel = null;
+ }
+ return extLabel;
+ }
+
+ private Library getDefaultLibrary() throws AssertionError {
+ try {
+ return addExternalLibraryName(Library.UNKNOWN, SourceType.ANALYSIS);
+ }
+ catch (InvalidInputException | DuplicateNameException e) {
+ throw new AssertionError(e); // reserved name should be OK
}
}
/**
* Get the external location which best matches the specified parameters.
* Preference is given to extLabel over extAddr
- * @param library the library namespace containing this external location.
+ * @param library the library containing this external location.
+ * @param namespace the namespace containing the external location (may be null for global)
* @param extLabel the name of the external location. Can be null.
* @param extAddr the address of function in the external program. Can be null
* @return the best matching ExternalLocation or null.
* @throws InvalidInputException if the extLabel name contains illegal characters (i.e. space)
*/
- private ExternalLocation getExtLocation(Namespace library, String extLabel, Address extAddr,
- boolean reuseExisting) throws InvalidInputException {
+ private ExternalLocation getExtLocation(Library library, Namespace namespace, String extLabel,
+ Address extAddr, boolean reuseExisting) throws InvalidInputException {
// Name match will also consider original import name if library is either null
- // or a Library, otherwise only a specific namespaced name match will be considered.
+ // or a Library, otherwise only a specific namespace name match will be considered.
ExternalLocation match =
- findMatchingLocationByName(library, extLabel, extAddr, reuseExisting);
+ findMatchingLocationByName(library, namespace, extLabel, extAddr, reuseExisting);
if (match != null) {
return match;
}
@@ -360,16 +364,17 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
return null;
}
- // Find an external location in the given namespace with the given name and address. If
- // reuseExisting is true, then also find a match as long as the name and namespace match and
+ // Find an external location in the given library and namespace with the given name and address. If
+ // reuseExisting is true, then also find a match as long as the name, namespace and library match and
// the address is null.
- private ExternalLocation findMatchingLocationByName(Namespace namespace, String extLabel,
- Address extAddr, boolean reuseExisting) {
+ private ExternalLocation findMatchingLocationByName(Library library, Namespace namespace,
+ String extLabel, Address extAddr, boolean reuseExisting) {
if (StringUtils.isBlank(extLabel)) {
return null;
}
- Set<ExternalLocation> externalLocations = getExternalLocations(namespace, extLabel);
+ Set<ExternalLocation> externalLocations =
+ getExternalLocations(library, namespace, extLabel);
if (externalLocations.isEmpty()) {
return null;
}
@@ -421,67 +426,75 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
}
@Override
- public Set<ExternalLocation> getExternalLocations(Namespace namespace, String extLabel) {
- if (namespace != null && !namespace.isExternal()) {
- return Set.of();
- }
+ public Set<ExternalLocation> getExternalLocations(Library library, Namespace namespace,
+ String extLabel) {
Set<ExternalLocation> externalLocations = new HashSet<>();
- if (namespace == null || namespace instanceof Library) {
- // Check for matching original import name
- SymbolIterator matchingSymbols =
- symbolMgr.getExternalSymbolByOriginalImportName((Library) namespace, extLabel);
- for (Symbol symbol : matchingSymbols) {
- ExternalLocation externalLocation = getExternalLocation(symbol);
- if (externalLocation != null) {
- externalLocations.add(externalLocation);
- }
+
+ try (Closeable c = lock.read()) {
+
+ if (library != null) {
+ symbolMgr.checkValidLibrary(library);
}
- }
- if (namespace != null) {
- List<Symbol> symbols = symbolMgr.getSymbols(extLabel, namespace);
- for (Symbol symbol : symbols) {
- ExternalLocation externalLocation = getExternalLocation(symbol);
- if (externalLocation != null) {
- externalLocations.add(externalLocation);
+
+ // search original mangled names if namespace is not specified
+ if (namespace == null || namespace.isGlobal()) {
+ SymbolIterator matchingSymbols =
+ symbolMgr.getExternalSymbolByOriginalImportName(library, extLabel);
+ for (Symbol symbol : matchingSymbols) {
+ ExternalLocation externalLocation = getExternalLocation(symbol);
+ if (externalLocation != null) {
+ externalLocations.add(externalLocation);
+ }
}
}
- }
- else {
- for (Symbol symbol : symbolMgr.getExternalSymbols(extLabel)) {
- ExternalLocation externalLocation = getExternalLocation(symbol);
- if (externalLocation != null) {
- externalLocations.add(externalLocation);
+
+ // search for symbol name within the specified namespace
+ for (Symbol symbol : symbolMgr.getSymbols(extLabel, namespace)) {
+ if (!symbol.isExternal()) {
+ continue;
+ }
+ if (library != null && !library.equals(symbol.getLibrary())) {
+ continue;
}
+ externalLocations.add(getExternalLocation(symbol));
}
}
- return Collections.unmodifiableSet(externalLocations);
+ return externalLocations;
}
@Override
public Set<ExternalLocation> getExternalLocations(String libraryName, String label) {
- Library library = getExternalLibrary(libraryName);
- if (library == null && !StringUtils.isBlank(libraryName)) {
- return Set.of();
+ try (Closeable c = lock.read()) {
+ Library library = getExternalLibrary(libraryName);
+ if (library == null && !StringUtils.isBlank(libraryName)) {
+ return Set.of();
+ }
+ return getExternalLocations(library, null, label);
}
- return getExternalLocations(library, label);
}
@Override
- public ExternalLocation getUniqueExternalLocation(Namespace namespace, String label) {
- Set<ExternalLocation> externalLocations = getExternalLocations(namespace, label);
- if (externalLocations.size() == 1) {
- return externalLocations.iterator().next();
+ public ExternalLocation getUniqueExternalLocation(Library library, Namespace namespace,
+ String label) {
+ try (Closeable c = lock.read()) {
+ Set<ExternalLocation> externalLocations =
+ getExternalLocations(library, namespace, label);
+ if (externalLocations.size() == 1) {
+ return externalLocations.iterator().next();
+ }
}
return null;
}
@Override
public ExternalLocation getUniqueExternalLocation(String libraryName, String label) {
- Library library = getExternalLibrary(libraryName);
- if (library == null && !StringUtils.isBlank(libraryName)) {
- return null;
+ try (Closeable c = lock.read()) {
+ Library library = libraryName != null ? getExternalLibrary(libraryName) : null;
+ if (libraryName != null && library == null) {
+ return null;
+ }
+ return getUniqueExternalLocation(library, null, label);
}
- return getUniqueExternalLocation(library, label);
}
/**
@@ -708,7 +721,7 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
if (extLoc.isFunction()) {
return extLoc.getFunction();
}
- try (Closeable c = lock.write()) {
+ try (Closeable _ = lock.write()) {
SymbolDB symbol = (SymbolDB) extLoc.getSymbol();
if (!(symbol instanceof CodeSymbol)) {
throw new IllegalStateException("Expected external code symbol");
@@ -717,17 +730,23 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
String origImpName = extLoc.getOriginalImportedName();
String name = symbol.getName();
Namespace namespace = symbol.getParentNamespace();
- Address extAddr = symbol.getAddress();
+ Library library = symbol.getLibrary();
+ Address externalSpaceAddress = symbol.getAddress();
SourceType source = symbol.getSource();
((CodeSymbol) symbol).delete(true);
- return functionMgr.createExternalFunction(extAddr, name, namespace, origImpName,
- extProgAddr, source);
+ FunctionSymbol functionSymbol = symbolMgr.createExternalFunctionSymbol(library,
+ externalSpaceAddress, name, namespace, source, origImpName, extProgAddr);
+ return functionSymbol.getObject();
}
- catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
+ catch (InvalidInputException e) {
+ throw new AssertException(e);
}
+ catch (IOException e) {
+ program.dbError(e);
+ }
+ return null;
}
AddressMap getAddressMap() {
@@ -741,11 +760,13 @@ public class ExternalManagerDB implements ProgramDBModule, ExternalManager {
@Override
public ExternalLocationIterator getExternalLocations(String externalName) {
- Library library = getExternalLibrary(externalName);
- if (library != null) {
- return new ExternalLocationDBIterator(symbolMgr.getSymbols(library));
+ try (Closeable c = lock.read()) {
+ Library library = getExternalLibrary(externalName);
+ if (library != null) {
+ return new ExternalLocationDBIterator(symbolMgr.getSymbols(library));
+ }
+ return new ExternalLocationDBIterator();
}
- return new ExternalLocationDBIterator();
}
private class ExternalLocationDBIterator implements ExternalLocationIterator {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
index 916beb909a..a02c744345 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
@@ -148,29 +148,14 @@ public class FunctionManagerDB implements FunctionManager {
}
/**
- * Transform an existing external symbol into an external function.
- * This method should only be invoked by the Function Manager.
- * The {@link ExternalLocation#getOriginalImportedName() original imported name} will initially
- * be null.
+ * Create the associated function record for the given function symbol that was just created.
*
- * @param extSpaceAddr the external space address to use when creating this external. Any
- * other symbol using this address must first be deleted. Results are unpredictable if this is
- * not done.
- * @param name the external function name
- * @param nameSpace the external function namespace
- * @param externalProgramAddress the external program address (may be null)
- * @param originalImportName the original imported name if different from name (may be null)
- * @param source the source of this external.
- * @return external function
- * @throws InvalidInputException if the name is invalid
+ * @param symbol the function symbol that was created for the function.
+ * @return the new function
*/
- public FunctionDB createExternalFunction(Address extSpaceAddr, String name, Namespace nameSpace,
- String originalImportName, Address externalProgramAddress, SourceType source)
- throws InvalidInputException {
-
- try (Closeable c = lock.write()) {
- FunctionSymbol symbol = symbolMgr.createExternalFunctionSymbol(extSpaceAddr, name,
- nameSpace, source, originalImportName, externalProgramAddress);
+ public FunctionDB createExternalFunction(FunctionSymbol symbol) {
+ lock.expectWriteLock();
+ try {
long returnDataTypeId = program.getDataTypeManager().getResolvedID(DataType.DEFAULT);
@@ -178,7 +163,8 @@ public class FunctionManagerDB implements FunctionManager {
FunctionDB function = new FunctionDB(this, addrMap, rec);
cache.add(function);
- program.setObjChanged(ProgramEvent.FUNCTION_ADDED, extSpaceAddr, function, null, null);
+ Address extAddress = symbol.getAddress();
+ program.setObjChanged(ProgramEvent.FUNCTION_ADDED, extAddress, function, null, null);
return function;
}
catch (IOException e) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/references/ReferenceDBManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/references/ReferenceDBManager.java
index 07ec455d86..14c1240d43 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/references/ReferenceDBManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/references/ReferenceDBManager.java
@@ -578,20 +578,22 @@ public class ReferenceDBManager implements ReferenceManager, ProgramDBModule, Er
if (!fromAddr.isMemoryAddress()) {
throw new IllegalArgumentException("From address must be memory addresses");
}
- try {
- if (symbolMgr.getPrimarySymbol(location.getExternalSpaceAddress()) != null) {
- removeAllFrom(fromAddr, opIndex);
- return addRef(fromAddr, location.getExternalSpaceAddress(), type, sourceType,
- opIndex, false, false, 0);
- }
- try {
- return addExternalReference(fromAddr, location.getParentName(), location.getLabel(),
- location.getAddress(), sourceType, opIndex, type);
+ try (Closeable c = lock.write()) {
+
+ Symbol extSym = location.getSymbol();
+ if (extSym.getProgram() != getProgram()) {
+ throw new IllegalArgumentException(
+ "External location originates from a different program instance");
}
- catch (DuplicateNameException e) {
- throw new InvalidInputException(
- "External location not found and failed to create due to name conflict");
+
+ if (extSym.isDeleted()) {
+ throw new ConcurrentModificationException("External location has been deleted");
}
+
+ removeAllFrom(fromAddr, opIndex);
+
+ return addRef(fromAddr, extSym.getAddress(), type, sourceType, opIndex, false, false,
+ 0);
}
catch (IOException e) {
program.dbError(e);
@@ -625,7 +627,8 @@ public class ReferenceDBManager implements ReferenceManager, ProgramDBModule, Er
}
@Override
- public Reference addExternalReference(Address fromAddr, Namespace extNamespace, String extLabel,
+ public Reference addExternalReference(Address fromAddr, Library library, Namespace namespace,
+ String extLabel,
Address extAddr, SourceType sourceType, int opIndex, RefType type)
throws InvalidInputException, DuplicateNameException {
if (!fromAddr.isMemoryAddress()) {
@@ -634,7 +637,7 @@ public class ReferenceDBManager implements ReferenceManager, ProgramDBModule, Er
try {
ExternalManagerDB extMgr = program.getExternalManager();
ExternalLocation extLoc =
- extMgr.addExtLocation(extNamespace, extLabel, extAddr, sourceType);
+ extMgr.addExtLocation(library, namespace, extLabel, extAddr, sourceType);
removeAllFrom(fromAddr, opIndex);
@@ -1799,9 +1802,10 @@ public class ReferenceDBManager implements ReferenceManager, ProgramDBModule, Er
int opIndex = ref.getOperandIndex();
if (ref.isExternalReference()) {
ExternalLocation extLoc = ((ExternalReference) ref).getExternalLocation();
+ Library library = extLoc.getLibrary();
try {
- return addExternalReference(from, extLoc.getParentNameSpace(), extLoc.getLabel(),
- extLoc.getAddress(), sourceType, opIndex, type);
+ return addExternalReference(from, library, extLoc.getParentNameSpace(),
+ extLoc.getLabel(), extLoc.getAddress(), sourceType, opIndex, type);
}
catch (DuplicateNameException e) {
throw new AssertException(e);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/ClassSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/ClassSymbol.java
index 5a7af253e5..9b37c17549 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/ClassSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/ClassSymbol.java
@@ -18,7 +18,8 @@ package ghidra.program.database.symbol;
import db.DBRecord;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.GhidraClass;
-import ghidra.program.model.symbol.*;
+import ghidra.program.model.symbol.Namespace;
+import ghidra.program.model.symbol.SymbolType;
import ghidra.util.Lock.Closeable;
/**
@@ -62,13 +63,12 @@ public class ClassSymbol extends SymbolDB {
@Override
public boolean isExternal() {
- Symbol parentSymbol = getParentSymbol();
- return parentSymbol != null ? parentSymbol.isExternal() : false;
+ return false;
}
@Override
public boolean isValidParent(Namespace parent) {
return super.isValidParent(parent) &&
- SymbolType.CLASS.isValidParent(symbolMgr.getProgram(), parent, address, isExternal());
+ SymbolType.CLASS.isValidParent(symbolMgr.getProgram(), parent, address);
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/CodeSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/CodeSymbol.java
index 7f34f90017..c56bb86d4d 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/CodeSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/CodeSymbol.java
@@ -152,7 +152,7 @@ public class CodeSymbol extends MemorySymbol {
@Override
public boolean isValidParent(Namespace parent) {
return super.isValidParent(parent) &&
- SymbolType.LABEL.isValidParent(symbolMgr.getProgram(), parent, address, isExternal());
+ SymbolType.LABEL.isValidParent(symbolMgr.getProgram(), parent, address);
}
@Override
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/FunctionSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/FunctionSymbol.java
index 3d2d745012..c92bb2042f 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/FunctionSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/FunctionSymbol.java
@@ -23,8 +23,7 @@ import db.DBRecord;
import ghidra.program.database.external.ExternalManagerDB;
import ghidra.program.database.function.FunctionManagerDB;
import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Function;
+import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.util.FunctionReturnTypeFieldLocation;
import ghidra.program.util.ProgramLocation;
@@ -81,6 +80,7 @@ public class FunctionSymbol extends MemorySymbol {
Symbol parentSymbol = getParentSymbol();
String extOrigImportName = null;
Address extProgramAddr = null;
+ Library library = getLibrary();
if (isExternal()) {
// preserve external data
extOrigImportName = getExternalOriginalImportedName();
@@ -107,8 +107,9 @@ public class FunctionSymbol extends MemorySymbol {
// does not mean that we want to lose the function name (that is our policy).
Symbol newSymbol;
if (isExternal()) {
- newSymbol = symbolMgr.createExternalCodeSymbol(address, symName, namespace,
- source, extOrigImportName, extProgramAddr);
+ newSymbol =
+ symbolMgr.createExternalCodeSymbol(library, address, symName, namespace,
+ source, extOrigImportName, extProgramAddr);
}
else {
newSymbol = symbolMgr.createLabel(address, symName, namespace, source);
@@ -161,7 +162,7 @@ public class FunctionSymbol extends MemorySymbol {
@Override
public boolean isValidParent(Namespace parent) {
return super.isValidParent(parent) && SymbolType.FUNCTION
- .isValidParent(symbolMgr.getProgram(), parent, address, isExternal());
+ .isValidParent(symbolMgr.getProgram(), parent, address);
}
@Override
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/GhidraClassDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/GhidraClassDB.java
index e7c0bf14b0..a574ac7382 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/GhidraClassDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/GhidraClassDB.java
@@ -48,11 +48,6 @@ class GhidraClassDB implements GhidraClass {
return symbol;
}
- @Override
- public boolean isExternal() {
- return symbol.isExternal();
- }
-
/**
* @see ghidra.program.model.symbol.Namespace#getName()
*/
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryDB.java
index 8cd76ad8c4..d54b5ae949 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryDB.java
@@ -15,12 +15,8 @@
*/
package ghidra.program.database.symbol;
-import ghidra.program.model.address.AddressSetView;
-import ghidra.program.model.listing.CircularDependencyException;
import ghidra.program.model.listing.Library;
-import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
-import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
/**
@@ -55,21 +51,6 @@ class LibraryDB implements Library {
return symbol.getID();
}
- @Override
- public Namespace getParentNamespace() {
- return symbol.getParentNamespace();
- }
-
- @Override
- public AddressSetView getBody() {
- return namespaceMgr.getAddressSet(this);
- }
-
- @Override
- public String getName(boolean includeNamespacePath) {
- return symbol.getName(includeNamespacePath);
- }
-
@Override
public int hashCode() {
return symbol.hashCode();
@@ -88,12 +69,6 @@ class LibraryDB implements Library {
return symbol == lib.symbol;
}
- @Override
- public void setParentNamespace(Namespace parentNamespace)
- throws DuplicateNameException, InvalidInputException, CircularDependencyException {
- symbol.setNamespace(parentNamespace);
- }
-
@Override
public String getAssociatedProgramPath() {
return symbol.getExternalLibraryPath();
@@ -104,11 +79,6 @@ class LibraryDB implements Library {
symbol.setExternalLibraryPath(programPath);
}
- @Override
- public boolean isExternal() {
- return true;
- }
-
@Override
public String toString() {
return getName();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibrarySymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibrarySymbol.java
index 55aaf6107e..d07e602c80 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibrarySymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibrarySymbol.java
@@ -146,7 +146,7 @@ public class LibrarySymbol extends SymbolDB implements Comparable<LibrarySymbol>
@Override
public boolean isValidParent(Namespace parent) {
return super.isValidParent(parent) &&
- SymbolType.LIBRARY.isValidParent(symbolMgr.getProgram(), parent, address, isExternal());
+ SymbolType.LIBRARY.isValidParent(symbolMgr.getProgram(), parent, address);
}
/**
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryUpgrader.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryUpgrader.java
new file mode 100644
index 0000000000..d321c4a6fd
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/LibraryUpgrader.java
@@ -0,0 +1,221 @@
+/* ###
+ * 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.program.database.symbol;
+
+import java.io.IOException;
+import java.util.*;
+
+import db.DBRecord;
+import db.RecordIterator;
+import ghidra.program.model.symbol.Namespace;
+import ghidra.program.model.symbol.SymbolType;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
+
+/**
+ * Helper class for upgrading the records in the SymbolDatabaseAdapter when upgrading
+ * to version 6. This version is where libraries are no longer considered namespaces. This
+ * upgrade re-parents all symbols and namespaces that have a library as their parent namespace to
+ * instead be parented to the global namespace. When promoting a namespace symbol, it may conflict
+ * with an existing namespace already at the promoted level. In this case it will use the existing
+ * namespace, possibly upgrading a generic namespace to a class namespace.
+ * <P>
+ * Also, sets a new library field in the symbol record for all external symbols.
+ */
+public class LibraryUpgrader {
+
+ private SymbolDatabaseAdapter adapter;
+ private TaskMonitor monitor;
+ private Map<Long, SymbolInfo> symbolMap = new HashMap<>();
+ private Set<Long> libraryIds = new HashSet<>();
+ private Set<Long> externalNamespaces = new HashSet<>();
+ private Map<String, SymbolInfo> nonExternalNamespaceMap = new HashMap<>();
+ private Map<Long, Long> resolvedNamespaces = new HashMap<>();
+ private List<Long> forRemoval = new ArrayList<>();
+
+ public LibraryUpgrader(SymbolDatabaseAdapter adapter, TaskMonitor monitor) {
+ this.adapter = adapter;
+ this.monitor = monitor;
+ }
+
+ public void update() throws IOException, CancelledException {
+ createSymbolMapping(); // create in memory mapping
+ prepareNamespaces(); // create namespace name mapping and find external namespaces
+ fixupExternalNamespaces(); // resolve external namespaces to non external namespaces
+ reparentExternalSymbols(); // reparent all external symbols based on namespace re-mapping
+ updateFunctionAndLabelSymbolsWithLibraryId(); // sets the library field for external symbols
+ removeMergedNamespaces(); // removes any namespaces that are no longer used because they
+ // were merged into another existing namespace.
+
+ }
+
+ private void removeMergedNamespaces() throws IOException {
+ for (Long key : forRemoval) {
+ adapter.removeSymbol(key);
+ }
+ }
+
+ private void reparentExternalSymbols() throws IOException, CancelledException {
+ for (SymbolInfo symbol : symbolMap.values()) {
+ monitor.checkCancelled();
+ if (resolvedNamespaces.containsKey(symbol.parentId)) {
+ updateParentNamespace(symbol);
+ }
+ }
+ }
+
+ private void updateParentNamespace(SymbolInfo symbol) throws IOException {
+ long newParentId = resolvedNamespaces.get(symbol.parentId);
+ DBRecord record = adapter.getSymbolRecord(symbol.id);
+ record.setLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL, newParentId);
+ adapter.updateSymbolRecord(record);
+ }
+
+ private void fixupExternalNamespaces() throws IOException, CancelledException {
+
+ // first all library namespaces will resolve to the global namespace
+ for (Long id : libraryIds) {
+ resolvedNamespaces.put(id, Namespace.GLOBAL_NAMESPACE_ID);
+ }
+
+ for (Long id : externalNamespaces) {
+ monitor.checkCancelled();
+ resolveNamespace(id);
+ }
+
+ }
+
+ private long resolveNamespace(Long id) throws IOException {
+
+ if (resolvedNamespaces.containsKey(id)) {
+ return resolvedNamespaces.get(id); // already resolved
+ }
+
+ SymbolInfo symbol = symbolMap.get(id);
+ long resolvedParentId = resolveNamespace(symbol.parentId);
+ String myPath = getNamespacePath(symbol.name, resolvedParentId);
+ SymbolInfo conflict = nonExternalNamespaceMap.get(myPath);
+ if (conflict == null) {
+ // we can keep this namespace as it is, just mark it resolved
+ resolvedNamespaces.put(id, id);
+ return id;
+ }
+ if (conflict.type == SymbolType.NAMESPACE && symbol.type == SymbolType.CLASS) {
+ upgradeType(conflict, SymbolType.CLASS);
+ }
+ resolvedNamespaces.put(id, conflict.id);
+ forRemoval.add(id);
+ return conflict.id;
+ }
+
+ private String getNamespacePath(String name, long parentId) {
+ if (parentId == Namespace.GLOBAL_NAMESPACE_ID) {
+ return name;
+ }
+ SymbolInfo parent = symbolMap.get(parentId);
+ String parentPath = getNamespacePath(parent);
+ return parentPath + "::" + name;
+ }
+
+ private String getNamespacePath(SymbolInfo symbol) {
+ if (symbol.parentId == Namespace.GLOBAL_NAMESPACE_ID) {
+ return symbol.name;
+ }
+ SymbolInfo parent = symbolMap.get(symbol.parentId);
+ return getNamespacePath(parent) + "::" + symbol.name;
+ }
+
+ private void upgradeType(SymbolInfo symbol, SymbolType type) throws IOException {
+ DBRecord record = adapter.getSymbolRecord(symbol.id);
+ record.setByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL, type.getID());
+ adapter.updateSymbolRecord(record);
+ }
+
+ private void updateFunctionAndLabelSymbolsWithLibraryId()
+ throws IOException, CancelledException {
+
+ for (SymbolInfo symbol : symbolMap.values()) {
+ monitor.checkCancelled();
+ if (symbol.type == SymbolType.FUNCTION || symbol.type == SymbolType.LABEL) {
+ // these are the only two types than need to have the new library field set in
+ // their database records
+ SymbolInfo library = getLibrarySymbolContaining(symbol);
+ if (library != null) {
+ updateSymbolWithLibraryInfo(symbol, library);
+ }
+ }
+ // all other symbols types should not be affected by this upgrade
+ }
+ }
+
+ private void prepareNamespaces() throws CancelledException {
+ for (SymbolInfo symbol : symbolMap.values()) {
+ monitor.checkCancelled();
+ if (symbol.type == SymbolType.NAMESPACE || symbol.type == SymbolType.CLASS) {
+ if (isExternal(symbol)) {
+ // track namespaces that we need to fixup
+ externalNamespaces.add(symbol.id);
+ }
+ else {
+ // otherwise create a mapping to use for resolving external namespaces
+ nonExternalNamespaceMap.put(getNamespacePath(symbol), symbol);
+ }
+ }
+ }
+ }
+
+ private void updateSymbolWithLibraryInfo(SymbolInfo symbol, SymbolInfo library)
+ throws IOException {
+ DBRecord record = adapter.getSymbolRecord(symbol.id);
+ record.setLongValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL, library.id);
+ adapter.updateSymbolRecord(record);
+ }
+
+ private boolean isExternal(SymbolInfo symbol) {
+ return getLibrarySymbolContaining(symbol) != null;
+ }
+
+ private SymbolInfo getLibrarySymbolContaining(SymbolInfo symbol) {
+ long id = symbol.parentId;
+ while (id != Namespace.GLOBAL_NAMESPACE_ID) {
+ if (libraryIds.contains(id)) {
+ return symbolMap.get(id);
+ }
+ SymbolInfo parentInfo = symbolMap.get(id);
+ id = parentInfo.parentId;
+ }
+ return null;
+ }
+
+ private void createSymbolMapping() throws IOException, CancelledException {
+ RecordIterator symbols = adapter.getSymbols();
+ while (symbols.hasNext()) {
+ monitor.checkCancelled();
+ DBRecord record = symbols.next();
+ long key = record.getKey();
+ String name = record.getString(SymbolDatabaseAdapter.SYMBOL_NAME_COL);
+ byte typeID = record.getByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL);
+ SymbolType type = SymbolType.getSymbolType(typeID);
+ long parentId = record.getLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL);
+ symbolMap.put(key, new SymbolInfo(key, name, parentId, type));
+ if (type == SymbolType.LIBRARY) {
+ libraryIds.add(key);
+ }
+ }
+ }
+
+ record SymbolInfo(long id, String name, long parentId, SymbolType type) {}
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/MemorySymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/MemorySymbol.java
index 06d49f04c2..173818cea6 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/MemorySymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/MemorySymbol.java
@@ -19,10 +19,15 @@ import java.util.ArrayList;
import java.util.Objects;
import db.DBRecord;
+import db.Field;
+import ghidra.program.database.ProgramDB;
import ghidra.program.database.external.ExternalLocationDB;
import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.symbol.*;
+import ghidra.program.util.ProgramEvent;
import ghidra.util.Lock.Closeable;
+import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
import ghidra.util.task.UnknownProgressWrappingTaskMonitor;
@@ -338,24 +343,21 @@ public abstract class MemorySymbol extends SymbolDB {
* @param externalProgramAddress the external Program Address which corresponds to the
* externally linked location (may be null).
* @param notify if true, a program change notification will be generated
- * @throws UnsupportedOperationException if symbol is neither an external {@link SymbolType#LABEL}
- * or {@link SymbolType#FUNCTION}.
+ * @throws InvalidInputException if invalid external program address specified
+ * @throws UnsupportedOperationException if symbol is not external.
*/
- public final void setExternalProgramAddress(Address externalProgramAddress, boolean notify) {
- SymbolType type = getSymbolType();
- if (!getAddress().isExternalAddress() ||
- (type != SymbolType.LABEL && type != SymbolType.FUNCTION)) {
+ public final void setExternalProgramAddress(Address externalProgramAddress, boolean notify)
+ throws InvalidInputException {
+ if (!isExternal()) {
throw new javax.help.UnsupportedOperationException(
"Symbol does not support: external program address");
}
- if (externalProgramAddress != null && !externalProgramAddress.isLoadedMemoryAddress()) {
- throw new IllegalArgumentException("Memory address required for external program");
- }
+
try (Closeable c = lock.write()) {
checkDeleted();
- if (record == null) {
- return;
- }
+
+ symbolMgr.checkExternalAddress(externalProgramAddress);
+
String addrStr =
externalProgramAddress != null ? externalProgramAddress.toString() : null;
String oldData = record.getString(SymbolDatabaseAdapter.SYMBOL_EXTERNAL_PROG_ADDR_COL);
@@ -369,9 +371,45 @@ public abstract class MemorySymbol extends SymbolDB {
}
}
- static void setExternalFields(DBRecord record, String originalImportName,
+ public void setLibrary(Library newLibrary) {
+ try (Closeable _ = lock.write()) {
+ if (!isExternal()) {
+ throw new UnsupportedOperationException("Can't set libary on non-external symbols");
+ }
+ symbolMgr.checkValidLibrary(newLibrary);
+ Library oldLibrary = getLibrary();
+ if (Objects.equals(newLibrary, oldLibrary)) {
+ return;
+ }
+ checkDeleted();
+ record.setLongValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL, newLibrary.getID());
+ ProgramDB program = symbolMgr.getProgram();
+ program.symbolChanged(this, ProgramEvent.SYMBOL_LIBRARY_CHANGED, getAddress(), this,
+ oldLibrary, newLibrary);
+ }
+ }
+
+ @Override
+ public Library getLibrary() {
+ try (Closeable _ = lock.read()) {
+ refreshIfNeeded();
+ if (record == null) {
+ return null;
+ }
+ Field field = record.getFieldValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL);
+ if (field.isNull()) {
+ return null;
+ }
+ long libraryId = field.getLongValue();
+ Symbol symbol = symbolMgr.getSymbol(libraryId);
+ return (Library) symbol.getObject();
+ }
+ }
+
+ static void setExternalFields(DBRecord record, Library library, String originalImportName,
Address externalProgramAddress) {
String addrStr = externalProgramAddress != null ? externalProgramAddress.toString() : null;
+ record.setLongValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL, library.getID());
record.setString(SymbolDatabaseAdapter.SYMBOL_EXTERNAL_PROG_ADDR_COL, addrStr);
record.setString(SymbolDatabaseAdapter.SYMBOL_ORIGINAL_IMPORTED_NAME_COL,
originalImportName);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceDB.java
index 16d8680da4..64e1de7d26 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceDB.java
@@ -99,10 +99,4 @@ class NamespaceDB implements Namespace {
public String toString() {
return getName(true);
}
-
- @Override
- public boolean isExternal() {
- return symbol.isExternal();
- }
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceSymbol.java
index 8caf78f856..259b00bd23 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/NamespaceSymbol.java
@@ -17,7 +17,8 @@ package ghidra.program.database.symbol;
import db.DBRecord;
import ghidra.program.model.address.Address;
-import ghidra.program.model.symbol.*;
+import ghidra.program.model.symbol.Namespace;
+import ghidra.program.model.symbol.SymbolType;
import ghidra.util.Lock.Closeable;
/**
@@ -43,8 +44,7 @@ public class NamespaceSymbol extends SymbolDB {
@Override
public boolean isExternal() {
- Symbol parentSymbol = getParentSymbol();
- return parentSymbol != null ? parentSymbol.isExternal() : false;
+ return false;
}
@Override
@@ -69,6 +69,6 @@ public class NamespaceSymbol extends SymbolDB {
public boolean isValidParent(Namespace parent) {
// TODO: Not sure what other constraints should be placed on namespace movement
return super.isValidParent(parent) && SymbolType.NAMESPACE
- .isValidParent(symbolMgr.getProgram(), parent, address, isExternal());
+ .isValidParent(symbolMgr.getProgram(), parent, address);
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/PreV6SymbolDatabaseAdapter.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/PreV6SymbolDatabaseAdapter.java
new file mode 100644
index 0000000000..042a891783
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/PreV6SymbolDatabaseAdapter.java
@@ -0,0 +1,162 @@
+/* ###
+ * 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.program.database.symbol;
+
+import java.io.IOException;
+import java.util.Set;
+
+import db.*;
+import ghidra.program.model.address.*;
+import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.SymbolType;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
+
+/**
+ * Base class for all adapters before version 6. Since versions prior to version 6 do
+ * not support read-only access, the only methods implemented are those required for the
+ * upgrade. This class stubs out all unnecessary methods so that subclasses just need to
+ * implement the few required methods.
+ */
+public abstract class PreV6SymbolDatabaseAdapter extends SymbolDatabaseAdapter {
+
+ @Override
+ final DBRecord createSymbolRecord(String name, long namespaceID, Address address,
+ SymbolType symbolType, boolean isPrimary, SourceType source) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final DBRecord getSymbolRecord(long symbolID) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final void removeSymbol(long symbolID) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final boolean hasSymbol(Address addr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final Field[] getSymbolIDs(Address addr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByAddress(Address startAddr, boolean forward)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final void updateSymbolRecord(DBRecord record) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbols(Address start, Address end, boolean forward)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getPrimarySymbols(AddressSetView set, boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final DBRecord getPrimarySymbol(Address address) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final void moveAddress(Address oldAddr, Address newAddr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
+ throws CancelledException, IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByNamespace(long id) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByName(String name) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByLibrary(long libraryID) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator scanSymbolsByName(String startName) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getExternalSymbolsByOriginalImportName(String extLabel)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final DBRecord getSymbolRecord(Address address, String name, long namespaceId)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final Address getMaxSymbolAddress(AddressSpace space) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ final Table getTable() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDB.java
index 54bde44ee7..c96455e406 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDB.java
@@ -28,8 +28,7 @@ import ghidra.program.database.external.ExternalManagerDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.GlobalNamespace;
import ghidra.program.model.lang.Register;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.util.ProgramEvent;
import ghidra.util.Lock;
@@ -84,9 +83,9 @@ public abstract class SymbolDB extends DbObject implements Symbol {
rec = symbolMgr.getSymbolRecord(key);
}
if (rec == null) {
- return false;
+ return false;
}
- byte currentTypeValue = record.getByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL);
+ byte currentTypeValue = record.getByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL);
byte newTypeValue = rec.getByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL);
if (newTypeValue != currentTypeValue) {
return false;
@@ -296,6 +295,9 @@ public abstract class SymbolDB extends DbObject implements Symbol {
boolean checkForDuplicates)
throws DuplicateNameException, InvalidInputException, CircularDependencyException {
+ if (newNamespace == null) {
+ newNamespace = symbolMgr.getProgram().getGlobalNamespace();
+ }
try (Closeable c = lock.write()) {
checkDeleted();
checkEditOK();
@@ -369,7 +371,7 @@ public abstract class SymbolDB extends DbObject implements Symbol {
ExternalManagerDB externalManager = symbolMgr.getExternalManager();
ExternalLocationDB externalLocation =
(ExternalLocationDB) externalManager.getExternalLocation(this);
- externalLocation.saveOriginalNameIfNeeded(oldNamespace, oldName, oldSource);
+ externalLocation.saveOriginalNameIfNeeded(oldName, oldSource);
}
symbolMgr.symbolRenamed(this, oldName);
if (dynamicallyRenamedSymbols != null) {
@@ -498,6 +500,11 @@ public abstract class SymbolDB extends DbObject implements Symbol {
return symbolMgr.getProgram().getGlobalNamespace();
}
+ @Override
+ public Library getLibrary() {
+ return null;
+ }
+
@Override
public Symbol getParentSymbol() {
try (Closeable c = lock.read()) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapter.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapter.java
index 9c3cdf4338..04a972eed7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapter.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapter.java
@@ -37,25 +37,28 @@ import ghidra.util.task.TaskMonitor;
abstract class SymbolDatabaseAdapter {
static final String SYMBOL_TABLE_NAME = "Symbols";
- static final int SYMBOL_NAME_COL = 0;
- static final int SYMBOL_ADDR_COL = 1;
- static final int SYMBOL_PARENT_ID_COL = 2;
- static final int SYMBOL_TYPE_COL = 3;
- static final int SYMBOL_FLAGS_COL = 4;
+ //@formatter:off
+ static final int SYMBOL_NAME_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_NAME_COL;
+ static final int SYMBOL_ADDR_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_ADDR_COL;
+ static final int SYMBOL_PARENT_ID_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_PARENT_ID_COL;
+ static final int SYMBOL_TYPE_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_TYPE_COL;
+ static final int SYMBOL_FLAGS_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_FLAGS_COL;
// Sparse fields - the following fields are not always applicable so they are optional and
// don't consume space in the database if they aren't used.
- static final int SYMBOL_HASH_COL = 5;
- static final int SYMBOL_PRIMARY_COL = 6;
- static final int SYMBOL_DATATYPE_COL = 7;
- static final int SYMBOL_VAROFFSET_COL = 8;
- static final int SYMBOL_ORIGINAL_IMPORTED_NAME_COL = 9;
- static final int SYMBOL_EXTERNAL_PROG_ADDR_COL = 10;
- static final int SYMBOL_COMMENT_COL = 11;
- static final int SYMBOL_LIBPATH_COL = 12;
- static final int SYMBOL_LIB_ORDINAL_COL = 13;
-
- static final Schema SYMBOL_SCHEMA = SymbolDatabaseAdapterV5.V5_SYMBOL_SCHEMA;
+ static final int SYMBOL_HASH_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_HASH_COL;
+ static final int SYMBOL_PRIMARY_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_PRIMARY_COL;
+ static final int SYMBOL_DATATYPE_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_DATATYPE_COL;
+ static final int SYMBOL_VAROFFSET_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_VAROFFSET_COL;
+ static final int SYMBOL_ORIGINAL_IMPORTED_NAME_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_ORIGINAL_IMPORTED_NAME_COL;
+ static final int SYMBOL_EXTERNAL_PROG_ADDR_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_EXTERNAL_PROG_ADDR_COL;
+ static final int SYMBOL_COMMENT_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_COMMENT_COL;
+ static final int SYMBOL_LIBPATH_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_LIBPATH_COL;
+ static final int SYMBOL_LIB_ORDINAL_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_LIB_ORDINAL_COL;
+ static final int SYMBOL_LIBRARY_ID_COL = SymbolDatabaseAdapterV6.V6_SYMBOL_LIBRARY_ID_COL;
+ //@formatter:on
+
+ static final Schema SYMBOL_SCHEMA = SymbolDatabaseAdapterV6.V6_SYMBOL_SCHEMA;
// Bits 0, 1 and 3 are used for the source of the symbol.
// NOTE: On the next V5 adapter revision the source type bits should be made contiguous
@@ -80,6 +83,8 @@ abstract class SymbolDatabaseAdapter {
static final int SYMBOL_TYPE_LOCAL_VAR = SymbolType.LOCAL_VAR.getID();
static final int SYMBOL_TYPE_GLOBAL_VAR = SymbolType.GLOBAL_VAR.getID();
+ private static final int LIBRARY_UPGRADE_VERSION = 6;
+
// TODO: NEXT UPGRADE: remove all variable/parameter symbols with NO_ADDRESS
/**
@@ -98,11 +103,11 @@ abstract class SymbolDatabaseAdapter {
throws VersionException, CancelledException, IOException {
if (openMode == OpenMode.CREATE) {
- return new SymbolDatabaseAdapterV5(dbHandle, addrMap, true);
+ return new SymbolDatabaseAdapterV6(dbHandle, addrMap, true);
}
try {
- SymbolDatabaseAdapter adapter = new SymbolDatabaseAdapterV5(dbHandle, addrMap, false);
+ SymbolDatabaseAdapter adapter = new SymbolDatabaseAdapterV6(dbHandle, addrMap, false);
return adapter;
}
catch (VersionException e) {
@@ -113,7 +118,7 @@ abstract class SymbolDatabaseAdapter {
if (openMode == OpenMode.UPGRADE) {
adapter = upgrade(dbHandle, addrMap, adapter, monitor);
}
- else if (adapter instanceof SymbolDatabaseAdapterV0) {
+ else if (adapter.getVersion() < SymbolDatabaseAdapterV6.VERSION) {
// Upgrade required - read-only use not supported
throw e;
}
@@ -124,6 +129,13 @@ abstract class SymbolDatabaseAdapter {
private static SymbolDatabaseAdapter findReadOnlyAdapter(DBHandle handle, AddressMap addrMap)
throws VersionException {
+ try {
+ return new SymbolDatabaseAdapterV5(handle, addrMap.getOldAddressMap());
+ }
+ catch (VersionException e) {
+ // failed try older version
+ }
+
try {
return new SymbolDatabaseAdapterV4(handle, addrMap.getOldAddressMap());
}
@@ -175,9 +187,13 @@ abstract class SymbolDatabaseAdapter {
SymbolDatabaseAdapter tmpAdapter =
copyToTempAndFixupRecords(addrMap, oldAdapter, tmpHandle, monitor);
+ if (oldAdapter.getVersion() < LIBRARY_UPGRADE_VERSION) {
+ LibraryUpgrader updater = new LibraryUpgrader(tmpAdapter, monitor);
+ updater.update();
+ }
dbHandle.deleteTable(SYMBOL_TABLE_NAME);
- SymbolDatabaseAdapter newAdapter = new SymbolDatabaseAdapterV5(dbHandle, addrMap, true);
+ SymbolDatabaseAdapter newAdapter = new SymbolDatabaseAdapterV6(dbHandle, addrMap, true);
copyTempToNewAdapter(tmpAdapter, newAdapter, monitor);
return newAdapter;
@@ -187,6 +203,11 @@ abstract class SymbolDatabaseAdapter {
}
}
+ /**
+ * {@return the symbol adapter version for this instance}
+ */
+ protected abstract int getVersion();
+
private static SymbolDatabaseAdapter copyToTempAndFixupRecords(AddressMap addrMap,
SymbolDatabaseAdapter oldAdapter, DBHandle tmpHandle, TaskMonitor monitor)
throws IOException, CancelledException, VersionException {
@@ -203,7 +224,7 @@ abstract class SymbolDatabaseAdapter {
((SymbolDatabaseAdapterV0) oldAdapter).extractLocalSymbols(tmpHandle, monitor);
}
- SymbolDatabaseAdapterV5 tmpAdapter = new SymbolDatabaseAdapterV5(tmpHandle, addrMap, true);
+ SymbolDatabaseAdapterV6 tmpAdapter = new SymbolDatabaseAdapterV6(tmpHandle, addrMap, true);
RecordIterator iter = oldAdapter.getSymbols();
while (iter.hasNext()) {
monitor.checkCancelled();
@@ -428,6 +449,16 @@ abstract class SymbolDatabaseAdapter {
*/
abstract RecordIterator getSymbolsByName(String name) throws IOException;
+ /**
+ * Return a record iterator over all symbols that have the given libraryID set in
+ * their library.
+ * @param libraryID the id of the library to find symbols for
+ * @return a record iterator over all symbols that have the given libraryID set in
+ * their library
+ * @throws IOException if a database io error occurs
+ */
+ abstract RecordIterator getSymbolsByLibrary(long libraryID) throws IOException;
+
/**
* Scan symbols lexicographically by name starting from the given name
* <p>
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV0.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV0.java
index 06742454ff..4c0da48a82 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV0.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV0.java
@@ -16,14 +16,10 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.Set;
import db.*;
import ghidra.framework.data.OpenMode;
-import ghidra.program.database.map.AddressIndexPrimaryKeyIterator;
import ghidra.program.database.map.AddressMap;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.model.address.*;
import ghidra.program.model.symbol.*;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
@@ -37,7 +33,7 @@ import ghidra.util.task.TaskMonitor;
* The upgrade of this version may also add additional Function symbols for which there
* is no corresponding label symbol.
*/
-class SymbolDatabaseAdapterV0 extends SymbolDatabaseAdapter {
+class SymbolDatabaseAdapterV0 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
/* Do not remove the following commented out schema! It shows the version 0 symbol table schema. */
// static final Schema SYMBOL_SCHEMA = new Schema(0, "Key",
@@ -47,7 +43,7 @@ class SymbolDatabaseAdapterV0 extends SymbolDatabaseAdapter {
// new String[] {"Name", "Is Dynamic", "Is Local",
// "Is Primary", "Address"});
- private static final int SYMBOL_VERSION = 0;
+ private static final int VERSION = 0;
private static final int V0_SYMBOL_NAME_COL = 0;
private static final int V0_SYMBOL_IS_DYNAMIC_COL = 1;
@@ -70,7 +66,7 @@ class SymbolDatabaseAdapterV0 extends SymbolDatabaseAdapter {
if (symbolTable == null) {
throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
+ if (symbolTable.getSchema().getVersion() != VERSION) {
throw new VersionException(false);
}
}
@@ -107,7 +103,8 @@ class SymbolDatabaseAdapterV0 extends SymbolDatabaseAdapter {
return symbolTable.getKey();
}
- private DBRecord convertV0Record(DBRecord record) {
+ @Override
+ public DBRecord translateRecord(DBRecord record) {
if (record == null) {
return null;
}
@@ -146,214 +143,18 @@ class SymbolDatabaseAdapterV0 extends SymbolDatabaseAdapter {
}
@Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- void removeSymbol(long symbolID) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- boolean hasSymbol(Address addr) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- throw new UnsupportedOperationException();
+ RecordIterator getSymbols() throws IOException {
+ RecordIterator it = symbolTable.iterator();
+ return new TranslatedRecordIterator(it, this);
}
@Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return convertV0Record(symbolTable.getRecord(symbolID));
+ protected int getVersion() {
+ return VERSION;
}
@Override
int getSymbolCount() {
return symbolTable.getRecordCount();
}
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- return new V0ConvertedRecordIterator(new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, V0_SYMBOL_ADDR_COL, addrMap, forward)));
- }
-
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- return new V0ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V0_SYMBOL_ADDR_COL, addrMap, startAddr, forward)));
- }
-
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getSymbols() throws IOException {
- return new V0ConvertedRecordIterator(symbolTable.iterator());
- }
-
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- return new V0ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V0_SYMBOL_ADDR_COL, addrMap, start, end, forward)));
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- return new V0ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V0_SYMBOL_ADDR_COL, addrMap, set, forward)));
- }
-
- @Override
- RecordIterator getPrimarySymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, set, forward));
-
- return getPrimaryFilterRecordIterator(new V0ConvertedRecordIterator(it));
- }
-
- @Override
- DBRecord getPrimarySymbol(Address address) throws IOException {
- RecordIterator it = getPrimarySymbols(new AddressSet(address, address), true);
- if (it.hasNext()) {
- return it.next();
- }
- return null;
- }
-
- @Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- return EmptyRecordIterator.INSTANCE; // External symbols were not supported
- }
-
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- return EmptyRecordIterator.INSTANCE; // External symbols were not supported
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- if (id == Namespace.GLOBAL_NAMESPACE_ID) {
- return new V0ConvertedRecordIterator(symbolTable.iterator());
- }
- return null;
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField val = new StringField(name);
- return new V0ConvertedRecordIterator(
- symbolTable.indexIterator(V0_SYMBOL_NAME_COL, val, val, true));
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField val = new StringField(startName);
- return new V0ConvertedRecordIterator(
- symbolTable.indexIterator(V0_SYMBOL_NAME_COL, val, null, true));
- }
-
- private class V0ConvertedRecordIterator implements RecordIterator {
-
- private RecordIterator symIter;
- private DBRecord rec;
-
- /**
- * Construct a symbol filtered record iterator
- * @param symIter the {@link RecordIterator} to wrap so that records are adapter to new schema
- */
- V0ConvertedRecordIterator(RecordIterator symIter) {
- this.symIter = symIter;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- if (rec == null) {
- while (rec == null && symIter.hasNext()) {
- rec = symIter.next();
- if (rec.getBooleanValue(V0_SYMBOL_LOCAL_COL) ||
- rec.getBooleanValue(V0_SYMBOL_IS_DYNAMIC_COL)) {
- rec = null;
- }
- }
- }
- return rec != null;
- }
-
- @Override
- public boolean hasPrevious() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public DBRecord next() throws IOException {
- if (hasNext()) {
- DBRecord r = rec;
- rec = null;
- return convertV0Record(r);
- }
- return null;
- }
-
- @Override
- public DBRecord previous() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean delete() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- }
-
- @Override
- Table getTable() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- RecordIterator symbolsByName = getSymbolsByName(name);
- return getNameAndNamespaceFilterIterator(name, id, symbolsByName);
- }
-
- @Override
- DBRecord getSymbolRecord(Address address, String name, long id) throws IOException {
- StringField value = new StringField(name);
- RecordIterator it = symbolTable.indexIterator(SYMBOL_NAME_COL, value, value, true);
- long addressKey = addrMap.getKey(address, false);
- RecordIterator filtered = getNameNamespaceAddressFilterIterator(name, id, addressKey, it);
- if (filtered.hasNext()) {
- return filtered.next();
- }
- return null;
- }
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV1.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV1.java
index 61500e88bc..c5a75a137a 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV1.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV1.java
@@ -16,22 +16,17 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.Set;
import db.*;
-import ghidra.program.database.map.AddressIndexPrimaryKeyIterator;
import ghidra.program.database.map.AddressMap;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.model.address.*;
+import ghidra.program.model.address.Address;
import ghidra.program.model.symbol.*;
-import ghidra.util.exception.CancelledException;
import ghidra.util.exception.VersionException;
-import ghidra.util.task.TaskMonitor;
/**
* SymbolDatabaseAdapter for version 1
*/
-class SymbolDatabaseAdapterV1 extends SymbolDatabaseAdapter {
+class SymbolDatabaseAdapterV1 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
/* Do not remove the following commented out schema! It shows the version 1 symbol table schema. */
// static final Schema SYMBOL_SCHEMA = new Schema(1, "Key",
@@ -41,7 +36,7 @@ class SymbolDatabaseAdapterV1 extends SymbolDatabaseAdapter {
// new String[] {"Name", "Address", "Parent", "Symbol Type",
// "SymbolData1", "SymbolData2", "Comment"});
- private static final int SYMBOL_VERSION = 1;
+ private static final int VERSION = 1;
private static final int V1_SYMBOL_NAME_COL = 0;
private static final int V1_SYMBOL_ADDR_COL = 1;
@@ -61,9 +56,9 @@ class SymbolDatabaseAdapterV1 extends SymbolDatabaseAdapter {
if (symbolTable == null) {
throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
+ if (symbolTable.getSchema().getVersion() != VERSION) {
int version = symbolTable.getSchema().getVersion();
- if (version < SYMBOL_VERSION) {
+ if (version < VERSION) {
throw new VersionException(true);
}
throw new VersionException(VersionException.NEWER_VERSION, false);
@@ -71,45 +66,7 @@ class SymbolDatabaseAdapterV1 extends SymbolDatabaseAdapter {
}
@Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- void removeSymbol(long symbolID) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- boolean hasSymbol(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY) {
- return false;
- }
- return symbolTable.hasRecord(new LongField(key), V1_SYMBOL_ADDR_COL);
- }
-
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY) {
- return Field.EMPTY_ARRAY;
- }
- return symbolTable.findRecords(new LongField(key), V1_SYMBOL_ADDR_COL);
- }
-
- @Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return convertV1Record(symbolTable.getRecord(symbolID));
- }
-
- /**
- * Returns a record matching the current data base schema from the version 1 record.
- * @param recV1 the record matching the version 1 schema.
- * @return a current symbol record.
- */
- private DBRecord convertV1Record(DBRecord record) {
+ public DBRecord translateRecord(DBRecord record) {
if (record == null) {
return null;
}
@@ -174,145 +131,19 @@ class SymbolDatabaseAdapterV1 extends SymbolDatabaseAdapter {
return rec;
}
- @Override
- int getSymbolCount() {
- return symbolTable.getRecordCount();
- }
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- return new V1ConvertedRecordIterator(new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, V1_SYMBOL_ADDR_COL, addrMap, forward)));
- }
-
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- return new V1ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V1_SYMBOL_ADDR_COL, addrMap, startAddr, forward)));
- }
-
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- throw new UnsupportedOperationException();
- }
-
@Override
RecordIterator getSymbols() throws IOException {
- return new V1ConvertedRecordIterator(symbolTable.iterator());
- }
-
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- return new V1ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V1_SYMBOL_ADDR_COL, addrMap, start, end, forward)));
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- return new V1ConvertedRecordIterator(
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V1_SYMBOL_ADDR_COL, addrMap, set, forward)));
+ RecordIterator it = symbolTable.iterator();
+ return new TranslatedRecordIterator(it, this);
}
@Override
- RecordIterator getPrimarySymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, set, forward));
-
- return getPrimaryFilterRecordIterator(new V1ConvertedRecordIterator(it));
- }
-
- @Override
- DBRecord getPrimarySymbol(Address address) throws IOException {
- RecordIterator it = getPrimarySymbols(new AddressSet(address, address), true);
- if (it.hasNext()) {
- return it.next();
- }
- return null;
+ protected int getVersion() {
+ return VERSION;
}
@Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- return EmptyRecordIterator.INSTANCE; // External symbols were not supported
- }
-
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- return EmptyRecordIterator.INSTANCE; // External symbols were not supported
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- LongField field = new LongField(id);
- return new V1ConvertedRecordIterator(
- symbolTable.indexIterator(V1_SYMBOL_PARENT_COL, field, field, true));
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField field = new StringField(name);
- return new V1ConvertedRecordIterator(
- symbolTable.indexIterator(V1_SYMBOL_NAME_COL, field, field, true));
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField val = new StringField(startName);
- return new V1ConvertedRecordIterator(
- symbolTable.indexIterator(V1_SYMBOL_NAME_COL, val, null, true));
- }
-
- private class V1ConvertedRecordIterator extends ConvertedRecordIterator {
-
- V1ConvertedRecordIterator(RecordIterator originalIterator) {
- super(originalIterator, false);
- }
-
- @Override
- protected DBRecord convertRecord(DBRecord record) {
- return convertV1Record(record);
- }
- }
-
- @Override
- Table getTable() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- RecordIterator symbolsByName = getSymbolsByName(name);
- return getNameAndNamespaceFilterIterator(name, id, symbolsByName);
- }
-
- @Override
- DBRecord getSymbolRecord(Address address, String name, long id) throws IOException {
- RecordIterator it = getSymbolsByName(name);
- long addressKey = addrMap.getKey(address, false);
- RecordIterator filtered = getNameNamespaceAddressFilterIterator(name, id, addressKey, it);
- if (filtered.hasNext()) {
- return filtered.next();
- }
- return null;
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
}
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV2.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV2.java
index eb4da55350..d94a80bcbe 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV2.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV2.java
@@ -16,22 +16,16 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.Set;
import db.*;
-import ghidra.program.database.map.*;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.model.address.*;
-import ghidra.program.model.symbol.SourceType;
+import ghidra.program.database.map.AddressMap;
import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.exception.CancelledException;
import ghidra.util.exception.VersionException;
-import ghidra.util.task.TaskMonitor;
/**
* SymbolDatabaseAdapter for version 2
*/
-class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
+class SymbolDatabaseAdapterV2 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
/* Do not remove the following commented out schema! It shows the version 2 symbol table schema. */
// static final Schema SYMBOL_SCHEMA = new Schema(2, "Key",
@@ -41,7 +35,7 @@ class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
// new String[] { "Name", "Address", "Parent", "Symbol Type", "SymbolData1", "SymbolData2",
// "SymbolData3", "Flags" });
- private static final int SYMBOL_VERSION = 2;
+ private static final int VERSION = 2;
private static final int V2_SYMBOL_NAME_COL = 0;
private static final int V2_SYMBOL_ADDR_COL = 1;
@@ -53,238 +47,27 @@ class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
private static final int V2_SYMBOL_FLAGS_COL = 7;
private Table symbolTable;
- private AddressMap addrMap;
SymbolDatabaseAdapterV2(DBHandle handle, AddressMap addrMap) throws VersionException {
- this.addrMap = addrMap;
symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
if (symbolTable == null) {
throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
+ if (symbolTable.getSchema().getVersion() != VERSION) {
int version = symbolTable.getSchema().getVersion();
- if (version < SYMBOL_VERSION) {
+ if (version < VERSION) {
throw new VersionException(true);
}
throw new VersionException(VersionException.NEWER_VERSION, false);
}
}
- @Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- void removeSymbol(long symbolID) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- boolean hasSymbol(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return false;
- }
- return symbolTable.hasRecord(new LongField(key), SYMBOL_ADDR_COL);
- }
-
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return Field.EMPTY_ARRAY;
- }
- return symbolTable.findRecords(new LongField(key), V2_SYMBOL_ADDR_COL);
- }
-
- @Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return convertV2Record(symbolTable.getRecord(symbolID));
- }
-
- @Override
- int getSymbolCount() {
- return symbolTable.getRecordCount();
- }
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- KeyToRecordIterator it = new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, V2_SYMBOL_ADDR_COL, addrMap, forward));
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V2_SYMBOL_ADDR_COL, addrMap, startAddr, forward));
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- throw new UnsupportedOperationException();
- }
-
@Override
RecordIterator getSymbols() throws IOException {
- return new V2ConvertedRecordIterator(symbolTable.iterator());
- }
-
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V2_SYMBOL_ADDR_COL, addrMap, start, end, forward));
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V2_SYMBOL_ADDR_COL, addrMap, set, forward));
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getPrimarySymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V2_SYMBOL_ADDR_COL, addrMap, set, forward));
-
- return getPrimaryFilterRecordIterator(new V2ConvertedRecordIterator(it));
- }
-
- @Override
- DBRecord getPrimarySymbol(Address address) throws IOException {
- RecordIterator it = getPrimarySymbols(new AddressSet(address, address), true);
- if (it.hasNext()) {
- return it.next();
- }
- return null;
- }
-
- @Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
- throw new UnsupportedOperationException();
- }
-
- private String getExternalStringData(DBRecord rec) {
- long addrKey = rec.getLongValue(V2_SYMBOL_ADDR_COL);
- Address addr = addrMap.decodeAddress(addrKey);
- if (addr == null || !addr.isExternalAddress()) {
- return null;
- }
- byte symbolTypeId = rec.getByteValue(V2_SYMBOL_TYPE_COL);
- if (symbolTypeId != SYMBOL_TYPE_FUNCTION && symbolTypeId != SYMBOL_TYPE_LABEL) {
- // NOTE: I don't think external functions were supported with this version
- return null;
- }
-
- return rec.getString(V2_SYMBOL_DATA3_COL);
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- if (extProgAddr == null) {
- return EmptyRecordIterator.INSTANCE;
- }
- String matchAddrStr = extProgAddr.toString();
- return new ConstrainedForwardRecordIterator(symbolTable.iterator(), rec -> {
- String str = getExternalStringData(rec);
- if (str != null) {
- int indexOf = str.indexOf(","); // [address][,importName]
- String addressString = indexOf >= 0 ? str.substring(0, indexOf) : str;
- if (matchAddrStr.equals(addressString)) {
- return convertV2Record(rec);
- }
- }
- return null;
- });
- }
+ RecordIterator it = symbolTable.iterator();
+ return new TranslatedRecordIterator(it, this);
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- return EmptyRecordIterator.INSTANCE;
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- LongField field = new LongField(id);
- RecordIterator it = symbolTable.indexIterator(V2_SYMBOL_PARENT_ID_COL, field, field, true);
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField field = new StringField(name);
- RecordIterator it = symbolTable.indexIterator(V2_SYMBOL_NAME_COL, field, field, true);
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField field = new StringField(startName);
- RecordIterator it = symbolTable.indexIterator(V2_SYMBOL_NAME_COL, field, null, true);
- return new V2ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- RecordIterator it = scanSymbolsByName(name);
- RecordIterator filtered = getNameAndNamespaceFilterIterator(name, id, it);
- return new V2ConvertedRecordIterator(filtered);
- }
-
- @Override
- DBRecord getSymbolRecord(Address address, String name, long id) throws IOException {
- RecordIterator it = scanSymbolsByName(name);
- long addressKey = addrMap.getKey(address, false);
- RecordIterator filtered = getNameNamespaceAddressFilterIterator(name, id, addressKey, it);
- if (filtered.hasNext()) {
- return filtered.next();
- }
- return null;
- }
-
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- if (space.isMemorySpace()) {
- AddressIndexKeyIterator addressKeyIterator = new AddressIndexKeyIterator(symbolTable,
- V2_SYMBOL_ADDR_COL, addrMap, space.getMinAddress(), space.getMaxAddress(), false);
- if (addressKeyIterator.hasNext()) {
- return addrMap.decodeAddress(addressKeyIterator.next());
- }
- }
- else {
- LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
- DBFieldIterator iterator =
- symbolTable.indexFieldIterator(null, max, false, V2_SYMBOL_ADDR_COL);
- if (iterator.hasPrevious()) {
- LongField val = (LongField) iterator.previous();
- Address addr = addrMap.decodeAddress(val.getLongValue());
- if (space.equals(addr.getAddressSpace())) {
- return addr;
- }
- }
- }
- return null;
- }
-
- @Override
- Table getTable() {
- return symbolTable;
}
/**
@@ -292,7 +75,8 @@ class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
* @param record the record matching the version 2 schema.
* @return a current symbol record.
*/
- private DBRecord convertV2Record(DBRecord record) {
+ @Override
+ public DBRecord translateRecord(DBRecord record) {
if (record == null) {
return null;
}
@@ -350,16 +134,13 @@ class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
return rec;
}
- private class V2ConvertedRecordIterator extends ConvertedRecordIterator {
-
- V2ConvertedRecordIterator(RecordIterator originalIterator) {
- super(originalIterator, false);
- }
-
- @Override
- protected DBRecord convertRecord(DBRecord record) {
- return convertV2Record(record);
- }
+ @Override
+ protected int getVersion() {
+ return VERSION;
}
+ @Override
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
+ }
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV3.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV3.java
index 8f2d5ffccc..852dbda1a2 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV3.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV3.java
@@ -16,19 +16,12 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import db.*;
-import ghidra.program.database.map.*;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.model.address.*;
-import ghidra.program.model.symbol.SourceType;
-import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.exception.CancelledException;
+import ghidra.program.database.map.AddressMap;
import ghidra.util.exception.VersionException;
-import ghidra.util.task.TaskMonitor;
/**
* SymbolDatabaseAdapter for version 3
@@ -38,13 +31,9 @@ import ghidra.util.task.TaskMonitor;
* It was created in June 2021 with ProgramDB version 24.
* It was first in affect within Ghidra starting at version 10.1
*/
-class SymbolDatabaseAdapterV3 extends SymbolDatabaseAdapter {
+class SymbolDatabaseAdapterV3 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
- static final int SYMBOL_VERSION = 3;
-
- // Used to create a range when searching symbols by name/namespace but don't care about address
- private static final long MIN_ADDRESS_OFFSET = 0;
- private static final long MAX_ADDRESS_OFFSET = -1;
+ static final int VERSION = 3;
// NOTE: the primary field duplicates the symbol's address when the symbol is primary. This
// allows us to index this field and quickly find the primary symbols. The field is sparse
@@ -75,269 +64,26 @@ class SymbolDatabaseAdapterV3 extends SymbolDatabaseAdapter {
private static final int V3_SYMBOL_VAROFFSET_COL = 9;
private Table symbolTable;
- private AddressMap addrMap;
SymbolDatabaseAdapterV3(DBHandle handle, AddressMap addrMap) throws VersionException {
- this.addrMap = addrMap;
symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
if (symbolTable == null) {
throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
+ if (symbolTable.getSchema().getVersion() != VERSION) {
int version = symbolTable.getSchema().getVersion();
- if (version < SYMBOL_VERSION) {
+ if (version < VERSION) {
throw new VersionException(true);
}
throw new VersionException(VersionException.NEWER_VERSION, false);
}
}
- @Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- void removeSymbol(long symbolID) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- boolean hasSymbol(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return false;
- }
- return symbolTable.hasRecord(new LongField(key), V3_SYMBOL_ADDR_COL);
- }
-
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return Field.EMPTY_ARRAY;
- }
- return symbolTable.findRecords(new LongField(key), V3_SYMBOL_ADDR_COL);
- }
-
- @Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return convertV3Record(symbolTable.getRecord(symbolID));
- }
-
- @Override
- int getSymbolCount() {
- return symbolTable.getRecordCount();
- }
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- KeyToRecordIterator it = new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, V3_SYMBOL_ADDR_COL, addrMap, forward));
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V3_SYMBOL_ADDR_COL, addrMap, startAddr, forward));
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- throw new UnsupportedOperationException();
- }
-
@Override
RecordIterator getSymbols() throws IOException {
- return new V3ConvertedRecordIterator(symbolTable.iterator());
- }
-
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V3_SYMBOL_ADDR_COL, addrMap, start, end, forward));
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V3_SYMBOL_ADDR_COL, addrMap, set, forward));
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- protected RecordIterator getPrimarySymbols(AddressSetView set, boolean forward)
- throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V3_SYMBOL_PRIMARY_COL, addrMap, set, forward));
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- protected DBRecord getPrimarySymbol(Address address) throws IOException {
- AddressIndexPrimaryKeyIterator it = new AddressIndexPrimaryKeyIterator(symbolTable,
- V3_SYMBOL_PRIMARY_COL, addrMap, address, address, true);
- if (it.hasNext()) {
- return convertV3Record(symbolTable.getRecord(it.next()));
- }
- return null;
- }
-
- @Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
- throw new UnsupportedOperationException();
- }
-
- private String getExternalStringData(DBRecord rec) {
- long addrKey = rec.getLongValue(V3_SYMBOL_ADDR_COL);
- Address addr = addrMap.decodeAddress(addrKey);
- if (addr == null || !addr.isExternalAddress()) {
- return null;
- }
- byte symbolTypeId = rec.getByteValue(V3_SYMBOL_TYPE_COL);
- if (symbolTypeId != SYMBOL_TYPE_FUNCTION && symbolTypeId != SYMBOL_TYPE_LABEL) {
- return null;
- }
-
- return rec.getString(V3_SYMBOL_STRING_DATA_COL);
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- if (extProgAddr == null) {
- return EmptyRecordIterator.INSTANCE;
- }
- String matchAddrStr = extProgAddr.toString();
- return new ConstrainedForwardRecordIterator(symbolTable.iterator(), rec -> {
- String str = getExternalStringData(rec);
- if (str != null) {
- int indexOf = str.indexOf(","); // [address][,importName]
- String addressString = indexOf >= 0 ? str.substring(0, indexOf) : str;
- if (matchAddrStr.equals(addressString)) {
- return convertV3Record(rec);
- }
- }
- return null;
- });
- }
-
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- if (StringUtils.isBlank(extLabel)) {
- return EmptyRecordIterator.INSTANCE;
- }
- return new ConstrainedForwardRecordIterator(symbolTable.iterator(), rec -> {
- String str = getExternalStringData(rec);
- if (str != null) {
- int indexOf = str.indexOf(","); // [address][,importName]
- String originalImportedName = indexOf >= 0 ? str.substring(indexOf + 1) : null;
- if (extLabel.equals(originalImportedName)) {
- return convertV3Record(rec);
- }
- }
- return null;
- });
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- LongField field = new LongField(id);
- RecordIterator it = symbolTable.indexIterator(V3_SYMBOL_PARENT_ID_COL, field, field, true);
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField field = new StringField(name);
- RecordIterator it = symbolTable.indexIterator(V3_SYMBOL_NAME_COL, field, field, true);
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField field = new StringField(startName);
- RecordIterator it = symbolTable.indexIterator(V3_SYMBOL_NAME_COL, field, null, true);
- return new V3ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- // create a range of hash fields for all symbols with this name and namespace id over all
- // possible addresses
- Field start = computeLocatorHash(name, id, MIN_ADDRESS_OFFSET);
- if (start == null) {
- return EmptyRecordIterator.INSTANCE;
- }
-
- Field end = computeLocatorHash(name, id, MAX_ADDRESS_OFFSET);
-
- RecordIterator it = symbolTable.indexIterator(V3_SYMBOL_HASH_COL, start, end, true);
- it = new V3ConvertedRecordIterator(it);
-
- RecordIterator filtered = getNameAndNamespaceFilterIterator(name, id, it);
- return new V3ConvertedRecordIterator(filtered);
- }
-
- @Override
- DBRecord getSymbolRecord(Address address, String name, long namespaceId) throws IOException {
- long addressKey = addrMap.getKey(address, false);
- Field search = computeLocatorHash(name, namespaceId, addressKey);
- if (search == null) {
- return null;
- }
- RecordIterator it = symbolTable.indexIterator(V3_SYMBOL_HASH_COL, search, search, true);
- it = new V3ConvertedRecordIterator(it);
-
- RecordIterator filtered =
- getNameNamespaceAddressFilterIterator(name, namespaceId, addressKey, it);
- if (filtered.hasNext()) {
- return filtered.next();
- }
- return null;
- }
-
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- if (space.isMemorySpace()) {
- AddressIndexKeyIterator addressKeyIterator = new AddressIndexKeyIterator(symbolTable,
- V3_SYMBOL_ADDR_COL, addrMap, space.getMinAddress(), space.getMaxAddress(), false);
- if (addressKeyIterator.hasNext()) {
- return addrMap.decodeAddress(addressKeyIterator.next());
- }
- }
- else {
- LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
- DBFieldIterator iterator =
- symbolTable.indexFieldIterator(null, max, false, V3_SYMBOL_ADDR_COL);
- if (iterator.hasPrevious()) {
- LongField val = (LongField) iterator.previous();
- Address addr = addrMap.decodeAddress(val.getLongValue());
- if (space.equals(addr.getAddressSpace())) {
- return addr;
- }
- }
- }
- return null;
- }
-
- @Override
- Table getTable() {
- return symbolTable;
+ RecordIterator it = symbolTable.iterator();
+ return new TranslatedRecordIterator(it, this);
}
/**
@@ -345,7 +91,8 @@ class SymbolDatabaseAdapterV3 extends SymbolDatabaseAdapter {
* @param record the record matching the version 3 schema.
* @return a current symbol record.
*/
- private DBRecord convertV3Record(DBRecord record) {
+ @Override
+ public DBRecord translateRecord(DBRecord record) {
if (record == null) {
return null;
}
@@ -395,6 +142,11 @@ class SymbolDatabaseAdapterV3 extends SymbolDatabaseAdapter {
return rec;
}
+ @Override
+ protected int getVersion() {
+ return VERSION;
+ }
+
static void convertSymbolStringData(byte symbolTypeId, DBRecord record, String str) {
// Adhoc String field use/format
@@ -421,16 +173,8 @@ class SymbolDatabaseAdapterV3 extends SymbolDatabaseAdapter {
}
}
- private class V3ConvertedRecordIterator extends ConvertedRecordIterator {
-
- V3ConvertedRecordIterator(RecordIterator originalIterator) {
- super(originalIterator, false);
- }
-
- @Override
- protected DBRecord convertRecord(DBRecord record) {
- return convertV3Record(record);
- }
+ @Override
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
}
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV4.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV4.java
index 1971bbd389..ae3a4ed6a7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV4.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV4.java
@@ -16,17 +16,10 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.Set;
import db.*;
-import ghidra.program.database.map.*;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.model.address.*;
-import ghidra.program.model.symbol.SourceType;
-import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.exception.CancelledException;
+import ghidra.program.database.map.AddressMap;
import ghidra.util.exception.VersionException;
-import ghidra.util.task.TaskMonitor;
/**
* SymbolDatabaseAdapter for version 4
@@ -34,13 +27,9 @@ import ghidra.util.task.TaskMonitor;
* This version added additional sparse columns to store optional data specific to certain
* symbol types. The adhoc string data column was eliminated.
*/
-class SymbolDatabaseAdapterV4 extends SymbolDatabaseAdapter {
+class SymbolDatabaseAdapterV4 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
- static final int SYMBOL_VERSION = 4;
-
- // Used to create a range when searching symbols by name/namespace but don't care about address
- private static final long MIN_ADDRESS_OFFSET = 0;
- private static final long MAX_ADDRESS_OFFSET = -1;
+ static final int VERSION = 4;
// NOTE: the primary field duplicates the symbol's address when the symbol is primary. This
// allows us to index this field and quickly find the primary symbols. The field is sparse
@@ -77,245 +66,34 @@ class SymbolDatabaseAdapterV4 extends SymbolDatabaseAdapter {
static final int V4_SYMBOL_LIBPATH_COL = 12;
private Table symbolTable;
- private AddressMap addrMap;
SymbolDatabaseAdapterV4(DBHandle handle, AddressMap addrMap) throws VersionException {
- this.addrMap = addrMap;
symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
if (symbolTable == null) {
throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
+ if (symbolTable.getSchema().getVersion() != VERSION) {
int version = symbolTable.getSchema().getVersion();
- if (version < SYMBOL_VERSION) {
+ if (version < VERSION) {
throw new VersionException(true);
}
throw new VersionException(VersionException.NEWER_VERSION, false);
}
}
- @Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- void removeSymbol(long symbolID) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- boolean hasSymbol(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return false;
- }
- return symbolTable.hasRecord(new LongField(key), V4_SYMBOL_ADDR_COL);
- }
-
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return Field.EMPTY_ARRAY;
- }
- return symbolTable.findRecords(new LongField(key), V4_SYMBOL_ADDR_COL);
- }
-
- @Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return convertV4Record(symbolTable.getRecord(symbolID));
- }
-
- @Override
- int getSymbolCount() {
- return symbolTable.getRecordCount();
- }
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- KeyToRecordIterator it = new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, V4_SYMBOL_ADDR_COL, addrMap, forward));
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V4_SYMBOL_ADDR_COL, addrMap, startAddr, forward));
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- throw new UnsupportedOperationException();
- }
-
@Override
RecordIterator getSymbols() throws IOException {
- return new V4ConvertedRecordIterator(symbolTable.iterator());
- }
-
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V4_SYMBOL_ADDR_COL, addrMap, start, end, forward));
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V4_SYMBOL_ADDR_COL, addrMap, set, forward));
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- protected RecordIterator getPrimarySymbols(AddressSetView set, boolean forward)
- throws IOException {
- KeyToRecordIterator it =
- new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- V4_SYMBOL_PRIMARY_COL, addrMap, set, forward));
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- protected DBRecord getPrimarySymbol(Address address) throws IOException {
- AddressIndexPrimaryKeyIterator it = new AddressIndexPrimaryKeyIterator(symbolTable,
- V4_SYMBOL_PRIMARY_COL, addrMap, address, address, true);
- if (it.hasNext()) {
- return convertV4Record(symbolTable.getRecord(it.next()));
- }
- return null;
- }
-
- void deleteExternalEntries(Address start, Address end) throws IOException {
- throw new UnsupportedOperationException();
+ return new TranslatedRecordIterator(symbolTable.iterator(), this);
}
@Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- throw new UnsupportedOperationException();
+ protected int getVersion() {
+ return VERSION;
}
@Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- LongField field = new LongField(id);
- RecordIterator it =
- symbolTable.indexIterator(V4_SYMBOL_PARENT_ID_COL, field, field, true);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField field = new StringField(name);
- RecordIterator it = symbolTable.indexIterator(V4_SYMBOL_NAME_COL, field, field, true);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField field = new StringField(startName);
- RecordIterator it = symbolTable.indexIterator(V4_SYMBOL_NAME_COL, field, null, true);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- StringField extLabelField = new StringField(extLabel);
- RecordIterator it =
- symbolTable.indexIterator(V4_SYMBOL_ORIGINAL_IMPORTED_NAME_COL, extLabelField,
- extLabelField, true);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- StringField addrField = new StringField(extProgAddr.toString());
- RecordIterator it =
- symbolTable.indexIterator(V4_SYMBOL_EXTERNAL_PROG_ADDR_COL, addrField, addrField,
- true);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- // create a range of hash fields for all symbols with this name and namespace id over all
- // possible addresses
- Field start = computeLocatorHash(name, id, MIN_ADDRESS_OFFSET);
- if (start == null) {
- return EmptyRecordIterator.INSTANCE;
- }
-
- Field end = computeLocatorHash(name, id, MAX_ADDRESS_OFFSET);
-
- RecordIterator it = symbolTable.indexIterator(V4_SYMBOL_HASH_COL, start, end, true);
- it = getNameAndNamespaceFilterIterator(name, id, it);
- return new V4ConvertedRecordIterator(it);
- }
-
- @Override
- DBRecord getSymbolRecord(Address address, String name, long namespaceId) throws IOException {
- long addressKey = addrMap.getKey(address, false);
- Field search = computeLocatorHash(name, namespaceId, addressKey);
- if (search == null) {
- return null;
- }
- RecordIterator it = symbolTable.indexIterator(V4_SYMBOL_HASH_COL, search, search, true);
- RecordIterator filtered =
- getNameNamespaceAddressFilterIterator(name, namespaceId, addressKey, it);
- if (filtered.hasNext()) {
- return convertV4Record(filtered.next());
- }
- return null;
- }
-
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- if (space.isMemorySpace()) {
- AddressIndexKeyIterator addressKeyIterator = new AddressIndexKeyIterator(symbolTable,
- V4_SYMBOL_ADDR_COL, addrMap, space.getMinAddress(), space.getMaxAddress(), false);
- if (addressKeyIterator.hasNext()) {
- return addrMap.decodeAddress(addressKeyIterator.next());
- }
- }
- else {
- LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
- DBFieldIterator iterator =
- symbolTable.indexFieldIterator(null, max, false, V4_SYMBOL_ADDR_COL);
- if (iterator.hasPrevious()) {
- LongField val = (LongField) iterator.previous();
- Address addr = addrMap.decodeAddress(val.getLongValue());
- if (space.equals(addr.getAddressSpace())) {
- return addr;
- }
- }
- }
- return null;
- }
-
- @Override
- Table getTable() {
- return symbolTable;
- }
-
- /**
- * Returns a record matching the current database schema from the version 4 record.
- * @param record the record matching the version 4 schema.
- * @return a current symbol record.
- */
- private DBRecord convertV4Record(DBRecord record) {
+ public DBRecord translateRecord(DBRecord record) throws IOException {
if (record == null) {
return null;
}
@@ -377,16 +155,8 @@ class SymbolDatabaseAdapterV4 extends SymbolDatabaseAdapter {
return rec;
}
- private class V4ConvertedRecordIterator extends ConvertedRecordIterator {
-
- V4ConvertedRecordIterator(RecordIterator originalIterator) {
- super(originalIterator, false);
- }
-
- @Override
- protected DBRecord convertRecord(DBRecord record) {
- return convertV4Record(record);
- }
+ @Override
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
}
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV5.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV5.java
index f50812dc0f..a0e331af5b 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV5.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV5.java
@@ -16,19 +16,10 @@
package ghidra.program.database.symbol;
import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
import db.*;
-import ghidra.program.database.map.*;
-import ghidra.program.database.util.EmptyRecordIterator;
-import ghidra.program.database.util.RecordFilter;
-import ghidra.program.model.address.*;
-import ghidra.program.model.symbol.SourceType;
-import ghidra.program.model.symbol.SymbolType;
-import ghidra.util.exception.CancelledException;
+import ghidra.program.database.map.AddressMap;
import ghidra.util.exception.VersionException;
-import ghidra.util.task.TaskMonitor;
/**
* SymbolDatabaseAdapter for version 5
@@ -36,316 +27,148 @@ import ghidra.util.task.TaskMonitor;
* This version added additional sparse columns to store optional data specific to certain
* symbol types. The adhoc string data column was eliminated.
*/
-class SymbolDatabaseAdapterV5 extends SymbolDatabaseAdapter {
-
- static final int SYMBOL_VERSION = 5;
-
- // Used to create a range when searching symbols by name/namespace but don't care about address
- private static final long MIN_ADDRESS_OFFSET = 0;
- private static final long MAX_ADDRESS_OFFSET = -1;
+class SymbolDatabaseAdapterV5 extends PreV6SymbolDatabaseAdapter implements RecordTranslator {
+
+ static final int VERSION = 5;
+
+ static final int V5_SYMBOL_NAME_COL = 0;
+ static final int V5_SYMBOL_ADDR_COL = 1;
+ static final int V5_SYMBOL_PARENT_ID_COL = 2;
+ static final int V5_SYMBOL_TYPE_COL = 3;
+ static final int V5_SYMBOL_FLAGS_COL = 4;
+
+ // Sparse fields - the following fields are not always applicable so they are optional and
+ // don't consume space in the database if they aren't used.
+ static final int V5_SYMBOL_HASH_COL = 5;
+ static final int V5_SYMBOL_PRIMARY_COL = 6;
+ static final int V5_SYMBOL_DATATYPE_COL = 7;
+ static final int V5_SYMBOL_VAROFFSET_COL = 8;
+ static final int V5_SYMBOL_ORIGINAL_IMPORTED_NAME_COL = 9;
+ static final int V5_SYMBOL_EXTERNAL_PROG_ADDR_COL = 10;
+ static final int V5_SYMBOL_COMMENT_COL = 11;
+ static final int V5_SYMBOL_LIBPATH_COL = 12;
+ static final int V5_SYMBOL_LIB_ORDINAL_COL = 13;
// NOTE: the primary field duplicates the symbol's address when the symbol is primary. This
// allows us to index this field and quickly find the primary symbols. The field is sparse
// so that non-primary symbols don't consume any space for this field.
- static final Schema V5_SYMBOL_SCHEMA = new Schema(SYMBOL_VERSION, "Key",
- new Field[] { StringField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
- ByteField.INSTANCE, ByteField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
- LongField.INSTANCE, IntField.INSTANCE, StringField.INSTANCE, StringField.INSTANCE,
- StringField.INSTANCE, StringField.INSTANCE, IntField.INSTANCE },
- new String[] { "Name", "Address", "Namespace", "Symbol Type", "Flags", "Locator Hash",
- "Primary", "Datatype", "Variable Offset", "ExtOrigImportName", "ExtProgAddr", "Comment",
- "LibPath", "LibOrdinal" },
- new int[] { SYMBOL_HASH_COL, SYMBOL_PRIMARY_COL, SYMBOL_DATATYPE_COL, SYMBOL_VAROFFSET_COL,
- SYMBOL_ORIGINAL_IMPORTED_NAME_COL, SYMBOL_EXTERNAL_PROG_ADDR_COL, SYMBOL_COMMENT_COL,
- SYMBOL_LIBPATH_COL, SYMBOL_LIB_ORDINAL_COL });
+// Do not remove the following commented out schema! It shows the version 4 symbol table schema. */
+// static final Schema V5_SYMBOL_SCHEMA = new Schema(SYMBOL_VERSION, "Key",
+// new Field[] { StringField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
+// ByteField.INSTANCE, ByteField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
+// LongField.INSTANCE, IntField.INSTANCE, StringField.INSTANCE, StringField.INSTANCE,
+// StringField.INSTANCE, StringField.INSTANCE, IntField.INSTANCE },
+// new String[] { "Name", "Address", "Namespace", "Symbol Type", "Flags", "Locator Hash",
+// "Primary", "Datatype", "Variable Offset", "ExtOrigImportName", "ExtProgAddr", "Comment",
+// "LibPath", "LibOrdinal" },
+// new int[] { V5_SYMBOL_HASH_COL, V5_SYMBOL_PRIMARY_COL, V5_SYMBOL_DATATYPE_COL,
+// V5_SYMBOL_VAROFFSET_COL, V5_SYMBOL_ORIGINAL_IMPORTED_NAME_COL,
+// V5_SYMBOL_EXTERNAL_PROG_ADDR_COL, V5_SYMBOL_COMMENT_COL, V5_SYMBOL_LIBPATH_COL,
+// V5_SYMBOL_LIB_ORDINAL_COL });
private Table symbolTable;
- private AddressMap addrMap;
- SymbolDatabaseAdapterV5(DBHandle handle, AddressMap addrMap, boolean create)
- throws VersionException, IOException {
+ SymbolDatabaseAdapterV5(DBHandle handle, AddressMap addrMap)
+ throws VersionException {
- this.addrMap = addrMap;
- if (create) {
- symbolTable = handle.createTable(SYMBOL_TABLE_NAME, SYMBOL_SCHEMA,
- new int[] { SYMBOL_ADDR_COL, SYMBOL_NAME_COL, SYMBOL_PARENT_ID_COL, SYMBOL_HASH_COL,
- SYMBOL_PRIMARY_COL, SYMBOL_ORIGINAL_IMPORTED_NAME_COL,
- SYMBOL_EXTERNAL_PROG_ADDR_COL });
+ symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
+ if (symbolTable == null) {
+ throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
}
- else {
- symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
- if (symbolTable == null) {
- throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
- }
- if (symbolTable.getSchema().getVersion() != SYMBOL_VERSION) {
- int version = symbolTable.getSchema().getVersion();
- if (version < SYMBOL_VERSION) {
- throw new VersionException(true);
- }
- throw new VersionException(VersionException.NEWER_VERSION, false);
+ if (symbolTable.getSchema().getVersion() != VERSION) {
+ int version = symbolTable.getSchema().getVersion();
+ if (version < VERSION) {
+ throw new VersionException(true);
}
+ throw new VersionException(VersionException.NEWER_VERSION, false);
}
}
@Override
- DBRecord createSymbolRecord(String name, long namespaceID, Address address,
- SymbolType symbolType, boolean isPrimary, SourceType source) {
-
- long nextID = symbolTable.getKey();
-
- // Avoid key 0, as it is reserved for the global namespace
- if (nextID == 0) {
- nextID++;
- }
-
- long addressKey = addrMap.getKey(address, true);
-
- DBRecord rec = symbolTable.getSchema().createRecord(nextID);
- rec.setString(SYMBOL_NAME_COL, name);
- rec.setLongValue(SYMBOL_ADDR_COL, addressKey);
- rec.setLongValue(SYMBOL_PARENT_ID_COL, namespaceID);
- rec.setByteValue(SYMBOL_TYPE_COL, symbolType.getID());
- rec.setByteValue(SYMBOL_FLAGS_COL, getSourceTypeFlagsBits(source)); // assume non-pinned
-
- // Sparse columns - these columns don't apply to all symbols.
- // they default to null unless specifically set. Null values don't consume space.
-
- rec.setField(SYMBOL_HASH_COL, computeLocatorHash(name, namespaceID, addressKey));
-
- if (isPrimary) {
- rec.setLongValue(SYMBOL_PRIMARY_COL, addressKey);
- }
-
- return rec;
+ RecordIterator getSymbols() throws IOException {
+ return new TranslatedRecordIterator(symbolTable.iterator(), this);
}
@Override
- void removeSymbol(long symbolID) throws IOException {
- symbolTable.deleteRecord(symbolID);
+ protected int getVersion() {
+ return VERSION;
}
@Override
- boolean hasSymbol(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return false;
+ public DBRecord translateRecord(DBRecord record) {
+ if (record == null) {
+ return null;
}
- return symbolTable.hasRecord(new LongField(key), SYMBOL_ADDR_COL);
- }
+ DBRecord rec = SymbolDatabaseAdapter.SYMBOL_SCHEMA.createRecord(record.getKey());
- @Override
- Field[] getSymbolIDs(Address addr) throws IOException {
- long key = addrMap.getKey(addr, false);
- if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
- return Field.EMPTY_ARRAY;
- }
- return symbolTable.findRecords(new LongField(key), SYMBOL_ADDR_COL);
- }
+ String symbolName = record.getString(V5_SYMBOL_NAME_COL);
+ rec.setString(SymbolDatabaseAdapter.SYMBOL_NAME_COL, symbolName);
- @Override
- DBRecord getSymbolRecord(long symbolID) throws IOException {
- return symbolTable.getRecord(symbolID);
- }
+ long symbolAddrKey = record.getLongValue(V5_SYMBOL_ADDR_COL);
+ rec.setLongValue(SymbolDatabaseAdapter.SYMBOL_ADDR_COL, symbolAddrKey);
- @Override
- int getSymbolCount() {
- return symbolTable.getRecordCount();
- }
-
- @Override
- RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
- return new KeyToRecordIterator(symbolTable,
- new AddressIndexPrimaryKeyIterator(symbolTable, SYMBOL_ADDR_COL, addrMap, forward));
- }
+ long namespaceId = record.getLongValue(V5_SYMBOL_PARENT_ID_COL);
+ rec.setLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL, namespaceId);
- @Override
- RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
- return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, startAddr, forward));
- }
+ byte symbolTypeId = record.getByteValue(V5_SYMBOL_TYPE_COL);
+ rec.setByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL, symbolTypeId);
- @Override
- void updateSymbolRecord(DBRecord record) throws IOException {
- // make sure hash is updated to current name and name space
- String name = record.getString(SYMBOL_NAME_COL);
- long namespaceId = record.getLongValue(SYMBOL_PARENT_ID_COL);
- long addressKey = record.getLongValue(SYMBOL_ADDR_COL);
- record.setField(SYMBOL_HASH_COL, computeLocatorHash(name, namespaceId, addressKey));
- symbolTable.putRecord(record);
- }
+ rec.setByteValue(SymbolDatabaseAdapter.SYMBOL_FLAGS_COL,
+ record.getByteValue(V5_SYMBOL_FLAGS_COL));
- @Override
- RecordIterator getSymbols() throws IOException {
- return symbolTable.iterator();
- }
+ //
+ // Convert sparse columns
- @Override
- RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
- return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, start, end, forward));
- }
-
- @Override
- RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
- return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, set, forward));
- }
-
- @Override
- protected RecordIterator getPrimarySymbols(AddressSetView set, boolean forward)
- throws IOException {
- return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_PRIMARY_COL, addrMap, set, forward));
- }
-
- @Override
- protected DBRecord getPrimarySymbol(Address address) throws IOException {
- AddressIndexPrimaryKeyIterator it = new AddressIndexPrimaryKeyIterator(symbolTable,
- SYMBOL_PRIMARY_COL, addrMap, address, address, true);
- if (it.hasNext()) {
- return symbolTable.getRecord(it.next());
+ Field hash = record.getFieldValue(V5_SYMBOL_HASH_COL);
+ if (hash != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_HASH_COL, hash);
}
- return null;
- }
- void deleteExternalEntries(Address start, Address end) throws IOException {
- AddressRecordDeleter.deleteRecords(symbolTable, SYMBOL_ADDR_COL, addrMap, start, end, null);
- }
-
- @Override
- void moveAddress(Address oldAddr, Address newAddr) throws IOException {
- LongField oldKey = new LongField(addrMap.getKey(oldAddr, false));
- long newKey = addrMap.getKey(newAddr, true);
- Field[] keys = symbolTable.findRecords(oldKey, SYMBOL_ADDR_COL);
- for (Field key : keys) {
- DBRecord rec = symbolTable.getRecord(key);
- rec.setLongValue(SYMBOL_ADDR_COL, newKey);
- symbolTable.putRecord(rec);
+ Field primaryAddr = record.getFieldValue(V5_SYMBOL_PRIMARY_COL);
+ if (primaryAddr != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_PRIMARY_COL, primaryAddr);
}
- }
-
- @Override
- Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
- throws CancelledException, IOException {
-
- AnchoredSymbolRecordFilter filter = new AnchoredSymbolRecordFilter();
- AddressRecordDeleter.deleteRecords(symbolTable, SYMBOL_ADDR_COL, addrMap, startAddr,
- endAddr, filter);
-
- return filter.getAddressesForSkippedRecords();
- }
-
- @Override
- RecordIterator getSymbolsByNamespace(long id) throws IOException {
- LongField field = new LongField(id);
- return symbolTable.indexIterator(SYMBOL_PARENT_ID_COL, field, field, true);
- }
-
- @Override
- RecordIterator getSymbolsByName(String name) throws IOException {
- StringField field = new StringField(name);
- return symbolTable.indexIterator(SYMBOL_NAME_COL, field, field, true);
- }
-
- @Override
- RecordIterator scanSymbolsByName(String startName) throws IOException {
- StringField field = new StringField(startName);
- return symbolTable.indexIterator(SYMBOL_NAME_COL, field, null, true);
- }
-
- @Override
- RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
- StringField extLabelField = new StringField(extLabel);
- return symbolTable.indexIterator(SYMBOL_ORIGINAL_IMPORTED_NAME_COL, extLabelField,
- extLabelField, true);
- }
-
- @Override
- RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
- StringField addrField = new StringField(extProgAddr.toString());
- return symbolTable.indexIterator(SYMBOL_EXTERNAL_PROG_ADDR_COL, addrField, addrField, true);
- }
- @Override
- RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
- // create a range of hash fields for all symbols with this name and namespace id over all
- // possible addresses
- Field start = computeLocatorHash(name, id, MIN_ADDRESS_OFFSET);
- if (start == null) {
- return EmptyRecordIterator.INSTANCE;
+ Field dataTypeId = record.getFieldValue(V5_SYMBOL_DATATYPE_COL);
+ if (dataTypeId != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_DATATYPE_COL, dataTypeId);
}
- Field end = computeLocatorHash(name, id, MAX_ADDRESS_OFFSET);
+ Field varOffset = record.getFieldValue(V5_SYMBOL_VAROFFSET_COL);
+ if (varOffset != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_VAROFFSET_COL, varOffset);
+ }
- RecordIterator it = symbolTable.indexIterator(SYMBOL_HASH_COL, start, end, true);
- return getNameAndNamespaceFilterIterator(name, id, it);
- }
+ Field origName = record.getFieldValue(V5_SYMBOL_ORIGINAL_IMPORTED_NAME_COL);
+ if (origName != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_ORIGINAL_IMPORTED_NAME_COL, origName);
+ }
- @Override
- DBRecord getSymbolRecord(Address address, String name, long namespaceId) throws IOException {
- long addressKey = addrMap.getKey(address, false);
- Field search = computeLocatorHash(name, namespaceId, addressKey);
- if (search == null) {
- return null;
+ Field extProgramAddr = record.getFieldValue(V5_SYMBOL_EXTERNAL_PROG_ADDR_COL);
+ if (extProgramAddr != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_EXTERNAL_PROG_ADDR_COL, extProgramAddr);
}
- RecordIterator it = symbolTable.indexIterator(SYMBOL_HASH_COL, search, search, true);
- RecordIterator filtered =
- getNameNamespaceAddressFilterIterator(name, namespaceId, addressKey, it);
- if (filtered.hasNext()) {
- return filtered.next();
+
+ Field comment = record.getFieldValue(V5_SYMBOL_COMMENT_COL);
+ if (comment != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_COMMENT_COL, comment);
}
- return null;
- }
- @Override
- Address getMaxSymbolAddress(AddressSpace space) throws IOException {
- if (space.isMemorySpace()) {
- AddressIndexKeyIterator addressKeyIterator = new AddressIndexKeyIterator(symbolTable,
- SYMBOL_ADDR_COL, addrMap, space.getMinAddress(), space.getMaxAddress(), false);
- if (addressKeyIterator.hasNext()) {
- return addrMap.decodeAddress(addressKeyIterator.next());
- }
+ Field libPath = record.getFieldValue(V5_SYMBOL_LIBPATH_COL);
+ if (libPath != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_LIBPATH_COL, libPath);
}
- else {
- LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
- DBFieldIterator iterator =
- symbolTable.indexFieldIterator(null, max, false, SYMBOL_ADDR_COL);
- if (iterator.hasPrevious()) {
- LongField val = (LongField) iterator.previous();
- Address addr = addrMap.decodeAddress(val.getLongValue());
- if (space.equals(addr.getAddressSpace())) {
- return addr;
- }
- }
+ Field libOrdinal = record.getFieldValue(V5_SYMBOL_LIB_ORDINAL_COL);
+ if (libOrdinal != null) {
+ rec.setField(SymbolDatabaseAdapter.SYMBOL_LIB_ORDINAL_COL, libOrdinal);
}
- return null;
- }
- @Override
- Table getTable() {
- return symbolTable;
+ return rec;
}
- private class AnchoredSymbolRecordFilter implements RecordFilter {
- private Set<Address> set = new HashSet<Address>();
-
- @Override
- public boolean matches(DBRecord record) {
- // only move symbols whose anchor flag is not on
- Address addr = addrMap.decodeAddress(record.getLongValue(SYMBOL_ADDR_COL));
- byte flags = record.getByteValue(SymbolDatabaseAdapter.SYMBOL_FLAGS_COL);
- boolean pinned = (flags & SymbolDatabaseAdapter.SYMBOL_PINNED_FLAG) != 0;
- if (!pinned) {
- return true;
- }
- set.add(addr);
- return false;
- }
-
- Set<Address> getAddressesForSkippedRecords() {
- return set;
- }
+ @Override
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
}
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV6.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV6.java
new file mode 100644
index 0000000000..df4946f563
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolDatabaseAdapterV6.java
@@ -0,0 +1,383 @@
+/* ###
+ * 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.program.database.symbol;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import db.*;
+import ghidra.program.database.map.*;
+import ghidra.program.database.util.EmptyRecordIterator;
+import ghidra.program.database.util.RecordFilter;
+import ghidra.program.model.address.*;
+import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.SymbolType;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.exception.VersionException;
+import ghidra.util.task.TaskMonitor;
+
+/**
+ * SymbolDatabaseAdapter for version 6
+ *
+ * This version adds a new column for storing a library symbol id. This id indicates the symbol
+ * is external in in the library associated with that id.
+ */
+class SymbolDatabaseAdapterV6 extends SymbolDatabaseAdapter {
+ static final int V6_SYMBOL_NAME_COL = 0;
+ static final int V6_SYMBOL_ADDR_COL = 1;
+ static final int V6_SYMBOL_PARENT_ID_COL = 2;
+ static final int V6_SYMBOL_TYPE_COL = 3;
+ static final int V6_SYMBOL_FLAGS_COL = 4;
+
+ // Sparse fields - the following fields are not always applicable so they are optional and
+ // don't consume space in the database if they aren't used.
+ static final int V6_SYMBOL_HASH_COL = 5;
+ static final int V6_SYMBOL_PRIMARY_COL = 6;
+ static final int V6_SYMBOL_DATATYPE_COL = 7;
+ static final int V6_SYMBOL_VAROFFSET_COL = 8;
+ static final int V6_SYMBOL_ORIGINAL_IMPORTED_NAME_COL = 9;
+ static final int V6_SYMBOL_EXTERNAL_PROG_ADDR_COL = 10;
+ static final int V6_SYMBOL_COMMENT_COL = 11;
+ static final int V6_SYMBOL_LIBPATH_COL = 12;
+ static final int V6_SYMBOL_LIB_ORDINAL_COL = 13;
+ static final int V6_SYMBOL_LIBRARY_ID_COL = 14;
+
+ static final int VERSION = 6;
+
+ // Used to create a range when searching symbols by name/namespace but don't care about address
+ private static final long MIN_ENCODED_ADDRESS = 0;
+ private static final long MAX_ENCODED_ADDRESS = -1;
+
+ // NOTE: the primary field duplicates the symbol's address when the symbol is primary. This
+ // allows us to index this field and quickly find the primary symbols. The field is sparse
+ // so that non-primary symbols don't consume any space for this field.
+
+ static final Schema V6_SYMBOL_SCHEMA = new Schema(VERSION, "Key",
+ new Field[] { StringField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
+ ByteField.INSTANCE, ByteField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE,
+ LongField.INSTANCE, IntField.INSTANCE, StringField.INSTANCE, StringField.INSTANCE,
+ StringField.INSTANCE, StringField.INSTANCE, IntField.INSTANCE, LongField.INSTANCE },
+ new String[] { "Name", "Address", "Namespace", "Symbol Type", "Flags", "Locator Hash",
+ "Primary", "Datatype", "Variable Offset", "ExtOrigImportName", "ExtProgAddr", "Comment",
+ "LibPath", "LibOrdinal", "LIBRARY_ID" },
+ new int[] { V6_SYMBOL_HASH_COL, V6_SYMBOL_PRIMARY_COL, V6_SYMBOL_DATATYPE_COL,
+ V6_SYMBOL_VAROFFSET_COL, V6_SYMBOL_ORIGINAL_IMPORTED_NAME_COL,
+ V6_SYMBOL_EXTERNAL_PROG_ADDR_COL, V6_SYMBOL_COMMENT_COL,
+ V6_SYMBOL_LIBPATH_COL, V6_SYMBOL_LIB_ORDINAL_COL, V6_SYMBOL_LIBRARY_ID_COL });
+
+ private Table symbolTable;
+ private AddressMap addrMap;
+
+ SymbolDatabaseAdapterV6(DBHandle handle, AddressMap addrMap, boolean create)
+ throws VersionException, IOException {
+
+ this.addrMap = addrMap;
+ if (create) {
+ symbolTable = handle.createTable(SYMBOL_TABLE_NAME, SYMBOL_SCHEMA,
+ new int[] { V6_SYMBOL_ADDR_COL, V6_SYMBOL_NAME_COL, V6_SYMBOL_PARENT_ID_COL,
+ V6_SYMBOL_HASH_COL, V6_SYMBOL_PRIMARY_COL, V6_SYMBOL_ORIGINAL_IMPORTED_NAME_COL,
+ V6_SYMBOL_EXTERNAL_PROG_ADDR_COL, V6_SYMBOL_LIBRARY_ID_COL });
+ }
+ else {
+ symbolTable = handle.getTable(SYMBOL_TABLE_NAME);
+ if (symbolTable == null) {
+ throw new VersionException("Missing Table: " + SYMBOL_TABLE_NAME);
+ }
+ if (symbolTable.getSchema().getVersion() != VERSION) {
+ int version = symbolTable.getSchema().getVersion();
+ if (version < VERSION) {
+ throw new VersionException(true);
+ }
+ throw new VersionException(VersionException.NEWER_VERSION, false);
+ }
+ }
+ }
+
+ @Override
+ DBRecord createSymbolRecord(String name, long namespaceID, Address address,
+ SymbolType symbolType, boolean isPrimary, SourceType source) {
+
+ long nextID = symbolTable.getKey();
+
+ // Avoid key 0, as it is reserved for the global namespace
+ if (nextID == 0) {
+ nextID++;
+ }
+
+ long addressKey = addrMap.getKey(address, true);
+
+ DBRecord rec = symbolTable.getSchema().createRecord(nextID);
+ rec.setString(V6_SYMBOL_NAME_COL, name);
+ rec.setLongValue(V6_SYMBOL_ADDR_COL, addressKey);
+ rec.setLongValue(V6_SYMBOL_PARENT_ID_COL, namespaceID);
+ rec.setByteValue(V6_SYMBOL_TYPE_COL, symbolType.getID());
+ rec.setByteValue(V6_SYMBOL_FLAGS_COL, getSourceTypeFlagsBits(source)); // assume non-pinned
+
+ // Sparse columns - these columns don't apply to all symbols.
+ // they default to null unless specifically set. Null values don't consume space.
+
+ rec.setField(V6_SYMBOL_HASH_COL, computeLocatorHash(name, namespaceID, addressKey));
+
+ if (isPrimary) {
+ rec.setLongValue(V6_SYMBOL_PRIMARY_COL, addressKey);
+ }
+
+ return rec;
+ }
+
+ @Override
+ void removeSymbol(long symbolID) throws IOException {
+ symbolTable.deleteRecord(symbolID);
+ }
+
+ @Override
+ boolean hasSymbol(Address addr) throws IOException {
+ long key = addrMap.getKey(addr, false);
+ if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
+ return false;
+ }
+ return symbolTable.hasRecord(new LongField(key), V6_SYMBOL_ADDR_COL);
+ }
+
+ @Override
+ Field[] getSymbolIDs(Address addr) throws IOException {
+ long key = addrMap.getKey(addr, false);
+ if (key == AddressMap.INVALID_ADDRESS_KEY && !addr.equals(Address.NO_ADDRESS)) {
+ return Field.EMPTY_ARRAY;
+ }
+ return symbolTable.findRecords(new LongField(key), V6_SYMBOL_ADDR_COL);
+ }
+
+ @Override
+ DBRecord getSymbolRecord(long symbolID) throws IOException {
+ return symbolTable.getRecord(symbolID);
+ }
+
+ @Override
+ int getSymbolCount() {
+ return symbolTable.getRecordCount();
+ }
+
+ @Override
+ RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
+ return new KeyToRecordIterator(symbolTable,
+ new AddressIndexPrimaryKeyIterator(symbolTable, V6_SYMBOL_ADDR_COL, addrMap, forward));
+ }
+
+ @Override
+ RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
+ return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
+ V6_SYMBOL_ADDR_COL, addrMap, startAddr, forward));
+ }
+
+ @Override
+ void updateSymbolRecord(DBRecord record) throws IOException {
+ // make sure hash is updated to current name and name space
+ String name = record.getString(V6_SYMBOL_NAME_COL);
+ long namespaceId = record.getLongValue(V6_SYMBOL_PARENT_ID_COL);
+ long addressKey = record.getLongValue(V6_SYMBOL_ADDR_COL);
+ record.setField(V6_SYMBOL_HASH_COL, computeLocatorHash(name, namespaceId, addressKey));
+ symbolTable.putRecord(record);
+ }
+
+ @Override
+ RecordIterator getSymbols() throws IOException {
+ return symbolTable.iterator();
+ }
+
+ @Override
+ RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
+ return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
+ V6_SYMBOL_ADDR_COL, addrMap, start, end, forward));
+ }
+
+ @Override
+ RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
+ return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
+ V6_SYMBOL_ADDR_COL, addrMap, set, forward));
+ }
+
+ @Override
+ protected RecordIterator getPrimarySymbols(AddressSetView set, boolean forward)
+ throws IOException {
+ return new KeyToRecordIterator(symbolTable, new AddressIndexPrimaryKeyIterator(symbolTable,
+ V6_SYMBOL_PRIMARY_COL, addrMap, set, forward));
+ }
+
+ @Override
+ protected DBRecord getPrimarySymbol(Address address) throws IOException {
+ AddressIndexPrimaryKeyIterator it = new AddressIndexPrimaryKeyIterator(symbolTable,
+ V6_SYMBOL_PRIMARY_COL, addrMap, address, address, true);
+ if (it.hasNext()) {
+ return symbolTable.getRecord(it.next());
+ }
+ return null;
+ }
+
+ void deleteExternalEntries(Address start, Address end) throws IOException {
+ AddressRecordDeleter.deleteRecords(symbolTable, V6_SYMBOL_ADDR_COL, addrMap, start, end,
+ null);
+ }
+
+ @Override
+ void moveAddress(Address oldAddr, Address newAddr) throws IOException {
+ LongField oldKey = new LongField(addrMap.getKey(oldAddr, false));
+ long newKey = addrMap.getKey(newAddr, true);
+ Field[] keys = symbolTable.findRecords(oldKey, V6_SYMBOL_ADDR_COL);
+ for (Field key : keys) {
+ DBRecord rec = symbolTable.getRecord(key);
+ rec.setLongValue(V6_SYMBOL_ADDR_COL, newKey);
+ symbolTable.putRecord(rec);
+ }
+ }
+
+ @Override
+ Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
+ throws CancelledException, IOException {
+
+ AnchoredSymbolRecordFilter filter = new AnchoredSymbolRecordFilter();
+ AddressRecordDeleter.deleteRecords(symbolTable, V6_SYMBOL_ADDR_COL, addrMap, startAddr,
+ endAddr, filter);
+
+ return filter.getAddressesForSkippedRecords();
+ }
+
+ @Override
+ RecordIterator getSymbolsByNamespace(long id) throws IOException {
+ LongField field = new LongField(id);
+ return symbolTable.indexIterator(V6_SYMBOL_PARENT_ID_COL, field, field, true);
+ }
+
+ @Override
+ RecordIterator getSymbolsByLibrary(long libraryID) throws IOException {
+ LongField field = new LongField(libraryID);
+ return symbolTable.indexIterator(V6_SYMBOL_LIBRARY_ID_COL, field, field, true);
+ }
+
+ @Override
+ RecordIterator getSymbolsByName(String name) throws IOException {
+ StringField field = new StringField(name);
+ return symbolTable.indexIterator(V6_SYMBOL_NAME_COL, field, field, true);
+ }
+
+ @Override
+ RecordIterator scanSymbolsByName(String startName) throws IOException {
+ StringField field = new StringField(startName);
+ return symbolTable.indexIterator(V6_SYMBOL_NAME_COL, field, null, true);
+ }
+
+ @Override
+ RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
+ StringField extLabelField = new StringField(extLabel);
+ return symbolTable.indexIterator(V6_SYMBOL_ORIGINAL_IMPORTED_NAME_COL, extLabelField,
+ extLabelField, true);
+ }
+
+ @Override
+ RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
+ StringField addrField = new StringField(extProgAddr.toString());
+ return symbolTable.indexIterator(V6_SYMBOL_EXTERNAL_PROG_ADDR_COL, addrField, addrField,
+ true);
+ }
+
+ @Override
+ RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
+ // create a range of hash fields for all symbols with this name and namespace id over all
+ // possible addresses
+ Field start = computeLocatorHash(name, id, MIN_ENCODED_ADDRESS);
+ if (start == null) {
+ return EmptyRecordIterator.INSTANCE;
+ }
+
+ Field end = computeLocatorHash(name, id, MAX_ENCODED_ADDRESS);
+
+ RecordIterator it = symbolTable.indexIterator(V6_SYMBOL_HASH_COL, start, end, true);
+ return getNameAndNamespaceFilterIterator(name, id, it);
+ }
+
+ @Override
+ DBRecord getSymbolRecord(Address address, String name, long namespaceId) throws IOException {
+ long addressKey = addrMap.getKey(address, false);
+ Field search = computeLocatorHash(name, namespaceId, addressKey);
+ if (search == null) {
+ return null;
+ }
+ RecordIterator it = symbolTable.indexIterator(V6_SYMBOL_HASH_COL, search, search, true);
+ RecordIterator filtered =
+ getNameNamespaceAddressFilterIterator(name, namespaceId, addressKey, it);
+ if (filtered.hasNext()) {
+ return filtered.next();
+ }
+ return null;
+ }
+
+ @Override
+ Address getMaxSymbolAddress(AddressSpace space) throws IOException {
+ if (space.isMemorySpace()) {
+ AddressIndexKeyIterator addressKeyIterator = new AddressIndexKeyIterator(symbolTable,
+ V6_SYMBOL_ADDR_COL, addrMap, space.getMinAddress(), space.getMaxAddress(), false);
+ if (addressKeyIterator.hasNext()) {
+ return addrMap.decodeAddress(addressKeyIterator.next());
+ }
+ }
+ else {
+ LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
+ DBFieldIterator iterator =
+ symbolTable.indexFieldIterator(null, max, false, V6_SYMBOL_ADDR_COL);
+ if (iterator.hasPrevious()) {
+ LongField val = (LongField) iterator.previous();
+ Address addr = addrMap.decodeAddress(val.getLongValue());
+ if (space.equals(addr.getAddressSpace())) {
+ return addr;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ Table getTable() {
+ return symbolTable;
+ }
+
+ @Override
+ protected int getVersion() {
+ return VERSION;
+ }
+
+ private class AnchoredSymbolRecordFilter implements RecordFilter {
+ private Set<Address> set = new HashSet<Address>();
+
+ @Override
+ public boolean matches(DBRecord record) {
+ // only move symbols whose anchor flag is not on
+ Address addr = addrMap.decodeAddress(record.getLongValue(V6_SYMBOL_ADDR_COL));
+ byte flags = record.getByteValue(V6_SYMBOL_FLAGS_COL);
+ boolean pinned = (flags & SymbolDatabaseAdapter.SYMBOL_PINNED_FLAG) != 0;
+ if (!pinned) {
+ return true;
+ }
+ set.add(addr);
+ return false;
+ }
+
+ Set<Address> getAddressesForSkippedRecords() {
+ return set;
+ }
+ }
+
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java
index 5a1dbee784..5a2c946ba2 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java
@@ -837,40 +837,41 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
if (namespace == null) {
namespace = program.getGlobalNamespace();
}
-
- if (isDeletedNamespace(namespace)) {
- return null;
- }
- checkValidNamespaceArgument(namespace);
-
- long namespaceId = namespace.getID();
-
try (Closeable c = lock.read()) {
- DBRecord record = adapter.getSymbolRecord(address, name, namespaceId);
+ if (isDeletedNamespace(namespace)) {
+ return null;
+ }
+ checkValidNamespaceArgument(namespace);
+
+ DBRecord record = adapter.getSymbolRecord(address, name, namespace.getID());
if (record != null) {
return cache.getCachedInstance(record);
}
- }
- catch (IOException e) {
- program.dbError(e);
- }
- // check for default external symbol
- if (namespace.isExternal() && SymbolUtilities.isPossibleDefaultExternalName(name)) {
- return searchNamespaceForSymbol(namespace, name, address);
- }
+ // also check for possible default parameter or local variable symbol
+ if (namespace instanceof Function &&
+ SymbolUtilities.isPossibleDefaultLocalOrParamName(name)) {
+ return searchNamespaceForSymbol(namespace, name, address);
+ }
- // also check for possible default parameter or local variable symbol
- if (namespace instanceof Function &&
- SymbolUtilities.isPossibleDefaultLocalOrParamName(name)) {
- return searchNamespaceForSymbol(namespace, name, address);
- }
+ // check for default external symbol
+ if (address.isExternalAddress() &&
+ SymbolUtilities.isPossibleDefaultExternalName(name)) {
+ Symbol s = searchNamespaceForSymbol(namespace, name, address);
+ if (s != null) {
+ return s;
+ }
+ }
- // check if name is a default name
- Symbol symbol = getSymbolForDynamicName(name);
- if (symbol != null && address.equals(symbol.getAddress()) &&
- namespace.equals(symbol.getParentNamespace())) {
- return symbol;
+ // check if name is a default name
+ Symbol symbol = getSymbolForDynamicName(name);
+ if (symbol != null && address.equals(symbol.getAddress()) &&
+ namespace.equals(symbol.getParentNamespace())) {
+ return symbol;
+ }
+ }
+ catch (IOException e) {
+ program.dbError(e);
}
return null;
}
@@ -918,38 +919,42 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
List<Symbol> list = new ArrayList<>();
- if (isDeletedNamespace(namespace)) {
- return list;
- }
- checkValidNamespaceArgument(namespace);
+ try (Closeable c = lock.read()) {
- // if name is possible default parameter or local variable name, must do brute force search
- if (namespace instanceof Function &&
- SymbolUtilities.isPossibleDefaultLocalOrParamName(name)) {
- return searchNamespaceForSymbols(name, namespace);
- }
+ if (isDeletedNamespace(namespace)) {
+ return list;
+ }
- // if the name is a possible default external name, do brute force search
- if (namespace.isExternal() && SymbolUtilities.isPossibleDefaultExternalName(name)) {
- return searchNamespaceForSymbols(name, namespace);
- }
+ checkValidNamespaceArgument(namespace);
+
+ // if name is possible default parameter or local variable name, must do brute force search
+ if (namespace instanceof Function &&
+ SymbolUtilities.isPossibleDefaultLocalOrParamName(name)) {
+ return searchNamespaceForSymbols(name, namespace);
+ }
+
+ // if the name is a possible default external name, do brute force search
+ if (SymbolUtilities.isPossibleDefaultExternalName(name)) {
+ List<Symbol> symbols = searchNamespaceForSymbols(name, namespace);
+ if (!symbols.isEmpty()) {
+ return symbols;
+ }
+ }
- try (Closeable c = lock.read()) {
RecordIterator it = adapter.getSymbolsByNameAndNamespace(name, namespace.getID());
while (it.hasNext()) {
list.add(cache.getCachedInstance(it.next()));
}
+
+ // also check if the given name could be a default symbol
+ Symbol symbol = getSymbolForDynamicName(name);
+ if (symbol != null && symbol.getParentNamespace().equals(namespace)) {
+ list.add(symbol);
+ }
}
catch (IOException e) {
program.dbError(e);
}
-
- // also check if the given name could be a default symbol
- Symbol symbol = getSymbolForDynamicName(name);
- if (symbol != null && symbol.getParentNamespace().equals(namespace)) {
- list.add(symbol);
- }
-
return list;
}
@@ -1004,8 +1009,11 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
// if the name is a possible default external name, do brute force search
- if (namespace.isExternal() && SymbolUtilities.isPossibleDefaultExternalName(name)) {
- return searchNamespaceForFirstSymbol(name, namespace, test);
+ if (SymbolUtilities.isPossibleDefaultExternalName(name)) {
+ Symbol s = searchNamespaceForFirstSymbol(name, namespace, test);
+ if (s != null) {
+ return s;
+ }
}
try (Closeable c = lock.read()) {
@@ -1036,16 +1044,17 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
* @param extLabel external original import name
* @return external symbol iterator
*/
+ @Override
public SymbolIterator getExternalSymbolByOriginalImportName(Library library, String extLabel) {
- if (library != null) {
- checkValidNamespaceArgument(library);
- }
try (Closeable c = lock.read()) {
+ if (library != null) {
+ checkValidLibrary(library);
+ }
long matchLibraryId = library != null ? library.getID() : -1;
RecordIterator recordIter = adapter.getExternalSymbolsByOriginalImportName(extLabel);
return new SymbolRecordConstraintIterator(recordIter, rec -> {
if (matchLibraryId > 0) {
- long parentId = rec.getLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL);
+ long parentId = rec.getLongValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL);
if (parentId == matchLibraryId) {
return true;
}
@@ -1073,10 +1082,10 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
if (extProgAddr == null || !extProgAddr.isLoadedMemoryAddress()) {
return SymbolIterator.EMPTY_ITERATOR;
}
- if (library != null) {
- checkValidNamespaceArgument(library);
- }
try (Closeable c = lock.read()) {
+ if (library != null) {
+ checkValidLibrary(library);
+ }
long matchLibraryId = library != null ? library.getID() : -1;
RecordIterator recordIter = adapter.getExternalSymbolsByMemoryAddress(extProgAddr);
return new SymbolRecordConstraintIterator(recordIter, rec -> {
@@ -1100,11 +1109,13 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
@Override
public Namespace getNamespace(String name, Namespace namespace) {
- List<Symbol> symbols = getSymbols(name, namespace);
- for (Symbol symbol : symbols) {
- SymbolType symbolType = symbol.getSymbolType();
- if (symbolType.isNamespace() && !symbolType.allowsDuplicates()) {
- return (Namespace) symbol.getObject();
+ try (Closeable c = lock.read()) {
+ List<Symbol> symbols = getSymbols(name, namespace);
+ for (Symbol symbol : symbols) {
+ SymbolType symbolType = symbol.getSymbolType();
+ if (symbolType.isNamespace() && !symbolType.allowsDuplicates()) {
+ return (Namespace) symbol.getObject();
+ }
}
}
return null;
@@ -1112,16 +1123,30 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
@Override
public SymbolIterator getSymbols(Namespace namespace) {
- if (isDeletedNamespace(namespace)) {
- return SymbolIterator.EMPTY_ITERATOR;
+ try (Closeable c = lock.read()) {
+ if (isDeletedNamespace(namespace)) {
+ return SymbolIterator.EMPTY_ITERATOR;
+ }
+ checkValidNamespaceArgument(namespace);
+ return getSymbols(namespace.getID());
}
- checkValidNamespaceArgument(namespace);
- return getSymbols(namespace.getID());
+ }
+
+ @Override
+ public SymbolIterator getSymbols(Library library) {
+ try (Closeable c = lock.read()) {
+ RecordIterator it = adapter.getSymbolsByLibrary(library.getID());
+ return new SymbolRecordIterator(it, false, true);
+ }
+ catch (IOException e) {
+ program.dbError(e);
+ }
+ return null;
}
@Override
public SymbolIterator getSymbols(long namespaceID) {
- try {
+ try (Closeable c = lock.read()) {
RecordIterator it = adapter.getSymbolsByNamespace(namespaceID);
return new SymbolRecordIterator(it, false, true);
}
@@ -1215,7 +1240,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
* @param space address space
* @return maximum symbol address within space or null if none are found.
*/
- public Address getMaxSymbolAddress(AddressSpace space) {
+ private Address getMaxSymbolAddress(AddressSpace space) {
try {
return adapter.getMaxSymbolAddress(space);
}
@@ -1230,7 +1255,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
*
* @return the address
*/
- public Address getNextExternalSymbolAddress() {
+ private Address getNextExternalSymbolAddress() {
int extID = 1;
Address maxAddr = getMaxSymbolAddress(AddressSpace.EXTERNAL_SPACE);
if (maxAddr != null) {
@@ -2611,9 +2636,8 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
throw new IllegalArgumentException("Invalid symbol type for variable: " + type);
}
- checkValidNamespaceArgument(function);
-
try (Closeable c = lock.write()) {
+ checkValidNamespaceArgument(function);
source = adjustSourceTypeIfNecessary(name, type, source, storage);
Address varAddr = variableStorageMgr.getVariableStorageAddress(storage, true);
DBRecord record =
@@ -2678,7 +2702,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
checkValidNamespaceArgument(namespace);
- if (namespace.isGlobal() || namespace.isLibrary()) {
+ if (namespace.isGlobal()) {
throw new IllegalArgumentException(
"May not convert namespace to class: " + namespace.getName(true));
}
@@ -2763,14 +2787,14 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
try (Closeable c = lock.write()) {
DBRecord record = doCreateBasicSymbolRecord(name, null, Address.NO_ADDRESS,
SymbolType.LIBRARY, false, source, true);
-
+
List<LibrarySymbol> librarySymbolList = new ArrayList<>(getLibrarySymbolList());
int ordinal = librarySymbolList.size();
- if (Library.UNKNOWN.equals(name)) {
+ if (Library.UNKNOWN.equals(name)) {
// UNKNOWN Library always assigned ordinal of 0
ordinal = 0;
}
-
+
LibrarySymbol newLibSymbol = new LibrarySymbol(this, record);
LibrarySymbol.setRecordFields(record, ordinal, pathname);
adapter.updateSymbolRecord(record);
@@ -2778,7 +2802,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
librarySymbolList.add(ordinal, newLibSymbol);
assignLibraryOrdinals(librarySymbolList, true);
-
+
symbolAdded(newLibSymbol);
return newLibSymbol;
}
@@ -2860,7 +2884,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
assignLibraryOrdinals(libSymList, false);
}
-
+
/**
* Update library symbol ordinal to reflect current placement within ordered list.
* The cached {@code libSymbolList} will be updated to refer to the list instance provided.
@@ -3038,11 +3062,12 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
/**
- * Internal method for creating external data/code symbol.
+ * Internal method for creating external data/code symbol using the next available external
+ * address. This method is used to create a completely new external location.
* <p>
* NOTE: Any name conflict concerns must be checked before invoking this method.
+ * @param library the library containing with this external symbol
*
- * @param addr the address for the new symbol
* @param name the name of the new symbol
* @param namespace the namespace for the new symbol (null may be specified for global
* namespace)
@@ -3053,25 +3078,51 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
* @throws IOException if IO error occurs
* @throws InvalidInputException if the name contains illegal characters (i.e. space)
*/
- public CodeSymbol createExternalCodeSymbol(Address addr, String name, Namespace namespace,
- SourceType source, String originalImportName, Address externalProgramAddress)
- throws IOException, InvalidInputException {
- if (!addr.isExternalAddress()) {
+ public CodeSymbol createExternalCodeSymbol(Library library, String name,
+ Namespace namespace, SourceType source, String originalImportName,
+ Address externalProgramAddress) throws IOException, InvalidInputException {
+ lock.expectWriteLock();
+ Address externalSpaceAddress = getNextExternalSymbolAddress();
+ return createExternalCodeSymbol(library, externalSpaceAddress, name, namespace, source,
+ originalImportName, externalProgramAddress);
+ }
+
+ /**
+ * Internal method for creating external data/code symbol using a given external address.
+ * <p>
+ * NOTE: Any name conflict concerns must be checked before invoking this method.
+ * @param library the library containing with this external symbol
+ *
+ * @param externalSpaceAddress the address for the new symbol
+ * @param name the name of the new symbol
+ * @param namespace the namespace for the new symbol (null may be specified for global
+ * namespace)
+ * @param source the SourceType of the new symbol
+ * @param externalProgramAddress associated external program memory address (may be null)
+ * @param originalImportName original imported name (i.e., mangled name)
+ * @return the new symbol
+ * @throws IOException if IO error occurs
+ * @throws InvalidInputException if the name contains illegal characters (i.e. space)
+ */
+ public CodeSymbol createExternalCodeSymbol(Library library, Address externalSpaceAddress,
+ String name, Namespace namespace, SourceType source, String originalImportName,
+ Address externalProgramAddress) throws IOException, InvalidInputException {
+ lock.expectWriteLock();
+ checkValidLibrary(library);
+ if (!externalSpaceAddress.isExternalAddress()) {
throw new IllegalArgumentException("External address required");
}
- if (!namespace.isExternal()) {
- throw new IllegalArgumentException("External namespace required");
- }
- if (externalProgramAddress != null && !externalProgramAddress.isLoadedMemoryAddress()) {
- throw new IllegalArgumentException("Memory address required for external program");
- }
+ checkExternalAddress(externalProgramAddress);
try {
- DBRecord record = doCreateBasicSymbolRecord(name, namespace, addr, SymbolType.LABEL,
- true, source, false);
- MemorySymbol.setExternalFields(record, originalImportName, externalProgramAddress);
+ DBRecord record =
+ doCreateBasicSymbolRecord(name, namespace, externalSpaceAddress, SymbolType.LABEL,
+ true, source, false);
+ MemorySymbol.setExternalFields(record, library, originalImportName,
+ externalProgramAddress);
adapter.updateSymbolRecord(record);
- CodeSymbol newSymbol = new CodeSymbol(this, addr, record, record.getKey());
+ CodeSymbol newSymbol =
+ new CodeSymbol(this, externalSpaceAddress, record, record.getKey());
cache.add(newSymbol);
symbolAdded(newSymbol);
@@ -3083,11 +3134,12 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
/**
- * Internal method for creating external function symbol.
+ * Internal method for creating external function symbol using the next available external
+ * address.
* <p>
* NOTE: Any name conflict concerns must be checked before invoking this method.
+ * @param library the library containing this external symbol
*
- * @param addr the address for the new symbol
* @param name the name of the new symbol
* @param namespace the namespace for the new symbol (null may be specified for global
* namespace)
@@ -3098,24 +3150,59 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
* @throws IOException if IO error occurs
* @throws InvalidInputException if the name contains illegal characters (i.e. space)
*/
- public FunctionSymbol createExternalFunctionSymbol(Address addr, String name,
- Namespace namespace, SourceType source, String originalImportName,
+ public FunctionSymbol createExternalFunctionSymbol(Library library,
+ String name, Namespace namespace, SourceType source, String originalImportName,
Address externalProgramAddress) throws IOException, InvalidInputException {
- if (!addr.isExternalAddress()) {
+ lock.expectWriteLock();
+ Address externalSpaceAddress = getNextExternalSymbolAddress();
+ return createExternalFunctionSymbol(library, externalSpaceAddress, name, namespace, source,
+ originalImportName, externalProgramAddress);
+ }
+
+ /**
+ * Internal method for creating external function symbol using a given external address. This
+ * methods is used when converting a label external location to a function external location
+ * <p>
+ * NOTE: Any name conflict concerns must be checked before invoking this method.
+ * @param library the library containing this external symbol
+ *
+ * @param externalSpaceAddress the address for the new symbol
+ * @param name the name of the new symbol
+ * @param namespace the namespace for the new symbol (null may be specified for global
+ * namespace)
+ * @param source the SourceType of the new symbol
+ * @param externalProgramAddress associated external program memory address (may be null)
+ * @param originalImportName original imported name (i.e., mangled name)
+ * @return the new symbol
+ * @throws IOException if IO error occurs
+ * @throws InvalidInputException if the name contains illegal characters (i.e. space)
+ */
+ public FunctionSymbol createExternalFunctionSymbol(Library library,
+ Address externalSpaceAddress, String name, Namespace namespace, SourceType source,
+ String originalImportName,
+ Address externalProgramAddress) throws IOException, InvalidInputException {
+ if (!externalSpaceAddress.isExternalAddress()) {
throw new IllegalArgumentException("External address required");
}
- if (externalProgramAddress != null && !externalProgramAddress.isLoadedMemoryAddress()) {
- throw new IllegalArgumentException("Memory address required for external program");
- }
+ lock.expectWriteLock();
+ checkValidLibrary(library);
+
+ checkExternalAddress(externalProgramAddress);
try {
- DBRecord record = doCreateBasicSymbolRecord(name, namespace, addr, SymbolType.FUNCTION,
+ DBRecord record = doCreateBasicSymbolRecord(name, namespace, externalSpaceAddress,
+ SymbolType.FUNCTION,
true, source, false);
- MemorySymbol.setExternalFields(record, originalImportName, externalProgramAddress);
+ MemorySymbol.setExternalFields(record, library, originalImportName,
+ externalProgramAddress);
adapter.updateSymbolRecord(record);
- FunctionSymbol newSymbol = new FunctionSymbol(this, addr, record);
+ FunctionSymbol newSymbol = new FunctionSymbol(this, externalSpaceAddress, record);
cache.add(newSymbol);
symbolAdded(newSymbol);
+
+ FunctionManagerDB functionMgr = getFunctionManager();
+ functionMgr.createExternalFunction(newSymbol);
+
return newSymbol;
}
catch (DuplicateNameException e) {
@@ -3186,6 +3273,7 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
if (!addr.isMemoryAddress()) {
throw new IllegalArgumentException("memory address required");
}
+ lock.expectWriteLock();
namespace = validateNamespace(namespace, addr, SymbolType.FUNCTION);
source = validateSource(source, name, addr, SymbolType.FUNCTION);
@@ -3371,40 +3459,38 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
throw new IllegalArgumentException(
"Invalid address specified for new " + type + " symbol: " + addr);
}
-
- boolean isExternal = isExternal(type, addr, parentNamespace);
-
- if (!type.isValidParent(program, parentNamespace, addr, isExternal)) {
- throw new InvalidInputException("Invalid parent namespace specified " + "for new " +
+ if (!type.isValidParent(program, parentNamespace, addr)) {
+ throw new InvalidInputException("Invalid parent namespace specified for new " +
type + " symbol: " + parentNamespace.getName(true));
}
}
- private boolean isExternal(SymbolType type, Address addr, Namespace parentNamespace) {
- if (type == SymbolType.LABEL || type == SymbolType.FUNCTION) {
- return addr.isExternalAddress();
- }
- return parentNamespace.isExternal();
- }
-
@Override
public Symbol getClassSymbol(String name, Namespace namespace) {
- return getSpecificSymbol(name, namespace, SymbolType.CLASS);
+ try (Closeable c = lock.read()) {
+ return getSpecificSymbol(name, namespace, SymbolType.CLASS);
+ }
}
@Override
public Symbol getParameterSymbol(String name, Namespace namespace) {
- return getSpecificSymbol(name, namespace, SymbolType.PARAMETER);
+ try (Closeable c = lock.read()) {
+ return getSpecificSymbol(name, namespace, SymbolType.PARAMETER);
+ }
}
@Override
public Symbol getLocalVariableSymbol(String name, Namespace namespace) {
- return getSpecificSymbol(name, namespace, SymbolType.LOCAL_VAR);
+ try (Closeable c = lock.read()) {
+ return getSpecificSymbol(name, namespace, SymbolType.LOCAL_VAR);
+ }
}
@Override
public Symbol getNamespaceSymbol(String name, Namespace namespace) {
- return getSpecificSymbol(name, namespace, SymbolType.NAMESPACE);
+ try (Closeable c = lock.read()) {
+ return getSpecificSymbol(name, namespace, SymbolType.NAMESPACE);
+ }
}
@Override
@@ -3439,6 +3525,19 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
}
}
+ public void checkValidLibrary(Library library) throws IllegalArgumentException {
+ if (!isMyLibrary(library)) {
+ throw new IllegalArgumentException(
+ "Library is from a different program instance: " + library.getName());
+ }
+ }
+
+ boolean isMyLibrary(Library library) {
+ Symbol librarySymbol = library.getSymbol();
+ return librarySymbol != null && !librarySymbol.isDeleted() &&
+ (librarySymbol.getProgram() == getProgram());
+ }
+
boolean isMyNamespace(Namespace namespace) {
Symbol newNamespaceSymbol = namespace.getSymbol();
return newNamespaceSymbol != null && !newNamespaceSymbol.isDeleted() &&
@@ -3454,6 +3553,22 @@ public class SymbolManager implements SymbolTable, ProgramDBModule {
return cache.getCachedInstance(rec);
}
+ public void checkExternalAddress(Address extAddr) throws InvalidInputException {
+ if (extAddr != null) {
+ if (!extAddr.isLoadedMemoryAddress()) {
+ throw new InvalidInputException("Invalid memory address: " + extAddr);
+ }
+ AddressSpace space = extAddr.getAddressSpace();
+ if (space.isOverlaySpace()) {
+ throw new InvalidInputException("Overlay address not permitted");
+ }
+ if (!space.equals(program.getAddressFactory().getAddressSpace(space.getName()))) {
+ throw new InvalidInputException(
+ "Memory address not defined for program: " + extAddr);
+ }
+ }
+ }
+
private class SymbolFactory implements DbFactory<SymbolDB> {
@Override
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/VariableSymbolDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/VariableSymbolDB.java
index a731948ebe..b05d7e629f 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/VariableSymbolDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/VariableSymbolDB.java
@@ -159,6 +159,12 @@ public class VariableSymbolDB extends SymbolDB {
return parentSymbol != null ? parentSymbol.isExternal() : false;
}
+ @Override
+ public Library getLibrary() {
+ Symbol parentSymbol = getParentSymbol();
+ return parentSymbol != null ? parentSymbol.getLibrary() : null;
+ }
+
public FunctionDB getFunction() {
return (FunctionDB) symbolMgr.getFunctionManager()
.getFunction(getParentNamespace().getID());
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalNamespace.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalNamespace.java
index dc25dabfa7..567e8971f7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalNamespace.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalNamespace.java
@@ -124,11 +124,6 @@ public class GlobalNamespace implements Namespace {
throw new InvalidInputException("Can't parent this namespace");
}
- @Override
- public boolean isExternal() {
- return false;
- }
-
@Override
public int hashCode() {
return getClass().hashCode();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalSymbol.java
index 5d79240d33..d54382efe7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/GlobalSymbol.java
@@ -15,8 +15,7 @@
*/
package ghidra.program.model.address;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@@ -230,4 +229,8 @@ public class GlobalSymbol implements Symbol {
return true;
}
+ @Override
+ public Library getLibrary() {
+ return null;
+ }
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
index b88d111d8c..3786e0e7e0 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
@@ -709,7 +709,6 @@ public interface Function extends Namespace {
/**
* @return true if this function is external (i.e., entry point is in EXTERNAL address space)
*/
- @Override
public boolean isExternal();
/**
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Library.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Library.java
index f55ecc2076..513d93bd25 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Library.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Library.java
@@ -15,20 +15,35 @@
*/
package ghidra.program.model.listing;
-import ghidra.program.model.symbol.*;
+import ghidra.program.model.symbol.Symbol;
+import ghidra.program.model.symbol.SymbolType;
import ghidra.util.exception.InvalidInputException;
/**
* Interface for a Library dependency and namespace.
*/
-public interface Library extends Namespace {
+public interface Library {
public static final String UNKNOWN = "<EXTERNAL>";
- @Override
- public default Type getType() {
- return Type.LIBRARY;
- }
+ /**
+ * {@return the simple namespace name (without parent path)}
+ * <p>
+ * See {@link #getName(boolean)} for the namespace-qualified variant.
+ */
+ public String getName();
+
+ /**
+ * Return the library id
+ * @return the library id
+ */
+ public long getID();
+
+ /**
+ * Get the symbol for this namespace.
+ * @return the symbol for this namespace.
+ */
+ public Symbol getSymbol();
/**
* @return the associated program file pathname within the project which corresponds to this library.
@@ -57,17 +72,7 @@ public interface Library extends Namespace {
if (symbol.getSymbolType() == SymbolType.LIBRARY) {
return (Library) symbol.getObject();
}
- if (symbol.getSymbolType() == SymbolType.NAMESPACE ||
- symbol.getSymbolType() == SymbolType.CLASS) {
- while (symbol != null && symbol.isExternal()) {
- Namespace n = (Namespace) symbol.getObject();
- if (n instanceof Library lib) {
- return lib;
- }
- symbol = n.getParentNamespace().getSymbol();
- }
- }
- return null;
+ return symbol.getLibrary();
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java
index 21ef7b438f..b898241516 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java
@@ -576,19 +576,6 @@ public class HighFunction extends PcodeSyntaxTree {
return res;
}
- /**
- * The decompiler treats some namespaces as equivalent to the "global" namespace.
- * Return true if the given namespace is treated as equivalent.
- * @param namespace is the namespace
- * @return true if equivalent
- */
- static final public boolean collapseToGlobal(Namespace namespace) {
- if (namespace instanceof Library) {
- return true;
- }
- return false;
- }
-
/**
* Encode &lt;parent&gt; element to the stream describing the formal path elements
* from the root (global) namespace up to the given namespace
@@ -605,9 +592,6 @@ public class HighFunction extends PcodeSyntaxTree {
Namespace curspc = namespace;
while (curspc != null) {
arr.add(0, curspc);
- if (collapseToGlobal(curspc)) {
- break; // Treat library namespace as root
- }
curspc = curspc.getParentNamespace();
}
encoder.openElement(ELEM_VAL); // Force global scope to have empty name
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java
index 90c81bed86..00e634ed2f 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java
@@ -354,10 +354,7 @@ public class LocalSymbolMap {
encoder.writeString(ATTRIB_LABEL, altName);
}
encoder.openElement(ELEM_PARENT);
- long parentid = Namespace.GLOBAL_NAMESPACE_ID;
- if (!HighFunction.collapseToGlobal(namespace)) {
- parentid = namespace.getID();
- }
+ long parentid = namespace == null ? Namespace.GLOBAL_NAMESPACE_ID : namespace.getID();
encoder.writeUnsignedInteger(ATTRIB_ID, parentid);
encoder.closeElement(ELEM_PARENT);
encoder.openElement(ELEM_RANGELIST); // Empty address range
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalLocation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalLocation.java
index 0f71e77c3b..6f9c02e98b 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalLocation.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalLocation.java
@@ -19,6 +19,7 @@ import ghidra.app.util.SymbolPath;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.Function;
+import ghidra.program.model.listing.Library;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@@ -42,6 +43,11 @@ public interface ExternalLocation {
*/
public String getLibraryName();
+ /**
+ * {@return the external library for this location}
+ */
+ public Library getLibrary();
+
/**
* NOTE: If this external location corresponds to a back-reference this
* may correspond to an application and not a library.
@@ -50,7 +56,7 @@ public interface ExternalLocation {
* null if unknown.
*/
public String getExternalLibraryPath();
-
+
/**
* Returns the parent namespace containing this location.
* @return the parent namespace containing this location.
@@ -113,6 +119,12 @@ public interface ExternalLocation {
public void setLocation(String label, Address addr, SourceType source)
throws DuplicateNameException, InvalidInputException;
+ /**
+ * Sets the library for the external location
+ * @param library the new library for the externalLocation
+ */
+ public void setLibrary(Library library);
+
/**
* @return true if location corresponds to a function
*/
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalManager.java
index 4990ddeda8..5ee76daada 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ExternalManager.java
@@ -25,10 +25,18 @@ import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
/**
- * External manager interface. Defines methods for dealing with external programs and locations
- * within those programs.
+ * External manager interface. Defines methods for dealing with external libraries/programs
+ * and associated {@link ExternalLocation} symbols used to reference locations within them.
+ * When a specific library is unknown, an external location may be associated with the
+ * {@link Library#UNKNOWN} library until a more suitable named library can be identified.
+ * <p>
+ * An {@link ExternalLocation} may be a {@link Function} or a generic location.
+ * <p>
+ * When creating a location with a mangled name it must be created within the global namespace
+ * to ensure that it will be considered for demangling. Once demangled, the original mangled
+ * name gets saved to the location object's
+ * {@link ExternalLocation#getOriginalImportedName() original imported name}.
*/
-
public interface ExternalManager {
/**
@@ -98,7 +106,7 @@ public interface ExternalManager {
*/
public void setExternalPath(String libraryName, String pathname, boolean userDefined)
throws InvalidInputException;
-
+
/**
* {@return the ordinal associated with an external library which represents its
* sequence within the order list of libraries or -1 if library name not found}
@@ -154,31 +162,39 @@ public interface ExternalManager {
/**
* Returns a set of External Locations matching the given label name in the specified Library.
- * If searching for an original import name which should not be constrained to a specific
- * library (e.g., mangled name), null may be specified for the libraryName.
+ * If searching for an original import name, which should not be constrained to a specific
+ * library (e.g., mangled name), null should be specified for the libraryName.
+ * <p>
+ * NOTE: Only those external symbols which are contained within the global namespace will be
+ * included.
*
- * @param libraryName the name of the library
+ * @param libraryName the name of the library (may be null to consider all libraries)
* @param label the name of the label
* @return a list of External Locations matching the given label name in the given Library.
*/
public Set<ExternalLocation> getExternalLocations(String libraryName, String label);
/**
- * Returns a set of External Locations matching the given label name in the given Namespace.
+ * Returns a set of External Locations matching the given label within an optional namespace and library.
* If searching for an original import name which should not be constrained to a specific
- * library (e.g., mangled name), null may be specified for the namespace. If a library
- * sub-namespace is specified the original import name will not be searched.
+ * library (e.g., mangled name), null should be specified for both library and namespace. If a namespace
+ * is specified the original import name will not be searched.
*
- * @param namespace the external Namespace to search or null
+ * @param library the external library (may be null to consider all libraries)
+ * @param namespace the namespace within which the label should be searched for (may be null for global namespace)
* @param label the name of the labels to search for.
* @return a list of External Locations matching the given label name in the given Namespace.
*/
- public Set<ExternalLocation> getExternalLocations(Namespace namespace, String label);
+ public Set<ExternalLocation> getExternalLocations(Library library, Namespace namespace,
+ String label);
/**
* Returns the unique external location associated with the given library name and label.
- * If searching for an original import name which should not be constrained to a specific
- * library (e.g., mangled name), null may be specified for the libraryName.
+ * If searching for an original import name, which should not be constrained to a specific
+ * library (e.g., mangled name), null should be specified for the libraryName.
+ * <p>
+ * NOTE: Only those external symbols which are contained within the global namespace will be
+ * included.
*
* @param libraryName the library name or null
* @param label the label of the external location
@@ -187,16 +203,18 @@ public interface ExternalManager {
public ExternalLocation getUniqueExternalLocation(String libraryName, String label);
/**
- * Returns the unique external location associated with the given namespace and label.
+ * Returns the unique external location associated with the given library, namespace and label.
* If searching for an original import name which should not be constrained to a specific
- * library (e.g., mangled name), null may be specified for the namespace. If a library
- * sub-namespace is specified the original import name will not be searched.
+ * library (e.g., mangled name), null may be specified for the library. If a namespace
+ * is specified the original import name will not be searched.
*
- * @param namespace the namespace or null
+ * @param library the library or null
+ * @param namespace the namespace within which the label should be searched for (may be null for global namespace)
* @param label the label of the external location
* @return the unique external location or null
*/
- public ExternalLocation getUniqueExternalLocation(Namespace namespace, String label);
+ public ExternalLocation getUniqueExternalLocation(Library library, Namespace namespace,
+ String label);
/**
* Returns the external location associated with the given external symbol
@@ -228,9 +246,11 @@ public interface ExternalManager {
throws InvalidInputException, DuplicateNameException;
/**
- * Get or create an external location associated with a library/file named {@code libraryName}
- * and the location within that file identified by {@code extLabel} and/or its memory address
- * {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * Get or create an external location associated with a specified library
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
*
* @param libraryName the external library name
* @param extLabel the external label or null
@@ -247,11 +267,13 @@ public interface ExternalManager {
SourceType sourceType) throws InvalidInputException, DuplicateNameException;
/**
- * Create an external location in the indicated external parent namespace
- * and identified by {@code extLabel} and/or its memory address
- * {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * Get or create an external location associated with a specified library
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
*
- * @param extNamespace the external namespace
+ * @param library The external library
* @param extLabel the external label or null
* @param extAddr the external memory address or null
* @param sourceType the source type of this external library's symbol
@@ -261,33 +283,91 @@ public interface ExternalManager {
* Neither {@code extLabel} nor {@code extAddr} was specified properly.
* @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
*/
- public ExternalLocation addExtLocation(Namespace extNamespace, String extLabel, Address extAddr,
- SourceType sourceType) throws InvalidInputException;
+ public default ExternalLocation addExtLocation(Library library, String extLabel,
+ Address extAddr, SourceType sourceType) throws InvalidInputException {
+ return addExtLocation(library, null, extLabel, extAddr, sourceType, true);
+ }
/**
- * Get or create an external location in the indicated external parent namespace
- * and identified by {@code extLabel} and/or its memory address
- * {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * Get or create an external location associated with a specified library and namespace,
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: If the extLabel is null the global or null namespace should be specified.
*
- * @param extNamespace the external namespace
+ * @param library The external library
+ * @param namespace the namespace or null for the global namespace
* @param extLabel the external label or null
* @param extAddr the external memory address or null
* @param sourceType the source type of this external library's symbol
- * @param reuseExisting if true, this will return an existing matching external
- * location instead of creating a new one.
* @return external location
* @throws InvalidInputException if an invalid {@code extlabel} is specified.
* Names with spaces or the empty string are not permitted.
* Neither {@code extLabel} nor {@code extAddr} was specified properly.
* @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
*/
- public ExternalLocation addExtLocation(Namespace extNamespace, String extLabel, Address extAddr,
- SourceType sourceType, boolean reuseExisting) throws InvalidInputException;
+ public default ExternalLocation addExtLocation(Library library, Namespace namespace,
+ String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException {
+ return addExtLocation(library, namespace, extLabel, extAddr, sourceType, true);
+ }
/**
- * Create an external {@link Function} in the external {@link Library} namespace
- * {@code libararyName} and identified by {@code extLabel} and/or its memory address
- * {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * Get or create an external location associated with a specified library and namespace,
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
+ *
+ * @param library the external library
+ * @param extLabel the external label or null
+ * @param extAddr the external memory address or null
+ * @param sourceType the source type of this external library's symbol
+ * @param reuseExisting if true, will return any existing matching location instead of
+ * creating a new one if a suitable match is found. If false, the method will create a
+ * new one as long as an extLabel has been specified.
+ * @return external location
+ * @throws InvalidInputException if an invalid {@code extlabel} is specified.
+ * Names with spaces or the empty string are not permitted.
+ * Neither {@code extLabel} nor {@code extAddr} was specified properly.
+ * @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
+ */
+ public default ExternalLocation addExtLocation(Library library, String extLabel,
+ Address extAddr, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException {
+ return addExtLocation(library, null, extLabel, extAddr, sourceType, reuseExisting);
+ }
+
+ /**
+ * Get or create an external location associated with a specified library and namespace,
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: If the extLabel is null the global or null namespace should be specified.
+ *
+ * @param library the external library
+ * @param namespace the namespace or null for the global namespace
+ * @param extLabel the external label or null
+ * @param extAddr the external memory address or null
+ * @param sourceType the source type of this external library's symbol
+ * @param reuseExisting if true, will return any existing matching location instead of
+ * creating a new one if a suitable match is found. If false, the method will create a
+ * new one as long as an extLabel has been specified.
+ * @return external location
+ * @throws InvalidInputException if an invalid {@code extlabel} is specified.
+ * Names with spaces or the empty string are not permitted.
+ * Neither {@code extLabel} nor {@code extAddr} was specified properly.
+ * @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
+ */
+ public ExternalLocation addExtLocation(Library library, Namespace namespace, String extLabel,
+ Address extAddr, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException;
+
+ /**
+ * Get or create an external {@link Function} location associated with a specified library
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
*
* @param libraryName the external library name
* @param extLabel label within the external program, may be null if extAddr is not null
@@ -304,42 +384,99 @@ public interface ExternalManager {
SourceType sourceType) throws InvalidInputException, DuplicateNameException;
/**
- * Create an external {@link Function} in the indicated external parent namespace
- * and identified by {@code extLabel} and/or its memory address
- * {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * Get or create an external {@link Function} location associated with a specified library
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
+ *
+ * @param library the external library
+ * @param extLabel the external label or null
+ * @param extAddr the external memory address or null
+ * @param sourceType the source type of this external library's symbol
+ * @return external location
+ * @throws InvalidInputException if an invalid {@code extlabel} is specified.
+ * Names with spaces or the empty string are not permitted.
+ * Neither {@code extLabel} nor {@code extAddr} was specified properly.
+ * @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
+ */
+ public default ExternalLocation addExtFunction(Library library, String extLabel,
+ Address extAddr, SourceType sourceType) throws InvalidInputException {
+ return addExtFunction(library, null, extLabel, extAddr, sourceType, true);
+ }
+
+ /**
+ * Get or create an external {@link Function} location associated with a specified library
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: The result location will be created within the global namespace.
*
- * @param extNamespace the external namespace
+ * @param library the external library
* @param extLabel the external label or null
* @param extAddr the external memory address or null
* @param sourceType the source type of this external library's symbol
+ * @param reuseExisting if true, will return any existing matching location instead of
+ * creating a new one if a suitable match is found. If false, the method will create a
+ * new one as long as an extLabel has been specified.
* @return external location
* @throws InvalidInputException if an invalid {@code extlabel} is specified.
* Names with spaces or the empty string are not permitted.
* Neither {@code extLabel} nor {@code extAddr} was specified properly.
* @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
*/
- public ExternalLocation addExtFunction(Namespace extNamespace, String extLabel, Address extAddr,
- SourceType sourceType) throws InvalidInputException;
+ public default ExternalLocation addExtFunction(Library library, String extLabel,
+ Address extAddr, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException {
+ return addExtFunction(library, null, extLabel, extAddr, sourceType, reuseExisting);
+ }
/**
- * Get or create an external {@link Function} in the indicated external parent namespace
+ * Get or create an external {@link Function} location associated with a specified library and namespace,
+ * and identified by {@code extLabel} and/or its memory address {@code extAddr}.
+ * Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: If the extLabel is null the global or null namespace should be specified.
+ *
+ * @param library the external library
+ * @param namespace the namespace or null for the global namespace
+ * @param extLabel the external label or null
+ * @param extAddr the external memory address or null
+ * @param sourceType the source type of this external library's symbol
+ * @return external location
+ * @throws InvalidInputException if an invalid {@code extlabel} is specified.
+ * Names with spaces or the empty string are not permitted.
+ * Neither {@code extLabel} nor {@code extAddr} was specified properly.
+ * @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
+ */
+ public default ExternalLocation addExtFunction(Library library, Namespace namespace,
+ String extLabel, Address extAddr, SourceType sourceType) throws InvalidInputException {
+ return addExtFunction(library, namespace, extLabel, extAddr, sourceType, true);
+ }
+
+ /**
+ * Get or create an external {@link Function} location associated with a specified library and namespace,
* and identified by {@code extLabel} and/or its memory address
* {@code extAddr}. Either or both {@code extLabel} or {@code extAddr} must be specified.
+ * <p>
+ * NOTE: If the extLabel is null the global or null namespace should be specified.
*
- * @param extNamespace the external namespace
+ * @param library the external library
+ * @param namespace the namespace or null for the global namespace
* @param extLabel the external label or null
* @param extAddr the external memory address or null
* @param sourceType the source type of this external library's symbol
* @param reuseExisting if true, will return any existing matching location instead of
- * creating a new one. If false, will prefer to create a new one as long as the specified
- * address is not null and not used in an existing location.
+ * creating a new one if a suitable match is found. If false, the method will create a
+ * new one as long as an extLabel has been specified.
* @return external location
* @throws InvalidInputException if an invalid {@code extlabel} is specified.
* Names with spaces or the empty string are not permitted.
* Neither {@code extLabel} nor {@code extAddr} was specified properly.
* @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
*/
- public ExternalLocation addExtFunction(Namespace extNamespace, String extLabel, Address extAddr,
- SourceType sourceType, boolean reuseExisting) throws InvalidInputException;
+ public ExternalLocation addExtFunction(Library library, Namespace namespace, String extLabel,
+ Address extAddr, SourceType sourceType, boolean reuseExisting)
+ throws InvalidInputException;
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Namespace.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Namespace.java
index 2d800eb21e..707f4ca358 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Namespace.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Namespace.java
@@ -74,12 +74,6 @@ public interface Namespace {
return Type.NAMESPACE;
}
- /**
- * Returns true if this namespace is external (i.e., associated with a Library)
- * @return true if this namespace is external (i.e., associated with a Library)
- */
- public boolean isExternal();
-
/**
* {@return the simple namespace name (without parent path)}
* <p>
@@ -98,20 +92,18 @@ public interface Namespace {
/**
* Get the namespace path as a list of namespace names.
- * @param omitLibrary if true Library name (if applicable) will be
- * omitted from returned list and treated same as global namespace.
* @return namespace path list or empty list for global namespace
*/
- public default List<String> getPathList(boolean omitLibrary) {
+ public default List<String> getPathList() {
if (isGlobal()) {
return Collections.emptyList();
}
- ArrayDeque<String> list = new ArrayDeque<>();
- for (Namespace n = this; !n.isGlobal() && !(omitLibrary && n.isLibrary()); n =
- n.getParentNamespace()) {
- list.addFirst(n.getName());
+ List<String> list = new ArrayList<>();
+ for (Namespace n = this; !n.isGlobal(); n = n.getParentNamespace()) {
+ list.add(n.getName());
}
- return List.copyOf(list);
+ Collections.reverse(list);
+ return list;
}
/**
@@ -153,14 +145,4 @@ public interface Namespace {
public default boolean isGlobal() {
return getID() == GLOBAL_NAMESPACE_ID;
}
-
- /**
- * Return true if this is a library
- * @return true if this is a library
- */
- public default boolean isLibrary() {
- Symbol s = getSymbol();
- return s != null && s.getSymbolType() == SymbolType.LIBRARY;
- }
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ReferenceManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ReferenceManager.java
index a01651cb39..f5eb973ae1 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ReferenceManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/ReferenceManager.java
@@ -156,12 +156,14 @@ public interface ReferenceManager {
throws InvalidInputException, DuplicateNameException;
/**
- * Adds an external reference. If a reference already
- * exists for the fromAddr and opIndex, the existing reference is replaced
- * with the new reference.
+ * Adds an external reference. If a reference already exists for the fromAddr and
+ * opIndex, the existing reference is replaced with the new reference. If an
+ * existing matching external location is found it will be referenced, if not a
+ * new one will be created.
*
* @param fromAddr from memory address (source of the reference)
- * @param extNamespace external namespace containing the named external label.
+ * @param library the external library
+ * @param namespace external namespace containing the named external label.
* @param extLabel label within the external program, may be null if extAddr is not null
* @param extAddr address within the external program, may be null
* @param source the source of this reference
@@ -174,18 +176,18 @@ public interface ReferenceManager {
* @throws DuplicateNameException if another non-Library namespace has the same name
* @throws IllegalArgumentException if an invalid {@code extAddr} was specified.
*/
- public Reference addExternalReference(Address fromAddr, Namespace extNamespace, String extLabel,
+ public Reference addExternalReference(Address fromAddr, Library library, Namespace namespace,
+ String extLabel,
Address extAddr, SourceType source, int opIndex, RefType type)
throws InvalidInputException, DuplicateNameException;
/**
- * Adds an external reference. If a reference already
- * exists for the fromAddr and opIndex, the existing reference is replaced
- * with the new reference.
+ * Adds an external reference. If a reference already exists for the fromAddr and opIndex,
+ * the existing reference(s) is replaced with the new reference.
*
* @param fromAddr from memory address (source of the reference)
* @param opIndex operand index
- * @param location external location
+ * @param location existing external location defined by this manager's program instance
* @param source the source of this reference
* @param type reference type - how the location is being referenced
* @return external reference
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Symbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Symbol.java
index 7664358051..f91fbf9bf8 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Symbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/Symbol.java
@@ -16,8 +16,7 @@
package ghidra.program.model.symbol;
import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.program.util.ProgramLocation;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@@ -237,7 +236,9 @@ public interface Symbol {
public boolean isDynamic();
/**
- * Returns true if this an external symbol.
+ * Returns true if this an external symbol. Note: only function and labels symbols can
+ * be external. Also, all external symbols will have an associated
+ * Library (See {@link #getLibrary()}
*
* @return true if this an external symbol.
* @see Address#isExternalAddress()
@@ -299,4 +300,11 @@ public interface Symbol {
* @return true if symbol has been deleted, false if not.
*/
public boolean isDeleted();
+
+ /**
+ * Returns the library containing this symbol. Note: only external functions or labels can
+ * have an associated Library.
+ * @return the library containing this symbol, or null if the symbol is not external
+ */
+ public Library getLibrary();
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolTable.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolTable.java
index f4dda9b75a..f42a8d1221 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolTable.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolTable.java
@@ -413,6 +413,13 @@ public interface SymbolTable {
*/
public SymbolIterator getSymbols(Namespace namespace);
+ /**
+ * Return an iterator over all symbols in the given library.
+ * @param library the library to get symbols for
+ * @return an iterator over all symbols in the given library
+ */
+ public SymbolIterator getSymbols(Library library);
+
/**
* Get an iterator over all the symbols in the given namespace
* <p>
@@ -514,8 +521,14 @@ public interface SymbolTable {
/**
* Get the external symbol with the given name. The first occurrence of the named symbol found
- * within any external namespace will be returned. If all matching symbols need to be
+ * within any library or namespace will be returned. If all matching symbols need to be
* considered the {@link #getExternalSymbols(String)} should be used.
+ * <p>
+ * NOTE: This does not consider the original import name for a demangled external
+ * symbol which must be searched for separately (see {@link #getExternalSymbolByOriginalImportName(Library, String)}).
+ * <p>
+ * NOTE: Use {@link ExternalManager} API for my flexible external location searching
+ * (see {@link Program#getExternalManager()}).
*
* @param name the name of the symbol
* @return the symbol, or null if no external symbol has that name
@@ -523,13 +536,29 @@ public interface SymbolTable {
public Symbol getExternalSymbol(String name);
/**
- * Get all the external symbols with the given name
+ * Get all the external symbols with the given name within any library or namespace.
+ * <p>
+ * NOTE: This does not consider the original import name for a demangled external
+ * symbol which must be searched for separately (see {@link #getExternalSymbolByOriginalImportName(Library, String)}).
+ * <p>
+ * NOTE: Use {@link ExternalManager} API for my flexible external location searching
+ * (see {@link Program#getExternalManager()}).
*
* @param name the name of symbols
* @return an iterator over the symbols
*/
public SymbolIterator getExternalSymbols(String name);
+ /**
+ * Get all external symbols whose original import name matches the specified extLabel with an
+ * optional constraint on a matching Library.
+ *
+ * @param library optional Library constraint (may be null to ignore).
+ * @param extLabel external original import name
+ * @return external symbol iterator
+ */
+ public SymbolIterator getExternalSymbolByOriginalImportName(Library library, String extLabel);
+
/**
* Get all defined external symbols in no particular order
*
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolType.java
index 7d58fd9f43..c2cb21e469 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolType.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolType.java
@@ -27,18 +27,16 @@ public abstract class SymbolType {
public static final SymbolType LABEL = new SymbolType("Label", false, 0) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
- boolean externalParent = parent.isExternal();
- if (symbolAddr.isExternalAddress() != externalParent) {
- return false;
- }
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
if (parent.getID() != Namespace.GLOBAL_NAMESPACE_ID &&
program != parent.getSymbol().getProgram()) {
return false;
}
// CODE symbol may not have an external function parent
- return !(parent instanceof Function) || !externalParent;
+ if (parent instanceof Function function) {
+ return !function.isExternal();
+ }
+ return true;
}
@Override
@@ -61,10 +59,9 @@ public abstract class SymbolType {
};
- public static final SymbolType LIBRARY = new SymbolType("Library", true, 1) {
+ public static final SymbolType LIBRARY = new SymbolType("Library", false, 1) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
return parent.getID() == Namespace.GLOBAL_NAMESPACE_ID;
}
@@ -82,19 +79,14 @@ public abstract class SymbolType {
public static final SymbolType NAMESPACE = new SymbolType("Namespace", true, 3) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
- // Uses NO_ADDRESS - External address not used
- boolean isExternalParent = parent.isExternal();
- if (isExternalSymbol != isExternalParent) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
+ Symbol parentSymbol = parent.getSymbol();
+ if (parentSymbol.isExternal()) {
return false;
}
- if (parent.getID() != Namespace.GLOBAL_NAMESPACE_ID &&
- program != parent.getSymbol().getProgram()) {
+ if (!parent.isGlobal() && program != parentSymbol.getProgram()) {
return false;
}
- // NAMESPACE can not be contained within a function or a class
- //return !(parent instanceof Function) && !(parent instanceof GhidraClass);
return true;
}
@@ -112,12 +104,7 @@ public abstract class SymbolType {
public static final SymbolType CLASS = new SymbolType("Class", true, 4) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
- // Uses NO_ADDRESS - External address not used
- if (isExternalSymbol != parent.isExternal()) {
- return false;
- }
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
if (parent.getID() != Namespace.GLOBAL_NAMESPACE_ID &&
program != parent.getSymbol().getProgram()) {
return false;
@@ -146,11 +133,8 @@ public abstract class SymbolType {
public static final SymbolType FUNCTION = new SymbolType("Function", true, 5) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
- if (symbolAddr.isExternalAddress() != parent.isExternal()) {
- return false;
- }
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
+
if (parent.getID() != Namespace.GLOBAL_NAMESPACE_ID &&
program != parent.getSymbol().getProgram()) {
return false;
@@ -183,8 +167,7 @@ public abstract class SymbolType {
public static final SymbolType PARAMETER = new SymbolType("Parameter", false, 6) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
if (parent instanceof Function) {
return program == parent.getSymbol().getProgram();
}
@@ -204,10 +187,13 @@ public abstract class SymbolType {
public static final SymbolType LOCAL_VAR = new SymbolType("Local Var", false, 7) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
+ Symbol parentSymbol = parent.getSymbol();
+ if (parentSymbol.isExternal()) {
+ return false;
+ }
if (parent instanceof Function) {
- return program == parent.getSymbol().getProgram();
+ return program == parentSymbol.getProgram();
}
return false;
}
@@ -226,8 +212,7 @@ public abstract class SymbolType {
public static final SymbolType GLOBAL_VAR = new SymbolType("Global Register Var", false, 8) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
return parent.getID() == Namespace.GLOBAL_NAMESPACE_ID;
}
@@ -246,8 +231,7 @@ public abstract class SymbolType {
public static final SymbolType GLOBAL =
new SymbolType(GlobalNamespace.GLOBAL_NAMESPACE_NAME, true, -1) {
@Override
- public boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol) {
+ public boolean isValidParent(Program program, Namespace parent, Address symbolAddr) {
return false;
}
@@ -266,13 +250,13 @@ public abstract class SymbolType {
{ LABEL, LIBRARY, null, NAMESPACE, CLASS, FUNCTION, PARAMETER, LOCAL_VAR, GLOBAL_VAR };
private final String name;
- private final byte value;
+ private final byte id;
private final boolean isNamespace;
- private SymbolType(String name, boolean isNamespace, int value) {
+ private SymbolType(String name, boolean isNamespace, int id) {
this.name = name;
this.isNamespace = isNamespace;
- this.value = (byte) value;
+ this.id = (byte) id;
}
/**
@@ -281,12 +265,10 @@ public abstract class SymbolType {
* @param program the program to contain the symbol
* @param parent the namespace where a symbol will potentially be parented.
* @param symbolAddr the address of they symbol to be parented.
- * @param isExternalSymbol true if the symbol is external.
* @return true if the given namespace is a valid parent for a symbol if it has the
* given address and whether or not it is external.
*/
- public abstract boolean isValidParent(Program program, Namespace parent, Address symbolAddr,
- boolean isExternalSymbol);
+ public abstract boolean isValidParent(Program program, Namespace parent, Address symbolAddr);
/**
* Returns true if the given address is valid for this symbol type.
@@ -314,7 +296,7 @@ public abstract class SymbolType {
}
/**
- * Returns true if this symbol represents a namespace.
+ * {@return true if this symbol represents a namespace}
*/
public boolean isNamespace() {
return isNamespace;
@@ -326,15 +308,16 @@ public abstract class SymbolType {
}
/**
- * Returns the id of this symbol type.
+ * {@return the id of this symbol type}
*/
public byte getID() {
- return value;
+ return id;
}
/**
* Returns the SymbolType for the given id.
* @param id the id for the SymbolType to find.
+ * @return the SymbolType for the given id.
*/
public static SymbolType getSymbolType(int id) {
if (id == -1) {
@@ -352,7 +335,7 @@ public abstract class SymbolType {
int result = 1;
result = prime * result + (isNamespace ? 1231 : 1237);
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + value;
+ result = prime * result + id;
return result;
}
@@ -379,7 +362,7 @@ public abstract class SymbolType {
else if (!name.equals(other.name)) {
return false;
}
- if (value != other.value) {
+ if (id != other.id) {
return false;
}
return true;
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramEvent.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramEvent.java
index 978643ca21..416c1a30da 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramEvent.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramEvent.java
@@ -47,7 +47,8 @@ public enum ProgramEvent implements EventType {
SYMBOL_ANCHOR_FLAG_CHANGED, // a symbol's pinned status was changed
SYMBOL_PRIMARY_STATE_CHANGED, // a symbol primary status changed
SYMBOL_RENAMED, // a symbol was renamed
- SYMBOL_SCOPE_CHANGED, // the set of addresses associated with a symbol changed
+ SYMBOL_SCOPE_CHANGED, // the namespace associated with a symbol changed
+ SYMBOL_LIBRARY_CHANGED, // the library for this symbol changed
SYMBOL_ASSOCIATION_ADDED, // a symbol association was added to a reference
SYMBOL_ASSOCIATION_REMOVED, // a symbol association was removed from a reference
SYMBOL_DATA_CHANGED, // some symbol property was changed
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleDiffUtility.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleDiffUtility.java
index 4672b38b8e..d3171479ad 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleDiffUtility.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleDiffUtility.java
@@ -449,10 +449,11 @@ public class SimpleDiffUtility {
private static class ExternalReferenceCount implements Comparable<ExternalReferenceCount> {
- static final int ADDRESS_RANK = 3;
+ static final int MANGLED_NAME_RANK = 4;
+ static final int ADDRESS_RANK = 2; // penalty for mismatch
static final int NAME_RANK = 2;
- static final int NAMESPACE_RANK = 1;
- static final int MANGLED_NAME_RANK = NAME_RANK + NAMESPACE_RANK;
+ static final int NAMESPACE_RANK = 2; // penalty for mismatch (considered with name match only)
+ static final int LIBRARY_RANK = 1; // considered with name and namespace match only, or mangled name match
final ExternalLocation extLoc;
final ExternalMatchType matchType;
@@ -502,20 +503,55 @@ public class SimpleDiffUtility {
return getSymbol().getName(true).compareTo(other.getSymbol().getName(true));
}
+ private boolean hasMatchingLibrary() {
+ return false;
+ }
+
/**
* Generate relative rank when a non-default name match occurs.
* Method should not be invoked when either location symbol has a default source type.
+ *
+ * Rank values and match criteria
+ *
+ * NOTE: (-) indicates with sub-criteria mismatch
+ * (+) indicates with sub-criteria match
+ *
+ * 2: ADDRESS (only consider if one has default name)
+ * 3: ADDRESS+LIBRARY (only consider if one has default name)
+ *
+ * 2: MANGLED-ADDRESS
+ * 3: MANGLED-ADDRESS+LIBRARY
+ * 4: MANGLED (either has no address)
+ * 5: MANGLED+LIBRARY (either has no address)
+ * 6: MANGLED+ADDRESS
+ * 7: MANGLED+ADDRESS+LIBRARY
+ *
+ * -1: NAME-ADDRESS-NAMESPACE (forced value)
+ * -1: NAME+ADDRESS-NAMESPACE (forced value)
+ *
+ * 2: NAME-ADDRESS+NAMESPACE
+ * 3: NAME-ADDRESS+NAMESPACE+LIBRARY
+ * 4: NAME+NAMESPACE (either has no address)
+ * 5: NAME+NAMESPACE+LIBRARY (either has no address)
+ * 6: NAME+ADDRESS+NAMESPACE
+ * 7: NAME+ADDRESS+NAMESPACE+LIBRARY
+ *
* @param targetAddr
* @param targetNamespace
* @param targetName
* @param targetOrigImportedName
+ * @param targetLibraryName
*/
void setRelativeRank(Address targetAddr, String targetNamespace, String targetName,
- String targetOrigImportedName) {
+ String targetOrigImportedName, String targetLibraryName) {
rank = 0;
if (matchType == ExternalMatchType.ADDRESS) {
+ // Failed to match on name - address match only
rank = ADDRESS_RANK;
+ if (hasMatchingLibrary()) {
+ rank += LIBRARY_RANK;
+ }
return;
}
@@ -539,18 +575,13 @@ public class SimpleDiffUtility {
return;
}
- // Impose mangled name mismatch penalty
- String myOrigImportedName = extLoc.getOriginalImportedName();
- if (targetOrigImportedName != null && myOrigImportedName != null) {
- rank -= MANGLED_NAME_RANK;
- return;
- }
-
- // assume NAME match
rank += NAME_RANK;
- if (targetNamespace != null && targetNamespace.equals(getFullNamespaceName())) {
- rank += NAMESPACE_RANK; // non-default namespace match improves name match
+ if (targetNamespace.equals(getFullNamespaceName())) {
+ rank += NAMESPACE_RANK; // namespace match improves name match
+ }
+ else {
+ rank = -1; // NAME-NAMESPACE (forced rank)
}
}
@@ -583,9 +614,6 @@ public class SimpleDiffUtility {
if (isDefaul1 || isDefaul2) {
return ExternalMatchType.NONE;
}
- if (!extLoc1.getLibraryName().equals(extLoc2.getLibraryName())) {
- return ExternalMatchType.NONE; // assume this prevails over Namespace
- }
String name1 = extLoc1.getLabel();
String name2 = extLoc2.getLabel();
@@ -597,15 +625,18 @@ public class SimpleDiffUtility {
return origName1.equals(origName2) ? ExternalMatchType.MANGLED_NAME
: ExternalMatchType.NONE;
}
- // mangled name must be in root namespace of library
- if (extLoc2.getSymbol().getParentNamespace().isLibrary() && origName1.equals(name2)) {
- return ExternalMatchType.MANGLED_NAME;
+ if (extLoc2.getSymbol().getParentNamespace().isGlobal()) {
+ // extLoc1 was demangled - extLoc2 was not (treat name2 as mangled if in global namespace)
+ return origName1.equals(name2) ? ExternalMatchType.MANGLED_NAME
+ : ExternalMatchType.NONE;
}
}
- else if (origName2 != null && extLoc1.getSymbol().getParentNamespace().isLibrary() &&
- origName2.equals(name1)) {
- return ExternalMatchType.MANGLED_NAME;
+ else if (origName2 != null && extLoc1.getSymbol().getParentNamespace().isGlobal()) {
+ // extLoc2 was demangled - extLoc1 was not (treat name1 as mangled if in global namespace)
+ return origName2.equals(name1) ? ExternalMatchType.MANGLED_NAME
+ : ExternalMatchType.NONE;
}
+ // neither has been demangled, but may not be mangled names
return name1.equals(name2) ? ExternalMatchType.NAME : ExternalMatchType.NONE;
}
@@ -636,7 +667,7 @@ public class SimpleDiffUtility {
}
SymbolType type = symbol.getSymbolType();
if ((type != SymbolType.FUNCTION && type != SymbolType.LABEL) || !symbol.isExternal()) {
- return null;
+ return null; // this is really a programming error
}
if (allowInferredMatch) {
@@ -650,11 +681,13 @@ public class SimpleDiffUtility {
ExternalLocation extLoc = extMgr.getExternalLocation(symbol);
String targetName = symbol.getSource() != SourceType.DEFAULT ? symbol.getName() : null;
+ Namespace targetNamespace = symbol.getParentNamespace();
+ String targetNamespaceName = targetNamespace.getName(true);
String targetOrigImportedName = extLoc.getOriginalImportedName();
- String targetNamespace = symbol.getParentNamespace().getName(true);
- if (targetNamespace.startsWith(Library.UNKNOWN)) {
- targetNamespace = null;
- }
+
+ Library targetLibrary = symbol.getLibrary();
+ String targetLibraryName = targetLibrary != null ? targetLibrary.getName() : null; // null is unexpected
+
Address targetAddr = extLoc.getAddress();
SymbolTable otherSymbMgr = otherProgram.getSymbolTable();
@@ -662,29 +695,47 @@ public class SimpleDiffUtility {
HashMap<Address, ExternalReferenceCount> matchesMap = new HashMap<>();
- // Search by name
- if (symbol.getSource() != SourceType.DEFAULT) {
+ // Search by name across all other libraries
- // TODO: Need to improve support for lookup based upon other fields
- // Need separate Symbol DB indexing of ExternalLocation fields (address,originalImportName)
+ if (targetOrigImportedName != null) {
+ // Handle case where target symbol has been demangled
+ for (Symbol otherSym : otherSymbMgr.getExternalSymbols(targetOrigImportedName)) {
+ ExternalLocation otherExtLoc = otherExtMgr.getExternalLocation(otherSym);
+ if (otherExtLoc != null && otherExtLoc.getParentNameSpace().isGlobal() &&
+ otherExtLoc.getOriginalImportedName() == null) {
+ ExternalReferenceCount refMatch =
+ new ExternalReferenceCount(otherExtLoc, ExternalMatchType.MANGLED_NAME);
+ refMatch.setRelativeRank(targetAddr, targetNamespaceName, targetName,
+ targetOrigImportedName, targetLibraryName);
+ // minimum rank of 2 expected: MANGLED+...
+ matchesMap.put(otherExtLoc.getExternalSpaceAddress(), refMatch);
+ }
+ }
+ }
+ Namespace otherNamespace = null;
+ if (targetName != null) {
+ // Only perform name search if non-default target name is used and corresponding
+ // namespace exists in other program
Symbol otherParent = getSymbol(symbol.getParentSymbol(), otherProgram);
if (otherParent != null) {
- SymbolIterator symbols =
- otherProgram.getSymbolTable().getExternalSymbols(symbol.getName());
- for (Symbol otherSym : symbols) {
- ExternalLocation otherExtLoc = otherExtMgr.getExternalLocation(otherSym);
- if (otherExtLoc != null) {
- ExternalMatchType matchType = testExternalMatch(otherExtLoc, extLoc);
- if (matchType == ExternalMatchType.NONE) {
- continue;
- }
- ExternalReferenceCount refMatch =
- new ExternalReferenceCount(otherExtLoc, matchType);
- refMatch.setRelativeRank(targetAddr, targetNamespace, targetName,
- targetOrigImportedName);
- matchesMap.put(otherSym.getAddress(), refMatch);
- }
+ otherNamespace = (Namespace) otherParent.getObject();
+ }
+ }
+
+ if (otherNamespace != null) {
+ for (ExternalLocation otherExtLoc : otherExtMgr.getExternalLocations(null, otherNamespace, targetName)) {
+ ExternalMatchType matchType = testExternalMatch(otherExtLoc, extLoc);
+ if (matchType == ExternalMatchType.NONE) {
+ continue; // skip if no match
+ }
+ ExternalReferenceCount refMatch =
+ new ExternalReferenceCount(otherExtLoc, matchType);
+ refMatch.setRelativeRank(targetAddr, targetNamespaceName, targetName,
+ targetOrigImportedName, targetLibraryName);
+ // minimum rank of 2 expected: MANGLED+...
+ if (refMatch.rank >= 0) {
+ matchesMap.put(otherExtLoc.getExternalSpaceAddress(), refMatch);
}
}
}
@@ -714,8 +765,8 @@ public class SimpleDiffUtility {
ExternalMatchType matchType = testExternalMatch(otherExtLoc, extLoc);
refMatch = new ExternalReferenceCount(otherExtLoc, matchType);
if (matchType != ExternalMatchType.NONE) {
- refMatch.setRelativeRank(targetAddr, targetNamespace, targetName,
- targetOrigImportedName);
+ refMatch.setRelativeRank(targetAddr, targetNamespaceName, targetName,
+ targetOrigImportedName, targetLibraryName);
}
matchesMap.put(otherExtAddr, refMatch);
}
@@ -754,8 +805,9 @@ public class SimpleDiffUtility {
ExternalMatchType matchType = testExternalMatch(otherExtLoc, extLoc);
refMatch = new ExternalReferenceCount(otherExtLoc, matchType);
if (matchType != ExternalMatchType.NONE) {
- refMatch.setRelativeRank(targetAddr, targetNamespace, targetName,
- targetOrigImportedName);
+ refMatch.setRelativeRank(targetAddr, targetNamespaceName,
+ targetName,
+ targetOrigImportedName, targetLibraryName);
}
matchesMap.put(otherThunkedFunc.getEntryPoint(), refMatch);
}
@@ -769,7 +821,7 @@ public class SimpleDiffUtility {
if (matchesMap.isEmpty()) {
// Brute force search for match candidates using address/name
- // This will occur anytime an external add occurs on program and not otherProgram
+ // This will occur any time an external add occurs on program and not otherProgram
for (Symbol otherSym : otherSymbMgr.getExternalSymbols()) {
if (otherRestrictedSymbolIds != null &&
!otherRestrictedSymbolIds.contains(otherSym.getID())) {
@@ -783,8 +835,8 @@ public class SimpleDiffUtility {
}
ExternalReferenceCount refMatch =
new ExternalReferenceCount(otherExtLoc, matchType);
- refMatch.setRelativeRank(targetAddr, targetNamespace, targetName,
- targetOrigImportedName);
+ refMatch.setRelativeRank(targetAddr, targetNamespaceName, targetName,
+ targetOrigImportedName, targetLibraryName);
matchesMap.put(otherSym.getAddress(), refMatch);
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/database/symbol/LibraryUpdaterTest.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/database/symbol/LibraryUpdaterTest.java
new file mode 100644
index 0000000000..db7d1f4ed9
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/database/symbol/LibraryUpdaterTest.java
@@ -0,0 +1,645 @@
+/* ###
+ * 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.program.database.symbol;
+
+import static ghidra.program.database.symbol.SymbolDatabaseAdapter.*;
+import static ghidra.program.model.symbol.Namespace.*;
+import static ghidra.program.model.symbol.SymbolType.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.*;
+
+import javax.help.UnsupportedOperationException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import db.*;
+import ghidra.program.model.address.*;
+import ghidra.program.model.symbol.SourceType;
+import ghidra.program.model.symbol.SymbolType;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.task.TaskMonitor;
+
+public class LibraryUpdaterTest {
+ private TestSymbolDatabaseAdapter adapter;
+ private Schema schema;
+ private Map<String, DBRecord> symbolMap;
+
+ private long nextId = 1;
+
+ @Before
+ public void setUp() {
+ adapter = new TestSymbolDatabaseAdapter();
+ schema = SymbolDatabaseAdapter.SYMBOL_SCHEMA;
+ symbolMap = new HashMap<>();
+ }
+
+ @Test
+ public void testUpgradeEternalLabel() throws Exception {
+ /*
+ upgrade from / to
+
+ user32.dll::bar
+
+ global::bar (in library: user32.dll)
+ */
+
+ library("user32.dll");
+ label("foo");
+ label("user32.dll::bar");
+ assertRecordCount(3);
+
+ performUpgrade();
+
+ assertRecordCount(3);
+ assertLibrary("user32.dll");
+ assertLabel("foo");
+ assertLabel("bar");
+
+ assertHasLibrary("bar", "user32.dll");
+ assertHasNoLibrary("foo");
+ }
+
+ @Test
+ public void testUpgradeEternalFunction() throws Exception {
+ /*
+ upgrade from / to
+
+ user32.dll::bar
+
+ global::bar (in library: user32.dll)
+ */
+
+ library("user32.dll");
+ function("foo");
+ function("user32.dll::bar");
+ assertRecordCount(3);
+
+ performUpgrade();
+
+ assertRecordCount(3);
+ assertLibrary("user32.dll");
+ assertFunction("foo");
+ assertFunction("bar");
+
+ assertHasLibrary("bar", "user32.dll");
+ assertHasNoLibrary("foo");
+ }
+
+ @Test
+ public void testUpgradeExternaSymbolInSubNamespace() throws Exception {
+ /*
+ upgrade from / to
+
+ user32.dll::namespace::foo
+
+ namespace::foo (in library user32.dll)
+ */
+
+ library("user32.dll");
+ namespace("user32.dll::fooNs");
+ label("user32.dll::fooNs::foo");
+
+ assertRecordCount(3);
+ performUpgrade();
+ assertRecordCount(3);
+
+ assertLibrary("user32.dll");
+ assertNamespace("fooNs");
+ assertLabel("fooNs::foo");
+
+ assertHasLibrary("fooNs::foo", "user32.dll");
+ assertHasNoLibrary("fooNs");
+ }
+
+ @Test
+ public void testUpgradeExternalSymbolMergedNamesapce() throws Exception {
+ /*
+ upgrade from / to
+
+ testNs::foo
+ user32.dll::testNs::bar
+
+ testNs::foo
+ testNs::bar (in library user32.dll)
+ (Note: instead of promoting the testNs inside the library, it was deleted and the
+ existing testNs was used)
+ */
+
+ library("user32.dll");
+ namespace("testNs");
+ namespace("user32.dll::testNs");
+ label("testNs::foo");
+ label("user32.dll::testNs::bar");
+
+ assertRecordCount(5);
+ performUpgrade();
+ assertRecordCount(4);
+
+ assertLibrary("user32.dll");
+ assertNamespace("testNs");
+ assertLabel("testNs::foo");
+ assertLabel("testNs::bar");
+
+ assertHasLibrary("testNs::bar", "user32.dll");
+ assertHasNoLibrary("testNs::foo");
+
+ assertMissing("user32.dll::testNs");
+ }
+
+ @Test
+ public void testUpgradeExternalSymbolMergedSubNamesapce() throws Exception {
+ /*
+ upgrade from / to
+
+ testNs::subNs::foo
+ user32.dll::testNs::subNs::bar
+
+ testNs::subNs::foo
+ testNs::subNs::bar (in library user32.dll)
+ (Note: instead of promoting the testNs::subNs inside the library, it was deleted and the
+ existing testNs::subNs was used)
+ */
+
+ library("user32.dll");
+ namespace("testNs");
+ namespace("testNs::subNs");
+ namespace("user32.dll::testNs");
+ namespace("user32.dll::testNs::subNs");
+ label("testNs::subNs::foo");
+ label("user32.dll::testNs::subNs::bar");
+
+ assertRecordCount(7);
+ performUpgrade();
+ assertRecordCount(5);
+
+ assertLibrary("user32.dll");
+ assertNamespace("testNs");
+ assertNamespace("testNs::subNs");
+ assertLabel("testNs::subNs::foo");
+ assertLabel("testNs::subNs::bar");
+
+ assertHasLibrary("testNs::subNs::bar", "user32.dll");
+ assertHasNoLibrary("testNs::subNs::foo");
+
+ assertMissing("user32.dll::testNs");
+ }
+
+ @Test
+ public void testUpgradeExternalLabelInSubNamespaceOfMergedNamespace() throws Exception {
+ /*
+ upgrade from / to
+
+ testNs::foo
+ user32.dll::testNs::subNs::bar
+
+ testNs::foo
+ testNs::subNs::bar (in library user32.dll)
+ (Note: instead of promoting the testNs inside the library, it was deleted and the
+ existing testNs was used, then the subNs was parented to the existing testNs)
+ */
+ library("user32.dll");
+ namespace("user32.dll::testNs");
+ namespace("testNs");
+ namespace("user32.dll::testNs::subNs");
+ label("testNs::foo");
+ label("user32.dll::testNs::subNs::bar");
+
+ assertRecordCount(6);
+ performUpgrade();
+ assertRecordCount(5);
+
+ assertLibrary("user32.dll");
+ assertNamespace("testNs");
+ assertNamespace("testNs::subNs");
+ assertLabel("testNs::foo");
+ assertLabel("testNs::subNs::bar");
+
+ assertHasNoLibrary("testNs::foo");
+ assertHasLibrary("testNs::subNs::bar", "user32.dll");
+
+ assertMissing("user32.dll::testNs");
+ assertMissing("user32.dll::testNs::subNs");
+ }
+
+ @Test
+ public void testUpgradeExternalLabelInNamespaceMergedWithNonClassNamespace() throws Exception {
+ /*
+ upgrade from / to
+
+ testNs::foo (testNs is a plain namespace)
+ user32.dll::testNs::bar (testNs is a class namespace)
+
+ testNs::foo
+ testNs::bar (in library user32.dll)
+ (Note: the testNs is now a class namespace)
+ */
+ library("user32.dll");
+ namespace("user32.dll::testNs");
+ classNamespace("testNs");
+ label("testNs::foo");
+ label("user32.dll::testNs::bar");
+
+ assertRecordCount(5);
+ performUpgrade();
+ assertRecordCount(4);
+
+ assertLibrary("user32.dll");
+ assertClass("testNs");
+ assertLabel("testNs::foo");
+ assertLabel("testNs::bar");
+
+ assertHasNoLibrary("testNs::foo");
+ assertHasLibrary("testNs::bar", "user32.dll");
+
+ assertMissing("user32.dll::testNs");
+ assertMissing("user32.dll::testNs::subNs");
+ }
+
+ @Test
+ public void testUpgradeExternalLabelInClasMergedWithNonClassNamespace() throws Exception {
+ /*
+ upgrade from / to
+
+ testNs::foo (testNs is a plain namespace)
+ user32.dll::testNs::bar (testNs is a class namespace)
+
+ testNs::foo
+ testNs::bar (in library user32.dll)
+ (Note: the testNs is now a class namespace)
+ */
+ library("user32.dll");
+ classNamespace("user32.dll::testNs");
+ namespace("testNs");
+ label("testNs::foo");
+ label("user32.dll::testNs::bar");
+
+ assertRecordCount(5);
+ performUpgrade();
+ assertRecordCount(4);
+
+ assertLibrary("user32.dll");
+ assertClass("testNs");
+ assertLabel("testNs::foo");
+ assertLabel("testNs::bar");
+
+ assertHasNoLibrary("testNs::foo");
+ assertHasLibrary("testNs::bar", "user32.dll");
+
+ assertMissing("user32.dll::testNs");
+ assertMissing("user32.dll::testNs::subNs");
+ }
+
+ private void assertRecordCount(int expectedCount) {
+ assertEquals("Record Count: ", expectedCount, adapter.getSymbolCount());
+
+ }
+
+ private void assertMissing(String path) {
+ DBRecord dbRecord = symbolMap.get(path);
+ if (dbRecord != null) {
+ fail("Expected no symbol for " + path + ", but found " +
+ dbRecord.getString(SYMBOL_NAME_COL));
+ }
+ }
+
+ private void assertHasLibrary(String path, String libraryName) {
+ DBRecord library = getRecord(libraryName, LIBRARY);
+ DBRecord record = getRecord(path, null);
+ Field value = record.getFieldValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL);
+ if (value.isNull()) {
+ fail(path + " does not have a library value");
+ }
+ if (value.getLongValue() != library.getKey()) {
+ DBRecord actual = adapter.getSymbolRecord(value.getLongValue());
+ String actualName = actual.getString(SYMBOL_NAME_COL);
+ fail("Expected library " + libraryName + ", but has library " + actualName);
+ }
+ }
+
+ private void assertHasNoLibrary(String path) {
+ DBRecord record = getRecord(path, null);
+ Field value = record.getFieldValue(SymbolDatabaseAdapter.SYMBOL_LIBRARY_ID_COL);
+ if (!value.isNull()) {
+ DBRecord actual = adapter.getSymbolRecord(value.getLongValue());
+ String actualName = actual.getString(SYMBOL_NAME_COL);
+ fail("Expected no library, but has library: " + actualName);
+ }
+ }
+
+ private void assertLibrary(String libraryPath) {
+ getRecord(libraryPath, LIBRARY);
+ }
+
+ private void assertLabel(String labelPath) {
+ getRecord(labelPath, LABEL);
+ }
+
+ private void assertFunction(String labelPath) {
+ getRecord(labelPath, FUNCTION);
+ }
+
+ private void assertNamespace(String namespacePath) {
+ getRecord(namespacePath, NAMESPACE);
+ }
+
+ private void assertClass(String classPath) {
+ getRecord(classPath, CLASS);
+ }
+
+ private DBRecord getRecord(String libraryPath, SymbolType expectedType) {
+ DBRecord dbRecord = symbolMap.get(libraryPath);
+ if (dbRecord == null) {
+ fail("No record found for " + libraryPath);
+ }
+ if (expectedType != null) {
+ SymbolType type = getType(dbRecord);
+ assertEquals("Unexpected symbol type for " + libraryPath, expectedType, type);
+ }
+ return dbRecord;
+ }
+
+ private SymbolType getType(DBRecord dbRecord) {
+ byte typeValue = dbRecord.getByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL);
+ return SymbolType.getSymbolType(typeValue);
+ }
+
+ private void performUpgrade() throws Exception {
+ LibraryUpgrader updater = new LibraryUpgrader(adapter, TaskMonitor.DUMMY);
+ updater.update();
+ reloadSymbolMap();
+ }
+
+ private void reloadSymbolMap() throws IOException {
+ symbolMap.clear();
+ RecordIterator it = adapter.getSymbols();
+ Map<Long, DBRecord> recordMap = new HashMap<>();
+ while (it.hasNext()) {
+ DBRecord next = it.next();
+ recordMap.put(next.getKey(), next);
+ }
+ for (DBRecord record : recordMap.values()) {
+ symbolMap.put(getPath(record, recordMap), record);
+ }
+ }
+
+ private String getPath(DBRecord record, Map<Long, DBRecord> recordMap) {
+ String name = record.getString(SYMBOL_NAME_COL);
+ long parentId = record.getLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL);
+ if (parentId == GLOBAL_NAMESPACE_ID) {
+ return name;
+ }
+ return getPath(recordMap.get(parentId), recordMap) + "::" + name;
+ }
+
+ private void label(String name) {
+ int index = name.lastIndexOf("::");
+ if (index < 0) {
+ createSymbolRecord(name, LABEL, 0);
+ return;
+ }
+ DBRecord parent = symbolMap.get(name.substring(0, index));
+ createSymbolRecord(name.substring(index + 2), LABEL, parent.getKey());
+ }
+
+ private void function(String name) {
+ int index = name.lastIndexOf("::");
+ if (index < 0) {
+ createSymbolRecord(name, FUNCTION, 0);
+ return;
+ }
+ DBRecord parent = symbolMap.get(name.substring(0, index));
+ createSymbolRecord(name.substring(index + 2), FUNCTION, parent.getKey());
+ }
+
+ private void library(String name) {
+ DBRecord record = createSymbolRecord(name, LIBRARY, 0);
+ symbolMap.put(name, record);
+
+ }
+
+ private void namespace(String name) {
+ int index = name.lastIndexOf("::");
+ if (index < 0) {
+ DBRecord record = createSymbolRecord(name, NAMESPACE, GLOBAL_NAMESPACE_ID);
+ symbolMap.put(name, record);
+ return;
+ }
+ DBRecord parent = symbolMap.get(name.substring(0, index));
+ DBRecord record = createSymbolRecord(name.substring(index + 2), NAMESPACE, parent.getKey());
+ symbolMap.put(name, record);
+ }
+
+ private void classNamespace(String name) {
+ int index = name.lastIndexOf("::");
+ if (index < 0) {
+ DBRecord record = createSymbolRecord(name, CLASS, GLOBAL_NAMESPACE_ID);
+ symbolMap.put(name, record);
+ return;
+ }
+ DBRecord parent = symbolMap.get(name.substring(0, index));
+ DBRecord record = createSymbolRecord(name.substring(index + 2), CLASS, parent.getKey());
+ symbolMap.put(name, record);
+ }
+
+ private DBRecord createSymbolRecord(String name, SymbolType type, long namespaceId) {
+ DBRecord record = schema.createRecord(nextId++);
+ record.setString(SYMBOL_NAME_COL, name);
+ record.setByteValue(SymbolDatabaseAdapter.SYMBOL_TYPE_COL, type.getID());
+ record.setLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_ID_COL, namespaceId);
+ adapter.updateSymbolRecord(record);
+ return record;
+ }
+
+ private class TestSymbolDatabaseAdapter extends SymbolDatabaseAdapter {
+ private Map<Long, DBRecord> records = new HashMap<>();
+
+ @Override
+ protected int getVersion() {
+ return 0;
+ }
+
+ @Override
+ DBRecord createSymbolRecord(String name, long namespaceID, Address address,
+ SymbolType symbolType, boolean isPrimary, SourceType source) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ DBRecord getSymbolRecord(long symbolId) {
+ return records.get(symbolId);
+ }
+
+ @Override
+ void removeSymbol(long symbolId) throws IOException {
+ records.remove(symbolId);
+ }
+
+ @Override
+ boolean hasSymbol(Address addr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ Field[] getSymbolIDs(Address addr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ int getSymbolCount() {
+ return records.size();
+ }
+
+ @Override
+ RecordIterator getSymbolsByAddress(boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbolsByAddress(Address startAddr, boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ void updateSymbolRecord(DBRecord record) {
+ records.put(record.getKey(), record);
+ }
+
+ @Override
+ RecordIterator getSymbols() throws IOException {
+ return new TestRecordIterator(records.values());
+ }
+
+ @Override
+ RecordIterator getSymbols(Address start, Address end, boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbols(AddressSetView set, boolean forward) throws IOException {
+ return null;
+ }
+
+ @Override
+ RecordIterator getPrimarySymbols(AddressSetView set, boolean forward) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ DBRecord getPrimarySymbol(Address address) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ void moveAddress(Address oldAddr, Address newAddr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ Set<Address> deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
+ throws CancelledException, IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbolsByNamespace(long id) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbolsByName(String name) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbolsByLibrary(long libraryID) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator scanSymbolsByName(String startName) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getExternalSymbolsByOriginalImportName(String extLabel) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getExternalSymbolsByMemoryAddress(Address extProgAddr) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ RecordIterator getSymbolsByNameAndNamespace(String name, long id) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ DBRecord getSymbolRecord(Address address, String name, long namespaceId)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ Address getMaxSymbolAddress(AddressSpace space) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ Table getTable() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ private class TestRecordIterator implements RecordIterator {
+ private Iterator<DBRecord> it;
+
+ TestRecordIterator(Collection<DBRecord> records) {
+ it = records.iterator();
+ }
+
+ @Override
+ public boolean hasNext() throws IOException {
+ return it.hasNext();
+ }
+
+ @Override
+ public boolean hasPrevious() throws IOException {
+ return false;
+ }
+
+ @Override
+ public DBRecord next() throws IOException {
+ return it.next();
+ }
+
+ @Override
+ public DBRecord previous() throws IOException {
+ return null;
+ }
+
+ @Override
+ public boolean delete() throws IOException {
+ return false;
+ }
+
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/ReferenceManagerTestDouble.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/ReferenceManagerTestDouble.java
index e57092c6f0..f0bf854ae0 100644
--- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/ReferenceManagerTestDouble.java
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/ReferenceManagerTestDouble.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,6 +17,7 @@ package ghidra.program.model;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.Register;
+import ghidra.program.model.listing.Library;
import ghidra.program.model.listing.Variable;
import ghidra.program.model.symbol.*;
import ghidra.util.exception.DuplicateNameException;
@@ -67,7 +68,7 @@ public class ReferenceManagerTestDouble implements ReferenceManager {
}
@Override
- public Reference addExternalReference(Address fromAddr, Namespace extNamespace,
+ public Reference addExternalReference(Address fromAddr, Library library, Namespace extNamespace,
String extLabel, Address extAddr, SourceType source, int opIndex, RefType type)
throws InvalidInputException, DuplicateNameException {
throw new UnsupportedOperationException();
@@ -180,7 +181,8 @@ public class ReferenceManagerTestDouble implements ReferenceManager {
}
@Override
- public AddressIterator getReferenceDestinationIterator(AddressSetView addrSet, boolean forward) {
+ public AddressIterator getReferenceDestinationIterator(AddressSetView addrSet,
+ boolean forward) {
throw new UnsupportedOperationException();
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubNamespace.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubNamespace.java
index 9c0836cfbe..0907042e53 100644
--- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubNamespace.java
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubNamespace.java
@@ -35,11 +35,6 @@ public class StubNamespace implements Namespace {
return new StubSymbol(name);
}
- @Override
- public boolean isExternal() {
- return false;
- }
-
@Override
public String getName() {
return name;
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbol.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbol.java
index 1ad147cabb..a14aa7fc29 100644
--- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbol.java
@@ -19,8 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.*;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@@ -209,4 +208,9 @@ public class StubSymbol implements Symbol {
}
list.add(namespace.getName());
}
+
+ @Override
+ public Library getLibrary() {
+ return null;
+ }
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbolTable.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbolTable.java
index 07b6416bf7..46409409e7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbolTable.java
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/symbol/StubSymbolTable.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -147,6 +147,11 @@ public class StubSymbolTable implements SymbolTable {
throw new UnsupportedOperationException();
}
+ @Override
+ public SymbolIterator getSymbols(Library library) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public SymbolIterator getSymbols(long namespaceID) {
throw new UnsupportedOperationException();
@@ -207,6 +212,11 @@ public class StubSymbolTable implements SymbolTable {
throw new UnsupportedOperationException();
}
+ @Override
+ public SymbolIterator getExternalSymbolByOriginalImportName(Library library, String extLabel) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public SymbolIterator getSymbolIterator(boolean forward) {
throw new UnsupportedOperationException();
diff --git a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/SymbolTreePluginScreenShots.java b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/SymbolTreePluginScreenShots.java
index 7c13601f0b..09d6cbd757 100644
--- a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/SymbolTreePluginScreenShots.java
+++ b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/SymbolTreePluginScreenShots.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,11 +38,19 @@ public class SymbolTreePluginScreenShots extends GhidraScreenShotGenerator {
showProvider(SymbolTreeProvider.class);
SymbolTreeProvider provider = getProvider(SymbolTreeProvider.class);
GTree tree = (GTree) getInstanceField("tree", provider);
- expandPath(tree, "Global", "Exports");
- expandTree(tree, "Global", "Labels");
+ expandPath(tree, "Root", "Exports");
+ expandTree(tree, "Root", "Namespaces");
captureIsolatedProvider(provider, 400, 600);
}
+ @Test
+ public void testSymbolTreeSettings() {
+ showProvider(SymbolTreeProvider.class);
+ performAction("Settings", "SymbolTreePlugin", false);
+ captureDialog();
+
+ }
+
@Test
public void testCreateExternalLocation() {
@@ -70,11 +78,11 @@ public class SymbolTreePluginScreenShots extends GhidraScreenShotGenerator {
try {
ExternalManager extMgr = program.getExternalManager();
Library lib = extMgr.addExternalLibraryName("TestLibrary", SourceType.IMPORTED);
- extLoc = extMgr.addExtFunction("TestLibrary", "??1type_info@@UEAA@XZ",
+ extLoc = extMgr.addExtFunction("TestLibrary", "??1category_info@@UEAA@XZ",
addr(0x010012345), SourceType.IMPORTED);
GhidraClass typeInfoClass =
- program.getSymbolTable().createClass(lib, "type_info", SourceType.ANALYSIS);
- extLoc.setName(typeInfoClass, "~type_info", SourceType.ANALYSIS);
+ program.getSymbolTable().createClass(null, "category_info", SourceType.ANALYSIS);
+ extLoc.setName(typeInfoClass, "~category_info", SourceType.ANALYSIS);
}
finally {
program.endTransaction(txId, true);
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/core/clipboard/ClipboardPluginTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/core/clipboard/ClipboardPluginTest.java
index 64bbdab59c..852b13986c 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/core/clipboard/ClipboardPluginTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/core/clipboard/ClipboardPluginTest.java
@@ -463,7 +463,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
//
// 1)
- String operandText = "dword ptr [->ADVAPI32.dll::RegQueryValueExW]";
+ String operandText = "dword ptr [->ADVAPI32.dll:RegQueryValueExW]";
OperandFieldLocation operandFieldLocation = new OperandFieldLocation(program,
addr("0100418c"), null, addr("01001008"), operandText, 15, 0);
codeBrowserPlugin.goTo(operandFieldLocation);