mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-28 15:45:32 +08:00
GP-0: Formatting
This commit is contained in:
+16
-16
@@ -256,8 +256,8 @@ public class OmfFileHeader extends OmfRecord {
|
|||||||
* @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 fastscan)
|
||||||
boolean fastscan) throws IOException, OmfException {
|
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");
|
||||||
@@ -275,24 +275,24 @@ public class OmfFileHeader extends OmfRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (record instanceof OmfCommentRecord comment) {
|
if (record instanceof OmfCommentRecord comment) {
|
||||||
switch(comment.getCommentClass()) {
|
switch (comment.getCommentClass()) {
|
||||||
case OmfCommentRecord.COMMENT_CLASS_TRANSLATOR:
|
case OmfCommentRecord.COMMENT_CLASS_TRANSLATOR:
|
||||||
header.translator = comment.getValue();
|
header.translator = comment.getValue();
|
||||||
break;
|
break;
|
||||||
case OmfCommentRecord.COMMENT_CLASS_LIBMOD:
|
case OmfCommentRecord.COMMENT_CLASS_LIBMOD:
|
||||||
header.libModuleName = comment.getValue();
|
header.libModuleName = comment.getValue();
|
||||||
break;
|
break;
|
||||||
case OmfCommentRecord.COMMENT_CLASS_WATCOM_SETTINGS:
|
case OmfCommentRecord.COMMENT_CLASS_WATCOM_SETTINGS:
|
||||||
header.translator = "Watcom";
|
header.translator = "Watcom";
|
||||||
break;
|
break;
|
||||||
case OmfCommentRecord.COMMENT_CLASS_MICROSOFT_SETTINGS:
|
case OmfCommentRecord.COMMENT_CLASS_MICROSOFT_SETTINGS:
|
||||||
header.translator = "Microsoft";
|
header.translator = "Microsoft";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (record instanceof OmfSegmentHeader head) {
|
else if (record instanceof OmfSegmentHeader head) {
|
||||||
header.format16bit = head.is16Bit();
|
header.format16bit = head.is16Bit();
|
||||||
if(fastscan) {
|
if (fastscan) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
if (record.equals("MS C")) {
|
if (record.equals("MS C")) {
|
||||||
return "windows";
|
return "windows";
|
||||||
}
|
}
|
||||||
if(record.startsWith("Watcom")) {
|
if (record.startsWith("Watcom")) {
|
||||||
return "watcom";
|
return "watcom";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -162,7 +162,7 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
message = "Unable to process relocation at " + addr + " with type 0x" +
|
message = "Unable to process relocation at " + addr + " with type 0x" +
|
||||||
Integer.toHexString(type);
|
Integer.toHexString(type);
|
||||||
program.getBookmarkManager()
|
program.getBookmarkManager()
|
||||||
.setBookmark(addr, BookmarkType.ERROR, "Relocations", message);
|
.setBookmark(addr, BookmarkType.ERROR, "Relocations", message);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message = "Badly broken relocation";
|
message = "Badly broken relocation";
|
||||||
@@ -241,10 +241,9 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
targetAddr += subrec.getTargetDisplacement();
|
targetAddr += subrec.getTargetDisplacement();
|
||||||
locationType = subrec.getLocationType();
|
locationType = subrec.getLocationType();
|
||||||
OmfSegmentHeader seg =
|
OmfSegmentHeader seg =
|
||||||
header.resolveSegment(fixup.getDataBlock().getSegmentIndex());
|
header.resolveSegment(fixup.getDataBlock().getSegmentIndex());
|
||||||
locAddress = seg.getAddress(language)
|
locAddress = seg.getAddress(language)
|
||||||
.add(
|
.add(fixup.getDataBlock().getDataOffset() +
|
||||||
fixup.getDataBlock().getDataOffset() +
|
|
||||||
subrec.getDataRecordOffset());
|
subrec.getDataRecordOffset());
|
||||||
if (locAddress == null) {
|
if (locAddress == null) {
|
||||||
log.appendMsg("Couldn't find address for fixup");
|
log.appendMsg("Couldn't find address for fixup");
|
||||||
@@ -252,74 +251,74 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
}
|
}
|
||||||
finalvalue = targetAddr;
|
finalvalue = targetAddr;
|
||||||
switch (locationType) {
|
switch (locationType) {
|
||||||
case 0: // Low-order byte
|
case 0: // Low-order byte
|
||||||
origbytes = new byte[1];
|
origbytes = new byte[1];
|
||||||
memory.getBytes(locAddress, origbytes);
|
memory.getBytes(locAddress, origbytes);
|
||||||
if (subrec.isSegmentRelative()) {
|
if (subrec.isSegmentRelative()) {
|
||||||
finalvalue += origbytes[0];
|
finalvalue += origbytes[0];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
finalvalue -= (locAddress.getOffset() + 1);
|
finalvalue -= (locAddress.getOffset() + 1);
|
||||||
}
|
}
|
||||||
memory.setByte(locAddress, (byte) finalvalue);
|
memory.setByte(locAddress, (byte) finalvalue);
|
||||||
break;
|
break;
|
||||||
case 1: // 16-bit offset
|
case 1: // 16-bit offset
|
||||||
case 5: // 16-bit loader-resolved offset (treated same as 1)
|
case 5: // 16-bit loader-resolved offset (treated same as 1)
|
||||||
origbytes = new byte[2];
|
origbytes = new byte[2];
|
||||||
memory.getBytes(locAddress, origbytes);
|
memory.getBytes(locAddress, origbytes);
|
||||||
if (subrec.isSegmentRelative()) {
|
if (subrec.isSegmentRelative()) {
|
||||||
finalvalue += converter.getShort(origbytes);
|
finalvalue += converter.getShort(origbytes);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
finalvalue -= (locAddress.getOffset() + 2);
|
finalvalue -= (locAddress.getOffset() + 2);
|
||||||
}
|
}
|
||||||
memory.setShort(locAddress, (short) finalvalue);
|
memory.setShort(locAddress, (short) finalvalue);
|
||||||
break;
|
break;
|
||||||
case 2: // 16-bit base -- logical segment base (selector)
|
case 2: // 16-bit base -- logical segment base (selector)
|
||||||
if (!subrec.isSegmentRelative()) {
|
if (!subrec.isSegmentRelative()) {
|
||||||
// Segment can't be self relative
|
// Segment can't be self relative
|
||||||
relocationError(program, log, locAddress, locationType);
|
relocationError(program, log, locAddress, locationType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
origbytes = new byte[2];
|
origbytes = new byte[2];
|
||||||
memory.getBytes(locAddress, origbytes);
|
memory.getBytes(locAddress, origbytes);
|
||||||
finalvalue += converter.getShort(origbytes) << 4;
|
finalvalue += converter.getShort(origbytes) << 4;
|
||||||
finalvalue >>= 4; // Convert address to segment
|
finalvalue >>= 4; // Convert address to segment
|
||||||
memory.setShort(locAddress, (short) finalvalue);
|
memory.setShort(locAddress, (short) finalvalue);
|
||||||
break;
|
break;
|
||||||
case 3: // 32-bit far pointer (16-bit segment:16-bit offset)
|
case 3: // 32-bit far pointer (16-bit segment:16-bit offset)
|
||||||
if (!subrec.isSegmentRelative()) {
|
if (!subrec.isSegmentRelative()) {
|
||||||
// Far can't be self relative
|
// Far can't be self relative
|
||||||
relocationError(program, log, locAddress, locationType);
|
relocationError(program, log, locAddress, locationType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
origbytes = new byte[4];
|
origbytes = new byte[4];
|
||||||
memory.getBytes(locAddress, origbytes);
|
memory.getBytes(locAddress, origbytes);
|
||||||
finalvalue += converter.getInt(origbytes);
|
|
||||||
// Convert to segment:offset in 64K blocks
|
|
||||||
finalvalue =
|
|
||||||
((finalvalue & 0xffff0000L) << 12) | (finalvalue & 0xffff);
|
|
||||||
memory.setInt(locAddress, (int) finalvalue);
|
|
||||||
break;
|
|
||||||
// case 11: // 48-bit far pointer (16-bit segment:32-bit offset)
|
|
||||||
case 4: // High-order byte (high byte of 16-bit offset)
|
|
||||||
case 9: // 32-bit offset
|
|
||||||
case 13: // 32-bit loader-resolved offset (treated same as 9)
|
|
||||||
origbytes = new byte[4];
|
|
||||||
memory.getBytes(locAddress, origbytes);
|
|
||||||
if (subrec.isSegmentRelative()) {
|
|
||||||
finalvalue += converter.getInt(origbytes);
|
finalvalue += converter.getInt(origbytes);
|
||||||
}
|
// Convert to segment:offset in 64K blocks
|
||||||
else {
|
finalvalue =
|
||||||
finalvalue -= (locAddress.getOffset() + 4);
|
((finalvalue & 0xffff0000L) << 12) | (finalvalue & 0xffff);
|
||||||
}
|
memory.setInt(locAddress, (int) finalvalue);
|
||||||
memory.setInt(locAddress, (int) finalvalue);
|
break;
|
||||||
break;
|
// case 11: // 48-bit far pointer (16-bit segment:32-bit offset)
|
||||||
default:
|
case 4: // High-order byte (high byte of 16-bit offset)
|
||||||
log.appendMsg("Unsupported relocation type " +
|
case 9: // 32-bit offset
|
||||||
Integer.toString(locationType) + " at 0x" +
|
case 13: // 32-bit loader-resolved offset (treated same as 9)
|
||||||
Long.toHexString(locAddress.getOffset()));
|
origbytes = new byte[4];
|
||||||
break;
|
memory.getBytes(locAddress, origbytes);
|
||||||
|
if (subrec.isSegmentRelative()) {
|
||||||
|
finalvalue += converter.getInt(origbytes);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
finalvalue -= (locAddress.getOffset() + 4);
|
||||||
|
}
|
||||||
|
memory.setInt(locAddress, (int) finalvalue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.appendMsg("Unsupported relocation type " +
|
||||||
|
Integer.toString(locationType) + " at 0x" +
|
||||||
|
Long.toHexString(locAddress.getOffset()));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MemoryAccessException e) {
|
catch (MemoryAccessException e) {
|
||||||
@@ -337,7 +336,7 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
long[] values = new long[1];
|
long[] values = new long[1];
|
||||||
values[0] = finalvalue;
|
values[0] = finalvalue;
|
||||||
program.getRelocationTable()
|
program.getRelocationTable()
|
||||||
.add(locAddress, Status.APPLIED, locationType, values, origbytes, null);
|
.add(locAddress, Status.APPLIED, locationType, values, origbytes, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +373,7 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
if (segmentSize == 0) {
|
if (segmentSize == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (segment.hasNonZeroData()) {
|
if (segment.hasNonZeroData()) {
|
||||||
MemoryBlockUtils.createInitializedBlock(program, false, segment.getName(),
|
MemoryBlockUtils.createInitializedBlock(program, false, segment.getName(),
|
||||||
segmentAddr, segment.getRawDataStream(reader, log), segmentSize, "", "",
|
segmentAddr, segment.getRawDataStream(reader, log), segmentSize, "", "",
|
||||||
@@ -551,7 +550,8 @@ public class OmfLoader extends AbstractProgramWrapperLoader {
|
|||||||
Map<String, OmfSymbol> publicSymbols = header.getPublicSymbols()
|
Map<String, OmfSymbol> publicSymbols = header.getPublicSymbols()
|
||||||
.stream()
|
.stream()
|
||||||
.flatMap(symbolRec -> symbolRec.getSymbols().stream())
|
.flatMap(symbolRec -> symbolRec.getSymbols().stream())
|
||||||
.collect(Collectors.toMap(sym -> sym.getName(), java.util.function.Function.identity()));
|
.collect(
|
||||||
|
Collectors.toMap(sym -> sym.getName(), java.util.function.Function.identity()));
|
||||||
|
|
||||||
monitor.setMessage("Creating External Symbols");
|
monitor.setMessage("Creating External Symbols");
|
||||||
|
|
||||||
|
|||||||
@@ -71,11 +71,11 @@
|
|||||||
<constraint primary="16bit" 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="32bit" secondary="borlandcpp" processor="x86" endian="little" size="32" />
|
<constraint primary="32bit" secondary="borlandcpp" processor="x86" endian="little" size="32" />
|
||||||
<constraint primary="32bit" 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="32bit" 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>
|
||||||
|
|||||||
Reference in New Issue
Block a user