Skip to content

Commit

Permalink
Implemented fixups for types 3 (16:16 pointer) and 8 (32bit self-ref)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetmorecode committed Dec 5, 2021
1 parent 3b8b395 commit 22064a4
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 85 deletions.
5 changes: 0 additions & 5 deletions src/main/java/yetmorecode/ghidra/format/lx/FixupRecord.java

This file was deleted.

7 changes: 3 additions & 4 deletions src/main/java/yetmorecode/ghidra/format/lx/LxExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.app.util.bin.format.mz.DOSHeader;
import yetmorecode.file.format.lx.ObjectTableEntry;
import yetmorecode.ghidra.format.lx.exception.InvalidHeaderException;


public class LxExecutable extends yetmorecode.file.format.lx.LxExecutable {
private FactoryBundledWithBinaryReader reader;
DOSHeader mzHeader;

public ArrayList<ObjectMapEntry> objects = new ArrayList<>();
public ArrayList<ObjectTableEntry> objects = new ArrayList<>();

public LxExecutable(GenericFactory factory, ByteProvider bp) throws IOException, InvalidHeaderException {
reader = new FactoryBundledWithBinaryReader(factory, bp, true);
Expand All @@ -27,7 +26,7 @@ public LxExecutable(GenericFactory factory, ByteProvider bp) throws IOException,
//objectTable = new ArrayList<ObjectMapEntry>(header.objectCount);
int objectTableOffset = mzHeader.e_lfanew() + header.objectTableOffset;
for (int i = 0; i < header.objectCount; i++) {
ObjectMapEntry e = new ObjectMapEntry(reader, objectTableOffset + i * ObjectTableEntry.SIZE);
ObjectTableEntry e = new ObjectTableEntry(reader, objectTableOffset + i * yetmorecode.file.format.lx.ObjectTableEntry.SIZE);
e.number = i+1;
//objectTable.add(e);
objects.add(e);
Expand Down Expand Up @@ -55,7 +54,7 @@ public LxHeader getLeHeader() {
return (LxHeader) header;
}

public ArrayList<ObjectMapEntry> getObjects() {
public ArrayList<ObjectTableEntry> getObjects() {
return objects;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/yetmorecode/ghidra/format/lx/LxHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
import ghidra.util.Conv;
import ghidra.util.Msg;
import yetmorecode.ghidra.format.lx.exception.InvalidHeaderException;

public class LxHeader extends yetmorecode.file.format.lx.LxHeader {
Expand All @@ -14,8 +13,10 @@ public LxHeader(FactoryBundledWithBinaryReader reader, short index) throws IOExc
reader.setPointerIndex(Conv.shortToInt(index));

signature = reader.readNextShort();
if (signature != yetmorecode.file.format.lx.LxHeader.SIGNATURE_LE) {
Msg.info("LE", String.format("wrong magic %x", signature));
if (signature != yetmorecode.file.format.lx.LxHeader.SIGNATURE_LE &&
signature != yetmorecode.file.format.lx.LxHeader.SIGNATURE_LX &&
signature != yetmorecode.file.format.lx.LxHeader.SIGNATURE_LC
) {
throw new InvalidHeaderException();
}

Expand Down
20 changes: 0 additions & 20 deletions src/main/java/yetmorecode/ghidra/format/lx/ObjectMapEntry.java

This file was deleted.

44 changes: 44 additions & 0 deletions src/main/java/yetmorecode/ghidra/format/lx/ObjectTableEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package yetmorecode.ghidra.format.lx;

import java.io.IOException;
import java.util.ArrayList;

import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;

public class ObjectTableEntry extends yetmorecode.file.format.lx.ObjectTableEntry {

public ObjectTableEntry(FactoryBundledWithBinaryReader reader, int index) throws IOException {
long oldIndex = reader.getPointerIndex();
reader.setPointerIndex(index);
size = reader.readNextInt();
base = reader.readNextInt();
flags = reader.readNextInt();
pageTableIndex = reader.readNextInt();
pageCount = reader.readNextInt();
reader.setPointerIndex(oldIndex);
}

public String getPermissionFlagsLabel() {
return String.format(
"%s%s%s",
(flags & FLAG_READABLE) > 0 ? "r" : "-",
(flags & FLAG_WRITEABLE) > 0 ? "w" : "-",
(flags & FLAG_EXECUTABLE) > 0 ? "x" : "-"
);
}

public String getExtraFlagsLabel() {
ArrayList<String> f = new ArrayList<>();
f.add(getPermissionFlagsLabel());
if ((flags & FLAG_PRELOAD_PAGES) > 0) {
f.add("preload pages");
}
if ((flags & FLAG_1616_ALIAS) > 0) {
f.add("16:16 alias");
}
if ((flags & FLAG_BIG_DEFAULT_BIT) > 0) {
f.add("big default");
}
return String.format("%04x (%s)", flags, String.join(", ", f));
}
}
Loading

0 comments on commit 22064a4

Please sign in to comment.