Skip to content

Ghidra is a software reverse engineering (SRE) framework

Backporting "Start using `long` for symbol table offsets instead of `int`" to patch (#7436, #7882)

Noah Gregorya962761ac0dd
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/DynamicSymbolTableCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/DynamicSymbolTableCommand.java
index 6e6c54e43d..0a27eb41c3 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/DynamicSymbolTableCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/DynamicSymbolTableCommand.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.
@@ -304,7 +304,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
}
@Override
- public int getLinkerDataOffset() {
+ public long getLinkerDataOffset() {
return indirectsymoff;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LinkEditDataCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LinkEditDataCommand.java
index 99f9e5f969..fb8110562e 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LinkEditDataCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LinkEditDataCommand.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.
@@ -58,7 +58,7 @@ public class LinkEditDataCommand extends LoadCommand {
}
@Override
- public int getLinkerDataOffset() {
+ public long getLinkerDataOffset() {
return dataoff;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LoadCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LoadCommand.java
index 46fd65296e..a87535a354 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LoadCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/LoadCommand.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.
@@ -91,7 +91,7 @@ public abstract class LoadCommand implements StructConverter {
*
* @return The file offset of this load command's "linker data", or 0 if it has no linker data
*/
- public int getLinkerDataOffset() {
+ public long getLinkerDataOffset() {
return 0;
}
@@ -170,7 +170,7 @@ public abstract class LoadCommand implements StructConverter {
* @param size The size (actual size not important, but 0 will cause null to be returned)
* @return The converted {@link Address}, or null if there is no corresponding {@link Address}
*/
- protected Address fileOffsetToAddress(Program program, MachHeader header, int fileOffset,
+ protected Address fileOffsetToAddress(Program program, MachHeader header, long fileOffset,
int size) {
if (fileOffset != 0 && size != 0) {
AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java
index 9cd919ad83..9061ea0063 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.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.
@@ -37,9 +37,9 @@ import ghidra.util.task.TaskMonitor;
* Represents a symtab_command structure
*/
public class SymbolTableCommand extends LoadCommand {
- private int symoff;
+ private long symoff;
private int nsyms;
- private int stroff;
+ private long stroff;
private int strsize;
private List<NList> symbols = new ArrayList<NList>();
@@ -58,9 +58,9 @@ public class SymbolTableCommand extends LoadCommand {
MachHeader header) throws IOException {
super(loadCommandReader);
- symoff = loadCommandReader.readNextInt();
+ symoff = loadCommandReader.readNextUnsignedInt();
nsyms = loadCommandReader.readNextInt();
- stroff = loadCommandReader.readNextInt();
+ stroff = loadCommandReader.readNextUnsignedInt();
strsize = loadCommandReader.readNextInt();
List<NList> nlistList = new ArrayList<>(nsyms);
@@ -90,7 +90,7 @@ public class SymbolTableCommand extends LoadCommand {
* The symbol table is an array of nlist data structures.
* @return symbol table offset
*/
- public int getSymbolOffset() {
+ public long getSymbolOffset() {
return symoff;
}
@@ -107,7 +107,7 @@ public class SymbolTableCommand extends LoadCommand {
* location of the string table.
* @return string table offset
*/
- public int getStringTableOffset() {
+ public long getStringTableOffset() {
return stroff;
}
@@ -169,7 +169,7 @@ public class SymbolTableCommand extends LoadCommand {
}
@Override
- public int getLinkerDataOffset() {
+ public long getLinkerDataOffset() {
return symoff;
}
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ExtractedMacho.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ExtractedMacho.java
index 613b7f3576..28231b5f33 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ExtractedMacho.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ExtractedMacho.java
@@ -98,7 +98,7 @@ public class ExtractedMacho {
if (cmd instanceof SymbolTableCommand symbolTable) {
symbolTable.addSymbols(getExtraSymbols());
}
- int offset = cmd.getLinkerDataOffset();
+ long offset = cmd.getLinkerDataOffset();
int size = cmd.getLinkerDataSize();
if (offset == 0 || size == 0) {
continue;