Skip to content

Commit 5357e43

Browse files
committed
Initial LE format (Linear executable)
0 parents  commit 5357e43

11 files changed

+1782
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package yetmorecode.format.exception;
2+
3+
/**
4+
* An exception class to handle encountering
5+
* invalid LX/LE Headers.
6+
*/
7+
public class InvalidHeaderException extends Exception {
8+
private static final long serialVersionUID = 1L;
9+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package yetmorecode.format.lx;
2+
3+
/**
4+
* The Object page table provides information about a logical page in an object.
5+
*
6+
* A logical page may be an enumerated page, a pseudo page or an iterated page.
7+
* The structure of the object page table in conjunction with the structure of the object table
8+
* allows for efficient access of a page when a page fault occurs, while still allowing the
9+
* physical page data to be located in the preload page, demand load page or
10+
* iterated data page sections in the linear EXE module.
11+
*
12+
* The logical page entries in the Object Page Table are numbered starting from one.
13+
*
14+
* The Object Page Table is parallel to the Fixup Page Table as they are both indexed by the logical page number.
15+
*
16+
* Each Object Page Table entry has the following format:
17+
*
18+
* 32 8 7 0
19+
* +-----+-----+-----+-----+-----+-----+-----+-----+
20+
* 00h | PAGE NUMBER | FLAGS |
21+
* +-----+-----+-----+-----+-----+-----+-----+-----+
22+
*
23+
* @author https://github.com/yetmorecode
24+
*
25+
*/
26+
public class LeObjectPageTableEntry implements ObjectPageTableEntry {
27+
/**
28+
* Size of an LE object page table entry
29+
*/
30+
public final static int SIZE = 0x4;
31+
32+
/**
33+
* PAGE Number = 24bit Offset to the page data in the EXE file.
34+
*
35+
* This field, when bit shifted left by the PAGE OFFSET SHIFT from the module header,
36+
* specifies the offset from the beginning of the Preload Page section of the physical
37+
* page data in the EXE file that corresponds to this logical page entry. The page data
38+
* may reside in the Preload Pages, Demand Load Pages or the Iterated Data Pages
39+
* sections.
40+
*
41+
* A page might not start at the next available alignment boundary. Extra padding is
42+
* acceptable between pages as long as each page starts on an alignment boundary.
43+
*
44+
* For example, several alignment boundaries may be skipped in order to start a
45+
* frequently accessed page on a sector boundary.
46+
* If the FLAGS field specifies that this is a Zero-Filled page then the PAGE DATA
47+
* OFFSET field will contain a 0.
48+
*
49+
* If the logical page is specified as an iterated data page, as indicated by the FLAGS
50+
* field, then this field specifies the offset into the Iterated Data Pages section.
51+
* The logical page number (Object Page Table index), is used to index the Fixup Page
52+
* Table to find any fixups associated with the logical page.
53+
*
54+
*/
55+
public int dataOffset;
56+
57+
/**
58+
* 00h = Legal Physical Page in the module (Offset from Preload Page Section).
59+
*/
60+
public final static short FLAG_LEGAL = 0x0;
61+
62+
/**
63+
* 01h = Iterated Data Page (Offset from Iterated Data Pages Section).
64+
*/
65+
public final static short FLAG_ITERATED = 0x1;
66+
67+
/**
68+
* 02h = Invalid Page (zero).
69+
*/
70+
public final static short FLAG_INVALID = 0x2;
71+
72+
/**
73+
* 03h = Zero Filled Page (zero).
74+
*/
75+
public final static short FLAG_ZERO = 0x3;
76+
77+
/**
78+
* 04h = Range of Pages.
79+
*/
80+
public final static short FLAG_RANGE = 0x4;
81+
82+
/**
83+
* 05h = Compressed Page (Offset from Preload Pages Section).
84+
*/
85+
public final static short FLAG_COMPRESSED = 0x5;
86+
87+
/**
88+
* FLAGS = DW Attributes specifying characteristics of this logical page.
89+
*
90+
* The bit definitions for this word field follow,
91+
* 00h = Legal Physical Page in the module (Offset from Preload Page Section).
92+
* 01h = Iterated Data Page (Offset from Iterated Data Pages Section).
93+
* 02h = Invalid Page (zero).
94+
* 03h = Zero Filled Page (zero).
95+
* 04h = Range of Pages.
96+
* 05h = Compressed Page (Offset from Preload Pages Section).
97+
*/
98+
public byte flags;
99+
100+
@Override
101+
public int getOffset() {
102+
return dataOffset;
103+
}
104+
105+
@Override
106+
public short getSize() {
107+
return 0;
108+
}
109+
110+
@Override
111+
public short getFlags() {
112+
// Prevent java sign extension issues
113+
if (flags < 0) {
114+
return (short) (flags + 0x100);
115+
}
116+
return flags;
117+
}
118+
119+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package yetmorecode.format.lx;
2+
3+
import java.util.ArrayList;
4+
5+
import yetmorecode.format.mz.MzHeader;
6+
7+
public class LxExecutable {
8+
/**
9+
* Old-style MS-DOS header (optional)
10+
*/
11+
public MzHeader dosHeader = new MzHeader();
12+
13+
/**
14+
* LX/LE/LC header
15+
*/
16+
public LxHeader header = new LxHeader();
17+
18+
/**
19+
* Object table
20+
*/
21+
public ArrayList<ObjectTableEntry> objectTable = new ArrayList<>();
22+
23+
/**
24+
* The object page table (mapping page numbers to file offsets)
25+
*/
26+
public ArrayList<ObjectPageTableEntry> objectPageTable = new ArrayList<>();
27+
28+
/**
29+
* The fixup record table
30+
*/
31+
public ArrayList<ArrayList<LxFixupRecord>> fixupRecordTable = new ArrayList<>();
32+
33+
/**
34+
* The actual data pages
35+
*/
36+
public ArrayList<byte[]> pages = new ArrayList<>();
37+
}

0 commit comments

Comments
 (0)