mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch 'origin/GP-5913_ghidranoob_Decomp_StructureMember_ParentPath--SQUASHED'
This commit is contained in:
commit
8571e83b36
3 changed files with 63 additions and 12 deletions
|
@ -31,8 +31,7 @@ import ghidra.program.model.data.Enum;
|
|||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.model.symbol.Equate;
|
||||
import ghidra.program.util.*;
|
||||
import ghidra.util.HTMLUtilities;
|
||||
import ghidra.util.UniversalID;
|
||||
import ghidra.util.*;
|
||||
|
||||
public class DataTypeListingHover extends AbstractConfigurableHover implements ListingHoverService {
|
||||
|
||||
|
@ -132,10 +131,48 @@ public class DataTypeListingHover extends AbstractConfigurableHover implements L
|
|||
dt = data.getDataType();
|
||||
return createTooltipComponent(dt.getRepresentation(data, data, data.getLength()));
|
||||
}
|
||||
if (programLocation instanceof FieldNameFieldLocation nameLoc) {
|
||||
Data data = nameLoc.getDataComponent();
|
||||
Data parent = data == null ? null : data.getParent();
|
||||
if (parent == null) {
|
||||
return createTooltipComponent("Field Name: " + nameLoc.getFieldName());
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(HTMLUtilities.HTML);
|
||||
sb.append("<TABLE>");
|
||||
if (parent != null) {
|
||||
DataType parentType = parent.getDataType();
|
||||
sb.append(row("Parent: ", html(parentType.getDataTypePath())));
|
||||
int offset = (int) data.getAddress().subtract(parent.getAddress());
|
||||
sb.append(row("Offset: ", NumericUtilities.toHexString(offset)));
|
||||
sb.append(row("Field Name: ", nameLoc.getFieldName()));
|
||||
if (parentType instanceof Structure pst) {
|
||||
DataTypeComponent dtc = pst.getComponentAt(offset);
|
||||
String comment = dtc == null ? null : dtc.getComment();
|
||||
if (comment != null) {
|
||||
sb.append(row("Comment: ", html(comment)));
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("</TABLE>");
|
||||
return createTooltipComponent(sb.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String row(String... cols) {
|
||||
StringBuilder sb = new StringBuilder("<TR>");
|
||||
for (String col : cols) {
|
||||
sb.append("<TD>").append(col).append("</TD>");
|
||||
}
|
||||
sb.append("</TR>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String html(Object obj) {
|
||||
return obj == null ? "" : HTMLUtilities.friendlyEncodeHTML(obj.toString());
|
||||
}
|
||||
|
||||
private String getLocationSupplimentalToolTipText(DataType dt, Data dataInstance) {
|
||||
String result = "";
|
||||
if (dt instanceof DataTypeWithCharset) {
|
||||
|
@ -145,12 +182,10 @@ public class DataTypeListingHover extends AbstractConfigurableHover implements L
|
|||
if (StringDataInstance.isString(dataInstance)) {
|
||||
StringDataInstance sdi = StringDataInstance.getStringDataInstance(dataInstance);
|
||||
if (sdi.isShowTranslation()) {
|
||||
result += String.format("<br>Original value: %s",
|
||||
HTMLUtilities.friendlyEncodeHTML(sdi.getStringValue()));
|
||||
result += String.format("<br>Original value: %s", html(sdi.getStringValue()));
|
||||
}
|
||||
if (!sdi.isShowTranslation() && sdi.getTranslatedValue() != null) {
|
||||
result += String.format("<br>Translated value: %s",
|
||||
HTMLUtilities.friendlyEncodeHTML(sdi.getTranslatedValue()));
|
||||
result += String.format("<br>Translated value: %s", html(sdi.getTranslatedValue()));
|
||||
}
|
||||
if (sdi.isMissingNullTerminator()) {
|
||||
result += "<br>Missing NULL terminator.";
|
||||
|
|
|
@ -119,7 +119,8 @@ public class DataTypeDecompilerHover extends AbstractConfigurableHover
|
|||
//@formatter:off
|
||||
buffy.append("<TABLE>");
|
||||
buffy.append(
|
||||
row("Parent: ", HTMLUtilities.friendlyEncodeHTML(parentType.getName())));
|
||||
row("Parent: ", HTMLUtilities.friendlyEncodeHTML(
|
||||
parentType.getDataTypePath().toString())));
|
||||
buffy.append(
|
||||
row("Offset: ", NumericUtilities.toHexString(offset)));
|
||||
buffy.append(
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Objects;
|
|||
|
||||
import ghidra.framework.options.SaveState;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Data;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +58,7 @@ public class FieldNameFieldLocation extends CodeUnitLocation {
|
|||
|
||||
/**
|
||||
* Returns the field name of this location.
|
||||
*
|
||||
* @return the name.
|
||||
*/
|
||||
public String getFieldName() {
|
||||
|
@ -105,4 +107,17 @@ public class FieldNameFieldLocation extends CodeUnitLocation {
|
|||
public String toString() {
|
||||
return super.toString() + ", Field Name = " + fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data component representing the named field
|
||||
*
|
||||
* @return the data unit
|
||||
*/
|
||||
public Data getDataComponent() {
|
||||
Data data = program.getListing().getDataContaining(addr);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return data.getComponent(getComponentPath());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue