Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3398: Adding a new type of COFF section header (fixes #1336)

Ryan Kurtzca21388e65de
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader.java
index a25161c32a..2362bb862f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader.java
@@ -29,6 +29,9 @@ import ghidra.util.*;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
+/**
+ * A 0x28 byte COFF section header
+ */
public class CoffSectionHeader implements StructConverter {
protected String s_name; // section name
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader1.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader1.java
index 3c861b5c5a..f9de1260c4 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader1.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader1.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.
@@ -16,14 +15,12 @@
*/
package ghidra.app.util.bin.format.coff;
-import ghidra.app.util.bin.BinaryReader;
-
import java.io.IOException;
+import ghidra.app.util.bin.BinaryReader;
+
/**
- *
- * COFF1 Section Header
- *
+ * A 0x28 byte COFF section header
*/
class CoffSectionHeader1 extends CoffSectionHeader {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader2.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader2.java
index 26b9b5e7e9..45a6cdf6e8 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader2.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader2.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.
@@ -16,14 +15,12 @@
*/
package ghidra.app.util.bin.format.coff;
-import ghidra.app.util.bin.BinaryReader;
-
import java.io.IOException;
+import ghidra.app.util.bin.BinaryReader;
+
/**
- *
- * COFF2 Section Header
- *
+ * A 0x30 byte COFF section header
*/
class CoffSectionHeader2 extends CoffSectionHeader {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader3.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader3.java
new file mode 100644
index 0000000000..d6de3fd962
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeader3.java
@@ -0,0 +1,50 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.bin.format.coff;
+
+import java.io.IOException;
+
+import ghidra.app.util.bin.BinaryReader;
+
+/**
+ * A 0x2c byte COFF section header
+ */
+class CoffSectionHeader3 extends CoffSectionHeader {
+
+ CoffSectionHeader3(BinaryReader reader, CoffFileHeader header) throws IOException {
+ super();
+
+ this._header = header;
+
+ readName(reader);
+
+ s_paddr = reader.readNextInt();
+ s_vaddr = reader.readNextInt();
+ s_size = reader.readNextInt();
+ 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.readNextInt();
+
+ reader.readNextInt(); // section alignment, currently unused
+
+ s_reserved = 0;
+ s_page = 0;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeaderFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeaderFactory.java
index c82a002c76..a6a402e785 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeaderFactory.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/coff/CoffSectionHeaderFactory.java
@@ -23,10 +23,13 @@ final class CoffSectionHeaderFactory {
static CoffSectionHeader createSectionHeader(BinaryReader reader, CoffFileHeader header) throws IOException {
switch (header.getMagic()) {
- case CoffMachineType.TICOFF2MAGIC:
- return new CoffSectionHeader2(reader, header);
case CoffMachineType.TICOFF1MAGIC:
return new CoffSectionHeader1(reader, header);
+ case CoffMachineType.TICOFF2MAGIC:
+ return new CoffSectionHeader2(reader, header);
+ case CoffMachineType.IMAGE_FILE_MACHINE_I960ROMAGIC:
+ case CoffMachineType.IMAGE_FILE_MACHINE_I960RWMAGIC:
+ return new CoffSectionHeader3(reader, header);
default:
return new CoffSectionHeader(reader, header);
}