frame SVG export, cleanup, (java) code formatting

This commit is contained in:
Honfika
2014-04-19 14:38:06 +02:00
parent e73185c204
commit 61fcfb8ec0
49 changed files with 2659 additions and 2466 deletions

View File

@@ -1566,14 +1566,14 @@ public final class SWF implements TreeItem, Timelined {
int frame = fframes.get(fi);
File f = new File(foutdir + File.separator + fframes.get(fi) + ".svg");
try (FileOutputStream fos = new FileOutputStream(f)) {
fos.write(Utf8Helper.getBytes(frameToSvgGet(ftim, frame, 0, null, 0, ftim.displayRect, new Matrix(), new ColorTransform(), fbackgroundColor)));
fos.write(Utf8Helper.getBytes(frameToSvg(ftim, frame, 0, null, 0, new SVGExporterContext(foutdir.toString()), ftim.displayRect, new ColorTransform(), fbackgroundColor, 0)));
}
ret.add(f);
}
}, handler).run();
}
}
final List<BufferedImage> frameImages = new ArrayList<>();
for (int frame : frames) {
frameImages.add(frameToImageGet(tim, frame, 0, null, 0, tim.displayRect, new Matrix(), new ColorTransform(), backgroundColor).getBufferedImage());
@@ -1837,7 +1837,7 @@ public final class SWF implements TreeItem, Timelined {
exportTexts(handler, outdir, tags, mode);
}
public static List<File> exportShapes(AbortRetryIgnoreHandler handler, String outdir, List<Tag> tags, final ShapeExportMode mode) throws IOException {
public static List<File> exportShapes(AbortRetryIgnoreHandler handler, final String outdir, List<Tag> tags, final ShapeExportMode mode) throws IOException {
List<File> ret = new ArrayList<>();
if (tags.isEmpty()) {
return ret;
@@ -1870,7 +1870,7 @@ public final class SWF implements TreeItem, Timelined {
switch (mode) {
case SVG:
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(Utf8Helper.getBytes(st.toSVG(new SVGExporterContext())));
fos.write(Utf8Helper.getBytes(st.toSVG(new SVGExporterContext(outdir), 0)));
}
break;
case PNG:
@@ -1895,7 +1895,7 @@ public final class SWF implements TreeItem, Timelined {
}
//TODO: implement morphshape export. How to handle 65536 frames?
public static List<File> exportMorphShapes(AbortRetryIgnoreHandler handler, String outdir, List<Tag> tags, final MorphshapeExportMode mode) throws IOException {
public static List<File> exportMorphShapes(AbortRetryIgnoreHandler handler, final String outdir, List<Tag> tags, final MorphshapeExportMode mode) throws IOException {
List<File> ret = new ArrayList<>();
if (tags.isEmpty()) {
return ret;
@@ -1925,7 +1925,7 @@ public final class SWF implements TreeItem, Timelined {
switch (mode) {
case SVG:
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(Utf8Helper.getBytes(mst.toSVG(new SVGExporterContext())));
fos.write(Utf8Helper.getBytes(mst.toSVG(new SVGExporterContext(outdir), 0)));
}
break;
}
@@ -2584,24 +2584,13 @@ public final class SWF implements TreeItem, Timelined {
return ret;
}
public static String frameToSvgGet(Timeline timeline, int frame, int time, DepthState stateUnderCursor, int mouseButton, RECT displayRect, Matrix transformation, ColorTransform colorTransform, Color backGroundColor) {
RECT rect = displayRect;
SVGExporter exporter = new SVGExporter(timeline.swf, new ExportRectangle(rect), colorTransform);
public static String frameToSvg(Timeline timeline, int frame, int time, DepthState stateUnderCursor, int mouseButton, SVGExporterContext exporterContext, RECT displayRect, ColorTransform colorTransform, Color backGroundColor, int level) throws IOException {
SVGExporter exporter = new SVGExporter(timeline.swf, new ExportRectangle(displayRect), colorTransform);
if (backGroundColor != null) {
exporter.setBackGroundColor(backGroundColor);
}
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
if (timeline.frames.isEmpty()) {
frameToSvg(timeline, frame, time, stateUnderCursor, mouseButton, exporter, m, colorTransform);
}
return exporter.getSVG();
}
public static void frameToSvg(Timeline timeline, int frame, int time, DepthState stateUnderCursor, int mouseButton, SVGExporter exporter, Matrix transformation, ColorTransform colorTransform) {
float unzoom = (float) SWF.unitDivisor;
if (timeline.frames.size() <= frame) {
return;
return exporter.getSVG();
}
Frame frameObj = timeline.frames.get(frame);
// TODO g.setTransform(transformation.toTransform());
@@ -2627,8 +2616,6 @@ public final class SWF implements TreeItem, Timelined {
continue;
}
CharacterTag character = timeline.swf.characters.get(layer.characterId);
Matrix mat = new Matrix(layer.matrix);
mat = mat.preConcatenate(transformation);
if (colorTransform == null) {
colorTransform = new ColorTransform();
@@ -2641,7 +2628,6 @@ public final class SWF implements TreeItem, Timelined {
if (character instanceof DrawableTag) {
DrawableTag drawable = (DrawableTag) character;
Matrix drawMatrix = new Matrix();
int dframe = (time + layer.time) % drawable.getNumFrames();
if (character instanceof ButtonTag) {
ButtonTag bt = (ButtonTag) character;
@@ -2655,29 +2641,42 @@ public final class SWF implements TreeItem, Timelined {
}
}
String assetFileName;
Tag drawableTag = (Tag) drawable;
if (exporterContext.exportedTags.containsKey(drawableTag)) {
assetFileName = exporterContext.exportedTags.get(drawableTag);
} else {
String assetsDir = exporterContext.outDir + File.separator + "assets";
File foutdir = new File(assetsDir);
if (!foutdir.exists()) {
if (!foutdir.mkdirs()) {
if (!foutdir.exists()) {
throw new IOException("Cannot create directory " + assetsDir);
}
}
}
assetFileName = exporterContext.exportedTags.size() + ".svg";
exporterContext.exportedTags.put(drawableTag, assetFileName);
File file = new File(assetsDir + File.separator + assetFileName);
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(Utf8Helper.getBytes(drawable.toSVG(exporterContext, level + 1)));
}
}
RECT boundRect = drawable.getRect();
ExportRectangle rect = new ExportRectangle(boundRect);
rect = mat.transform(rect);
Matrix m = mat.clone();
m.translate(-rect.xMin, -rect.yMin);
drawMatrix.translate(rect.xMin, rect.yMin);
//drawable.toSVG(dframe, layer.time + time, layer.ratio, stateUnderCursor, mouseButton, exporter, m, clrTrans);
// TODO: drawable.toSVG();
// TODO: if (layer.filters != null)
// TODO: if (layer.blendMode > 1)
drawMatrix.translateX /= unzoom;
drawMatrix.translateY /= unzoom;
AffineTransform trans = drawMatrix.toTransform();
String assetPath = level == 0 ? "assets" + File.separator + assetFileName : assetFileName;
Matrix mat = new Matrix(layer.matrix);
mat.translate(rect.xMin, rect.yMin);
exporter.addImage(mat, boundRect, assetPath);
// TODO: if (layer.clipDepth > -1)...
// TODO: g.setTransform(trans);
}
}
return exporter.getSVG();
}
public static SerializableImage frameToImageGet(Timeline timeline, int frame, int time, DepthState stateUnderCursor, int mouseButton, RECT displayRect, Matrix transformation, ColorTransform colorTransform, Color backGroundColor) {

View File

@@ -1266,203 +1266,202 @@ public class AVM2Code implements Serializable {
String ret = "";
int ip = start;
//try {
//int addr;
iploop:
while (ip <= end) {
//int addr;
iploop:
while (ip <= end) {
if (ignoredIns.contains(ip)) {
ip++;
continue;
}
boolean processTry = processJumps;
//addr = pos2adr(ip);
int ipfix = fixIPAfterDebugLine(ip);
//int addrfix = pos2adr(ipfix);
int maxend = -1;
if (ignoredIns.contains(ip)) {
ip++;
continue;
}
boolean processTry = processJumps;
//addr = pos2adr(ip);
int ipfix = fixIPAfterDebugLine(ip);
//int addrfix = pos2adr(ipfix);
int maxend = -1;
if (ip > end) {
break;
}
if (ip > end) {
break;
}
if (unknownJumps.contains(ip)) {
unknownJumps.remove(Integer.valueOf(ip));
throw new UnknownJumpException(stack, ip, output);
}
if (visited[ip]) {
Logger.getLogger(AVM2Code.class.getName()).warning("Code already visited, ofs:" + Helper.formatAddress(pos2adr(ip)) + ", ip:" + ip);
break;
}
visited[ip] = true;
AVM2Instruction ins = code.get(ip);
if (debugMode) {
System.err.println("translating ip " + ip + " ins " + ins.toString() + " stack:" + stack.toString() + " scopeStack:" + scopeStack.toString());
}
if (ins.definition instanceof NewFunctionIns) {
if (ip + 1 <= end) {
if (code.get(ip + 1).definition instanceof PopIns) {
ip += 2;
continue;
}
if (unknownJumps.contains(ip)) {
unknownJumps.remove(Integer.valueOf(ip));
throw new UnknownJumpException(stack, ip, output);
}
if (visited[ip]) {
Logger.getLogger(AVM2Code.class.getName()).warning("Code already visited, ofs:" + Helper.formatAddress(pos2adr(ip)) + ", ip:" + ip);
break;
}
visited[ip] = true;
AVM2Instruction ins = code.get(ip);
if (debugMode) {
System.err.println("translating ip " + ip + " ins " + ins.toString() + " stack:" + stack.toString() + " scopeStack:" + scopeStack.toString());
}
if (ins.definition instanceof NewFunctionIns) {
if (ip + 1 <= end) {
if (code.get(ip + 1).definition instanceof PopIns) {
ip += 2;
continue;
}
}
/*if ((ip + 8 < code.size())) { //return in finally clause
if (ins.definition instanceof SetLocalTypeIns) {
if (code.get(ip + 1).definition instanceof PushByteIns) {
AVM2Instruction jmp = code.get(ip + 2);
if (jmp.definition instanceof JumpIns) {
if (jmp.operands[0] == 0) {
if (code.get(ip + 3).definition instanceof LabelIns) {
if (code.get(ip + 4).definition instanceof PopIns) {
if (code.get(ip + 5).definition instanceof LabelIns) {
AVM2Instruction gl = code.get(ip + 6);
if (gl.definition instanceof GetLocalTypeIns) {
if (((GetLocalTypeIns) gl.definition).getRegisterId(gl) == ((SetLocalTypeIns) ins.definition).getRegisterId(ins)) {
AVM2Instruction ki = code.get(ip + 7);
if (ki.definition instanceof KillIns) {
if (ki.operands[0] == ((SetLocalTypeIns) ins.definition).getRegisterId(ins)) {
if (code.get(ip + 8).definition instanceof ReturnValueIns) {
ip = ip + 8;
continue;
}
}
}
}
}
}
}
}
}
}
}
}
}//*/
}
/*if ((ip + 8 < code.size())) { //return in finally clause
if (ins.definition instanceof SetLocalTypeIns) {
if (code.get(ip + 1).definition instanceof PushByteIns) {
AVM2Instruction jmp = code.get(ip + 2);
if (jmp.definition instanceof JumpIns) {
if (jmp.operands[0] == 0) {
if (code.get(ip + 3).definition instanceof LabelIns) {
if (code.get(ip + 4).definition instanceof PopIns) {
if (code.get(ip + 5).definition instanceof LabelIns) {
AVM2Instruction gl = code.get(ip + 6);
if (gl.definition instanceof GetLocalTypeIns) {
if (((GetLocalTypeIns) gl.definition).getRegisterId(gl) == ((SetLocalTypeIns) ins.definition).getRegisterId(ins)) {
AVM2Instruction ki = code.get(ip + 7);
if (ki.definition instanceof KillIns) {
if (ki.operands[0] == ((SetLocalTypeIns) ins.definition).getRegisterId(ins)) {
if (code.get(ip + 8).definition instanceof ReturnValueIns) {
ip = ip + 8;
continue;
}
}
}
}
}
}
}
}
}
}
}
}
}//*/
/*if ((ip + 2 < code.size()) && (ins.definition instanceof NewCatchIns)) { //Filling local register in catch clause
if (code.get(ip + 1).definition instanceof DupIns) {
if (code.get(ip + 2).definition instanceof SetLocalTypeIns) {
ins.definition.translate(isStatic, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames);
ip += 3;
continue;
}
}
}*/
if ((ins.definition instanceof GetLocalTypeIns) && (!output.isEmpty()) && (output.get(output.size() - 1) instanceof SetLocalAVM2Item) && (((SetLocalAVM2Item) output.get(output.size() - 1)).regIndex == ((GetLocalTypeIns) ins.definition).getRegisterId(ins)) && isKilled(((SetLocalAVM2Item) output.get(output.size() - 1)).regIndex, start, end)) {
SetLocalAVM2Item slt = (SetLocalAVM2Item) output.remove(output.size() - 1);
stack.push(slt.getValue());
/*if ((ip + 2 < code.size()) && (ins.definition instanceof NewCatchIns)) { //Filling local register in catch clause
if (code.get(ip + 1).definition instanceof DupIns) {
if (code.get(ip + 2).definition instanceof SetLocalTypeIns) {
ins.definition.translate(isStatic, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames);
ip += 3;
continue;
}
}
}*/
if ((ins.definition instanceof GetLocalTypeIns) && (!output.isEmpty()) && (output.get(output.size() - 1) instanceof SetLocalAVM2Item) && (((SetLocalAVM2Item) output.get(output.size() - 1)).regIndex == ((GetLocalTypeIns) ins.definition).getRegisterId(ins)) && isKilled(((SetLocalAVM2Item) output.get(output.size() - 1)).regIndex, start, end)) {
SetLocalAVM2Item slt = (SetLocalAVM2Item) output.remove(output.size() - 1);
stack.push(slt.getValue());
ip++;
} else if ((ins.definition instanceof SetLocalTypeIns) && (ip + 1 <= end) && (isKilled(((SetLocalTypeIns) ins.definition).getRegisterId(ins), ip, end))) { //set_local_x,get_local_x..kill x
AVM2Instruction insAfter = code.get(ip + 1);
if ((insAfter.definition instanceof GetLocalTypeIns) && (((GetLocalTypeIns) insAfter.definition).getRegisterId(insAfter) == ((SetLocalTypeIns) ins.definition).getRegisterId(ins))) {
GraphTargetItem before = stack.peek();
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
stack.push(before);
ip += 2;
continue iploop;
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
} else if ((ins.definition instanceof SetLocalTypeIns) && (ip + 1 <= end) && (isKilled(((SetLocalTypeIns) ins.definition).getRegisterId(ins), ip, end))) { //set_local_x,get_local_x..kill x
continue iploop;
}
} else if (ins.definition instanceof DupIns) {
int nextPos;
do {
AVM2Instruction insAfter = code.get(ip + 1);
if ((insAfter.definition instanceof GetLocalTypeIns) && (((GetLocalTypeIns) insAfter.definition).getRegisterId(insAfter) == ((SetLocalTypeIns) ins.definition).getRegisterId(ins))) {
GraphTargetItem before = stack.peek();
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
stack.push(before);
ip += 2;
continue iploop;
AVM2Instruction insBefore = ins;
if (ip - 1 >= start) {
insBefore = code.get(ip - 1);
}
if (insAfter.definition instanceof ConvertBIns) { //SWF compiled with debug contain convert_b
ip++;
//addr = pos2adr(ip);
insAfter = code.get(ip + 1);
}
boolean isAnd;
if (processJumps && (insAfter.definition instanceof IfFalseIns)) {
//stack.add("(" + stack.pop() + ")&&");
isAnd = true;
} else if (processJumps && (insAfter.definition instanceof IfTrueIns)) {
//stack.add("(" + stack.pop() + ")||");
isAnd = false;
} else if (insAfter.definition instanceof SetLocalTypeIns) {
//chained assignments
int reg = (((SetLocalTypeIns) insAfter.definition).getRegisterId(insAfter));
for (int t = ip + 1; t <= end - 1; t++) {
if (code.get(t).definition instanceof KillIns) {
if (code.get(t).operands[0] == reg) {
break;
}
}
if (code.get(t).definition instanceof GetLocalTypeIns) {
if (((GetLocalTypeIns) code.get(t).definition).getRegisterId(code.get(t)) == reg) {
if (code.get(t + 1).definition instanceof KillIns) {
if (code.get(t + 1).operands[0] == reg) {
ConvertOutput assignment = toSourceOutput(path, part, processJumps, isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, abc, constants, method_info, body, ip + 2, t - 1, localRegNames, fullyQualifiedNames, visited, localRegAssigmentIps, refs);
GraphTargetItem tar = assignment.output.remove(assignment.output.size() - 1);
tar.firstPart = part;
stack.push(tar);
ip = t + 2;
continue iploop;
}
}
}
}
}
if (!isKilled(reg, 0, end)) {
for (int i = ip; i >= start; i--) {
if (code.get(i).definition instanceof DupIns) {
if (stack.isEmpty()) {
break;//FIXME?o
}
GraphTargetItem v = stack.pop();
stack.push(new LocalRegAVM2Item(ins, reg, v));
stack.push(v);
} else {
break;
}
}
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
}
ip++;
break;
//}
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
continue iploop;
break;
//throw new ConvertException("Unknown pattern after DUP:" + insComparsion.toString());
}
} else if (ins.definition instanceof DupIns) {
int nextPos;
do {
AVM2Instruction insAfter = code.get(ip + 1);
AVM2Instruction insBefore = ins;
if (ip - 1 >= start) {
insBefore = code.get(ip - 1);
}
if (insAfter.definition instanceof ConvertBIns) { //SWF compiled with debug contain convert_b
ip++;
//addr = pos2adr(ip);
insAfter = code.get(ip + 1);
}
boolean isAnd;
if (processJumps && (insAfter.definition instanceof IfFalseIns)) {
//stack.add("(" + stack.pop() + ")&&");
isAnd = true;
} else if (processJumps && (insAfter.definition instanceof IfTrueIns)) {
//stack.add("(" + stack.pop() + ")||");
isAnd = false;
} else if (insAfter.definition instanceof SetLocalTypeIns) {
//chained assignments
int reg = (((SetLocalTypeIns) insAfter.definition).getRegisterId(insAfter));
for (int t = ip + 1; t <= end - 1; t++) {
if (code.get(t).definition instanceof KillIns) {
if (code.get(t).operands[0] == reg) {
break;
}
} while (ins.definition instanceof DupIns);
} else if ((ins.definition instanceof ReturnValueIns) || (ins.definition instanceof ReturnVoidIns) || (ins.definition instanceof ThrowIns)) {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
//ip = end + 1;
break;
} else if (ins.definition instanceof NewFunctionIns) {
String functionName = "";
if ((ip >= start + 2) && (ip <= end - 4)) {
AVM2Instruction prev2 = code.get(ip - 2);
if (prev2.definition instanceof NewObjectIns) {
if (prev2.operands[0] == 0) {
if (code.get(ip - 1).definition instanceof PushWithIns) {
boolean hasDup = false;
int plus = 0;
if (code.get(ip + 1).definition instanceof DupIns) {
hasDup = true;
plus = 1;
}
if (code.get(t).definition instanceof GetLocalTypeIns) {
if (((GetLocalTypeIns) code.get(t).definition).getRegisterId(code.get(t)) == reg) {
if (code.get(t + 1).definition instanceof KillIns) {
if (code.get(t + 1).operands[0] == reg) {
ConvertOutput assignment = toSourceOutput(path, part, processJumps, isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, abc, constants, method_info, body, ip + 2, t - 1, localRegNames, fullyQualifiedNames, visited, localRegAssigmentIps, refs);
GraphTargetItem tar = assignment.output.remove(assignment.output.size() - 1);
tar.firstPart = part;
stack.push(tar);
ip = t + 2;
continue iploop;
}
}
}
}
}
if (!isKilled(reg, 0, end)) {
for (int i = ip; i >= start; i--) {
if (code.get(i).definition instanceof DupIns) {
if (stack.isEmpty()) {
break;//FIXME?o
}
GraphTargetItem v = stack.pop();
stack.push(new LocalRegAVM2Item(ins, reg, v));
stack.push(v);
} else {
break;
}
}
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
}
ip++;
break;
//}
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
break;
//throw new ConvertException("Unknown pattern after DUP:" + insComparsion.toString());
}
} while (ins.definition instanceof DupIns);
} else if ((ins.definition instanceof ReturnValueIns) || (ins.definition instanceof ReturnVoidIns) || (ins.definition instanceof ThrowIns)) {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
//ip = end + 1;
break;
} else if (ins.definition instanceof NewFunctionIns) {
String functionName = "";
if ((ip >= start + 2) && (ip <= end - 4)) {
AVM2Instruction prev2 = code.get(ip - 2);
if (prev2.definition instanceof NewObjectIns) {
if (prev2.operands[0] == 0) {
if (code.get(ip - 1).definition instanceof PushWithIns) {
boolean hasDup = false;
int plus = 0;
if (code.get(ip + 1).definition instanceof DupIns) {
hasDup = true;
plus = 1;
}
AVM2Instruction psco = code.get(ip + 1 + plus);
if (psco.definition instanceof GetScopeObjectIns) {
if (psco.operands[0] == scopeStack.size() - 1) {
if (code.get(ip + plus + 2).definition instanceof SwapIns) {
if (code.get(ip + plus + 4).definition instanceof PopScopeIns) {
if (code.get(ip + plus + 3).definition instanceof SetPropertyIns) {
functionName = abc.constants.getMultiname(code.get(ip + plus + 3).operands[0]).getName(constants, fullyQualifiedNames);
scopeStack.pop();//with
output.remove(output.size() - 1); //with
ip = ip + plus + 4; //+1 below
}
AVM2Instruction psco = code.get(ip + 1 + plus);
if (psco.definition instanceof GetScopeObjectIns) {
if (psco.operands[0] == scopeStack.size() - 1) {
if (code.get(ip + plus + 2).definition instanceof SwapIns) {
if (code.get(ip + plus + 4).definition instanceof PopScopeIns) {
if (code.get(ip + plus + 3).definition instanceof SetPropertyIns) {
functionName = abc.constants.getMultiname(code.get(ip + plus + 3).operands[0]).getName(constants, fullyQualifiedNames);
scopeStack.pop();//with
output.remove(output.size() - 1); //with
ip = ip + plus + 4; //+1 below
}
}
}
@@ -1471,41 +1470,42 @@ public class AVM2Code implements Serializable {
}
}
}
//What to do when hasDup is false?
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
NewFunctionAVM2Item nft = (NewFunctionAVM2Item) stack.peek();
nft.functionName = functionName;
ip++;
} else {
try{
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
}catch(RuntimeException re){
/*String last="";
int len=5;
for(int i=(ip-len<0?0:ip-len);i<ip+len && ip<code.size();i++){
if(i==ip){
last+=">";
}
last+=""+i+": "+code.get(i).toString()+"\r\n";
}
Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "ins list:\r\n{0}", last);*/
throw re;
}
ip++;
//addr = pos2adr(ip);
}
//What to do when hasDup is false?
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
NewFunctionAVM2Item nft = (NewFunctionAVM2Item) stack.peek();
nft.functionName = functionName;
ip++;
} else {
try {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
} catch (RuntimeException re) {
/*String last="";
int len=5;
for(int i=(ip-len<0?0:ip-len);i<ip+len && ip<code.size();i++){
if(i==ip){
last+=">";
}
last+=""+i+": "+code.get(i).toString()+"\r\n";
}
Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "ins list:\r\n{0}", last);*/
throw re;
}
ip++;
//addr = pos2adr(ip);
}
}
if (debugMode) {
System.out.println("CLOSE SubSource:" + start + "-" + end + " " + code.get(start).toString() + " to " + code.get(end).toString());
}
/*if (hideTemporaryRegisters) {
clearTemporaryRegisters(output);
}*/
return new ConvertOutput(stack, output);
}
if (debugMode) {
System.out.println("CLOSE SubSource:" + start + "-" + end + " " + code.get(start).toString() + " to " + code.get(end).toString());
}
/*if (hideTemporaryRegisters) {
clearTemporaryRegisters(output);
}*/
return new ConvertOutput(stack, output);
/*} catch (ConvertException cex) {
throw cex;
}*/
throw cex;
}*/
}
public int getRegisterCount() {

View File

@@ -70,7 +70,7 @@ public class AVM2Instruction implements Serializable, GraphSourceItem {
case AVM2Code.OPT_S24:
aos.writeS24(operands[i]);
break;
case AVM2Code.OPT_U30:
case AVM2Code.OPT_U30:
aos.writeU30(operands[i]);
break;
case AVM2Code.OPT_U8:

View File

@@ -50,8 +50,8 @@ public class GetPropertyIns extends InstructionDefinition {
int multinameIndex = ins.operands[0];
//Note: In official compiler, the stack can be wrong(greater) for some MULTINAMEL/A, e.g. increments
/*
var arr=[1,2,3];
return arr[2]++;
var arr=[1,2,3];
return arr[2]++;
*/
if (abc.constants.getMultiname(multinameIndex).needsName()) {
ret--;

View File

@@ -35,7 +35,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreDecrementAVM2Item
import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -136,9 +135,9 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
int multinameIndex = ins.operands[0];
//Note: In official compiler, the stack can be wrong(greater) for some MULTINAMEL/A, e.g. increments
/*
var arr=[1,2,3];
trace(arr[2]++);
*/
var arr=[1,2,3];
trace(arr[2]++);
*/
if (abc.constants.getMultiname(multinameIndex).needsName()) {
ret--;
}

View File

@@ -116,7 +116,7 @@ public class CoerceAVM2Item extends AVM2Item {
ins = new AVM2Instruction(0, new CoerceSIns(), new int[]{}, new byte[0]);
break;
default:
int type_index = AVM2SourceGenerator.resolveType(new TypeItem(type),(((AVM2SourceGenerator) generator).abc));
int type_index = AVM2SourceGenerator.resolveType(new TypeItem(type), (((AVM2SourceGenerator) generator).abc));
ins = new AVM2Instruction(0, new CoerceIns(), new int[]{type_index}, new byte[0]);
break;
}

View File

@@ -61,6 +61,5 @@ public class DefaultXMLNamespace extends AVM2Item {
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, ns, ins(new DXNSLateIns()));
}
}

View File

@@ -19,7 +19,6 @@ package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXAttrIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXElemIns;
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
@@ -58,7 +57,7 @@ public class EscapeXAttrAVM2Item extends AVM2Item {
public boolean hasReturnValue() {
return true;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, ins(new EscXAttrIns()));

View File

@@ -34,7 +34,6 @@ import java.util.List;
*/
public class EscapeXElemAVM2Item extends AVM2Item {
public EscapeXElemAVM2Item(AVM2Instruction instruction, GraphTargetItem expression) {
super(instruction, NOPRECEDENCE);
this.value = expression;
@@ -61,6 +60,5 @@ public class EscapeXElemAVM2Item extends AVM2Item {
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, ins(new EscXElemIns()));
}
}

View File

@@ -35,7 +35,6 @@ public class GetDescendantsAVM2Item extends AVM2Item {
public List<Integer> openedNamespaces;
public String nameStr;
//constructor for compiler
public GetDescendantsAVM2Item(GraphTargetItem object, String nameStr, List<Integer> openedNamespaces) {
super(null, PRECEDENCE_PRIMARY);
@@ -43,7 +42,7 @@ public class GetDescendantsAVM2Item extends AVM2Item {
this.nameStr = nameStr;
this.openedNamespaces = openedNamespaces;
}
public GetDescendantsAVM2Item(AVM2Instruction instruction, GraphTargetItem object, GraphTargetItem multiname) {
super(instruction, PRECEDENCE_PRIMARY);
this.object = object;
@@ -69,8 +68,7 @@ public class GetDescendantsAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return ((AVM2SourceGenerator)generator).generate(localData, this);
return ((AVM2SourceGenerator) generator).generate(localData, this);
}
}

View File

@@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.DeletePropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.UnresolvedAVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;

View File

@@ -153,12 +153,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
nssa[i] = item.openedNamespaces.get(i);
}
int nsset = abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true);
return GraphTargetItem.toSourceMerge(localData, this,
return GraphTargetItem.toSourceMerge(localData, this,
item.object,
ins(new GetDescendantsIns(),abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, abc.constants.getStringId(item.nameStr, true), 0, nsset, 0, new ArrayList<Integer>()), true))
ins(new GetDescendantsIns(), abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, abc.constants.getStringId(item.nameStr, true), 0, nsset, 0, new ArrayList<Integer>()), true))
);
}
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
@@ -279,7 +280,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
return ret;
}
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, XMLFilterAVM2Item item) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
final Reference<Integer> counterReg = new Reference<>(0);
@@ -293,14 +294,14 @@ public class AVM2SourceGenerator implements SourceGenerator {
ins(new CheckFilterIns()),
NameAVM2Item.generateCoerce(this, TypeItem.UNBOUNDED),
AssignableAVM2Item.setTemp(localData, this, collectionReg),
ins(new GetLexIns(),abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId("XMLList", true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<Integer>()), true)),
ins(new PushStringIns(),abc.constants.getStringId("", true)),
ins(new ConstructIns(),1),
ins(new GetLexIns(), abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId("XMLList", true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<Integer>()), true)),
ins(new PushStringIns(), abc.constants.getStringId("", true)),
ins(new ConstructIns(), 1),
xmlListSetTemp
));
));
final Reference<Integer> tempVal1 = new Reference<>(0);
final Reference<Integer> tempVal2 = new Reference<>(0);
List<AVM2Instruction> forBody = toInsList(GraphTargetItem.toSourceMerge(localData, this,
ins(new LabelIns()),
AssignableAVM2Item.getTemp(localData, this, collectionReg),
@@ -308,7 +309,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
ins(new NextValueIns()),
AssignableAVM2Item.dupSetTemp(localData, this, tempVal1),
AssignableAVM2Item.dupSetTemp(localData, this, tempVal2),
ins(new PushWithIns())
ins(new PushWithIns())
));
localData.scopeStack.add(new LocalRegAVM2Item(null, tempVal2.getVal(), null));
forBody.addAll(toInsList(item.value.toSource(localData, this)));
@@ -317,18 +318,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, counterReg)));
trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, tempVal1)));
int nss[] = new int[item.openedNamespaces.size()];
for(int i=0;i<item.openedNamespaces.size();i++){
for (int i = 0; i < item.openedNamespaces.size(); i++) {
nss[i] = item.openedNamespaces.get(i);
}
trueBody.add(ins(new SetPropertyIns(),abc.constants.getMultinameId(new Multiname(Multiname.MULTINAMEL, 0, 0, abc.constants.getNamespaceSetId(new NamespaceSet(nss), true), 0, new ArrayList<Integer>()), true)));
forBody.add(ins(new IfFalseIns(),insToBytes(trueBody).length));
trueBody.add(ins(new SetPropertyIns(), abc.constants.getMultinameId(new Multiname(Multiname.MULTINAMEL, 0, 0, abc.constants.getNamespaceSetId(new NamespaceSet(nss), true), 0, new ArrayList<Integer>()), true)));
forBody.add(ins(new IfFalseIns(), insToBytes(trueBody).length));
forBody.addAll(trueBody);
forBody.add(ins(new PopScopeIns()));
localData.scopeStack.remove(localData.scopeStack.size()-1);
forBody.addAll(toInsList(AssignableAVM2Item.killTemp(localData, this, Arrays.asList(tempVal2,tempVal1))));
localData.scopeStack.remove(localData.scopeStack.size() - 1);
forBody.addAll(toInsList(AssignableAVM2Item.killTemp(localData, this, Arrays.asList(tempVal2, tempVal1))));
int forBodyLen = insToBytes(forBody).length;
AVM2Instruction forwardJump = ins(new JumpIns(), forBodyLen);
ret.add(forwardJump);
@@ -680,20 +679,20 @@ public class AVM2SourceGenerator implements SourceGenerator {
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, FunctionAVM2Item item) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
int scope = 0;
if(!item.functionName.equals("")){
ret.add(ins(new NewObjectIns(),0));
if (!item.functionName.isEmpty()) {
ret.add(ins(new NewObjectIns(), 0));
ret.add(ins(new PushWithIns()));
scope=localData.scopeStack.size();
scope = localData.scopeStack.size();
localData.scopeStack.add(new PropertyAVM2Item(null, item.functionName, null, abc, allABCs, new ArrayList<Integer>(), localData.callStack));
}
ret.add(ins(new NewFunctionIns(), method(localData.callStack, localData.pkg, item.needsActivation, item.subvariables, 0 /*Set later*/, item.hasRest, item.line, null, null, false, localData, item.paramTypes, item.paramNames, item.paramValues, item.body, item.retType)));
if(!item.functionName.equals("")){
if (!item.functionName.isEmpty()) {
ret.add(ins(new DupIns()));
ret.add(ins(new GetScopeObjectIns(),scope));
ret.add(ins(new GetScopeObjectIns(), scope));
ret.add(ins(new SwapIns()));
ret.add(ins(new SetPropertyIns(),abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(item.functionName, true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(localData.pkg, true)), 0, true), 0, 0, new ArrayList<Integer>()), true)));
ret.add(ins(new SetPropertyIns(), abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(item.functionName, true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(localData.pkg, true)), 0, true), 0, 0, new ArrayList<Integer>()), true)));
ret.add(ins(new PopScopeIns()));
localData.scopeStack.remove(localData.scopeStack.size()-1);
localData.scopeStack.remove(localData.scopeStack.size() - 1);
}
return ret;
}
@@ -1154,7 +1153,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
return abc;
}
public void generateClass(List<Integer> openedNamespaces,int namespace, int initScope, PackageAVM2Item pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List<GraphTargetItem> implementsStr, GraphTargetItem constructor, List<GraphTargetItem> traitItems) throws ParseException, CompilationException {
public void generateClass(List<Integer> openedNamespaces, int namespace, int initScope, PackageAVM2Item pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List<GraphTargetItem> implementsStr, GraphTargetItem constructor, List<GraphTargetItem> traitItems) throws ParseException, CompilationException {
localData.currentClass = pkg.packageName.isEmpty() ? name : pkg.packageName + "." + name;
List<GraphSourceItem> ret = new ArrayList<>();
if (extendsVal == null && !isInterface) {
@@ -1164,8 +1163,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
Trait[] it = generateTraitsPhase1(pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits);
Trait[] st = generateTraitsPhase1(pkg, name, superName, true, localData, traitItems, classInfo.static_traits);
generateTraitsPhase2(pkg.packageName,traitItems, it, openedNamespaces, localData);
generateTraitsPhase2(pkg.packageName,traitItems, st, openedNamespaces, localData);
generateTraitsPhase2(pkg.packageName, traitItems, it, openedNamespaces, localData);
generateTraitsPhase2(pkg.packageName, traitItems, st, openedNamespaces, localData);
generateTraitsPhase3(initScope, pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it);
generateTraitsPhase3(initScope, pkg, name, superName, true, localData, traitItems, classInfo.static_traits, st);
if (constructor == null) {
@@ -1232,7 +1231,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
*/
if (cls instanceof ClassAVM2Item) {
ClassAVM2Item cai = (ClassAVM2Item) cls;
generateClass(cai.openedNamespaces,namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits);
generateClass(cai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits);
if (!cai.isDynamic) {
ii.flags |= InstanceInfo.CLASS_SEALED;
}
@@ -1244,7 +1243,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
if (cls instanceof InterfaceAVM2Item) {
InterfaceAVM2Item iai = (InterfaceAVM2Item) cls;
generateClass(iai.openedNamespaces,namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods);
generateClass(iai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods);
ii.flags |= InstanceInfo.CLASS_INTERFACE;
}
@@ -1270,25 +1269,25 @@ public class AVM2SourceGenerator implements SourceGenerator {
return 0;
}
TypeItem nameItem = (TypeItem) type;
name = nameItem.fullTypeName;
TypeItem nameItem = (TypeItem) type;
name = nameItem.fullTypeName;
if (name.contains(".")) {
pkg = name.substring(0, name.lastIndexOf('.'));
name = name.substring(name.lastIndexOf('.') + 1);
}
if(!nameItem.subtypes.isEmpty()){ //It's vector => TypeName
if (!nameItem.subtypes.isEmpty()) { //It's vector => TypeName
List<Integer> params = new ArrayList<>();
for(String p:nameItem.subtypes){
for (String p : nameItem.subtypes) {
String ppkg = "";
if (p.contains(".")) {
ppkg = p.substring(0, p.lastIndexOf('.'));
p = p.substring(p.lastIndexOf('.') + 1);
}
params.add(abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(p), namespace(Namespace.KIND_PACKAGE/*?*/, ppkg), 0, 0, new ArrayList<Integer>()), true));
params.add(abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(p), namespace(Namespace.KIND_PACKAGE/*?*/, ppkg), 0, 0, new ArrayList<Integer>()), true));
}
int qname = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE/*?*/, pkg), 0, 0, new ArrayList<Integer>()), true);
return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0,0, 0, qname, params), true);
}else{
int qname = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE/*?*/, pkg), 0, 0, new ArrayList<Integer>()), true);
return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0, 0, 0, qname, params), true);
} else {
return abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE/*?*/, pkg), 0, 0, new ArrayList<Integer>()), true);
}
}
@@ -1721,78 +1720,76 @@ public class AVM2SourceGenerator implements SourceGenerator {
return null;
}
private int genNs(String custom,int namespace, List<Integer> openedNamespaces, SourceGeneratorLocalData localData){
if(custom!=null){
private int genNs(String custom, int namespace, List<Integer> openedNamespaces, SourceGeneratorLocalData localData) {
if (custom != null) {
PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, null, abc, allABCs, openedNamespaces, new ArrayList<MethodBody>());
Reference<ValueKind> value=new Reference<>(null);
Reference<ValueKind> value = new Reference<>(null);
prop.resolve(localData, new Reference<String>(""), new Reference<String>(""), new Reference<Integer>(0), value);
namespace = value.getVal().value_index;
}
return namespace;
}
public void generateTraitsPhase2(String pkg,List<GraphTargetItem> items,Trait[] traits, List<Integer> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException{
public void generateTraitsPhase2(String pkg, List<GraphTargetItem> items, Trait[] traits, List<Integer> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException {
for (int k = 0; k < items.size(); k++) {
GraphTargetItem item = items.get(k);
if (traits[k] == null) {
continue;
} else if (item instanceof InterfaceAVM2Item) {
traits[k].name_index = traitName(((InterfaceAVM2Item)item).namespace,((InterfaceAVM2Item)item).name);
traits[k].name_index = traitName(((InterfaceAVM2Item) item).namespace, ((InterfaceAVM2Item) item).name);
} else if (item instanceof ClassAVM2Item) {
traits[k].name_index = traitName(((ClassAVM2Item)item).namespace,((ClassAVM2Item)item).className);
traits[k].name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className);
} else if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) {
traits[k].name_index = traitName(genNs(((MethodAVM2Item)item).customNamespace,((MethodAVM2Item)item).namespace, openedNamespaces, localData),((MethodAVM2Item)item).functionName);
traits[k].name_index = traitName(genNs(((MethodAVM2Item) item).customNamespace, ((MethodAVM2Item) item).namespace, openedNamespaces, localData), ((MethodAVM2Item) item).functionName);
} else if (item instanceof FunctionAVM2Item) {
traits[k].name_index = traitName(((FunctionAVM2Item)item).namespace,((FunctionAVM2Item)item).functionName);
} else if(item instanceof ConstAVM2Item){
traits[k].name_index = traitName(genNs(((ConstAVM2Item)item).customNamespace,((ConstAVM2Item)item).getNamespace(), openedNamespaces, localData),((ConstAVM2Item)item).var);
} else if(item instanceof SlotAVM2Item){
traits[k].name_index = traitName(genNs(((SlotAVM2Item)item).customNamespace,((SlotAVM2Item)item).getNamespace(), openedNamespaces, localData),((SlotAVM2Item)item).var);
traits[k].name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName);
} else if (item instanceof ConstAVM2Item) {
traits[k].name_index = traitName(genNs(((ConstAVM2Item) item).customNamespace, ((ConstAVM2Item) item).getNamespace(), openedNamespaces, localData), ((ConstAVM2Item) item).var);
} else if (item instanceof SlotAVM2Item) {
traits[k].name_index = traitName(genNs(((SlotAVM2Item) item).customNamespace, ((SlotAVM2Item) item).getNamespace(), openedNamespaces, localData), ((SlotAVM2Item) item).var);
}
}
for (int k = 0; k < items.size(); k++) {
GraphTargetItem item = items.get(k);
if (traits[k] == null) {
continue;
}
}
if (item instanceof ClassAVM2Item) {
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass)traits[k]).class_info);
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info);
instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true),
abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, true)), 0, true), 0, 0, new ArrayList<Integer>()));
if (((ClassAVM2Item) item).extendsOp != null) {
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
}else{
} else {
instanceInfo.super_index = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList<Integer>()), true);
}
instanceInfo.interfaces = new int[((ClassAVM2Item) item).implementsOp.size()];
for(int i=0;i<((ClassAVM2Item) item).implementsOp.size();i++)
{
instanceInfo.interfaces[i] = typeName(localData,((ClassAVM2Item) item).implementsOp.get(i));
for (int i = 0; i < ((ClassAVM2Item) item).implementsOp.size(); i++) {
instanceInfo.interfaces[i] = typeName(localData, ((ClassAVM2Item) item).implementsOp.get(i));
}
}
if (item instanceof InterfaceAVM2Item) {
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass)traits[k]).class_info);
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info);
instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true),
abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, true)), 0, true), 0, 0, new ArrayList<Integer>()));
instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()];
for(int i=0;i<((InterfaceAVM2Item) item).superInterfaces.size();i++)
{
instanceInfo.interfaces[i] = typeName(localData,((InterfaceAVM2Item) item).superInterfaces.get(i));
for (int i = 0; i < ((InterfaceAVM2Item) item).superInterfaces.size(); i++) {
instanceInfo.interfaces[i] = typeName(localData, ((InterfaceAVM2Item) item).superInterfaces.get(i));
}
}
}
}
public void generateTraitsPhase3(int initScope, PackageAVM2Item pkg, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List<GraphTargetItem> items, Traits ts, Trait[] traits) throws ParseException, CompilationException {
//Note: Names must be generated first before accesed in inner subs
for (int k = 0; k < items.size(); k++) {
GraphTargetItem item = items.get(k);
if (traits[k] == null) {
continue;
}
}
if (item instanceof InterfaceAVM2Item) {
generateClass(((InterfaceAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScope, pkg, localData, (InterfaceAVM2Item) item);
}
@@ -1805,7 +1802,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
if (mai.isStatic() != generateStatic) {
continue;
}
((TraitMethodGetterSetter) traits[k]).method_info = method(new ArrayList<MethodBody>(), pkg.packageName, mai.needsActivation, mai.subvariables, initScope + (mai.isStatic()?0:1), mai.hasRest, mai.line, className, superName, false, localData, mai.paramTypes, mai.paramNames, mai.paramValues, mai.body, mai.retType);
((TraitMethodGetterSetter) traits[k]).method_info = method(new ArrayList<MethodBody>(), pkg.packageName, mai.needsActivation, mai.subvariables, initScope + (mai.isStatic() ? 0 : 1), mai.hasRest, mai.line, className, superName, false, localData, mai.paramTypes, mai.paramNames, mai.paramValues, mai.body, mai.retType);
} else if (item instanceof FunctionAVM2Item) {
FunctionAVM2Item fai = (FunctionAVM2Item) item;
((TraitFunction) traits[k]).method_info = method(new ArrayList<MethodBody>(), pkg.packageName, fai.needsActivation, fai.subvariables, initScope, fai.hasRest, fai.line, className, superName, false, localData, fai.paramTypes, fai.paramNames, fai.paramValues, fai.body, fai.retType);
@@ -1842,17 +1839,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
tc.class_info = abc.instance_info.size() - 1;
/*instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true),
abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg.packageName, true)), 0, true), 0, 0, new ArrayList<Integer>()));
*/
abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg.packageName, true)), 0, true), 0, 0, new ArrayList<Integer>()));
*/
/*if (((ClassAVM2Item) item).extendsOp != null) {
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
} else {
instanceInfo.super_index = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList<Integer>()), true);
}*/
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
} else {
instanceInfo.super_index = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList<Integer>()), true);
}*/
tc.kindType = Trait.TRAIT_CLASS;
// tc.name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className);
// tc.name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className);
tc.slot_id = slot_id++;
ts.traits.add(tc);
traits[k] = tc;
@@ -1890,7 +1886,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
isNamespace = type.toString().equals("Namespace");
isStatic = cai.isStatic();
}
if(isNamespace){
if (isNamespace) {
tsc.name_index = traitName(namespace, var);
}
tsc.type_index = isNamespace ? 0 : (type == null ? 0 : typeName(localData, type));
@@ -1914,8 +1910,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
TraitMethodGetterSetter tmgs = new TraitMethodGetterSetter();
tmgs.kindType = (item instanceof MethodAVM2Item) ? Trait.TRAIT_METHOD : ((item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : Trait.TRAIT_SETTER);
//tmgs.name_index = traitName(((MethodAVM2Item) item).namespace, ((MethodAVM2Item) item).functionName);
tmgs.disp_id = mai.isStatic()?disp_id++:0; //For a reason, there is disp_id only for static methods (or not?)
if (mai.isFinal()||mai.isStatic()) {
tmgs.disp_id = mai.isStatic() ? disp_id++ : 0; //For a reason, there is disp_id only for static methods (or not?)
if (mai.isFinal() || mai.isStatic()) {
tmgs.kindFlags |= Trait.ATTR_Final;
}
if (mai.isOverride()) {
@@ -1932,7 +1928,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
ts.traits.add(tf);
traits[k] = tf;
}
}
}
return traits;
}
@@ -1941,14 +1937,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
ScriptInfo si = new ScriptInfo();
localData.currentScript = si;
Trait[] traitArr = generateTraitsPhase1(pkg, null, null, false, localData, commands, si.traits);
generateTraitsPhase2(pkg.packageName,commands, traitArr, new ArrayList<Integer>(), localData);
generateTraitsPhase2(pkg.packageName, commands, traitArr, new ArrayList<Integer>(), localData);
MethodInfo mi = new MethodInfo(new int[0], 0, 0, 0, new ValueKind[0], new int[0]);
MethodBody mb = new MethodBody();
mb.method_info = abc.addMethodInfo(mi);
mb.code = new AVM2Code();
mb.code.code.add(ins(new GetLocal0Ins()));
mb.code.code.add(ins(new PushScopeIns()));
int traitScope = 1;
@@ -2045,8 +2040,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants));
outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind);
outPropType.setVal(getTraitReturnType(abc, t).toString());
if(t instanceof TraitSlotConst){
TraitSlotConst tsc=(TraitSlotConst)t;
if (t instanceof TraitSlotConst) {
TraitSlotConst tsc = (TraitSlotConst) t;
outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind));
}
return true;
@@ -2069,8 +2064,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants));
outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind);
outPropType.setVal(getTraitReturnType(abc, t).toString());
if(t instanceof TraitSlotConst){
TraitSlotConst tsc=(TraitSlotConst)t;
if (t instanceof TraitSlotConst) {
TraitSlotConst tsc = (TraitSlotConst) t;
outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind));
}
return true;
@@ -2085,8 +2080,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants));
outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind);
outPropType.setVal(getTraitReturnType(abc, t).toString());
if(t instanceof TraitSlotConst){
TraitSlotConst tsc=(TraitSlotConst)t;
if (t instanceof TraitSlotConst) {
TraitSlotConst tsc = (TraitSlotConst) t;
outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind));
}
return true;
@@ -2164,28 +2159,27 @@ public class AVM2SourceGenerator implements SourceGenerator {
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException {
String currentFullClassName = localData.currentClass==null?null:(localData.pkg.equals("")?localData.currentClass:localData.pkg+"."+localData.currentClass);
if(localData.documentClass && item.toString().equals(currentFullClassName)){
String currentFullClassName = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass);
if (localData.documentClass && item.toString().equals(currentFullClassName)) {
int slotId = 0;
int c = abc.findClassByName(currentFullClassName);
for(Trait t:localData.currentScript.traits.traits){
if(t instanceof TraitClass){
TraitClass tc=(TraitClass)t;
if(tc.class_info == c){
for (Trait t : localData.currentScript.traits.traits) {
if (t instanceof TraitClass) {
TraitClass tc = (TraitClass) t;
if (tc.class_info == c) {
slotId = tc.slot_id;
break;
}
}
}
return GraphTargetItem.toSourceMerge(localData, this, ins(new GetGlobalScopeIns()),ins(new GetSlotIns(),slotId));
}else{
return GraphTargetItem.toSourceMerge(localData, this, ins(new GetLexIns(),resolveType(item, abc)));
return GraphTargetItem.toSourceMerge(localData, this, ins(new GetGlobalScopeIns()), ins(new GetSlotIns(), slotId));
} else {
return GraphTargetItem.toSourceMerge(localData, this, ins(new GetLexIns(), resolveType(item, abc)));
}
}
public static int resolveType(TypeItem type,ABC abc) {
public static int resolveType(TypeItem type, ABC abc) {
String name = type.fullTypeName;
String pkg = "";
int name_index = 0;
@@ -2211,16 +2205,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
}
}
if(name_index == 0){
if (name_index == 0) {
name_index = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(name, true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, true)), 0, true), 0, 0, new ArrayList<Integer>()), true);
}
if(type.subtypes.isEmpty()){
if (type.subtypes.isEmpty()) {
return name_index;
}
List<Integer> params=new ArrayList<>();
for(String s:type.subtypes){
params.add(resolveType(new TypeItem(s),abc));
List<Integer> params = new ArrayList<>();
for (String s : type.subtypes) {
params.add(resolveType(new TypeItem(s), abc));
}
return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME,0,0,0,name_index,params),true);
return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0, 0, 0, name_index, params), true);
}
}

View File

@@ -77,7 +77,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.URShiftAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
@@ -256,7 +255,7 @@ public class ActionScriptParser {
String nsprop = null;
if (s.type == SymbolType.NAMESPACE_OP) {
if (name.contains(".")) {
nsname = name.substring(name.lastIndexOf(".") + 1);
nsname = name.substring(name.lastIndexOf('.') + 1);
} else {
nsname = name;
}
@@ -268,7 +267,7 @@ public class ActionScriptParser {
lexer.pushback(s);
}
if (name.contains(".")) {
name = name.substring(0, name.lastIndexOf("."));
name = name.substring(0, name.lastIndexOf('.'));
} else {
name = null;
}

View File

@@ -41,7 +41,7 @@ public class ConstAVM2Item extends AVM2Item {
return isStatic;
}
public ConstAVM2Item(String customNamespace,boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) {
public ConstAVM2Item(String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) {
super(null, NOPRECEDENCE);
this.namespace = namespace;
this.value = value;

View File

@@ -42,8 +42,8 @@ import java.util.List;
public class ConstructSomethingAVM2Item extends CallAVM2Item {
public List<Integer> openedNamespaces;
public ConstructSomethingAVM2Item(List<Integer> openedNamespaces,GraphTargetItem name, List<GraphTargetItem> arguments) {
public ConstructSomethingAVM2Item(List<Integer> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments) {
super(name, arguments);
this.openedNamespaces = openedNamespaces;
}
@@ -54,15 +54,15 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
}
private int allNsSetWithVec(ABC abc) {
int nssa[] = new int[openedNamespaces.size()+1];
int nssa[] = new int[openedNamespaces.size() + 1];
for (int i = 0; i < openedNamespaces.size(); i++) {
nssa[i] = openedNamespaces.get(i);
}
nssa[nssa.length-1] = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("__AS3__.vec", true)), 0, true);
nssa[nssa.length - 1] = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("__AS3__.vec", true)), 0, true);
return abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true);
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
@@ -72,32 +72,32 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
}
if (resname instanceof TypeItem) {
TypeItem prop = (TypeItem) resname;
if(!prop.subtypes.isEmpty()){ //It's Vector - TypeName
if (!prop.subtypes.isEmpty()) { //It's Vector - TypeName
//int qname = ((AVM2SourceGenerator) generator).resolveType(prop.fullTypeName);
String name = prop.fullTypeName.substring(prop.fullTypeName.lastIndexOf(".")+1);
ABC abc=((AVM2SourceGenerator)generator).abc;
int qname = abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME,abc.constants.getStringId(name,true) , 0,allNsSetWithVec(abc), 0, new ArrayList<Integer>()), true);
List<Integer> params=new ArrayList<>();
for(String p:prop.subtypes){
String name = prop.fullTypeName.substring(prop.fullTypeName.lastIndexOf('.') + 1);
ABC abc = ((AVM2SourceGenerator) generator).abc;
int qname = abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, abc.constants.getStringId(name, true), 0, allNsSetWithVec(abc), 0, new ArrayList<Integer>()), true);
List<Integer> params = new ArrayList<>();
for (String p : prop.subtypes) {
params.add(((AVM2SourceGenerator) generator).resolveType(p));
}
List<GraphSourceItem> ret=new ArrayList<>();
ret.add(ins(new GetLexIns(),qname));
for(int p:params){
ret.add(ins(new GetLexIns(),p));
List<GraphSourceItem> ret = new ArrayList<>();
ret.add(ins(new GetLexIns(), qname));
for (int p : params) {
ret.add(ins(new GetLexIns(), p));
}
ret.add(ins(new ApplyTypeIns(),params.size()));
ret.add(ins(new ApplyTypeIns(), params.size()));
ret.addAll(toSourceMerge(localData, generator, arguments,
ins(new ConstructIns(),arguments.size())
));
ins(new ConstructIns(), arguments.size())
));
return ret;
}else{
int type_index = ((AVM2SourceGenerator) generator).resolveType(resname.toString());
return toSourceMerge(localData, generator,
new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{type_index, arguments.size()}, new byte[0]), arguments,
new AVM2Instruction(0, new ConstructPropIns(), new int[]{type_index, arguments.size()}, new byte[0])
);
} else {
int type_index = ((AVM2SourceGenerator) generator).resolveType(resname.toString());
return toSourceMerge(localData, generator,
new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{type_index, arguments.size()}, new byte[0]), arguments,
new AVM2Instruction(0, new ConstructPropIns(), new int[]{type_index, arguments.size()}, new byte[0])
);
}
}
if (resname instanceof NameAVM2Item) {

View File

@@ -26,7 +26,7 @@ import java.util.List;
public class GetterAVM2Item extends MethodAVM2Item {
public GetterAVM2Item(String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(customNamespace,needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
super(customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
}
}

View File

@@ -25,7 +25,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIIns
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.IncLocalIIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.IncLocalIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetPropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetScopeObjectIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns;
@@ -37,7 +36,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceSIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertIIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertSIns;
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NanAVM2Item;
@@ -221,12 +219,12 @@ public class NameAVM2Item extends AssignableAVM2Item {
ins = ins(new CoerceSIns());
break;
default:
int type_index = AVM2SourceGenerator.resolveType(type,((AVM2SourceGenerator) generator).abc);
int type_index = AVM2SourceGenerator.resolveType(type, ((AVM2SourceGenerator) generator).abc);
ins = ins(new CoerceIns(), type_index);
break;
}
} else {
int type_index = AVM2SourceGenerator.resolveType(type,((AVM2SourceGenerator) generator).abc);
int type_index = AVM2SourceGenerator.resolveType(type, ((AVM2SourceGenerator) generator).abc);
ins = ins(new CoerceIns(), type_index);
}
}
@@ -242,14 +240,14 @@ public class NameAVM2Item extends AssignableAVM2Item {
}
String name = variableName;
boolean attr = false;
if(name!=null && name.startsWith("@")){
if (name != null && name.startsWith("@")) {
name = name.substring(1);
attr = true;
}
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
Reference<Integer> ns_temp = new Reference<>(-1);
Reference<Integer> index_temp = new Reference<>(-1);
Reference<Integer> ret_temp = new Reference<>(-1);
Reference<Integer> ret_temp = new Reference<>(-1);
if (index != null) {
if (assignedValue != null) {
@@ -356,8 +354,6 @@ public class NameAVM2Item extends AssignableAVM2Item {
*/
if (index != null) {
return toSourceMerge(localData, generator,
generateGetLoc(regNumber), generateGetSlot(slotScope, slotNumber), dupSetTemp(localData, generator, name_temp), index, dupSetTemp(localData, generator, index_temp),

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -30,7 +29,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertSIns;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.dupSetTemp;
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.getTemp;
@@ -73,9 +71,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
this.attr = attr;
this.openedNamespaces = openedNamespaces;
}
private int allNsSet(ABC abc) {
int nssa[] = new int[openedNamespaces.size()];
for (int i = 0; i < openedNamespaces.size(); i++) {
@@ -83,7 +79,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
}
return abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true);
}
@Override
public AssignableAVM2Item copy() {
return new NamespacedAVM2Item(index, ns, name, obj, attr, openedNamespaces, assignedValue);
@@ -91,9 +87,9 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
@Override
public List<GraphSourceItem> toSourceChange(SourceGeneratorLocalData localData, SourceGenerator generator, boolean post, boolean decrement, boolean needsReturn) throws CompilationException {
AVM2SourceGenerator g = (AVM2SourceGenerator)generator;
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
boolean isInteger = returnType().toString().equals("int");
Reference<Integer> ns_temp = new Reference<>(-1);
Reference<Integer> ns_temp = new Reference<>(-1);
Reference<Integer> name_temp = new Reference<>(-1);
Reference<Integer> ret_temp = new Reference<>(-1);
if (name == null && index != null) {
@@ -115,8 +111,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
getTemp(localData, generator, ret_temp),
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.MULTINAMEL, 0, 0, allNsSet(g.abc), 0, new ArrayList<Integer>()), true)),
killTemp(localData, generator, Arrays.asList(ret_temp, name_temp, ns_temp)));
}else
if (name != null && index == null) {
} else if (name != null && index == null) {
return toSourceMerge(localData, generator,
ns, generateCoerce(generator, new TypeItem("Namespace")),
ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
@@ -139,9 +134,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.MULTINAMEL, 0, 0, allNsSet(g.abc), 0, new ArrayList<Integer>()), true)),
killTemp(localData, generator, Arrays.asList(ret_temp, name_temp, ns_temp))
);
}
else
{
} else {
return new ArrayList<>();
}
}
@@ -161,16 +154,15 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
return TypeItem.UNBOUNDED;
}
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException {
AVM2SourceGenerator g = (AVM2SourceGenerator)generator;
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
Reference<Integer> ns_temp = new Reference<>(-1);
Reference<Integer> index_temp = new Reference<>(-1);
Reference<Integer> ret_temp = new Reference<>(-1);
if (name == null) {
if (assignedValue != null) {
return toSourceMerge(localData, generator,
obj==null?ns:null, obj==null?generateCoerce(generator, new TypeItem("Namespace")):null, obj==null?index:null, ins(new ConvertSIns()), obj!=null?obj:ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj == null ? index : null, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
ns, generateCoerce(generator, new TypeItem("Namespace")), index, ins(new ConvertSIns()), assignedValue,
needsReturn ? dupSetTemp(localData, generator, ret_temp) : null,
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
@@ -179,34 +171,33 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
);
} else {
return toSourceMerge(localData, generator,
obj==null?ns:null, obj==null?generateCoerce(generator, new TypeItem("Namespace")):null, obj==null?index:null, ins(new ConvertSIns()), obj!=null?obj:ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj == null ? index : null, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
ns, generateCoerce(generator, new TypeItem("Namespace")), index, ins(new ConvertSIns()), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
needsReturn ? null : ins(new PopIns()),
killTemp(localData, generator, Arrays.asList(ns_temp, index_temp, ret_temp))
);
}
}else{
} else {
if (assignedValue != null) {
return toSourceMerge(localData, generator,
obj==null?ns:null, obj==null?generateCoerce(generator, new TypeItem("Namespace")):null, obj!=null?obj:ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr?Multiname.RTQNAMEA:Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
ns, generateCoerce(generator, new TypeItem("Namespace")), assignedValue,
needsReturn ? dupSetTemp(localData, generator, ret_temp) : null,
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr?Multiname.RTQNAMEA:Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
needsReturn ? getTemp(localData, generator, ret_temp) : null,
killTemp(localData, generator, Arrays.asList(ns_temp, index_temp, ret_temp))
);
} else {
return toSourceMerge(localData, generator,
obj==null?ns:null, obj==null?generateCoerce(generator, new TypeItem("Namespace")):null, obj!=null?obj:ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr?Multiname.RTQNAMEA:Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
ns, generateCoerce(generator, new TypeItem("Namespace")), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr?Multiname.RTQNAMEA:Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
ns, generateCoerce(generator, new TypeItem("Namespace")), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
needsReturn ? null : ins(new PopIns()),
killTemp(localData, generator, Arrays.asList(ns_temp, index_temp, ret_temp))
);
}
}
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSource(localData, generator, true);
@@ -217,10 +208,4 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
return toSource(localData, generator, false);
}
}

View File

@@ -64,7 +64,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
private List<Integer> openedNamespaces;
private List<MethodBody> callStack;
public List<GraphTargetItem> scopeStack = new ArrayList<GraphTargetItem>();
@Override
public AssignableAVM2Item copy() {
PropertyAVM2Item p = new PropertyAVM2Item(object, propertyName, index, abc, otherABCs, openedNamespaces, callStack);
@@ -301,9 +301,9 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
if (attr) {
pname = pname.substring(1);
}
propIndex = abc.constants.getMultinameId(new Multiname(attr ? (pname.equals("") ? Multiname.MULTINAMELA : Multiname.MULTINAMEA) : Multiname.MULTINAME,
propIndex = abc.constants.getMultinameId(new Multiname(attr ? (pname.isEmpty() ? Multiname.MULTINAMELA : Multiname.MULTINAMEA) : Multiname.MULTINAME,
abc.constants.getStringId(pname, true), 0,
attr && pname.equals("") ? abc.constants.getNamespaceSetId(new NamespaceSet(new int[]{abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE_INTERNAL, abc.constants.getStringId(localData.pkg, true)), 0, true)}), true) : allNsSet(), 0, new ArrayList<Integer>()), true);
attr && pname.isEmpty() ? abc.constants.getNamespaceSetId(new NamespaceSet(new int[]{abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE_INTERNAL, abc.constants.getStringId(localData.pkg, true)), 0, true)}), true) : allNsSet(), 0, new ArrayList<Integer>()), true);
propType = "*";
objType = "*";
propValue = null;
@@ -545,8 +545,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
@Override
public String toString() {
return ""+object+"."+propertyName;
}
return "" + object + "." + propertyName;
}
@Override
public boolean hasReturnValue() {

View File

@@ -25,8 +25,8 @@ import java.util.List;
*/
public class SetterAVM2Item extends MethodAVM2Item {
public SetterAVM2Item(String customNamespace,boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(customNamespace,needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
public SetterAVM2Item(String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
}
}

View File

@@ -40,6 +40,7 @@ import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -86,9 +87,8 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
/*public void setNs(GraphTargetItem ns) {
this.ns = ns;
}*/
this.ns = ns;
}*/
public void setRegNumber(int regNumber) {
if (resolved instanceof NameAVM2Item) {
((NameAVM2Item) resolved).setRegNumber(regNumber);
@@ -114,11 +114,12 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
return -1;
}
/*
public GraphTargetItem getNs() {
return ns;
}
*/
/*
public GraphTargetItem getNs() {
return ns;
}
*/
public void appendName(String name) {
this.name += "." + name;
}
@@ -157,8 +158,6 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
public void setVariableName(String name) {
this.name = name;
}
public UnresolvedAVM2Item(List<String> subtypes, List<String> importedClasses, boolean mustBeType, GraphTargetItem type, int line, String name, GraphTargetItem storeValue, List<Integer> openedNamespaces) {
super(storeValue);
@@ -295,14 +294,11 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
List<String> parts = new ArrayList<>();
if (name.contains(".")) {
String partsArr[] = name.split("\\.");
for (String p : partsArr) {
parts.add(p);
}
parts.addAll(Arrays.asList(partsArr));
} else {
parts.add(name);
}
if (scopeStack.isEmpty()) { //Everything is multiname property in with command
//search for variable
@@ -337,8 +333,8 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
String impName = imp;
String impPkg = "";
if (impName.contains(".")) {
impPkg = impName.substring(0, impName.lastIndexOf("."));
impName = impName.substring(impName.lastIndexOf(".") + 1);
impPkg = impName.substring(0, impName.lastIndexOf('.'));
impName = impName.substring(impName.lastIndexOf('.') + 1);
}
if (impName.equals(parts.get(0))) {
TypeItem ret = new TypeItem(imp);

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -61,14 +60,12 @@ public class XMLAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
AVM2SourceGenerator g=(AVM2SourceGenerator)generator;
return toSourceMerge(localData, generator,
ins(new GetLexIns(),g.abc.constants.getMultinameId(new Multiname(Multiname.QNAME, g.abc.constants.getStringId("XML", true), g.abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE,g.abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<Integer>()), true)),
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
return toSourceMerge(localData, generator,
ins(new GetLexIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.QNAME, g.abc.constants.getStringId("XML", true), g.abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, g.abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<Integer>()), true)),
value,
ins(new ConstructIns(),1)
);
ins(new ConstructIns(), 1)
);
}
}

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -32,12 +31,12 @@ import java.util.List;
*
* @author JPEXS
*/
public class XMLFilterAVM2Item extends AVM2Item
{
public class XMLFilterAVM2Item extends AVM2Item {
public List<Integer> openedNamespaces;
public GraphTargetItem object;
public XMLFilterAVM2Item(GraphTargetItem object, GraphTargetItem value,List<Integer> openedNamespaces) {
public XMLFilterAVM2Item(GraphTargetItem object, GraphTargetItem value, List<Integer> openedNamespaces) {
super(null, NOPRECEDENCE);
this.value = value;
this.openedNamespaces = openedNamespaces;
@@ -61,8 +60,7 @@ public class XMLFilterAVM2Item extends AVM2Item
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return ((AVM2SourceGenerator)generator).generate(localData, this);
return ((AVM2SourceGenerator) generator).generate(localData, this);
}
}

View File

@@ -770,6 +770,5 @@ public class ActionSourceGenerator implements SourceGenerator {
//Unsupported in AS1/2
return new ArrayList<>();
}
}

View File

@@ -16,8 +16,8 @@
*/
package com.jpexs.decompiler.flash.exporters;
import com.jpexs.decompiler.flash.exporters.shape.ShapeExporterBase;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.exporters.shape.ShapeExporterBase;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.types.ColorTransform;

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.exporters;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.RGBA;
import java.awt.Color;
import java.io.StringWriter;
@@ -104,7 +105,25 @@ public class SVGExporter {
Attr attr = _svg.createAttribute("style");
attr.setValue("background: " + new RGBA(backGroundColor).toHexARGB());
}
public void addImage(Matrix transform, RECT boundRect, String href) {
Element image = _svg.createElement("image");
if (transform != null) {
double translateX = roundPixels400(transform.translateX / SWF.unitDivisor);
double translateY = roundPixels400(transform.translateY / SWF.unitDivisor);
double rotateSkew0 = roundPixels400(transform.rotateSkew0);
double rotateSkew1 = roundPixels400(transform.rotateSkew1);
double scaleX = roundPixels400(transform.scaleX);
double scaleY = roundPixels400(transform.scaleY);
image.setAttribute("transform", "matrix(" + scaleX + ", " + rotateSkew0
+ ", " + rotateSkew1 + ", " + scaleY + ", " + translateX + ", " + translateY + ")");
image.setAttribute("width", Double.toString(boundRect.getWidth() / (double) SWF.unitDivisor));
image.setAttribute("height", Double.toString(boundRect.getHeight() / (double) SWF.unitDivisor));
}
image.setAttribute("xlink:href", href);
_svgG.appendChild(image);
}
protected static double roundPixels20(double pixels) {
return Math.round(pixels * 100) / 100.0;
}

View File

@@ -16,10 +16,20 @@
*/
package com.jpexs.decompiler.flash.exporters;
import com.jpexs.decompiler.flash.tags.Tag;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class SVGExporterContext {
public String outDir;
public Map<Tag, String> exportedTags = new HashMap<>();
public SVGExporterContext(String outDir) {
this.outDir = outDir;
}
}

View File

@@ -27,7 +27,7 @@ public class CurvedMorphEdge extends StraightMorphEdge implements IMorphEdge {
private final PointInt control;
private final PointInt controlEnd;
CurvedMorphEdge(PointInt from, PointInt control, PointInt to,
CurvedMorphEdge(PointInt from, PointInt control, PointInt to,
PointInt fromEnd, PointInt controlEnd, PointInt toEnd, int lineStyleIdx, int fillStyleIdx) {
super(from, to, fromEnd, toEnd, lineStyleIdx, fillStyleIdx);
this.control = control;

View File

@@ -53,7 +53,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
protected List<FILLSTYLE> _fillStylesEnd;
protected List<LINESTYLE> _lineStylesEnd;
protected List<Map<Integer, List<IMorphEdge>>> _fillEdgeMaps;
protected List<Map<Integer, List<IMorphEdge>>> _lineEdgeMaps;
@@ -85,7 +85,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
_fillEdgeMaps = new ArrayList<>();
_lineEdgeMaps = new ArrayList<>();
createEdgeMaps(_fillStyles, _lineStyles, _fillStylesEnd, _lineStylesEnd, _fillEdgeMaps, _lineEdgeMaps);
// Let the doc handler know that a shape export starts
beginShape();
// Export fills and strokes for each group separately
@@ -123,10 +123,10 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
for (int i = 0; i < records.size(); i++) {
SHAPERECORD shapeRecord = records.get(i);
SHAPERECORD shapeRecordEnd = recordsEnd.get(i);
if ((shapeRecord instanceof StyleChangeRecord && !(shapeRecordEnd instanceof StyleChangeRecord)) ||
(shapeRecord instanceof StraightEdgeRecord && !(shapeRecordEnd instanceof StraightEdgeRecord)) ||
(shapeRecord instanceof CurvedEdgeRecord && !(shapeRecordEnd instanceof CurvedEdgeRecord)) ||
(shapeRecord instanceof EndShapeRecord && !(shapeRecordEnd instanceof EndShapeRecord))) {
if ((shapeRecord instanceof StyleChangeRecord && !(shapeRecordEnd instanceof StyleChangeRecord))
|| (shapeRecord instanceof StraightEdgeRecord && !(shapeRecordEnd instanceof StraightEdgeRecord))
|| (shapeRecord instanceof CurvedEdgeRecord && !(shapeRecordEnd instanceof CurvedEdgeRecord))
|| (shapeRecord instanceof EndShapeRecord && !(shapeRecordEnd instanceof EndShapeRecord))) {
throw new Error("Begin and end shaperecord should have the same type.");
}
if (shapeRecord instanceof StyleChangeRecord) {
@@ -252,7 +252,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
}
}
protected void processSubPath(List<IMorphEdge> subPath, int lineStyleIdx, int fillStyleIdx0, int fillStyleIdx1,
protected void processSubPath(List<IMorphEdge> subPath, int lineStyleIdx, int fillStyleIdx0, int fillStyleIdx1,
Map<Integer, List<IMorphEdge>> currentFillEdgeMap, Map<Integer, List<IMorphEdge>> currentLineEdgeMap) {
List<IMorphEdge> path;
if (fillStyleIdx0 != 0) {

View File

@@ -240,7 +240,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
path.appendChild(createAnimateElement("stroke", color.toHexRGB(), colorEnd.toHexRGB()));
path.setAttribute("stroke-width", Double.toString(thickness == 0 ? 1 : thickness));
path.appendChild(createAnimateElement("stroke-width", thickness, thicknessEnd));
if (color instanceof RGBA) {
RGBA colorA = (RGBA) color;
if (colorA.alpha != 255) {
@@ -303,7 +303,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
animate.setAttribute("values", startValue + ";" + endValue);
return animate;
}
@Override
protected void finalizePath() {
if (path != null && !"".equals(pathData)) {
@@ -350,17 +350,17 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
double b = roundPixels400(matrix.rotateSkew1);
double c = roundPixels400(matrix.rotateSkew0);
double d = roundPixels400(matrix.scaleY);
double rotate = Math.atan(c / d);
double rotate = Math.atan2(c, d);
double scaleX = Math.signum(a) * Math.sqrt(a * a + b * b);
double scaleY = Math.signum(d) * Math.sqrt(c * c + d * d);
double translateXEnd = roundPixels400(matrixEnd.translateX / SWF.unitDivisor);
double translateYEnd = roundPixels400(matrixEnd.translateY / SWF.unitDivisor);
a = roundPixels400(matrixEnd.scaleX);
b = roundPixels400(matrixEnd.rotateSkew1);
c = roundPixels400(matrixEnd.rotateSkew0);
d = roundPixels400(matrixEnd.scaleY);
double rotateEnd = Math.atan(c / d);
double rotateEnd = Math.atan2(c, d);
double scaleXEnd = Math.signum(a) * Math.sqrt(a * a + b * b);
double scaleYEnd = Math.signum(d) * Math.sqrt(c * c + d * d);
@@ -381,7 +381,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
animateScale.setAttribute("additive", "sum");
animateScale.setAttribute("from", scaleX + " " + scaleY);
animateScale.setAttribute("to", scaleXEnd + " " + scaleYEnd);
Element animateTranslate = _svg.createElement("animateTransform");
animateTranslate.setAttribute("dur", "2s"); // todo
animateTranslate.setAttribute("repeatCount", "indefinite");
@@ -390,7 +390,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
animateTranslate.setAttribute("additive", "sum");
animateTranslate.setAttribute("from", translateX + " " + translateY);
animateTranslate.setAttribute("to", translateXEnd + " " + translateYEnd);
gradient.appendChild(animateTranslate);
gradient.appendChild(animateScale);
gradient.appendChild(animateRotate);

View File

@@ -73,7 +73,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
_fillEdgeMaps = new ArrayList<>();
_lineEdgeMaps = new ArrayList<>();
createEdgeMaps(_fillStyles, _lineStyles, _fillEdgeMaps, _lineEdgeMaps);
// Let the doc handler know that a shape export starts
beginShape();
// Export fills and strokes for each group separately
@@ -87,7 +87,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
endShape();
}
protected void createEdgeMaps(List<FILLSTYLE> fillStyles, List<LINESTYLE> lineStyles,
protected void createEdgeMaps(List<FILLSTYLE> fillStyles, List<LINESTYLE> lineStyles,
List<Map<Integer, List<IEdge>>> fillEdgeMaps, List<Map<Integer, List<IEdge>>> lineEdgeMaps) {
if (!edgeMapsCreated) {
int xPos = 0;
@@ -191,7 +191,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
}
}
protected void processSubPath(List<IEdge> subPath, int lineStyleIdx, int fillStyleIdx0, int fillStyleIdx1,
protected void processSubPath(List<IEdge> subPath, int lineStyleIdx, int fillStyleIdx0, int fillStyleIdx1,
Map<Integer, List<IEdge>> currentFillEdgeMap, Map<Integer, List<IEdge>> currentLineEdgeMap) {
List<IEdge> path;
if (fillStyleIdx0 != 0) {

View File

@@ -939,10 +939,11 @@ public class DefineEditTextTag extends TextTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) {
return "";
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private FontTag getFontTag() {
FontTag font = null;
for (Tag tag : swf.tags) {

View File

@@ -100,7 +100,7 @@ public class DefineMorphShape2Tag extends CharacterTag implements MorphShapeTag,
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SHAPEWITHSTYLE beginShapes = getShapeAtRatio(0);
SHAPEWITHSTYLE endShapes = getShapeAtRatio(65535);

View File

@@ -148,7 +148,7 @@ public class DefineMorphShapeTag extends CharacterTag implements MorphShapeTag,
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SHAPEWITHSTYLE beginShapes = getShapeAtRatio(0);
SHAPEWITHSTYLE endShapes = getShapeAtRatio(65535);

View File

@@ -61,7 +61,7 @@ public class DefineShape2Tag extends ShapeTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes(), rect, new ColorTransform() /*FIXME?*/);
exporter.export();

View File

@@ -66,7 +66,7 @@ public class DefineShape3Tag extends ShapeTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes(), rect, new ColorTransform() /*FIXME?*/);
exporter.export();

View File

@@ -69,7 +69,7 @@ public class DefineShape4Tag extends ShapeTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes(), rect, new ColorTransform() /*FIXME?*/);
exporter.export();

View File

@@ -94,7 +94,7 @@ public class DefineShapeTag extends ShapeTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
public String toSVG(SVGExporterContext exporterContext, int level) {
ExportRectangle rect = new ExportRectangle(getRect());
SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes(), rect, new ColorTransform() /*FIXME?*/);
exporter.export();

View File

@@ -290,10 +290,10 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) throws IOException {
return SWF.frameToSvg(getTimeline(), 0, 0, null, 0, exporterContext, getRect(), new ColorTransform(), null, level + 1);
}
@Override
public Point getImagePos(int frame) {
return new Point(0, 0);

View File

@@ -494,10 +494,11 @@ public class DefineText2Tag extends TextTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) {
return "";
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Point getImagePos(int frame) {
return new Point(textBounds.Xmin / 20, textBounds.Ymin / 20);

View File

@@ -510,8 +510,9 @@ public class DefineTextTag extends TextTag {
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) {
return "";
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override

View File

@@ -59,10 +59,11 @@ public abstract class ButtonTag extends CharacterTag implements DrawableTag, Tim
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) {
return "";
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public DefineButtonSoundTag getSounds() {
for (Tag t : swf.tags) {
if (t instanceof DefineButtonSoundTag) {

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.timeline.DepthState;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.helpers.SerializableImage;
import java.awt.Shape;
import java.io.IOException;
/**
*
@@ -32,7 +33,7 @@ public interface DrawableTag extends BoundedTag {
public void toImage(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, SerializableImage image, Matrix transformation, ColorTransform colorTransform);
public String toSVG(SVGExporterContext exporterContext);
public String toSVG(SVGExporterContext exporterContext, int level) throws IOException;
public Point getImagePos(int frame);

View File

@@ -260,8 +260,9 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
}
@Override
public String toSVG(SVGExporterContext exporterContext) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public String toSVG(SVGExporterContext exporterContext, int level) {
return "";
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override

View File

@@ -41,7 +41,7 @@ public interface MorphShapeTag {
public SHAPE getEndEdges();
public String toSVG(SVGExporterContext exporterContext);
public String toSVG(SVGExporterContext exporterContext, int level);
public int getShapeNum();

View File

@@ -426,7 +426,7 @@ public class Graph {
System.out.println(el);
}
System.out.println("</loops>");*/
getPrecontinues(path,localData, null, heads.get(0), allParts, loops, null);
getPrecontinues(path, localData, null, heads.get(0), allParts, loops, null);
/*System.err.println("<loopspre>");
for (Loop el : loops) {
System.err.println(el);
@@ -691,8 +691,8 @@ public class Graph {
return loopItem;
}
private void getPrecontinues(String path,BaseLocalData localData, GraphPart parent, GraphPart part, List<GraphPart> allParts, List<Loop> loops, List<GraphPart> stopPart) throws InterruptedException {
markLevels(path,localData, part, allParts, loops);
private void getPrecontinues(String path, BaseLocalData localData, GraphPart parent, GraphPart part, List<GraphPart> allParts, List<Loop> loops, List<GraphPart> stopPart) throws InterruptedException {
markLevels(path, localData, part, allParts, loops);
//Note: this also marks part as precontinue when there is if
/*
while(k<10){
@@ -745,11 +745,11 @@ public class Graph {
private void markLevels(String path, BaseLocalData localData, GraphPart part, List<GraphPart> allParts, List<Loop> loops) throws InterruptedException {
clearLoops(loops);
markLevels(path,localData, part, allParts, loops, new ArrayList<GraphPart>(), 1, new ArrayList<GraphPart>(), 0);
markLevels(path, localData, part, allParts, loops, new ArrayList<GraphPart>(), 1, new ArrayList<GraphPart>(), 0);
clearLoops(loops);
}
private void markLevels(String path,BaseLocalData localData, GraphPart part, List<GraphPart> allParts, List<Loop> loops, List<GraphPart> stopPart, int level, List<GraphPart> visited, int recursionLevel) throws InterruptedException {
private void markLevels(String path, BaseLocalData localData, GraphPart part, List<GraphPart> allParts, List<Loop> loops, List<GraphPart> stopPart, int level, List<GraphPart> visited, int recursionLevel) throws InterruptedException {
boolean debugMode = false;
if (stopPart == null) {
stopPart = new ArrayList<>();
@@ -818,13 +818,13 @@ public class Graph {
stopParts2.add(stopPart.get(stopPart.size() - 1));
}
if (next != nextParts.get(0)) {
markLevels(path,localData, nextParts.get(0), allParts, loops, next == null ? stopPart : stopParts2, level + 1, visited, recursionLevel + 1);
markLevels(path, localData, nextParts.get(0), allParts, loops, next == null ? stopPart : stopParts2, level + 1, visited, recursionLevel + 1);
}
if (next != nextParts.get(1)) {
markLevels(path,localData, nextParts.get(1), allParts, loops, next == null ? stopPart : stopParts2, level + 1, visited, recursionLevel + 1);
markLevels(path, localData, nextParts.get(1), allParts, loops, next == null ? stopPart : stopParts2, level + 1, visited, recursionLevel + 1);
}
if (next != null) {
markLevels(path,localData, next, allParts, loops, stopPart, level, visited, recursionLevel + 1);
markLevels(path, localData, next, allParts, loops, stopPart, level, visited, recursionLevel + 1);
}
}
@@ -850,17 +850,17 @@ public class Graph {
}
}
if (next != p) {
markLevels(path,localData, p, allParts, loops, stopPart2, level + 1, visited, recursionLevel + 1);
markLevels(path, localData, p, allParts, loops, stopPart2, level + 1, visited, recursionLevel + 1);
vis.add(p);
}
}
if (next != null) {
markLevels(path,localData, next, allParts, loops, stopPart, level, visited, recursionLevel + 1);
markLevels(path, localData, next, allParts, loops, stopPart, level, visited, recursionLevel + 1);
}
}
if (nextParts.size() == 1) {
markLevels(path,localData, nextParts.get(0), allParts, loops, stopPart, level, visited, recursionLevel + 1);
markLevels(path, localData, nextParts.get(0), allParts, loops, stopPart, level, visited, recursionLevel + 1);
}
for (GraphPart t : part.throwParts) {
@@ -876,14 +876,14 @@ public class Graph {
stopPart2 = stopPart;
}
markLevels(path,localData, t, allParts, loops, stopPart2, level, visited, recursionLevel + 1);
markLevels(path, localData, t, allParts, loops, stopPart2, level, visited, recursionLevel + 1);
}
}
if (isLoop) {
if (currentLoop.loopBreak != null) {
currentLoop.phase = 2;
markLevels(path,localData, currentLoop.loopBreak, allParts, loops, stopPart, level, visited, recursionLevel + 1);
markLevels(path, localData, currentLoop.loopBreak, allParts, loops, stopPart, level, visited, recursionLevel + 1);
}
}
}

View File

@@ -65,6 +65,6 @@ public interface SourceGenerator {
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, List<GraphTargetItem> commands) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException;
}

View File

@@ -17,10 +17,6 @@
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.UnboundedTypeItem;
@@ -43,11 +39,11 @@ public class TypeItem extends GraphTargetItem {
public String fullTypeName;
public List<String> subtypes = new ArrayList<>();
public TypeItem(String fullTypeName){
this(fullTypeName,new ArrayList<String>());
public TypeItem(String fullTypeName) {
this(fullTypeName, new ArrayList<String>());
}
public TypeItem(String fullTypeName,List<String> subtypes) {
public TypeItem(String fullTypeName, List<String> subtypes) {
super(null, NOPRECEDENCE);
this.fullTypeName = fullTypeName;
this.subtypes.addAll(subtypes);
@@ -93,20 +89,17 @@ public class TypeItem extends GraphTargetItem {
@Override
public String toString() {
String add="";
if(!subtypes.isEmpty()){
add+=".<";
add+=Helper.joinStrings(subtypes, ",");
add+=">";
String add = "";
if (!subtypes.isEmpty()) {
add += ".<";
add += Helper.joinStrings(subtypes, ",");
add += ">";
}
return fullTypeName+add;
return fullTypeName + add;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
}
}