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);
|
||||
int magic = this.data.getInt(0);
|
||||
if (magic != MARSHAL_MAGIC_SMALL) {
|
||||
throw new Exception("bad marshal magic");
|
||||
}
|
||||
|
||||
int byteLength = this.data.getInt(4);
|
||||
// int byteLength = this.data.getInt(4);
|
||||
int numObjs = this.data.getInt(8);
|
||||
System.out.println(numObjs);
|
||||
|
||||
|
@ -411,26 +411,39 @@ public class Jocaml {
|
|||
}
|
||||
|
||||
System.out.println(shared.size());
|
||||
|
||||
System.out.println(objs);
|
||||
return objs;
|
||||
}
|
||||
|
||||
public void disassemble() throws Exception {
|
||||
public void disassemble(List<String> prim) throws Exception {
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.data.position(0);
|
||||
int offset = 0;
|
||||
while (this.data.position() < this.data.capacity()) {
|
||||
int op = this.data.getInt();
|
||||
String rep = null;
|
||||
try {
|
||||
CamlInst inst = CamlInst.values()[op];
|
||||
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++) {
|
||||
rep += " " + this.data.getInt();
|
||||
}
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
rep = "<UNKNOWN " + op + ">";
|
||||
}
|
||||
System.out.printf("%04d: ", offset);
|
||||
System.out.println(rep);
|
||||
offset += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,9 +492,13 @@ public class Jocaml {
|
|||
}
|
||||
|
||||
System.out.println(Arrays.toString(sections));
|
||||
findSection(sections, "SYMB").unmarshal();
|
||||
findSection(sections, "CRCS").unmarshal();
|
||||
findSection(sections, "DATA").unmarshal();
|
||||
findSection(sections, "CODE").disassemble();
|
||||
List<Object> symb = findSection(sections, "SYMB").unmarshal();
|
||||
System.out.println(symb);
|
||||
List<Object> crcs = findSection(sections, "CRCS").unmarshal();
|
||||
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