-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpjxe.py
144 lines (130 loc) · 4.54 KB
/
dumpjxe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import sys
from construct import *
input = open(sys.argv[1], "rb")
data = input.read()
input.close()
def deco(obj, ctx):
if obj._ptr == 0:
print "Obj: " + repr(obj)
print "Ctx: " + repr(ctx)
return obj._base + obj._ptr
def Relative(name):
return ExprAdapter(Struct(name, Anchor("base"), SLInt32("ptr")),
encoder = None,
decoder = lambda obj, ctx: obj.base + obj.ptr if obj.ptr != 0 else None)
#decoder = deco)
def SetAddr(obj, ctx):
obj.addr = obj.base + obj.ptr
return obj
def DebugRelative(name):
return ExprAdapter(Struct(name, Anchor("base"), SLInt32("ptr")),
encoder = None,
decoder = SetAddr)
#decoder = deco)
def MaybePointer(ptr, struct):
return If(lambda ctx: ptr(ctx) is not None, Pointer(ptr, struct))
def StringPointer(ptr, name):
return MaybePointer(ptr, PascalString(name, length_field=ULInt16("length")))
def StringRef(name):
return ExprAdapter(
Struct(name,
Relative("ptr"),
StringPointer(lambda ctx: ctx.ptr, "str")
),
encoder = None,
decoder = lambda obj, ctx: obj.str)
def BytecodeSize(ctx):
size = ctx.bytecode_size_low;
mods = ctx.modifiers
if mods.use_bytecodesize_high:
size += ctx.bytecode_size_high << 16;
size *= 4
if mods.add_four1:
size += 4
return size
J9ROMImageHeader = Struct("J9ROMImageHeader",
Enum(ULInt32("signature"),
CORRECT = 1245264202,
_default_ = Pass,
),
ULInt32("flags_and_version"),
ULInt32("rom_size"),
ULInt32("class_count"),
Relative("jxe_pointer"),
Relative("toc_pointer"),
Relative("first_class_pointer"),
Relative("aot_pointer"),
Array(16, ULInt8("symbol_file_id")),
Pointer(lambda ctx: ctx.toc_pointer, Array(lambda ctx: min(99999, ctx.class_count),
Struct("J9ROMClassTOCEntry",
StringRef("class_name"),
Relative("class_pointer"),
MaybePointer(lambda ctx: ctx.class_pointer, Struct("J9ROMClass",
ULInt32("rom_size"),
ULInt32("single_scalar_static_count"),
StringRef("class_name"),
StringRef("superclass_name"),
ULInt32("modifiers"),
ULInt32("interface_count"),
Relative("interfaces_pointer"),
ULInt32("rom_method_count"),
Relative("rom_methods_pointer"),
ULInt32("rom_field_count"),
Relative("rom_fields_pointer"),
ULInt32("object_static_count"),
ULInt32("double_scalar_static_count"),
ULInt32("ram_constant_pool_count"),
ULInt32("rom_constant_pool_count"),
ULInt32("crc"),
ULInt32("instance_size"),
ULInt32("instance_shape"),
Relative("cp_shape_description_pointer"),
Relative("outer_class_name_pointer"),
ULInt32("member_access_flags"),
ULInt32("inner_class_count"),
Relative("inner_classes_pointer"),
ULInt16("major_version"),
ULInt16("minor_version"),
ULInt32("optional_flags"),
Relative("optional_info_pointer"),
MaybePointer(lambda ctx: ctx.interfaces_pointer, Array(lambda ctx: ctx.interface_count, StringRef("interfaces"))),
MaybePointer(lambda ctx: ctx.rom_methods_pointer, Array(lambda ctx: ctx.rom_method_count, Struct("method",
StringRef("name"),
StringRef("signature"),
# xx8xxxxx -> use_bytecodesize_high
# xxxxxxx2 -> add_four1
# xxxxx2xx -> use_relative_bytecode
# xxxx4xxx -> add_four2
BitStruct("modifiers",
BitField("unknown1", 8),
Flag("use_bytecodesize_high"),
BitField("unknown2", 8),
Flag("add_four2"),
BitField("unknown3", 4),
Flag("has_bytecode_extra"),
BitField("unknown4", 7),
Flag("add_four1"),
BitField("unknown5", 1),
),
ULInt16("max_stack"),
ULInt16("bytecode_size_low"),
ULInt8("bytecode_size_high"),
ULInt8("arg_count"),
ULInt16("temp_count"),
Value("bytecodesize", BytecodeSize),
Padding(BytecodeSize),
If(lambda ctx: ctx.modifiers.has_bytecode_extra, Struct("bytecode_extra",
ULInt16("size16"), ULInt16("size4"),
Padding(lambda ctx: ctx.size16 * 16 + ctx.size4 * 4),
))
))),
Array(lambda ctx: ctx.rom_constant_pool_count, Struct("constant",
Union("data", ULInt32("data"), Relative("ptr")),
ULInt32("metadata"),
)),
)),
)
)),
)
header = J9ROMImageHeader.parse(data)
print header