mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-24 22:50:45 +00:00
AS3: Better finding usage of multinames
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.jpexs.asdec.abc;
|
package com.jpexs.asdec.abc;
|
||||||
|
|
||||||
import com.jpexs.asdec.Main;
|
import com.jpexs.asdec.Main;
|
||||||
@@ -36,7 +35,6 @@ import java.io.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class ABC {
|
public class ABC {
|
||||||
|
|
||||||
public int major_version = 0;
|
public int major_version = 0;
|
||||||
@@ -194,7 +192,7 @@ public class ABC {
|
|||||||
}
|
}
|
||||||
bodies[i].traits = ais.readTraits();
|
bodies[i].traits = ais.readTraits();
|
||||||
/*try {
|
/*try {
|
||||||
bodies[i].code.clearCode(constants, bodies[i]);
|
bodies[i].code.clearCode(constants, bodies[i]);
|
||||||
} catch (ConvertException ignored) {
|
} catch (ConvertException ignored) {
|
||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
@@ -517,8 +515,9 @@ public class ABC {
|
|||||||
|
|
||||||
//class header
|
//class header
|
||||||
String classHeader = instance_info[i].getClassHeaderStr(constants);
|
String classHeader = instance_info[i].getClassHeaderStr(constants);
|
||||||
if (classHeader.startsWith("private "))
|
if (classHeader.startsWith("private ")) {
|
||||||
classHeader = "public " + classHeader.substring("private ".length());
|
classHeader = "public " + classHeader.substring("private ".length());
|
||||||
|
}
|
||||||
out.println(IDENT_STRING + classHeader);
|
out.println(IDENT_STRING + classHeader);
|
||||||
out.println(IDENT_STRING + "{");
|
out.println(IDENT_STRING + "{");
|
||||||
|
|
||||||
@@ -687,13 +686,12 @@ public class ABC {
|
|||||||
output.println("MethodBody[" + i + "]:"); //+ bodies[i].toString(this, constants, method_info));
|
output.println("MethodBody[" + i + "]:"); //+ bodies[i].toString(this, constants, method_info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String[] reservedWords = {
|
public static final String[] reservedWords = {
|
||||||
"as", "break", "case", "catch", "class", "const", "continue", /*"default",*/ "delete", "do", "each", "else",
|
"as", "break", "case", "catch", "class", "const", "continue", /*"default",*/ "delete", "do", "each", "else",
|
||||||
"extends", "false", "finally", "for", "function", "if", "implements", "import", "in", "instanceof",
|
"extends", "false", "finally", "for", "function", "if", "implements", "import", "in", "instanceof",
|
||||||
"interface", "internal", "is", "native", "new", "null", "package", "private", "protected", "public",
|
"interface", "internal", "is", "native", "new", "null", "package", "private", "protected", "public",
|
||||||
"return", "super", "switch", "this", "throw", "true", "try", "typeof", "use", "var", /*"void",*/ "while",
|
"return", "super", "switch", "this", "throw", "true", "try", "typeof", "use", "var", /*"void",*/ "while",
|
||||||
"with"};
|
"with"};
|
||||||
public int unknownCount = 0;
|
public int unknownCount = 0;
|
||||||
|
|
||||||
public void cleanOneName(int index) {
|
public void cleanOneName(int index) {
|
||||||
@@ -733,20 +731,109 @@ public class ABC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> findMultinameUsage(int multinameIndex){
|
public List<Usage> findMultinameUsage(int multinameIndex) {
|
||||||
List<Integer> ret=new ArrayList<Integer>();
|
List<Usage> ret = new ArrayList<Usage>();
|
||||||
for(int i=0;i<bodies.length;i++){
|
List<Integer> bodyIndices = new ArrayList<Integer>();
|
||||||
loopbody:for(AVM2Instruction ins:bodies[i].code.code){
|
List<Integer> subTraitBodyIndices = new ArrayList<Integer>();
|
||||||
for(int op=0;op<ins.definition.operands.length;op++){
|
List<Integer> subTraitIndexIndices = new ArrayList<Integer>();
|
||||||
if(ins.definition.operands[op]==AVM2Code.DAT_MULTINAME_INDEX){
|
for (int i = 0; i < bodies.length; i++) {
|
||||||
if(ins.operands[op]==multinameIndex){
|
for(int t=0;t<bodies[i].traits.traits.length;t++){
|
||||||
ret.add(i);
|
Trait tr=bodies[i].traits.traits[t];
|
||||||
|
if(tr.name_index==multinameIndex){
|
||||||
|
subTraitBodyIndices.add(i);
|
||||||
|
subTraitIndexIndices.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loopbody:
|
||||||
|
for (AVM2Instruction ins : bodies[i].code.code) {
|
||||||
|
for (int op = 0; op < ins.definition.operands.length; op++) {
|
||||||
|
if (ins.definition.operands[op] == AVM2Code.DAT_MULTINAME_INDEX) {
|
||||||
|
if (ins.operands[op] == multinameIndex) {
|
||||||
|
bodyIndices.add(i);
|
||||||
break loopbody;
|
break loopbody;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int c = 0; c < class_info.length; c++) {
|
||||||
|
if(instance_info[c].name_index==multinameIndex){
|
||||||
|
ret.add(new Usage(this,-1, c, -1,-1, false, Usage.TYPE_CLASS_NAME));
|
||||||
|
}
|
||||||
|
for (int t = 0; t < class_info[c].static_traits.traits.length; t++) {
|
||||||
|
Trait tr = class_info[c].static_traits.traits[t];
|
||||||
|
if (tr.name_index == multinameIndex) {
|
||||||
|
ret.add(new Usage(this,-1, c, t,-1, true, Usage.TYPE_TRAIT_NAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int t = 0; t < instance_info[c].instance_traits.traits.length; t++) {
|
||||||
|
Trait tr = instance_info[c].instance_traits.traits[t];
|
||||||
|
if (tr.name_index == multinameIndex) {
|
||||||
|
ret.add(new Usage(this,-1, c, t,-1, false, Usage.TYPE_TRAIT_NAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int bodyIndex : bodyIndices) {
|
||||||
|
for (int c = 0; c < class_info.length; c++) {
|
||||||
|
if (class_info[c].cinit_index == bodyIndex) {
|
||||||
|
ret.add(new Usage(this, bodyIndex,c, -1,-1, true, Usage.TYPE_INITIALIZER));
|
||||||
|
}
|
||||||
|
if (instance_info[c].iinit_index == bodyIndex) {
|
||||||
|
ret.add(new Usage(this, bodyIndex,c, -1,-1, false, Usage.TYPE_INITIALIZER));
|
||||||
|
}
|
||||||
|
for (int t = 0; t < class_info[c].static_traits.traits.length; t++) {
|
||||||
|
Trait tr = class_info[c].static_traits.traits[t];
|
||||||
|
if (tr instanceof TraitMethodGetterSetter) {
|
||||||
|
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) tr;
|
||||||
|
if (tmgs.method_info == bodies[bodyIndex].method_info) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, t,-1, true, Usage.TYPE_TRAIT_BODY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int t = 0; t < instance_info[c].instance_traits.traits.length; t++) {
|
||||||
|
Trait tr = instance_info[c].instance_traits.traits[t];
|
||||||
|
if (tr instanceof TraitMethodGetterSetter) {
|
||||||
|
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) tr;
|
||||||
|
if (tmgs.method_info == bodies[bodyIndex].method_info) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, t,-1, false, Usage.TYPE_TRAIT_BODY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int b=0;b<subTraitBodyIndices.size();b++) {
|
||||||
|
int bodyIndex=subTraitBodyIndices.get(b);
|
||||||
|
for (int c = 0; c < class_info.length; c++) {
|
||||||
|
if (class_info[c].cinit_index == bodyIndex) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, -1,subTraitIndexIndices.get(b), true, Usage.TYPE_INITIALIZER_SUBTRAIT_NAME));
|
||||||
|
}
|
||||||
|
if (instance_info[c].iinit_index == bodyIndex) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, -1,subTraitIndexIndices.get(b), false, Usage.TYPE_INITIALIZER_SUBTRAIT_NAME));
|
||||||
|
}
|
||||||
|
for (int t = 0; t < class_info[c].static_traits.traits.length; t++) {
|
||||||
|
Trait tr = class_info[c].static_traits.traits[t];
|
||||||
|
if (tr instanceof TraitMethodGetterSetter) {
|
||||||
|
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) tr;
|
||||||
|
if (tmgs.method_info == bodies[bodyIndex].method_info) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, t,subTraitIndexIndices.get(b), true, Usage.TYPE_SUBTRAIT_NAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int t = 0; t < instance_info[c].instance_traits.traits.length; t++) {
|
||||||
|
Trait tr = instance_info[c].instance_traits.traits[t];
|
||||||
|
if (tr instanceof TraitMethodGetterSetter) {
|
||||||
|
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) tr;
|
||||||
|
if (tmgs.method_info == bodies[bodyIndex].method_info) {
|
||||||
|
ret.add(new Usage(this,bodyIndex, c, t,subTraitIndexIndices.get(b), false, Usage.TYPE_SUBTRAIT_NAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 JPEXS
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.jpexs.asdec.abc;
|
||||||
|
|
||||||
|
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||||
|
import com.jpexs.asdec.abc.types.traits.TraitMethodGetterSetter;
|
||||||
|
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author JPEXS
|
||||||
|
*/
|
||||||
|
public class Usage {
|
||||||
|
public int classIndex;
|
||||||
|
public int traitIndex;
|
||||||
|
public int subTraitIndex;
|
||||||
|
public boolean isStatic;
|
||||||
|
public static final int TYPE_CLASS_NAME=0;
|
||||||
|
public static final int TYPE_TRAIT_NAME=1;
|
||||||
|
public static final int TYPE_SUBTRAIT_NAME=4;
|
||||||
|
public static final int TYPE_INITIALIZER_SUBTRAIT_NAME=5;
|
||||||
|
public static final int TYPE_INITIALIZER=2;
|
||||||
|
public static final int TYPE_TRAIT_BODY=3;
|
||||||
|
public int type;
|
||||||
|
public ABC abc;
|
||||||
|
public int bodyIndex;
|
||||||
|
|
||||||
|
|
||||||
|
public Usage(ABC abc,int bodyIndex,int classIndex, int traitIndex, int subTraitIndex, boolean isStatic, int type) {
|
||||||
|
this.abc = abc;
|
||||||
|
this.classIndex = classIndex;
|
||||||
|
this.traitIndex = traitIndex;
|
||||||
|
this.isStatic = isStatic;
|
||||||
|
this.type = type;
|
||||||
|
this.subTraitIndex = subTraitIndex;
|
||||||
|
this.bodyIndex = bodyIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String ret="";
|
||||||
|
String className=abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants);
|
||||||
|
Trait tr=null;
|
||||||
|
String staticStr="";
|
||||||
|
String traitName="";
|
||||||
|
String subTraitName="";
|
||||||
|
switch(type){
|
||||||
|
case TYPE_CLASS_NAME:
|
||||||
|
return "Class "+className;
|
||||||
|
case TYPE_TRAIT_NAME:
|
||||||
|
|
||||||
|
if(isStatic){
|
||||||
|
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
|
||||||
|
}else{
|
||||||
|
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
|
||||||
|
}
|
||||||
|
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
|
||||||
|
staticStr=isStatic?"static ":"";
|
||||||
|
String typeStr="";
|
||||||
|
if(tr instanceof TraitMethodGetterSetter) typeStr="method ";
|
||||||
|
if(tr instanceof TraitSlotConst) {
|
||||||
|
if(((TraitSlotConst)tr).isConst()) typeStr="const ";
|
||||||
|
if(((TraitSlotConst)tr).isVar()) typeStr="var ";
|
||||||
|
}
|
||||||
|
return staticStr+typeStr+className+"."+traitName;
|
||||||
|
case TYPE_INITIALIZER_SUBTRAIT_NAME:
|
||||||
|
case TYPE_INITIALIZER:
|
||||||
|
if(type==TYPE_SUBTRAIT_NAME){
|
||||||
|
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
|
||||||
|
}
|
||||||
|
if(isStatic){
|
||||||
|
return "static initializer "+className+subTraitName;
|
||||||
|
}else{
|
||||||
|
return "instance initializer "+className+subTraitName;
|
||||||
|
}
|
||||||
|
case TYPE_SUBTRAIT_NAME:
|
||||||
|
case TYPE_TRAIT_BODY:
|
||||||
|
if(isStatic){
|
||||||
|
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
|
||||||
|
}else{
|
||||||
|
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
|
||||||
|
}
|
||||||
|
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
|
||||||
|
|
||||||
|
if(type==TYPE_SUBTRAIT_NAME){
|
||||||
|
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
|
||||||
|
}
|
||||||
|
staticStr=isStatic?"static ":"";
|
||||||
|
return staticStr+"method body "+className+"."+traitName+subTraitName;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
package com.jpexs.asdec.abc.gui;
|
package com.jpexs.asdec.abc.gui;
|
||||||
|
|
||||||
import com.jpexs.asdec.abc.ABC;
|
import com.jpexs.asdec.abc.ABC;
|
||||||
|
import com.jpexs.asdec.abc.Usage;
|
||||||
import com.jpexs.asdec.abc.types.traits.Trait;
|
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||||
import com.jpexs.asdec.abc.types.traits.TraitMethodGetterSetter;
|
import com.jpexs.asdec.abc.types.traits.TraitMethodGetterSetter;
|
||||||
import com.jpexs.asdec.gui.View;
|
import com.jpexs.asdec.gui.View;
|
||||||
@@ -45,28 +46,9 @@ public class UsageFrame extends JFrame implements ActionListener {
|
|||||||
private JList usageList;
|
private JList usageList;
|
||||||
private DefaultListModel usageListModel=new DefaultListModel();
|
private DefaultListModel usageListModel=new DefaultListModel();
|
||||||
public UsageFrame(ABC abc,int multinameIndex){
|
public UsageFrame(ABC abc,int multinameIndex){
|
||||||
List<Integer> usages=abc.findMultinameUsage(multinameIndex);
|
List<Usage> usages=abc.findMultinameUsage(multinameIndex);
|
||||||
for(int bodyIndex:usages){
|
for(Usage u:usages){
|
||||||
for(int c=0;c<abc.class_info.length;c++){
|
usageListModel.addElement(u);
|
||||||
if(abc.class_info[c].cinit_index==bodyIndex) usageListModel.addElement(abc.instance_info[c].getName(abc.constants).getNameWithNamespace(abc.constants)+" (static initializer)");
|
|
||||||
if(abc.instance_info[c].iinit_index==bodyIndex) usageListModel.addElement(abc.instance_info[c].getName(abc.constants).getNameWithNamespace(abc.constants)+" (instance initializer)");
|
|
||||||
for(Trait t:abc.class_info[c].static_traits.traits){
|
|
||||||
if(t instanceof TraitMethodGetterSetter){
|
|
||||||
TraitMethodGetterSetter tmgs=(TraitMethodGetterSetter)t;
|
|
||||||
if(tmgs.method_info==abc.bodies[bodyIndex].method_info){
|
|
||||||
usageListModel.addElement("static "+abc.instance_info[c].getName(abc.constants).getNameWithNamespace(abc.constants)+"."+tmgs.getMethodName(abc.constants));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Trait t:abc.instance_info[c].instance_traits.traits){
|
|
||||||
if(t instanceof TraitMethodGetterSetter){
|
|
||||||
TraitMethodGetterSetter tmgs=(TraitMethodGetterSetter)t;
|
|
||||||
if(tmgs.method_info==abc.bodies[bodyIndex].method_info){
|
|
||||||
usageListModel.addElement(abc.instance_info[c].getName(abc.constants).getNameWithNamespace(abc.constants)+"."+tmgs.getMethodName(abc.constants));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
usageList=new JList(usageListModel);
|
usageList=new JList(usageListModel);
|
||||||
gotoButton.setActionCommand("GOTO");
|
gotoButton.setActionCommand("GOTO");
|
||||||
|
|||||||
@@ -72,4 +72,12 @@ public class TraitSlotConst extends Trait {
|
|||||||
return modifier + getNameValueStr(constants);
|
return modifier + getNameValueStr(constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConst(){
|
||||||
|
return kindType == TRAIT_CONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVar(){
|
||||||
|
return kindType == TRAIT_SLOT;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user