Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-397 fix PE loader to handle uninitialized section

dev74736892f7cae52c84
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/SectionHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/SectionHeader.java
index 2c2ddd1c52..6eba2f307a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/SectionHeader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/SectionHeader.java
@@ -394,6 +394,9 @@ public class SectionHeader implements StructConverter, ByteArrayConverter {
* for the section begins. For executables,
* this value must be a multiple of the file
* alignment given in the PE header.
+ * <p>
+ * If a section is uninitialized, this value will be 0.
+ *
* @return the file offset where the data for the section begins
*/
public int getPointerToRawData() {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java
index 6d4541014b..5d367b8c82 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java
@@ -642,8 +642,9 @@ public class PeLoader extends AbstractPeDebugLoader {
SectionFlags.IMAGE_SCN_MEM_EXECUTE.getMask()) != 0x0);
int rawDataSize = sections[i].getSizeOfRawData();
+ int rawDataPtr = sections[i].getPointerToRawData();
virtualSize = sections[i].getVirtualSize();
- if (rawDataSize != 0) {
+ if (rawDataSize != 0 && rawDataPtr != 0) {
int dataSize =
((rawDataSize > virtualSize && virtualSize > 0) || rawDataSize < 0)
? virtualSize
@@ -654,13 +655,12 @@ public class PeLoader extends AbstractPeDebugLoader {
Msg.warn(this, "OptionalHeader.SizeOfImage < size of " +
sections[i].getName() + " section");
}
- long offset = sections[i].getPointerToRawData();
String sectionName = sections[i].getReadableName();
if (sectionName.isBlank()) {
sectionName = "SECTION." + i;
}
MemoryBlockUtils.createInitializedBlock(prog, false, sectionName, address,
- fileBytes, offset, dataSize, "", "", r, w, x, log);
+ fileBytes, rawDataPtr, dataSize, "", "", r, w, x, log);
sectionToAddress.put(sections[i], address);
}
if (rawDataSize == virtualSize) {