GP-9181 - Theming - Base Module

This commit is contained in:
dragonmacher
2022-09-15 17:44:01 -04:00
committed by ghidragon
parent 2dade60b3e
commit 4eb3d8fd86
113 changed files with 1092 additions and 1099 deletions

View File

@@ -17,7 +17,6 @@
//NOTE: I do not de-duplicate, since the address of the instruction may affect the output.
//@category Assembly
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.HashSet;
@@ -27,6 +26,7 @@ import javax.swing.ImageIcon;
import org.apache.commons.lang3.StringUtils;
import generic.theme.GThemeDefaults.Colors.Palette;
import ghidra.app.plugin.assembler.*;
import ghidra.app.plugin.assembler.sleigh.sem.*;
import ghidra.app.plugin.processors.sleigh.SleighDebugLogger;
@@ -105,7 +105,7 @@ public class AssemblyThrasherDevScript extends GhidraScript {
BookmarkManager bm = currentProgram.getBookmarkManager();
ImageIcon myIcon = ResourceManager.loadImage("images/warning.png");
bm.defineType(BOOKMARK_FAIL, myIcon, new Color(255, 255, 0), 0);
bm.defineType(BOOKMARK_FAIL, myIcon, Palette.YELLOW, 0);
bm.removeBookmarks(BOOKMARK_FAIL);
monitor.setMessage("Constructing Assembler");
@@ -157,7 +157,7 @@ public class AssemblyThrasherDevScript extends GhidraScript {
}
println("Unique instructions by constructor: " + done.size());
setBackgroundColor(uniques, new Color(255, 128, 128));
setBackgroundColor(uniques, Palette.getColor("lightcoral"));
}
protected PseudoInstruction disassemble(Instruction orig, byte[] ins) {

View File

@@ -16,13 +16,14 @@
// An example of how to color the listing background
//@category Examples
import java.awt.Color;
import generic.theme.GThemeDefaults.Colors.Palette;
import ghidra.app.plugin.core.colorizer.ColorizingService;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import java.awt.Color;
public class ExampleColorScript extends GhidraScript {
@Override
@@ -34,10 +35,10 @@ public class ExampleColorScript extends GhidraScript {
}
if (currentSelection != null) {
service.setBackgroundColor(currentSelection, new Color(255, 200, 200));
service.setBackgroundColor(currentSelection, Palette.PINK);
}
else if (currentAddress != null) {
service.setBackgroundColor(currentAddress, currentAddress, new Color(255, 200, 200));
service.setBackgroundColor(currentAddress, currentAddress, Palette.PINK);
}
else {
println("No selection or current address to color");

View File

@@ -19,12 +19,12 @@
import java.util.ArrayList;
import java.util.List;
import generic.theme.GThemeDefaults.Colors.Palette;
import ghidra.app.script.GhidraScript;
import ghidra.app.services.GraphDisplayBroker;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.data.*;
import ghidra.service.graph.*;
import ghidra.util.WebColors;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -36,7 +36,7 @@ public class GraphClassesScript extends GhidraScript {
private static final String VIRTUAL_INHERITANCE = "Virtual Inheritance";
private static final String NON_VIRTUAL_INHERITANCE = "Non-virtual Inheritance";
List<Structure> classStructures = new ArrayList<Structure>();
List<Structure> classStructures = new ArrayList<>();
@Override
public void run() throws Exception {
@@ -107,9 +107,8 @@ public class GraphClassesScript extends GhidraScript {
}
/**
* Method to create a graph using preconfigured information found in class structure descriptions.
* The structure descriptions are created using
* {@link RecoveredClassUtils#createParentStringBuffer(RecoveredClass)}
* Method to create a graph using pre-configured information found in class structure
* descriptions.
* @return the newly created graph
*/
private AttributedGraph createGraph() throws Exception {
@@ -290,7 +289,7 @@ public class GraphClassesScript extends GhidraScript {
private Structure getParentStructureFromClassStructures(String parentName)
throws CancelledException {
List<Structure> parentStructures = new ArrayList<Structure>();
List<Structure> parentStructures = new ArrayList<>();
for (Structure classStructure : classStructures) {
monitor.checkCanceled();
@@ -315,13 +314,13 @@ public class GraphClassesScript extends GhidraScript {
display = service.getGraphDisplay(false, TaskMonitor.DUMMY);
GraphDisplayOptions graphOptions = new GraphDisplayOptionsBuilder(graph.getGraphType())
.vertex(NO_INHERITANCE, VertexShape.RECTANGLE, WebColors.BLUE)
.vertex(SINGLE_INHERITANCE, VertexShape.RECTANGLE, WebColors.GREEN)
.vertex(MULTIPLE_INHERITANCE, VertexShape.RECTANGLE, WebColors.RED)
.edge(NON_VIRTUAL_INHERITANCE, WebColors.LIME_GREEN)
.edge(VIRTUAL_INHERITANCE, WebColors.ORANGE)
.defaultVertexColor(WebColors.PURPLE)
.defaultEdgeColor(WebColors.PURPLE)
.vertex(NO_INHERITANCE, VertexShape.RECTANGLE, Palette.BLUE)
.vertex(SINGLE_INHERITANCE, VertexShape.RECTANGLE, Palette.GREEN)
.vertex(MULTIPLE_INHERITANCE, VertexShape.RECTANGLE, Palette.RED)
.edge(NON_VIRTUAL_INHERITANCE, Palette.LIME)
.edge(VIRTUAL_INHERITANCE, Palette.ORANGE)
.defaultVertexColor(Palette.PURPLE)
.defaultEdgeColor(Palette.PURPLE)
.defaultLayoutAlgorithm("Compact Hierarchical")
.maxNodeCount(1000)
.build();
@@ -330,7 +329,6 @@ public class GraphClassesScript extends GhidraScript {
"Recovered Classes Graph", false, TaskMonitor.DUMMY);
}
private String getClassName(String description) {
int indexOfColon = getIndexOfFirstSingleColon(description);

View File

@@ -26,6 +26,9 @@ import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import generic.theme.GThemeDefaults.Colors;
import generic.theme.GThemeDefaults.Colors.Palette;
public class SearchGuiMulti extends SearchBaseExtended {
private JScrollPane jScrollPane1;
@@ -65,39 +68,19 @@ public class SearchGuiMulti extends SearchBaseExtended {
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
mnemonicButton.setText("Mnemonic");
mnemonicButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
mnemonicButtonActionPerformed(evt);
}
});
mnemonicButton.addActionListener(evt -> mnemonicButtonActionPerformed(evt));
mnemonicButton.setVisible(false);
op1Button.setText("Operand 1");
op1Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
op1ButtonActionPerformed(evt);
}
});
op1Button.addActionListener(evt -> op1ButtonActionPerformed(evt));
op1Button.setVisible(false);
op2Button.setText("Operand 2");
op2Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
op2ButtonActionPerformed(evt);
}
});
op2Button.addActionListener(evt -> op2ButtonActionPerformed(evt));
op2Button.setVisible(false);
searchButton.setText("Search");
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
searchButtonActionPerformed(evt);
}
});
searchButton.addActionListener(evt -> searchButtonActionPerformed(evt));
fillTable();
tableModel = new DefaultTableModel(tableContentsDO, columnIdentifiers) {
@@ -122,12 +105,7 @@ public class SearchGuiMulti extends SearchBaseExtended {
Color backgroundColor = dataObject.getBackgroundColor();
if (backgroundColor != null) {
if (isSelected) {
theRenderer.setBackground(backgroundColor.darker());
}
else {
theRenderer.setBackground(backgroundColor);
}
theRenderer.setBackground(backgroundColor);
}
return theRenderer;
@@ -152,45 +130,47 @@ public class SearchGuiMulti extends SearchBaseExtended {
GroupLayout layout = new GroupLayout(frame.getContentPane());
frame.getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap(15, Short.MAX_VALUE) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() //
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 357,
GroupLayout.PREFERRED_SIZE) //
.addContainerGap() //
) //
.addGroup(GroupLayout.Alignment.CENTER, layout.createSequentialGroup() //
.addComponent(mnemonicButton) //
.addGap(39, 39, 39) //
.addComponent(op1Button) //
.addGap(42, 42, 42) //
.addComponent(op2Button) //
.addGap(40, 40, 40) //
) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap(15, Short.MAX_VALUE) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(GroupLayout.Alignment.TRAILING, layout
.createSequentialGroup() //
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 357,
GroupLayout.PREFERRED_SIZE) //
.addContainerGap() //
) //
.addGroup(GroupLayout.Alignment.CENTER,
layout.createSequentialGroup() //
.addComponent(mnemonicButton) //
.addGap(39, 39, 39) //
.addComponent(op1Button) //
.addGap(42, 42, 42) //
.addComponent(op2Button) //
.addGap(40, 40, 40) //
) //
) //
) //
.addGroup(layout.createSequentialGroup() //
.addGap(153, 153, 153) //
.addComponent(searchButton) //
.addContainerGap(164, Short.MAX_VALUE) //
) //
) //
.addGroup(layout.createSequentialGroup() //
.addGap(153, 153, 153) //
.addComponent(searchButton) //
.addContainerGap(164, Short.MAX_VALUE) //
) //
);
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createSequentialGroup() //
.addGap(23, 23, 23) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) //
.addComponent(op1Button) //
.addComponent(op2Button) //
.addComponent(mnemonicButton) //
.addGroup(layout.createSequentialGroup() //
.addGap(23, 23, 23) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) //
.addComponent(op1Button) //
.addComponent(op2Button) //
.addComponent(mnemonicButton) //
) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 402,
GroupLayout.PREFERRED_SIZE) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(searchButton) //
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //
) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 402,
GroupLayout.PREFERRED_SIZE) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(searchButton) //
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //
) //
);
frame.pack();
@@ -205,7 +185,7 @@ public class SearchGuiMulti extends SearchBaseExtended {
if (column == 0) {
tableContentsDO[mnemonic][column] =
new DataObject(mnemonics.get(mnemonic).textRep, Color.green);
new DataObject(mnemonics.get(mnemonic).textRep, Palette.GREEN);
}
else {
OperandCase temp = null;
@@ -217,10 +197,10 @@ public class SearchGuiMulti extends SearchBaseExtended {
}
if (temp != null) {
tableContentsDO[mnemonic][column] =
new DataObject(temp.textRep, Color.red.brighter());
new DataObject(temp.textRep, Palette.PINK);
}
else {
tableContentsDO[mnemonic][column] = new DataObject("", Color.white);
tableContentsDO[mnemonic][column] = new DataObject("", Palette.WHITE);
}
}
@@ -239,13 +219,13 @@ public class SearchGuiMulti extends SearchBaseExtended {
throw new IndexOutOfBoundsException();
}
if (tableContentsDO[rowSelection][columnSelection].getBackgroundColor().equals(
Color.green)) {
tableContentsDO[rowSelection][columnSelection].setBackgroundColor(Color.red);
if (tableContentsDO[rowSelection][columnSelection].getBackgroundColor()
.equals(Palette.GREEN)) {
tableContentsDO[rowSelection][columnSelection].setBackgroundColor(Palette.RED);
}
else if (tableContentsDO[rowSelection][columnSelection].getBackgroundColor().equals(
Color.red)) {
tableContentsDO[rowSelection][columnSelection].setBackgroundColor(Color.green);
else if (tableContentsDO[rowSelection][columnSelection].getBackgroundColor()
.equals(Palette.RED)) {
tableContentsDO[rowSelection][columnSelection].setBackgroundColor(Palette.GREEN);
}
else {
//TODO Determine what to do if the cell is white when clicked on. White cell means that there isn't an operand or mnemonic in that position.
@@ -258,10 +238,10 @@ public class SearchGuiMulti extends SearchBaseExtended {
int selectedRow = jTable1.getSelectedRow();
if (mnemonicButton.isSelected()) {
tableContentsDO[selectedRow][0].setBackgroundColor(Color.red);
tableContentsDO[selectedRow][0].setBackgroundColor(Palette.RED);
}
else {//off when clicked, turn on and update the table to reflect being enabled
tableContentsDO[selectedRow][0].setBackgroundColor(Color.green);
tableContentsDO[selectedRow][0].setBackgroundColor(Palette.GREEN);
}
jTable1.repaint();
}
@@ -271,10 +251,10 @@ public class SearchGuiMulti extends SearchBaseExtended {
int selectedRow = jTable1.getSelectedRow();
if (op1Button.isSelected()) {
tableContentsDO[selectedRow][1].setBackgroundColor(Color.red);
tableContentsDO[selectedRow][1].setBackgroundColor(Palette.RED);
}
else {//off when clicked, turn on and update the table to reflect being enabled
tableContentsDO[selectedRow][1].setBackgroundColor(Color.green);
tableContentsDO[selectedRow][1].setBackgroundColor(Palette.GREEN);
}
jTable1.repaint();
}
@@ -284,10 +264,10 @@ public class SearchGuiMulti extends SearchBaseExtended {
int selectedRow = jTable1.getSelectedRow();
if (op2Button.isSelected()) {
tableContentsDO[selectedRow][2].setBackgroundColor(Color.red);
tableContentsDO[selectedRow][2].setBackgroundColor(Palette.RED);
}
else {//off when clicked, turn on and update the table to reflect being enabled
tableContentsDO[selectedRow][2].setBackgroundColor(Color.green);
tableContentsDO[selectedRow][2].setBackgroundColor(Palette.GREEN);
}
jTable1.repaint();
}
@@ -300,14 +280,14 @@ public class SearchGuiMulti extends SearchBaseExtended {
for (int row = 0; row < mnemonics.size(); row++) {
SLMaskControl temp = new SLMaskControl();
if (tableContentsDO[row][0].getBackgroundColor().equals(Color.green)) {
if (tableContentsDO[row][0].getBackgroundColor().equals(Palette.GREEN)) {
temp.useMnemonic = true;
}
else {
temp.useMnemonic = false;
}
if (tableContentsDO[row][1].getBackgroundColor().equals(Color.green)) {
if (tableContentsDO[row][1].getBackgroundColor().equals(Palette.GREEN)) {
temp.useOp1 = true;
if (ops.get(0).get(mnemonics.get(row)).constant) {
temp.useConst = true;
@@ -317,7 +297,7 @@ public class SearchGuiMulti extends SearchBaseExtended {
temp.useOp1 = false;
}
if (tableContentsDO[row][2].getBackgroundColor().equals(Color.green)) {
if (tableContentsDO[row][2].getBackgroundColor().equals(Palette.GREEN)) {
temp.useOp2 = true;
if (ops.get(1).get(mnemonics.get(row)).constant) {
temp.useConst = true;
@@ -336,7 +316,7 @@ public class SearchGuiMulti extends SearchBaseExtended {
private class DataObject {
private String data;
private Color background = Color.white;
private Color background = Colors.BACKGROUND;
public DataObject(String data, Color color) {
this.data = data;