flop 2
This commit is contained in:
parent
eba135ad2c
commit
1a975a65dc
35
Jocaml.java
35
Jocaml.java
|
@ -389,14 +389,14 @@ public class Jocaml {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unmarshal() throws Exception {
|
public List<Object> unmarshal() throws Exception {
|
||||||
this.data.order(ByteOrder.BIG_ENDIAN);
|
this.data.order(ByteOrder.BIG_ENDIAN);
|
||||||
int magic = this.data.getInt(0);
|
int magic = this.data.getInt(0);
|
||||||
if (magic != MARSHAL_MAGIC_SMALL) {
|
if (magic != MARSHAL_MAGIC_SMALL) {
|
||||||
throw new Exception("bad marshal magic");
|
throw new Exception("bad marshal magic");
|
||||||
}
|
}
|
||||||
|
|
||||||
int byteLength = this.data.getInt(4);
|
// int byteLength = this.data.getInt(4);
|
||||||
int numObjs = this.data.getInt(8);
|
int numObjs = this.data.getInt(8);
|
||||||
System.out.println(numObjs);
|
System.out.println(numObjs);
|
||||||
|
|
||||||
|
@ -411,26 +411,39 @@ public class Jocaml {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(shared.size());
|
System.out.println(shared.size());
|
||||||
|
return objs;
|
||||||
System.out.println(objs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disassemble() throws Exception {
|
public void disassemble(List<String> prim) throws Exception {
|
||||||
this.data.order(ByteOrder.LITTLE_ENDIAN);
|
this.data.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.data.position(0);
|
this.data.position(0);
|
||||||
|
int offset = 0;
|
||||||
while (this.data.position() < this.data.capacity()) {
|
while (this.data.position() < this.data.capacity()) {
|
||||||
int op = this.data.getInt();
|
int op = this.data.getInt();
|
||||||
String rep = null;
|
String rep = null;
|
||||||
try {
|
try {
|
||||||
CamlInst inst = CamlInst.values()[op];
|
CamlInst inst = CamlInst.values()[op];
|
||||||
rep = inst.name();
|
rep = inst.name();
|
||||||
|
if (inst == CamlInst.C_CALL1 || inst == CamlInst.C_CALL2
|
||||||
|
|| inst == CamlInst.C_CALL3 || inst == CamlInst.C_CALL4
|
||||||
|
|| inst == CamlInst.C_CALL5 || inst == CamlInst.C_CALLN) {
|
||||||
|
int p = this.data.getInt();
|
||||||
|
rep += " " + prim.get(p);
|
||||||
|
if (inst == CamlInst.C_CALLN) {
|
||||||
|
int n = this.data.getInt();
|
||||||
|
rep += " " + n;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (int i = 0; i < inst.numArgs; i++) {
|
for (int i = 0; i < inst.numArgs; i++) {
|
||||||
rep += " " + this.data.getInt();
|
rep += " " + this.data.getInt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
rep = "<UNKNOWN " + op + ">";
|
rep = "<UNKNOWN " + op + ">";
|
||||||
}
|
}
|
||||||
|
System.out.printf("%04d: ", offset);
|
||||||
System.out.println(rep);
|
System.out.println(rep);
|
||||||
|
offset += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,9 +492,13 @@ public class Jocaml {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(Arrays.toString(sections));
|
System.out.println(Arrays.toString(sections));
|
||||||
findSection(sections, "SYMB").unmarshal();
|
List<Object> symb = findSection(sections, "SYMB").unmarshal();
|
||||||
findSection(sections, "CRCS").unmarshal();
|
System.out.println(symb);
|
||||||
findSection(sections, "DATA").unmarshal();
|
List<Object> crcs = findSection(sections, "CRCS").unmarshal();
|
||||||
findSection(sections, "CODE").disassemble();
|
System.out.println(crcs);
|
||||||
|
List<Object> data = findSection(sections, "DATA").unmarshal();
|
||||||
|
System.out.println(data);
|
||||||
|
List<String> prim = findSection(sections, "PRIM").unstring();
|
||||||
|
findSection(sections, "CODE").disassemble(prim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue