mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-22 17:35:33 +00:00
Import fixes, full package handling, make test pass
This commit is contained in:
@@ -118,7 +118,7 @@ public abstract class InstructionDefinition implements Serializable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected FullMultinameAVM2Item resolveMultiname(TranslateStack stack, AVM2ConstantPool constants, int multinameIndex, AVM2Instruction ins) {
|
||||
protected FullMultinameAVM2Item resolveMultiname(boolean property, TranslateStack stack, AVM2ConstantPool constants, int multinameIndex, AVM2Instruction ins) {
|
||||
GraphTargetItem ns = null;
|
||||
GraphTargetItem name = null;
|
||||
if (multinameIndex > 0 && multinameIndex < constants.constant_multiname.size()) {
|
||||
@@ -130,7 +130,7 @@ public abstract class InstructionDefinition implements Serializable {
|
||||
}
|
||||
|
||||
}
|
||||
return new FullMultinameAVM2Item(ins, multinameIndex, name, ns);
|
||||
return new FullMultinameAVM2Item(property, ins, multinameIndex, name, ns);
|
||||
}
|
||||
|
||||
protected int getMultinameRequiredStackSize(AVM2ConstantPool constants, int multinameIndex) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ConstructPropAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.XMLAVM2Item;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -61,8 +62,11 @@ public class ConstructPropIns extends InstructionDefinition {
|
||||
for (int a = 0; a < argCount; a++) {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
if (obj instanceof FindPropertyAVM2Item) {
|
||||
multiname.property = false; //can be type
|
||||
}
|
||||
|
||||
if (multiname.isXML(localData.getConstants(), localData.localRegNames, localData.fullyQualifiedNames)) {
|
||||
if (args.size() == 1) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CallPropLexIns extends CallPropertyIns {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem receiver = stack.pop();
|
||||
|
||||
stack.push(new CallPropertyAVM2Item(ins, false, receiver, multiname, args));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CallPropVoidIns extends InstructionDefinition {
|
||||
for (int a = 0; a < argCount; a++) {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
|
||||
GraphTargetItem receiver = stack.pop();
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CallPropertyIns extends InstructionDefinition {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem receiver = stack.pop();
|
||||
|
||||
stack.push(new CallPropertyAVM2Item(ins, false, receiver, multiname, args));
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CallSuperIns extends InstructionDefinition {
|
||||
for (int a = 0; a < argCount; a++) {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem receiver = stack.pop();
|
||||
|
||||
stack.push(new CallSuperAVM2Item(ins, false, receiver, multiname, args));
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CallSuperVoidIns extends InstructionDefinition {
|
||||
for (int a = 0; a < argCount; a++) {
|
||||
args.add(0, stack.pop());
|
||||
}
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem receiver = stack.pop();
|
||||
|
||||
output.add(new CallSuperAVM2Item(ins, true, receiver, multiname, args));
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DeletePropertyIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
//stack.add(new BooleanAVM2Item(ins, Boolean.TRUE));//property successfully deleted
|
||||
stack.add(new DeletePropertyAVM2Item(ins, obj, multiname));
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FindPropertyIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
stack.push(new FindPropertyAVM2Item(ins, multiname)); //resolve right object
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FindPropertyStrictIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
stack.push(new FindPropertyAVM2Item(ins, multiname));
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class GetDescendantsIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
stack.push(new GetDescendantsAVM2Item(ins, obj, multiname));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GetPropertyIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
stack.push(new GetPropertyAVM2Item(ins, obj, multiname));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GetSuperIns extends InstructionDefinition {
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
stack.push(new GetSuperAVM2Item(ins, obj, multiname));
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class InitPropertyIns extends InstructionDefinition {
|
||||
int multinameIndex = ins.operands[0];
|
||||
|
||||
GraphTargetItem val = stack.pop();
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
output.add(new InitPropertyAVM2Item(ins, obj, multiname, val));
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
GraphTargetItem value = stack.pop();
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
if (value.getThroughDuplicate().getThroughRegister().getThroughDuplicate() instanceof IncrementAVM2Item) {
|
||||
GraphTargetItem inside = ((IncrementAVM2Item) value.getThroughDuplicate().getThroughRegister().getThroughDuplicate()).value.getThroughRegister().getNotCoerced().getThroughDuplicate();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns {
|
||||
int multinameIndex = ins.operands[0];
|
||||
|
||||
GraphTargetItem value = stack.pop();
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
|
||||
FullMultinameAVM2Item multiname = resolveMultiname(true, stack, localData.getConstants(), multinameIndex, ins);
|
||||
GraphTargetItem obj = stack.pop();
|
||||
output.add(new SetSuperAVM2Item(ins, value, obj, multiname));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class AsTypeIns extends InstructionDefinition {
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
GraphTargetItem val = stack.pop();
|
||||
|
||||
stack.push(new AsTypeAVM2Item(ins, val, new FullMultinameAVM2Item(ins, ins.operands[0])));
|
||||
stack.push(new AsTypeAVM2Item(ins, val, new FullMultinameAVM2Item(false, ins, ins.operands[0])));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,7 @@ public class IsTypeIns extends InstructionDefinition {
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
int multinameIndex = ins.operands[0];
|
||||
GraphTargetItem value = stack.pop();
|
||||
stack.push(new IsTypeAVM2Item(ins, value, new FullMultinameAVM2Item(ins, multinameIndex)));
|
||||
stack.push(new IsTypeAVM2Item(ins, value, new FullMultinameAVM2Item(false, ins, multinameIndex)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -35,25 +36,30 @@ public class FullMultinameAVM2Item extends AVM2Item {
|
||||
|
||||
public GraphTargetItem namespace;
|
||||
|
||||
public FullMultinameAVM2Item(AVM2Instruction instruction, int multinameIndex, GraphTargetItem name) {
|
||||
public boolean property;
|
||||
|
||||
public FullMultinameAVM2Item(boolean property, AVM2Instruction instruction, int multinameIndex, GraphTargetItem name) {
|
||||
super(instruction, PRECEDENCE_PRIMARY);
|
||||
this.multinameIndex = multinameIndex;
|
||||
this.name = name;
|
||||
this.namespace = null;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public FullMultinameAVM2Item(AVM2Instruction instruction, int multinameIndex) {
|
||||
public FullMultinameAVM2Item(boolean property, AVM2Instruction instruction, int multinameIndex) {
|
||||
super(instruction, PRECEDENCE_PRIMARY);
|
||||
this.multinameIndex = multinameIndex;
|
||||
this.name = null;
|
||||
this.namespace = null;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public FullMultinameAVM2Item(AVM2Instruction instruction, int multinameIndex, GraphTargetItem name, GraphTargetItem namespace) {
|
||||
public FullMultinameAVM2Item(boolean property, AVM2Instruction instruction, int multinameIndex, GraphTargetItem name, GraphTargetItem namespace) {
|
||||
super(instruction, PRECEDENCE_PRIMARY);
|
||||
this.multinameIndex = multinameIndex;
|
||||
this.name = name;
|
||||
this.namespace = namespace;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public boolean isRuntime() {
|
||||
@@ -96,7 +102,7 @@ public class FullMultinameAVM2Item extends AVM2Item {
|
||||
writer.append("]");
|
||||
} else {
|
||||
AVM2ConstantPool constants = localData.constantsAvm2;
|
||||
List<DottedChain> fullyQualifiedNames = localData.fullyQualifiedNames;
|
||||
List<DottedChain> fullyQualifiedNames = property ? new ArrayList<>() : localData.fullyQualifiedNames;
|
||||
if (multinameIndex > 0 && multinameIndex < constants.constant_multiname.size()) {
|
||||
writer.append(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false));
|
||||
} else {
|
||||
|
||||
@@ -304,6 +304,14 @@ public class Multiname {
|
||||
|
||||
public DottedChain getNameWithNamespace(AVM2ConstantPool constants) {
|
||||
Namespace ns = getNamespace(constants);
|
||||
if (ns == null) {
|
||||
NamespaceSet nss = getNamespaceSet(constants);
|
||||
if (nss != null) {
|
||||
if (nss.namespaces.length == 1) {
|
||||
ns = constants.getNamespace(nss.namespaces[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String name = getName(constants, null, true);
|
||||
if (ns != null) {
|
||||
return ns.getName(constants).add(name);
|
||||
|
||||
@@ -123,9 +123,9 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newimport.isEmpty()) {
|
||||
newimport = oldimport.add(name);
|
||||
}
|
||||
/* if (newimport.isEmpty()) {
|
||||
newimport = oldimport.add(name);
|
||||
}*/
|
||||
|
||||
if (!newimport.isEmpty()) {
|
||||
/* if(ns.kind==Namespace.KIND_PACKAGE){
|
||||
@@ -292,7 +292,6 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
}
|
||||
} else {
|
||||
for (int k = 0; k < ins.definition.operands.length; k++) {
|
||||
|
||||
if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) {
|
||||
int multinameIndex = ins.operands[k];
|
||||
if (multinameIndex < abc.constants.constant_multiname.size()) {
|
||||
@@ -395,29 +394,17 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
|
||||
List<String> importnames = new ArrayList<>();
|
||||
importnames.addAll(namesInThisPackage);
|
||||
for (DottedChain ipath : imports) {
|
||||
for (int i = 0; i < imports.size(); i++) {
|
||||
DottedChain ipath = imports.get(i);
|
||||
String name = ipath.getLast();
|
||||
DottedChain pkg = ipath.getWithoutLast();
|
||||
if (importnames.contains(name) || isBuiltInClass(name)) {
|
||||
imports.remove(i);
|
||||
i--;
|
||||
fullyQualifiedNames.add(new DottedChain(name));
|
||||
} else {
|
||||
importnames.add(name);
|
||||
}
|
||||
}
|
||||
/*List<DottedChain> imports2 = new ArrayList<String>();
|
||||
for (String path : imports) {
|
||||
String name = path;
|
||||
String pkg = "";
|
||||
if (name.contains(".")) {
|
||||
pkg = name.substring(0, name.lastIndexOf("."));
|
||||
name = name.substring(name.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
if ((!packageName.equals(pkg)) && (!fullyQualifiedNames.contains(name))) {
|
||||
imports2.add(path);
|
||||
}
|
||||
}
|
||||
imports = imports2;*/
|
||||
|
||||
for (int i = 0; i < imports.size(); i++) {
|
||||
DottedChain imp = imports.get(i);
|
||||
|
||||
@@ -80,7 +80,8 @@ public class TypeItem extends GraphTargetItem {
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
boolean as3 = localData.constantsAvm2 != null;
|
||||
if (localData.fullyQualifiedNames.contains(fullTypeName)) {
|
||||
|
||||
if (localData.fullyQualifiedNames.contains(new DottedChain(fullTypeName.getLast()))) {
|
||||
writer.hilightSpecial(fullTypeName.toPrintableString(as3), HighlightSpecialType.TYPE_NAME, fullTypeName.toPrintableString(as3));
|
||||
} else {
|
||||
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(as3, fullTypeName.getLast()), HighlightSpecialType.TYPE_NAME, fullTypeName.toPrintableString(as3));
|
||||
|
||||
Reference in New Issue
Block a user