Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2528 fix OMF comment record parsing

dev747368236643af0a5a
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfCommentRecord.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfCommentRecord.java
index c24c5cd58b..d12ff8dc91 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfCommentRecord.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfCommentRecord.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +16,14 @@
package ghidra.app.util.bin.format.omf;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import ghidra.app.util.bin.BinaryReader;
public class OmfCommentRecord extends OmfRecord {
+ public static final byte COMMENT_CLASS_TRANSLATOR = 0;
+ public static final byte COMMENT_CLASS_LIBMOD = (byte) 0xA3;
+
private byte commentType;
private byte commentClass;
private String value;
@@ -29,12 +32,12 @@ public class OmfCommentRecord extends OmfRecord {
readRecordHeader(reader);
commentType = reader.readNextByte();
commentClass = reader.readNextByte();
- byte[] bytes = reader.readNextByteArray(getRecordLength()-3); // May not be a string, depending on commentClass
- if ((commentClass == (byte)0)||(commentClass == (byte)0xA3)) {
- int len = bytes[0] & 0xff;
- value = new String(bytes,1,len); // This is the translator/libmod string
+ byte[] bytes = reader.readNextByteArray(
+ getRecordLength() - 3 /* 3 = sizeof(commentType+commentClass+trailing_crcbyte*/);
+
+ if (commentClass == COMMENT_CLASS_TRANSLATOR || commentClass == COMMENT_CLASS_LIBMOD) {
+ value = new String(bytes, StandardCharsets.US_ASCII); // assuming ASCII
}
- // value = reader.readNextAsciiString(getRecordLength() - 3);
readCheckSumByte(reader);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfFileHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfFileHeader.java
index 15f85be5f8..42a4bb116b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfFileHeader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfFileHeader.java
@@ -15,9 +15,10 @@
*/
package ghidra.app.util.bin.format.omf;
-import java.io.IOException;
import java.util.ArrayList;
+import java.io.IOException;
+
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
import ghidra.util.task.TaskMonitor;
@@ -276,10 +277,10 @@ public class OmfFileHeader extends OmfRecord {
switch(type) {
case COMENT:
byte commentClass = ((OmfCommentRecord)record).getCommentClass();
- if (commentClass == (byte)0) {
+ if (commentClass == OmfCommentRecord.COMMENT_CLASS_TRANSLATOR) {
header.translator = ((OmfCommentRecord)record).getValue();
}
- else if (commentClass == (byte)0xA3) {
+ else if (commentClass == OmfCommentRecord.COMMENT_CLASS_LIBMOD) {
header.libModuleName = ((OmfCommentRecord)record).getValue();
}
break;
@@ -316,10 +317,10 @@ public class OmfFileHeader extends OmfRecord {
switch(type) {
case COMENT:
byte commentClass = ((OmfCommentRecord)record).getCommentClass();
- if (commentClass == (byte)0) {
+ if (commentClass == OmfCommentRecord.COMMENT_CLASS_TRANSLATOR) {
header.translator = ((OmfCommentRecord)record).getValue();
}
- else if (commentClass == (byte)0xA3) {
+ else if (commentClass == OmfCommentRecord.COMMENT_CLASS_LIBMOD) {
header.libModuleName = ((OmfCommentRecord)record).getValue();
}
break;