Skip to content

Commit 4c17794

Browse files
authored
Merge pull request #3 from madebr/github-actions
Add github workflow to build and upload an artifact
2 parents 705ccd8 + 1419c41 commit 4c17794

File tree

12 files changed

+70
-52
lines changed

12 files changed

+70
-52
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build ghidra-lx-loader
2+
on:
3+
pull_request:
4+
push:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-java@v3
12+
with:
13+
java-version: '17'
14+
distribution: 'zulu'
15+
- name: Setup ghidra
16+
uses: er28-0652/setup-ghidra@master
17+
with:
18+
version: '10.2'
19+
- name: Build Ghidra extension (using gradle)
20+
uses: gradle/gradle-build-action@v2
21+
with:
22+
gradle-version: 'current'
23+
arguments: 'buildExtension'
24+
- uses: actions/upload-artifact@v3
25+
with:
26+
name: ghidra-lx-loader
27+
path: |
28+
dist/*.zip

src/main/java/yetmorecode/ghidra/format/lx/model/DOSHeader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.io.IOException;
44
import java.io.RandomAccessFile;
55

6+
import ghidra.app.util.bin.BinaryReader;
67
import ghidra.app.util.bin.StructConverter;
7-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
88
import ghidra.app.util.bin.format.Writeable;
99
import ghidra.program.model.data.ArrayDataType;
1010
import ghidra.program.model.data.CategoryPath;
@@ -41,25 +41,25 @@ public class DOSHeader implements StructConverter, Writeable {
4141

4242
private byte [] stubBytes;
4343

44-
private FactoryBundledWithBinaryReader reader;
44+
private BinaryReader reader;
4545

4646
/**
4747
* Constructs a new DOS header.
4848
* @param reader the binary reader
4949
*/
5050
public static DOSHeader createDOSHeader(
51-
FactoryBundledWithBinaryReader reader) throws IOException {
52-
DOSHeader dosHeader = (DOSHeader) reader.getFactory().create(DOSHeader.class);
51+
BinaryReader reader) throws IOException {
52+
DOSHeader dosHeader = new DOSHeader();
5353
dosHeader.initDOSHeader(reader);
5454
return dosHeader;
5555
}
5656

5757
/**
58-
* DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
58+
* DO NOT USE THIS CONSTRUCTOR, USE create*(BinaryReader ...) FACTORY METHODS INSTEAD.
5959
*/
6060
public DOSHeader() {}
6161

62-
private void initDOSHeader(FactoryBundledWithBinaryReader reader1) throws IOException {
62+
private void initDOSHeader(BinaryReader reader1) throws IOException {
6363
this.reader = reader1;
6464

6565
parse();

src/main/java/yetmorecode/ghidra/format/lx/model/Dos16Header.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44

5+
import ghidra.app.util.bin.BinaryReader;
56
import ghidra.app.util.bin.StructConverter;
6-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
77
import ghidra.program.model.data.ArrayDataType;
88
import ghidra.program.model.data.DataType;
99
import ghidra.program.model.data.StructureDataType;
@@ -16,7 +16,7 @@ public class Dos16Header extends BwHeader implements StructConverter {
1616

1717
private StructureDataType dt = new StructureDataType(DATATYPE_NAME, 0);
1818

19-
public Dos16Header(FactoryBundledWithBinaryReader reader, long index) throws IOException, InvalidHeaderException {
19+
public Dos16Header(BinaryReader reader, long index) throws IOException, InvalidHeaderException {
2020
long oldIndex = reader.getPointerIndex();
2121
reader.setPointerIndex(index);
2222

src/main/java/yetmorecode/ghidra/format/lx/model/Executable.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import java.util.ArrayList;
55
import java.util.HashMap;
66

7-
import generic.continues.GenericFactory;
7+
import ghidra.app.util.bin.BinaryReader;
88
import ghidra.app.util.bin.ByteProvider;
9-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
109
import yetmorecode.file.format.lx.LinearExecutable;
1110
import yetmorecode.file.format.lx.LinearObjectTableEntry;
1211
import yetmorecode.ghidra.lx.InvalidHeaderException;
1312
import yetmorecode.ghidra.lx.Options;
1413

1514

1615
public class Executable extends LinearExecutable {
17-
private FactoryBundledWithBinaryReader reader;
16+
private BinaryReader reader;
1817

1918
public boolean isUnbound = false;
2019

@@ -32,8 +31,8 @@ public class Executable extends LinearExecutable {
3231
public long lfanew = 0;
3332
public long lfamz = 0;
3433

35-
public Executable(GenericFactory factory, ByteProvider bp, Options options) throws IOException, InvalidHeaderException {
36-
reader = new FactoryBundledWithBinaryReader(factory, bp, true);
34+
public Executable(ByteProvider bp, Options options) throws IOException, InvalidHeaderException {
35+
reader = new BinaryReader(bp, true);
3736
try {
3837
// Try reading MZ header
3938
mz = DOSHeader.createDOSHeader(reader);
@@ -120,11 +119,11 @@ public Executable(GenericFactory factory, ByteProvider bp, Options options) thro
120119
* Returns the underlying binary reader.
121120
* @return the underlying binary reader
122121
*/
123-
public FactoryBundledWithBinaryReader getBinaryReader() {
122+
public BinaryReader getBinaryReader() {
124123
return reader;
125124
}
126125

127-
public FactoryBundledWithBinaryReader getReader() {
126+
public BinaryReader getReader() {
128127
return reader;
129128
}
130129

src/main/java/yetmorecode/ghidra/format/lx/model/FixupRecord.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.io.IOException;
44
import java.nio.ByteBuffer;
55
import java.nio.ByteOrder;
6+
import ghidra.app.util.bin.BinaryReader;
67
import ghidra.app.util.bin.StructConverter;
7-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
88
import ghidra.program.model.data.ArrayDataType;
99
import ghidra.program.model.data.DataType;
1010
import ghidra.program.model.data.StructureDataType;
@@ -35,7 +35,7 @@ public class FixupRecord extends LinearFixupRecord implements StructConverter {
3535

3636
private StructureDataType dt;
3737

38-
public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, int baseAddress, int page) throws IOException {
38+
public FixupRecord(BinaryReader reader, long l, int number, int baseAddress, int page) throws IOException {
3939
var oldIndex = reader.getPointerIndex();
4040
reader.setPointerIndex(l);
4141
index = number;
@@ -72,14 +72,14 @@ public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, in
7272
// target data
7373
if (objectNumber16Bit()) {
7474
objectNumber = reader.readNextShort();
75-
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.");
75+
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.");
7676
size += 2;
7777
} else {
7878
objectNumber = reader.readNextByte();
7979
if (objectNumber < 0) {
8080
objectNumber += 0x100;
8181
}
82-
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.");
82+
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.");
8383
size++;
8484
}
8585

@@ -88,11 +88,11 @@ public FixupRecord(FactoryBundledWithBinaryReader reader, long l, int number, in
8888
// no target offset
8989
} else if (isTargetOffset32Bit()) {
9090
targetOffset = reader.readNextInt();
91-
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.");
91+
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.");
9292
size += 4;
9393
} else {
9494
targetOffset = reader.readNextShort();
95-
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.");
95+
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.");
9696
size += 2;
9797
if (targetOffset < 0) {
9898
targetOffset += 0x10000;

src/main/java/yetmorecode/ghidra/format/lx/model/Header.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44

5+
import ghidra.app.util.bin.BinaryReader;
56
import ghidra.app.util.bin.StructConverter;
6-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
77
import ghidra.program.model.data.ArrayDataType;
88
import ghidra.program.model.data.DataType;
99
import ghidra.program.model.data.StructureDataType;
@@ -22,7 +22,7 @@ public class Header extends yetmorecode.file.format.lx.LinearHeader implements S
2222

2323
public int unknown;
2424

25-
public Header(FactoryBundledWithBinaryReader reader, long index) throws IOException, InvalidHeaderException {
25+
public Header(BinaryReader reader, long index) throws IOException, InvalidHeaderException {
2626
long oldIndex = reader.getPointerIndex();
2727
reader.setPointerIndex(index);
2828

@@ -68,7 +68,7 @@ public Header(FactoryBundledWithBinaryReader reader, long index) throws IOExcept
6868
pageCount = reader.readNextInt();
6969
dt.add(
7070
DWORD, 4, "e32_mpages",
71-
"# 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."
71+
"# 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."
7272
);
7373
eipObject = reader.readNextInt();
7474
dt.add(

src/main/java/yetmorecode/ghidra/format/lx/model/VxDDescriptionBlock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44

5+
import ghidra.app.util.bin.BinaryReader;
56
import ghidra.app.util.bin.StructConverter;
6-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
77
import ghidra.program.model.data.ArrayDataType;
88
import ghidra.program.model.data.DataType;
99
import ghidra.program.model.data.StructureDataType;
@@ -15,9 +15,9 @@ public class VxDDescriptionBlock extends DescriptionBlock implements StructConve
1515

1616
private StructureDataType dt = new StructureDataType(DATATYPE_NAME, 0);
1717

18-
private FactoryBundledWithBinaryReader reader;
18+
private BinaryReader reader;
1919

20-
public VxDDescriptionBlock(FactoryBundledWithBinaryReader reader, long index) throws IOException {
20+
public VxDDescriptionBlock(BinaryReader reader, long index) throws IOException {
2121
this.reader = reader;
2222
long oldIndex = reader.getPointerIndex();
2323
reader.setPointerIndex(index);

src/main/java/yetmorecode/ghidra/format/lx/model/VxDVersionResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44

5+
import ghidra.app.util.bin.BinaryReader;
56
import ghidra.app.util.bin.StructConverter;
6-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
77
import ghidra.program.model.data.ArrayDataType;
88
import ghidra.program.model.data.DataType;
99
import ghidra.program.model.data.StructureDataType;
@@ -18,9 +18,9 @@ public class VxDVersionResource extends VersionResource implements StructConvert
1818
private StructureDataType vartype = new StructureDataType("VarFileInfo", 0);
1919
private StructureDataType versiontype = new StructureDataType("VS_VERSIONINFO", 0);
2020
private StructureDataType infotype = new StructureDataType("VS_FIXEDFILEINFO", 0);
21-
private FactoryBundledWithBinaryReader reader;
21+
private BinaryReader reader;
2222

23-
public VxDVersionResource(FactoryBundledWithBinaryReader reader, long index) throws IOException {
23+
public VxDVersionResource(BinaryReader reader, long index) throws IOException {
2424
this.reader = reader;
2525
long oldIndex = reader.getPointerIndex();
2626
reader.setPointerIndex(index);

src/main/java/yetmorecode/ghidra/lx/LinearLoader.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
import java.io.IOException;
55
import java.util.*;
66

7-
import generic.continues.ContinuesFactory;
8-
import generic.continues.RethrowContinuesFactory;
97
import ghidra.app.util.MemoryBlockUtils;
108
import ghidra.app.util.Option;
9+
import ghidra.app.util.bin.BinaryReader;
1110
import ghidra.app.util.bin.ByteProvider;
1211
import ghidra.app.util.bin.StructConverter;
13-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
1412
import ghidra.app.util.importer.MessageLog;
15-
import ghidra.app.util.importer.MessageLogContinuesFactory;
1613
import ghidra.app.util.opinion.AbstractLibrarySupportLoader;
1714
import ghidra.app.util.opinion.LoadSpec;
1815
import ghidra.framework.model.DomainObject;
@@ -22,7 +19,6 @@
2219
import ghidra.program.model.address.AddressSpace;
2320
import ghidra.program.model.data.CategoryPath;
2421
import ghidra.program.model.data.DataType;
25-
import ghidra.program.model.data.DataTypeConflictException;
2622
import ghidra.program.model.data.StructureDataType;
2723
import ghidra.program.model.lang.LanguageCompilerSpecPair;
2824
import ghidra.program.model.listing.CodeUnit;
@@ -70,15 +66,15 @@ public abstract class LinearLoader extends AbstractLibrarySupportLoader {
7066
@Override
7167
public abstract String getName();
7268

73-
public abstract void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException;
69+
public abstract void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException;
7470

7571
@Override
7672
public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException {
7773
List<LoadSpec> loadSpecs = new ArrayList<>();
7874
if (provider.length() < 4) {
7975
return loadSpecs;
8076
}
81-
var reader = new FactoryBundledWithBinaryReader(RethrowContinuesFactory.INSTANCE, provider, true);
77+
var reader = new BinaryReader(provider, true);
8278
try {
8379
checkFormat(reader);
8480
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<Option> optio
110106
int id = program.startTransaction(ARROW + "Loading..");
111107
monitor.setIndeterminate(true);
112108
monitor.setMessage(String.format(ARROW + "Loading %s", getName()));
113-
ContinuesFactory factory = MessageLogContinuesFactory.create(messageLog);
114109
try {
115110
// Parse EXE from file
116-
var executable = new Executable(factory, provider, loaderOptions);
111+
var executable = new Executable(provider, loaderOptions);
117112

118113
// Map IMAGE data (MZ, LX)
119114
createImageMappings(executable, program, provider, monitor);
@@ -279,10 +274,6 @@ private Data createData(Program program, Address address, DataType dt) {
279274
Msg.warn(this, "LX data markup conflict at " + address + ": " + e.getMessage());
280275
e.printStackTrace();
281276
}
282-
catch (DataTypeConflictException e) {
283-
Msg.error(this, "LX data type markup conflict at " + address + ": " + e.getMessage());
284-
e.printStackTrace();
285-
}
286277
return null;
287278
}
288279

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

311302
// Read page from file
312-
FactoryBundledWithBinaryReader r = le.getReader();
303+
BinaryReader r = le.getReader();
313304
r.setPointerIndex(pageOffset);
314305
byte[] pageData;
315306
var isLastPage = i == object.pageCount - 1;

src/main/java/yetmorecode/ghidra/lx/loader/LeLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package yetmorecode.ghidra.lx.loader;
22

33
import java.io.IOException;
4-
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
4+
import ghidra.app.util.bin.BinaryReader;
55
import ghidra.program.model.listing.Program;
66
import ghidra.util.Msg;
77
import yetmorecode.file.format.lx.LinearHeader;
@@ -32,7 +32,7 @@ public String getName() {
3232
}
3333

3434
@Override
35-
public void checkFormat(FactoryBundledWithBinaryReader reader) throws IOException, InvalidHeaderException {
35+
public void checkFormat(BinaryReader reader) throws IOException, InvalidHeaderException {
3636
// Try parsing MZ header
3737
reader.setPointerIndex(0);
3838
var mzHeader = DOSHeader.createDOSHeader(reader);

0 commit comments

Comments
 (0)