From 6fb115358a5247161521d24b1af856c93aec395b Mon Sep 17 00:00:00 2001
From: ghidragon <106987263+ghidragon@users.noreply.github.com>
Date: Fri, 28 Feb 2025 20:08:40 -0500
Subject: [PATCH] GP-5310 Created global search and replace feature
---
.../AbstractDBTraceProgramViewListing.java | 17 +
.../program/DBTraceProgramViewFragment.java | 9 +-
.../program/DBTraceProgramViewRootModule.java | 9 +-
Ghidra/Features/Base/certification.manifest | 15 +-
.../Base/data/ExtensionPoint.manifest | 1 +
.../Base/data/base.icons.theme.properties | 6 +-
.../Base/src/main/help/help/TOC_Source.xml | 13 +-
.../topics/MemoryMapPlugin/Memory_Map.htm | 9 +
.../help/topics/Search/SearchAndReplace.htm | 478 +++++++++++++++
.../help/help/topics/Search/Searching.htm | 11 +-
.../Search/images/SearchAndReplaceDialog.png | Bin 0 -> 18914 bytes
.../Search/images/SearchAndReplaceResults.png | Bin 0 -> 38164 bytes
.../DefaultDataTypeManagerService.java | 11 +-
.../core/comments/CommentsActionFactory.java | 9 +-
.../plugin/core/comments/CommentsPlugin.java | 12 +-
.../CompositeEditorProvider.java | 6 +
.../StructureEditorProvider.java | 6 -
.../core/datamgr/DataTypeManagerPlugin.java | 13 +-
.../core/datamgr/DataTypesProvider.java | 39 ++
.../datamgr/editor/DataTypeEditorManager.java | 18 +-
.../plugin/core/memory/MemoryMapPlugin.java | 9 +-
.../plugin/core/memory/MemoryMapProvider.java | 32 +-
.../searchtext/ListingDisplaySearcher.java | 8 +-
.../core/symboltree/SymbolTreePlugin.java | 15 +-
.../core/symboltree/SymbolTreeProvider.java | 5 +
.../core/symboltree/SymbolTreeService.java | 29 +
.../app/services/DataTypeManagerService.java | 21 +-
.../app/services/ProgramTreeService.java | 23 +-
.../base/quickfix/QuckFixTableProvider.java | 356 +++++++++++
.../features/base/quickfix/QuickFix.java | 231 ++++++++
.../base/quickfix/QuickFixStatus.java | 28 +
.../base/quickfix/QuickFixStatusRenderer.java | 78 +++
.../base/quickfix/QuickFixTableModel.java | 346 +++++++++++
.../base/quickfix/TableDataLoader.java | 58 ++
.../features/base/replace/RenameQuickFix.java | 49 ++
.../base/replace/SearchAndReplaceDialog.java | 356 +++++++++++
.../base/replace/SearchAndReplaceHandler.java | 68 +++
.../base/replace/SearchAndReplacePlugin.java | 133 +++++
.../replace/SearchAndReplaceProvider.java | 106 ++++
.../SearchAndReplaceQuckFixTableLoader.java | 66 +++
.../base/replace/SearchAndReplaceQuery.java | 152 +++++
.../features/base/replace/SearchType.java | 93 +++
.../DataTypesSearchAndReplaceHandler.java | 274 +++++++++
...tatypeCategorySearchAndReplaceHandler.java | 78 +++
...istingCommentsSearchAndReplaceHandler.java | 75 +++
.../MemoryBlockSearchAndReplaceHandler.java | 64 ++
.../ProgramTreeSearchAndReplaceHandler.java | 100 ++++
.../SymbolsSearchAndReplaceHandler.java | 115 ++++
.../replace/items/CompositeFieldQuickFix.java | 116 ++++
.../replace/items/RenameCategoryQuickFix.java | 121 ++++
.../replace/items/RenameDataTypeQuickFix.java | 125 ++++
.../items/RenameEnumValueQuickFix.java | 127 ++++
.../replace/items/RenameFieldQuickFix.java | 89 +++
.../items/RenameMemoryBlockQuickFix.java | 79 +++
.../items/RenameProgramTreeGroupQuickFix.java | 144 +++++
.../replace/items/RenameSymbolQuickFix.java | 136 +++++
.../replace/items/UpdateCommentQuickFix.java | 96 +++
.../UpdateDataTypeDescriptionQuickFix.java | 128 ++++
.../items/UpdateEnumCommentQuickFix.java | 112 ++++
.../items/UpdateFieldCommentQuickFix.java | 82 +++
.../program/database/ProgramBuilder.java | 2 +-
.../java/ghidra/util/table/GhidraTable.java | 2 +-
.../table/actions/DeleteTableRowAction.java | 15 +-
.../actions/MakeProgramSelectionAction.java | 28 +-
.../TestDoubleDataTypeManagerService.java | 11 +-
.../replace/AbstractSearchAndReplaceTest.java | 201 +++++++
.../CategoriesSearchAndReplaceTest.java | 95 +++
.../DataTypesSearchAndReplaceTest.java | 454 ++++++++++++++
.../ListingCommentsSearchAndReplaceTest.java | 194 ++++++
.../MemoryBlockSearchAndReplaceTest.java | 95 +++
.../ProgramTreeSearchAndReplaceTest.java | 176 ++++++
.../replace/SearchAndReplaceDialogTest.java | 200 +++++++
.../replace/SymbolsSearchAndReplaceTest.java | 553 ++++++++++++++++++
.../DecompilerCommentsActionFactory.java | 8 +-
.../util/task/TaskMonitorComponent.java | 4 +-
.../datastruct/AccumulatorSizeException.java | 30 +
.../SizeRestrictedAccumulatorWrapper.java | 71 +++
Ghidra/Framework/Gui/certification.manifest | 1 +
.../Framework/Gui/data/gui.theme.properties | 2 +-
.../Gui/src/main/resources/images/tick.png | Bin 0 -> 537 bytes
.../ghidra/program/database/ListingDB.java | 14 +-
.../program/database/code/CodeManager.java | 42 +-
.../program/database/module/FragmentDB.java | 9 +-
.../program/database/module/ModuleDB.java | 9 +-
.../program/model/listing/CodeUnit.java | 59 +-
.../model/listing/CodeUnitComments.java | 40 ++
.../program/model/listing/CommentType.java | 28 +
.../ghidra/program/model/listing/Group.java | 59 +-
.../ghidra/program/model/listing/Listing.java | 80 ++-
.../program/model/listing/StubListing.java | 14 +-
...CommentType.java => CommentTypeUtils.java} | 7 +-
.../java/ghidra/util/UserSearchUtils.java | 10 +-
.../SearchAndReplaceScreenShots.java | 92 +++
93 files changed, 7469 insertions(+), 141 deletions(-)
create mode 100644 Ghidra/Features/Base/src/main/help/help/topics/Search/SearchAndReplace.htm
create mode 100644 Ghidra/Features/Base/src/main/help/help/topics/Search/images/SearchAndReplaceDialog.png
create mode 100644 Ghidra/Features/Base/src/main/help/help/topics/Search/images/SearchAndReplaceResults.png
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeService.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/QuckFixTableProvider.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/QuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/QuickFixStatus.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/QuickFixStatusRenderer.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/QuickFixTableModel.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/quickfix/TableDataLoader.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/RenameQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplaceDialog.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplacePlugin.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplaceProvider.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplaceQuckFixTableLoader.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchAndReplaceQuery.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/SearchType.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/DataTypesSearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/DatatypeCategorySearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/ListingCommentsSearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/MemoryBlockSearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/ProgramTreeSearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/SymbolsSearchAndReplaceHandler.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/CompositeFieldQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameCategoryQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameDataTypeQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameEnumValueQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameFieldQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameMemoryBlockQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameProgramTreeGroupQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/RenameSymbolQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/UpdateCommentQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/UpdateDataTypeDescriptionQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/UpdateEnumCommentQuickFix.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/items/UpdateFieldCommentQuickFix.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/AbstractSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/CategoriesSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/DataTypesSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/ListingCommentsSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/MemoryBlockSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/ProgramTreeSearchAndReplaceTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/SearchAndReplaceDialogTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/features/base/replace/SymbolsSearchAndReplaceTest.java
create mode 100644 Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/AccumulatorSizeException.java
create mode 100644 Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/SizeRestrictedAccumulatorWrapper.java
create mode 100644 Ghidra/Framework/Gui/src/main/resources/images/tick.png
create mode 100644 Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CodeUnitComments.java
create mode 100644 Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/CommentType.java
rename Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/{CommentType.java => CommentTypeUtils.java} (97%)
create mode 100644 Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/SearchAndReplaceScreenShots.java
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java
index 8ffa102571..971c1fff3f 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java
@@ -439,6 +439,13 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV
return getCommentAddresses(addrSet).getAddresses(forward);
}
+ @Override
+ public long getCommentAddressCount() {
+ return program.viewport.unionedAddresses(
+ s -> program.trace.getCommentAdapter().getAddressSetView(Lifespan.at(s)))
+ .getNumAddresses();
+ }
+
@Override
public String getComment(int commentType, Address address) {
try (LockHold hold = program.trace.lockRead()) {
@@ -447,6 +454,16 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV
}
}
+ @Override
+ public CodeUnitComments getAllComments(Address address) {
+ CommentType[] types = CommentType.values();
+ String[] comments = new String[types.length];
+ for (CommentType type : types) {
+ comments[type.ordinal()] = getComment(type, address);
+ }
+ return new CodeUnitComments(comments);
+ }
+
@Override
public void setComment(Address address, int commentType, String comment) {
program.trace.getCommentAdapter()
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewFragment.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewFragment.java
index 6f5a197dc5..007097f7da 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewFragment.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewFragment.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.
@@ -249,4 +249,9 @@ public class DBTraceProgramViewFragment implements ProgramFragment {
public void move(Address min, Address max) throws NotFoundException {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public boolean isDeleted() {
+ return false;
+ }
}
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRootModule.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRootModule.java
index e77b345bca..bc8a4a705e 100644
--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRootModule.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRootModule.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.
@@ -239,4 +239,9 @@ public class DBTraceProgramViewRootModule implements ProgramModule {
public long getTreeID() {
return 0;
}
+
+ @Override
+ public boolean isDeleted() {
+ return false;
+ }
}
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest
index 5c4b89797b..615571e55b 100644
--- a/Ghidra/Features/Base/certification.manifest
+++ b/Ghidra/Features/Base/certification.manifest
@@ -516,7 +516,7 @@ src/main/help/help/topics/ScalarSearchPlugin/images/ScalarWindow.png||GHIDRA||||
src/main/help/help/topics/ScalarSearchPlugin/images/SearchAllScalarsDialog.png||GHIDRA||||END|
src/main/help/help/topics/Search/Instruction_Mnemonic_Search.htm||GHIDRA||||END|
src/main/help/help/topics/Search/Query_Results_Dialog.htm||GHIDRA||||END|
-src/main/help/help/topics/Search/Regular_Expressions.htm||GHIDRA||||END|
+src/main/help/help/topics/Search/SearchAndReplace.htm||GHIDRA||||END|
src/main/help/help/topics/Search/Search_Formats.htm||GHIDRA||||END|
src/main/help/help/topics/Search/Search_Instruction_Patterns.htm||GHIDRA||||END|
src/main/help/help/topics/Search/Search_Memory.htm||GHIDRA||||END|
@@ -533,6 +533,8 @@ src/main/help/help/topics/Search/images/MemorySearchProviderWithOptionsOn.png||G
src/main/help/help/topics/Search/images/MemorySearchProviderWithScanPanelOn.png||GHIDRA||||END|
src/main/help/help/topics/Search/images/MultipleSelectionError.png||GHIDRA||||END|
src/main/help/help/topics/Search/images/QueryResultsSearch.png||GHIDRA||||END|
+src/main/help/help/topics/Search/images/SearchAndReplaceDialog.png||GHIDRA||||END|
+src/main/help/help/topics/Search/images/SearchAndReplaceResults.png||GHIDRA||||END|
src/main/help/help/topics/Search/images/SearchForAddressTables.png||GHIDRA||||END|
src/main/help/help/topics/Search/images/SearchInstructionPatterns.png||GHIDRA||||END|
src/main/help/help/topics/Search/images/SearchInstructionPatternsControlPanel.png||GHIDRA||||END|
@@ -579,10 +581,6 @@ 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/Tables/GhidraTableHeaders.html||GHIDRA||||END|
-src/main/help/help/topics/Tables/images/BytesSettingsDialog.png||GHIDRA||reviewed||END|
-src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png||GHIDRA||||END|
-src/main/help/help/topics/Tables/images/SelectColumnsDialog.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|
@@ -604,13 +602,6 @@ src/main/help/help/topics/Tool/images/SetToolAssociations.png||GHIDRA||||END|
src/main/help/help/topics/Tool/images/ShowLog.png||GHIDRA||||END|
src/main/help/help/topics/Tool/images/Tip.png||GHIDRA||||END|
src/main/help/help/topics/TranslateStringsPlugin/TranslateStringsPlugin.htm||GHIDRA||||END|
-src/main/help/help/topics/Trees/GhidraTreeFilter.html||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/Filter.png||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/FilterClearButton.png||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/FilterOptions.png||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/TableColumnFilter.png||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png||GHIDRA||||END|
-src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png||GHIDRA||||END|
src/main/help/help/topics/VSCodeIntegration/VSCodeIntegration.htm||GHIDRA||||END|
src/main/help/help/topics/ValidateProgram/ValidateProgram.html||GHIDRA||||END|
src/main/help/help/topics/ValidateProgram/images/ValidateProgram.png||GHIDRA||||END|
diff --git a/Ghidra/Features/Base/data/ExtensionPoint.manifest b/Ghidra/Features/Base/data/ExtensionPoint.manifest
index 6fada20354..c6e74d361d 100644
--- a/Ghidra/Features/Base/data/ExtensionPoint.manifest
+++ b/Ghidra/Features/Base/data/ExtensionPoint.manifest
@@ -22,3 +22,4 @@ OverviewColorService
DWARFFunctionFixup
ElfInfoProducer
FSBFileHandler
+SearchAndReplaceHandler
diff --git a/Ghidra/Features/Base/data/base.icons.theme.properties b/Ghidra/Features/Base/data/base.icons.theme.properties
index 6549fbe9b1..85b4e71297 100644
--- a/Ghidra/Features/Base/data/base.icons.theme.properties
+++ b/Ghidra/Features/Base/data/base.icons.theme.properties
@@ -204,7 +204,7 @@ icon.plugin.merge.conflict.lock = lock.gif
icon.plugin.merge.conflict.unlock = unlock.gif
icon.plugin.merge.status.pending = bullet_green.png
icon.plugin.merge.status.in.progress = right.png
-icon.plugin.merge.status.complete = checkmark_green.gif
+icon.plugin.merge.status.complete = icon.checkmark.green
icon.plugin.myprogramchanges.merge = vcMerge.png
icon.plugin.myprogramchanges.checkin = vcCheckIn.png
@@ -402,9 +402,7 @@ icon.base.mem.search.panel.options = view_left_right.png
icon.base.mem.search.panel.scan = view_bottom.png
icon.base.mem.search.panel.search = view_top_bottom.png
-
-
-
+icon.base.plugin.quickfix.done = icon.checkmark.green
[Dark Defaults]
diff --git a/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml b/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
index 506c93713f..0fbf5ed0d9 100644
--- a/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
@@ -327,12 +327,13 @@
++The
+button controls whether a memory + block is selected in the Memory Map table when the global program location changes such + as when you click in the CodeBrowser, Byte Viewer, or Decompiler.
Provided by: Memory Map Plugin
+ + ++ +Search And Replace
+ +The search and replace feature allows to users to search for specific text sequences in + various Ghidra elements and replace that text sequence with a different text sequence. Using + this feature, many different elements in Ghidra can be renamed including labels, functions, + namespaces, parameters, datatypes, field elements, enum values, and others. This feature can + also be used to change comments placed on items such as instructions or data, structure field + element, or enum values.
+ +By default, the search matches the text anywhere in an element ("contains"), but it has + full regular expression support where + users can easily perform a "starts with" or "ends with" search. Regular expression capture + groups are also supported which allows for complex replacing of disjoint strings. See the examples section below for details.
+ +To initiate a search and replace operation, select Search
+ +Search and Replace from the main tool menu.
Search and Replace Dialog
+ +++ +The Search and Replace Dialog provides controls and options for performing and search + and replace operation.
++ +
![]()
Search and Replace Dialog
+ +++ + +Find
+ +++ +This is a text field for entering the text to be searched for in the selected Ghidra + elements. Elements are either the names of things such as labels, functions, datatypes, + or a comment associated with some item such as an instruction comment or structure field + comment.
+ +Ghidra will find all the elements that contain the given text. To perform a "starts + with" or "ends with" search, you must enter a regular expression here and select the + regular expression option below.
+ +There is also a drop down list of recent searches for this Ghidra session.
+Replace
+ +++ +This is a text field for entering the replacement text. This text will be used to + replace the text that matched the search text. For example, if a function was named + "startCat" and the goal was to change it to "startDog", you would enter "Cat" in the + Find field and "Dog" in this field.
+ +This field also include a drop drow of the most recently enter replacement + strings.
+Options
+ +++ +Regular Expression
+ +++ +If selected, the search text will be interpreted as a regular expression. This + allows for complex search and replace operations. See the general section on regular expressions for more information. If + you want to anything other than a "contains" search, you must use a regular expression. + See below for examples on how to do this.
+Case Sensitive
+ +++ +If selected, the entered search text must match exactly. Otherwise, the entered + search text can match regardless of the case of the search text or the target text.
+Whole Word
+ +++If selected, the target text must be an entire word. In other words it must be + surrounded by white space or must be the first or last word in a word sequence. So, + when applied to renaming elements, the search text must match the entire name of the + element since element names cannot contain whitespace. But for comments, the search + text must entirely match one word withing the comment.
+Search For
+ +++This section contains a group of checkboxes used to turn on or off the type of Ghidra + elements to search. There are also buttons for selecting and deselecting all the element + checkboxes. At least one checkbox must be selected to perform a search.
+ ++
+- Classes - Search the names of classes.
+ +- Comments - Search instruction or data comments. This includes pre-comments, + plate comments, end of line comments, post-comments, and repeatable comments.
+ +- Datatype Categories - Search for the names of categories in the data types + tree.
+ +- Datatype Comments - Search comments associated with datatypes. This includes + descriptions on enums and structures, datatype field comments, and enum value + comments.
+ +- Datatype Fields - Search the names of structure or union field elements.
+ +- Datatypes - Search the names of any nameable datatype (i.e., does + not search built-in datatypes such as byte, word, string, etc.)
+ +- Enum Values - Search the names of enum values.
+ +- Functions - Search the names of functions. (Note: This search does not + include external function names.)
+ +- Labels - Search the names of labels. (Note: This search does not include + external labels.)
+ +- Local Variables - Search the names of function local variables. (Note: This + does not include local variables derived by the decompiler that haven't been committed + to the database.)
+ +- Memory Blocks - Search the names of Memory Blocks.
+ +- Namespaces - Search the names of namespaces.
+ +- Parameters - Search the names of function parameters.
+ +- Program Trees - Search the names of modules and fragments defined in program + trees.
+Results Window
+ +++After initiating a search and replace action, a results window will appear containing a + table showing each search match as an entry in the table. At this point, no changes have + been made to the program. This provides an opportunity to review the pending changes before + they are applied. The changes can now be applied all at once or individually.
+
Search and Replace Results Window
+ +++++Table information
+ +++ +Each entry in the table represents one changes that can be applied.
+ +Standard Columns
+ ++
+ +- Original - This column displays the original value of the matched + element.
+ +- Preview - This column displays a preview of the value if this change is + applied.
+ +- Action - The change to be applied. (either Rename for names or Update for + comments changes.)
+ +- Type - This column displays the type of element being changed (label, + function, comment, etc.)
+ +- Status - The icon displayed in this column indicates the status of this + change.
+Status Icons
+ +++ +The status column will have one of the following icons to indicate item's + status:
++
+ +- Blank - The change has not been applied.
+ +- + +
- The change has some associated warning. + Hover on the status to get a detailed message of the issue.
- + +
- The change can't be applied. This status can + appear either before or after an attempt to apply has been made. Hover on the status + for more information.
- +
- The changes has been applied.
Optional Columns
+ ++
+ +- Current - Displays the current value of the element.
+ +- Address - Displays the elements address if applicable, blank otherwise
+ +- Path - Displays any path associated with the element, if applicable. The type of + path varies greatly with the element type.
+Path Column Information
+ +++ +The Path column shows different path information depending on the element type:
++
+- Classes - the namespace path.
+ +- Datatype Categories - the parent category path.
+ +- Datatype Comments - the parent category path.
+ +- Datatype Names - the parent category path.
+ +- Enum Values - the category path of the enum.
+ +- Field Names - the category path of the structure or union.
+ +- Functions - the namespace path.
+ +- Labels - the namespace path.
+ +- Local Variables - the namespace path.
+ +- Namespaces - the parent namespace path.
+ +- Parameters - the namespace path.
+ +- Program Trees - the program tree module path
+Applying Changes
+ +++ +Changes can be applied in bulk or individually.
+ +Apply All Button
+ +++ + +Press this button to apply all items in the table, regardless of what is + selected.
+Apply Selected Action
+ +++ + +Press the
+toolbar button or use the + popup action Execute Selected Action(s) to apply just the selected entries in + the table. If only one item is selected when this this is done, the selected item will + move to the next item in the table to facilitate a one at a time workflow.
+
There is also a popup toggle action + to turn on an option to auto delete applied entries from the table.
Navigation
+ +++ +If the
+ +toolbar button is + selected, selecting items in the table will attempt to navigate to that item in the tool + if possible.
Double clicking (or pressing return key) will also attempt to navigate the tool to the + selected item. In addition, if the item is related to a datatype, an editor for that + datatype will be shown.
+Search Examples
+ +++Basic Searches
+ +++ +Without using regular expressions, you can find matches that contain the search text + or fully match the search text by turning on the "whole word" option. However, to + perform a "starts with" or "ends with" search, you must use a regular expression. Also, + you can do advanced match and replace using regular expressions capture groups.
+ +The following examples assume we are trying to replace label names and we have the + following labels in our program:
+ ++
+ +- Apple
+ +- myApple
+ +- AppleJuice
++++ +
++ + +Search Type + +
+RegEx + +
+Whole Word + +
+Search For + +
+Replace With + +
+Matches + +
+Results +
++ + +Contains + +Off + +Off + +Apple + +Pear + +Apple, myApple, AppleJuice + +Pear, myPear, PearJuice ++ + +Matches Fully + +Off + +On + +Apple + +Pear + +Apple + +Pear ++ + +Starts With + +On + +N/A + +^Apple + +Pear + +Apple, AppleJuice + +Pear, PearJuice ++ + +Ends With + +On + +N/A + +Apple$ + +Pear + +Apple, MyApple + +Pear, MyPear +Advanced RegEx Searches
+ +++Regular Expression can do many advanced types of matching and replacing which is + beyond the scope of this document. However, a simple example using capture groups will + be given as follows:
+ ++++ +
++ + +Search For + +
+Replace With + +
+Matches + +
+Results +
++ + +Red(.*)Blue(.*) + +Green$1Purple$2 + +RedApplesBlueBerries + +GreenApplesPurpleBerries +
Provided by: SearchAndReplacePlugin
+
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Search/SearchAndReplace.htm b/Ghidra/Features/Base/src/main/help/help/topics/Search/SearchAndReplace.htm new file mode 100644 index 0000000000..3b261ce011 --- /dev/null +++ b/Ghidra/Features/Base/src/main/help/help/topics/Search/SearchAndReplace.htm @@ -0,0 +1,478 @@ + + + +
+ + +
+ + + + + +
+