Skip to content

Commit 32d2d54

Browse files
committed
Merge remote-tracking branch 'origin/GT-3054_new_function_tags_view'
2 parents 125a3fa + bddb1a5 commit 32d2d54

File tree

21 files changed

+1111
-370
lines changed

21 files changed

+1111
-370
lines changed

Ghidra/Features/Base/certification.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ src/main/help/help/topics/FunctionTagPlugin/images/DeleteWarning.png||GHIDRA||||
400400
src/main/help/help/topics/FunctionTagPlugin/images/EditNotAllowedWarning.png||GHIDRA||||END|
401401
src/main/help/help/topics/FunctionTagPlugin/images/EditTag.png||GHIDRA||||END|
402402
src/main/help/help/topics/FunctionTagPlugin/images/FilterField.png||GHIDRA||||END|
403-
src/main/help/help/topics/FunctionTagPlugin/images/FunctionTagPlugin.png||GHIDRA||||END|
403+
src/main/help/help/topics/FunctionTagPlugin/images/FullWindow.png||GHIDRA||||END|
404404
src/main/help/help/topics/FunctionTagPlugin/images/InputField.png||GHIDRA||||END|
405405
src/main/help/help/topics/FunctionWindowPlugin/function_window.htm||GHIDRA||||END|
406406
src/main/help/help/topics/FunctionWindowPlugin/images/FunctionWindow.png||GHIDRA||||END|

Ghidra/Features/Base/src/main/help/help/topics/FunctionTagPlugin/function_tag_window.htm

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,43 @@ <H1><A name="FunctionTagPlugin"></A> Function Tag Window</H1>
2525
<TABLE border="0" width="100%">
2626
<TR>
2727
<TD width="100%" align="center"><IMG alt="" border="0" src=
28-
"images/FunctionTagPlugin.png"></TD>
28+
"images/FullWindow.png"></TD>
2929
</TR>
3030
</TABLE>
3131
</CENTER>
3232

3333
<H2>Window Components</H2>
3434

3535
<BLOCKQUOTE>
36-
<P>This window has five distinct sections:</P>
37-
3836
<UL>
39-
<LI><B>Available Tags List</B>: Displays all tags that are available to assign to the
40-
current function.</LI>
37+
<LI><B>All Tags TAble</B>: Displays all tags that are available to assign to the
38+
current function, as well as a count of the number of times each tag has been used
39+
in the current program.</LI>
4140

4241
<LI><B>Assigned Tags List</B>: Displays all tags that have been assigned to the current
4342
function.</LI>
43+
44+
<LI><B>Function Panel</B>: Displays functions that contain any selected tags. If multiple
45+
tags are selected, functions containing ANY of the tags will be displayed.</LI>
4446

4547
<LI>
4648
<B>Tag Input Field</B>: Allows users to create new tags. Multiple tags may be created at one time.
47-
4849
<P style="margin: 20px;"><IMG alt="" border="0" src="images/InputField.png"></P>
4950
</LI>
5051

5152
<LI>
5253
<B>Filter Field</B>: Allows users to filter what is shown in the Available and Assigned tag lists.
53-
5454
<P style="margin: 20px;"><IMG alt="" border="0" src="images/FilterField.png"></P>
5555
</LI>
5656
</UL>
5757

5858
<UL class="noindent">
5959
<LI><B>Action Buttons</B></LI>
6060
<UL>
61-
<LI><IMG alt="" border="0" src="images/2rightarrow.png"> &nbsp;
61+
<LI><IMG alt="" border="0" src="images/2rightarrow.png" width="16" height="16"> &nbsp;
6262
Assigns the selected tag(s) to the current function</LI>
6363

64-
<LI><IMG alt="" border="0" src="images/2leftarrow.png"> &nbsp;
64+
<LI><IMG alt="" border="0" src="images/2leftarrow.png" width="16" height="16"> &nbsp;
6565
Removes the selected tag(s) from the current function</LI>
6666

6767
<LI><IMG alt="" border="0" src="Icons.DELETE_ICON"> &nbsp;
@@ -80,7 +80,7 @@ <H3><A name="Create_Tag"></A>Create</H3>
8080
<BLOCKQUOTE>
8181
<P>Tags can be created by using the <I>Tag Input Field</I> described above. Users may enter
8282
multiple tag names delimited by a comma. All newly-created tags will be displayed in the
83-
Available Tags List and are NOT assigned to any function.</P>
83+
Available Tags List but are NOT yet assigned to any function.</P>
8484

8585
<P><IMG alt="" border="0" src="../../shared/tip.png">Each tag may have an associated comment that
8686
is visible as a tooltip. This can be assigned after the tag has been created (see <code>edit</code> section below).</P>
@@ -112,14 +112,22 @@ <H3><A name="Edit_Tag"></A>Edit</H3>
112112
<P>If editing is allowed, the following dialog will be shown:</P>
113113

114114
<P align="center"><IMG alt="" border="0" src="images/EditTag.png"></P>
115+
116+
<P><IMG alt="" border="0" src="../../shared/tip.png">An <i>italicized</i> tag name
117+
indicates that the tag was loaded from an external source and has not yet been
118+
added to the program, making it immutable. As soon as the tag is assigned to a function it becomes
119+
editable. If you delete the tag using the <IMG alt="" border="0" src=
120+
"Icons.DELETE_ICON" width="16" height="16"> icon it will be removed from
121+
the program and once again be immutable.</P>
122+
115123
</BLOCKQUOTE>
116124

117125
<H3><A name="Add_Tag_To_Function"></A>Add to Function</H3>
118126

119127
<BLOCKQUOTE>
120128
<P>Tags may be added to a function by selecting a set of tags and pressing the <IMG alt=""
121129
border="0" src="images/2rightarrow.png" width="16" height="16"> button. The tags will be
122-
removed from the Available Tags List and added to the Assigned Tags List.</P>
130+
added to the Assigned Tags list, and shown as disabled in the Available Tags list.</P>
123131
</BLOCKQUOTE>
124132

125133
<H3><A name="Remove_Tag_From_Function"></A>Remove from Function</H3>
@@ -134,10 +142,12 @@ <H3><A name="Remove_Tag_From_Function"></A>Remove from Function</H3>
134142
<H2><a name="loading_tags">Loading External Tags</a></H2>
135143

136144
<BLOCKQUOTE>
137-
<P>Tags may be loaded on startup from an external source if desired. These will be shown in
138-
<FONT color="blue">blue</FONT> and cannot be edited or deleted, with one caveat: once a tag has
139-
been assigned to a function it ceases to have any special protections and can be edited/deleted
140-
just as any other.</P>
145+
<P>Tags may be loaded on startup from an external source if desired. These tags will be shown with
146+
an asterisk (*) after the name and cannot be edited or deleted; with one caveat: once a tag has
147+
been assigned to a function it ceases to have any special protections and can be edited
148+
like any other. If the tag is ever removed from all functions using the
149+
<IMG alt="" border="0" src="Icons.DELETE_ICON"> button, it will again be present in the
150+
Available Tags list.</P>
141151

142152
<P>To make these available there must be a file named <I>functionTags.xml</I> available on
143153
the classpath. Edit (or create) this file and add tags as needed. The format is
Loading
Loading
Loading
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* ###
2+
* IP: GHIDRA
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ghidra.app.plugin.core.function.tags;
17+
18+
import java.awt.BorderLayout;
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
22+
import javax.swing.BorderFactory;
23+
import javax.swing.JLabel;
24+
import javax.swing.JPanel;
25+
26+
import ghidra.app.services.GoToService;
27+
import ghidra.framework.plugintool.ComponentProviderAdapter;
28+
import ghidra.program.model.listing.Function;
29+
import ghidra.program.model.listing.FunctionTag;
30+
import ghidra.program.model.listing.Program;
31+
import ghidra.util.table.GhidraThreadedTablePanel;
32+
33+
/**
34+
* Displays all functions that are associated with the selected tag in the
35+
* {@link SourceTagsPanel}
36+
*/
37+
public class AllFunctionsPanel extends JPanel {
38+
39+
private FunctionTableModel model;
40+
private JLabel titleLabel;
41+
42+
/**
43+
* Constructor
44+
*
45+
* @param program the current program
46+
* @param provider the component provider
47+
* @param title the title of the panel
48+
*/
49+
public AllFunctionsPanel(Program program, ComponentProviderAdapter provider, String title) {
50+
51+
model = new FunctionTableModel(title, provider.getTool(), program, null);
52+
GhidraThreadedTablePanel<Function> tablePanel = new GhidraThreadedTablePanel<>(model);
53+
setLayout(new BorderLayout());
54+
55+
titleLabel = new JLabel(title);
56+
titleLabel.setBorder(BorderFactory.createEmptyBorder(3, 5, 0, 0));
57+
58+
add(titleLabel, BorderLayout.NORTH);
59+
add(tablePanel, BorderLayout.CENTER);
60+
61+
GoToService goToService = provider.getTool().getService(GoToService.class);
62+
if (goToService != null) {
63+
tablePanel.getTable().installNavigation(goToService, goToService.getDefaultNavigatable());
64+
}
65+
}
66+
67+
/**
68+
* Updates the table with whatever is in the {@link #model}
69+
*/
70+
public void refresh() {
71+
model.fireTableDataChanged();
72+
}
73+
74+
/**
75+
* Updates the table with functions containing the selected tags given
76+
*
77+
* @param selectedTags the selected function tags
78+
*/
79+
public void refresh(List<FunctionTag> selectedTags) {
80+
setSelectedTags(selectedTags);
81+
}
82+
83+
/**
84+
* Stores the current program
85+
*
86+
* @param program the current program
87+
*/
88+
public void setProgram(Program program) {
89+
model.setProgram(program);
90+
}
91+
92+
/**
93+
* Updates the panel with the set of tags selected by the user. This
94+
* will update the panel title and the contents of the function table.
95+
*
96+
* @param tags the selected tags
97+
*/
98+
public void setSelectedTags(List<FunctionTag> tags) {
99+
String tagNames = tags.stream()
100+
.map(t -> t.getName())
101+
.collect(Collectors.joining(" or "))
102+
.toString();
103+
104+
titleLabel.setText("Functions With Tag: " + tagNames);
105+
model.setSelectedTags(tags);
106+
}
107+
108+
/**
109+
* Returns the list of functions in the panel
110+
* <p>
111+
* This is only used for testing!
112+
*
113+
* @return the list of functions
114+
*/
115+
public List<Function> getFunctions() {
116+
return model.getFunctions();
117+
}
118+
119+
/**
120+
* Returns the functions table model
121+
*
122+
* @return the functions table model
123+
*/
124+
public FunctionTableModel getTableModel() {
125+
return model;
126+
}
127+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* ###
2+
* IP: GHIDRA
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ghidra.app.plugin.core.function.tags;
17+
18+
import java.util.List;
19+
20+
import docking.widgets.table.DiscoverableTableUtils;
21+
import docking.widgets.table.TableColumnDescriptor;
22+
import ghidra.framework.plugintool.ServiceProvider;
23+
import ghidra.program.model.address.Address;
24+
import ghidra.program.model.listing.*;
25+
import ghidra.util.datastruct.Accumulator;
26+
import ghidra.util.exception.CancelledException;
27+
import ghidra.util.table.AddressBasedTableModel;
28+
import ghidra.util.table.field.*;
29+
import ghidra.util.task.TaskMonitor;
30+
31+
/**
32+
* The data model that backs the {@link AllFunctionsPanel}. This displays a list
33+
* of functions that have function tags matching a provided set. Note that
34+
* a function will be displayed as long as it has AT LEAST ONE of the tags
35+
* in the set.
36+
*/
37+
class FunctionTableModel extends AddressBasedTableModel<Function> {
38+
39+
// The function tags to display functions for
40+
private List<FunctionTag> tags;
41+
42+
/**
43+
* Constructor
44+
*
45+
* @param title the title of the model
46+
* @param serviceProvider the service provider
47+
* @param program the current program
48+
* @param monitor the task monitor
49+
*/
50+
public FunctionTableModel(String title, ServiceProvider serviceProvider, Program program,
51+
TaskMonitor monitor) {
52+
super(title, serviceProvider, program, monitor);
53+
}
54+
55+
@Override
56+
public Address getAddress(int row) {
57+
Function rowObject = getRowObject(row);
58+
return rowObject.getEntryPoint();
59+
}
60+
61+
@Override
62+
protected TableColumnDescriptor<Function> createTableColumnDescriptor() {
63+
TableColumnDescriptor<Function> descriptor = new TableColumnDescriptor<>();
64+
65+
descriptor.addVisibleColumn(
66+
DiscoverableTableUtils.adaptColumForModel(this, new LabelTableColumn()));
67+
descriptor.addVisibleColumn(
68+
DiscoverableTableUtils.adaptColumForModel(this, new AddressTableColumn()), 1, true);
69+
descriptor.addVisibleColumn(
70+
DiscoverableTableUtils.adaptColumForModel(this, new FunctionTagTableColumn()));
71+
72+
return descriptor;
73+
}
74+
75+
@Override
76+
protected void doLoad(Accumulator<Function> accumulator, TaskMonitor monitor)
77+
throws CancelledException {
78+
79+
if (program == null) {
80+
return;
81+
}
82+
if (tags == null) {
83+
return;
84+
}
85+
86+
// Loop over all functions in the program, filtering out those that do not
87+
// do not contain at least one of the tags in the provided set.
88+
FunctionIterator iter = program.getFunctionManager().getFunctions(true);
89+
monitor.initialize(program.getFunctionManager().getFunctionCount());
90+
while (iter.hasNext()) {
91+
monitor.incrementProgress(1);
92+
monitor.checkCanceled();
93+
Function f = iter.next();
94+
boolean hasTag = f.getTags().stream().anyMatch(t -> tags.contains(t));
95+
if (hasTag) {
96+
accumulator.add(f);
97+
}
98+
}
99+
}
100+
101+
/**
102+
* Sets the tags associated with this model. This causes a reload of
103+
* the function table
104+
*
105+
* @param tags the selected tags
106+
*/
107+
public void setSelectedTags(List<FunctionTag> tags) {
108+
this.tags = tags;
109+
reload();
110+
}
111+
112+
/**
113+
* Returns the list of functions in the table
114+
*
115+
* @return the contents of the table
116+
*/
117+
public List<Function> getFunctions() {
118+
return getAllData();
119+
}
120+
}

0 commit comments

Comments
 (0)