mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-08-02 15:51:16 +00:00
AS3: Editing types and default values of Slot/Const trait type
This commit is contained in:
@@ -519,6 +519,18 @@ public class ABC {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Trait findTraitByTraitId(int classIndex, int traitId)
|
||||
{
|
||||
if (traitId < class_info[classIndex].static_traits.traits.length) {
|
||||
return class_info[classIndex].static_traits.traits[traitId];
|
||||
} else if (traitId < class_info[classIndex].static_traits.traits.length + instance_info[classIndex].instance_traits.traits.length) {
|
||||
traitId -= class_info[classIndex].static_traits.traits.length;
|
||||
return instance_info[classIndex].instance_traits.traits[traitId];
|
||||
} else {
|
||||
return null; //Can be class or instance initializer
|
||||
}
|
||||
}
|
||||
|
||||
public int findMethodIdByTraitId(int classIndex, int traitId) {
|
||||
if (traitId < class_info[classIndex].static_traits.traits.length) {
|
||||
if (class_info[classIndex].static_traits.traits[traitId] instanceof TraitMethodGetterSetter) {
|
||||
|
||||
@@ -20,6 +20,8 @@ package com.jpexs.asdec.abc.gui;
|
||||
import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.avm2.ConvertException;
|
||||
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
|
||||
import com.jpexs.asdec.helpers.Highlighting;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -48,13 +50,20 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
int pos = getCaretPosition();
|
||||
for (Highlighting th : traitHighlights) {
|
||||
if ((pos >= th.startPos) && (pos < th.startPos + th.len)) {
|
||||
|
||||
lastTraitIndex = (int) th.offset;
|
||||
Trait tr=abc.findTraitByTraitId(classIndex, (int) th.offset);
|
||||
if(tr!=null){
|
||||
if(tr instanceof TraitSlotConst){
|
||||
Main.abcMainFrame.detailPanel.slotConstTraitPanel.load((TraitSlotConst)tr, abc);
|
||||
Main.abcMainFrame.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD);
|
||||
return;
|
||||
}
|
||||
}
|
||||
int bi = abc.findBodyIndex(abc.findMethodIdByTraitId(classIndex, (int) th.offset));
|
||||
if (bi == -1) {
|
||||
break;
|
||||
}
|
||||
Main.abcMainFrame.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD);
|
||||
lastTraitIndex = (int) th.offset;
|
||||
Main.abcMainFrame.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD);
|
||||
if (Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) {
|
||||
Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc);
|
||||
Main.abcMainFrame.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]);
|
||||
@@ -102,8 +111,12 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
}
|
||||
for (Highlighting th : traitHighlights) {
|
||||
if (th.offset == traitId) {
|
||||
//setCaretPosition(th.startPos + th.len - 1);
|
||||
setCaretPosition(th.startPos);
|
||||
try{
|
||||
setCaretPosition(th.startPos + th.len - 1);
|
||||
setCaretPosition(th.startPos);
|
||||
}catch(IllegalArgumentException iae){
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,22 @@
|
||||
|
||||
package com.jpexs.asdec.abc.gui;
|
||||
|
||||
import com.jpexs.asdec.Main;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -38,12 +42,15 @@ import javax.swing.SwingConstants;
|
||||
public class DetailPanel extends JPanel implements ActionListener {
|
||||
public MethodTraitDetailPanel methodTraitPanel;
|
||||
public JPanel unsupportedTraitPanel;
|
||||
public static final String METHOD_TRAIT_CARD="MethodTrait";
|
||||
public static final String UNSUPPORTED_TRAIT_CARD="UnsupportedTrait";
|
||||
public SlotConstTraitDetailPanel slotConstTraitPanel;
|
||||
public static final String METHOD_TRAIT_CARD="Method/Getter/Setter Trait";
|
||||
public static final String UNSUPPORTED_TRAIT_CARD="Unsupported Trait Type";
|
||||
public static final String SLOT_CONST_TRAIT_CARD="Slot/Const Trait";
|
||||
private JPanel innerPanel;
|
||||
public JButton saveButton;
|
||||
private HashMap<String,JComponent> cardMap=new HashMap<String,JComponent>();
|
||||
private String selectedCard;
|
||||
private JLabel selectedLabel;
|
||||
|
||||
public DetailPanel()
|
||||
{
|
||||
@@ -59,6 +66,8 @@ public class DetailPanel extends JPanel implements ActionListener {
|
||||
|
||||
cardMap.put(UNSUPPORTED_TRAIT_CARD, unsupportedTraitPanel);
|
||||
|
||||
slotConstTraitPanel=new SlotConstTraitDetailPanel();
|
||||
cardMap.put(SLOT_CONST_TRAIT_CARD,slotConstTraitPanel);
|
||||
|
||||
for(String key:cardMap.keySet())
|
||||
{
|
||||
@@ -70,14 +79,20 @@ public class DetailPanel extends JPanel implements ActionListener {
|
||||
|
||||
JPanel buttonsPanel=new JPanel();
|
||||
buttonsPanel.setLayout(new FlowLayout());
|
||||
saveButton = new JButton("Save");
|
||||
saveButton = new JButton("Save trait");
|
||||
saveButton.setActionCommand("SAVEDETAIL");
|
||||
saveButton.addActionListener(this);
|
||||
buttonsPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
|
||||
buttonsPanel.add(saveButton);
|
||||
add(buttonsPanel,BorderLayout.SOUTH);
|
||||
selectedCard=UNSUPPORTED_TRAIT_CARD;
|
||||
layout.show(innerPanel, UNSUPPORTED_TRAIT_CARD);
|
||||
saveButton.setVisible(false);
|
||||
selectedLabel=new JLabel("");
|
||||
selectedLabel.setText(selectedCard);
|
||||
selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
|
||||
selectedLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(selectedLabel,BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
public void showCard(String name)
|
||||
@@ -86,6 +101,7 @@ public class DetailPanel extends JPanel implements ActionListener {
|
||||
layout.show(innerPanel, name);
|
||||
saveButton.setVisible(cardMap.get(name) instanceof TraitDetail);
|
||||
selectedCard=name;
|
||||
selectedLabel.setText(selectedCard);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -94,6 +110,9 @@ public class DetailPanel extends JPanel implements ActionListener {
|
||||
{
|
||||
if(((TraitDetail)cardMap.get(selectedCard)).save())
|
||||
{
|
||||
int lasttrait = Main.abcMainFrame.decompiledTextArea.lastTraitIndex;
|
||||
Main.abcMainFrame.decompiledTextArea.reloadClass();
|
||||
Main.abcMainFrame.decompiledTextArea.gotoTrait(lasttrait);
|
||||
JOptionPane.showMessageDialog(this, "Trait Successfully saved");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +54,7 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int lasttrait = Main.abcMainFrame.decompiledTextArea.lastTraitIndex;
|
||||
Main.abcMainFrame.decompiledTextArea.reloadClass();
|
||||
Main.abcMainFrame.decompiledTextArea.gotoTrait(lasttrait);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.gui;
|
||||
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.methodinfo_parser.MethodInfoParser;
|
||||
import com.jpexs.asdec.abc.methodinfo_parser.ParseException;
|
||||
import com.jpexs.asdec.abc.types.ValueKind;
|
||||
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
|
||||
import com.jpexs.asdec.helpers.Helper;
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import jsyntaxpane.syntaxkits.Flasm3MethodInfoSyntaxKit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail {
|
||||
|
||||
public JEditorPane slotConstEditor;
|
||||
private ABC abc;
|
||||
private TraitSlotConst trait;
|
||||
|
||||
public SlotConstTraitDetailPanel() {
|
||||
slotConstEditor=new JEditorPane();
|
||||
setLayout(new BorderLayout());
|
||||
add(new JLabel("Type and Value:"),BorderLayout.NORTH);
|
||||
add(new JScrollPane(slotConstEditor),BorderLayout.CENTER);
|
||||
slotConstEditor.setContentType("text/flasm3_methodinfo");
|
||||
Flasm3MethodInfoSyntaxKit sk=(Flasm3MethodInfoSyntaxKit)slotConstEditor.getEditorKit();
|
||||
sk.deinstallComponent(slotConstEditor, "jsyntaxpane.components.LineNumbersRuler");
|
||||
}
|
||||
|
||||
|
||||
public void load(TraitSlotConst trait,ABC abc){
|
||||
this.abc=abc;
|
||||
this.trait=trait;
|
||||
String s="";
|
||||
String typeStr = "*";
|
||||
if (trait.type_index > 0) {
|
||||
typeStr = "m["+trait.type_index+"]\""+Helper.escapeString(abc.constants.constant_multiname[trait.type_index].toString(abc.constants))+"\"";
|
||||
}else{
|
||||
typeStr = "*";
|
||||
}
|
||||
String valueStr = "";
|
||||
if (trait.value_kind != 0) {
|
||||
valueStr = " = " + (new ValueKind(trait.value_index, trait.value_kind)).toString(abc.constants);
|
||||
}
|
||||
|
||||
s=typeStr + valueStr;
|
||||
|
||||
slotConstEditor.setText(s);
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
try {
|
||||
if(!MethodInfoParser.parseSlotConst(slotConstEditor.getText(), trait, abc)){
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException ex) {
|
||||
JOptionPane.showMessageDialog(slotConstEditor, ex.text, "SlotConst typevalue Error", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,8 +37,7 @@ public class TraitsList extends JList implements ListSelectionListener {
|
||||
|
||||
public void setABC(ABC abc) {
|
||||
this.abc = abc;
|
||||
if (classIndex != -1)
|
||||
setModel(new TraitsListModel(abc, classIndex));
|
||||
setModel(new DefaultListModel());
|
||||
}
|
||||
|
||||
public void setClassIndex(int classIndex) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
import com.jpexs.asdec.abc.types.ValueKind;
|
||||
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,6 +33,105 @@ import java.util.List;
|
||||
*/
|
||||
public class MethodInfoParser {
|
||||
|
||||
public static boolean parseSlotConst(String text,TraitSlotConst trait,ABC abc) throws ParseException{
|
||||
MethodInfoLexer lexer = new MethodInfoLexer(new ByteArrayInputStream(text.getBytes()));
|
||||
ParsedSymbol symb;
|
||||
int type_index=-1;
|
||||
ValueKind value=new ValueKind(0,0);
|
||||
try{
|
||||
ParsedSymbol symbType=lexer.yylex();
|
||||
if(symbType.type==ParsedSymbol.TYPE_STAR)
|
||||
{
|
||||
type_index=0;
|
||||
}else if(symbType.type==ParsedSymbol.TYPE_MULTINAME){
|
||||
type_index=(int)(long)(Long)symbType.value;
|
||||
}else{
|
||||
throw new ParseException("Multiname or * expected", lexer.yyline());
|
||||
}
|
||||
ParsedSymbol symbEqual=lexer.yylex();
|
||||
if(symbEqual.type==ParsedSymbol.TYPE_ASSIGN)
|
||||
{
|
||||
ParsedSymbol symbValue;
|
||||
String nstype="";
|
||||
do{
|
||||
symbValue=lexer.yylex();
|
||||
if(symbValue.type>=8&&symbValue.type<=13){
|
||||
nstype=nstype+symbValue.type+":";
|
||||
}
|
||||
}while(symbValue.type>=8&&symbValue.type<=13);
|
||||
if((!nstype.equals(""))&&(symbValue.type!=ParsedSymbol.TYPE_NAMESPACE))
|
||||
{
|
||||
throw new ParseException("Namespace expected", lexer.yyline());
|
||||
}
|
||||
int id=0;
|
||||
switch(symbValue.type)
|
||||
{
|
||||
case ParsedSymbol.TYPE_INTEGER:
|
||||
value=new ValueKind(abc.constants.forceGetIntId((Long)symbValue.value),ValueKind.CONSTANT_Int);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_FLOAT:
|
||||
value=new ValueKind(abc.constants.forceGetDoubleId((Double)symbValue.value),ValueKind.CONSTANT_Double);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_STRING:
|
||||
value=new ValueKind(abc.constants.forceGetStringId((String)symbValue.value),ValueKind.CONSTANT_Utf8);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_TRUE:
|
||||
value=new ValueKind(0,ValueKind.CONSTANT_True);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_FALSE:
|
||||
value=new ValueKind(0,ValueKind.CONSTANT_False);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_NULL:
|
||||
value=new ValueKind(0,ValueKind.CONSTANT_Null);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_UNDEFINED:
|
||||
value=new ValueKind(0,ValueKind.CONSTANT_Undefined);
|
||||
break;
|
||||
case ParsedSymbol.TYPE_NAMESPACE:
|
||||
if(nstype.equals("9:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PackageNamespace);
|
||||
}else
|
||||
if(nstype.equals("9:10:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PackageInternalNs);
|
||||
}else
|
||||
if(nstype.equals("13:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_ProtectedNamespace);
|
||||
}else
|
||||
if(nstype.equals("12:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_ExplicitNamespace);
|
||||
}else
|
||||
if(nstype.equals("11:13:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_StaticProtectedNs);
|
||||
}else
|
||||
if(nstype.equals("8:")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PrivateNs);
|
||||
}else if(nstype.equals("")){
|
||||
value=new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_Namespace);
|
||||
}else{
|
||||
throw new ParseException("Invalid type of namespace", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
symb=lexer.yylex();
|
||||
if(symb.type!=ParsedSymbol.TYPE_EOF){
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
}else if(symbEqual.type==ParsedSymbol.TYPE_EOF){
|
||||
|
||||
} else {
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
}catch(IOException ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
trait.type_index=type_index;
|
||||
trait.value_kind=value.value_kind;
|
||||
trait.value_index=value.value_index;
|
||||
return true;
|
||||
}
|
||||
public static boolean parseReturnType(String text, MethodInfo update) throws ParseException {
|
||||
MethodInfoLexer lexer = new MethodInfoLexer(new ByteArrayInputStream(text.getBytes()));
|
||||
ParsedSymbol symb;
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.jpexs.asdec.abc.types.traits;
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
|
||||
import com.jpexs.asdec.abc.types.MethodBody;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
import com.jpexs.asdec.abc.types.ValueKind;
|
||||
import com.jpexs.asdec.helpers.Helper;
|
||||
|
||||
Reference in New Issue
Block a user