Skip to content

Commit 7701f63

Browse files
committed
Merge remote-tracking branch 'origin/Ghidra_10.2'
2 parents bfe9fa8 + 17884b8 commit 7701f63

File tree

11 files changed

+653
-177
lines changed

11 files changed

+653
-177
lines changed

Ghidra/Configurations/Public_Release/src/global/docs/ChangeHistory.html

Lines changed: 364 additions & 1 deletion
Large diffs are not rendered by default.

Ghidra/Configurations/Public_Release/src/global/docs/WhatsNew.html

Lines changed: 162 additions & 105 deletions
Large diffs are not rendered by default.

Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/DBTrace.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ public void setChanged(TraceChangeRecord<?, ?> event) {
580580
}
581581

582582
@Override
583-
// NOTE: addListener synchronizes on this and might generate callbacks immediately
584-
public synchronized DBTraceProgramView getFixedProgramView(long snap) {
583+
public DBTraceProgramView getFixedProgramView(long snap) {
585584
// NOTE: The new viewport will need to read from the time manager during init
586585
DBTraceProgramView view;
587586
try (LockHold hold = lockRead()) {
@@ -595,8 +594,7 @@ public synchronized DBTraceProgramView getFixedProgramView(long snap) {
595594
}
596595

597596
@Override
598-
// NOTE: Ditto getFixedProgramView
599-
public synchronized DBTraceVariableSnapProgramView createProgramView(long snap) {
597+
public DBTraceVariableSnapProgramView createProgramView(long snap) {
600598
// NOTE: The new viewport will need to read from the time manager during init
601599
DBTraceVariableSnapProgramView view;
602600
try (LockHold hold = lockRead()) {
@@ -613,7 +611,7 @@ public DBTraceVariableSnapProgramView getProgramView() {
613611
}
614612

615613
@Override
616-
public synchronized DBTraceTimeViewport createTimeViewport() {
614+
public DBTraceTimeViewport createTimeViewport() {
617615
try (LockHold hold = lockRead()) {
618616
DBTraceTimeViewport view = new DBTraceTimeViewport(this);
619617
viewports.add(view);

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/StoredAnalyzerTimes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static StoredAnalyzerTimes getStoredAnalyzerTimes(Program program) {
165165
Options options = program.getOptions(OPTIONS_LIST);
166166
StoredAnalyzerTimes times = (StoredAnalyzerTimes) options
167167
.getCustomOption(StoredAnalyzerTimes.OPTION_NAME, new StoredAnalyzerTimes());
168-
return times;
168+
return times.clone();
169169
}
170170

171171
/**

Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ListingCodeComparisonPanel.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,8 @@ private void setupAreaMarkerSets() {
15591559
if (programs[LEFT] != null) {
15601560
AddressIndexMap indexMap = listingPanels[LEFT].getAddressIndexMap();
15611561
listingPanels[LEFT].getFieldPanel()
1562-
.setBackgroundColorModel(
1563-
new MarkerServiceBackgroundColorModel(markerManagers[LEFT], indexMap));
1562+
.setBackgroundColorModel(new MarkerServiceBackgroundColorModel(
1563+
markerManagers[LEFT], programs[LEFT], indexMap));
15641564
unmatchedCodeMarkers[LEFT] =
15651565
markerManagers[LEFT].createAreaMarker("Listing1 Unmatched Code",
15661566
"Instructions that are not matched to an instruction in the other function.",
@@ -1573,9 +1573,8 @@ private void setupAreaMarkerSets() {
15731573
if (programs[RIGHT] != null) {
15741574
AddressIndexMap rightIndexMap = listingPanels[RIGHT].getAddressIndexMap();
15751575
listingPanels[RIGHT].getFieldPanel()
1576-
.setBackgroundColorModel(
1577-
new MarkerServiceBackgroundColorModel(markerManagers[RIGHT],
1578-
rightIndexMap));
1576+
.setBackgroundColorModel(new MarkerServiceBackgroundColorModel(
1577+
markerManagers[RIGHT], programs[RIGHT], rightIndexMap));
15791578
unmatchedCodeMarkers[RIGHT] =
15801579
markerManagers[RIGHT].createAreaMarker("Listing2 Unmatched Code",
15811580
"Instructions that are not matched to an instruction in the other function.",
@@ -1675,8 +1674,8 @@ private void updateLeftAddressSet(Function leftFunction) {
16751674
indexMaps[LEFT] = new AddressIndexMap(addressSets[LEFT]);
16761675
markerManagers[LEFT].getOverviewProvider().setProgram(getLeftProgram(), indexMaps[LEFT]);
16771676
listingPanels[LEFT].getFieldPanel()
1678-
.setBackgroundColorModel(
1679-
new MarkerServiceBackgroundColorModel(markerManagers[LEFT], indexMaps[LEFT]));
1677+
.setBackgroundColorModel(new MarkerServiceBackgroundColorModel(markerManagers[LEFT],
1678+
programs[LEFT], indexMaps[LEFT]));
16801679
}
16811680

16821681
private void updateRightAddressSet(Function rightFunction) {
@@ -1692,8 +1691,8 @@ private void updateRightAddressSet(Function rightFunction) {
16921691
indexMaps[RIGHT] = new AddressIndexMap(addressSets[RIGHT]);
16931692
markerManagers[RIGHT].getOverviewProvider().setProgram(getRightProgram(), indexMaps[RIGHT]);
16941693
listingPanels[RIGHT].getFieldPanel()
1695-
.setBackgroundColorModel(
1696-
new MarkerServiceBackgroundColorModel(markerManagers[RIGHT], indexMaps[RIGHT]));
1694+
.setBackgroundColorModel(new MarkerServiceBackgroundColorModel(
1695+
markerManagers[RIGHT], programs[RIGHT], indexMaps[RIGHT]));
16971696
}
16981697

16991698
@Override

Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,15 @@ public Function createEmptyFunction(String name, String namespace, String callin
597597
returnType, params);
598598
}
599599

600+
public void deleteFunction(String address) throws Exception {
601+
602+
tx(() -> {
603+
Address entryPoint = addr(address);
604+
FunctionManager functionManager = program.getFunctionManager();
605+
functionManager.removeFunction(entryPoint);
606+
});
607+
}
608+
600609
public Library createLibrary(String libraryName)
601610
throws DuplicateNameException, InvalidInputException {
602611
return createLibrary(libraryName, SourceType.USER_DEFINED);

Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ void createFunction(String address) throws Exception {
341341
waitForBusyTool(tool);
342342
}
343343

344+
void deleteFunction(String address) throws Exception {
345+
setLocation(address);
346+
builder.deleteFunction(address);
347+
waitForBusyTool(tool);
348+
}
349+
344350
void analyzeStack(String address) {
345351
setLocation(address);
346352
DockingActionIf analyzeStack =

Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorProvider1Test.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626

2727
import docking.action.DockingActionIf;
28+
import ghidra.app.util.datatype.EmptyCompositeException;
2829
import ghidra.framework.options.Options;
2930
import ghidra.program.model.data.*;
3031
import ghidra.program.model.listing.*;
@@ -139,10 +140,12 @@ public void testEditUnchangedStackAndDeleteFunction() throws Exception {
139140
}
140141

141142
@Test
142-
public void testUndoAssociatedFunctionCreate() throws Exception {
143+
public void testDeleteAssociatedFunction() throws Exception {
143144
Window dialog;
144145
// Create the stack frame @ 00000200.
145146
createFunction("0x200");
147+
waitForBusyTool(tool); // wait for analysis to complete
148+
146149
editStack("0x200");
147150

148151
Function f = program.getFunctionManager().getFunctionAt(addr("0x200"));
@@ -159,16 +162,23 @@ public void testUndoAssociatedFunctionCreate() throws Exception {
159162
// Put byte at -0x18
160163
setType(new ByteDataType(), 0);
161164

162-
// Undo the apply of a new data type to an editor component.
163-
undo(program, false); // don't wait, in case there is a modal dialog
164-
waitForSwing();
165+
runSwing(() -> {
166+
try {
167+
model.apply();
168+
}
169+
catch (EmptyCompositeException | InvalidDataTypeException e) {
170+
failWithException("Editor apply failure", e);
171+
}
172+
});
173+
174+
deleteFunction("0x200");
165175

166176
// Verify the Reload Stack Editor? dialog is not displayed.
167177
dialog = getWindow("Reload Stack Editor?");
168178
assertNull(dialog);
169179

170180
// Verify the stack editor is not displayed.
171-
assertStackEditorHidden(f);
181+
assertStackEditorHidden(f); // This occurs if function is removed
172182
}
173183

174184
@Test

Ghidra/Features/BytePatterns/src/main/java/ghidra/app/analyzers/FunctionStartAnalyzer.java

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import ghidra.xml.XmlPullParser;
4545

4646
public class FunctionStartAnalyzer extends AbstractAnalyzer implements PatternFactory {
47-
private static final String FUNCTION_START_SEARCH = "Function Start Search";
47+
protected static final String FUNCTION_START_SEARCH = "Function Start Search";
4848
protected static final String NAME = FUNCTION_START_SEARCH;
4949
private static final String DESCRIPTION =
5050
"Search for architecture specific byte patterns: typically starts of functions";
@@ -742,7 +742,7 @@ public BigInteger getValue() {
742742
}
743743

744744
}
745-
745+
746746
@Override
747747
public boolean canAnalyze(Program program) {
748748
ProgramDecisionTree patternDecisionTree = getPatternDecisionTree();
@@ -816,57 +816,17 @@ public void postMatchApply(MatchAction[] actions, Address addr) {
816816

817817
AutoAnalysisManager analysisManager = AutoAnalysisManager.getAnalysisManager(program);
818818
if (!disassemResult.isEmpty()) {
819-
analysisManager.disassemble(disassemResult);
819+
analysisManager.disassemble(disassemResult, AnalysisPriority.DISASSEMBLY);
820820
}
821821
analysisManager.setProtectedLocations(codeLocations);
822822

823823
if (!potentialFuncResult.isEmpty()) {
824824
// could be a pattern that said this is a function start, so it isn't potentially anymore
825825
potentialFuncResult = potentialFuncResult.subtract(funcResult);
826826

827-
// kick off a later analyzer to create the functions after all the fallout
828-
// it should check that the function is not already part of another function
829-
analysisManager.scheduleOneTimeAnalysis(new AnalyzerAdapter(
830-
FUNCTION_START_SEARCH + " delayed", AnalysisPriority.DATA_ANALYSIS.after()) {
831-
@Override
832-
public boolean added(Program addedProgram, AddressSetView addedSet,
833-
TaskMonitor addedMonitor, MessageLog addedLog) throws CancelledException {
834-
AddressIterator addresses = addedSet.getAddresses(true);
835-
while (addresses.hasNext() && !addedMonitor.isCancelled()) {
836-
Address address = addresses.next();
837-
// if there are any conditional references, then this can't be a function start
838-
if (hasConditionalReferences(addedProgram, address)) {
839-
continue;
840-
}
841-
Function funcAt =
842-
addedProgram.getFunctionManager().getFunctionContaining(address);
843-
if (funcAt != null) {
844-
if (funcAt.getEntryPoint().equals(address)) {
845-
continue;
846-
}
847-
BookmarkManager bookmarkManager = addedProgram.getBookmarkManager();
848-
bookmarkManager.setBookmark(address, BookmarkType.ANALYSIS,
849-
getName() + " Overlap",
850-
"Function exists at probable good function start");
851-
continue;
852-
}
853-
new CreateFunctionCmd(address, false).applyTo(addedProgram, addedMonitor);
854-
}
855-
return true;
856-
}
857-
858-
private boolean hasConditionalReferences(Program addedProgram, Address address) {
859-
ReferenceIterator refsTo =
860-
addedProgram.getReferenceManager().getReferencesTo(address);
861-
while (refsTo.hasNext()) {
862-
Reference reference = refsTo.next();
863-
if (reference.getReferenceType().isConditional()) {
864-
return true;
865-
}
866-
}
867-
return false;
868-
}
869-
}, potentialFuncResult);
827+
// kick off a later analyzer to create the functions after all the fallout from disassemlby
828+
PossibleDelayedFunctionCreator analyzer = new PossibleDelayedFunctionCreator();
829+
analysisManager.scheduleOneTimeAnalysis(analyzer, potentialFuncResult);
870830
}
871831

872832
if (!funcResult.isEmpty()) {
@@ -994,3 +954,59 @@ public PostRule getPostRuleByName(String nm) {
994954
}
995955

996956
}
957+
958+
/**
959+
*
960+
* One time analyzer used to delay function creation until disassembly has settled.
961+
*/
962+
final class PossibleDelayedFunctionCreator extends AnalyzerAdapter {
963+
964+
PossibleDelayedFunctionCreator() {
965+
super(FunctionStartAnalyzer.FUNCTION_START_SEARCH + " delayed", AnalysisPriority.DATA_ANALYSIS.after());
966+
}
967+
968+
@Override
969+
public boolean added(Program addedProgram, AddressSetView addedSet,
970+
TaskMonitor addedMonitor, MessageLog addedLog) throws CancelledException {
971+
AddressIterator addresses = addedSet.getAddresses(true);
972+
AddressSet functionStarts = new AddressSet();
973+
while (addresses.hasNext() && !addedMonitor.isCancelled()) {
974+
Address address = addresses.next();
975+
// if there are any conditional references, then this can't be a function start
976+
if (hasConditionalReferences(addedProgram, address)) {
977+
continue;
978+
}
979+
980+
// Check for any function containing the potential start detected earlier in analysis
981+
Function funcAt =
982+
addedProgram.getFunctionManager().getFunctionContaining(address);
983+
if (funcAt != null) {
984+
if (funcAt.getEntryPoint().equals(address)) {
985+
continue;
986+
}
987+
BookmarkManager bookmarkManager = addedProgram.getBookmarkManager();
988+
bookmarkManager.setBookmark(address, BookmarkType.ANALYSIS,
989+
getName() + " Overlap",
990+
"Function exists at probable good function start");
991+
continue;
992+
}
993+
functionStarts.add(address);
994+
}
995+
996+
// create functions that still don't exist/overlap
997+
new CreateFunctionCmd(functionStarts, false).applyTo(addedProgram, addedMonitor);
998+
return true;
999+
}
1000+
1001+
private boolean hasConditionalReferences(Program addedProgram, Address address) {
1002+
ReferenceIterator refsTo =
1003+
addedProgram.getReferenceManager().getReferencesTo(address);
1004+
while (refsTo.hasNext()) {
1005+
Reference reference = refsTo.next();
1006+
if (reference.getReferenceType().isConditional()) {
1007+
return true;
1008+
}
1009+
}
1010+
return false;
1011+
}
1012+
}

Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/app/plugin/assembler/sleigh/ARMAssemblyTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,14 @@ public void testAssemble_T_push_r7_lr() {
111111
}
112112

113113
@Test
114-
public void testAssemble_T_vmov_i32_d0_simdExpand_0x0_0x0_0xb1() {
114+
public void testAssemble_T_vmov_simd_immed() {
115115
assertOneCompatRestExact("vmov.i32 d0,simdExpand(0x0,0x0,0xb1)", "83:ff:11:00", THUMB,
116116
0x00010100, "vmov.i32 d0,simdExpand(0x0,0x0,0xb1)");
117+
assertOneCompatRestExact("vmov.i16 d0,simdExpand(0x0,0xa,0xb1)", "83:ff:11:0a", THUMB,
118+
0x00010100, "vmov.i16 d0,simdExpand(0x0,0xa,0xb1)");
119+
assertOneCompatRestExact("vmov.i32 d0,simdExpand(0x0,0xd,0xb1)", "83:ff:11:0d", THUMB,
120+
0x00010100, "vmov.i32 d0,simdExpand(0x0,0xd,0xb1)");
121+
assertOneCompatRestExact("vmov.i64 d0,simdExpand(0x1,0xe,0xb1)", "83:ff:31:0e", THUMB,
122+
0x00010100, "vmov.i64 d0,simdExpand(0x1,0xe,0xb1)");
117123
}
118124
}

0 commit comments

Comments
 (0)