Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0: Removing 'numSections' parameter from SegmentCommand.create(), since creating sections is not supported (Closes #7428)

Ryan Kurtz4519440f535b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SegmentCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SegmentCommand.java
index 4fe32917b3..9e11cc50ed 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SegmentCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SegmentCommand.java
@@ -314,7 +314,9 @@ public class SegmentCommand extends LoadCommand {
}
/**
- * Creates a new segment command byte array
+ * Creates a new segment command byte array.
+ * <p>
+ * NOTE: The new segment will have 0 sections.
*
* @param magic The magic
* @param name The name of the segment (must be less than or equal to 16 bytes)
@@ -324,15 +326,13 @@ public class SegmentCommand extends LoadCommand {
* @param fileSize The size of the segment on disk
* @param maxProt The maximum protections of the segment
* @param initProt The initial protection of the segment
- * @param numSections The number of sections in the segment
* @param flags The segment flags
* @return The new segment in byte array form
* @throws MachException if an invalid magic value was passed in (see {@link MachConstants}), or
* if the desired segment name exceeds 16 bytes
*/
public static byte[] create(int magic, String name, long vmAddr, long vmSize, long fileOffset,
- long fileSize, int maxProt, int initProt, int numSections, int flags)
- throws MachException {
+ long fileSize, int maxProt, int initProt, int flags) throws MachException {
if (name.length() > 16) {
throw new MachException("Segment name cannot exceed 16 bytes: " + name);
@@ -355,7 +355,7 @@ public class SegmentCommand extends LoadCommand {
conv.putLong(bytes, 0x30, fileSize);
conv.putInt(bytes, 0x38, maxProt);
conv.putInt(bytes, 0x3c, initProt);
- conv.putInt(bytes, 0x40, numSections);
+ conv.putInt(bytes, 0x40, 0);
conv.putInt(bytes, 0x44, flags);
}
else {
@@ -365,7 +365,7 @@ public class SegmentCommand extends LoadCommand {
conv.putInt(bytes, 0x24, (int) fileSize);
conv.putInt(bytes, 0x28, maxProt);
conv.putInt(bytes, 0x2c, initProt);
- conv.putInt(bytes, 0x30, numSections);
+ conv.putInt(bytes, 0x30, 0);
conv.putInt(bytes, 0x34, flags);
}
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheExtractor.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheExtractor.java
index d5c748f00e..73c7298b30 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheExtractor.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheExtractor.java
@@ -114,7 +114,7 @@ public class DyldCacheExtractor {
SegmentCommand.create(magic,
"%s.%d.%d".formatted(segmentName, entry.splitCacheIndex(), i),
range.lowerEndpoint(), dataSize, current, dataSize,
- mappingInfo.getMaxProtection(), mappingInfo.getMaxProtection(), 0, 0));
+ mappingInfo.getMaxProtection(), mappingInfo.getMaxProtection(), 0));
// Data
data.add(slidProvider.readBytes(
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/fileset/MachoFileSetExtractor.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/fileset/MachoFileSetExtractor.java
index 9cf69fa7ef..472ae4adc9 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/fileset/MachoFileSetExtractor.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/fileset/MachoFileSetExtractor.java
@@ -4,9 +4,9 @@
* 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.
@@ -74,7 +74,8 @@ public class MachoFileSetExtractor {
* @throws IOException If there was an IO-related issue with extracting the segment
* @throws CancelledException If the user cancelled the operation
*/
- public static ByteProvider extractSegment(ByteProvider provider, SegmentCommand segment, FSRL fsrl, TaskMonitor monitor) throws IOException, MachException, CancelledException {
+ public static ByteProvider extractSegment(ByteProvider provider, SegmentCommand segment,
+ FSRL fsrl, TaskMonitor monitor) throws IOException, MachException, CancelledException {
int magic = MachConstants.MH_MAGIC_64;
int allSegmentsSize = SegmentCommand.size(magic);
@@ -87,7 +88,7 @@ public class MachoFileSetExtractor {
byte[] segmentCommandBytes =
SegmentCommand.create(magic, segment.getSegmentName(), segment.getVMaddress(),
segment.getVMsize(), header.length + allSegmentsSize, segment.getFileSize(),
- segment.getMaxProtection(), segment.getInitProtection(), 0, segment.getFlags());
+ segment.getMaxProtection(), segment.getInitProtection(), segment.getFlags());
// Segment data
byte[] segmentDataBytes =