GP-5742 Cleanup preferred CommentType enum use. Changed SARIF data component comment JSON serialization from int to String.

This commit is contained in:
ghidra1
2025-06-06 17:58:07 -04:00
parent 4a65e9af3b
commit 8c441250f5
211 changed files with 4627 additions and 4860 deletions
@@ -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.
@@ -41,7 +41,7 @@ import ghidra.app.util.viewer.field.*;
import ghidra.app.util.viewer.listingpanel.ListingPanel;
import ghidra.app.util.viewer.listingpanel.OverviewProvider;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
public class CodeBrowserPluginScreenShots extends GhidraScreenShotGenerator {
@@ -253,7 +253,7 @@ public class CodeBrowserPluginScreenShots extends GhidraScreenShotGenerator {
setToolSize(1000, 800);
positionListingTop(0x040364c);
createComment(0x403653, CodeUnit.PRE_COMMENT, "PUSH some stuff");
createComment(0x403653, CommentType.PRE, "PUSH some stuff");
positionCursor(0x0403653, MnemonicFieldFactory.FIELD_NAME);
middleClickCursor();
@@ -366,7 +366,7 @@ public class CodeBrowserPluginScreenShots extends GhidraScreenShotGenerator {
waitForBusyTool(tool);
}
private void createComment(long address, int commentType, String comment) {
private void createComment(long address, CommentType commentType, String comment) {
goToListing(address);
SetCommentCmd cmd = new SetCommentCmd(addr(address), commentType, comment);
tool.execute(cmd, program);
@@ -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.
@@ -68,11 +68,11 @@ public class CommentWindowPluginScreenShots extends GhidraScreenShotGenerator {
int id = prog.startTransaction("Test");
Listing listing = prog.getListing();
listing.setComment(addr(0x00401006), CodeUnit.EOL_COMMENT, "My EOL comment");
listing.setComment(addr(0x0040101b), CodeUnit.PRE_COMMENT, "My Pre comment");
listing.setComment(addr(0x0040101c), CodeUnit.POST_COMMENT, "My Post comment");
listing.setComment(addr(0x00401020), CodeUnit.PLATE_COMMENT, "My Plate comment");
listing.setComment(addr(0x0040100d), CodeUnit.REPEATABLE_COMMENT, "My Repeatable comment");
listing.setComment(addr(0x00401006), CommentType.EOL, "My EOL comment");
listing.setComment(addr(0x0040101b), CommentType.PRE, "My Pre comment");
listing.setComment(addr(0x0040101c), CommentType.POST, "My Post comment");
listing.setComment(addr(0x00401020), CommentType.PLATE, "My Plate comment");
listing.setComment(addr(0x0040100d), CommentType.REPEATABLE, "My Repeatable comment");
prog.endTransaction(id, true);
prog.flushEvents();
waitForSwing();
@@ -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.
@@ -32,7 +32,8 @@ import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.app.util.viewer.listingpanel.ListingPanel;
import ghidra.features.base.codecompare.listing.ListingCodeComparisonPanel;
import ghidra.features.base.codecompare.panel.FunctionComparisonPanel;
import ghidra.features.codecompare.plugin.*;
import ghidra.features.codecompare.plugin.FunctionComparisonPlugin;
import ghidra.features.codecompare.plugin.FunctionComparisonProvider;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.*;
@@ -85,7 +86,7 @@ public class FunctionComparisonScreenShots extends GhidraScreenShotGenerator {
Function f1 = getFunction(sourceProgram, addr(0x004118f0));
f1.setName("FunctionA", SourceType.USER_DEFINED);
sourceListing.setComment(addr(0x004118f0), CodeUnit.PLATE_COMMENT, null);
sourceListing.setComment(addr(0x004118f0), CommentType.PLATE, null);
sourceListing.clearCodeUnits(addr(0x004119b1), addr(0x004119b4), false);
sourceMemory.setByte(addr(0x004119b2), (byte) 0x55);
sourceMemory.setByte(addr(0x004119b4), (byte) 0x52);
@@ -93,13 +94,12 @@ public class FunctionComparisonScreenShots extends GhidraScreenShotGenerator {
Function f2 = getFunction(destinationProgram, addr(0x004118c0));
f2.setName("FunctionB", SourceType.USER_DEFINED);
destListing.setComment(addr(0x004118c0), CodeUnit.PLATE_COMMENT, null);
destListing.setComment(addr(0x004118c0), CommentType.PLATE, null);
plugin.createComparison(f1, f2);
FunctionComparisonProvider provider =
waitForComponentProvider(FunctionComparisonProvider.class);
FunctionComparisonPanel functionComparisonPanel =
provider.getComponent();
FunctionComparisonPanel functionComparisonPanel = provider.getComponent();
runSwing(() -> {
functionComparisonPanel.setCurrentTabbedComponent("Listing View");
ListingCodeComparisonPanel dualListing =
@@ -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.
@@ -363,8 +363,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
ProgramContext pc = program.getProgramContext();
Register regDR0 = pc.getRegister(regNameDR0);
setRegValue(pc, addr(program, "004010a0"), addr(program, "004010a3"), regDR0,
0x5L);
setRegValue(pc, addr(program, "004010a0"), addr(program, "004010a3"), regDR0, 0x5L);
}
@Override
@@ -1512,8 +1511,8 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
ReferenceManager refMgr = program.getReferenceManager();
ProgramContext pc = program.getProgramContext();
Register regESI = pc.getRegister("ESI");
refMgr.addRegisterReference(addr(program, "0x004018e4"), 0, regESI,
RefType.READ, SourceType.USER_DEFINED);
refMgr.addRegisterReference(addr(program, "0x004018e4"), 0, regESI, RefType.READ,
SourceType.USER_DEFINED);
}
@Override
@@ -1596,15 +1595,14 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
@Override
public void modifyLatest(ProgramDB program) throws Exception {
ReferenceManager refMgr = program.getReferenceManager();
refMgr.addMemoryReference(addr(program, "0x004017db"),
addr(program, "0x00401953"), RefType.READ, SourceType.USER_DEFINED, 1);
refMgr.addMemoryReference(addr(program, "0x004017db"),
addr(program, "0x0040cbc8"), RefType.DATA, SourceType.USER_DEFINED, 1);
refMgr.addMemoryReference(addr(program, "0x004017db"),
addr(program, "0x004018bc"), RefType.READ_IND, SourceType.USER_DEFINED, 1);
refMgr.addExternalReference(addr(program, "0x00401810"), "USER32.DLL",
"getMessage", addr(program, "0x1001a11"), SourceType.USER_DEFINED, 0,
RefType.DATA);
refMgr.addMemoryReference(addr(program, "0x004017db"), addr(program, "0x00401953"),
RefType.READ, SourceType.USER_DEFINED, 1);
refMgr.addMemoryReference(addr(program, "0x004017db"), addr(program, "0x0040cbc8"),
RefType.DATA, SourceType.USER_DEFINED, 1);
refMgr.addMemoryReference(addr(program, "0x004017db"), addr(program, "0x004018bc"),
RefType.READ_IND, SourceType.USER_DEFINED, 1);
refMgr.addExternalReference(addr(program, "0x00401810"), "USER32.DLL", "getMessage",
addr(program, "0x1001a11"), SourceType.USER_DEFINED, 0, RefType.DATA);
}
@Override
@@ -1612,14 +1610,12 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
ReferenceManager refMgr = program.getReferenceManager();
refMgr.addExternalReference(addr(program, "0x004017db"), "USER32.DLL", "printf",
addr(program, "0x01234567"), SourceType.USER_DEFINED, 1, RefType.DATA);
refMgr.addMemoryReference(addr(program, "0x00401810"),
addr(program, "0x00000010"), RefType.CONDITIONAL_JUMP,
SourceType.USER_DEFINED, 0);
refMgr.addMemoryReference(addr(program, "0x00401810"),
addr(program, "0x100190b"), RefType.DATA, SourceType.USER_DEFINED, 0);
refMgr.addMemoryReference(addr(program, "0x00401810"),
addr(program, "0x100191f"), RefType.CONDITIONAL_JUMP,
SourceType.USER_DEFINED, 0);
refMgr.addMemoryReference(addr(program, "0x00401810"), addr(program, "0x00000010"),
RefType.CONDITIONAL_JUMP, SourceType.USER_DEFINED, 0);
refMgr.addMemoryReference(addr(program, "0x00401810"), addr(program, "0x100190b"),
RefType.DATA, SourceType.USER_DEFINED, 0);
refMgr.addMemoryReference(addr(program, "0x00401810"), addr(program, "0x100191f"),
RefType.CONDITIONAL_JUMP, SourceType.USER_DEFINED, 0);
}
});
@@ -1721,7 +1717,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT, "Before the code unit.");
cu.setComment(CommentType.PRE, "Before the code unit.");
}
@Override
@@ -1729,7 +1725,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT, null);
cu.setComment(CommentType.PRE, null);
}
@Override
@@ -1737,7 +1733,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT, "This is a changed pre-comment.");
cu.setComment(CommentType.PRE, "This is a changed pre-comment.");
}
});
@@ -1765,7 +1761,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT, "This is a simple comment for example.");
cu.setComment(CommentType.PRE, "This is a simple comment for example.");
}
@Override
@@ -1773,7 +1769,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT, "This is a simple comment for example.\n" +
cu.setComment(CommentType.PRE, "This is a simple comment for example.\n" +
"I added some more to this comment to make it multiple lines.");
}
@@ -1782,9 +1778,8 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
Listing listing = program.getListing();
CodeUnit cu;
cu = listing.getCodeUnitAt(addr(program, "0x0040156c"));
cu.setComment(CodeUnit.PRE_COMMENT,
"Changed this to a multiple line comment.\n" +
"It was necessary for demonstration purposes.");
cu.setComment(CommentType.PRE, "Changed this to a multiple line comment.\n" +
"It was necessary for demonstration purposes.");
}
});
@@ -1935,7 +1930,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
SourceArchive sourceArchive =
dtm.getSourceArchive(myTestArchive.getDataTypeManager().getUniversalID());
sourceArchive.setName("TestArchiveOne");
assertNotNull(sourceArchive);
assertEquals("TestArchiveOne", sourceArchive.getName());
}
@@ -1947,7 +1942,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest {
SourceArchive sourceArchive =
dtm.getSourceArchive(myTestArchive.getDataTypeManager().getUniversalID());
sourceArchive.setName("TestArchiveTwo");
assertNotNull(sourceArchive);
assertEquals("TestArchiveTwo", sourceArchive.getName());
}
@@ -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.
@@ -149,7 +149,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
builder.createComment("0x0100415a",
"\n;|||||||||||||||||||| FUNCTION ||||||||||||||||||||||||||||||||||||||||||||||||||\n ",
CodeUnit.PLATE_COMMENT);
CommentType.PLATE);
builder.setBytes("0x0100418c", "ff 15 08 10 00 01");
builder.disassemble("0x0100418c", 6);
@@ -633,7 +633,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
// 3)
// 0100415a PreCommentFieldLocation
CommentFieldLocation commentFieldLocation = new CommentFieldLocation(program,
addr("0100415a"), null, new String[] { "" }, CodeUnit.PRE_COMMENT, 5, 10);
addr("0100415a"), null, new String[] { "" }, CommentType.PRE, 5, 10);
codeBrowserPlugin.goTo(plateFieldLocation);
@@ -1008,8 +1008,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
Rectangle bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
ProgramSelection selection =
new ProgramSelection(program.getAddressFactory(), addr("1001050"), addr("1001052"));
ProgramSelection selection = new ProgramSelection(addr("1001050"), addr("1001052"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -1034,8 +1033,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
selection =
new ProgramSelection(program.getAddressFactory(), addr("1001050"), addr("1001052"));
selection = new ProgramSelection(addr("1001050"), addr("1001052"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -1058,8 +1056,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
selection =
new ProgramSelection(program.getAddressFactory(), addr("1001050"), addr("1001052"));
selection = new ProgramSelection(addr("1001050"), addr("1001052"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -1100,8 +1097,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
Rectangle bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
ProgramSelection selection =
new ProgramSelection(program.getAddressFactory(), addr("1001051"), addr("1001070"));
ProgramSelection selection = new ProgramSelection(addr("1001051"), addr("1001070"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -1127,8 +1123,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
selection =
new ProgramSelection(program.getAddressFactory(), addr("1001051"), addr("1001070"));
selection = new ProgramSelection(addr("1001051"), addr("1001070"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -1151,8 +1146,7 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
bounds = bc.getBounds();
clickMouse(bc, 1, bounds.x + 20, bounds.y + 20, 1, 0);
selection =
new ProgramSelection(program.getAddressFactory(), addr("1001051"), addr("1001070"));
selection = new ProgramSelection(addr("1001051"), addr("1001070"));
tool.firePluginEvent(new ProgramSelectionPluginEvent("Test", selection, program));
waitForBusyTool(tool);
@@ -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,8 +38,7 @@ import ghidra.framework.model.DomainFile;
import ghidra.framework.model.DomainFolder;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolTable;
import ghidra.util.task.TaskMonitor;
@@ -222,8 +221,7 @@ public class VersionControlAction2Test extends AbstractVersionControlActionTest
waitForTasks();
ProgramDB program = (ProgramDB) ((DomainFileNode) node).getDomainFile()
.getDomainObject(this,
true, false, TaskMonitor.DUMMY);
.getDomainObject(this, true, false, TaskMonitor.DUMMY);
int transactionID = program.startTransaction("test");
try {
SymbolTable symTable = program.getSymbolTable();
@@ -255,7 +253,7 @@ public class VersionControlAction2Test extends AbstractVersionControlActionTest
assertTrue(!df.isCheckedOut());
}
@Test
public void testCheckInWhileOpen() throws Exception {
GTreeNode node = getNode(PROGRAM_A);
@@ -268,15 +266,15 @@ public class VersionControlAction2Test extends AbstractVersionControlActionTest
waitForTasks();
ProgramDB program = (ProgramDB) ((DomainFileNode) node).getDomainFile()
.getDomainObject(this,
true, false, TaskMonitor.DUMMY);
.getDomainObject(this, true, false, TaskMonitor.DUMMY);
int transactionID = program.startTransaction("test");
try {
// Ensure that buffer memory cache has been completely consumed
// Max BufferMgr cache size is 256*16KByte=4MByte
AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
program.getMemory().createInitializedBlock("BigBlock", space.getAddress(0x80000000L),
4*1024*1024, (byte)0xff, TaskMonitor.DUMMY, false);
program.getMemory()
.createInitializedBlock("BigBlock", space.getAddress(0x80000000L),
4 * 1024 * 1024, (byte) 0xff, TaskMonitor.DUMMY, false);
}
finally {
program.endTransaction(transactionID, true);
@@ -446,7 +444,7 @@ public class VersionControlAction2Test extends AbstractVersionControlActionTest
Program p = (Program) df.getDomainObject(this, true, false, TaskMonitor.DUMMY);
editProgram(p, program -> {
CodeUnit cu = program.getListing().getCodeUnitAt(program.getMinAddress());
cu.setComment(CodeUnit.PLATE_COMMENT, "my Plate Comment");
cu.setComment(CommentType.PLATE, "my Plate Comment");
});
p.release(this);
@@ -486,6 +484,7 @@ public class VersionControlAction2Test extends AbstractVersionControlActionTest
* @param icon the icon to get a URL for
* @return the URL for the given icon
*/
@Override
public URL getURL(Icon icon) {
if (icon instanceof UrlImageIcon urlIcon) {
return urlIcon.getUrl();