mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-30 18:57:04 +00:00
AS3 test methods separated to classes, Fixed AS3: get/set slot for global scope
This commit is contained in:
@@ -3636,7 +3636,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
|
||||
int mi = ((TraitMethodGetterSetter) t).method_info;
|
||||
try {
|
||||
documentPack.abc.findBody(mi).convert(new ConvertData(), "??", ScriptExportMode.AS, true, mi, documentPack.scriptIndex, cindex, documentPack.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
documentPack.abc.findBody(mi).convert(new ConvertData(), "??", ScriptExportMode.AS, true, mi, documentPack.scriptIndex, cindex, documentPack.abc, t, new ScopeStack(documentPack.scriptIndex), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
List<GraphTargetItem> infos = documentPack.abc.findBody(mi).convertedItems;
|
||||
if (!infos.isEmpty()) {
|
||||
if (infos.get(0) instanceof IfItem) {
|
||||
@@ -3712,7 +3712,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
if (tr instanceof TraitClass) {
|
||||
int ci = ((TraitClass) tr).class_info;
|
||||
int cinit = p.abc.class_info.get(ci).cinit_index;
|
||||
p.abc.findBody(cinit).convert(new ConvertData(), "??", ScriptExportMode.AS, true, cinit, p.scriptIndex, cindex, p.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
p.abc.findBody(cinit).convert(new ConvertData(), "??", ScriptExportMode.AS, true, cinit, p.scriptIndex, cindex, p.abc, t, new ScopeStack(p.scriptIndex), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
List<GraphTargetItem> cinitBody = p.abc.findBody(cinit).convertedItems;
|
||||
for (GraphTargetItem cit : cinitBody) {
|
||||
if (cit instanceof SetPropertyAVM2Item) {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
}
|
||||
ts.add(abc.script_info.get(scriptIndex).traits);
|
||||
writer.mark();
|
||||
abc.bodies.get(sinit_bodyIndex).convert(convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, sinit_index, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true);
|
||||
abc.bodies.get(sinit_bodyIndex).convert(convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, sinit_index, scriptIndex, -1, abc, null, new ScopeStack(scriptIndex), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true);
|
||||
scriptInitializerIsEmpty = !writer.getMark();
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.NextValueAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ReturnValueAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ReturnVoidAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.SetTypeAVM2Item;
|
||||
@@ -338,7 +339,7 @@ public class AVM2Graph extends Graph {
|
||||
st2.clear();
|
||||
st2.add(new ExceptionAVM2Item(catchedExceptions.get(e)));
|
||||
AVM2LocalData localData2 = new AVM2LocalData(aLocalData);
|
||||
localData2.scopeStack = new ScopeStack();
|
||||
localData2.scopeStack = new ScopeStack(localData2.scriptIndex);
|
||||
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
|
||||
stopPart2.add(nepart);
|
||||
if (retPart != null) {
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.other;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
@@ -45,11 +46,13 @@ public class GetGlobalScopeIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
if (localData.scopeStack.isEmpty()) {
|
||||
if (localData.scopeStack.isEmpty()) {
|
||||
if (localData.classIndex == -1) {
|
||||
/*if (localData.classIndex == -1) {
|
||||
|
||||
} else {
|
||||
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
|
||||
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
|
||||
}*/
|
||||
//FIXME??
|
||||
stack.push(new ScriptAVM2Item(localData.scriptIndex));
|
||||
return;
|
||||
}
|
||||
stack.push(localData.scopeStack.get(0));
|
||||
|
||||
@@ -53,12 +53,8 @@ public class GetSlotIns extends InstructionDefinition {
|
||||
Multiname slotname = null;
|
||||
if (obj instanceof ExceptionAVM2Item) {
|
||||
slotname = localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
|
||||
} else if (obj instanceof ClassAVM2Item) {
|
||||
slotname = ((ClassAVM2Item) obj).className;
|
||||
} else if (obj instanceof ThisAVM2Item) {
|
||||
slotname = ((ThisAVM2Item) obj).classMultiname;
|
||||
} else if (obj instanceof ScriptAVM2Item) {
|
||||
List<Trait> traits = localData.getScriptInfo().get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
|
||||
} else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item) || (obj instanceof ScriptAVM2Item)) {
|
||||
List<Trait> traits = localData.getScriptInfo().get(localData.scriptIndex).traits.traits;
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
Trait tr = traits.get(t);
|
||||
if (tr instanceof TraitWithSlot) {
|
||||
|
||||
@@ -73,12 +73,9 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
|
||||
|
||||
if (obj instanceof ExceptionAVM2Item) {
|
||||
slotname = localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
|
||||
} else if (obj instanceof ClassAVM2Item) {
|
||||
slotname = ((ClassAVM2Item) obj).className;
|
||||
} else if (obj instanceof ThisAVM2Item) {
|
||||
} else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item) || (obj instanceof ScriptAVM2Item)) {
|
||||
slotname = ((ThisAVM2Item) obj).classMultiname;
|
||||
} else if (obj instanceof ScriptAVM2Item) {
|
||||
List<Trait> traits = localData.getScriptInfo().get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
|
||||
List<Trait> traits = localData.getScriptInfo().get(localData.scriptIndex).traits.traits;
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
Trait tr = traits.get(t);
|
||||
if (tr instanceof TraitWithSlot) {
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
@@ -83,7 +84,7 @@ public class NewFunctionAVM2Item extends AVM2Item {
|
||||
abc.method_info.get(methodIndex).getReturnTypeStr(writer, abc.constants, fullyQualifiedNames);
|
||||
writer.startBlock();
|
||||
if (body != null) {
|
||||
if (body != null) {
|
||||
body.convert(new ConvertData(), path + "/inner", ScriptExportMode.AS, isStatic, methodIndex, scriptIndex, classIndex, abc, null, new ScopeStack(scriptIndex), 0, new NulWriter(), fullyQualifiedNames, null, false);
|
||||
body.toString(path + "/inner", ScriptExportMode.AS, abc, null, writer, fullyQualifiedNames);
|
||||
}
|
||||
writer.endBlock();
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
|
||||
@@ -406,11 +406,11 @@ public final class MethodBody implements Cloneable {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String toSource() {
|
||||
public String toSource(int scriptIndex) {
|
||||
ConvertData convertData = new ConvertData();
|
||||
convertData.deobfuscationMode = 0;
|
||||
try {
|
||||
convert(convertData, "", ScriptExportMode.AS, false, method_info, 0, 0, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
convert(convertData, "", ScriptExportMode.AS, false, method_info, 0, 0, abc, null, new ScopeStack(scriptIndex), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
writer.indent().indent().indent();
|
||||
toString("", ScriptExportMode.AS, abc, null, writer, new ArrayList<>());
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.types.traits;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
@@ -223,7 +224,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
writer.mark();
|
||||
List<Traits> ts = new ArrayList<>();
|
||||
ts.add(classInfo.static_traits);
|
||||
ts.add(classInfo.static_traits);
|
||||
abc.bodies.get(bodyIndex).convert(convertData, path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, true, classInfo.cinit_index, scriptIndex, class_info, abc, this, new ScopeStack(scriptIndex), GraphTextWriter.TRAIT_CLASS_INITIALIZER, writer, fullyQualifiedNames, ts, true);
|
||||
classInitializerIsEmpty = !writer.getMark();
|
||||
}
|
||||
|
||||
@@ -233,7 +234,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
if (bodyIndex != -1) {
|
||||
List<Traits> ts = new ArrayList<>();
|
||||
ts.add(instanceInfo.instance_traits);
|
||||
ts.add(instanceInfo.instance_traits);
|
||||
abc.bodies.get(bodyIndex).convert(convertData, path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, false, instanceInfo.iinit_index, scriptIndex, class_info, abc, this, new ScopeStack(scriptIndex), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, writer, fullyQualifiedNames, ts, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.types.traits;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
@@ -104,7 +105,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
|
||||
convertHeader(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel);
|
||||
int bodyIndex = abc.findBodyIndex(method_info);
|
||||
if (bodyIndex != -1) {
|
||||
if (bodyIndex != -1) {
|
||||
abc.bodies.get(bodyIndex).convert(convertData, path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(classIndex), 0, writer, fullyQualifiedNames, null, true);
|
||||
}
|
||||
writer.endMethod();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.types.traits;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
@@ -115,7 +116,7 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
if (exportMode != ScriptExportMode.AS_METHOD_STUBS) {
|
||||
if (!(classIndex != -1 && abc.instance_info.get(classIndex).isInterface() || bodyIndex == -1)) {
|
||||
if (bodyIndex != -1) {
|
||||
if (bodyIndex != -1) {
|
||||
abc.bodies.get(bodyIndex).convert(convertData, path, exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(scriptIndex), 0, writer, fullyQualifiedNames, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
||||
@@ -105,7 +106,7 @@ public class AS3ScriptExporter {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int method = t.method_info;
|
||||
try {
|
||||
try {
|
||||
pack.abc.findBody(method).convert(new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(pack.scriptIndex), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
|
||||
List<GraphTargetItem> ci = pack.abc.findBody(method).convertedItems;
|
||||
if (!ci.isEmpty()) {
|
||||
@@ -178,7 +179,7 @@ public class AS3ScriptExporter {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int method = t.method_info;
|
||||
try {
|
||||
try {
|
||||
pack.abc.findBody(method).convert(new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(pack.scriptIndex), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
|
||||
List<GraphTargetItem> ci = pack.abc.findBody(method).convertedItems;
|
||||
if (!ci.isEmpty() && (ci.get(0) instanceof DeclarationAVM2Item)) {
|
||||
@@ -269,7 +270,7 @@ public class AS3ScriptExporter {
|
||||
int iinit = pack.abc.instance_info.get(cindex).iinit_index;
|
||||
|
||||
try {
|
||||
try {
|
||||
pack.abc.findBody(iinit).convert(new ConvertData(), "??", ScriptExportMode.AS, false, iinit, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(pack.scriptIndex), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
List<GraphTargetItem> iinitBody = pack.abc.findBody(iinit).convertedItems;
|
||||
for (GraphTargetItem it : iinitBody) {
|
||||
if (it instanceof InitPropertyAVM2Item) {
|
||||
|
||||
@@ -2455,7 +2455,7 @@ public class XFLConverter {
|
||||
MethodBody constructorBody = abc.findBody(constructorMethodIndex);
|
||||
try {
|
||||
if (constructorBody.convertedItems == null) {
|
||||
constructorBody.convert(new ConvertData(), "??", ScriptExportMode.AS, true, constructorMethodIndex, pack.scriptIndex, classIndex, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
constructorBody.convert(new ConvertData(), "??", ScriptExportMode.AS, true, constructorMethodIndex, pack.scriptIndex, classIndex, abc, null, new ScopeStack(pack.scriptIndex), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
}
|
||||
|
||||
Map<Integer, Integer> frameToTraitMultiname = new HashMap<>();
|
||||
@@ -2518,7 +2518,7 @@ public class XFLConverter {
|
||||
MethodBody frameBody = abc.findBody(methodIndex);
|
||||
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
frameBody.convert(new ConvertData(), "??", ScriptExportMode.AS, false, methodIndex, pack.scriptIndex, classIndex, abc, methodTrait, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
frameBody.convert(new ConvertData(), "??", ScriptExportMode.AS, false, methodIndex, pack.scriptIndex, classIndex, abc, methodTrait, new ScopeStack(pack.scriptIndex), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
|
||||
StringBuilderTextWriter writer = new StringBuilderTextWriter(Configuration.getCodeFormatting(), scriptBuilder);
|
||||
frameBody.toString("??", ScriptExportMode.AS, abc, methodTrait, writer, new ArrayList<>());
|
||||
|
||||
|
||||
@@ -724,6 +724,7 @@ public class Graph {
|
||||
lastUsage.get(labelName).labelName = null;
|
||||
}
|
||||
}
|
||||
expandGotos(ret);
|
||||
processIfs(ret);
|
||||
finalProcessStack(stack, ret, path);
|
||||
finalProcessAll(ret, 0, new FinalProcessLocalData(loops), path);
|
||||
@@ -1203,16 +1204,6 @@ public class Graph {
|
||||
}
|
||||
|
||||
protected void finalProcessAfter(List<GraphTargetItem> list, int level, FinalProcessLocalData localData, String path) {
|
||||
if (!list.isEmpty() && (list.get(list.size() - 1) instanceof GotoItem)) {
|
||||
GotoItem gi = (GotoItem) list.get(list.size() - 1);
|
||||
if (gi.targetCommands != null) {
|
||||
list.remove(gi);
|
||||
if (gi.labelName != null) {
|
||||
list.add(new LabelItem(null, gi.lineStartItem, gi.labelName));
|
||||
}
|
||||
list.addAll(gi.targetCommands);
|
||||
}
|
||||
}
|
||||
if (list.size() >= 2) {
|
||||
if (list.get(list.size() - 1) instanceof ExitItem) {
|
||||
ExitItem e = (ExitItem) list.get(list.size() - 1);
|
||||
@@ -1306,6 +1297,28 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
|
||||
private void expandGotos(List<GraphTargetItem> list) {
|
||||
if (!list.isEmpty() && (list.get(list.size() - 1) instanceof GotoItem)) {
|
||||
GotoItem gi = (GotoItem) list.get(list.size() - 1);
|
||||
if (gi.targetCommands != null) {
|
||||
list.remove(gi);
|
||||
if (gi.labelName != null) {
|
||||
list.add(new LabelItem(null, gi.lineStartItem, gi.labelName));
|
||||
}
|
||||
list.addAll(gi.targetCommands);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
GraphTargetItem item = list.get(i);
|
||||
if (item instanceof Block) {
|
||||
List<List<GraphTargetItem>> subs = ((Block) item).getSubs();
|
||||
for (List<GraphTargetItem> sub : subs) {
|
||||
expandGotos(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processIfs(List<GraphTargetItem> list) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
GraphTargetItem item = list.get(i);
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
@@ -28,4 +31,9 @@ public class ScopeStack extends TranslateStack {
|
||||
public ScopeStack() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public ScopeStack(int scriptIndex) {
|
||||
this(true);
|
||||
//push(new ScriptAVM2Item(scriptIndex));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user