ABC Exporter tool - view constants - WIP

This commit is contained in:
Jindra Petřík
2023-09-29 11:45:42 +02:00
parent b70b5547a0
commit 9fa19e598f
7 changed files with 664 additions and 3 deletions

View File

@@ -134,6 +134,8 @@ public class ABC implements Openable {
private OpenableList openableList;
private boolean isOpenable = false;
private long dataSize = 0L;
public ABC(ABCContainerTag tag) {
this.parentTag = tag;
@@ -570,11 +572,14 @@ public class ABC implements Openable {
isOpenable = true;
}
long posBefore = ais.getPosition();
try {
read(ais, swf);
} catch (IOException ie) {
throw new ABCOpenException(AppResources.translate("error.abc.invalid"), ie);
}
long posAfter = ais.getPosition();
dataSize = posAfter - posBefore;
//this will read all method body codes. TODO: make this ondemand
refreshMultinameNamespaceSuffixes();
getMethodIndexing();
@@ -808,7 +813,7 @@ public class ABC implements Openable {
}
public void saveToStream(OutputStream os) throws IOException {
ABCOutputStream aos = new ABCOutputStream(os);
ABCOutputStream aos = new ABCOutputStream(os);
aos.writeU16(version.minor);
aos.writeU16(version.major);
@@ -918,6 +923,7 @@ public class ABC implements Openable {
}
aos.writeTraits(mb.traits);
}
dataSize = aos.getPosition();
}
public MethodBody findBody(MethodInfo methodInfo) {
@@ -2476,4 +2482,8 @@ public class ABC implements Openable {
}
return false;
}
public long getDataSize() {
return dataSize;
}
}

View File

@@ -39,16 +39,34 @@ import java.io.OutputStream;
public class ABCOutputStream extends OutputStream {
private final OutputStream os;
private long position = 0L;
public ABCOutputStream(OutputStream os) {
this.os = os;
}
public long getPosition() {
return position;
}
@Override
public void write(int b) throws IOException {
os.write(b);
position++;
}
@Override
public void write(byte[] data) throws IOException {
super.write(data);
position += data.length;
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
super.write(b, off, len);
position += len;
}
public void writeU30(long value) throws IOException {
writeS32(value);
/*boolean loop = true;

View File

@@ -269,7 +269,7 @@ public class Multiname {
return constants.getNamespace(index).getKindStr() + "(" + (name == null ? "null" : "\"" + Helper.escapePCodeString(name) + "\"") + (sub > 0 ? ",\"" + sub + "\"" : "") + ")";
}
private static String namespaceSetToString(AVM2ConstantPool constants, int index) {
public static String namespaceSetToString(AVM2ConstantPool constants, int index) {
if (index == 0) {
return "null";
}