mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 02:20:44 +00:00
AS1/2 editing - bit of SWF version dependency, Greater vs Less improvements
This commit is contained in:
@@ -18,6 +18,8 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
@@ -63,7 +65,8 @@ public class GeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionLess2(), new ActionNot());
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, g.getSwfVersion()>=5?new ActionLess2():new ActionLess(), new ActionNot());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionGreater;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
@@ -46,7 +49,11 @@ public class GtActionItem extends BinaryOpItem implements LogicalOpItem {
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionGreater());
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
if(g.getSwfVersion()>=6){
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionGreater());
|
||||
}
|
||||
return toSourceMerge(localData, generator, rightSide, leftSide, g.getSwfVersion()>=5?new ActionLess2():new ActionLess());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionGreater;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOpItem;
|
||||
@@ -53,8 +57,12 @@ public class LeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionGreater(), new ActionNot());
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
if(g.getSwfVersion()>=6){
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionGreater(), new ActionNot());
|
||||
}
|
||||
return toSourceMerge(localData, generator, rightSide, leftSide, g.getSwfVersion()>=5?new ActionLess2():new ActionLess(), new ActionNot());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
@@ -55,7 +57,8 @@ public class LtActionItem extends BinaryOpItem implements LogicalOpItem {
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionLess2());
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, g.getSwfVersion()>=5?new ActionLess2():new ActionLess());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionStringGreater;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -40,6 +42,10 @@ public class StringGtActionItem extends BinaryOpItem implements Inverted {
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
if(g.getSwfVersion()>=6){
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringGreater());
|
||||
}
|
||||
return toSourceMerge(localData, generator, rightSide, leftSide, new ActionStringLess());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionStringGreater;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOpItem;
|
||||
@@ -41,6 +44,12 @@ public class StringLeActionItem extends BinaryOpItem implements Inverted{
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
|
||||
ActionSourceGenerator g = (ActionSourceGenerator)generator;
|
||||
if(g.getSwfVersion()>=6){
|
||||
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringGreater(), new ActionNot());
|
||||
}
|
||||
|
||||
return toSourceMerge(localData, generator, rightSide, leftSide, new ActionStringLess(), new ActionNot());
|
||||
}
|
||||
|
||||
|
||||
@@ -1686,10 +1686,14 @@ public class ActionScriptParser {
|
||||
case IDENTIFIER:
|
||||
case THIS:
|
||||
case SUPER:
|
||||
lexer.pushback(s);
|
||||
GraphTargetItem var = variable(registerVars, inFunction, inMethod, variables);
|
||||
var = memberOrCall(var, registerVars, inFunction, inMethod, variables);
|
||||
ret = var;
|
||||
if(s.value.equals("not")){
|
||||
ret = new NotItem(null, expression(registerVars, inFunction, inMethod, false, variables));
|
||||
}else{
|
||||
lexer.pushback(s);
|
||||
GraphTargetItem var = variable(registerVars, inFunction, inMethod, variables);
|
||||
var = memberOrCall(var, registerVars, inFunction, inMethod, variables);
|
||||
ret = var;
|
||||
}
|
||||
existsRemainder = true;
|
||||
break;
|
||||
default:
|
||||
@@ -1753,8 +1757,8 @@ public class ActionScriptParser {
|
||||
return retTree;
|
||||
}
|
||||
|
||||
public List<Action> actionsFromTree(List<GraphTargetItem> tree, List<String> constantPool) throws CompilationException {
|
||||
ActionSourceGenerator gen = new ActionSourceGenerator(constantPool);
|
||||
public List<Action> actionsFromTree(int swfVersion, List<GraphTargetItem> tree, List<String> constantPool) throws CompilationException {
|
||||
ActionSourceGenerator gen = new ActionSourceGenerator(swfVersion, constantPool);
|
||||
List<Action> ret = new ArrayList<>();
|
||||
SourceGeneratorLocalData localData = new SourceGeneratorLocalData(
|
||||
new HashMap<String, Integer>(), 0, Boolean.FALSE, 0);
|
||||
@@ -1768,9 +1772,9 @@ public class ActionScriptParser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Action> actionsFromString(String s) throws ParseException, IOException, CompilationException {
|
||||
public List<Action> actionsFromString(int swfVersion,String s) throws ParseException, IOException, CompilationException {
|
||||
List<String> constantPool = new ArrayList<>();
|
||||
List<GraphTargetItem> tree = treeFromString(s, constantPool);
|
||||
return actionsFromTree(tree, constantPool);
|
||||
return actionsFromTree(swfVersion,tree, constantPool);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,9 +596,17 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
return ret;
|
||||
}
|
||||
private final List<String> constantPool;
|
||||
private int swfVersion;
|
||||
|
||||
public ActionSourceGenerator(List<String> constantPool) {
|
||||
public int getSwfVersion() {
|
||||
return swfVersion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ActionSourceGenerator(int swfVersion,List<String> constantPool) {
|
||||
this.constantPool = constantPool;
|
||||
this.swfVersion = swfVersion;
|
||||
}
|
||||
|
||||
public List<String> getConstantPool() {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.swf6;
|
||||
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.model.operations.GtActionItem;
|
||||
import com.jpexs.decompiler.flash.action.model.operations.StringGtActionItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -38,6 +39,6 @@ public class ActionStringGreater extends Action {
|
||||
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
|
||||
GraphTargetItem a = stack.pop();
|
||||
GraphTargetItem b = stack.pop();
|
||||
stack.push(new GtActionItem(this, b, a));
|
||||
stack.push(new StringGtActionItem(this, b, a));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +749,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
|
||||
case ACTION_SAVE_DECOMPILED:
|
||||
try {
|
||||
ActionScriptParser par = new ActionScriptParser();
|
||||
src.setActions(par.actionsFromString(decompiledEditor.getText()));
|
||||
src.setActions(par.actionsFromString(mainPanel.getCurrentSwf().version,decompiledEditor.getText()));
|
||||
src.setModified();
|
||||
setSource(src, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user