diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d0792eb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: Build ghidra-lx-loader +on: + pull_request: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + - name: Setup ghidra + uses: er28-0652/setup-ghidra@master + with: + version: '10.2' + - name: Build Ghidra extension (using gradle) + uses: gradle/gradle-build-action@v2 + with: + gradle-version: 'current' + arguments: 'buildExtension' + - uses: actions/upload-artifact@v3 + with: + name: ghidra-lx-loader + path: | + dist/*.zip diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java b/src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java index 34d096e..157dcf1 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java @@ -3,8 +3,8 @@ 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.program.model.data.ArrayDataType; import ghidra.program.model.data.CategoryPath; @@ -41,25 +41,25 @@ 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); + BinaryReader reader) throws IOException { + DOSHeader dosHeader = new DOSHeader(); dosHeader.initDOSHeader(reader); return dosHeader; } /** - * DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD. + * DO NOT USE THIS CONSTRUCTOR, USE create*(BinaryReader ...) FACTORY METHODS INSTEAD. */ public DOSHeader() {} - private void initDOSHeader(FactoryBundledWithBinaryReader reader1) throws IOException { + private void initDOSHeader(BinaryReader reader1) throws IOException { this.reader = reader1; parse(); diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/Dos16Header.java b/src/main/java/yetmorecode/ghidra/format/lx/model/Dos16Header.java index 5ff7f2e..10cbe6e 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/Dos16Header.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/Dos16Header.java @@ -2,8 +2,8 @@ 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.ArrayDataType; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; @@ -16,7 +16,7 @@ public class Dos16Header extends BwHeader implements StructConverter { private StructureDataType dt = new StructureDataType(DATATYPE_NAME, 0); - public Dos16Header(FactoryBundledWithBinaryReader reader, long index) throws IOException, InvalidHeaderException { + public Dos16Header(BinaryReader reader, long index) throws IOException, InvalidHeaderException { long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java b/src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java index a6ad357..6a57159 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java @@ -4,9 +4,8 @@ import java.util.ArrayList; import java.util.HashMap; -import generic.continues.GenericFactory; +import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.ByteProvider; -import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader; import yetmorecode.file.format.lx.LinearExecutable; import yetmorecode.file.format.lx.LinearObjectTableEntry; import yetmorecode.ghidra.lx.InvalidHeaderException; @@ -14,7 +13,7 @@ public class Executable extends LinearExecutable { - private FactoryBundledWithBinaryReader reader; + private BinaryReader reader; public boolean isUnbound = false; @@ -32,8 +31,8 @@ public class Executable extends LinearExecutable { public long lfanew = 0; public long lfamz = 0; - public Executable(GenericFactory factory, ByteProvider bp, Options options) throws IOException, InvalidHeaderException { - reader = new FactoryBundledWithBinaryReader(factory, bp, true); + public Executable(ByteProvider bp, Options options) throws IOException, InvalidHeaderException { + reader = new BinaryReader(bp, true); try { // Try reading MZ header mz = DOSHeader.createDOSHeader(reader); @@ -120,11 +119,11 @@ public Executable(GenericFactory factory, ByteProvider bp, Options options) thro * Returns the underlying binary reader. * @return the underlying binary reader */ - public FactoryBundledWithBinaryReader getBinaryReader() { + public BinaryReader getBinaryReader() { return reader; } - public FactoryBundledWithBinaryReader getReader() { + public BinaryReader getReader() { return reader; } diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/FixupRecord.java b/src/main/java/yetmorecode/ghidra/format/lx/model/FixupRecord.java index 22bc365..632514b 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/FixupRecord.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/FixupRecord.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +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.program.model.data.StructureDataType; @@ -35,7 +35,7 @@ public class FixupRecord extends LinearFixupRecord implements StructConverter { private StructureDataType dt; - public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, int baseAddress, int page) throws IOException { + public FixupRecord(BinaryReader reader, long l, int number, int baseAddress, int page) throws IOException { var oldIndex = reader.getPointerIndex(); reader.setPointerIndex(l); index = number; @@ -72,14 +72,14 @@ public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, in // target data if (objectNumber16Bit()) { objectNumber = reader.readNextShort(); - dt.add(WORD, "objectNumber", "This field is an index into the current module’s Object Table to specify the targetObject. It is a Byte value when the ‘16-bit Object Number/Module Ordinal Flag’ bit inthe target flags field is clear and a Word value when the bit is set."); + dt.add(WORD, "objectNumber", "This field is an index into the current module’s Object Table to specify the targetObject. It is a Byte value when the ‘16-bit Object Number/Module Ordinal Flag’ bit inthe target flags field is clear and a Word value when the bit is set."); size += 2; } else { objectNumber = reader.readNextByte(); if (objectNumber < 0) { objectNumber += 0x100; } - dt.add(BYTE, "objectNumber", "This field is an index into the current module’s Object Table to specify the targetObject. It is a Byte value when the ‘16-bit Object Number/Module Ordinal Flag’ bit inthe target flags field is clear and a Word value when the bit is set."); + dt.add(BYTE, "objectNumber", "This field is an index into the current module’s Object Table to specify the targetObject. It is a Byte value when the ‘16-bit Object Number/Module Ordinal Flag’ bit inthe target flags field is clear and a Word value when the bit is set."); size++; } @@ -88,11 +88,11 @@ public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, in // no target offset } else if (isTargetOffset32Bit()) { targetOffset = reader.readNextInt(); - dt.add(DWORD, "targetOffset", "This field is an offset into the specified target Object. It is not present when theSource Type specifies a 16-bit Selector fixup. It is a Word value when the ‘32-bitTarget Offset Flag’ bit in the target flags field is clear and a Dword value when the bitis set."); + dt.add(DWORD, "targetOffset", "This field is an offset into the specified target Object. It is not present when theSource Type specifies a 16-bit Selector fixup. It is a Word value when the ‘32-bitTarget Offset Flag’ bit in the target flags field is clear and a Dword value when the bitis set."); size += 4; } else { targetOffset = reader.readNextShort(); - dt.add(WORD, "targetOffset", "This field is an offset into the specified target Object. It is not present when theSource Type specifies a 16-bit Selector fixup. It is a Word value when the ‘32-bitTarget Offset Flag’ bit in the target flags field is clear and a Dword value when the bitis set."); + dt.add(WORD, "targetOffset", "This field is an offset into the specified target Object. It is not present when theSource Type specifies a 16-bit Selector fixup. It is a Word value when the ‘32-bitTarget Offset Flag’ bit in the target flags field is clear and a Dword value when the bitis set."); size += 2; if (targetOffset < 0) { targetOffset += 0x10000; diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/Header.java b/src/main/java/yetmorecode/ghidra/format/lx/model/Header.java index 87d2f64..9d0de2c 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/Header.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/Header.java @@ -2,8 +2,8 @@ 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.ArrayDataType; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; @@ -22,7 +22,7 @@ public class Header extends yetmorecode.file.format.lx.LinearHeader implements S public int unknown; - public Header(FactoryBundledWithBinaryReader reader, long index) throws IOException, InvalidHeaderException { + public Header(BinaryReader reader, long index) throws IOException, InvalidHeaderException { long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); @@ -68,7 +68,7 @@ public Header(FactoryBundledWithBinaryReader reader, long index) throws IOExcept pageCount = reader.readNextInt(); dt.add( DWORD, 4, "e32_mpages", - "# of physical pages in module. This field specifies the number of pages physically contained in this module. In other words, pages containing either enumerated or iterated data, not invalid or zero-fillpages. These pages are contained in the ‘preload pages’, ‘demand load pages’ and ‘iterated data pages’ sections of the linear EXE module." + "# of physical pages in module. This field specifies the number of pages physically contained in this module. In other words, pages containing either enumerated or iterated data, not invalid or zero-fillpages. These pages are contained in the ‘preload pages’, ‘demand load pages’ and ‘iterated data pages’ sections of the linear EXE module." ); eipObject = reader.readNextInt(); dt.add( diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/VxDDescriptionBlock.java b/src/main/java/yetmorecode/ghidra/format/lx/model/VxDDescriptionBlock.java index eb4bf3d..52cd4d1 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/VxDDescriptionBlock.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/VxDDescriptionBlock.java @@ -2,8 +2,8 @@ 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.ArrayDataType; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; @@ -15,9 +15,9 @@ public class VxDDescriptionBlock extends DescriptionBlock implements StructConve private StructureDataType dt = new StructureDataType(DATATYPE_NAME, 0); - private FactoryBundledWithBinaryReader reader; + private BinaryReader reader; - public VxDDescriptionBlock(FactoryBundledWithBinaryReader reader, long index) throws IOException { + public VxDDescriptionBlock(BinaryReader reader, long index) throws IOException { this.reader = reader; long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); diff --git a/src/main/java/yetmorecode/ghidra/format/lx/model/VxDVersionResource.java b/src/main/java/yetmorecode/ghidra/format/lx/model/VxDVersionResource.java index fe101af..03ef1f9 100644 --- a/src/main/java/yetmorecode/ghidra/format/lx/model/VxDVersionResource.java +++ b/src/main/java/yetmorecode/ghidra/format/lx/model/VxDVersionResource.java @@ -2,8 +2,8 @@ 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.ArrayDataType; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; @@ -18,9 +18,9 @@ public class VxDVersionResource extends VersionResource implements StructConvert private StructureDataType vartype = new StructureDataType("VarFileInfo", 0); private StructureDataType versiontype = new StructureDataType("VS_VERSIONINFO", 0); private StructureDataType infotype = new StructureDataType("VS_FIXEDFILEINFO", 0); - private FactoryBundledWithBinaryReader reader; + private BinaryReader reader; - public VxDVersionResource(FactoryBundledWithBinaryReader reader, long index) throws IOException { + public VxDVersionResource(BinaryReader reader, long index) throws IOException { this.reader = reader; long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); diff --git a/src/main/java/yetmorecode/ghidra/lx/LinearLoader.java b/src/main/java/yetmorecode/ghidra/lx/LinearLoader.java index 8707773..f9b7858 100644 --- a/src/main/java/yetmorecode/ghidra/lx/LinearLoader.java +++ b/src/main/java/yetmorecode/ghidra/lx/LinearLoader.java @@ -4,15 +4,12 @@ import java.io.IOException; import java.util.*; -import generic.continues.ContinuesFactory; -import generic.continues.RethrowContinuesFactory; import ghidra.app.util.MemoryBlockUtils; import ghidra.app.util.Option; +import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.ByteProvider; import ghidra.app.util.bin.StructConverter; -import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader; import ghidra.app.util.importer.MessageLog; -import ghidra.app.util.importer.MessageLogContinuesFactory; import ghidra.app.util.opinion.AbstractLibrarySupportLoader; import ghidra.app.util.opinion.LoadSpec; import ghidra.framework.model.DomainObject; @@ -22,7 +19,6 @@ import ghidra.program.model.address.AddressSpace; import ghidra.program.model.data.CategoryPath; import ghidra.program.model.data.DataType; -import ghidra.program.model.data.DataTypeConflictException; import ghidra.program.model.data.StructureDataType; import ghidra.program.model.lang.LanguageCompilerSpecPair; import ghidra.program.model.listing.CodeUnit; @@ -70,7 +66,7 @@ public abstract class LinearLoader extends AbstractLibrarySupportLoader { @Override public abstract String getName(); - public abstract void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException; + public abstract void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException; @Override public Collection findSupportedLoadSpecs(ByteProvider provider) throws IOException { @@ -78,7 +74,7 @@ public Collection findSupportedLoadSpecs(ByteProvider provider) throws if (provider.length() < 4) { return loadSpecs; } - var reader = new FactoryBundledWithBinaryReader(RethrowContinuesFactory.INSTANCE, provider, true); + var reader = new BinaryReader(provider, true); try { checkFormat(reader); loadSpecs.add(new LoadSpec(this, 0, new LanguageCompilerSpecPair("x86:LE:32:default", "borlandcpp"), true)); @@ -110,10 +106,9 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List