mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-07-04 16:58:46 +00:00
Merge remote-tracking branch 'origin/GP-2045_emteere_COFFImportNonWindows' into patch
This commit is contained in:
commit
27c2b7d64a
|
@ -65,8 +65,8 @@ public class CoffSectionHeader implements StructConverter {
|
|||
s_scnptr = reader.readNextInt();
|
||||
s_relptr = reader.readNextInt();
|
||||
s_lnnoptr = reader.readNextInt();
|
||||
s_nreloc = reader.readNextShort() & 0xffff;
|
||||
s_nlnno = reader.readNextShort() & 0xffff;
|
||||
s_nreloc = reader.readNextUnsignedShort();
|
||||
s_nlnno = reader.readNextUnsignedShort();
|
||||
s_flags = reader.readNextInt();
|
||||
s_reserved = 0;
|
||||
s_page = 0;
|
||||
|
@ -306,14 +306,6 @@ public class CoffSectionHeader implements StructConverter {
|
|||
struct.add(WORD, "s_nreloc", null);
|
||||
struct.add(WORD, "s_nlnno", null);
|
||||
struct.add(DWORD, "s_flags", null);
|
||||
if (_header.getMagic() == CoffMachineType.TICOFF1MAGIC) {
|
||||
struct.add(BYTE, "s_reserved", null);
|
||||
struct.add(BYTE, "s_page", null);
|
||||
}
|
||||
else if (_header.getMagic() == CoffMachineType.TICOFF2MAGIC) {
|
||||
struct.add(WORD, "s_reserved", null);
|
||||
struct.add(WORD, "s_page", null);
|
||||
}
|
||||
return struct;
|
||||
}
|
||||
|
||||
|
@ -400,6 +392,10 @@ public class CoffSectionHeader implements StructConverter {
|
|||
public static Address getAddress(Language language, long offset, CoffSectionHeader section) {
|
||||
boolean isData = section == null || section.isData();
|
||||
AddressSpace space = isData ? language.getDefaultDataSpace() : language.getDefaultSpace();
|
||||
if (offset > space.getMaxAddress().getAddressableWordOffset()) {
|
||||
// offset too big to fit, try the opposite space, so at least the blocks will load
|
||||
space = !isData ? language.getDefaultDataSpace() : language.getDefaultSpace();
|
||||
}
|
||||
return space.getAddress(offset * getOffsetUnitSize(language, section));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ package ghidra.app.util.bin.format.coff;
|
|||
import java.io.IOException;
|
||||
|
||||
import ghidra.app.util.bin.BinaryReader;
|
||||
import ghidra.app.util.bin.StructConverterUtil;
|
||||
import ghidra.program.model.data.*;
|
||||
|
||||
/**
|
||||
* A 0x28 byte COFF section header
|
||||
|
@ -37,11 +39,30 @@ class CoffSectionHeader1 extends CoffSectionHeader {
|
|||
s_scnptr = reader.readNextInt();
|
||||
s_relptr = reader.readNextInt();
|
||||
s_lnnoptr = reader.readNextInt();
|
||||
s_nreloc = reader.readNextShort() & 0xffff;
|
||||
s_nlnno = reader.readNextShort() & 0xffff;
|
||||
s_flags = reader.readNextShort() & 0xffff;
|
||||
s_reserved = reader.readNextByte();
|
||||
s_page = reader.readNextByte();
|
||||
s_nreloc = reader.readNextUnsignedShort();
|
||||
s_nlnno = reader.readNextUnsignedShort();
|
||||
s_flags = reader.readNextUnsignedShort();
|
||||
s_reserved = (short) (reader.readNextByte() & 0xff);
|
||||
s_page = (short) (reader.readNextByte() & 0xff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType toDataType() throws IOException {
|
||||
Structure struct = new StructureDataType(StructConverterUtil.parseName(getClass()), 0);
|
||||
struct.add(new ArrayDataType(ASCII, CoffConstants.SECTION_NAME_LENGTH, ASCII.getLength()),
|
||||
"s_name", null);
|
||||
struct.add(DWORD, "s_paddr", null);
|
||||
struct.add(DWORD, "s_vaddr", null);
|
||||
struct.add(DWORD, "s_size", null);
|
||||
struct.add(DWORD, "s_scnptr", null);
|
||||
struct.add(DWORD, "s_relptr", null);
|
||||
struct.add(DWORD, "s_lnnoptr", null);
|
||||
struct.add(WORD, "s_nreloc", null);
|
||||
struct.add(WORD, "s_nlnno", null);
|
||||
struct.add(WORD, "s_flags", null);
|
||||
struct.add(BYTE, "s_reserved", null);
|
||||
struct.add(BYTE, "s_page", null);
|
||||
return struct;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package ghidra.app.util.bin.format.coff;
|
|||
import java.io.IOException;
|
||||
|
||||
import ghidra.app.util.bin.BinaryReader;
|
||||
import ghidra.app.util.bin.StructConverterUtil;
|
||||
import ghidra.program.model.data.*;
|
||||
|
||||
/**
|
||||
* A 0x30 byte COFF section header
|
||||
|
@ -44,4 +46,23 @@ class CoffSectionHeader2 extends CoffSectionHeader {
|
|||
s_page = reader.readNextShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType toDataType() throws IOException {
|
||||
Structure struct = new StructureDataType(StructConverterUtil.parseName(getClass()), 0);
|
||||
struct.add(new ArrayDataType(ASCII, CoffConstants.SECTION_NAME_LENGTH, ASCII.getLength()),
|
||||
"s_name", null);
|
||||
struct.add(DWORD, "s_paddr", null);
|
||||
struct.add(DWORD, "s_vaddr", null);
|
||||
struct.add(DWORD, "s_size", null);
|
||||
struct.add(DWORD, "s_scnptr", null);
|
||||
struct.add(DWORD, "s_relptr", null);
|
||||
struct.add(DWORD, "s_lnnoptr", null);
|
||||
struct.add(DWORD, "s_nreloc", null);
|
||||
struct.add(DWORD, "s_nlnno", null);
|
||||
struct.add(DWORD, "s_flags", null);
|
||||
struct.add(WORD, "s_reserved", null);
|
||||
struct.add(WORD, "s_page", null);
|
||||
return struct;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package ghidra.app.util.bin.format.coff;
|
|||
import java.io.IOException;
|
||||
|
||||
import ghidra.app.util.bin.BinaryReader;
|
||||
import ghidra.app.util.bin.StructConverterUtil;
|
||||
import ghidra.program.model.data.*;
|
||||
|
||||
/**
|
||||
* A 0x2c byte COFF section header
|
||||
|
@ -37,14 +39,32 @@ class CoffSectionHeader3 extends CoffSectionHeader {
|
|||
s_scnptr = reader.readNextInt();
|
||||
s_relptr = reader.readNextInt();
|
||||
s_lnnoptr = reader.readNextInt();
|
||||
s_nreloc = reader.readNextShort() & 0xffff;
|
||||
s_nlnno = reader.readNextShort() & 0xffff;
|
||||
s_nreloc = reader.readNextUnsignedShort();
|
||||
s_nlnno = reader.readNextUnsignedShort();
|
||||
s_flags = reader.readNextInt();
|
||||
|
||||
reader.readNextInt(); // section alignment, currently unused
|
||||
reader.readNextUnsignedInt(); // s_align: section alignment, currently unused
|
||||
|
||||
s_reserved = 0;
|
||||
s_page = 0;
|
||||
s_page = 0; // TODO: (short) (reader.readNextUnsignedByte() & 0xff) ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType toDataType() throws IOException {
|
||||
Structure struct = new StructureDataType(StructConverterUtil.parseName(getClass()), 0);
|
||||
struct.add(new ArrayDataType(ASCII, CoffConstants.SECTION_NAME_LENGTH, ASCII.getLength()),
|
||||
"s_name", null);
|
||||
struct.add(DWORD, "s_paddr", null);
|
||||
struct.add(DWORD, "s_vaddr", null);
|
||||
struct.add(DWORD, "s_size", null);
|
||||
struct.add(DWORD, "s_scnptr", null);
|
||||
struct.add(DWORD, "s_relptr", null);
|
||||
struct.add(DWORD, "s_lnnoptr", null);
|
||||
struct.add(WORD, "s_nreloc", null);
|
||||
struct.add(WORD, "s_nlnno", null);
|
||||
struct.add(DWORD, "s_flags", null);
|
||||
struct.add(DWORD, "s_align", null);
|
||||
return struct;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class CoffLoader extends AbstractLibrarySupportLoader {
|
|||
List<QueryResult> results =
|
||||
QueryOpinionService.query(getName(), header.getMachineName(), secondary);
|
||||
for (QueryResult result : results) {
|
||||
loadSpecs.add(new LoadSpec(this, header.getImageBase(true), result));
|
||||
loadSpecs.add(new LoadSpec(this, header.getImageBase(isMicrosoftFormat()), result));
|
||||
}
|
||||
if (loadSpecs.isEmpty()) {
|
||||
loadSpecs.add(new LoadSpec(this, header.getImageBase(false), true));
|
||||
|
|
Loading…
Reference in New Issue
Block a user