OMF format: Select 16/32 bit based on SEGHEAD

This commit is contained in:
Gravelbones
2023-03-21 19:26:23 +01:00
parent acb07dd535
commit f462733ae3
5 changed files with 42 additions and 14 deletions
@@ -27,6 +27,10 @@ public class OmfCommentRecord extends OmfRecord {
public static final byte COMMENT_CLASS_LIBMOD = (byte) 0xA3; public static final byte COMMENT_CLASS_LIBMOD = (byte) 0xA3;
// Default library cmd // Default library cmd
public static final byte COMMENT_CLASS_DEFAULT_LIBRARY = (byte) 0x9F; public static final byte COMMENT_CLASS_DEFAULT_LIBRARY = (byte) 0x9F;
// Watcom compile parameters
public static final byte COMMENT_CLASS_WATCOM_SETTINGS = (byte) 0x9b;
// Microsoft compile parameters
public static final byte COMMENT_CLASS_MICROSOFT_SETTINGS = (byte) 0x9d;
private byte commentType; private byte commentType;
private byte commentClass; private byte commentClass;
@@ -37,6 +37,7 @@ public class OmfFileHeader extends OmfRecord {
private ArrayList<OmfFixupRecord> fixup = new ArrayList<OmfFixupRecord>(); private ArrayList<OmfFixupRecord> fixup = new ArrayList<OmfFixupRecord>();
private ArrayList<OmfSegmentHeader> extraSeg = null; // Holds implied segments that don't have official header record private ArrayList<OmfSegmentHeader> extraSeg = null; // Holds implied segments that don't have official header record
// private OmfModuleEnd endModule = null; // private OmfModuleEnd endModule = null;
private boolean format16bit;
public OmfFileHeader(BinaryReader reader) throws IOException { public OmfFileHeader(BinaryReader reader) throws IOException {
readRecordHeader(reader); readRecordHeader(reader);
@@ -65,7 +66,7 @@ public class OmfFileHeader extends OmfRecord {
* @return the string identifying the architecture this object was compiled for * @return the string identifying the architecture this object was compiled for
*/ */
public String getMachineName() { public String getMachineName() {
return "i386"; // This is the only possibility return format16bit ? "16bit" : "32bit";
} }
/** /**
@@ -250,13 +251,13 @@ public class OmfFileHeader extends OmfRecord {
* Scan the object file, for the main header and comment records. Other records are parsed but not saved * Scan the object file, for the main header and comment records. Other records are parsed but not saved
* @param reader is the byte stream * @param reader is the byte stream
* @param monitor is checked for cancellation * @param monitor is checked for cancellation
* @param initialCommentsOnly is true if we only want to scan the header and the initial comments, * @param fastscan is true if we only want to scan the header until first seghead,
* @return the header record * @return the header record
* @throws IOException for problems reading program data * @throws IOException for problems reading program data
* @throws OmfException for malformed records * @throws OmfException for malformed records
*/ */
public static OmfFileHeader scan(BinaryReader reader, TaskMonitor monitor, public static OmfFileHeader scan(BinaryReader reader, TaskMonitor monitor,
boolean initialCommentsOnly) throws IOException, OmfException { boolean fastscan) throws IOException, OmfException {
OmfRecord record = OmfRecord.readRecord(reader); OmfRecord record = OmfRecord.readRecord(reader);
if (!(record instanceof OmfFileHeader)) { if (!(record instanceof OmfFileHeader)) {
throw new OmfException("Object file does not start with proper header"); throw new OmfException("Object file does not start with proper header");
@@ -274,16 +275,26 @@ public class OmfFileHeader extends OmfRecord {
} }
if (record instanceof OmfCommentRecord comment) { if (record instanceof OmfCommentRecord comment) {
byte commentClass = comment.getCommentClass(); switch(comment.getCommentClass()) {
if (commentClass == OmfCommentRecord.COMMENT_CLASS_TRANSLATOR) { case OmfCommentRecord.COMMENT_CLASS_TRANSLATOR:
header.translator = comment.getValue(); header.translator = comment.getValue();
} break;
else if (commentClass == OmfCommentRecord.COMMENT_CLASS_LIBMOD) { case OmfCommentRecord.COMMENT_CLASS_LIBMOD:
header.libModuleName = comment.getValue(); header.libModuleName = comment.getValue();
break;
case OmfCommentRecord.COMMENT_CLASS_WATCOM_SETTINGS:
header.translator = "Watcom";
break;
case OmfCommentRecord.COMMENT_CLASS_MICROSOFT_SETTINGS:
header.translator = "Microsoft";
break;
} }
} }
else if (initialCommentsOnly) { else if (record instanceof OmfSegmentHeader head) {
break; header.format16bit = head.is16Bit();
if(fastscan) {
break;
}
} }
} }
return header; return header;
@@ -206,6 +206,13 @@ public class OmfSegmentHeader extends OmfRecord {
return (segAttr >> 2) & 0x7; return (segAttr >> 2) & 0x7;
} }
/**
* @return if 16 or 32 bit segments are used
*/
public boolean is16Bit() {
return (segAttr & 1) == 0;
}
/** /**
* @return true if this block uses filler other than zero bytes * @return true if this block uses filler other than zero bytes
*/ */
@@ -70,6 +70,12 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
if (record.startsWith("CodeGear")) { if (record.startsWith("CodeGear")) {
return "codegearcpp"; return "codegearcpp";
} }
if (record.equals("MS C")) {
return "windows";
}
if(record.startsWith("Watcom")) {
return "watcom";
}
return null; return null;
} }
@@ -65,17 +65,17 @@
</constraint> </constraint>
<constraint loader="Relocatable Object Module Format (OMF)"> <constraint loader="Relocatable Object Module Format (OMF)">
<constraint compilerSpecID="windows"> <constraint compilerSpecID="windows">
<constraint primary="i386" processor="x86" endian="little" size="32" /> <constraint primary="32bit" processor="x86" endian="little" size="32" />
</constraint> </constraint>
<constraint compilerSpecID="default"> <constraint compilerSpecID="default">
<constraint primary="i386" processor="x86" endian="little" size="16" /> <constraint primary="16bit" processor="x86" endian="little" size="16" />
</constraint> </constraint>
<constraint compilerSpecID="borlandcpp"> <constraint compilerSpecID="borlandcpp">
<constraint primary="i386" secondary="borlandcpp" processor="x86" endian="little" size="32" /> <constraint primary="32bit" secondary="borlandcpp" processor="x86" endian="little" size="32" />
<constraint primary="i386" secondary="codegearcpp" processor="x86" endian="little" size="32" /> <constraint primary="32bit" secondary="codegearcpp" processor="x86" endian="little" size="32" />
</constraint> </constraint>
<constraint compilerSpecID="borlanddelphi"> <constraint compilerSpecID="borlanddelphi">
<constraint primary="i386" secondary="borlanddelphi" processor="x86" endian="little" size="32" /> <constraint primary="32bit" secondary="borlanddelphi" processor="x86" endian="little" size="32" />
</constraint> </constraint>
</constraint> </constraint>
</opinions> </opinions>