mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +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.listing.*;
|
||||||
import ghidra.program.model.symbol.Equate;
|
import ghidra.program.model.symbol.Equate;
|
||||||
import ghidra.program.util.*;
|
import ghidra.program.util.*;
|
||||||
import ghidra.util.HTMLUtilities;
|
import ghidra.util.*;
|
||||||
import ghidra.util.UniversalID;
|
|
||||||
|
|
||||||
public class DataTypeListingHover extends AbstractConfigurableHover implements ListingHoverService {
|
public class DataTypeListingHover extends AbstractConfigurableHover implements ListingHoverService {
|
||||||
|
|
||||||
|
@ -132,10 +131,48 @@ public class DataTypeListingHover extends AbstractConfigurableHover implements L
|
||||||
dt = data.getDataType();
|
dt = data.getDataType();
|
||||||
return createTooltipComponent(dt.getRepresentation(data, data, data.getLength()));
|
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;
|
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) {
|
private String getLocationSupplimentalToolTipText(DataType dt, Data dataInstance) {
|
||||||
String result = "";
|
String result = "";
|
||||||
if (dt instanceof DataTypeWithCharset) {
|
if (dt instanceof DataTypeWithCharset) {
|
||||||
|
@ -145,12 +182,10 @@ public class DataTypeListingHover extends AbstractConfigurableHover implements L
|
||||||
if (StringDataInstance.isString(dataInstance)) {
|
if (StringDataInstance.isString(dataInstance)) {
|
||||||
StringDataInstance sdi = StringDataInstance.getStringDataInstance(dataInstance);
|
StringDataInstance sdi = StringDataInstance.getStringDataInstance(dataInstance);
|
||||||
if (sdi.isShowTranslation()) {
|
if (sdi.isShowTranslation()) {
|
||||||
result += String.format("<br>Original value: %s",
|
result += String.format("<br>Original value: %s", html(sdi.getStringValue()));
|
||||||
HTMLUtilities.friendlyEncodeHTML(sdi.getStringValue()));
|
|
||||||
}
|
}
|
||||||
if (!sdi.isShowTranslation() && sdi.getTranslatedValue() != null) {
|
if (!sdi.isShowTranslation() && sdi.getTranslatedValue() != null) {
|
||||||
result += String.format("<br>Translated value: %s",
|
result += String.format("<br>Translated value: %s", html(sdi.getTranslatedValue()));
|
||||||
HTMLUtilities.friendlyEncodeHTML(sdi.getTranslatedValue()));
|
|
||||||
}
|
}
|
||||||
if (sdi.isMissingNullTerminator()) {
|
if (sdi.isMissingNullTerminator()) {
|
||||||
result += "<br>Missing NULL terminator.";
|
result += "<br>Missing NULL terminator.";
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -119,7 +119,8 @@ public class DataTypeDecompilerHover extends AbstractConfigurableHover
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
buffy.append("<TABLE>");
|
buffy.append("<TABLE>");
|
||||||
buffy.append(
|
buffy.append(
|
||||||
row("Parent: ", HTMLUtilities.friendlyEncodeHTML(parentType.getName())));
|
row("Parent: ", HTMLUtilities.friendlyEncodeHTML(
|
||||||
|
parentType.getDataTypePath().toString())));
|
||||||
buffy.append(
|
buffy.append(
|
||||||
row("Offset: ", NumericUtilities.toHexString(offset)));
|
row("Offset: ", NumericUtilities.toHexString(offset)));
|
||||||
buffy.append(
|
buffy.append(
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -21,6 +21,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
import ghidra.framework.options.SaveState;
|
import ghidra.framework.options.SaveState;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
|
import ghidra.program.model.listing.Data;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +38,7 @@ public class FieldNameFieldLocation extends CodeUnitLocation {
|
||||||
* @param program the program of the location
|
* @param program the program of the location
|
||||||
* @param addr the address of the code unit
|
* @param addr the address of the code unit
|
||||||
* @param componentPath if not null, it is the array of indexes that point to a specific data
|
* @param componentPath if not null, it is the array of indexes that point to a specific data
|
||||||
* type inside of another data type
|
* type inside of another data type
|
||||||
* @param fieldName the field name
|
* @param fieldName the field name
|
||||||
* @param charOffset the character position within the field name for this location.
|
* @param charOffset the character position within the field name for this location.
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +58,7 @@ public class FieldNameFieldLocation extends CodeUnitLocation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the field name of this location.
|
* Returns the field name of this location.
|
||||||
|
*
|
||||||
* @return the name.
|
* @return the name.
|
||||||
*/
|
*/
|
||||||
public String getFieldName() {
|
public String getFieldName() {
|
||||||
|
@ -105,4 +107,17 @@ public class FieldNameFieldLocation extends CodeUnitLocation {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + ", Field Name = " + fieldName;
|
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