GP-5371: MachoLoader now uses longs to model native uint32_t

This commit is contained in:
Ryan Kurtz 2025-02-12 12:05:25 -05:00
parent eaa8aeb0c8
commit bf92745d25
23 changed files with 242 additions and 223 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -31,7 +31,7 @@ public class BuildVersionCommand extends LoadCommand {
private int platform; private int platform;
private int minos; private int minos;
private int sdk; private int sdk;
private int ntools; private long ntools;
private BuildToolVersion[] buildToolVersions; private BuildToolVersion[] buildToolVersions;
BuildVersionCommand(BinaryReader reader) throws IOException { BuildVersionCommand(BinaryReader reader) throws IOException {
@ -40,8 +40,8 @@ public class BuildVersionCommand extends LoadCommand {
platform = reader.readNextInt(); platform = reader.readNextInt();
minos = reader.readNextInt(); minos = reader.readNextInt();
sdk = reader.readNextInt(); sdk = reader.readNextInt();
ntools = reader.readNextInt(); ntools = checkCount(reader.readNextUnsignedInt());
buildToolVersions = new BuildToolVersion[ntools]; buildToolVersions = new BuildToolVersion[(int) ntools];
for (int i = 0; i < ntools; i++) { for (int i = 0; i < ntools; i++) {
buildToolVersions[i] = new BuildToolVersion(reader.readNextInt(), reader.readNextInt()); buildToolVersions[i] = new BuildToolVersion(reader.readNextInt(), reader.readNextInt());
} }
@ -58,7 +58,7 @@ public class BuildVersionCommand extends LoadCommand {
struct.add(DWORD, "sdk", null); struct.add(DWORD, "sdk", null);
struct.add(DWORD, "ntools", null); struct.add(DWORD, "ntools", null);
if (ntools > 0) { if (ntools > 0) {
struct.add(new ArrayDataType(buildToolVersionDataType, ntools, struct.add(new ArrayDataType(buildToolVersionDataType, (int) ntools,
buildToolVersionDataType.getLength()), "build_tool_version[]", null); buildToolVersionDataType.getLength()), "build_tool_version[]", null);
} }
struct.setCategoryPath(new CategoryPath(MachConstants.DATA_TYPE_CATEGORY)); struct.setCategoryPath(new CategoryPath(MachConstants.DATA_TYPE_CATEGORY));
@ -82,7 +82,7 @@ public class BuildVersionCommand extends LoadCommand {
return sdk; return sdk;
} }
public int getNumTools() { public long getNumTools() {
return ntools; return ntools;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -35,16 +35,16 @@ import ghidra.util.task.TaskMonitor;
* Represents a dyld_info_command structure * Represents a dyld_info_command structure
*/ */
public class DyldInfoCommand extends LoadCommand { public class DyldInfoCommand extends LoadCommand {
private int rebaseOff; private long rebaseOff;
private int rebaseSize; private long rebaseSize;
private int bindOff; private long bindOff;
private int bindSize; private long bindSize;
private int weakBindOff; private long weakBindOff;
private int weakBindSize; private long weakBindSize;
private int lazyBindOff; private long lazyBindOff;
private int lazyBindSize; private long lazyBindSize;
private int exportOff; private long exportOff;
private int exportSize; private long exportSize;
private RebaseTable rebaseTable; private RebaseTable rebaseTable;
private BindingTable bindingTable; private BindingTable bindingTable;
@ -66,16 +66,16 @@ public class DyldInfoCommand extends LoadCommand {
throws IOException { throws IOException {
super(loadCommandReader); super(loadCommandReader);
rebaseOff = loadCommandReader.readNextInt(); rebaseOff = loadCommandReader.readNextUnsignedInt();
rebaseSize = loadCommandReader.readNextInt(); rebaseSize = loadCommandReader.readNextUnsignedInt();
bindOff = loadCommandReader.readNextInt(); bindOff = loadCommandReader.readNextUnsignedInt();
bindSize = loadCommandReader.readNextInt(); bindSize = loadCommandReader.readNextUnsignedInt();
weakBindOff = loadCommandReader.readNextInt(); weakBindOff = loadCommandReader.readNextUnsignedInt();
weakBindSize = loadCommandReader.readNextInt(); weakBindSize = loadCommandReader.readNextUnsignedInt();
lazyBindOff = loadCommandReader.readNextInt(); lazyBindOff = loadCommandReader.readNextUnsignedInt();
lazyBindSize = loadCommandReader.readNextInt(); lazyBindSize = loadCommandReader.readNextUnsignedInt();
exportOff = loadCommandReader.readNextInt(); exportOff = loadCommandReader.readNextUnsignedInt();
exportSize = loadCommandReader.readNextInt(); exportSize = loadCommandReader.readNextUnsignedInt();
if (rebaseOff > 0 && rebaseSize > 0) { if (rebaseOff > 0 && rebaseSize > 0) {
dataReader.setPointerIndex(header.getStartIndex() + rebaseOff); dataReader.setPointerIndex(header.getStartIndex() + rebaseOff);
@ -121,70 +121,70 @@ public class DyldInfoCommand extends LoadCommand {
/** /**
* {@return The rebase info offset} * {@return The rebase info offset}
*/ */
public int getRebaseOffset() { public long getRebaseOffset() {
return rebaseOff; return rebaseOff;
} }
/** /**
* {@return The rebase info size} * {@return The rebase info size}
*/ */
public int getRebaseSize() { public long getRebaseSize() {
return rebaseSize; return rebaseSize;
} }
/** /**
* {@return The bind info offset} * {@return The bind info offset}
*/ */
public int getBindOffset() { public long getBindOffset() {
return bindOff; return bindOff;
} }
/** /**
* {@return The bind info size} * {@return The bind info size}
*/ */
public int getBindSize() { public long getBindSize() {
return bindSize; return bindSize;
} }
/** /**
* {@return The weak bind info offset} * {@return The weak bind info offset}
*/ */
public int getWeakBindOffset() { public long getWeakBindOffset() {
return weakBindOff; return weakBindOff;
} }
/** /**
* {@return The weak bind info size} * {@return The weak bind info size}
*/ */
public int getWeakBindSize() { public long getWeakBindSize() {
return weakBindSize; return weakBindSize;
} }
/** /**
* {@return The lazy bind info offset} * {@return The lazy bind info offset}
*/ */
public int getLazyBindOffset() { public long getLazyBindOffset() {
return lazyBindOff; return lazyBindOff;
} }
/** /**
* {@return The lazy bind info size} * {@return The lazy bind info size}
*/ */
public int getLazyBindSize() { public long getLazyBindSize() {
return lazyBindSize; return lazyBindSize;
} }
/** /**
* {@return The export info offset} * {@return The export info offset}
*/ */
public int getExportOffset() { public long getExportOffset() {
return exportOff; return exportOff;
} }
/** /**
* {@return The export info size} * {@return The export info size}
*/ */
public int getExportSize() { public long getExportSize() {
return exportSize; return exportSize;
} }

View file

@ -37,31 +37,31 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class DynamicSymbolTableCommand extends LoadCommand { public class DynamicSymbolTableCommand extends LoadCommand {
private int ilocalsym; private long ilocalsym;
private int nlocalsym; private long nlocalsym;
private int iextdefsym; private long iextdefsym;
private int nextdefsym; private long nextdefsym;
private int iundefsym; private long iundefsym;
private int nundefsym; private long nundefsym;
private int tocoff; private long tocoff;
private int ntoc; private long ntoc;
private int modtaboff; private long modtaboff;
private int nmodtab; private long nmodtab;
private int extrefsymoff; private long extrefsymoff;
private int nextrefsyms; private long nextrefsyms;
private int indirectsymoff; private long indirectsymoff;
private int nindirectsyms; private long nindirectsyms;
private int extreloff; private long extreloff;
private int nextrel; private long nextrel;
private int locreloff; private long locreloff;
private int nlocrel; private long nlocrel;
private List<TableOfContents> tocList = new ArrayList<TableOfContents>(); private List<TableOfContents> tocList = new ArrayList<>();
private List<DynamicLibraryModule> moduleList = new ArrayList<DynamicLibraryModule>(); private List<DynamicLibraryModule> moduleList = new ArrayList<>();
private List<DynamicLibraryReference> referencedList = new ArrayList<DynamicLibraryReference>(); private List<DynamicLibraryReference> referencedList = new ArrayList<>();
private int[] indirectSymbols = new int[0]; private List<Integer> indirectSymbols = new ArrayList<>();
private List<RelocationInfo> externalRelocations = new ArrayList<RelocationInfo>(); private List<RelocationInfo> externalRelocations = new ArrayList<>();
private List<RelocationInfo> localRelocations = new ArrayList<RelocationInfo>(); private List<RelocationInfo> localRelocations = new ArrayList<>();
/** /**
* Creates and parses a new {@link DynamicSymbolTableCommand} * Creates and parses a new {@link DynamicSymbolTableCommand}
@ -77,59 +77,58 @@ public class DynamicSymbolTableCommand extends LoadCommand {
MachHeader header) throws IOException { MachHeader header) throws IOException {
super(loadCommandReader); super(loadCommandReader);
ilocalsym = loadCommandReader.readNextInt(); ilocalsym = loadCommandReader.readNextUnsignedInt();
nlocalsym = loadCommandReader.readNextInt(); nlocalsym = checkCount(loadCommandReader.readNextUnsignedInt());
iextdefsym = loadCommandReader.readNextInt(); iextdefsym = loadCommandReader.readNextUnsignedInt();
nextdefsym = loadCommandReader.readNextInt(); nextdefsym = checkCount(loadCommandReader.readNextUnsignedInt());
iundefsym = loadCommandReader.readNextInt(); iundefsym = loadCommandReader.readNextUnsignedInt();
nundefsym = loadCommandReader.readNextInt(); nundefsym = checkCount(loadCommandReader.readNextUnsignedInt());
tocoff = loadCommandReader.readNextInt(); tocoff = loadCommandReader.readNextUnsignedInt();
ntoc = loadCommandReader.readNextInt(); ntoc = checkCount(loadCommandReader.readNextUnsignedInt());
modtaboff = loadCommandReader.readNextInt(); modtaboff = loadCommandReader.readNextUnsignedInt();
nmodtab = loadCommandReader.readNextInt(); nmodtab = checkCount(loadCommandReader.readNextUnsignedInt());
extrefsymoff = loadCommandReader.readNextInt(); extrefsymoff = loadCommandReader.readNextUnsignedInt();
nextrefsyms = loadCommandReader.readNextInt(); nextrefsyms = checkCount(loadCommandReader.readNextUnsignedInt());
indirectsymoff = loadCommandReader.readNextInt(); indirectsymoff = loadCommandReader.readNextUnsignedInt();
nindirectsyms = loadCommandReader.readNextInt(); nindirectsyms = checkCount(loadCommandReader.readNextUnsignedInt());
extreloff = loadCommandReader.readNextInt(); extreloff = loadCommandReader.readNextUnsignedInt();
nextrel = loadCommandReader.readNextInt(); nextrel = checkCount(loadCommandReader.readNextUnsignedInt());
locreloff = loadCommandReader.readNextInt(); locreloff = loadCommandReader.readNextUnsignedInt();
nlocrel = loadCommandReader.readNextInt(); nlocrel = checkCount(loadCommandReader.readNextUnsignedInt());
if (tocoff > 0) { if (tocoff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + tocoff); dataReader.setPointerIndex(header.getStartIndex() + tocoff);
for (int i = 0; i < ntoc; ++i) { for (long i = 0; i < ntoc; ++i) {
tocList.add(new TableOfContents(dataReader)); tocList.add(new TableOfContents(dataReader));
} }
} }
if (modtaboff > 0) { if (modtaboff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + modtaboff); dataReader.setPointerIndex(header.getStartIndex() + modtaboff);
for (int i = 0; i < nmodtab; ++i) { for (long i = 0; i < nmodtab; ++i) {
moduleList.add(new DynamicLibraryModule(dataReader, header)); moduleList.add(new DynamicLibraryModule(dataReader, header));
} }
} }
if (extrefsymoff > 0) { if (extrefsymoff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + extrefsymoff); dataReader.setPointerIndex(header.getStartIndex() + extrefsymoff);
for (int i = 0; i < nextrefsyms; ++i) { for (long i = 0; i < nextrefsyms; ++i) {
referencedList.add(new DynamicLibraryReference(dataReader)); referencedList.add(new DynamicLibraryReference(dataReader));
} }
} }
if (indirectsymoff > 0) { if (indirectsymoff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + indirectsymoff); dataReader.setPointerIndex(header.getStartIndex() + indirectsymoff);
indirectSymbols = new int[nindirectsyms]; for (long i = 0; i < nindirectsyms; ++i) {
for (int i = 0; i < nindirectsyms; ++i) { indirectSymbols.add(dataReader.readNextInt());
indirectSymbols[i] = dataReader.readNextInt();
} }
} }
if (extreloff > 0) { if (extreloff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + extreloff); dataReader.setPointerIndex(header.getStartIndex() + extreloff);
for (int i = 0; i < nextrel; ++i) { for (long i = 0; i < nextrel; ++i) {
externalRelocations.add(new RelocationInfo(dataReader)); externalRelocations.add(new RelocationInfo(dataReader));
} }
} }
if (locreloff > 0) { if (locreloff > 0) {
dataReader.setPointerIndex(header.getStartIndex() + locreloff); dataReader.setPointerIndex(header.getStartIndex() + locreloff);
for (int i = 0; i < nlocrel; ++i) { for (long i = 0; i < nlocrel; ++i) {
localRelocations.add(new RelocationInfo(dataReader)); localRelocations.add(new RelocationInfo(dataReader));
} }
} }
@ -139,7 +138,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the index of the first local symbol. * Returns the index of the first local symbol.
* @return the index of the first local symbol * @return the index of the first local symbol
*/ */
public int getLocalSymbolIndex() { public long getLocalSymbolIndex() {
return ilocalsym; return ilocalsym;
} }
@ -147,7 +146,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the total number of local symbols. * Returns the total number of local symbols.
* @return the total number of local symbols * @return the total number of local symbols
*/ */
public int getLocalSymbolCount() { public long getLocalSymbolCount() {
return nlocalsym; return nlocalsym;
} }
@ -155,7 +154,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the index of the first external symbol. * Returns the index of the first external symbol.
* @return the index of the first external symbol * @return the index of the first external symbol
*/ */
public int getExternalSymbolIndex() { public long getExternalSymbolIndex() {
return iextdefsym; return iextdefsym;
} }
@ -163,7 +162,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the total number of external symbols. * Returns the total number of external symbols.
* @return the total number of external symbols * @return the total number of external symbols
*/ */
public int getExternalSymbolCount() { public long getExternalSymbolCount() {
return nextdefsym; return nextdefsym;
} }
@ -171,7 +170,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the index of the first undefined symbol. * Returns the index of the first undefined symbol.
* @return the index of the first undefined symbol * @return the index of the first undefined symbol
*/ */
public int getUndefinedSymbolIndex() { public long getUndefinedSymbolIndex() {
return iundefsym; return iundefsym;
} }
@ -179,7 +178,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the total number of undefined symbols. * Returns the total number of undefined symbols.
* @return the total number of undefined symbols * @return the total number of undefined symbols
*/ */
public int getUndefinedSymbolCount() { public long getUndefinedSymbolCount() {
return nundefsym; return nundefsym;
} }
@ -187,7 +186,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the table of contents (TOC). * Returns the byte index from the start of the file to the table of contents (TOC).
* @return the byte index of the TOC * @return the byte index of the TOC
*/ */
public int getTableOfContentsOffset() { public long getTableOfContentsOffset() {
return tocoff; return tocoff;
} }
@ -195,7 +194,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the table of contents. * Returns the number of entries in the table of contents.
* @return the number of entries in the table of contents * @return the number of entries in the table of contents
*/ */
public int getTableOfContentsSize() { public long getTableOfContentsSize() {
return ntoc; return ntoc;
} }
@ -207,7 +206,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the module table. * Returns the byte index from the start of the file to the module table.
* @return the byte index of the module table * @return the byte index of the module table
*/ */
public int getModuleTableOffset() { public long getModuleTableOffset() {
return modtaboff; return modtaboff;
} }
@ -215,7 +214,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the module table. * Returns the number of entries in the module table.
* @return the number of entries in the module table * @return the number of entries in the module table
*/ */
public int getModuleTableSize() { public long getModuleTableSize() {
return nmodtab; return nmodtab;
} }
@ -227,7 +226,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the external reference table. * Returns the byte index from the start of the file to the external reference table.
* @return the byte index of the external reference table * @return the byte index of the external reference table
*/ */
public int getReferencedSymbolTableOffset() { public long getReferencedSymbolTableOffset() {
return extrefsymoff; return extrefsymoff;
} }
@ -235,7 +234,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the external reference table. * Returns the number of entries in the external reference table.
* @return the number of entries in the external reference table * @return the number of entries in the external reference table
*/ */
public int getReferencedSymbolTableSize() { public long getReferencedSymbolTableSize() {
return nextrefsyms; return nextrefsyms;
} }
@ -247,7 +246,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the indirect symbol table. * Returns the byte index from the start of the file to the indirect symbol table.
* @return the byte index of the indirect symbol table * @return the byte index of the indirect symbol table
*/ */
public int getIndirectSymbolTableOffset() { public long getIndirectSymbolTableOffset() {
return indirectsymoff; return indirectsymoff;
} }
@ -255,11 +254,11 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the indirect symbol table. * Returns the number of entries in the indirect symbol table.
* @return the number of entries in the indirect symbol table * @return the number of entries in the indirect symbol table
*/ */
public int getIndirectSymbolTableSize() { public long getIndirectSymbolTableSize() {
return nindirectsyms; return nindirectsyms;
} }
public int[] getIndirectSymbols() { public List<Integer> getIndirectSymbols() {
return indirectSymbols; return indirectSymbols;
} }
@ -267,7 +266,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the external relocation table. * Returns the byte index from the start of the file to the external relocation table.
* @return the byte index of the external relocation table * @return the byte index of the external relocation table
*/ */
public int getExternalRelocationOffset() { public long getExternalRelocationOffset() {
return extreloff; return extreloff;
} }
@ -275,7 +274,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the external relocation table. * Returns the number of entries in the external relocation table.
* @return the number of entries in the external relocation table * @return the number of entries in the external relocation table
*/ */
public int getExternalRelocationSize() { public long getExternalRelocationSize() {
return nextrel; return nextrel;
} }
@ -287,7 +286,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the byte index from the start of the file to the local relocation table. * Returns the byte index from the start of the file to the local relocation table.
* @return the byte index of the local relocation table * @return the byte index of the local relocation table
*/ */
public int getLocalRelocationOffset() { public long getLocalRelocationOffset() {
return locreloff; return locreloff;
} }
@ -295,7 +294,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
* Returns the number of entries in the local relocation table. * Returns the number of entries in the local relocation table.
* @return the number of entries in the local relocation table * @return the number of entries in the local relocation table
*/ */
public int getLocalRelocationSize() { public long getLocalRelocationSize() {
return nlocrel; return nlocrel;
} }
@ -309,7 +308,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
} }
@Override @Override
public int getLinkerDataSize() { public long getLinkerDataSize() {
return nindirectsyms * Integer.BYTES; return nindirectsyms * Integer.BYTES;
} }
@ -373,7 +372,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
ReferenceManager referenceManager = program.getReferenceManager(); ReferenceManager referenceManager = program.getReferenceManager();
try { try {
for (int i = 0; i < nindirectsyms; i++) { for (int i = 0; i < nindirectsyms; i++) {
int nlistIndex = indirectSymbols[i]; int nlistIndex = indirectSymbols.get(i);
Address dataAddr = indirectSymbolTableAddr.add(i * DWORD.getLength()); Address dataAddr = indirectSymbolTableAddr.add(i * DWORD.getLength());
DataUtilities.createData(program, dataAddr, DWORD, -1, DataUtilities.createData(program, dataAddr, DWORD, -1,
DataUtilities.ClearDataMode.CHECK_FOR_SPACE); DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
@ -472,19 +471,19 @@ public class DynamicSymbolTableCommand extends LoadCommand {
api.createFragment(parentModule, "INDIRECT_SYMBOLS", start, length); api.createFragment(parentModule, "INDIRECT_SYMBOLS", start, length);
for (int i = 0; i < indirectSymbols.length; ++i) { for (int i = 0; i < indirectSymbols.size(); ++i) {
if (monitor.isCancelled()) { if (monitor.isCancelled()) {
return; return;
} }
Address addr = start.add(i * SIZEOF_DWORD); Address addr = start.add(i * SIZEOF_DWORD);
NList symbol = header.getFirstLoadCommand(SymbolTableCommand.class).getSymbolAt( NList symbol = header.getFirstLoadCommand(SymbolTableCommand.class).getSymbolAt(
indirectSymbols[i]); indirectSymbols.get(i));
if (symbol != null) { if (symbol != null) {
api.setEOLComment(addr, symbol.getString()); api.setEOLComment(addr, symbol.getString());
} }
} }
api.createDwords(start, getIndirectSymbolTableSize()); api.createDwords(start, (int) getIndirectSymbolTableSize());
} }
private void markupExternalRelocations(FlatProgramAPI api, Address baseAddress, private void markupExternalRelocations(FlatProgramAPI api, Address baseAddress,

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -26,8 +26,8 @@ import ghidra.util.exception.DuplicateNameException;
* Represents an encryption_info_command structure * Represents an encryption_info_command structure
*/ */
public class EncryptedInformationCommand extends LoadCommand { public class EncryptedInformationCommand extends LoadCommand {
private int cryptoff; private long cryptoff;
private int cryptsize; private long cryptsize;
private int cryptid; private int cryptid;
private boolean is32bit; private boolean is32bit;
@ -36,8 +36,8 @@ public class EncryptedInformationCommand extends LoadCommand {
super(reader); super(reader);
this.is32bit = is32bit; this.is32bit = is32bit;
cryptoff = reader.readNextInt(); cryptoff = reader.readNextUnsignedInt();
cryptsize = reader.readNextInt(); cryptsize = reader.readNextUnsignedInt();
cryptid = reader.readNextInt(); cryptid = reader.readNextInt();
} }
@ -45,11 +45,11 @@ public class EncryptedInformationCommand extends LoadCommand {
return cryptid; return cryptid;
} }
public int getCryptOffset() { public long getCryptOffset() {
return cryptoff; return cryptoff;
} }
public int getCryptSize() { public long getCryptSize() {
return cryptsize; return cryptsize;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -33,7 +33,7 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class FixedVirtualMemoryFileCommand extends LoadCommand { public class FixedVirtualMemoryFileCommand extends LoadCommand {
private LoadCommandString name; private LoadCommandString name;
private int header_addr; private long header_addr;
public FixedVirtualMemoryFileCommand(BinaryReader reader) throws IOException { public FixedVirtualMemoryFileCommand(BinaryReader reader) throws IOException {
super(reader); super(reader);
@ -51,7 +51,7 @@ public class FixedVirtualMemoryFileCommand extends LoadCommand {
* Returns the file's virtual address. * Returns the file's virtual address.
* @return the file's virtual address * @return the file's virtual address
*/ */
public int getHeaderAddress() { public long getHeaderAddress() {
return header_addr; return header_addr;
} }

View file

@ -34,8 +34,8 @@ import ghidra.util.task.TaskMonitor;
* Represents a linkedit_data_command structure * Represents a linkedit_data_command structure
*/ */
public class LinkEditDataCommand extends LoadCommand { public class LinkEditDataCommand extends LoadCommand {
protected int dataoff; protected long dataoff;
protected int datasize; protected long datasize;
protected BinaryReader dataReader; protected BinaryReader dataReader;
/** /**
@ -51,8 +51,8 @@ public class LinkEditDataCommand extends LoadCommand {
LinkEditDataCommand(BinaryReader loadCommandReader, BinaryReader dataReader) LinkEditDataCommand(BinaryReader loadCommandReader, BinaryReader dataReader)
throws IOException { throws IOException {
super(loadCommandReader); super(loadCommandReader);
this.dataoff = loadCommandReader.readNextInt(); this.dataoff = loadCommandReader.readNextUnsignedInt();
this.datasize = loadCommandReader.readNextInt(); this.datasize = loadCommandReader.readNextUnsignedInt();
this.dataReader = dataReader; this.dataReader = dataReader;
this.dataReader.setPointerIndex(dataoff); this.dataReader.setPointerIndex(dataoff);
} }
@ -63,7 +63,7 @@ public class LinkEditDataCommand extends LoadCommand {
} }
@Override @Override
public int getLinkerDataSize() { public long getLinkerDataSize() {
return datasize; return datasize;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -29,13 +29,13 @@ import ghidra.util.exception.DuplicateNameException;
*/ */
public class LinkerOptionCommand extends LoadCommand { public class LinkerOptionCommand extends LoadCommand {
private int count; private long count;
private List<String> linkerOptions; private List<String> linkerOptions;
LinkerOptionCommand(BinaryReader reader) throws IOException { LinkerOptionCommand(BinaryReader reader) throws IOException {
super(reader); super(reader);
count = reader.readNextInt(); count = checkCount(reader.readNextUnsignedInt());
linkerOptions = new ArrayList<>(count); linkerOptions = new ArrayList<>();
BinaryReader stringReader = reader.clone(); BinaryReader stringReader = reader.clone();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String str = stringReader.readNextAsciiString(); String str = stringReader.readNextAsciiString();

View file

@ -16,6 +16,7 @@
package ghidra.app.util.bin.format.macho.commands; package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.cmd.formats.MachoBinaryAnalysisCommand; import ghidra.app.cmd.formats.MachoBinaryAnalysisCommand;
import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.BinaryReader;
@ -101,7 +102,7 @@ public abstract class LoadCommand implements StructConverter {
* *
* @return The file size of this load command's "linker data", or 0 if it has no linker data * @return The file size of this load command's "linker data", or 0 if it has no linker data
*/ */
public int getLinkerDataSize() { public long getLinkerDataSize() {
return 0; return 0;
} }
@ -171,7 +172,7 @@ public abstract class LoadCommand implements StructConverter {
* @return The converted {@link Address}, or null if there is no corresponding {@link Address} * @return The converted {@link Address}, or null if there is no corresponding {@link Address}
*/ */
protected Address fileOffsetToAddress(Program program, MachHeader header, long fileOffset, protected Address fileOffsetToAddress(Program program, MachHeader header, long fileOffset,
int size) { long size) {
if (fileOffset != 0 && size != 0) { if (fileOffset != 0 && size != 0) {
AddressSpace space = program.getAddressFactory().getDefaultAddressSpace(); AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
SegmentCommand segment = getContainingSegment(header, fileOffset); SegmentCommand segment = getContainingSegment(header, fileOffset);
@ -183,6 +184,25 @@ public abstract class LoadCommand implements StructConverter {
return null; return null;
} }
/**
* Checks to make sure the given count value isn't larger than {@link Integer#MAX_VALUE}.
* <p>
* Count values are typically {@code uint32_t}, so we store them as {@code long}s. But, we
* usually end up storing the items in an array or {@link ArrayList}, which can't exceed the
* size of an {@code int}.
*
* @param count The count value to check
* @return The original count value
* @throws IOException if the given count value exceeds {@link Integer#MAX_VALUE}
*/
protected long checkCount(long count) throws IOException {
if (count > Integer.MAX_VALUE) {
throw new IOException("Count value 0x%x in %s is greater than Integer.MAX_VALUE"
.formatted(count, getClass().getSimpleName()));
}
return count;
}
/** /**
* Gets the {@link SegmentCommand segment} that contains the give file offset * Gets the {@link SegmentCommand segment} that contains the give file offset
* *

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -33,13 +33,13 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class PreboundDynamicLibraryCommand extends LoadCommand { public class PreboundDynamicLibraryCommand extends LoadCommand {
private LoadCommandString name; private LoadCommandString name;
private int nmodules; private long nmodules;
private LoadCommandString linkedModules; private LoadCommandString linkedModules;
PreboundDynamicLibraryCommand(BinaryReader reader) throws IOException { PreboundDynamicLibraryCommand(BinaryReader reader) throws IOException {
super(reader); super(reader);
name = new LoadCommandString(reader, this); name = new LoadCommandString(reader, this);
nmodules = reader.readNextInt(); nmodules = checkCount(reader.readNextUnsignedInt());
linkedModules = new LoadCommandString(reader, this); linkedModules = new LoadCommandString(reader, this);
} }
@ -67,7 +67,7 @@ public class PreboundDynamicLibraryCommand extends LoadCommand {
* Returns number of modules in library. * Returns number of modules in library.
* @return number of modules in library * @return number of modules in library
*/ */
public int getNumberOfModules() { public long getNumberOfModules() {
return nmodules; return nmodules;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -44,7 +44,7 @@ public class SegmentCommand extends LoadCommand {
private long filesize; private long filesize;
private int maxprot; private int maxprot;
private int initprot; private int initprot;
private int nsects; private long nsects;
private int flags; private int flags;
private boolean is32bit; private boolean is32bit;
@ -69,10 +69,10 @@ public class SegmentCommand extends LoadCommand {
} }
maxprot = reader.readNextInt(); maxprot = reader.readNextInt();
initprot = reader.readNextInt(); initprot = reader.readNextInt();
nsects = reader.readNextInt(); nsects = checkCount(reader.readNextUnsignedInt());
flags = reader.readNextInt(); flags = reader.readNextInt();
for (int i = 0; i < nsects; ++i) { for (long i = 0; i < nsects; ++i) {
sections.add(new Section(reader, is32bit)); sections.add(new Section(reader, is32bit));
} }
} }
@ -194,7 +194,7 @@ public class SegmentCommand extends LoadCommand {
return (initprot & SegmentConstants.PROTECTION_X) != 0; return (initprot & SegmentConstants.PROTECTION_X) != 0;
} }
public int getNumberOfSections() { public long getNumberOfSections() {
return nsects; return nsects;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -26,18 +26,18 @@ import ghidra.app.util.bin.format.macho.MachException;
* @see <a href="https://opensource.apple.com/source/xnu/xnu-4570.71.2/EXTERNAL_HEADERS/mach-o/loader.h.auto.html">mach-o/loader.h</a> * @see <a href="https://opensource.apple.com/source/xnu/xnu-4570.71.2/EXTERNAL_HEADERS/mach-o/loader.h.auto.html">mach-o/loader.h</a>
*/ */
public class SymbolCommand extends ObsoleteCommand { public class SymbolCommand extends ObsoleteCommand {
private int offset; private long offset;
private int size; private long size;
SymbolCommand(BinaryReader reader) throws IOException, MachException { SymbolCommand(BinaryReader reader) throws IOException, MachException {
super(reader); super(reader);
} }
public int getOffset() { public long getOffset() {
return offset; return offset;
} }
public int getSize() { public long getSize() {
return size; return size;
} }

View file

@ -38,9 +38,9 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class SymbolTableCommand extends LoadCommand { public class SymbolTableCommand extends LoadCommand {
private long symoff; private long symoff;
private int nsyms; private long nsyms;
private long stroff; private long stroff;
private int strsize; private long strsize;
private List<NList> symbols = new ArrayList<NList>(); private List<NList> symbols = new ArrayList<NList>();
@ -59,11 +59,11 @@ public class SymbolTableCommand extends LoadCommand {
super(loadCommandReader); super(loadCommandReader);
symoff = loadCommandReader.readNextUnsignedInt(); symoff = loadCommandReader.readNextUnsignedInt();
nsyms = loadCommandReader.readNextInt(); nsyms = checkCount(loadCommandReader.readNextUnsignedInt());
stroff = loadCommandReader.readNextUnsignedInt(); stroff = loadCommandReader.readNextUnsignedInt();
strsize = loadCommandReader.readNextInt(); strsize = loadCommandReader.readNextUnsignedInt();
List<NList> nlistList = new ArrayList<>(nsyms); List<NList> nlistList = new ArrayList<>((int) nsyms);
dataReader.setPointerIndex(header.getStartIndex() + symoff); dataReader.setPointerIndex(header.getStartIndex() + symoff);
for (int i = 0; i < nsyms; ++i) { for (int i = 0; i < nsyms; ++i) {
nlistList.add(new NList(dataReader, header.is32bit())); nlistList.add(new NList(dataReader, header.is32bit()));
@ -98,7 +98,7 @@ public class SymbolTableCommand extends LoadCommand {
* An integer indicating the number of entries in the symbol table. * An integer indicating the number of entries in the symbol table.
* @return the number of entries in the symbol table * @return the number of entries in the symbol table
*/ */
public int getNumberOfSymbols() { public long getNumberOfSymbols() {
return nsyms; return nsyms;
} }
@ -115,7 +115,7 @@ public class SymbolTableCommand extends LoadCommand {
* An integer indicating the size (in bytes) of the string table. * An integer indicating the size (in bytes) of the string table.
* @return string table size in bytes * @return string table size in bytes
*/ */
public int getStringTableSize() { public long getStringTableSize() {
return strsize; return strsize;
} }
@ -174,7 +174,7 @@ public class SymbolTableCommand extends LoadCommand {
} }
@Override @Override
public int getLinkerDataSize() { public long getLinkerDataSize() {
return NList.getSize(symbols); return NList.getSize(symbols);
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -35,18 +35,18 @@ import ghidra.util.task.TaskMonitor;
* Represents a twolevel_hints_command structure * Represents a twolevel_hints_command structure
*/ */
public class TwoLevelHintsCommand extends LoadCommand { public class TwoLevelHintsCommand extends LoadCommand {
private int offset; private long offset;
private int nhints; private long nhints;
private List<TwoLevelHint> hints = new ArrayList<TwoLevelHint>(); private List<TwoLevelHint> hints = new ArrayList<>();
TwoLevelHintsCommand(BinaryReader reader) throws IOException { TwoLevelHintsCommand(BinaryReader reader) throws IOException {
super(reader); super(reader);
offset = reader.readNextInt(); offset = reader.readNextUnsignedInt();
nhints = reader.readNextInt(); nhints = checkCount(reader.readNextUnsignedInt());
long index = reader.getPointerIndex(); long index = reader.getPointerIndex();
reader.setPointerIndex(offset); reader.setPointerIndex(offset);
for (int i = 0; i < nhints; ++i) { for (long i = 0; i < nhints; ++i) {
hints.add(new TwoLevelHint(reader)); hints.add(new TwoLevelHint(reader));
} }
reader.setPointerIndex(index); reader.setPointerIndex(index);
@ -60,7 +60,7 @@ public class TwoLevelHintsCommand extends LoadCommand {
* Returns the offset to the hint table. * Returns the offset to the hint table.
* @return the offset to the hint table * @return the offset to the hint table
*/ */
public int getOffset() { public long getOffset() {
return offset; return offset;
} }
@ -68,7 +68,7 @@ public class TwoLevelHintsCommand extends LoadCommand {
* Returns the number of hints in the hint table. * Returns the number of hints in the hint table.
* @return the number of hints in the hint table * @return the number of hints in the hint table
*/ */
public int getNumberOfHints() { public long getNumberOfHints() {
return nhints; return nhints;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -38,11 +38,11 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class DyldChainedFixupHeader implements StructConverter { public class DyldChainedFixupHeader implements StructConverter {
private int fixupsVersion; private long fixupsVersion;
private int startsOffset; private long startsOffset;
private int importsOffset; private long importsOffset;
private int symbolsOffset; private long symbolsOffset;
private int importsCount; private long importsCount;
private int importsFormat; private int importsFormat;
private int symbolsFormat; private int symbolsFormat;
@ -58,11 +58,11 @@ public class DyldChainedFixupHeader implements StructConverter {
public DyldChainedFixupHeader(BinaryReader reader) throws IOException { public DyldChainedFixupHeader(BinaryReader reader) throws IOException {
long ptrIndex = reader.getPointerIndex(); long ptrIndex = reader.getPointerIndex();
fixupsVersion = reader.readNextInt(); fixupsVersion = reader.readNextUnsignedInt();
startsOffset = reader.readNextInt(); startsOffset = reader.readNextUnsignedInt();
importsOffset = reader.readNextInt(); importsOffset = reader.readNextUnsignedInt();
symbolsOffset = reader.readNextInt(); symbolsOffset = reader.readNextUnsignedInt();
importsCount = reader.readNextInt(); importsCount = reader.readNextUnsignedInt();
importsFormat = reader.readNextInt(); importsFormat = reader.readNextInt();
symbolsFormat = reader.readNextInt(); symbolsFormat = reader.readNextInt();
@ -134,23 +134,23 @@ public class DyldChainedFixupHeader implements StructConverter {
return struct; return struct;
} }
public int getFixupsVersion() { public long getFixupsVersion() {
return fixupsVersion; return fixupsVersion;
} }
public int getStartsOffset() { public long getStartsOffset() {
return startsOffset; return startsOffset;
} }
public int getImportsOffset() { public long getImportsOffset() {
return importsOffset; return importsOffset;
} }
public int getSymbolsOffset() { public long getSymbolsOffset() {
return symbolsOffset; return symbolsOffset;
} }
public int getImportsCount() { public long getImportsCount() {
return importsCount; return importsCount;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -29,7 +29,7 @@ import ghidra.app.util.bin.format.macho.commands.dyld.BindingTable.Binding;
*/ */
public class DyldChainedImports { public class DyldChainedImports {
private int importsCount; private long importsCount;
private int importsFormat; private int importsFormat;
private long importsOffset; private long importsOffset;
private DyldChainedImport[] chainedImports; private DyldChainedImport[] chainedImports;
@ -57,7 +57,7 @@ public class DyldChainedImports {
} }
} }
public int getImportsCount() { public long getImportsCount() {
return importsCount; return importsCount;
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -38,7 +38,7 @@ import ghidra.util.task.TaskMonitor;
public class CodeSignatureGenericBlob implements StructConverter { public class CodeSignatureGenericBlob implements StructConverter {
protected int magic; protected int magic;
protected int length; protected long length;
protected long base; protected long base;
@ -51,7 +51,7 @@ public class CodeSignatureGenericBlob implements StructConverter {
public CodeSignatureGenericBlob(BinaryReader reader) throws IOException { public CodeSignatureGenericBlob(BinaryReader reader) throws IOException {
base = reader.getPointerIndex(); base = reader.getPointerIndex();
magic = reader.readNextInt(); magic = reader.readNextInt();
length = reader.readNextInt(); length = reader.readNextUnsignedInt();
} }
/** /**
@ -64,7 +64,7 @@ public class CodeSignatureGenericBlob implements StructConverter {
/** /**
* {@return the length} * {@return the length}
*/ */
public int getLength() { public long getLength() {
return length; return length;
} }
@ -84,7 +84,7 @@ public class CodeSignatureGenericBlob implements StructConverter {
return; return;
} }
try { try {
DataType dt = new ArrayDataType(BYTE, length - 8, 1); DataType dt = new ArrayDataType(BYTE, (int) length - 8, 1);
Address hashAddr = address.add(toDataType().getLength()); Address hashAddr = address.add(toDataType().getLength());
DataUtilities.createData(program, hashAddr, dt, -1, DataUtilities.createData(program, hashAddr, dt, -1,
DataUtilities.ClearDataMode.CHECK_FOR_SPACE); DataUtilities.ClearDataMode.CHECK_FOR_SPACE);

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -51,7 +51,7 @@ public class BindingTable extends OpcodeTable {
* @param lazy True if this is a lazy binding table; otherwise, false * @param lazy True if this is a lazy binding table; otherwise, false
* @throws IOException if an IO-related error occurs while parsing * @throws IOException if an IO-related error occurs while parsing
*/ */
public BindingTable(BinaryReader reader, MachHeader header, int tableSize, boolean lazy) public BindingTable(BinaryReader reader, MachHeader header, long tableSize, boolean lazy)
throws IOException { throws IOException {
this(); this();

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -79,7 +79,7 @@ public class ClassicBindProcessor extends AbstractClassicProcessor {
int indirectOffset = section.getReserved1(); int indirectOffset = section.getReserved1();
long count = section.getSize() / program.getDefaultPointerSize(); long count = section.getSize() / program.getDefaultPointerSize();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
int symbolIndex = command.getIndirectSymbols()[indirectOffset + i]; int symbolIndex = command.getIndirectSymbols().get(indirectOffset + i);
if (symbolIndex != DynamicSymbolTableConstants.INDIRECT_SYMBOL_LOCAL) { if (symbolIndex != DynamicSymbolTableConstants.INDIRECT_SYMBOL_LOCAL) {
NList nList = symbolTableCommand.getSymbolAt(symbolIndex); NList nList = symbolTableCommand.getSymbolAt(symbolIndex);
if (nList == null) { if (nList == null) {

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,13 +15,13 @@
*/ */
package ghidra.app.util.bin.format.macho.commands.dyld; package ghidra.app.util.bin.format.macho.commands.dyld;
import java.util.List;
import ghidra.app.util.bin.format.macho.*; import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.bin.format.macho.commands.*; import ghidra.app.util.bin.format.macho.commands.*;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.List;
public class ClassicLazyBindProcessor extends AbstractClassicProcessor { public class ClassicLazyBindProcessor extends AbstractClassicProcessor {
public ClassicLazyBindProcessor(MachHeader header, Program program) { public ClassicLazyBindProcessor(MachHeader header, Program program) {
@ -50,7 +50,7 @@ public class ClassicLazyBindProcessor extends AbstractClassicProcessor {
int indirectOffset = section.getReserved1(); int indirectOffset = section.getReserved1();
long count = section.getSize() / program.getDefaultPointerSize(); long count = section.getSize() / program.getDefaultPointerSize();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
int symbolIndex = command.getIndirectSymbols()[indirectOffset + i]; int symbolIndex = command.getIndirectSymbols().get(indirectOffset + i);
NList nList = symbolTableCommand.getSymbolAt(symbolIndex); NList nList = symbolTableCommand.getSymbolAt(symbolIndex);
boolean isWeak = boolean isWeak =
(nList.getDescription() & NListConstants.DESC_N_WEAK_REF) != 0; (nList.getDescription() & NListConstants.DESC_N_WEAK_REF) != 0;
@ -68,7 +68,7 @@ public class ClassicLazyBindProcessor extends AbstractClassicProcessor {
int indirectOffset = section.getReserved1(); int indirectOffset = section.getReserved1();
long count = section.getSize() / 5; long count = section.getSize() / 5;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
int symbolIndex = command.getIndirectSymbols()[indirectOffset + i]; int symbolIndex = command.getIndirectSymbols().get(indirectOffset + i);
if (symbolIndex != DynamicSymbolTableConstants.INDIRECT_SYMBOL_ABS) { if (symbolIndex != DynamicSymbolTableConstants.INDIRECT_SYMBOL_ABS) {
NList nList = symbolTableCommand.getSymbolAt(symbolIndex); NList nList = symbolTableCommand.getSymbolAt(symbolIndex);
boolean isWeak = boolean isWeak =

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -47,7 +47,7 @@ public class RebaseTable extends OpcodeTable {
* @param tableSize The size of the table, in bytes * @param tableSize The size of the table, in bytes
* @throws IOException if an IO-related error occurs while parsing * @throws IOException if an IO-related error occurs while parsing
*/ */
public RebaseTable(BinaryReader reader, MachHeader header, int tableSize) throws IOException { public RebaseTable(BinaryReader reader, MachHeader header, long tableSize) throws IOException {
this(); this();
int pointerSize = header.getAddressSize(); int pointerSize = header.getAddressSize();

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,11 +25,11 @@ import ghidra.util.exception.DuplicateNameException;
public class ThreadStateHeader implements StructConverter { public class ThreadStateHeader implements StructConverter {
private int flavor; private int flavor;
private int count; private long count;
ThreadStateHeader(BinaryReader reader) throws IOException { ThreadStateHeader(BinaryReader reader) throws IOException {
flavor = reader.readNextInt(); flavor = reader.readNextInt();
count = reader.readNextInt(); count = reader.readNextUnsignedInt();
} }
/** /**
@ -44,7 +44,7 @@ public class ThreadStateHeader implements StructConverter {
* Returns the count of longs in thread state. * Returns the count of longs in thread state.
* @return the count of longs in thread state * @return the count of longs in thread state
*/ */
public int getCount() { public long getCount() {
return count; return count;
} }

View file

@ -660,8 +660,8 @@ public class MachoProgramBuilder {
if (dynamicCommand == null) { if (dynamicCommand == null) {
return; return;
} }
int[] indirectSymbols = dynamicCommand.getIndirectSymbols(); List<Integer> indirectSymbols = dynamicCommand.getIndirectSymbols();
if (indirectSymbols.length == 0) { if (indirectSymbols.size() == 0) {
return; return;
} }
@ -687,7 +687,7 @@ public class MachoProgramBuilder {
if (monitor.isCancelled()) { if (monitor.isCancelled()) {
break; break;
} }
int symbolIndex = indirectSymbols[i]; int symbolIndex = indirectSymbols.get(i);
NList symbol = symbolTableCommand.getSymbolAt(symbolIndex); NList symbol = symbolTableCommand.getSymbolAt(symbolIndex);
if (symbol == null) { if (symbol == null) {
continue; continue;

View file

@ -99,7 +99,7 @@ public class ExtractedMacho {
symbolTable.addSymbols(getExtraSymbols()); symbolTable.addSymbols(getExtraSymbols());
} }
long offset = cmd.getLinkerDataOffset(); long offset = cmd.getLinkerDataOffset();
int size = cmd.getLinkerDataSize(); long size = cmd.getLinkerDataSize();
if (offset == 0 || size == 0) { if (offset == 0 || size == 0) {
continue; continue;
} }