Merge branch 'GP-1907_ryanmkurtz_ContinuesInterceptor'

This commit is contained in:
Ryan Kurtz 2022-04-15 02:25:01 -04:00
commit 2e2380c927
226 changed files with 1319 additions and 3794 deletions

View File

@ -22,7 +22,6 @@ import java.util.Set;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.app.plugin.core.debug.workflow.DisassemblyInject;
import ghidra.app.plugin.core.debug.workflow.DisassemblyInjectInfo;
@ -107,8 +106,7 @@ public class DbgengX64DisassemblyInject implements DisassemblyInject {
}
MemoryByteProvider mbp = new MemoryByteProvider(view.getMemory(), module.getBase());
try {
PortableExecutable pe = PortableExecutable.createPortableExecutable(
RethrowContinuesFactory.INSTANCE, mbp, SectionLayout.MEMORY, false, false);
PortableExecutable pe = new PortableExecutable(mbp, SectionLayout.MEMORY, false, false);
NTHeader ntHeader = pe.getNTHeader();
if (ntHeader == null) {
return Mode.UNK;

View File

@ -29,6 +29,6 @@
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="_Integration Test"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="ghidra.GhidraRun"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="_Integration Test"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+IgnoreUnrecognizedVMOptions&#13;&#10;-Djava.system.class.loader=ghidra.GhidraClassLoader&#13;&#10;-Xshare:off&#13;&#10;-Dfile.encoding=UTF8&#13;&#10;-Duser.country=US&#13;&#10;-Duser.language=en&#13;&#10;-Dsun.java2d.pmoffscreen=false&#13;&#10;-Dsun.java2d.xrender=true&#13;&#10;-Dsun.java2d.d3d=false&#13;&#10;-Xdock:name=&quot;Ghidra&quot;&#13;&#10;-Dvisualvm.display.name=Ghidra&#13;&#10;-Dpython.console.encoding=UTF-8&#13;&#10;--add-opens=java.base/java.lang=ALL-UNNAMED&#13;&#10;--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+IgnoreUnrecognizedVMOptions&#13;&#10;-Djava.system.class.loader=ghidra.GhidraClassLoader&#13;&#10;-Xshare:off&#13;&#10;-Dfile.encoding=UTF8&#13;&#10;-Duser.country=US&#13;&#10;-Duser.language=en&#13;&#10;-Dsun.java2d.pmoffscreen=false&#13;&#10;-Dsun.java2d.xrender=true&#13;&#10;-Dsun.java2d.d3d=false&#13;&#10;-Xdock:name=&quot;Ghidra&quot;&#13;&#10;-Dvisualvm.display.name=Ghidra&#13;&#10;-Dpython.console.encoding=UTF-8&#13;&#10;--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:Framework Utility}"/>
</launchConfiguration>

View File

@ -31,5 +31,5 @@
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="Framework Utility"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="ghidra.GhidraRun"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Framework Utility"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+IgnoreUnrecognizedVMOptions&#13;&#10;-Djava.system.class.loader=ghidra.GhidraClassLoader&#13;&#10;-Xshare:off&#13;&#10;-Dfile.encoding=UTF8&#13;&#10;-Duser.country=US&#13;&#10;-Duser.language=en&#13;&#10;-Dsun.java2d.pmoffscreen=false&#13;&#10;-Dsun.java2d.xrender=true&#13;&#10;-Dsun.java2d.d3d=false&#13;&#10;-Xdock:name=&quot;Ghidra&quot;&#13;&#10;-Dvisualvm.display.name=Ghidra&#13;&#10;-Dpython.console.encoding=UTF-8&#13;&#10;--add-opens=java.base/java.lang=ALL-UNNAMED&#13;&#10;--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+IgnoreUnrecognizedVMOptions&#13;&#10;-Djava.system.class.loader=ghidra.GhidraClassLoader&#13;&#10;-Xshare:off&#13;&#10;-Dfile.encoding=UTF8&#13;&#10;-Duser.country=US&#13;&#10;-Duser.language=en&#13;&#10;-Dsun.java2d.pmoffscreen=false&#13;&#10;-Dsun.java2d.xrender=true&#13;&#10;-Dsun.java2d.d3d=false&#13;&#10;-Xdock:name=&quot;Ghidra&quot;&#13;&#10;-Dvisualvm.display.name=Ghidra&#13;&#10;-Dpython.console.encoding=UTF-8&#13;&#10;--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED"/>
</launchConfiguration>

View File

@ -24,7 +24,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.MemoryByteProvider;
@ -48,8 +47,7 @@ public class PortableExecutableRichPrintScript extends GhidraScript {
PortableExecutable pe = null;
try {
pe = PortableExecutable.createPortableExecutable(RethrowContinuesFactory.INSTANCE,
provider, SectionLayout.MEMORY, false, false);
pe = new PortableExecutable(provider, SectionLayout.MEMORY, false, false);
}
catch (Exception e) {
printerr("Unable to create PE from current program");

View File

@ -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.
@ -19,7 +18,9 @@
//are placed in the same directory with the processor name appended.
//@category Binary
import generic.continues.RethrowContinuesFactory;
import java.io.*;
import java.util.List;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.RandomAccessByteProvider;
@ -28,9 +29,6 @@ import ghidra.app.util.bin.format.ubi.FatArch;
import ghidra.app.util.bin.format.ubi.FatHeader;
import ghidra.program.model.lang.Processor;
import java.io.*;
import java.util.List;
public class SplitUniversalBinariesScript extends GhidraScript {
@ -40,7 +38,7 @@ public class SplitUniversalBinariesScript extends GhidraScript {
File outputDirectory = askDirectory("Select Output Directory", "GO");
ByteProvider provider = new RandomAccessByteProvider(ubiFile) ;
FatHeader header = FatHeader.createFatHeader(RethrowContinuesFactory.INSTANCE, provider);
FatHeader header = new FatHeader(provider);
List<FatArch> architectures = header.getArchitectures();
for (FatArch arch : architectures) {

View File

@ -17,7 +17,6 @@ package ghidra.app.cmd.formats;
import java.util.Arrays;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.plugin.core.analysis.AnalysisWorker;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.util.bin.*;
@ -36,7 +35,8 @@ import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.symbol.*;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.*;
import ghidra.util.Msg;
import ghidra.util.StringUtilities;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
@ -80,8 +80,7 @@ public class ElfBinaryAnalysisCommand extends FlatProgramAPI
ByteProvider provider = new MemoryByteProvider(currentProgram.getMemory(),
currentProgram.getAddressFactory().getDefaultAddressSpace());
try {
ElfHeader elf = ElfHeader.createElfHeader(RethrowContinuesFactory.INSTANCE, provider,
msg -> messages.appendMsg(msg));
ElfHeader elf = new ElfHeader(provider, msg -> messages.appendMsg(msg));
elf.parse();
processElfHeader(elf, listing);
@ -221,7 +220,7 @@ public class ElfBinaryAnalysisCommand extends FlatProgramAPI
}
Structure phStructDt = (Structure) elf.getProgramHeaders()[0].toDataType();
phStructDt = (Structure) phStructDt.clone(listing.getDataTypeManager());
phStructDt = phStructDt.clone(listing.getDataTypeManager());
Array arrayDt = new ArrayDataType(phStructDt, headerCount, size);
Data array = createData(addr(elf.e_phoff()), arrayDt);
@ -382,7 +381,7 @@ public class ElfBinaryAnalysisCommand extends FlatProgramAPI
}
String name = symbols[j].getNameAsString();
long value = symbols[j].getValue() & Conv.INT_MASK;
long value = Integer.toUnsignedLong((int) symbols[j].getValue());
try {
Address currAddr = symbolTableAddr.add(j * symbolTable2.getEntrySize());

View File

@ -17,7 +17,6 @@ package ghidra.app.cmd.formats;
import java.util.List;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.plugin.core.analysis.AnalysisWorker;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.util.bin.ByteProvider;
@ -94,8 +93,8 @@ public class MachoBinaryAnalysisCommand extends FlatProgramAPI
program.getAddressFactory().getDefaultAddressSpace());
try {
MachHeader header = MachHeader.createMachHeader(RethrowContinuesFactory.INSTANCE,
provider, getAddress(program).getOffset(), isRelativeToAddress);
MachHeader header =
new MachHeader(provider, getAddress(program).getOffset(), isRelativeToAddress);
header.parse();
Address machAddress = getAddress(program);

View File

@ -18,12 +18,9 @@ package ghidra.app.cmd.formats;
import java.io.IOException;
import java.util.List;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.plugin.core.analysis.AnalysisWorker;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.MemoryByteProvider;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.mz.DOSHeader;
import ghidra.app.util.bin.format.pe.*;
import ghidra.app.util.bin.format.pe.PortableExecutable.SectionLayout;
@ -56,10 +53,9 @@ public class PortableExecutableBinaryAnalysisCommand extends FlatProgramAPI
ByteProvider provider = new MemoryByteProvider(memory,
program.getAddressFactory().getDefaultAddressSpace());
FactoryBundledWithBinaryReader reader = new FactoryBundledWithBinaryReader(
RethrowContinuesFactory.INSTANCE, provider, !program.getLanguage().isBigEndian());
BinaryReader reader = new BinaryReader(provider, !program.getLanguage().isBigEndian());
DOSHeader dosHeader = DOSHeader.createDOSHeader(reader);
DOSHeader dosHeader = new DOSHeader(reader);
if (dosHeader.isDosSignature()) {
@ -82,9 +78,7 @@ public class PortableExecutableBinaryAnalysisCommand extends FlatProgramAPI
ByteProvider provider = new MemoryByteProvider(currentProgram.getMemory(),
program.getAddressFactory().getDefaultAddressSpace());
PortableExecutable pe =
PortableExecutable.createPortableExecutable(RethrowContinuesFactory.INSTANCE, provider,
SectionLayout.FILE);
PortableExecutable pe = new PortableExecutable(provider, SectionLayout.FILE);
DOSHeader dos = pe.getDOSHeader();
if (dos == null || dos.e_magic() != DOSHeader.IMAGE_DOS_SIGNATURE) {

View File

@ -15,7 +15,10 @@
*/
package ghidra.app.plugin.core.analysis;
import generic.continues.RethrowContinuesFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import ghidra.app.services.*;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.dwarf.DwarfSectionNames;
@ -32,10 +35,6 @@ import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class DwarfLineNumberAnalyzer extends AbstractAnalyzer {
private static final String NAME = "DWARF Line Number";
private static final String DESCRIPTION = "Extracts DWARF debug line number information.";
@ -114,8 +113,7 @@ public class DwarfLineNumberAnalyzer extends AbstractAnalyzer {
}
RandomAccessByteProvider provider = new RandomAccessByteProvider(dSymFile);
try {
MachHeader header =
MachHeader.createMachHeader(RethrowContinuesFactory.INSTANCE, provider);
MachHeader header = new MachHeader(provider);
header.parse();
List<Section> allSections = header.getAllSections();
for (Section section : allSections) {

View File

@ -19,7 +19,6 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
import generic.continues.GenericFactory;
import ghidra.app.cmd.function.CreateFunctionCmd;
import ghidra.app.services.*;
import ghidra.app.util.PseudoDisassembler;
@ -29,7 +28,6 @@ import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.bin.format.macho.commands.*;
import ghidra.app.util.bin.format.macho.dyld.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.importer.MessageLogContinuesFactory;
import ghidra.app.util.opinion.DyldCacheLoader;
import ghidra.app.util.opinion.MachoLoader;
import ghidra.framework.options.Options;
@ -170,8 +168,7 @@ public class MachoFunctionStartsAnalyzer extends AbstractAnalyzer {
private void analyzeMachoFunctionStarts(Program program, ByteProvider provider,
AddressSetView set, TaskMonitor monitor, MessageLog log)
throws MachException, IOException, CancelledException {
GenericFactory factory = MessageLogContinuesFactory.create(log);
MachHeader header = MachHeader.createMachHeader(factory, provider);
MachHeader header = new MachHeader(provider);
header.parse();
monitor.setIndeterminate(true);
monitor.setMessage("Analyzing function starts...");
@ -215,8 +212,7 @@ public class MachoFunctionStartsAnalyzer extends AbstractAnalyzer {
monitor.incrementProgress(1);
// Parse Mach-O header
MachHeader machoHeader = MachHeader.createMachHeader(
MessageLogContinuesFactory.create(log), providerMap.get(dyldCacheHeader),
MachHeader machoHeader = new MachHeader(providerMap.get(dyldCacheHeader),
mappedImage.getAddress() - dyldCacheHeader.getBaseAddress(), false);
machoHeader.parse();

View File

@ -1,37 +0,0 @@
/* ###
* 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.
* 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;
import generic.continues.*;
import ghidra.app.util.bin.*;
public class FactoryBundledWithBinaryReader extends BinaryReader {
private final GenericFactory factory;
public GenericFactory getFactory() {
return factory;
}
public FactoryBundledWithBinaryReader(GenericFactory factory,
ByteProvider provider, boolean isLittleEndian) {
super(provider, isLittleEndian);
if (factory == null) {
throw new IllegalArgumentException("factory == null not allowed");
}
this.factory = factory;
}
}

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.opinion.MachoLoader;
@ -62,7 +61,7 @@ public class DSymSectionProvider implements DWARFSectionProvider {
public DSymSectionProvider(File dsymFile) throws IOException, MachException {
this.provider = new RandomAccessByteProvider(dsymFile);
machHeader = MachHeader.createMachHeader(RethrowContinuesFactory.INSTANCE, provider);
machHeader = new MachHeader(provider);
machHeader.parse();
for (Section s : machHeader.getAllSections()) {
// strip leading "_"'s from section name to normalize

View File

@ -17,9 +17,10 @@ package ghidra.app.util.bin.format.elf;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteArrayConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.util.*;
import ghidra.util.DataConverter;
import ghidra.util.StringUtilities;
/**
* A class to represent the Elf<code>32</code>_Dyn data structure.
@ -56,28 +57,14 @@ public class ElfDynamic implements ByteArrayConverter {
private ElfHeader elf;
private int d_tag;
// private ElfDynamicType d_tag_type;
private long d_val;
public static ElfDynamic createElfDynamic(
FactoryBundledWithBinaryReader reader, ElfHeader elf)
throws IOException {
ElfDynamic elfDynamic = (ElfDynamic) reader.getFactory().create(ElfDynamic.class);
elfDynamic.initElfDynamic(reader, elf);
return elfDynamic;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfDynamic() {}
private void initElfDynamic(FactoryBundledWithBinaryReader reader, ElfHeader elf)
public ElfDynamic(BinaryReader reader, ElfHeader elf)
throws IOException {
this.elf = elf;
if (elf.is32Bit()) {
d_tag = reader.readNextInt();
d_val = reader.readNextInt() & Conv.INT_MASK;
d_val = Integer.toUnsignedLong(reader.readNextInt());
}
else {
d_tag = (int) reader.readNextLong();
@ -148,7 +135,7 @@ FactoryBundledWithBinaryReader reader, ElfHeader elf)
* @param value the new value dynamic
*/
public void setValue(int value) {
this.d_val = value & Conv.INT_MASK;
this.d_val = Integer.toUnsignedLong(value);
}
/**
@ -191,8 +178,8 @@ FactoryBundledWithBinaryReader reader, ElfHeader elf)
}
/**
* Returns the size in bytes of this object.
*/
* @return the size in bytes of this object.
*/
public int sizeof() {
return elf.is32Bit() ? 8 : 16;
}

View File

@ -18,7 +18,7 @@ package ghidra.app.util.bin.format.elf;
import java.io.IOException;
import java.util.*;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.program.model.data.*;
import ghidra.util.DataConverter;
import ghidra.util.exception.DuplicateNameException;
@ -42,20 +42,7 @@ public class ElfDynamicTable implements ElfFileSection {
private long fileOffset;
private long addrOffset;
public static ElfDynamicTable createDynamicTable(FactoryBundledWithBinaryReader reader,
ElfHeader header, long fileOffset, long addrOffset) throws IOException {
ElfDynamicTable pt_dynamic = (ElfDynamicTable) reader.getFactory().create(ElfDynamicTable.class);
pt_dynamic.initDynamicTable(reader, header, fileOffset, addrOffset);
return pt_dynamic;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfDynamicTable() {
}
private void initDynamicTable(FactoryBundledWithBinaryReader reader, ElfHeader header,
public ElfDynamicTable(BinaryReader reader, ElfHeader header,
long fileOffset, long addrOffset) throws IOException {
long oldptr = reader.getPointerIndex();
@ -68,7 +55,7 @@ public class ElfDynamicTable implements ElfFileSection {
// Collect set of all _DYNAMIC array tags specified in .dynamic section
while (true) {
ElfDynamic dyn = ElfDynamic.createElfDynamic(reader, header);
ElfDynamic dyn = new ElfDynamic(reader, header);
dynamics.add(dyn);
if (dyn.getTag() == ElfDynamicType.DT_NULL.value) {
break;

View File

@ -20,9 +20,7 @@ import java.io.RandomAccessFile;
import java.util.*;
import java.util.function.Consumer;
import generic.continues.GenericFactory;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.Writeable;
import ghidra.app.util.bin.format.elf.ElfRelocationTable.TableFormat;
import ghidra.app.util.bin.format.elf.extend.ElfExtensionFactory;
@ -30,7 +28,8 @@ import ghidra.app.util.bin.format.elf.extend.ElfLoadAdapter;
import ghidra.program.model.data.*;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.util.*;
import ghidra.util.DataConverter;
import ghidra.util.Msg;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.NotFoundException;
@ -49,7 +48,7 @@ public class ElfHeader implements StructConverter, Writeable {
private HashMap<Integer, ElfDynamicType> dynamicTypeMap;
private ByteProvider provider; // original byte provider
private FactoryBundledWithBinaryReader reader; // based on unlimited byte provider
private BinaryReader reader; // unlimited reader
private ElfLoadAdapter elfLoadAdapter = new ElfLoadAdapter();
private byte e_ident_magic_num; //magic number
@ -98,28 +97,17 @@ public class ElfHeader implements StructConverter, Writeable {
private static int INITIAL_READ_LEN = ElfConstants.EI_NIDENT + 18;
/**
* Constructs a new ELF header using the specified byte provider.
* Only the one header is parsed. The related headers are not
* parsed until {@link #parse()} is invoked.
* @param factory instantiation factory
* @param provider the byte provider to supply the bytes
* @param errorConsumer optional error consumer or null for no logging
* @return ELF Header object
* @throws ElfException if the underlying bytes in the byte provider
* do not constitute a valid ELF.
* Construct <code>ElfHeader</code> from byte provider
* @param provider byte provider
* @param errorConsumer error consumer
* @throws ElfException if header parse failed
*/
public static ElfHeader createElfHeader(GenericFactory factory, ByteProvider provider,
Consumer<String> errorConsumer)
throws ElfException {
ElfHeader elfHeader = (ElfHeader) factory.create(ElfHeader.class);
elfHeader.initElfHeader(factory, provider, errorConsumer);
return elfHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfHeader() {
public ElfHeader(ByteProvider provider, Consumer<String> errorConsumer) throws ElfException {
this.provider = provider;
this.errorConsumer = errorConsumer != null ? errorConsumer : msg -> {
/* no logging if errorConsumer was null */
};
initElfHeader();
}
/**
@ -143,20 +131,14 @@ public class ElfHeader implements StructConverter, Writeable {
errorConsumer.accept(msg);
}
protected void initElfHeader(GenericFactory factory, ByteProvider provider,
Consumer<String> errorConsumer)
throws ElfException {
protected void initElfHeader() throws ElfException {
try {
this.provider = provider;
this.errorConsumer = errorConsumer != null ? errorConsumer : msg -> {
/* no logging if errorConsumer was null */
};
determineHeaderEndianess();
// reader uses unbounded provider wrapper to allow handling of missing/truncated headers
reader = new FactoryBundledWithBinaryReader(factory,
new UnlimitedByteProviderWrapper(provider), hasLittleEndianHeaders);
reader = new BinaryReader(new UnlimitedByteProviderWrapper(provider),
hasLittleEndianHeaders);
e_ident_magic_num = reader.readNextByte();
e_ident_magic_str = reader.readNextAsciiString(ElfConstants.MAGIC_STR_LEN);
@ -278,7 +260,7 @@ public class ElfHeader implements StructConverter, Writeable {
* Adjust address offset for certain pre-linked binaries which do not adjust certain
* header fields (e.g., dynamic table address entries). Standard GNU/Linux pre-linked
* shared libraries have adjusted header entries and this method should have no effect.
* @param address
* @param address unadjusted address offset
* @return address with appropriate pre-link adjustment added
*/
public long adjustAddressForPrelink(long address) {
@ -299,7 +281,7 @@ public class ElfHeader implements StructConverter, Writeable {
* Unadjust address offset for certain pre-linked binaries which do not adjust certain
* header fields (e.g., dynamic table address entries). This may be needed when updating
* a header address field which requires pre-link adjustment.
* @param address
* @param address prelink-adjusted address offset
* @return address with appropriate pre-link adjustment subtracted
*/
public long unadjustAddressForPrelink(long address) {
@ -489,7 +471,7 @@ public class ElfHeader implements StructConverter, Writeable {
format = TableFormat.RELR;
}
ElfRelocationTable relocTable = ElfRelocationTable.createElfRelocationTable(reader,
ElfRelocationTable relocTable = new ElfRelocationTable(reader,
this, section, section.getOffset(), section.getAddress(), section.getSize(),
section.getEntrySize(), addendTypeReloc, symbolTable, sectionToBeRelocated,
format);
@ -587,7 +569,7 @@ public class ElfHeader implements StructConverter, Writeable {
format = TableFormat.RELR;
}
ElfRelocationTable relocTable = ElfRelocationTable.createElfRelocationTable(reader,
ElfRelocationTable relocTable = new ElfRelocationTable(reader,
this, null, relocTableOffset, relocTableAddr, tableSize, tableEntrySize,
addendTypeReloc, dynamicSymbolTable, null, format);
relocationTableList.add(relocTable);
@ -599,7 +581,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Get linked section
* @param sectionIndex
* @param sectionIndex section index
* @param expectedTypes list of expectedTypes (may be omitted to accept any type)
* @return section or null if not found
*/
@ -661,7 +643,7 @@ public class ElfHeader implements StructConverter, Writeable {
if (loadHeader != null) {
long dynamicTableOffset = loadHeader.getOffset() +
(dynamicHeaders[0].getVirtualAddress() - loadHeader.getVirtualAddress());
dynamicTable = ElfDynamicTable.createDynamicTable(reader, this, dynamicTableOffset,
dynamicTable = new ElfDynamicTable(reader, this, dynamicTableOffset,
dynamicHeaders[0].getVirtualAddress());
return;
}
@ -678,7 +660,7 @@ public class ElfHeader implements StructConverter, Writeable {
if (loadHeader != null) {
long dynamicTableOffset = loadHeader.getOffset() +
(dynamicSections[0].getAddress() - loadHeader.getVirtualAddress());
dynamicTable = ElfDynamicTable.createDynamicTable(reader, this, dynamicTableOffset,
dynamicTable = new ElfDynamicTable(reader, this, dynamicTableOffset,
dynamicSections[0].getAddress());
return;
}
@ -686,7 +668,7 @@ public class ElfHeader implements StructConverter, Writeable {
}
private void parseStringTables() throws IOException {
private void parseStringTables() {
// identify dynamic symbol table address
long dynamicStringTableAddr = -1;
@ -703,7 +685,7 @@ public class ElfHeader implements StructConverter, Writeable {
ArrayList<ElfStringTable> stringTableList = new ArrayList<>();
for (ElfSectionHeader stringTableSectionHeader : sectionHeaders) {
if (stringTableSectionHeader.getType() == ElfSectionHeaderConstants.SHT_STRTAB) {
ElfStringTable stringTable = ElfStringTable.createElfStringTable(reader, this,
ElfStringTable stringTable = new ElfStringTable(reader, this,
stringTableSectionHeader, stringTableSectionHeader.getOffset(),
stringTableSectionHeader.getAddress(), stringTableSectionHeader.getSize());
stringTableList.add(stringTable);
@ -724,7 +706,7 @@ public class ElfHeader implements StructConverter, Writeable {
stringTableList.toArray(stringTables);
}
private ElfStringTable parseDynamicStringTable(long dynamicStringTableAddr) throws IOException {
private ElfStringTable parseDynamicStringTable(long dynamicStringTableAddr) {
if (!dynamicTable.containsDynamicValue(ElfDynamicType.DT_STRSZ)) {
errorConsumer.accept("Failed to parse DT_STRTAB, missing dynamic dependency");
@ -748,7 +730,7 @@ public class ElfHeader implements StructConverter, Writeable {
return null;
}
return ElfStringTable.createElfStringTable(reader, this, null,
return new ElfStringTable(reader, this, null,
stringTableLoadHeader.getOffset(dynamicStringTableAddr), dynamicStringTableAddr,
stringTableSize);
}
@ -792,7 +774,7 @@ public class ElfHeader implements StructConverter, Writeable {
boolean isDyanmic = ElfSectionHeaderConstants.dot_dynsym
.equals(symbolTableSectionHeader.getNameAsString());
ElfSymbolTable symbolTable = ElfSymbolTable.createElfSymbolTable(reader, this,
ElfSymbolTable symbolTable = new ElfSymbolTable(reader, this,
symbolTableSectionHeader, symbolTableSectionHeader.getOffset(),
symbolTableSectionHeader.getAddress(), symbolTableSectionHeader.getSize(),
symbolTableSectionHeader.getEntrySize(), stringTable, isDyanmic);
@ -880,7 +862,7 @@ public class ElfHeader implements StructConverter, Writeable {
symCount = reader.readInt(symbolHashTableOffset + 4); // nchain from DT_HASH
}
return ElfSymbolTable.createElfSymbolTable(reader, this, null, symbolTableOffset,
return new ElfSymbolTable(reader, this, null, symbolTableOffset,
tableAddr, tableEntrySize * symCount, tableEntrySize, dynamicStringTable, true);
}
catch (NotFoundException e) {
@ -890,7 +872,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Walk DT_GNU_HASH table to determine dynamic symbol count
* @param DT_GNU_HASH table file offset
* @param gnuHashTableOffset DT_GNU_HASH table file offset
* @return dynamic symbol count
* @throws IOException file read error
*/
@ -966,7 +948,7 @@ public class ElfHeader implements StructConverter, Writeable {
missing = true;
}
reader.setPointerIndex(index);
sectionHeaders[i] = ElfSectionHeader.createElfSectionHeader(reader, this);
sectionHeaders[i] = new ElfSectionHeader(reader, this);
}
//note: we cannot retrieve all the names
@ -992,7 +974,7 @@ public class ElfHeader implements StructConverter, Writeable {
missing = true;
}
reader.setPointerIndex(index);
programHeaders[i] = ElfProgramHeader.createElfProgramHeader(reader, this);
programHeaders[i] = new ElfProgramHeader(reader, this);
}
// TODO: Find sample file which requires this hack to verify its necessity
@ -1045,7 +1027,7 @@ public class ElfHeader implements StructConverter, Writeable {
private long getMinBase(long addr, long minBase) {
if (is32Bit()) {
addr &= Conv.INT_MASK;
addr = Integer.toUnsignedLong((int) addr);
}
if (Long.compareUnsigned(addr, minBase) < 0) {
minBase = addr;
@ -1079,7 +1061,7 @@ public class ElfHeader implements StructConverter, Writeable {
try {
int headerType = reader.peekNextInt();
if (headerType == ElfProgramHeaderConstants.PT_LOAD) {
ElfProgramHeader header = ElfProgramHeader.createElfProgramHeader(reader, this);
ElfProgramHeader header = new ElfProgramHeader(reader, this);
minBase = getMinBase(header.getVirtualAddress(), minBase);
}
}
@ -1418,7 +1400,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Returns the section headers with the specified type.
* The array could be zero-length, but will not be null.
* @param type
* @param type section type
* @return the section headers with the specified type
* @see ElfSectionHeader
*/
@ -1548,7 +1530,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Returns the program headers with the specified type.
* The array could be zero-length, but will not be null.
* @param type
* @param type program header type
* @return the program headers with the specified type
* @see ElfProgramHeader
*/
@ -1671,6 +1653,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Returns the string table associated to the specified section header.
* Or, null if one does not exist.
* @param section section whose associated string table is requested
* @return the string table associated to the specified section header
*/
public ElfStringTable getStringTable(ElfSectionHeader section) {
@ -1701,6 +1684,7 @@ public class ElfHeader implements StructConverter, Writeable {
/**
* Returns the symbol table associated to the specified section header.
* Or, null if one does not exist.
* @param symbolTableSection symbol table section header
* @return the symbol table associated to the specified section header
*/
public ElfSymbolTable getSymbolTable(ElfSectionHeader symbolTableSection) {

View File

@ -21,9 +21,11 @@ import java.util.HashMap;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.format.MemoryLoadable;
import ghidra.app.util.bin.format.Writeable;
import ghidra.program.model.data.*;
import ghidra.util.*;
import ghidra.util.DataConverter;
import ghidra.util.StringUtilities;
/**
* An executable or shared object file's program header table is an
@ -76,36 +78,22 @@ public class ElfProgramHeader
private long p_memsz;
private long p_align;
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
static ElfProgramHeader createElfProgramHeader(FactoryBundledWithBinaryReader reader,
ElfHeader header) throws IOException {
ElfProgramHeader elfProgramHeader =
(ElfProgramHeader) reader.getFactory().create(ElfProgramHeader.class);
elfProgramHeader.initElfProgramHeader(reader, header);
return elfProgramHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfProgramHeader() {
}
protected void initElfProgramHeader(FactoryBundledWithBinaryReader reader, ElfHeader header)
public ElfProgramHeader(BinaryReader reader, ElfHeader header)
throws IOException {
this.header = header;
this.reader = reader;
if (header.is32Bit()) {
p_type = reader.readNextInt();
p_offset = reader.readNextInt() & Conv.INT_MASK;
p_vaddr = reader.readNextInt() & Conv.INT_MASK;
p_paddr = reader.readNextInt() & Conv.INT_MASK;
p_filesz = reader.readNextInt() & Conv.INT_MASK;
p_memsz = reader.readNextInt() & Conv.INT_MASK;
p_offset = Integer.toUnsignedLong(reader.readNextInt());
p_vaddr = Integer.toUnsignedLong(reader.readNextInt());
p_paddr = Integer.toUnsignedLong(reader.readNextInt());
p_filesz = Integer.toUnsignedLong(reader.readNextInt());
p_memsz = Integer.toUnsignedLong(reader.readNextInt());
p_flags = reader.readNextInt();
p_align = reader.readNextInt() & Conv.INT_MASK;
p_align = Integer.toUnsignedLong(reader.readNextInt());
}
else if (header.is64Bit()) {
p_type = reader.readNextInt();
@ -130,6 +118,7 @@ public class ElfProgramHeader
/**
* Constructs a new program header with the specified type.
* @param header ELF header
* @param type the new type of the program header
*/
public ElfProgramHeader(ElfHeader header, int type) {

View File

@ -16,18 +16,15 @@
package ghidra.app.util.bin.format.elf;
import java.io.IOException;
import java.lang.reflect.Constructor;
import generic.continues.GenericFactory;
import ghidra.app.util.bin.ByteArrayConverter;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.elf.extend.ElfLoadAdapter;
import ghidra.app.util.bin.format.elf.relocation.ElfRelocationContext;
import ghidra.app.util.bin.format.elf.relocation.ElfRelocationHandler;
import ghidra.program.model.data.*;
import ghidra.util.Conv;
import ghidra.util.DataConverter;
import ghidra.util.exception.AssertException;
/**
* A class to represent the Elf32_Rel and Elf64_Rel data structure.
@ -70,6 +67,11 @@ import ghidra.util.exception.AssertException;
* relocation table which only specifies <i>r_offset</i> for each entry.
*
* </pre>
*
* NOTE: instantiation relies on the use of a default constructor which must be
* implemented by any extension. An extension should implement the methods
* {@link #initElfRelocation(BinaryReader, ElfHeader, int, boolean)} and/or
* {@link #initElfRelocation(ElfHeader, int, boolean, long, long, long)}.
*/
public class ElfRelocation implements ByteArrayConverter, StructConverter {
@ -88,20 +90,18 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
private int relocationIndex;
/**
* GenericFactory construction and initialization method for a ELF relocation entry
* Factory construction and initialization method for a ELF relocation entry
* @param reader binary reader positioned at start of relocation entry.
* @param elfHeader ELF header
* @param relocationIndex index of entry in relocation table
* @param withAddend true if if RELA entry with addend, else false
* @return ELF relocation object
* @throws IOException
* @throws IOException if an IO or parse error occurs
*/
static ElfRelocation createElfRelocation(FactoryBundledWithBinaryReader reader,
static ElfRelocation createElfRelocation(BinaryReader reader,
ElfHeader elfHeader, int relocationIndex, boolean withAddend) throws IOException {
Class<? extends ElfRelocation> elfRelocationClass = getElfRelocationClass(elfHeader);
ElfRelocation elfRelocation =
(ElfRelocation) reader.getFactory().create(elfRelocationClass);
Class<? extends ElfRelocation> elfRelocationClazz = getElfRelocationClass(elfHeader);
ElfRelocation elfRelocation = getInstance(elfRelocationClazz);
elfRelocation.initElfRelocation(reader, elfHeader, relocationIndex, withAddend);
return elfRelocation;
}
@ -109,7 +109,6 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
/**
* GenericFactory construction and initialization method for a ELF representative
* relocation entry
* @param reader binary reader positioned at start of relocation entry.
* @param elfHeader ELF header
* @param relocationIndex index of entry in relocation table
* @param withAddend true if if RELA entry with addend, else false
@ -117,23 +116,33 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
* @param r_info The info value for the entry
* @param r_addend The addend for the entry
* @return ELF relocation object
* @throws IOException if an IO or parse error occurs
*/
static ElfRelocation createElfRelocation(GenericFactory factory, ElfHeader elfHeader,
int relocationIndex, boolean withAddend, long r_offset, long r_info, long r_addend) {
Class<? extends ElfRelocation> elfRelocationClass = getElfRelocationClass(elfHeader);
ElfRelocation elfRelocation = (ElfRelocation) factory.create(elfRelocationClass);
try {
elfRelocation.initElfRelocation(elfHeader, relocationIndex, withAddend, r_offset,
r_info, r_addend);
}
catch (IOException e) {
// absence of reader should prevent any IOException from occurring
throw new AssertException("unexpected IO error", e);
}
static ElfRelocation createElfRelocation(ElfHeader elfHeader,
int relocationIndex, boolean withAddend, long r_offset, long r_info, long r_addend)
throws IOException {
Class<? extends ElfRelocation> elfRelocationClazz = getElfRelocationClass(elfHeader);
ElfRelocation elfRelocation = getInstance(elfRelocationClazz);
elfRelocation.initElfRelocation(elfHeader, relocationIndex, withAddend, r_offset, r_info,
r_addend);
return elfRelocation;
}
private static ElfRelocation getInstance(Class<? extends ElfRelocation> elfRelocationClazz)
throws IOException {
try {
Constructor<? extends ElfRelocation> constructor = elfRelocationClazz.getConstructor();
return constructor.newInstance();
}
catch (NoSuchMethodException e) {
throw new IOException(
elfRelocationClazz.getName() + " does not provide default constructor");
}
catch (Exception e) {
throw new IOException(e);
}
}
private static Class<? extends ElfRelocation> getElfRelocationClass(ElfHeader elfHeader) {
Class<? extends ElfRelocation> elfRelocationClass = null;
ElfLoadAdapter loadAdapter = elfHeader.getLoadAdapter();
@ -147,8 +156,11 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
* @see ElfRelocation#createElfRelocation
* Instantiate an uninitialized relocation object.
* <p>
* NOTE: This method is intended for use by the various factory methods which should generally
* be used when building-up a relocation table (see {@link #createElfRelocation(BinaryReader, ElfHeader, int, boolean)}
* and {@link #createElfRelocation(ElfHeader, int, boolean, long, long, long)}).
*/
public ElfRelocation() {
}
@ -160,9 +172,9 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
* @param elfHeader ELF header
* @param relocationTableIndex index of relocation within relocation table
* @param withAddend true if if RELA entry with addend, else false
* @throws IOException
* @throws IOException if an IO or parse error occurs
*/
protected void initElfRelocation(FactoryBundledWithBinaryReader reader, ElfHeader elfHeader,
protected void initElfRelocation(BinaryReader reader, ElfHeader elfHeader,
int relocationTableIndex, boolean withAddend) throws IOException {
this.is32bit = elfHeader.is32Bit();
this.relocationIndex = relocationTableIndex;
@ -180,7 +192,7 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
* @param r_offset The offset for the entry
* @param r_info The info value for the entry
* @param r_addend The addend for the entry
* @throws IOException
* @throws IOException if an IO or parse error occurs
*/
protected void initElfRelocation(ElfHeader elfHeader, int relocationTableIndex,
boolean withAddend, long r_offset, long r_info, long r_addend) throws IOException {
@ -189,10 +201,10 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
this.hasAddend = withAddend;
if (is32bit) {
this.r_offset = r_offset & Conv.INT_MASK;
this.r_info = r_info & Conv.INT_MASK;
this.r_offset = Integer.toUnsignedLong((int) r_offset);
this.r_info = Integer.toUnsignedLong((int) r_info);
if (hasAddend) {
this.r_addend = r_addend & Conv.INT_MASK;
this.r_addend = Integer.toUnsignedLong((int) r_addend);
}
}
else {
@ -204,12 +216,12 @@ public class ElfRelocation implements ByteArrayConverter, StructConverter {
}
}
private void readEntryData(FactoryBundledWithBinaryReader reader) throws IOException {
private void readEntryData(BinaryReader reader) throws IOException {
if (is32bit) {
this.r_offset = reader.readNextInt() & Conv.INT_MASK;
this.r_info = reader.readNextInt() & Conv.INT_MASK;
this.r_offset = Integer.toUnsignedLong(reader.readNextInt());
this.r_info = Integer.toUnsignedLong(reader.readNextInt());
if (hasAddend) {
r_addend = reader.readNextInt() & Conv.INT_MASK;
r_addend = Integer.toUnsignedLong(reader.readNextInt());
}
}
else {

View File

@ -19,9 +19,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import generic.continues.GenericFactory;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteArrayConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.dwarf4.LEB128;
import ghidra.program.model.data.ArrayDataType;
import ghidra.program.model.data.DataType;
@ -50,14 +49,14 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
private long entrySize;
private boolean addendTypeReloc;
private GenericFactory factory;
private ElfHeader elfHeader;
private ElfRelocation[] relocs;
/**
* Create an Elf Relocation Table
* @param reader
* Construct an Elf Relocation Table
* @param reader byte provider reader
* @param header elf header
* @param relocTableSection relocation table section header or null if associated with a dynamic table entry
* @param fileOffset relocation table file offset
@ -68,28 +67,9 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
* @param symbolTable associated symbol table
* @param sectionToBeRelocated or null for dynamic relocation table
* @param format table format
* @return Elf relocation table object
* @throws IOException
* @throws IOException if an IO or parse error occurs
*/
static ElfRelocationTable createElfRelocationTable(FactoryBundledWithBinaryReader reader,
ElfHeader header, ElfSectionHeader relocTableSection, long fileOffset, long addrOffset,
long length, long entrySize, boolean addendTypeReloc, ElfSymbolTable symbolTable,
ElfSectionHeader sectionToBeRelocated, TableFormat format) throws IOException {
ElfRelocationTable elfRelocationTable =
(ElfRelocationTable) reader.getFactory().create(ElfRelocationTable.class);
elfRelocationTable.initElfRelocationTable(reader, header, relocTableSection, fileOffset,
addrOffset, length, entrySize, addendTypeReloc, symbolTable, sectionToBeRelocated,
format);
return elfRelocationTable;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfRelocationTable() {
}
private void initElfRelocationTable(FactoryBundledWithBinaryReader reader, ElfHeader header,
public ElfRelocationTable(BinaryReader reader, ElfHeader header,
ElfSectionHeader relocTableSection, long fileOffset, long addrOffset, long length,
long entrySize, boolean addendTypeReloc, ElfSymbolTable symbolTable,
ElfSectionHeader sectionToBeRelocated, TableFormat format) throws IOException {
@ -101,7 +81,6 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
this.entrySize = entrySize;
this.addendTypeReloc = addendTypeReloc;
this.elfHeader = header;
this.factory = reader.getFactory();
this.format = format;
this.sectionToBeRelocated = sectionToBeRelocated;
@ -127,7 +106,7 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
relocList.toArray(relocs);
}
private List<ElfRelocation> parseStandardRelocations(FactoryBundledWithBinaryReader reader)
private List<ElfRelocation> parseStandardRelocations(BinaryReader reader)
throws IOException {
List<ElfRelocation> relocations = new ArrayList<>();
@ -142,23 +121,23 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
return relocations;
}
private long readNextRelrEntry(FactoryBundledWithBinaryReader reader) throws IOException {
private long readNextRelrEntry(BinaryReader reader) throws IOException {
return entrySize == 8 ? reader.readNextLong() : reader.readNextUnsignedInt();
}
private long addRelrEntry(long offset, List<ElfRelocation> relocList) {
relocList.add(ElfRelocation.createElfRelocation(factory, elfHeader, relocList.size(),
private long addRelrEntry(long offset, List<ElfRelocation> relocList) throws IOException {
relocList.add(ElfRelocation.createElfRelocation(elfHeader, relocList.size(),
addendTypeReloc, offset, 0, 0));
return offset + entrySize;
}
private long addRelrEntries(long baseOffset, long entry, List<ElfRelocation> relocList) {
private long addRelrEntries(long baseOffset, long entry, List<ElfRelocation> relocList)
throws IOException {
long offset = baseOffset;
while (entry != 0) {
entry >>>= 1;
if ((entry & 1) != 0) {
relocList.add(ElfRelocation.createElfRelocation(factory, elfHeader,
relocList.add(ElfRelocation.createElfRelocation(elfHeader,
relocList.size(), addendTypeReloc, offset, 0, 0));
}
offset += entrySize;
@ -167,7 +146,7 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
return baseOffset + (nBits * entrySize);
}
private List<ElfRelocation> parseRelrRelocations(FactoryBundledWithBinaryReader reader)
private List<ElfRelocation> parseRelrRelocations(BinaryReader reader)
throws IOException {
// NOTE: Current implementation supports an entrySize of 8 or 4. This could be
@ -193,7 +172,7 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
return relocList;
}
private List<ElfRelocation> parseAndroidRelocations(FactoryBundledWithBinaryReader reader)
private List<ElfRelocation> parseAndroidRelocations(BinaryReader reader)
throws IOException {
String identifier = reader.readNextAsciiString(4);
@ -258,8 +237,8 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
}
rAddend = addend;
}
relocations.add(ElfRelocation.createElfRelocation(reader.getFactory(),
elfHeader, relocationIndex++, addendTypeReloc, offset, info, rAddend));
relocations.add(ElfRelocation.createElfRelocation(elfHeader, relocationIndex++,
addendTypeReloc, offset, info, rAddend));
}
remainingRelocations -= groupSize;
@ -363,7 +342,7 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
}
@Override
public DataType toDataType() {
public DataType toDataType() throws IOException {
if (format == TableFormat.RELR) {
String relrStructureName = "Elf_RelrRelocationTable_" + Long.toHexString(addrOffset);
return new ElfRelrRelocationTableDataType(relrStructureName, (int) length,
@ -374,7 +353,7 @@ public class ElfRelocationTable implements ElfFileSection, ByteArrayConverter {
}
ElfRelocation relocationRepresentative =
ElfRelocation.createElfRelocation(factory, elfHeader, -1, addendTypeReloc, 0, 0, 0);
ElfRelocation.createElfRelocation(elfHeader, -1, addendTypeReloc, 0, 0, 0);
DataType relocEntryDataType = relocationRepresentative.toDataType();
return new ArrayDataType(relocEntryDataType, (int) (length / entrySize), (int) entrySize);
}

View File

@ -20,11 +20,13 @@ import java.util.HashMap;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.format.MemoryLoadable;
import ghidra.app.util.bin.format.Writeable;
import ghidra.program.model.data.*;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.util.*;
import ghidra.util.DataConverter;
import ghidra.util.StringUtilities;
/**
* A class to represent the Elf32_Shdr data structure.
@ -80,7 +82,7 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
private long sh_addralign;
private long sh_entsize;
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private ElfHeader header;
private String name;
@ -88,21 +90,7 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
private boolean modified = false;
private boolean bytesChanged = false;
static ElfSectionHeader createElfSectionHeader(FactoryBundledWithBinaryReader reader,
ElfHeader header) throws IOException {
ElfSectionHeader elfSectionHeader =
(ElfSectionHeader) reader.getFactory().create(ElfSectionHeader.class);
elfSectionHeader.initElfSectionHeader(reader, header);
return elfSectionHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfSectionHeader() {
}
private void initElfSectionHeader(FactoryBundledWithBinaryReader reader, ElfHeader header)
public ElfSectionHeader(BinaryReader reader, ElfHeader header)
throws IOException {
this.reader = reader;
this.header = header;
@ -111,10 +99,10 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
sh_type = reader.readNextInt();
if (header.is32Bit()) {
sh_flags = reader.readNextInt() & Conv.INT_MASK;
sh_addr = reader.readNextInt() & Conv.INT_MASK;
sh_offset = reader.readNextInt() & Conv.INT_MASK;
sh_size = reader.readNextInt() & Conv.INT_MASK;
sh_flags = Integer.toUnsignedLong(reader.readNextInt());
sh_addr = Integer.toUnsignedLong(reader.readNextInt());
sh_offset = Integer.toUnsignedLong(reader.readNextInt());
sh_size = Integer.toUnsignedLong(reader.readNextInt());
}
else if (header.is64Bit()) {
sh_flags = reader.readNextLong();
@ -127,8 +115,8 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
sh_info = reader.readNextInt();
if (header.is32Bit()) {
sh_addralign = reader.readNextInt() & Conv.INT_MASK;
sh_entsize = reader.readNextInt() & Conv.INT_MASK;
sh_addralign = Integer.toUnsignedLong(reader.readNextInt());
sh_entsize = Integer.toUnsignedLong(reader.readNextInt());
}
else if (header.is64Bit()) {
sh_addralign = reader.readNextLong();
@ -568,7 +556,7 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
/**
* Sets the name of this section (may get changed due to conflict)
* @param name
* @param name section name
*/
public void setName(String name) {
this.name = name;
@ -631,7 +619,7 @@ public class ElfSectionHeader implements StructConverter, Writeable, MemoryLoada
}
private void checkSize() {
if (sh_size > (Integer.MAX_VALUE & Conv.INT_MASK)) {
if (sh_size > Integer.toUnsignedLong(Integer.MAX_VALUE)) {
throw new UnsupportedOperationException(
"ELF Section is too large: 0x" + Long.toHexString(sh_size));
}

View File

@ -1,71 +0,0 @@
/* ###
* 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.elf;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
public class ElfString {
/**
* Read an ElfString at the readers current position. ElfString only supports
* null-terminated ASCII strings.
* @param reader reader positioned at start of string
* @param stringOffset string offset from start of string table
* @param header Elf header object
* @return Elf string object
* @throws IOException
*/
public static ElfString createElfString(FactoryBundledWithBinaryReader reader, int stringOffset,
ElfHeader header) throws IOException {
ElfString elfString = (ElfString) reader.getFactory().create(ElfString.class);
elfString.initElfString(reader, stringOffset, header);
return elfString;
}
private ElfHeader header;
private int stringOffset;
private String string;
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfString() {
}
private void initElfString(FactoryBundledWithBinaryReader reader, int stringOffset,
ElfHeader header) throws IOException {
this.header = header;
this.stringOffset = stringOffset;
this.string = reader.readAsciiString(0);
}
/**
* @return string object
*/
public String getString() {
return string;
}
/**
* @return string offset within string table
*/
public int getStringOffset() {
return stringOffset;
}
}

View File

@ -18,33 +18,11 @@ package ghidra.app.util.bin.format.elf;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.program.model.data.DataType;
import ghidra.util.exception.DuplicateNameException;
public class ElfStringTable implements ElfFileSection {
/**
* Create and parse an Elf string table
* @param reader the binary reader containing the elf string table
* @param header elf header
* @param stringTableSection string table section header or null if associated with a dynamic table entry
* @param fileOffset symbol table file offset
* @param addrOffset memory address of symbol table (should already be adjusted for prelink)
* @param length length of symbol table in bytes of -1 if unknown
* @return Elf string table object
* @throws IOException
*/
public static ElfStringTable createElfStringTable(FactoryBundledWithBinaryReader reader,
ElfHeader header, ElfSectionHeader stringTableSection, long fileOffset, long addrOffset,
long length) throws IOException {
ElfStringTable elfStringTable =
(ElfStringTable) reader.getFactory().create(ElfStringTable.class);
elfStringTable.initElfStringTable(reader, header, stringTableSection, fileOffset,
addrOffset, length);
return elfStringTable;
}
private ElfHeader header;
private ElfSectionHeader stringTableSection; // may be null
@ -52,15 +30,16 @@ public class ElfStringTable implements ElfFileSection {
private long addrOffset;
private long length;
// private LongObjectHashtable<String> stringOffsetMap;
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
* Construct and parse an Elf string table
* @param reader the binary reader containing the elf string table
* @param header elf header
* @param stringTableSection string table section header or null if associated with a dynamic table entry
* @param fileOffset symbol table file offset
* @param addrOffset memory address of symbol table (should already be adjusted for prelink)
* @param length length of symbol table in bytes of -1 if unknown
*/
public ElfStringTable() {
}
private void initElfStringTable(FactoryBundledWithBinaryReader reader, ElfHeader header,
public ElfStringTable(BinaryReader reader, ElfHeader header,
ElfSectionHeader stringTableSection, long fileOffset, long addrOffset, long length) {
this.header = header;
this.stringTableSection = stringTableSection;
@ -71,7 +50,7 @@ public class ElfStringTable implements ElfFileSection {
/**
* Read string from table at specified relative table offset
* @param reader
* @param reader byte reader
* @param stringOffset table relative string offset
* @return string or null on error
*/

View File

@ -17,9 +17,8 @@ package ghidra.app.util.bin.format.elf;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteArrayConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.util.Conv;
import ghidra.util.DataConverter;
import ghidra.util.exception.NotFoundException;
@ -104,33 +103,9 @@ public class ElfSymbol implements ByteArrayConverter {
private String nameAsString;
/**
* create an ElfSymbol()
* Creates a new section symbol.
* Warning! the routine initSymbolName() must be called on the symbol later
* to initialize the string name. This is a performance enhancement.
*
* @param reader to read symbol from
* @param symbolIndex index of the symbol to read
* @param symbolTable symbol table to associate the symbol to
* @param header else header
* @return newly created ElfSymbol
*
* @throws IOException if an issue with reading occurs
*/
public static ElfSymbol createElfSymbol(FactoryBundledWithBinaryReader reader, int symbolIndex,
ElfSymbolTable symbolTable, ElfHeader header) throws IOException {
ElfSymbol elfSymbol = (ElfSymbol) reader.getFactory().create(ElfSymbol.class);
elfSymbol.initElfSymbol(reader, symbolIndex, symbolTable, header);
return elfSymbol;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfSymbol() {
}
/**
* Creates a new section symbol.
* @param header the corresponding ELF header
* @param sectionAddress the start address of the section
* @param sectionHeaderIndex the index of the section in the section header table
@ -147,6 +122,8 @@ public class ElfSymbol implements ByteArrayConverter {
/**
* Creates a new global function symbol.
* Warning! the routine initSymbolName() must be called on the symbol later
* to initialize the string name. This is a performance enhancement.
* @param header the corresponding ELF header
* @param name the byte index of the name
* @param nameAsString the string name of the section
@ -178,7 +155,17 @@ public class ElfSymbol implements ByteArrayConverter {
this.symbolTableIndex = symbolIndex;
}
private void initElfSymbol(FactoryBundledWithBinaryReader reader, int symbolIndex,
/**
* Construct a normal ElfSymbol.
* Warning! the routine initSymbolName() must be called on the symbol later
* to initialize the string name. This is a performance enhancement.
* @param reader to read symbol from
* @param symbolIndex index of the symbol to read
* @param symbolTable symbol table to associate the symbol to
* @param header else header
* @throws IOException if an issue with reading occurs
*/
public ElfSymbol(BinaryReader reader, int symbolIndex,
ElfSymbolTable symbolTable, ElfHeader header) throws IOException {
this.header = header;
this.symbolTable = symbolTable;
@ -186,8 +173,8 @@ public class ElfSymbol implements ByteArrayConverter {
if (header.is32Bit()) {
st_name = reader.readNextInt();
st_value = reader.readNextInt() & Conv.INT_MASK;
st_size = reader.readNextInt() & Conv.INT_MASK;
st_value = Integer.toUnsignedLong(reader.readNextInt());
st_size = Integer.toUnsignedLong(reader.readNextInt());
st_info = reader.readNextByte();
st_other = reader.readNextByte();
st_shndx = reader.readNextShort();
@ -235,7 +222,7 @@ public class ElfSymbol implements ByteArrayConverter {
* @param reader to read from
* @param stringTable stringTable to initialize symbol name
*/
public void initSymbolName(FactoryBundledWithBinaryReader reader, ElfStringTable stringTable) {
public void initSymbolName(BinaryReader reader, ElfStringTable stringTable) {
if (nameAsString == null) {
nameAsString = stringTable.readString(reader, st_name);
}

View File

@ -20,8 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteArrayConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.program.model.data.*;
import ghidra.util.DataConverter;
import ghidra.util.exception.DuplicateNameException;
@ -46,8 +46,8 @@ public class ElfSymbolTable implements ElfFileSection, ByteArrayConverter {
private ElfSymbol[] symbols;
/**
* Create and parse an Elf symbol table
* @param reader
* Construct and parse an Elf symbol table
* @param reader byte reader
* @param header elf header
* @param symbolTableSection string table section header or null if associated with a dynamic table entry
* @param fileOffset symbol table file offset
@ -56,27 +56,9 @@ public class ElfSymbolTable implements ElfFileSection, ByteArrayConverter {
* @param entrySize size of each symbol entry in bytes
* @param stringTable associated string table
* @param isDynamic true if symbol table is the dynamic symbol table
* @return Elf symbol table object
* @throws IOException
* @throws IOException if an IO or parse error occurs
*/
static ElfSymbolTable createElfSymbolTable(FactoryBundledWithBinaryReader reader,
ElfHeader header, ElfSectionHeader symbolTableSection, long fileOffset, long addrOffset,
long length, long entrySize, ElfStringTable stringTable, boolean isDynamic)
throws IOException {
ElfSymbolTable elfSymbolTable =
(ElfSymbolTable) reader.getFactory().create(ElfSymbolTable.class);
elfSymbolTable.initElfSymbolTable(reader, header, symbolTableSection, fileOffset,
addrOffset, length, entrySize, stringTable, isDynamic);
return elfSymbolTable;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ElfSymbolTable() {
}
private void initElfSymbolTable(FactoryBundledWithBinaryReader reader, ElfHeader header,
public ElfSymbolTable(BinaryReader reader, ElfHeader header,
ElfSectionHeader symbolTableSection, long fileOffset, long addrOffset, long length,
long entrySize, ElfStringTable stringTable, boolean isDynamic) throws IOException {
@ -103,7 +85,7 @@ public class ElfSymbolTable implements ElfFileSection, ByteArrayConverter {
// Reposition reader to start of symbol element since ElfSymbol object
// may not consume all symbol element data
reader.setPointerIndex(entryPos);
ElfSymbol sym = ElfSymbol.createElfSymbol(reader, i, this, header);
ElfSymbol sym = new ElfSymbol(reader, i, this, header);
symbolList.add(sym);
entryPos += entrySize;
}

View File

@ -19,9 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import generic.continues.GenericFactory;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.commands.*;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -44,7 +42,7 @@ public class MachHeader implements StructConverter {
private boolean _is32bit;
private List<LoadCommand> _commands = new ArrayList<>();
private long _commandIndex;
private FactoryBundledWithBinaryReader _reader;
private BinaryReader _reader;
private long _machHeaderStartIndexInProvider;
private long _machHeaderStartIndex = 0;
private boolean _parsed = false;
@ -65,58 +63,49 @@ public class MachHeader implements StructConverter {
}
return false;
}
/**
* Assumes the MachHeader starts at index 0 in the ByteProvider.
* Creates a new {@link MachHeader}. Assumes the MachHeader starts at index 0 in the
* ByteProvider.
*
* @param provider the ByteProvider
* @throws IOException if an I/O error occurs while reading from the ByteProvider
* @throws MachException if an invalid MachHeader is detected
*/
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider)
throws IOException, MachException {
return createMachHeader(factory, provider, 0);
public MachHeader(ByteProvider provider) throws IOException, MachException {
this(provider, 0);
}
/**
* Assumes the MachHeader starts at index <i>machHeaderStartIndexInProvider</i> in the ByteProvider.
* Creates a new {@link MachHeader}. Assumes the MachHeader starts at index
* <i>machHeaderStartIndexInProvider</i> in the ByteProvider.
*
* @param provider the ByteProvider
* @param machHeaderStartIndexInProvider the index into the ByteProvider where the MachHeader begins.
* @param machHeaderStartIndexInProvider the index into the ByteProvider where the MachHeader
* begins
* @throws IOException if an I/O error occurs while reading from the ByteProvider
* @throws MachException if an invalid MachHeader is detected
*/
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider,
long machHeaderStartIndexInProvider) throws IOException, MachException {
MachHeader machHeader = (MachHeader) factory.create(MachHeader.class);
machHeader.initMachHeader(factory, provider, machHeaderStartIndexInProvider, true);
return machHeader;
public MachHeader(ByteProvider provider, long machHeaderStartIndexInProvider)
throws IOException, MachException {
this(provider, machHeaderStartIndexInProvider, true);
}
/**
* Assumes the MachHeader starts at index <i>machHeaderStartIndexInProvider</i> in the ByteProvider.
* Creatse a new {@link MachHeader}. Assumes the MachHeader starts at index
* <i>machHeaderStartIndexInProvider</i> in the ByteProvider.
*
* @param provider the ByteProvider
* @param machHeaderStartIndexInProvider the index into the ByteProvider where the MachHeader begins.
* @param isRemainingMachoRelativeToStartIndex TRUE if the rest of the macho uses relative indexing. This is common in UBI and kernel cache files.
* FALSE if the rest of the file uses absolute indexing from 0. This is common in DYLD cache files.
* @param machHeaderStartIndexInProvider the index into the ByteProvider where the MachHeader
* begins.
* @param isRemainingMachoRelativeToStartIndex true if the rest of the macho uses relative
* indexin (this is common in UBI and kernel cache files); otherwise, false if the rest of the
* file uses absolute indexing from 0 (this is common in DYLD cache files)
* @throws IOException if an I/O error occurs while reading from the ByteProvider
* @throws MachException if an invalid MachHeader is detected
*/
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider,
long machHeaderStartIndexInProvider, boolean isRemainingMachoRelativeToStartIndex)
throws IOException, MachException {
MachHeader machHeader = (MachHeader) factory.create(MachHeader.class);
machHeader.initMachHeader(factory, provider, machHeaderStartIndexInProvider,
isRemainingMachoRelativeToStartIndex);
return machHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public MachHeader() {
}
private void initMachHeader(GenericFactory factory, ByteProvider provider,
long machHeaderStartIndexInProvider, boolean isRemainingMachoRelativeToStartIndex)
throws IOException, MachException {
public MachHeader(ByteProvider provider, long machHeaderStartIndexInProvider,
boolean isRemainingMachoRelativeToStartIndex) throws IOException, MachException {
magic = readMagic(provider, machHeaderStartIndexInProvider);
if (!MachConstants.isMagic(magic)) {
@ -128,7 +117,7 @@ public class MachHeader implements StructConverter {
}
_machHeaderStartIndexInProvider = machHeaderStartIndexInProvider;
_reader = new FactoryBundledWithBinaryReader(factory, provider, isLittleEndian());
_reader = new BinaryReader(provider, isLittleEndian());
_reader.setPointerIndex(machHeaderStartIndexInProvider + 4);//skip magic number...
cpuType = _reader.readNextInt();
@ -219,13 +208,17 @@ public class MachHeader implements StructConverter {
* Returns the start index that should be used for calculating offsets.
* This will be 0 for things such as the dyld shared cache where offsets are
* based off the beginning of the file.
*
* @return the start index that should be used for calculating offsets
*/
public long getStartIndex() {
return _machHeaderStartIndex;
}
/**
* Returns offset of MachHeader in the ByteProvider
* Returns the offset of the MachHeader in the ByteProvider
*
* @return the offset of the MachHeader in the ByteProvider
*/
public long getStartIndexInProvider() {
return _machHeaderStartIndexInProvider;

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -72,19 +72,7 @@ public class RelocationInfo implements StructConverter {
*/
private int r_type;
public static RelocationInfo createRelocationInfo(FactoryBundledWithBinaryReader reader)
throws IOException {
RelocationInfo relocationInfo =
(RelocationInfo) reader.getFactory().create(RelocationInfo.class);
relocationInfo.initRelocationInfo(reader);
return relocationInfo;
}
public RelocationInfo() {
}
private void initRelocationInfo(FactoryBundledWithBinaryReader reader) throws IOException {
public RelocationInfo(BinaryReader reader) throws IOException {
int i1 = reader.readNextInt();
int i2 = reader.readNextInt();

View File

@ -20,8 +20,8 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.commands.SegmentNames;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -46,25 +46,11 @@ public class Section implements StructConverter {
private int reserved2;
private int reserved3;//only used for 64 bit
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private boolean is32bit;
private List<RelocationInfo> relocations = new ArrayList<>();
public static Section createSection(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
Section section = (Section) reader.getFactory().create(Section.class);
section.initSection(reader, is32bit);
return section;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public Section() {
}
private void initSection(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
public Section(BinaryReader reader, boolean is32bit) throws IOException {
this.reader = reader;
this.is32bit = is32bit;
@ -93,7 +79,7 @@ public class Section implements StructConverter {
long index = reader.getPointerIndex();
reader.setPointerIndex(reloff);
for (int i = 0; i < nrelocs; ++i) {
relocations.add(RelocationInfo.createRelocationInfo(reader));
relocations.add(new RelocationInfo(reader));
}
reader.setPointerIndex(index);
}

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -42,22 +42,7 @@ public class BuildVersionCommand extends LoadCommand {
private int ntools;
private BuildToolVersion[] buildToolVersions;
static BuildVersionCommand createBuildVersionCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
BuildVersionCommand command =
(BuildVersionCommand) reader.getFactory().create(BuildVersionCommand.class);
command.initEntryPointCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public BuildVersionCommand() {
}
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException {
BuildVersionCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
platform = reader.readNextInt();

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -41,22 +41,7 @@ public class DyldChainedFixupHeader implements StructConverter {
DyldChainedStartsInImage chainedStartsInImage;
DyldChainedImports chainedImports;
static DyldChainedFixupHeader createDyldChainedFixupHeader(
FactoryBundledWithBinaryReader reader) throws IOException {
DyldChainedFixupHeader dyldChainedFixupHeader =
(DyldChainedFixupHeader) reader.getFactory().create(DyldChainedFixupHeader.class);
dyldChainedFixupHeader.initDyldChainedFixupHeader(reader);
return dyldChainedFixupHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedFixupHeader() {
}
private void initDyldChainedFixupHeader(FactoryBundledWithBinaryReader reader)
throws IOException {
DyldChainedFixupHeader(BinaryReader reader) throws IOException {
long ptrIndex = reader.getPointerIndex();
fixups_version = reader.readNextInt();
@ -68,10 +53,10 @@ public class DyldChainedFixupHeader implements StructConverter {
symbols_format = reader.readNextInt();
reader.setPointerIndex(ptrIndex + starts_offset);
chainedStartsInImage = DyldChainedStartsInImage.createDyldChainedStartsInImage(reader);
chainedStartsInImage = new DyldChainedStartsInImage(reader);
reader.setPointerIndex(ptrIndex + imports_offset);
chainedImports = DyldChainedImports.createDyldChainedImports(reader, this);
chainedImports = new DyldChainedImports(reader, this);
reader.setPointerIndex(ptrIndex + symbols_offset);
chainedImports.initSymbols(reader, this);

View File

@ -18,7 +18,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import java.util.List;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
@ -38,24 +38,13 @@ public class DyldChainedFixupsCommand extends LinkEditDataCommand {
private DyldChainedFixupHeader chainHeader;
static LinkEditDataCommand createDyldChainedFixupsCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
DyldChainedFixupsCommand command =
(DyldChainedFixupsCommand) reader.getFactory().create(DyldChainedFixupsCommand.class);
command.initLinkEditDataCommand(reader);
DyldChainedFixupsCommand(BinaryReader reader) throws IOException {
super(reader);
long ptrIndex = reader.getPointerIndex();
reader.setPointerIndex(command.getDataOffset());
command.chainHeader = DyldChainedFixupHeader.createDyldChainedFixupHeader(reader);
reader.setPointerIndex(getDataOffset());
chainHeader = new DyldChainedFixupHeader(reader);
reader.setPointerIndex(ptrIndex);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedFixupsCommand() {
}
@Override

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -40,25 +40,10 @@ public class DyldChainedImport implements StructConverter {
private long addend;
private String symbolName;
static DyldChainedImport createDyldChainedImport(FactoryBundledWithBinaryReader reader,
DyldChainedFixupHeader cfh, int imports_format) throws IOException {
DyldChainedImport dyldChainedImport =
(DyldChainedImport) reader.getFactory().create(DyldChainedImport.class);
dyldChainedImport.initDyldChainedImport(reader, cfh, imports_format);
return dyldChainedImport;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedImport() {
}
private void initDyldChainedImport(FactoryBundledWithBinaryReader reader,
DyldChainedFixupHeader cfh, int format) throws IOException {
this.imports_format = format;
switch (format) {
DyldChainedImport(BinaryReader reader, DyldChainedFixupHeader cfh, int imports_format)
throws IOException {
this.imports_format = imports_format;
switch (imports_format) {
case DYLD_CHAINED_IMPORT: {
int ival = reader.readNextInt();
lib_ordinal = ival & 0xff;
@ -83,7 +68,7 @@ public class DyldChainedImport implements StructConverter {
break;
}
default:
throw new IOException("Bad Chained import format: " + format);
throw new IOException("Bad Chained import format: " + imports_format);
}
}
@ -142,7 +127,7 @@ public class DyldChainedImport implements StructConverter {
return symbolName;
}
public void initString(FactoryBundledWithBinaryReader reader) throws IOException {
public void initString(BinaryReader reader) throws IOException {
symbolName = reader.readNextNullTerminatedAsciiString();
}

View File

@ -18,8 +18,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.program.model.data.ArrayDataType;
import ghidra.program.model.data.DataType;
import ghidra.util.exception.DuplicateNameException;
@ -36,23 +36,7 @@ public class DyldChainedImports implements StructConverter {
private long imports_offset;
private DyldChainedImport chainedImports[];
static DyldChainedImports createDyldChainedImports(FactoryBundledWithBinaryReader reader,
DyldChainedFixupHeader cfh) throws IOException {
DyldChainedImports dyldChainedImports =
(DyldChainedImports) reader.getFactory().create(DyldChainedImports.class);
dyldChainedImports.initDyldChainedStartsInImage(reader, cfh);
return dyldChainedImports;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedImports() {
}
private void initDyldChainedStartsInImage(FactoryBundledWithBinaryReader reader,
DyldChainedFixupHeader cfh) throws IOException {
DyldChainedImports(BinaryReader reader, DyldChainedFixupHeader cfh) throws IOException {
long ptrIndex = reader.getPointerIndex();
imports_offset = ptrIndex;
@ -61,7 +45,7 @@ public class DyldChainedImports implements StructConverter {
ArrayList<DyldChainedImport> starts = new ArrayList<>();
for (int i = 0; i < imports_count; i++) {
starts.add(DyldChainedImport.createDyldChainedImport(reader, cfh, imports_format));
starts.add(new DyldChainedImport(reader, cfh, imports_format));
}
chainedImports = starts.toArray(DyldChainedImport[]::new);
}
@ -94,8 +78,8 @@ public class DyldChainedImports implements StructConverter {
return chainedImports[ordinal];
}
public void initSymbols(FactoryBundledWithBinaryReader reader,
DyldChainedFixupHeader dyldChainedFixupHeader) throws IOException {
public void initSymbols(BinaryReader reader, DyldChainedFixupHeader dyldChainedFixupHeader)
throws IOException {
long ptrIndex = reader.getPointerIndex();
for (DyldChainedImport dyldChainedImport : chainedImports) {

View File

@ -18,8 +18,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -36,22 +36,7 @@ public class DyldChainedStartsInImage implements StructConverter {
private DyldChainedStartsInSegment chainedStarts[];
static DyldChainedStartsInImage createDyldChainedStartsInImage(
FactoryBundledWithBinaryReader reader) throws IOException {
DyldChainedStartsInImage dyldChainedStartsInImage =
(DyldChainedStartsInImage) reader.getFactory().create(DyldChainedStartsInImage.class);
dyldChainedStartsInImage.initDyldChainedStartsInImage(reader);
return dyldChainedStartsInImage;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedStartsInImage() {
}
private void initDyldChainedStartsInImage(FactoryBundledWithBinaryReader reader)
throws IOException {
DyldChainedStartsInImage(BinaryReader reader) throws IOException {
long ptrIndex = reader.getPointerIndex();
@ -62,7 +47,7 @@ public class DyldChainedStartsInImage implements StructConverter {
for (int off : seg_info_offset) {
reader.setPointerIndex(ptrIndex + off);
starts.add(DyldChainedStartsInSegment.createDyldChainedFixupHeader(reader));
starts.add(new DyldChainedStartsInSegment(reader));
}
chainedStarts = starts.toArray(DyldChainedStartsInSegment[]::new);
}

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -39,23 +39,7 @@ public class DyldChainedStartsInSegment implements StructConverter {
private short page_starts[]; // each entry is offset in each page of first element in chain
private short chain_starts[]; // TODO: used for some 32-bit formats with multiple starts per page
static DyldChainedStartsInSegment createDyldChainedFixupHeader(
FactoryBundledWithBinaryReader reader) throws IOException {
DyldChainedStartsInSegment dyldChainedFixupHeader =
(DyldChainedStartsInSegment) reader.getFactory().create(
DyldChainedStartsInSegment.class);
dyldChainedFixupHeader.initDyldChainedStartsInSegment(reader);
return dyldChainedFixupHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldChainedStartsInSegment() {
}
private void initDyldChainedStartsInSegment(FactoryBundledWithBinaryReader reader)
throws IOException {
DyldChainedStartsInSegment(BinaryReader reader) throws IOException {
size = reader.readNextInt();
page_size = reader.readNextShort();
pointer_format = reader.readNextShort();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -45,21 +45,7 @@ public class DyldInfoCommand extends LoadCommand {
private int export_off;
private int export_size;
static DyldInfoCommand createDyldInfoCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
DyldInfoCommand command =
(DyldInfoCommand) reader.getFactory().create(DyldInfoCommand.class);
command.initDyldInfoCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DyldInfoCommand() {
}
private void initDyldInfoCommand(FactoryBundledWithBinaryReader reader) throws IOException {
DyldInfoCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
rebase_off = reader.readNextInt();

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -34,23 +34,8 @@ public class DynamicLibrary implements StructConverter {
private int current_version;
private int compatibility_version;
public static DynamicLibrary createDynamicLibrary(FactoryBundledWithBinaryReader reader,
LoadCommand command) throws IOException {
DynamicLibrary dynamicLibrary =
(DynamicLibrary) reader.getFactory().create(DynamicLibrary.class);
dynamicLibrary.initDynamicLibrary(reader, command);
return dynamicLibrary;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicLibrary() {
}
private void initDynamicLibrary(FactoryBundledWithBinaryReader reader, LoadCommand command)
throws IOException {
name = LoadCommandString.createLoadCommandString(reader, command);
public DynamicLibrary(BinaryReader reader, LoadCommand command) throws IOException {
name = new LoadCommandString(reader, command);
timestamp = reader.readNextInt();
current_version = reader.readNextInt();
compatibility_version = reader.readNextInt();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,24 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class DynamicLibraryCommand extends LoadCommand {
private DynamicLibrary dylib;
static DynamicLibraryCommand createDynamicLibraryCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
DynamicLibraryCommand dynamicLibraryCommand =
(DynamicLibraryCommand) reader.getFactory().create(DynamicLibraryCommand.class);
dynamicLibraryCommand.initDynamicLibraryCommand(reader);
return dynamicLibraryCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicLibraryCommand() {
}
private void initDynamicLibraryCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
DynamicLibraryCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
dylib = DynamicLibrary.createDynamicLibrary(reader, this);
dylib = new DynamicLibrary(reader, this);
}
/**

View File

@ -15,13 +15,14 @@
*/
package ghidra.app.util.bin.format.macho.commands;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.format.macho.*;
import ghidra.program.model.data.*;
import ghidra.util.exception.*;
import java.io.IOException;
import java.io.*;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
public class DynamicLibraryModule implements StructConverter {
private int module_name; // the module name (index into string table)
@ -41,20 +42,7 @@ public class DynamicLibraryModule implements StructConverter {
private boolean is32bit;
private String moduleName;
public static DynamicLibraryModule createDynamicLibraryModule(
FactoryBundledWithBinaryReader reader, MachHeader header)
throws IOException {
DynamicLibraryModule dynamicLibraryModule = (DynamicLibraryModule) reader.getFactory().create(DynamicLibraryModule.class);
dynamicLibraryModule.initDynamicLibraryModule(reader, header);
return dynamicLibraryModule;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicLibraryModule() {}
private void initDynamicLibraryModule(FactoryBundledWithBinaryReader reader, MachHeader header) throws IOException {
public DynamicLibraryModule(BinaryReader reader, MachHeader header) throws IOException {
this.is32bit = header.is32bit();
module_name = reader.readNextInt();

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -32,22 +32,7 @@ public class DynamicLibraryReference implements StructConverter {
private int isym;
private int flags;
static DynamicLibraryReference createDynamicLibraryReference(
FactoryBundledWithBinaryReader reader) throws IOException {
DynamicLibraryReference dynamicLibraryReference =
(DynamicLibraryReference) reader.getFactory().create(DynamicLibraryReference.class);
dynamicLibraryReference.initDynamicLibraryReference(reader);
return dynamicLibraryReference;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicLibraryReference() {
}
private void initDynamicLibraryReference(FactoryBundledWithBinaryReader reader)
throws IOException {
DynamicLibraryReference(BinaryReader reader) throws IOException {
int value = reader.readNextInt();
if (reader.isLittleEndian()) {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,24 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class DynamicLinkerCommand extends LoadCommand {
private LoadCommandString name;
public static DynamicLinkerCommand createDynamicLinkerCommand(
FactoryBundledWithBinaryReader reader) throws IOException {
DynamicLinkerCommand dynamicLinkerCommand =
(DynamicLinkerCommand) reader.getFactory().create(DynamicLinkerCommand.class);
dynamicLinkerCommand.initDynamicLinkerCommand(reader);
return dynamicLinkerCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicLinkerCommand() {
}
private void initDynamicLinkerCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
public DynamicLinkerCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
name = LoadCommandString.createLoadCommandString(reader, this);
name = new LoadCommandString(reader, this);
}
public LoadCommandString getLoadCommandString() {

View File

@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
@ -65,22 +65,7 @@ public class DynamicSymbolTableCommand extends LoadCommand {
private List<RelocationInfo> externalRelocations = new ArrayList<RelocationInfo>();
private List<RelocationInfo> localRelocations = new ArrayList<RelocationInfo>();
static DynamicSymbolTableCommand createDynamicSymbolTableCommand(
FactoryBundledWithBinaryReader reader, MachHeader header) throws IOException {
DynamicSymbolTableCommand command =
(DynamicSymbolTableCommand) reader.getFactory().create(DynamicSymbolTableCommand.class);
command.initDynamicSymbolTableCommand(reader, header);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DynamicSymbolTableCommand() {
}
private void initDynamicSymbolTableCommand(FactoryBundledWithBinaryReader reader,
MachHeader header) throws IOException {
DynamicSymbolTableCommand(BinaryReader reader, MachHeader header) throws IOException {
initLoadCommand(reader);
ilocalsym = reader.readNextInt();
@ -107,19 +92,19 @@ public class DynamicSymbolTableCommand extends LoadCommand {
if (tocoff > 0) {
reader.setPointerIndex(header.getStartIndex() + tocoff);
for (int i = 0; i < ntoc; ++i) {
tocList.add(TableOfContents.createTableOfContents(reader));
tocList.add(new TableOfContents(reader));
}
}
if (modtaboff > 0) {
reader.setPointerIndex(header.getStartIndex() + modtaboff);
for (int i = 0; i < nmodtab; ++i) {
moduleList.add(DynamicLibraryModule.createDynamicLibraryModule(reader, header));
moduleList.add(new DynamicLibraryModule(reader, header));
}
}
if (extrefsymoff > 0) {
reader.setPointerIndex(header.getStartIndex() + extrefsymoff);
for (int i = 0; i < nextrefsyms; ++i) {
referencedList.add(DynamicLibraryReference.createDynamicLibraryReference(reader));
referencedList.add(new DynamicLibraryReference(reader));
}
}
if (indirectsymoff > 0) {
@ -132,13 +117,13 @@ public class DynamicSymbolTableCommand extends LoadCommand {
if (extreloff > 0) {
reader.setPointerIndex(header.getStartIndex() + extreloff);
for (int i = 0; i < nextrel; ++i) {
externalRelocations.add(RelocationInfo.createRelocationInfo(reader));
externalRelocations.add(new RelocationInfo(reader));
}
}
if (locreloff > 0) {
reader.setPointerIndex(header.getStartIndex() + locreloff);
for (int i = 0; i < nlocrel; ++i) {
localRelocations.add(RelocationInfo.createRelocationInfo(reader));
localRelocations.add(new RelocationInfo(reader));
}
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -40,26 +40,10 @@ public class EncryptedInformationCommand extends LoadCommand {
private boolean is32bit;
static EncryptedInformationCommand createEncryptedInformationCommand(
FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException {
EncryptedInformationCommand command =
(EncryptedInformationCommand) reader.getFactory().create(
EncryptedInformationCommand.class);
command.initEncryptedInformationCommand(reader, is32bit);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public EncryptedInformationCommand() {
}
private void initEncryptedInformationCommand(FactoryBundledWithBinaryReader reader,
boolean is32bit) throws IOException {
EncryptedInformationCommand(BinaryReader reader, boolean is32bit) throws IOException {
initLoadCommand(reader);
this.is32bit = is32bit;
cryptoff = reader.readNextInt();
cryptsize = reader.readNextInt();
cryptid = reader.readNextInt();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -37,22 +37,7 @@ public class EntryPointCommand extends LoadCommand {
private long entryOffset;
private long stackSize;
static EntryPointCommand createEntryPointCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
EntryPointCommand command =
(EntryPointCommand) reader.getFactory().create(EntryPointCommand.class);
command.initEntryPointCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public EntryPointCommand() {
}
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException {
EntryPointCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
entryOffset = reader.readNextLong();
stackSize = reader.readNextLong();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -42,22 +42,7 @@ public class FileSetEntryCommand extends LoadCommand {
boolean is32bit;
public static FileSetEntryCommand createFileSetEntryCommand(
FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException {
FileSetEntryCommand filesetEntryCommand =
(FileSetEntryCommand) reader.getFactory().create(FileSetEntryCommand.class);
filesetEntryCommand.initFileSetEntryCommand(reader, is32bit);
return filesetEntryCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public FileSetEntryCommand() {
}
private void initFileSetEntryCommand(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
public FileSetEntryCommand(BinaryReader reader, boolean is32bit) throws IOException {
initLoadCommand(reader);
this.is32bit = is32bit;

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -37,23 +37,7 @@ public class FixedVirtualMemoryFileCommand extends LoadCommand {
private LoadCommandString name;
private int header_addr;
public static FixedVirtualMemoryFileCommand createFixedVirtualMemoryFileCommand(
FactoryBundledWithBinaryReader reader) throws IOException {
FixedVirtualMemoryFileCommand command =
(FixedVirtualMemoryFileCommand) reader.getFactory().create(
FixedVirtualMemoryFileCommand.class);
command.initFixedVirtualMemoryFileCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public FixedVirtualMemoryFileCommand() {
}
private void initFixedVirtualMemoryFileCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
public FixedVirtualMemoryFileCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachException;
/**
@ -27,24 +27,8 @@ import ghidra.app.util.bin.format.macho.MachException;
*/
public class FixedVirtualMemorySharedLibraryCommand extends ObsoleteCommand {
static FixedVirtualMemorySharedLibraryCommand createFixedVirtualMemorySharedLibraryCommand(
FactoryBundledWithBinaryReader reader) throws IOException, MachException {
FixedVirtualMemorySharedLibraryCommand command =
(FixedVirtualMemorySharedLibraryCommand) reader.getFactory().create(
FixedVirtualMemorySharedLibraryCommand.class);
command.initFixedVirtualMemorySharedLibraryCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public FixedVirtualMemorySharedLibraryCommand() {
}
private void initFixedVirtualMemorySharedLibraryCommand(FactoryBundledWithBinaryReader reader)
throws IOException, MachException {
initObsoleteCommand(reader);
FixedVirtualMemorySharedLibraryCommand(BinaryReader reader) throws IOException, MachException {
super(reader);
}
@Override

View File

@ -21,7 +21,6 @@ import java.util.List;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.dwarf4.LEB128;
import ghidra.program.model.address.Address;
@ -32,18 +31,8 @@ import ghidra.program.model.address.Address;
*/
public class FunctionStartsCommand extends LinkEditDataCommand {
static FunctionStartsCommand createFunctionStartsCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
FunctionStartsCommand command =
(FunctionStartsCommand) reader.getFactory().create(FunctionStartsCommand.class);
command.initLinkEditDataCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public FunctionStartsCommand() {
FunctionStartsCommand(BinaryReader reader) throws IOException {
super(reader);
}
/**

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachException;
/**
@ -27,22 +27,8 @@ import ghidra.app.util.bin.format.macho.MachException;
*/
public class IdentCommand extends ObsoleteCommand {
static IdentCommand createIdentCommand(FactoryBundledWithBinaryReader reader)
throws IOException, MachException {
IdentCommand identCommand = (IdentCommand) reader.getFactory().create(IdentCommand.class);
identCommand.initIdentCommand(reader);
return identCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public IdentCommand() {
}
private void initIdentCommand(FactoryBundledWithBinaryReader reader)
throws IOException, MachException {
initObsoleteCommand(reader);
IdentCommand(BinaryReader reader) throws IOException, MachException {
super(reader);
}
@Override

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -37,22 +37,7 @@ public class LinkEditDataCommand extends LoadCommand {
private int dataoff;
private int datasize;
static LinkEditDataCommand createLinkEditDataCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
LinkEditDataCommand command =
(LinkEditDataCommand) reader.getFactory().create(LinkEditDataCommand.class);
command.initLinkEditDataCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public LinkEditDataCommand() {
}
protected void initLinkEditDataCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
LinkEditDataCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
dataoff = reader.readNextInt();
datasize = reader.readNextInt();

View File

@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
@ -40,22 +40,7 @@ public class LinkerOptionCommand extends LoadCommand {
private int count;
private List<String> linkerOptions;
static LinkerOptionCommand createLinkerOptionCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
LinkerOptionCommand command =
(LinkerOptionCommand) reader.getFactory().create(LinkerOptionCommand.class);
command.initLinkerOptionCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public LinkerOptionCommand() {
}
private void initLinkerOptionCommand(FactoryBundledWithBinaryReader reader) throws IOException {
LinkerOptionCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
count = reader.readNextInt();
linkerOptions = new ArrayList<>(count);

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
@ -37,10 +37,7 @@ public abstract class LoadCommand implements StructConverter {
private int cmd;
private int cmdsize;
public LoadCommand() {
}
protected void initLoadCommand(FactoryBundledWithBinaryReader reader) throws IOException {
protected void initLoadCommand(BinaryReader reader) throws IOException {
startIndex = reader.getPointerIndex();
cmd = reader.readNextInt();
cmdsize = reader.readNextInt();

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -32,23 +32,7 @@ public class LoadCommandString implements StructConverter {
private int offset;
private String string;
static LoadCommandString createLoadCommandString(FactoryBundledWithBinaryReader reader,
LoadCommand command) throws IOException {
LoadCommandString loadCommandString =
(LoadCommandString) reader.getFactory().create(LoadCommandString.class);
loadCommandString.initLoadCommandString(reader, command);
return loadCommandString;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY
* METHODS INSTEAD.
*/
public LoadCommandString() {
}
private void initLoadCommandString(FactoryBundledWithBinaryReader reader, LoadCommand command)
throws IOException {
LoadCommandString(BinaryReader reader, LoadCommand command) throws IOException {
offset = reader.readNextInt();
string = reader.readAsciiString(command.getStartIndex() + offset);
}

View File

@ -19,7 +19,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import java.lang.reflect.Field;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachException;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.bin.format.macho.threadcommand.ThreadCommand;
@ -30,145 +30,143 @@ import ghidra.util.Msg;
*/
public final class LoadCommandTypes {
public static LoadCommand getLoadCommand(FactoryBundledWithBinaryReader reader,
MachHeader header) throws IOException, MachException {
public static LoadCommand getLoadCommand(BinaryReader reader, MachHeader header)
throws IOException, MachException {
int type = reader.peekNextInt();
switch (type) {
case LC_SEGMENT: {
return SegmentCommand.createSegmentCommand(reader, header.is32bit());
return new SegmentCommand(reader, header.is32bit());
}
case LC_SYMTAB: {
return SymbolTableCommand.createSymbolTableCommand(reader, header);
return new SymbolTableCommand(reader, header);
}
case LC_SYMSEG: {
return SymbolCommand.createSymbolCommand(reader);
return new SymbolCommand(reader);
}
case LC_THREAD:
case LC_UNIXTHREAD: {
return ThreadCommand.createThreadCommand(reader, header);
return new ThreadCommand(reader, header);
}
case LC_LOADFVMLIB:
case LC_IDFVMLIB: {
return FixedVirtualMemorySharedLibraryCommand
.createFixedVirtualMemorySharedLibraryCommand(reader);
return new FixedVirtualMemorySharedLibraryCommand(reader);
}
case LC_IDENT: {
return IdentCommand.createIdentCommand(reader);
return new IdentCommand(reader);
}
case LC_FVMFILE: {
return FixedVirtualMemoryFileCommand.createFixedVirtualMemoryFileCommand(reader);
return new FixedVirtualMemoryFileCommand(reader);
}
case LC_PREPAGE: {
return UnsupportedLoadCommand.createUnsupportedLoadCommand(reader, type);
return new UnsupportedLoadCommand(reader, type);
}
case LC_DYSYMTAB: {
return DynamicSymbolTableCommand.createDynamicSymbolTableCommand(reader, header);
return new DynamicSymbolTableCommand(reader, header);
}
case LC_LOAD_DYLIB:
case LC_ID_DYLIB:
case LC_LOAD_UPWARD_DYLIB:
case LC_DYLD_ENVIRONMENT: {
return DynamicLibraryCommand.createDynamicLibraryCommand(reader);
return new DynamicLibraryCommand(reader);
}
case LC_LOAD_DYLINKER:
case LC_ID_DYLINKER: {
return DynamicLinkerCommand.createDynamicLinkerCommand(reader);
return new DynamicLinkerCommand(reader);
}
case LC_PREBOUND_DYLIB: {
return PreboundDynamicLibraryCommand.createPreboundDynamicLibraryCommand(reader);
return new PreboundDynamicLibraryCommand(reader);
}
case LC_ROUTINES: {
return RoutinesCommand.createRoutinesCommand(reader, header.is32bit());
return new RoutinesCommand(reader, header.is32bit());
}
case LC_SUB_FRAMEWORK: {
return SubFrameworkCommand.createSubFrameworkCommand(reader);
return new SubFrameworkCommand(reader);
}
case LC_SUB_UMBRELLA: {
return SubUmbrellaCommand.createSubUmbrellaCommand(reader);
return new SubUmbrellaCommand(reader);
}
case LC_SUB_CLIENT: {
return SubClientCommand.createSubClientCommand(reader);
return new SubClientCommand(reader);
}
case LC_SUB_LIBRARY: {
return SubLibraryCommand.createSubLibraryCommand(reader);
return new SubLibraryCommand(reader);
}
case LC_TWOLEVEL_HINTS: {
return TwoLevelHintsCommand.createTwoLevelHintsCommand(reader);
return new TwoLevelHintsCommand(reader);
}
case LC_PREBIND_CKSUM: {
return PrebindChecksumCommand.createPrebindChecksumCommand(reader);
return new PrebindChecksumCommand(reader);
}
case LC_LOAD_WEAK_DYLIB: {
return DynamicLibraryCommand.createDynamicLibraryCommand(reader);
return new DynamicLibraryCommand(reader);
}
case LC_SEGMENT_64: {
return SegmentCommand.createSegmentCommand(reader, header.is32bit());
return new SegmentCommand(reader, header.is32bit());
}
case LC_ROUTINES_64: {
return RoutinesCommand.createRoutinesCommand(reader, header.is32bit());
return new RoutinesCommand(reader, header.is32bit());
}
case LC_UUID: {
return UuidCommand.createUuidCommand(reader);
return new UuidCommand(reader);
}
case LC_RPATH: {
return RunPathCommand.createRunPathCommand(reader);
return new RunPathCommand(reader);
}
case LC_CODE_SIGNATURE:
case LC_SEGMENT_SPLIT_INFO:
case LC_DATA_IN_CODE:
case LC_OPTIMIZATION_HINT:
case LC_DYLIB_CODE_SIGN_DRS: {
return LinkEditDataCommand.createLinkEditDataCommand(reader);
return new LinkEditDataCommand(reader);
}
case LC_REEXPORT_DYLIB: {
return DynamicLibraryCommand.createDynamicLibraryCommand(reader);
return new DynamicLibraryCommand(reader);
}
case LC_ENCRYPTION_INFO:
case LC_ENCRYPTION_INFO_64: {
return EncryptedInformationCommand.createEncryptedInformationCommand(reader,
header.is32bit());
return new EncryptedInformationCommand(reader, header.is32bit());
}
case LC_DYLD_INFO:
case LC_DYLD_INFO_ONLY: {
return DyldInfoCommand.createDyldInfoCommand(reader);
return new DyldInfoCommand(reader);
}
case LC_VERSION_MIN_MACOSX:
case LC_VERSION_MIN_IPHONEOS:
case LC_VERSION_MIN_TVOS:
case LC_VERSION_MIN_WATCHOS: {
return VersionMinCommand.createVersionMinCommand(reader);
return new VersionMinCommand(reader);
}
case LC_FUNCTION_STARTS: {
return FunctionStartsCommand.createFunctionStartsCommand(reader);
return new FunctionStartsCommand(reader);
}
case LC_MAIN: {
return EntryPointCommand.createEntryPointCommand(reader);
return new EntryPointCommand(reader);
}
case LC_SOURCE_VERSION: {
return SourceVersionCommand.createSourceVersionCommand(reader);
return new SourceVersionCommand(reader);
}
case LC_LAZY_LOAD_DYLIB: {
return DynamicLibraryCommand.createDynamicLibraryCommand(reader);
return new DynamicLibraryCommand(reader);
}
case LC_BUILD_VERSION: {
return BuildVersionCommand.createBuildVersionCommand(reader);
return new BuildVersionCommand(reader);
}
case LC_LINKER_OPTIONS: {
return LinkerOptionCommand.createLinkerOptionCommand(reader);
return new LinkerOptionCommand(reader);
}
case LC_DYLD_EXPORTS_TRIE:
return LinkEditDataCommand.createLinkEditDataCommand(reader);
return new LinkEditDataCommand(reader);
case LC_DYLD_CHAINED_FIXUPS:
return DyldChainedFixupsCommand.createDyldChainedFixupsCommand(reader);
return new DyldChainedFixupsCommand(reader);
case LC_FILESET_ENTRY:
return FileSetEntryCommand.createFileSetEntryCommand(reader, header.is32bit());
return new FileSetEntryCommand(reader, header.is32bit());
default: {
Msg.warn(header, "Unsupported load command " + Integer.toHexString(type));
return UnsupportedLoadCommand.createUnsupportedLoadCommand(reader, type);
return new UnsupportedLoadCommand(reader, type);
}
}
}

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.AssertException;
@ -39,21 +39,7 @@ public class NList implements StructConverter {
private String string;
private boolean is32bit;
public static NList createNList(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
NList nList = (NList) reader.getFactory().create(NList.class);
nList.initNList(reader, is32bit);
return nList;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public NList() {
}
private void initNList(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
public NList(BinaryReader reader, boolean is32bit) throws IOException {
this.is32bit = is32bit;
n_strx = reader.readNextInt();
@ -78,10 +64,10 @@ public class NList implements StructConverter {
* scattered. Initializing the strings linearly from the string table is much
* faster.
*
* @param reader
* @param reader The BinaryReader
* @param stringTableOffset offset of the string table
*/
public void initString(FactoryBundledWithBinaryReader reader, long stringTableOffset) {
public void initString(BinaryReader reader, long stringTableOffset) {
try {
string = reader.readAsciiString(stringTableOffset + n_strx);
}

View File

@ -15,26 +15,21 @@
*/
package ghidra.app.util.bin.format.macho.commands;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.importer.*;
import ghidra.program.flatapi.*;
import ghidra.program.model.address.*;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
import ghidra.util.exception.*;
import ghidra.util.task.*;
import java.io.IOException;
import java.io.*;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.ProgramModule;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
public abstract class ObsoleteCommand extends LoadCommand {
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ObsoleteCommand() {}
protected void initObsoleteCommand(FactoryBundledWithBinaryReader reader) throws IOException, MachException {
public ObsoleteCommand(BinaryReader reader) throws IOException, MachException {
initLoadCommand(reader);
throw new ObsoleteException();
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,22 +36,7 @@ import ghidra.util.task.TaskMonitor;
public class PrebindChecksumCommand extends LoadCommand {
private int cksum;
static PrebindChecksumCommand createPrebindChecksumCommand(
FactoryBundledWithBinaryReader reader) throws IOException {
PrebindChecksumCommand checksumCommand =
(PrebindChecksumCommand) reader.getFactory().create(PrebindChecksumCommand.class);
checksumCommand.initPrebindChecksumCommand(reader);
return checksumCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public PrebindChecksumCommand() {
}
private void initPrebindChecksumCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
PrebindChecksumCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
cksum = reader.readNextInt();
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -38,27 +38,11 @@ public class PreboundDynamicLibraryCommand extends LoadCommand {
private int nmodules;
private LoadCommandString linkedModules;
static PreboundDynamicLibraryCommand createPreboundDynamicLibraryCommand(
FactoryBundledWithBinaryReader reader) throws IOException {
PreboundDynamicLibraryCommand command =
(PreboundDynamicLibraryCommand) reader.getFactory().create(
PreboundDynamicLibraryCommand.class);
command.initPreboundDynamicLibraryCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public PreboundDynamicLibraryCommand() {
}
private void initPreboundDynamicLibraryCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
PreboundDynamicLibraryCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
name = LoadCommandString.createLoadCommandString(reader, this);
name = new LoadCommandString(reader, this);
nmodules = reader.readNextInt();
linkedModules = LoadCommandString.createLoadCommandString(reader, this);
linkedModules = new LoadCommandString(reader, this);
}
@Override

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -45,20 +45,7 @@ public class RoutinesCommand extends LoadCommand {
private boolean is32bit;
static RoutinesCommand createRoutinesCommand(FactoryBundledWithBinaryReader reader,
boolean is32bit) throws IOException {
RoutinesCommand command = (RoutinesCommand) reader.getFactory().create(RoutinesCommand.class);
command.initRoutinesCommand(reader, is32bit);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public RoutinesCommand() {}
private void initRoutinesCommand(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
RoutinesCommand(BinaryReader reader, boolean is32bit) throws IOException {
initLoadCommand(reader);
this.is32bit = is32bit;
if (is32bit) {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,22 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class RunPathCommand extends LoadCommand {
private LoadCommandString path;
static RunPathCommand createRunPathCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
RunPathCommand command = (RunPathCommand) reader.getFactory().create(RunPathCommand.class);
command.initRunPathCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public RunPathCommand() {
}
private void initRunPathCommand(FactoryBundledWithBinaryReader reader) throws IOException {
RunPathCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
path = LoadCommandString.createLoadCommandString(reader, this);
path = new LoadCommandString(reader, this);
}
public LoadCommandString getPath() {

View File

@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.flatapi.FlatProgramAPI;
@ -50,22 +50,7 @@ public class SegmentCommand extends LoadCommand {
private boolean is32bit;
private List<Section> sections = new ArrayList<Section>();
public static SegmentCommand createSegmentCommand(FactoryBundledWithBinaryReader reader,
boolean is32bit) throws IOException {
SegmentCommand segmentCommand =
(SegmentCommand) reader.getFactory().create(SegmentCommand.class);
segmentCommand.initSegmentCommand(reader, is32bit);
return segmentCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SegmentCommand() {
}
private void initSegmentCommand(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
public SegmentCommand(BinaryReader reader, boolean is32bit) throws IOException {
initLoadCommand(reader);
this.is32bit = is32bit;
@ -88,7 +73,7 @@ public class SegmentCommand extends LoadCommand {
flags = reader.readNextInt();
for (int i = 0; i < nsects; ++i) {
sections.add(Section.createSection(reader, is32bit));
sections.add(new Section(reader, is32bit));
}
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,22 +36,7 @@ import ghidra.util.task.TaskMonitor;
public class SourceVersionCommand extends LoadCommand {
private long version;
static SourceVersionCommand createSourceVersionCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
SourceVersionCommand command =
(SourceVersionCommand) reader.getFactory().create(SourceVersionCommand.class);
command.initEntryPointCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SourceVersionCommand() {
}
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException {
SourceVersionCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
version = reader.readNextLong();
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,23 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class SubClientCommand extends LoadCommand {
private LoadCommandString client;
static SubClientCommand createSubClientCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
SubClientCommand clientCommand =
(SubClientCommand) reader.getFactory().create(SubClientCommand.class);
clientCommand.initSubClientCommand(reader);
return clientCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SubClientCommand() {
}
private void initSubClientCommand(FactoryBundledWithBinaryReader reader) throws IOException {
SubClientCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
client = LoadCommandString.createLoadCommandString(reader, this);
client = new LoadCommandString(reader, this);
}
/**

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,23 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class SubFrameworkCommand extends LoadCommand {
private LoadCommandString umbrella;
static SubFrameworkCommand createSubFrameworkCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
SubFrameworkCommand command =
(SubFrameworkCommand) reader.getFactory().create(SubFrameworkCommand.class);
command.initSubFrameworkCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SubFrameworkCommand() {
}
private void initSubFrameworkCommand(FactoryBundledWithBinaryReader reader) throws IOException {
SubFrameworkCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
umbrella = LoadCommandString.createLoadCommandString(reader, this);
umbrella = new LoadCommandString(reader, this);
}
public LoadCommandString getUmbrellaFrameworkName() {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,23 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class SubLibraryCommand extends LoadCommand {
private LoadCommandString sub_library;
static SubLibraryCommand createSubLibraryCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
SubLibraryCommand command =
(SubLibraryCommand) reader.getFactory().create(SubLibraryCommand.class);
command.initSubLibraryCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SubLibraryCommand() {
}
private void initSubLibraryCommand(FactoryBundledWithBinaryReader reader) throws IOException {
SubLibraryCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
sub_library = LoadCommandString.createLoadCommandString(reader, this);
sub_library = new LoadCommandString(reader, this);
}
public LoadCommandString getSubLibraryName() {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,23 +36,9 @@ import ghidra.util.task.TaskMonitor;
public class SubUmbrellaCommand extends LoadCommand {
private LoadCommandString sub_umbrella;
static SubUmbrellaCommand createSubUmbrellaCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
SubUmbrellaCommand command =
(SubUmbrellaCommand) reader.getFactory().create(SubUmbrellaCommand.class);
command.initSubUmbrellaCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SubUmbrellaCommand() {
}
private void initSubUmbrellaCommand(FactoryBundledWithBinaryReader reader) throws IOException {
SubUmbrellaCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
sub_umbrella = LoadCommandString.createLoadCommandString(reader, this);
sub_umbrella = new LoadCommandString(reader, this);
}
public LoadCommandString getSubUmbrellaFrameworkName() {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachException;
/**
@ -29,23 +29,10 @@ public class SymbolCommand extends ObsoleteCommand {
private int offset;
private int size;
static SymbolCommand createSymbolCommand(
FactoryBundledWithBinaryReader reader) throws IOException,
MachException {
SymbolCommand symbolCommand = (SymbolCommand) reader.getFactory().create(SymbolCommand.class);
symbolCommand.initSymbolCommand(reader);
return symbolCommand;
SymbolCommand(BinaryReader reader) throws IOException, MachException {
super(reader);
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SymbolCommand() {}
private void initSymbolCommand(FactoryBundledWithBinaryReader reader) throws IOException, MachException {
initObsoleteCommand(reader);
}
public int getOffset() {
return offset;
}

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -48,22 +48,7 @@ public class SymbolTableCommand extends LoadCommand {
private List<NList> symbols = new ArrayList<NList>();
public static SymbolTableCommand createSymbolTableCommand(FactoryBundledWithBinaryReader reader,
MachHeader header) throws IOException {
SymbolTableCommand symbolTableCommand =
(SymbolTableCommand) reader.getFactory().create(SymbolTableCommand.class);
symbolTableCommand.initSymbolTableCommand(reader, header);
return symbolTableCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public SymbolTableCommand() {
}
private void initSymbolTableCommand(FactoryBundledWithBinaryReader reader, MachHeader header)
throws IOException {
public SymbolTableCommand(BinaryReader reader, MachHeader header) throws IOException {
initLoadCommand(reader);
symoff = reader.readNextInt();
@ -81,7 +66,7 @@ public class SymbolTableCommand extends LoadCommand {
reader.setPointerIndex(startIndex + symoff);
for (int i = 0; i < nsyms; ++i) {
nlistList.add(NList.createNList(reader, is32bit));
nlistList.add(new NList(reader, is32bit));
}
// sort the entries by the index in the string table, so don't jump around reading
List<NList> sortedList =

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -32,21 +32,7 @@ public class TableOfContents implements StructConverter {
private int symbol_index;
private int module_index;
static TableOfContents createTableOfContents(FactoryBundledWithBinaryReader reader)
throws IOException {
TableOfContents tableOfContents =
(TableOfContents) reader.getFactory().create(TableOfContents.class);
tableOfContents.initTableOfContents(reader);
return tableOfContents;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public TableOfContents() {
}
private void initTableOfContents(FactoryBundledWithBinaryReader reader) throws IOException {
TableOfContents(BinaryReader reader) throws IOException {
symbol_index = reader.readNextInt();
module_index = reader.readNextInt();
}

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -34,20 +34,7 @@ public class TwoLevelHint implements StructConverter {
private int isub_image;
private int itoc;
static TwoLevelHint createTwoLevelHint(FactoryBundledWithBinaryReader reader)
throws IOException {
TwoLevelHint hint = (TwoLevelHint) reader.getFactory().create(TwoLevelHint.class);
hint.initTwoLevelHint(reader);
return hint;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public TwoLevelHint() {
}
private void initTwoLevelHint(FactoryBundledWithBinaryReader reader) throws IOException {
TwoLevelHint(BinaryReader reader) throws IOException {
int value = reader.readNextInt();
isub_image = value & 0xff;

View File

@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -41,22 +41,7 @@ public class TwoLevelHintsCommand extends LoadCommand {
private int nhints;
private List<TwoLevelHint> hints = new ArrayList<TwoLevelHint>();
static TwoLevelHintsCommand createTwoLevelHintsCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
TwoLevelHintsCommand command =
(TwoLevelHintsCommand) reader.getFactory().create(TwoLevelHintsCommand.class);
command.initTwoLevelHintsCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public TwoLevelHintsCommand() {
}
private void initTwoLevelHintsCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
TwoLevelHintsCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
offset = reader.readNextInt();
nhints = reader.readNextInt();
@ -64,7 +49,7 @@ public class TwoLevelHintsCommand extends LoadCommand {
long index = reader.getPointerIndex();
reader.setPointerIndex(offset);
for (int i = 0; i < nhints; ++i) {
hints.add(TwoLevelHint.createTwoLevelHint(reader));
hints.add(new TwoLevelHint(reader));
}
reader.setPointerIndex(index);
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -31,22 +31,7 @@ import ghidra.util.task.TaskMonitor;
public class UnsupportedLoadCommand extends LoadCommand {
private int type;
static UnsupportedLoadCommand createUnsupportedLoadCommand(
FactoryBundledWithBinaryReader reader, int type) throws IOException {
UnsupportedLoadCommand command =
(UnsupportedLoadCommand) reader.getFactory().create(UnsupportedLoadCommand.class);
command.initUnsupportedLoadCommand(reader, type);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public UnsupportedLoadCommand() {
}
private void initUnsupportedLoadCommand(FactoryBundledWithBinaryReader reader, int type)
throws IOException {
UnsupportedLoadCommand(BinaryReader reader, int type) throws IOException {
initLoadCommand(reader);
this.type = type;
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -36,19 +36,7 @@ import ghidra.util.task.TaskMonitor;
public class UuidCommand extends LoadCommand {
private byte[] uuid;
static UuidCommand createUuidCommand(FactoryBundledWithBinaryReader reader) throws IOException {
UuidCommand command = (UuidCommand) reader.getFactory().create(UuidCommand.class);
command.initUuidCommand(reader);
return command;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public UuidCommand() {
}
private void initUuidCommand(FactoryBundledWithBinaryReader reader) throws IOException {
UuidCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
uuid = reader.readNextByteArray(16);
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.commands;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.MachHeader;
import ghidra.app.util.importer.MessageLog;
@ -38,21 +38,7 @@ public class VersionMinCommand extends LoadCommand {
private int version;
private int sdk;
static VersionMinCommand createVersionMinCommand(FactoryBundledWithBinaryReader reader)
throws IOException {
VersionMinCommand versionMinCommand =
(VersionMinCommand) reader.getFactory().create(VersionMinCommand.class);
versionMinCommand.initVersionMinCommand(reader);
return versionMinCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public VersionMinCommand() {
}
private void initVersionMinCommand(FactoryBundledWithBinaryReader reader) throws IOException {
VersionMinCommand(BinaryReader reader) throws IOException {
initLoadCommand(reader);
version = reader.readNextInt();

View File

@ -20,10 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.macho.CpuTypes;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.app.util.bin.format.macho.commands.NList;
@ -146,15 +144,15 @@ public class DyldCacheLocalSymbolsInfo implements StructConverter {
}
private void parseNList(MessageLog log, TaskMonitor monitor) throws CancelledException {
FactoryBundledWithBinaryReader nListReader = new FactoryBundledWithBinaryReader(
RethrowContinuesFactory.INSTANCE, reader.getByteProvider(), reader.isLittleEndian());
BinaryReader nListReader =
new BinaryReader(reader.getByteProvider(), reader.isLittleEndian());
monitor.setMessage("Parsing DYLD nlist symbol table...");
monitor.initialize(nlistCount * 2);
nListReader.setPointerIndex(startIndex + nlistOffset);
try {
for (int i = 0; i < nlistCount; ++i) {
nlistList.add(NList.createNList(nListReader, is32bit));
nlistList.add(new NList(nListReader, is32bit));
monitor.checkCanceled();
monitor.incrementProgress(1);
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.*;
import ghidra.app.util.bin.format.macho.commands.LoadCommand;
import ghidra.app.util.importer.MessageLog;
@ -38,54 +38,39 @@ public class ThreadCommand extends LoadCommand {
private ThreadStateHeader threadStateHeader;
private ThreadState threadState;
public static ThreadCommand createThreadCommand(FactoryBundledWithBinaryReader reader,
MachHeader header) throws IOException {
ThreadCommand threadCommand =
(ThreadCommand) reader.getFactory().create(ThreadCommand.class);
threadCommand.initThreadCommand(reader, header);
return threadCommand;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadCommand() {
}
private void initThreadCommand(FactoryBundledWithBinaryReader reader, MachHeader header)
throws IOException {
public ThreadCommand(BinaryReader reader, MachHeader header) throws IOException {
initLoadCommand(reader);
threadStateHeader = ThreadStateHeader.createThreadStateHeader(reader);
threadStateHeader = new ThreadStateHeader(reader);
if (header.getCpuType() == CpuTypes.CPU_TYPE_X86) {
if (threadStateHeader.getFlavor() == ThreadStateX86.x86_THREAD_STATE32) {
threadState = ThreadStateX86_32.createThreadStateX86_32(reader);
threadState = new ThreadStateX86_32(reader);
}
}
else if (header.getCpuType() == CpuTypes.CPU_TYPE_X86_64) {
if (threadStateHeader.getFlavor() == ThreadStateX86.x86_THREAD_STATE64) {
threadState = ThreadStateX86_64.createThreadStateX86_64(reader);
threadState = new ThreadStateX86_64(reader);
}
}
else if (header.getCpuType() == CpuTypes.CPU_TYPE_POWERPC) {
if (threadStateHeader.getFlavor() == ThreadStatePPC.PPC_THREAD_STATE) {
threadState = ThreadStatePPC.createThreadStatePPC(reader, header.is32bit());
threadState = new ThreadStatePPC(reader, header.is32bit());
}
}
else if (header.getCpuType() == CpuTypes.CPU_TYPE_POWERPC64) {
if (threadStateHeader.getFlavor() == ThreadStatePPC.PPC_THREAD_STATE64) {
threadState = ThreadStatePPC.createThreadStatePPC(reader, header.is32bit());
threadState = new ThreadStatePPC(reader, header.is32bit());
}
}
else if (header.getCpuType() == CpuTypes.CPU_TYPE_ARM) {
if (threadStateHeader.getFlavor() == ThreadStateARM.ARM_THREAD_STATE) {
threadState = ThreadStateARM.createThreadStateARM(reader);
threadState = new ThreadStateARM(reader);
}
}
else if (header.getCpuType() == CpuTypes.CPU_TYPE_ARM_64) {
if (threadStateHeader.getFlavor() == ThreadStateARM_64.ARM64_THREAD_STATE) {
threadState = ThreadStateARM_64.createThreadStateARM_64(reader);
threadState = new ThreadStateARM_64(reader);
}
}
else {

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.Conv;
@ -53,21 +53,7 @@ public class ThreadStateARM extends ThreadState {
public int pc;
public int cpsr;
static ThreadStateARM createThreadStateARM(FactoryBundledWithBinaryReader reader)
throws IOException {
ThreadStateARM threadStateARM =
(ThreadStateARM) reader.getFactory().create(ThreadStateARM.class);
threadStateARM.initThreadStateARM(reader);
return threadStateARM;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStateARM() {
}
private void initThreadStateARM(FactoryBundledWithBinaryReader reader) throws IOException {
ThreadStateARM(BinaryReader reader) throws IOException {
r0 = reader.readNextInt();
r1 = reader.readNextInt();
r2 = reader.readNextInt();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -67,21 +67,7 @@ public class ThreadStateARM_64 extends ThreadState {
public int cpsr;
public int pad;
static ThreadStateARM_64 createThreadStateARM_64(FactoryBundledWithBinaryReader reader)
throws IOException {
ThreadStateARM_64 threadStateARM_64 =
(ThreadStateARM_64) reader.getFactory().create(ThreadStateARM_64.class);
threadStateARM_64.initThreadStateARM_64(reader);
return threadStateARM_64;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStateARM_64() {
}
private void initThreadStateARM_64(FactoryBundledWithBinaryReader reader) throws IOException {
ThreadStateARM_64(BinaryReader reader) throws IOException {
x0 = reader.readNextLong();
x1 = reader.readNextLong();
x2 = reader.readNextLong();

View File

@ -17,8 +17,8 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.StructureDataType;
import ghidra.util.exception.DuplicateNameException;
@ -27,21 +27,7 @@ public class ThreadStateHeader implements StructConverter {
private int flavor;
private int count;
static ThreadStateHeader createThreadStateHeader(FactoryBundledWithBinaryReader reader)
throws IOException {
ThreadStateHeader threadStateHeader =
(ThreadStateHeader) reader.getFactory().create(ThreadStateHeader.class);
threadStateHeader.initThreadStateHeader(reader);
return threadStateHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStateHeader() {
}
private void initThreadStateHeader(FactoryBundledWithBinaryReader reader) throws IOException {
ThreadStateHeader(BinaryReader reader) throws IOException {
flavor = reader.readNextInt();
count = reader.readNextInt();
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -80,22 +80,7 @@ public class ThreadStatePPC extends ThreadState {
/** Vector Save Register */
public long vrsave;
static ThreadStatePPC createThreadStatePPC(FactoryBundledWithBinaryReader reader,
boolean is32bit) throws IOException {
ThreadStatePPC threadStatePPC =
(ThreadStatePPC) reader.getFactory().create(ThreadStatePPC.class);
threadStatePPC.initThreadStatePPC(reader, is32bit);
return threadStatePPC;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStatePPC() {
}
private void initThreadStatePPC(FactoryBundledWithBinaryReader reader, boolean is32bit)
throws IOException {
ThreadStatePPC(BinaryReader reader, boolean is32bit) throws IOException {
srr0 = read(reader, is32bit);
srr1 = read(reader, is32bit);
r0 = read(reader, is32bit);
@ -138,7 +123,7 @@ public class ThreadStatePPC extends ThreadState {
vrsave = read(reader, is32bit);
}
private long read(FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException {
private long read(BinaryReader reader, boolean is32bit) throws IOException {
if (is32bit) {
return reader.readNextUnsignedInt();
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.Conv;
@ -46,21 +46,7 @@ public class ThreadStateX86_32 extends ThreadStateX86 {
public int fs;
public int gs;
static ThreadStateX86_32 createThreadStateX86_32(FactoryBundledWithBinaryReader reader)
throws IOException {
ThreadStateX86_32 threadStateX86_32 =
(ThreadStateX86_32) reader.getFactory().create(ThreadStateX86_32.class);
threadStateX86_32.initThreadStateX86_32(reader);
return threadStateX86_32;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStateX86_32() {
}
private void initThreadStateX86_32(FactoryBundledWithBinaryReader reader) throws IOException {
ThreadStateX86_32(BinaryReader reader) throws IOException {
eax = reader.readNextInt();
ebx = reader.readNextInt();
ecx = reader.readNextInt();

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.macho.threadcommand;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.macho.MachConstants;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
@ -50,21 +50,7 @@ public class ThreadStateX86_64 extends ThreadStateX86 {
public long fs;
public long gs;
static ThreadStateX86_64 createThreadStateX86_64(FactoryBundledWithBinaryReader reader)
throws IOException {
ThreadStateX86_64 threadStateX86_64 =
(ThreadStateX86_64) reader.getFactory().create(ThreadStateX86_64.class);
threadStateX86_64.initThreadStateX86_64(reader);
return threadStateX86_64;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public ThreadStateX86_64() {
}
private void initThreadStateX86_64(FactoryBundledWithBinaryReader reader) throws IOException {
ThreadStateX86_64(BinaryReader reader) throws IOException {
rax = reader.readNextLong();
rbx = reader.readNextLong();
rcx = reader.readNextLong();

View File

@ -18,8 +18,8 @@ package ghidra.app.util.bin.format.mz;
import java.io.IOException;
import java.io.RandomAccessFile;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.Writeable;
import ghidra.app.util.bin.format.ne.InvalidWindowsHeaderException;
import ghidra.app.util.bin.format.ne.WindowsHeader;
@ -89,27 +89,14 @@ public class DOSHeader implements StructConverter, Writeable {
private byte [] stubBytes;
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
/**
* Constructs a new DOS header.
* @param reader the binary reader
*/
public static DOSHeader createDOSHeader(
FactoryBundledWithBinaryReader reader) throws IOException {
DOSHeader dosHeader = (DOSHeader) reader.getFactory().create(DOSHeader.class);
dosHeader.initDOSHeader(reader);
return dosHeader;
}
/**
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
*/
public DOSHeader() {}
private void initDOSHeader(FactoryBundledWithBinaryReader reader) throws IOException {
public DOSHeader(BinaryReader reader) throws IOException {
this.reader = reader;
parse();
}
@ -283,7 +270,7 @@ public class DOSHeader implements StructConverter, Writeable {
if (e_lfanew >= 0 && e_lfanew <= 0x1000000) {
try {
NTHeader ntHeader =
NTHeader.createNTHeader(reader, e_lfanew, SectionLayout.FILE, false, false);
new NTHeader(reader, e_lfanew, SectionLayout.FILE, false, false);
if (ntHeader != null && ntHeader.getOptionalHeader() != null) {
return true;
}

View File

@ -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,11 +15,10 @@
*/
package ghidra.app.util.bin.format.mz;
import generic.continues.*;
import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.*;
import java.io.IOException;
import java.io.*;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
/**
* A class to manage loading Old-style (MZ) Executables.
@ -28,7 +26,7 @@ import java.io.*;
*
*/
public class OldStyleExecutable {
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private DOSHeader dosHeader;
/**
@ -36,16 +34,16 @@ public class OldStyleExecutable {
* @param bp the byte provider
* @throws IOException if an I/O error occurs
*/
public OldStyleExecutable(GenericFactory factory, ByteProvider bp) throws IOException {
reader = new FactoryBundledWithBinaryReader(factory, bp, true);
dosHeader = DOSHeader.createDOSHeader(reader);
public OldStyleExecutable(ByteProvider bp) throws IOException {
reader = new BinaryReader(bp, true);
dosHeader = new DOSHeader(reader);
}
/**
* Returns the underlying binary reader.
* @return the underlying binary reader
*/
public FactoryBundledWithBinaryReader getBinaryReader() {
public BinaryReader getBinaryReader() {
return reader;
}

View File

@ -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.
@ -18,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.BinaryReader;
/**
* A class to represent a new-executable entry point.
@ -43,7 +42,7 @@ public class EntryPoint {
* @param reader the binary reader
* @param etb the entry table bundle
*/
EntryPoint(FactoryBundledWithBinaryReader reader, EntryTableBundle etb) throws IOException {
EntryPoint(BinaryReader reader, EntryTableBundle etb) throws IOException {
this.etb = etb;
flagword = reader.readNextByte();

View File

@ -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,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class to represent a new-executable entry table.
*
@ -36,7 +35,7 @@ public class EntryTable {
* @param index the index where the entry table begins
* @param byteCount the length in bytes of the entry table
*/
EntryTable(FactoryBundledWithBinaryReader reader, short index, short byteCount) throws IOException {
EntryTable(BinaryReader reader, short index, short byteCount) throws IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(Conv.shortToInt(index));

View File

@ -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.
@ -18,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
@ -49,7 +48,7 @@ public class EntryTableBundle {
* Constructs a new entry table bundle.
* @param reader the binary reader
*/
EntryTableBundle(FactoryBundledWithBinaryReader reader) throws IOException {
EntryTableBundle(BinaryReader reader) throws IOException {
count = reader.readNextByte();
if (count == 0) return; //do not read anymore data...

View File

@ -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.
@ -18,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
@ -27,7 +26,7 @@ import ghidra.util.Conv;
*
*/
public class ImportedNameTable {
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private short index;
/**
@ -35,7 +34,7 @@ public class ImportedNameTable {
* @param reader the binary reader
* @param index the index where the table begins
*/
ImportedNameTable(FactoryBundledWithBinaryReader reader, short index) {
ImportedNameTable(BinaryReader reader, short index) {
this.reader = reader;
this.index = index;
}

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
@ -195,7 +195,7 @@ public class InformationBlock {
private short ne_swaparea; // Minimum code swap area size
private short ne_expver; // Expected windows version number
InformationBlock(FactoryBundledWithBinaryReader reader, short index)
InformationBlock(BinaryReader reader, short index)
throws InvalidWindowsHeaderException, IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(Conv.shortToInt(index));

View File

@ -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.
@ -18,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.*;
import ghidra.app.util.bin.BinaryReader;
/**
* A class to hold a length/string/ordinal set.
@ -30,7 +29,7 @@ public class LengthStringOrdinalSet extends LengthStringSet {
* Constructs a new length/string/ordinal set.
* @param reader the binary reader
*/
LengthStringOrdinalSet(FactoryBundledWithBinaryReader reader) throws IOException {
LengthStringOrdinalSet(BinaryReader reader) throws IOException {
super(reader);
if (getLength() == 0) return;

View File

@ -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,11 +15,11 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class to store a length/string set,
* where the string is not null-terminated
@ -38,7 +37,7 @@ public class LengthStringSet {
* Constructs a new length/string set.
* @param reader the binary reader
*/
LengthStringSet(FactoryBundledWithBinaryReader reader) throws IOException {
LengthStringSet(BinaryReader reader) throws IOException {
index = reader.getPointerIndex();
length = reader.readNextByte();

View File

@ -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,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class to represent the new-executable module reference table.
*
@ -38,7 +37,8 @@ public class ModuleReferenceTable {
* @param count the count of modules referenced
* @param imp the imported name table
*/
ModuleReferenceTable(FactoryBundledWithBinaryReader reader, short index, short count, ImportedNameTable imp) throws IOException {
ModuleReferenceTable(BinaryReader reader, short index, short count, ImportedNameTable imp)
throws IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(Conv.shortToInt(index));

View File

@ -17,9 +17,8 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import generic.continues.GenericFactory;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.mz.DOSHeader;
import ghidra.program.model.address.SegmentedAddress;
@ -29,7 +28,7 @@ import ghidra.program.model.address.SegmentedAddress;
*
*/
public class NewExecutable {
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private DOSHeader dosHeader;
private WindowsHeader winHeader;
@ -40,10 +39,9 @@ public class NewExecutable {
* @param baseAddr the image base of the executable
* @throws IOException if an I/O error occurs.
*/
public NewExecutable(GenericFactory factory, ByteProvider bp, SegmentedAddress baseAddr)
throws IOException {
reader = new FactoryBundledWithBinaryReader(factory, bp, true);
dosHeader = DOSHeader.createDOSHeader(reader);
public NewExecutable(ByteProvider bp, SegmentedAddress baseAddr) throws IOException {
reader = new BinaryReader(bp, true);
dosHeader = new DOSHeader(reader);
if (dosHeader.isDosSignature()) {
try {
@ -57,7 +55,7 @@ public class NewExecutable {
* Returns the underlying binary reader.
* @return the underlying binary reader
*/
public FactoryBundledWithBinaryReader getBinaryReader() {
public BinaryReader getBinaryReader() {
return reader;
}
/**

View File

@ -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,11 +15,11 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
/**
* A class to represent the new-executable non-resident name table.
*
@ -36,7 +35,7 @@ public class NonResidentNameTable {
* @param index the index where the non-resident name table begins
* @param byteCount the number of bytes in the non-resident name table
*/
NonResidentNameTable(FactoryBundledWithBinaryReader reader, int index, short byteCount) throws IOException {
NonResidentNameTable(BinaryReader reader, int index, short byteCount) throws IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(index);

View File

@ -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,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class to represent the new-executable resident name table.
*
@ -29,7 +28,7 @@ import java.util.ArrayList;
public class ResidentNameTable {
private LengthStringOrdinalSet [] names;
ResidentNameTable(FactoryBundledWithBinaryReader reader, short index) throws IOException {
ResidentNameTable(BinaryReader reader, short index) throws IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(Conv.shortToInt(index));

View File

@ -17,7 +17,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
@ -33,7 +33,7 @@ public class Resource {
/**The resource is preloaded.*/
public final static short FLAG_PRELOAD = 0x0040;
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private ResourceTable rt;
private short fileOffset; //this value must be shifted
private short fileLength; //this value must be shifted
@ -42,7 +42,7 @@ public class Resource {
private short handle; //reserved
private short usage; //reserved
Resource(FactoryBundledWithBinaryReader reader, ResourceTable rt) throws IOException {
Resource(BinaryReader reader, ResourceTable rt) throws IOException {
this.reader = reader;
this.rt = rt;
fileOffset = reader.readNextShort();

View File

@ -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,10 +15,10 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
/**
* A class for storing new-executable resource names.
*
@ -33,7 +32,7 @@ public class ResourceName {
* Constructs a resource name.
* @param reader the binary reader
*/
ResourceName(FactoryBundledWithBinaryReader reader) throws IOException {
ResourceName(BinaryReader reader) throws IOException {
index = reader.getPointerIndex();
lns = new LengthStringSet(reader);

View File

@ -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,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class for storing new-executable resource string tables.
* Strings are not stored as individual resources, rather
@ -38,7 +37,7 @@ public class ResourceStringTable extends Resource {
* @param reader the binary reade
* @param rt the resource table where this resource string table is defined
*/
ResourceStringTable(FactoryBundledWithBinaryReader reader, ResourceTable rt) throws IOException {
ResourceStringTable(BinaryReader reader, ResourceTable rt) throws IOException {
super(reader, rt);
byte [] bytes = getBytes();

View File

@ -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,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class for storing the new-executable resource table.
* A resource table contains all of the supported types
@ -41,7 +40,7 @@ public class ResourceTable {
* @param index the byte index where the Resource Table begins,
* (this is relative to the beginning of the file
*/
ResourceTable(FactoryBundledWithBinaryReader reader, short index) throws IOException {
ResourceTable(BinaryReader reader, short index) throws IOException {
this.index = index;
long oldIndex = reader.getPointerIndex();

View File

@ -18,7 +18,7 @@ package ghidra.app.util.bin.format.ne;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
@ -69,7 +69,7 @@ public class ResourceType {
* @param reader the binary reader
* @param rt the resource table
*/
ResourceType(FactoryBundledWithBinaryReader reader, ResourceTable rt) throws IOException {
ResourceType(BinaryReader reader, ResourceTable rt) throws IOException {
typeID = reader.readNextShort();
if (typeID == 0) {
return; //not a valid resource type...

View File

@ -15,12 +15,12 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import ghidra.util.Conv;
import java.io.IOException;
import java.util.ArrayList;
import ghidra.app.util.bin.BinaryReader;
import ghidra.util.Conv;
/**
* A class to represent a new-executable segment.
*
@ -50,7 +50,7 @@ public class Segment {
/**segment is 32 bit */
private final static short FLAG_32BIT = (short) 0x2000;
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;
private int segmentID;
private short offset; //byte offset to content, relative to BOF (zero means no file data)
private short length; //length of segment in file (zero means 64k)
@ -60,7 +60,7 @@ public class Segment {
private short nRelocations; //number of relocations
private SegmentRelocation [] relocations; //relocation records
Segment(FactoryBundledWithBinaryReader reader, short segmentAlignment, int segmentID) throws IOException {
Segment(BinaryReader reader, short segmentAlignment, int segmentID) throws IOException {
this.reader = reader;
this.segmentID = segmentID;

View File

@ -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,10 +15,10 @@
*/
package ghidra.app.util.bin.format.ne;
import ghidra.app.util.bin.format.*;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader;
/**
* A class to represent a new-executable segment relocation.
*
@ -102,7 +101,7 @@ public class SegmentRelocation {
* Constucts a new segment relocation.
* @param reader the binary reader
*/
SegmentRelocation(FactoryBundledWithBinaryReader reader, int segment) throws IOException {
SegmentRelocation(BinaryReader reader, int segment) throws IOException {
this.segment = segment;
type = reader.readNextByte();
flagbyte = reader.readNextByte();

Some files were not shown because too many files have changed in this diff Show More