Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
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;
import yetmorecode.ghidra.lx.Options;


public class Executable extends LinearExecutable {
private FactoryBundledWithBinaryReader reader;
private BinaryReader reader;

public boolean isUnbound = false;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 modules 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 modules 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 modules 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 modules 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++;
}

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/yetmorecode/ghidra/format/lx/model/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/yetmorecode/ghidra/lx/LinearLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -70,15 +66,15 @@ 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<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException {
List<LoadSpec> loadSpecs = new ArrayList<>();
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));
Expand Down Expand Up @@ -110,10 +106,9 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> optio
int id = program.startTransaction(ARROW + "Loading..");
monitor.setIndeterminate(true);
monitor.setMessage(String.format(ARROW + "Loading %s", getName()));
ContinuesFactory factory = MessageLogContinuesFactory.create(messageLog);
try {
// Parse EXE from file
var executable = new Executable(factory, provider, loaderOptions);
var executable = new Executable(provider, loaderOptions);

// Map IMAGE data (MZ, LX)
createImageMappings(executable, program, provider, monitor);
Expand Down Expand Up @@ -279,10 +274,6 @@ private Data createData(Program program, Address address, DataType dt) {
Msg.warn(this, "LX data markup conflict at " + address + ": " + e.getMessage());
e.printStackTrace();
}
catch (DataTypeConflictException e) {
Msg.error(this, "LX data type markup conflict at " + address + ": " + e.getMessage());
e.printStackTrace();
}
return null;
}

Expand All @@ -309,7 +300,7 @@ private byte[] createObjectBlock(Program program, Executable le, LinearObjectTab
var pageOffset = le.lfamz + header.dataPagesOffset + (entry.getOffset()-1) * pageSize;

// Read page from file
FactoryBundledWithBinaryReader r = le.getReader();
BinaryReader r = le.getReader();
r.setPointerIndex(pageOffset);
byte[] pageData;
var isLastPage = i == object.pageCount - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/yetmorecode/ghidra/lx/loader/LeLoader.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package yetmorecode.ghidra.lx.loader;

import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
import yetmorecode.file.format.lx.LinearHeader;
Expand Down Expand Up @@ -32,7 +32,7 @@ public String getName() {
}

@Override
public void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException {
public void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException {
// Try parsing MZ header
reader.setPointerIndex(0);
var mzHeader = DOSHeader.createDOSHeader(reader);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/yetmorecode/ghidra/lx/loader/LxLoader.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package yetmorecode.ghidra.lx.loader;

import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.mz.DOSHeader;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
Expand Down Expand Up @@ -30,9 +30,9 @@ public String getName() {
}

@Override
public void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException {
public void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException {
// Try parsing MZ header
var mzHeader = DOSHeader.createDOSHeader(reader);
var mzHeader = new DOSHeader(reader);
var lfanew = 0;
if (mzHeader.isDosSignature()) {
lfanew = mzHeader.e_lfanew();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/yetmorecode/ghidra/lx/loader/VxDLoader.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package yetmorecode.ghidra.lx.loader;

import java.io.IOException;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.mz.DOSHeader;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
Expand Down Expand Up @@ -30,9 +30,9 @@ public String getName() {
}

@Override
public void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException {
public void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException {
// Try parsing MZ header
var mzHeader = DOSHeader.createDOSHeader(reader);
var mzHeader = new DOSHeader(reader);
var lfanew = 0;
if (mzHeader.isDosSignature()) {
lfanew = mzHeader.e_lfanew();
Expand Down