mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-22 12:11:55 +00:00
Fixed html rendering that was still using css
This commit is contained in:
parent
6f35c7ec47
commit
38c11444a6
@ -28,8 +28,6 @@ import java.util.stream.Collectors;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import db.Transaction;
|
||||
import docking.action.DockingAction;
|
||||
import docking.widgets.table.*;
|
||||
@ -61,8 +59,7 @@ import ghidra.program.model.pcode.PcodeOp;
|
||||
import ghidra.program.model.pcode.Varnode;
|
||||
import ghidra.trace.model.Trace;
|
||||
import ghidra.trace.model.time.schedule.TraceSchedule;
|
||||
import ghidra.util.ColorUtils;
|
||||
import ghidra.util.HTMLUtilities;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.table.GhidraTable;
|
||||
import ghidra.util.table.GhidraTableFilterPanel;
|
||||
import ghidra.util.table.column.AbstractGColumnRenderer;
|
||||
@ -71,23 +68,16 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
private static final FontRenderContext METRIC_FRC =
|
||||
new FontRenderContext(new AffineTransform(), false, false);
|
||||
|
||||
private static final Color COLOR_BACKGROUND =
|
||||
new GColor("color.bg.listing");
|
||||
private static final Color COLOR_BACKGROUND_CURSOR =
|
||||
new GColor("color.bg.currentline.listing");
|
||||
private static final Color COLOR_BACKGROUND = new GColor("color.bg.listing");
|
||||
private static final Color COLOR_BACKGROUND_CURSOR = new GColor("color.bg.currentline.listing");
|
||||
private static final Color COLOR_BACKGROUND_COUNTER =
|
||||
new GColor("color.debugger.plugin.resources.pcode.counter");
|
||||
|
||||
private static final Color COLOR_FOREGROUND_ADDRESS =
|
||||
new GColor("color.fg.listing.address");
|
||||
private static final Color COLOR_FOREGROUND_REGISTER =
|
||||
new GColor("color.fg.listing.register");
|
||||
private static final Color COLOR_FOREGROUND_SCALAR =
|
||||
new GColor("color.fg.listing.constant");
|
||||
private static final Color COLOR_FOREGROUND_LOCAL =
|
||||
new GColor("color.fg.listing.label.local");
|
||||
private static final Color COLOR_FOREGROUND_MNEMONIC =
|
||||
new GColor("color.fg.listing.mnemonic");
|
||||
private static final Color COLOR_FOREGROUND_ADDRESS = new GColor("color.fg.listing.address");
|
||||
private static final Color COLOR_FOREGROUND_REGISTER = new GColor("color.fg.listing.register");
|
||||
private static final Color COLOR_FOREGROUND_SCALAR = new GColor("color.fg.listing.constant");
|
||||
private static final Color COLOR_FOREGROUND_LOCAL = new GColor("color.fg.listing.label.local");
|
||||
private static final Color COLOR_FOREGROUND_MNEMONIC = new GColor("color.fg.listing.mnemonic");
|
||||
private static final Color COLOR_FOREGROUND_UNIMPL =
|
||||
new GColor("color.fg.listing.mnemonic.unimplemented");
|
||||
private static final Color COLOR_FOREGROUND_SEPARATOR =
|
||||
@ -96,23 +86,10 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
new GColor("color.fg.listing.pcode.label");
|
||||
private static final Color COLOR_FOREGROUND_SPACE =
|
||||
new GColor("color.fg.listing.pcode.address.space");
|
||||
private static final Color COLOR_FOREGROUND_RAW =
|
||||
new GColor("color.fg.listing.pcode.varnode");
|
||||
private static final Color COLOR_FOREGROUND_RAW = new GColor("color.fg.listing.pcode.varnode");
|
||||
private static final Color COLOR_FOREGROUND_USEROP =
|
||||
new GColor("color.fg.listing.pcode.userop");
|
||||
|
||||
private static final String SPAN_ADDRESS = "addr";
|
||||
private static final String SPAN_REGISTER = "reg";
|
||||
private static final String SPAN_SCALAR = "scalar";
|
||||
private static final String SPAN_LOCAL = "loc";
|
||||
private static final String SPAN_MNEMONIC = "op";
|
||||
private static final String SPAN_UNIMPL = "unimpl";
|
||||
private static final String SPAN_SEPARATOR = "sep";
|
||||
private static final String SPAN_LINE_LABEL = "lab";
|
||||
private static final String SPAN_SPACE = "space";
|
||||
private static final String SPAN_RAW = "raw";
|
||||
private static final String SPAN_USEROP = "usr";
|
||||
|
||||
protected static final Comparator<Varnode> UNIQUE_COMPARATOR = (u1, u2) -> {
|
||||
assert u1.isUnique() && u2.isUnique();
|
||||
return u1.getAddress().compareTo(u2.getAddress());
|
||||
@ -241,8 +218,7 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
if (dataType == null) {
|
||||
return null;
|
||||
}
|
||||
try (Transaction tid =
|
||||
current.getTrace().openTransaction("Resolve DataType")) {
|
||||
try (Transaction tid = current.getTrace().openTransaction("Resolve DataType")) {
|
||||
return current.getTrace().getDataTypeManager().resolve(dataType, null);
|
||||
}
|
||||
}
|
||||
@ -296,17 +272,11 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(GTableCellRenderingData data) {
|
||||
super.getTableCellRendererComponent(data);
|
||||
setText(injectStyle(getText()));
|
||||
Object value = data.getValue();
|
||||
String text = getText(value);
|
||||
setText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
String injectStyle(String html) {
|
||||
if (StringUtils.startsWithIgnoreCase(html, "<html>")) {
|
||||
String style = computeStyle();
|
||||
return style + html.substring("<html>".length());
|
||||
}
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
class UniqueRefCellRenderer extends AbstractGColumnRenderer<RefType> {
|
||||
@ -339,8 +309,8 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
protected static String htmlSpan(String cls, String display) {
|
||||
return String.format("<span class=\"%s\">%s</span>", cls,
|
||||
protected static String htmlColor(Color color, String display) {
|
||||
return String.format("<font color=\"%s\">%s</font>", WebColors.toString(color),
|
||||
HTMLUtilities.escapeHTML(display));
|
||||
}
|
||||
|
||||
@ -391,83 +361,87 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
|
||||
@Override
|
||||
public void appendAddressWordOffcut(long wordOffset, long offcut) {
|
||||
codeHtml.append(htmlSpan(SPAN_ADDRESS, stringifyWordOffcut(wordOffset, offcut)));
|
||||
codeHtml.append(
|
||||
htmlColor(COLOR_FOREGROUND_ADDRESS, stringifyWordOffcut(wordOffset, offcut)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendCharacter(char c) {
|
||||
if (c == '=') {
|
||||
codeHtml.append(" ");
|
||||
codeHtml.append(htmlSpan(SPAN_SEPARATOR, "="));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_SEPARATOR, "="));
|
||||
codeHtml.append(" ");
|
||||
}
|
||||
else if (c == ' ') {
|
||||
codeHtml.append(" ");
|
||||
}
|
||||
else {
|
||||
codeHtml.append(htmlSpan(SPAN_SEPARATOR, Character.toString(c)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_SEPARATOR, Character.toString(c)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendIndent() {
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendLabel(String label) {
|
||||
codeHtml.append(htmlSpan(SPAN_LOCAL, label));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_LOCAL, label));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendLineLabel(long label) {
|
||||
hasLabel = true;
|
||||
labelHtml.append(htmlSpan(SPAN_LINE_LABEL, stringifyLineLabel(label)));
|
||||
labelHtml.append(htmlColor(COLOR_FOREGROUND_LINE_LABEL, stringifyLineLabel(label)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendLineLabelRef(long label) {
|
||||
codeHtml.append(htmlSpan(SPAN_LINE_LABEL, stringifyLineLabel(label)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_LINE_LABEL, stringifyLineLabel(label)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendMnemonic(int opcode) {
|
||||
String style = opcode == PcodeOp.UNIMPLEMENTED ? SPAN_UNIMPL : SPAN_MNEMONIC;
|
||||
codeHtml.append(htmlSpan(style, stringifyOpMnemonic(opcode)));
|
||||
Color style = opcode == PcodeOp.UNIMPLEMENTED ? COLOR_FOREGROUND_UNIMPL
|
||||
: COLOR_FOREGROUND_MNEMONIC;
|
||||
codeHtml.append(htmlColor(style, stringifyOpMnemonic(opcode)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRawVarnode(AddressSpace space, long offset, long size) {
|
||||
codeHtml.append(htmlSpan(SPAN_RAW, stringifyRawVarnode(space, offset, size)));
|
||||
codeHtml.append(
|
||||
htmlColor(COLOR_FOREGROUND_RAW, stringifyRawVarnode(space, offset, size)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRegister(Register register) {
|
||||
codeHtml.append(htmlSpan(SPAN_REGISTER, stringifyRegister(register)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_REGISTER, stringifyRegister(register)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendScalar(long value) {
|
||||
codeHtml.append(htmlSpan(SPAN_SCALAR, stringifyScalarValue(value)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_SCALAR, stringifyScalarValue(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSpace(AddressSpace space) {
|
||||
codeHtml.append(htmlSpan(SPAN_SPACE, stringifySpace(space)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_SPACE, stringifySpace(space)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendUnique(long offset) {
|
||||
codeHtml.append(htmlSpan(SPAN_LOCAL, stringifyUnique(offset)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_LOCAL, stringifyUnique(offset)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendUserop(int id) {
|
||||
codeHtml.append(htmlSpan(SPAN_USEROP, stringifyUserop(language, id)));
|
||||
codeHtml.append(htmlColor(COLOR_FOREGROUND_USEROP, stringifyUserop(language, id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String stringifyUseropUnchecked(Language language, int id) {
|
||||
String name = super.stringifyUseropUnchecked(language, id);
|
||||
protected String stringifyUseropUnchecked(Language lang, int id) {
|
||||
String name = super.stringifyUseropUnchecked(lang, id);
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
@ -507,8 +481,8 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ToPcodeRowsAppender createAppender(Language language, boolean indent) {
|
||||
return new ToPcodeRowsAppender(language, frame);
|
||||
protected ToPcodeRowsAppender createAppender(Language lang, boolean indent) {
|
||||
return new ToPcodeRowsAppender(lang, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -598,23 +572,6 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
contextChanged();
|
||||
}
|
||||
|
||||
protected String computeStyle() {
|
||||
StringBuilder sb = new StringBuilder("<html><head><style>");
|
||||
sb.append(createColoredStyle(SPAN_ADDRESS, COLOR_FOREGROUND_ADDRESS));
|
||||
sb.append(createColoredStyle(SPAN_REGISTER, COLOR_FOREGROUND_REGISTER));
|
||||
sb.append(createColoredStyle(SPAN_SCALAR, COLOR_FOREGROUND_SCALAR));
|
||||
sb.append(createColoredStyle(SPAN_LOCAL, COLOR_FOREGROUND_LOCAL));
|
||||
sb.append(createColoredStyle(SPAN_MNEMONIC, COLOR_FOREGROUND_MNEMONIC));
|
||||
sb.append(createColoredStyle(SPAN_UNIMPL, COLOR_FOREGROUND_UNIMPL));
|
||||
sb.append(createColoredStyle(SPAN_SEPARATOR, COLOR_FOREGROUND_SEPARATOR));
|
||||
sb.append(createColoredStyle(SPAN_LINE_LABEL, COLOR_FOREGROUND_LINE_LABEL));
|
||||
sb.append(createColoredStyle(SPAN_SPACE, COLOR_FOREGROUND_SPACE));
|
||||
sb.append(createColoredStyle(SPAN_RAW, COLOR_FOREGROUND_RAW));
|
||||
sb.append(createColoredStyle(SPAN_USEROP, COLOR_FOREGROUND_USEROP));
|
||||
sb.append("</style></head>"); // NB. </html> should already be at end
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected int measureColWidth(JLabel renderer, String sample) {
|
||||
Font font = renderer.getFont();
|
||||
Insets insets = renderer.getBorder().getBorderInsets(renderer);
|
||||
@ -636,9 +593,9 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
pcodeTable.setBackground(COLOR_BACKGROUND);
|
||||
pcodeTable.setSelectionBackground(COLOR_BACKGROUND_CURSOR);
|
||||
|
||||
JScrollPane pcodeScrollPane = new JScrollPane(pcodeTablePanel,
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
JScrollPane pcodeScrollPane =
|
||||
new JScrollPane(pcodeTablePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
JPanel pcodePanel = new JPanel(new BorderLayout());
|
||||
pcodePanel.add(pcodeScrollPane, BorderLayout.CENTER);
|
||||
@ -706,8 +663,7 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
.onAction(c -> stepBackwardActivated())
|
||||
.buildAndInstallLocal(this);
|
||||
actionStepForward = DebuggerResources.EmulatePcodeForwardAction.builder(plugin)
|
||||
.enabledWhen(
|
||||
c -> current.getThread() != null)
|
||||
.enabledWhen(c -> current.getThread() != null)
|
||||
.onAction(c -> stepForwardActivated())
|
||||
.buildAndInstallLocal(this);
|
||||
}
|
||||
@ -814,10 +770,9 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
|
||||
// TODO: Highlight uniques that the selected op(s) reference
|
||||
// (including overlaps)
|
||||
// TODO: Permit modification of unique variables
|
||||
List<UniqueRow> toAdd =
|
||||
uniques.stream()
|
||||
.map(u -> new UniqueRow(this, language, state, arithmetic, u))
|
||||
.collect(Collectors.toList());
|
||||
List<UniqueRow> toAdd = uniques.stream()
|
||||
.map(u -> new UniqueRow(this, language, state, arithmetic, u))
|
||||
.collect(Collectors.toList());
|
||||
uniqueTableModel.addAll(toAdd);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user