mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge branch 'GP-0_ryanmkurtz_omf'
This commit is contained in:
commit
6d5a5da013
5 changed files with 38 additions and 34 deletions
|
@ -17,7 +17,9 @@ package ghidra.app.util.bin;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import ghidra.docking.settings.SettingsDefinition;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.listing.Data;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
|
||||
/**
|
||||
|
@ -112,4 +114,26 @@ public interface StructConverter {
|
|||
* @see ghidra.program.model.data.StructureDataType
|
||||
*/
|
||||
public DataType toDataType() throws DuplicateNameException, IOException;
|
||||
|
||||
/**
|
||||
* Recursively sets the given {@link Data} and its components to big/little endian
|
||||
*
|
||||
* @param data The {@link Data}
|
||||
* @param bigEndian True to set to big endian; false to set to little endian
|
||||
* @throws Exception if there was a problem setting the endianness
|
||||
*/
|
||||
public static void setEndian(Data data, boolean bigEndian) throws Exception {
|
||||
for (int i = 0; i < data.getNumComponents(); i++) {
|
||||
Data component = data.getComponent(i);
|
||||
SettingsDefinition[] settings = component.getDataType().getSettingsDefinitions();
|
||||
for (int j = 0; j < settings.length; j++) {
|
||||
if (settings[j] instanceof EndianSettingsDefinition endianSetting) {
|
||||
endianSetting.setBigEndian(component, bigEndian);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < component.getNumComponents(); j++) {
|
||||
setEndian(component.getComponent(j), bigEndian);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package ghidra.app.util.bin.format.macho.commands;
|
|||
import java.io.IOException;
|
||||
|
||||
import ghidra.app.util.bin.BinaryReader;
|
||||
import ghidra.app.util.bin.StructConverter;
|
||||
import ghidra.app.util.bin.format.macho.MachHeader;
|
||||
import ghidra.app.util.bin.format.macho.commands.codesignature.CodeSignatureBlobParser;
|
||||
import ghidra.app.util.bin.format.macho.commands.codesignature.CodeSignatureGenericBlob;
|
||||
|
@ -64,7 +65,7 @@ public class CodeSignatureCommand extends LinkEditDataCommand {
|
|||
try {
|
||||
Data d = DataUtilities.createData(program, addr, blob.toDataType(), -1,
|
||||
DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
|
||||
LoadCommand.setEndian(d, true);
|
||||
StructConverter.setEndian(d, true);
|
||||
blob.markup(program, addr, header, monitor, log);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -22,11 +22,9 @@ import ghidra.app.util.bin.BinaryReader;
|
|||
import ghidra.app.util.bin.StructConverter;
|
||||
import ghidra.app.util.bin.format.macho.MachHeader;
|
||||
import ghidra.app.util.importer.MessageLog;
|
||||
import ghidra.docking.settings.SettingsDefinition;
|
||||
import ghidra.program.flatapi.FlatProgramAPI;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.data.EndianSettingsDefinition;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
@ -203,28 +201,6 @@ public abstract class LoadCommand implements StructConverter {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sets the given {@link Data} and its components to big/little endian
|
||||
*
|
||||
* @param data The {@link Data}
|
||||
* @param bigEndian True to set to big endian; false to set to little endian
|
||||
* @throws Exception if there was a problem setting the endianness
|
||||
*/
|
||||
public static void setEndian(Data data, boolean bigEndian) throws Exception {
|
||||
for (int i = 0; i < data.getNumComponents(); i++) {
|
||||
Data component = data.getComponent(i);
|
||||
SettingsDefinition[] settings = component.getDataType().getSettingsDefinitions();
|
||||
for (int j = 0; j < settings.length; j++) {
|
||||
if (settings[j] instanceof EndianSettingsDefinition endianSetting) {
|
||||
endianSetting.setBigEndian(component, true);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < component.getNumComponents(); j++) {
|
||||
setEndian(component.getComponent(j), bigEndian);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------Legacy code to support Raw Binary markup----------------------------------
|
||||
/**
|
||||
* Marks-up this {@link LoadCommand} with data structures and comments. Assumes the program
|
||||
|
|
|
@ -20,9 +20,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import ghidra.app.util.bin.BinaryReader;
|
||||
import ghidra.app.util.bin.StructConverter;
|
||||
import ghidra.app.util.bin.format.macho.MachConstants;
|
||||
import ghidra.app.util.bin.format.macho.MachHeader;
|
||||
import ghidra.app.util.bin.format.macho.commands.LoadCommand;
|
||||
import ghidra.app.util.importer.MessageLog;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.data.*;
|
||||
|
@ -97,7 +97,7 @@ public class CodeSignatureSuperBlob extends CodeSignatureGenericBlob {
|
|||
CodeSignatureGenericBlob blob = indexBlobs.get(i);
|
||||
Data d = DataUtilities.createData(program, addr.add(blobIndex.getOffset()),
|
||||
blob.toDataType(), -1, DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
|
||||
LoadCommand.setEndian(d, true);
|
||||
StructConverter.setEndian(d, true);
|
||||
blob.markup(program, addr.add(blobIndex.getOffset()), header, monitor, log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.*;
|
|||
import ghidra.app.util.MemoryBlockUtils;
|
||||
import ghidra.app.util.Option;
|
||||
import ghidra.app.util.bin.ByteProvider;
|
||||
import ghidra.app.util.bin.StructConverter;
|
||||
import ghidra.app.util.bin.format.omf.*;
|
||||
import ghidra.app.util.bin.format.omf.omf51.Omf51RecordFactory;
|
||||
import ghidra.app.util.importer.MessageLog;
|
||||
|
@ -28,6 +29,7 @@ import ghidra.program.database.mem.FileBytes;
|
|||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.data.DataUtilities;
|
||||
import ghidra.program.model.listing.Data;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.mem.MemoryBlock;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
|
@ -95,8 +97,9 @@ public class Omf51Loader extends AbstractProgramWrapperLoader {
|
|||
Address start = headerBlock.getStart();
|
||||
|
||||
for (OmfRecord record : records) {
|
||||
DataUtilities.createData(program, start.add(record.getRecordOffset()),
|
||||
Data d = DataUtilities.createData(program, start.add(record.getRecordOffset()),
|
||||
record.toDataType(), -1, DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
|
||||
StructConverter.setEndian(d, false);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue