GP-3197 fix elf note markup when default data is present

This commit is contained in:
dev747368
2023-03-27 16:27:24 -04:00
parent 738e662e82
commit b3dec2a2ba
5 changed files with 19 additions and 10 deletions
@@ -23,8 +23,9 @@ import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.framework.options.Options;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataUtilities;
import ghidra.program.model.data.DataUtilities.ClearDataMode;
import ghidra.program.model.data.StringUTF8DataType;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolTable;
@@ -93,7 +94,6 @@ public class ElfComment implements ElfInfoItem {
public void markupProgram(Program program, Address address) {
try {
Options progInfo = program.getOptions(Program.PROGRAM_INFO);
Listing listing = program.getListing();
SymbolTable symTable = program.getSymbolTable();
for (int commentNum = 0; commentNum < commentStrings.size(); commentNum++) {
@@ -103,7 +103,8 @@ public class ElfComment implements ElfInfoItem {
progInfo.setString("Elf Comment[%d]".formatted(commentNum), commentStr);
symTable.createLabel(address, "ElfComment[%d]".formatted(commentNum),
SourceType.IMPORTED);
listing.createData(address, StringUTF8DataType.dataType, strLen);
DataUtilities.createData(program, address, StringUTF8DataType.dataType, strLen,
false, ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
address = address.addWrap(strLen); // need to allow wrap so we don't error when hitting end-of-section
}
}
@@ -24,6 +24,7 @@ import ghidra.app.util.bin.*;
import ghidra.framework.options.Options;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.DataUtilities.ClearDataMode;
import ghidra.program.model.listing.Program;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.Msg;
@@ -240,7 +241,8 @@ public class ElfNote implements ElfInfoItem {
StructureDataType dt = toStructure(program.getDataTypeManager());
if (dt != null) {
try {
program.getListing().createData(address, dt);
DataUtilities.createData(program, address, dt, -1, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
}
catch (CodeUnitInsertionException e) {
Msg.error(this, "Failed to markup Elf Note at %s: %s".formatted(address, this), e);
@@ -22,6 +22,7 @@ import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.DataUtilities.ClearDataMode;
import ghidra.program.model.listing.Program;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.Msg;
@@ -98,7 +99,8 @@ public class GnuDebugLink implements ElfInfoItem {
try {
StructureDataType struct = toStructure(program.getDataTypeManager());
if (struct != null) {
program.getListing().createData(address, struct);
DataUtilities.createData(program, address, struct, -1, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
}
}
catch (CodeUnitInsertionException e) {
@@ -25,6 +25,7 @@ import ghidra.app.util.bin.StructConverter;
import ghidra.framework.options.Options;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.DataUtilities.ClearDataMode;
import ghidra.program.model.listing.*;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.Msg;
@@ -180,12 +181,14 @@ public class NoteGnuProperty extends ElfNote {
StructureDataType struct =
createNoteStructure(null, "NoteGnuProperty_%d".formatted(getNameLen()), false,
getNameLen(), 0, program.getDataTypeManager());
Data propData = listing.createData(address, struct);
Data propData = DataUtilities.createData(program, address, struct, -1, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
address = propData.getMaxAddress().next();
for (NotePropertyElement element : elements) {
DataType elementDT = getElementDataType(dtm, element);
Data elementData = listing.createData(address, elementDT);
Data elementData = DataUtilities.createData(program, address, elementDT, -1, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
listing.setComment(address, CodeUnit.EOL_COMMENT,
element.typeName() + "=" + element.value());
address = elementData.getMaxAddress().next();
@@ -24,8 +24,8 @@ import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.elf.*;
import ghidra.app.util.bin.format.elf.info.ElfInfoItem.ReaderFunc;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.CategoryPath;
import ghidra.program.model.data.StructureDataType;
import ghidra.program.model.data.*;
import ghidra.program.model.data.DataUtilities.ClearDataMode;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
@@ -107,7 +107,8 @@ public class StandardElfInfoProducer implements ElfInfoProducer {
try {
StructureDataType struct = note.toStructure(program.getDataTypeManager());
program.getListing().createData(addr, struct);
DataUtilities.createData(program, addr, struct, -1, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
String comment =
"ELF Note \"%s\", %xh".formatted(note.getName(), note.getVendorType());
program.getListing().setComment(addr, CodeUnit.EOL_COMMENT, comment);