├── LICENSE ├── README.md ├── lib ├── cfr-0.146.jar ├── jgraphx.jar ├── rsyntaxtextarea-1-9-2019.jar └── weblaf-1.28.jar └── src ├── me └── nov │ └── cafebabe │ ├── Cafebabe.java │ ├── analysis │ └── blocks │ │ ├── Block.java │ │ └── Converter.java │ ├── decompiler │ └── CFR.java │ ├── gui │ ├── ClassMemberList.java │ ├── ClassTree.java │ ├── HelpBar.java │ ├── InnerSplitPane.java │ ├── OuterSplitPane.java │ ├── decompiler │ │ ├── DecompilerPanel.java │ │ └── DecompilerTextArea.java │ ├── editor │ │ ├── Editor.java │ │ ├── InstructionPanel.java │ │ └── list │ │ │ ├── AdressList.java │ │ │ └── InstructionList.java │ ├── graph │ │ ├── CFGPanel.java │ │ ├── CFGraph.java │ │ ├── layout │ │ │ ├── PatchedCoordinateAssignment.java │ │ │ └── PatchedHierarchicalLayout.java │ │ └── vertex │ │ │ └── BlockVertex.java │ ├── node │ │ ├── InstructionNode.java │ │ ├── MethodListNode.java │ │ ├── OpcodeNode.java │ │ ├── SettingNode.java │ │ └── SortedTreeClassNode.java │ ├── opchooser │ │ ├── OpcodeChooserDialog.java │ │ └── OpcodeChooserPane.java │ ├── preferences │ │ ├── AboutPanel.java │ │ ├── PreferencesDialog.java │ │ ├── PreferencesPane.java │ │ └── list │ │ │ └── SettingList.java │ ├── smalleditor │ │ ├── ChangelogPanel.java │ │ ├── ClassEditorPanel.java │ │ ├── InstructionEditorPanel.java │ │ ├── MethodEditorPanel.java │ │ └── list │ │ │ └── OpList.java │ ├── translations │ │ └── TranslationEditor.java │ └── ui │ │ ├── ClassTreeCellRenderer.java │ │ └── MethodListCellRenderer.java │ ├── loading │ ├── FrameHack.java │ ├── Loader.java │ └── Saver.java │ ├── setting │ ├── Setting.java │ └── Settings.java │ ├── translations │ └── Translations.java │ └── utils │ ├── analysis │ ├── CoffeeInterpreter.java │ └── CoffeeValue.java │ ├── asm │ ├── Access.java │ ├── Code.java │ ├── Descriptors.java │ ├── Hints.java │ ├── LibClassWriter.java │ ├── OpcodeLink.java │ └── ParentUtils.java │ ├── drop │ ├── IDropUser.java │ └── JarDropHandler.java │ ├── formatting │ ├── Colors.java │ ├── EscapedString.java │ ├── Html.java │ ├── InstructionFormatting.java │ └── OpcodeFormatting.java │ ├── interfaces │ ├── Action.java │ └── BooleanAction.java │ ├── io │ └── Scanning.java │ ├── ui │ ├── Images.java │ ├── LazyListModel.java │ ├── Listeners.java │ └── WebLaF.java │ └── web │ └── URLReader.java ├── org └── objectweb │ └── asm │ ├── AnnotationVisitor.java │ ├── AnnotationWriter.java │ ├── Attribute.java │ ├── ByteVector.java │ ├── ClassReader.java │ ├── ClassTooLargeException.java │ ├── ClassVisitor.java │ ├── ClassWriter.java │ ├── ConstantDynamic.java │ ├── Constants.java │ ├── Context.java │ ├── CurrentFrame.java │ ├── Edge.java │ ├── FieldVisitor.java │ ├── FieldWriter.java │ ├── Frame.java │ ├── Handle.java │ ├── Handler.java │ ├── Label.java │ ├── MethodTooLargeException.java │ ├── MethodVisitor.java │ ├── MethodWriter.java │ ├── ModuleVisitor.java │ ├── ModuleWriter.java │ ├── Opcodes.java │ ├── Symbol.java │ ├── SymbolTable.java │ ├── Type.java │ ├── TypePath.java │ ├── TypeReference.java │ ├── package.html │ ├── signature │ ├── SignatureReader.java │ ├── SignatureVisitor.java │ ├── SignatureWriter.java │ └── package.html │ └── tree │ ├── AbstractInsnNode.java │ ├── AnnotationNode.java │ ├── ClassNode.java │ ├── FieldInsnNode.java │ ├── FieldNode.java │ ├── FrameNode.java │ ├── IincInsnNode.java │ ├── InnerClassNode.java │ ├── InsnList.java │ ├── InsnNode.java │ ├── IntInsnNode.java │ ├── InvokeDynamicInsnNode.java │ ├── JumpInsnNode.java │ ├── LabelNode.java │ ├── LdcInsnNode.java │ ├── LineNumberNode.java │ ├── LocalVariableAnnotationNode.java │ ├── LocalVariableNode.java │ ├── LookupSwitchInsnNode.java │ ├── MethodInsnNode.java │ ├── MethodNode.java │ ├── ModuleExportNode.java │ ├── ModuleNode.java │ ├── ModuleOpenNode.java │ ├── ModuleProvideNode.java │ ├── ModuleRequireNode.java │ ├── MultiANewArrayInsnNode.java │ ├── ParameterNode.java │ ├── TableSwitchInsnNode.java │ ├── TryCatchBlockNode.java │ ├── TypeAnnotationNode.java │ ├── TypeInsnNode.java │ ├── UnsupportedClassVersionException.java │ ├── Util.java │ ├── VarInsnNode.java │ ├── analysis │ ├── Analyzer.java │ ├── AnalyzerException.java │ ├── BasicInterpreter.java │ ├── BasicValue.java │ ├── BasicVerifier.java │ ├── Frame.java │ ├── Interpreter.java │ ├── SimpleVerifier.java │ ├── SmallSet.java │ ├── SourceInterpreter.java │ ├── SourceValue.java │ ├── Subroutine.java │ ├── Value.java │ └── package.html │ └── package.html └── resources ├── LICENSES ├── about.txt ├── access ├── abstract.png ├── constructor.png ├── final.png ├── native.png ├── static.png ├── synchronized.png ├── synthetic.png ├── transient.png └── volatile.png ├── changelog.txt ├── classtype ├── class.png ├── enum.png └── interface.png ├── file.png ├── html └── optable.html ├── icon.png ├── license.txt ├── method ├── default.png ├── private.png ├── protected.png └── public.png ├── overlay └── info.png └── tree └── package.png /README.md: -------------------------------------------------------------------------------- 1 | # Cafebabe Lite 2 | 3 | Cafebabe is an user-friendly java bytecode editor suited for bytecode amateurs and pros. It supports multiview; edit and decompile multiple class files at once. Many features have been adopted from JByteMod, including the control flow graphing capability. Using Cafebabe you don't have to create or edit stack frames manually, they will automatically get regenerated at exporting, without the requirement of library jar files needed at runtime. Method descriptors will automatically be reversed to original java-syntax and node access can be changed without knowing the actual jvm access-values. 4 | Try catch blocks are (*going to be*) automatically implemented into the bytecode as well as jump offsets (labels). You don't need to know every opcode, the in-editor help will explain them to you. 5 | Note that this version is not completed yet and may not support some features listed here. If you encounter bugs, please report them by opening an issue. You are also welcome to contribute to this project! 6 | 7 | ## Screenshots 8 | ![Screenshot 1](https://i.imgur.com/hR5TUUE.png) 9 | ![Screenshot 2](https://i.imgur.com/GHtHY6v.png) 10 | ![Screenshot 3](https://i.imgur.com/yU0BvIs.png) 11 | ![Screenshot 4](https://i.imgur.com/GAVzrhy.png) 12 | ![Screenshot 5](https://i.imgur.com/XCja3oY.png) 13 | ## Libraries 14 | - Objectweb ASM 7.0 (Modified version) 15 | - WebLaF 1.28 16 | - RSyntaxTextArea ? 17 | - CFR Decompiler 0.145 18 | - JGraphX ? 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib/cfr-0.146.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/lib/cfr-0.146.jar -------------------------------------------------------------------------------- /lib/jgraphx.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/lib/jgraphx.jar -------------------------------------------------------------------------------- /lib/rsyntaxtextarea-1-9-2019.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/lib/rsyntaxtextarea-1-9-2019.jar -------------------------------------------------------------------------------- /lib/weblaf-1.28.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/lib/weblaf-1.28.jar -------------------------------------------------------------------------------- /src/me/nov/cafebabe/analysis/blocks/Block.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.analysis.blocks; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.objectweb.asm.tree.AbstractInsnNode; 6 | import org.objectweb.asm.tree.JumpInsnNode; 7 | import org.objectweb.asm.tree.LabelNode; 8 | import org.objectweb.asm.tree.LookupSwitchInsnNode; 9 | import org.objectweb.asm.tree.TableSwitchInsnNode; 10 | 11 | public class Block { 12 | private ArrayList output = new ArrayList<>(); 13 | 14 | /** 15 | * when output is added automatically add input 16 | **/ 17 | private ArrayList input = new ArrayList<>(); 18 | 19 | private AbstractInsnNode endNode; 20 | private ArrayList nodes = new ArrayList<>(); 21 | 22 | private LabelNode label; 23 | 24 | private ArrayList surroundingBlocks = new ArrayList<>(); 25 | private int depth; 26 | 27 | public Block() { 28 | super(); 29 | } 30 | 31 | public AbstractInsnNode getEndNode() { 32 | return endNode; 33 | } 34 | 35 | public void setEndNode(AbstractInsnNode endNode) { 36 | this.endNode = endNode; 37 | } 38 | 39 | public ArrayList getOutput() { 40 | return output; 41 | } 42 | 43 | public void setOutput(ArrayList output) { 44 | this.output = output; 45 | } 46 | 47 | public ArrayList getInput() { 48 | return input; 49 | } 50 | 51 | public void setInput(ArrayList input) { 52 | this.input = input; 53 | } 54 | 55 | public LabelNode getLabel() { 56 | return label; 57 | } 58 | 59 | public void setLabel(LabelNode label) { 60 | this.label = label; 61 | } 62 | 63 | public ArrayList getNodes() { 64 | return nodes; 65 | } 66 | 67 | public void setNodes(ArrayList nodes) { 68 | this.nodes = nodes; 69 | } 70 | 71 | public ArrayList getSurroundingBlocks() { 72 | return surroundingBlocks; 73 | } 74 | 75 | public void setSurroundingBlocks(ArrayList surroundingBlocks) { 76 | this.surroundingBlocks = surroundingBlocks; 77 | } 78 | 79 | public int getDepth() { 80 | return depth; 81 | } 82 | 83 | public void setDepth(int depth) { 84 | this.depth = depth; 85 | } 86 | 87 | public boolean endsWithJump() { 88 | return endNode instanceof JumpInsnNode; 89 | } 90 | 91 | public boolean endsWithSwitch() { 92 | return endNode instanceof TableSwitchInsnNode || endNode instanceof LookupSwitchInsnNode; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/ClassMemberList.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui; 2 | 3 | import javax.swing.JTree; 4 | import javax.swing.event.TreeSelectionEvent; 5 | import javax.swing.event.TreeSelectionListener; 6 | import javax.swing.tree.DefaultTreeModel; 7 | import javax.swing.tree.TreeSelectionModel; 8 | 9 | import org.objectweb.asm.tree.ClassNode; 10 | import org.objectweb.asm.tree.MethodNode; 11 | 12 | import me.nov.cafebabe.Cafebabe; 13 | import me.nov.cafebabe.gui.node.MethodListNode; 14 | import me.nov.cafebabe.gui.smalleditor.MethodEditorPanel; 15 | import me.nov.cafebabe.gui.ui.MethodListCellRenderer; 16 | 17 | public class ClassMemberList extends JTree { 18 | private static final long serialVersionUID = 1L; 19 | 20 | private DefaultTreeModel model; 21 | private MethodListNode root; 22 | 23 | public ClassMemberList() { 24 | MethodEditorPanel editor = new MethodEditorPanel(this); 25 | this.setRootVisible(false); 26 | this.setShowsRootHandles(false); 27 | this.setFocusable(false); 28 | this.setCellRenderer(new MethodListCellRenderer()); 29 | this.addTreeSelectionListener(new TreeSelectionListener() { 30 | @Override 31 | public void valueChanged(TreeSelectionEvent e) { 32 | MethodListNode node = (MethodListNode) getLastSelectedPathComponent(); 33 | if (node != null && node.getMethod() != null) { 34 | Cafebabe.gui.smallEditorPanel.setViewportView(editor); 35 | editor.editMethod(node.getMethod()); 36 | } 37 | } 38 | }); 39 | this.model = new DefaultTreeModel(root = new MethodListNode(null, null)); 40 | this.setModel(model); 41 | this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 42 | } 43 | 44 | public void setMethods(ClassNode cn) { 45 | root.removeAllChildren(); 46 | for (MethodNode mn : cn.methods) { 47 | root.add(new MethodListNode(cn, mn)); 48 | } 49 | this.model.reload(); 50 | this.repaint(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/HelpBar.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui; 2 | 3 | import java.awt.BorderLayout; 4 | 5 | import javax.swing.BorderFactory; 6 | import javax.swing.JLabel; 7 | import javax.swing.JPanel; 8 | import javax.swing.border.Border; 9 | 10 | import com.alee.extended.statusbar.WebMemoryBar; 11 | 12 | import me.nov.cafebabe.Cafebabe; 13 | 14 | public class HelpBar extends JPanel { 15 | private static final long serialVersionUID = 1L; 16 | private JLabel label; 17 | 18 | public HelpBar() { 19 | Border b = BorderFactory.createLoweredSoftBevelBorder(); 20 | this.setBorder(b); 21 | this.setLayout(new BorderLayout()); 22 | label = new JLabel(); 23 | this.resetText(); 24 | this.add(label, BorderLayout.WEST); 25 | WebMemoryBar mb = new WebMemoryBar(); 26 | mb.setShowMaximumMemory(false); 27 | mb.setFocusable(false); 28 | this.add(mb, BorderLayout.EAST); 29 | } 30 | 31 | public void setText(String text) { 32 | label.setText(" " + text); 33 | } 34 | 35 | public void resetText() { 36 | label.setText(" " + Cafebabe.gui.getTitle()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/InnerSplitPane.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui; 2 | 3 | import java.awt.Component; 4 | import java.awt.Dimension; 5 | 6 | import javax.swing.JSplitPane; 7 | import javax.swing.border.BevelBorder; 8 | 9 | import me.nov.cafebabe.Cafebabe; 10 | 11 | public class InnerSplitPane extends JSplitPane { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | public InnerSplitPane(Component above, Component below) { 16 | super(JSplitPane.VERTICAL_SPLIT, above, below); 17 | 18 | this.setBorder(new BevelBorder(BevelBorder.LOWERED)); 19 | this.setPreferredSize(new Dimension(this.getWidth(), 24)); 20 | this.setDividerLocation((int) (Cafebabe.gui.getSize().getHeight() / 3)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/OuterSplitPane.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui; 2 | 3 | import java.awt.Component; 4 | import java.awt.Dimension; 5 | 6 | import javax.swing.JSplitPane; 7 | import javax.swing.border.BevelBorder; 8 | 9 | import me.nov.cafebabe.Cafebabe; 10 | 11 | public class OuterSplitPane extends JSplitPane { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | public OuterSplitPane(Component left, Component right) { 16 | super(JSplitPane.HORIZONTAL_SPLIT, left, right); 17 | 18 | this.setBorder(new BevelBorder(BevelBorder.LOWERED)); 19 | this.setPreferredSize(new Dimension(this.getWidth(), 24)); 20 | this.setDividerLocation((int) (Cafebabe.gui.getSize().getWidth() / 3.5)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/decompiler/DecompilerPanel.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.decompiler; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.GridLayout; 5 | import java.util.Objects; 6 | 7 | import javax.swing.JButton; 8 | import javax.swing.JLabel; 9 | import javax.swing.JPanel; 10 | import javax.swing.JScrollPane; 11 | import javax.swing.border.EmptyBorder; 12 | import javax.swing.text.BadLocationException; 13 | import javax.swing.text.DefaultHighlighter; 14 | import javax.swing.text.Document; 15 | import javax.swing.text.Highlighter; 16 | 17 | import org.fife.ui.rtextarea.RTextScrollPane; 18 | import org.objectweb.asm.tree.ClassNode; 19 | import org.objectweb.asm.tree.MethodNode; 20 | 21 | import com.alee.laf.text.WebTextField; 22 | 23 | import me.nov.cafebabe.decompiler.CFR; 24 | import me.nov.cafebabe.translations.Translations; 25 | import me.nov.cafebabe.utils.formatting.Colors; 26 | 27 | public class DecompilerPanel extends JPanel { 28 | private static final long serialVersionUID = 1L; 29 | 30 | private DecompilerTextArea dp; 31 | private JLabel label; 32 | 33 | private int searchIndex = -1; 34 | private String lastSearchText = null; 35 | 36 | public DecompilerPanel(ClassNode cn, MethodNode mn) { 37 | this.dp = new DecompilerTextArea(); 38 | dp.setText(CFR.decompile(cn, mn)); 39 | this.label = new JLabel("CFR Decompiler 0.145"); 40 | this.setLayout(new BorderLayout(0, 0)); 41 | JPanel lpad = new JPanel(); 42 | lpad.setBorder(new EmptyBorder(1, 5, 0, 1)); 43 | lpad.setLayout(new GridLayout()); 44 | lpad.add(label); 45 | JPanel rs = new JPanel(); 46 | rs.setLayout(new GridLayout(1, 5)); 47 | for (int i = 0; i < 3; i++) 48 | rs.add(new JPanel()); 49 | WebTextField search = new WebTextField(); 50 | search.setInputPrompt(Translations.get("Search...")); 51 | search.addActionListener(l -> { 52 | try { 53 | String text = search.getText(); 54 | if (text.isEmpty()) { 55 | dp.getHighlighter().removeAllHighlights(); 56 | return; 57 | } 58 | String searchText = text.toLowerCase(); 59 | if (!Objects.equals(searchText, lastSearchText)) { 60 | searchIndex = -1; 61 | lastSearchText = searchText; 62 | } 63 | String[] split = dp.getText().split("\\r?\\n"); 64 | System.out.println(searchText); 65 | int firstIndex = -1; 66 | boolean first = false; 67 | Label: { 68 | for (int i = 0; i < split.length; i++) { 69 | String line = split[i]; 70 | if (line.toLowerCase().contains(searchText)) { 71 | if (i > searchIndex) { 72 | dp.setCaretPosition(dp.getDocument().getDefaultRootElement().getElement(i).getStartOffset()); 73 | searchIndex = i; 74 | break Label; 75 | } else if (!first) { 76 | firstIndex = i; 77 | first = true; 78 | } 79 | } 80 | } 81 | if (first) { 82 | // go back to first line 83 | dp.setCaretPosition(dp.getDocument().getDefaultRootElement().getElement(firstIndex).getStartOffset()); 84 | searchIndex = firstIndex; 85 | } 86 | } 87 | hightlightText(searchText); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | } 91 | }); 92 | rs.add(search); 93 | JButton reload = new JButton(Translations.get("Reload")); 94 | reload.addActionListener(l -> { 95 | dp.setText(CFR.decompile(cn, mn)); 96 | }); 97 | rs.add(reload); 98 | lpad.add(rs); 99 | this.add(lpad, BorderLayout.NORTH); 100 | JScrollPane scp = new RTextScrollPane(dp); 101 | scp.getVerticalScrollBar().setUnitIncrement(16); 102 | this.add(scp, BorderLayout.CENTER); 103 | } 104 | 105 | private void hightlightText(String searchText) throws BadLocationException { 106 | Highlighter highlighter = dp.getHighlighter(); 107 | highlighter.removeAllHighlights(); 108 | Document document = dp.getDocument(); 109 | String text = document.getText(0, document.getLength()).toLowerCase(); 110 | int pos = text.indexOf(searchText); 111 | while (pos >= 0) { 112 | highlighter.addHighlight(pos, pos + searchText.length(), 113 | (Highlighter.HighlightPainter) new DefaultHighlighter.DefaultHighlightPainter(Colors.highlightColor)); 114 | pos = text.indexOf(searchText, pos + searchText.length()); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/decompiler/DecompilerTextArea.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.decompiler; 2 | 3 | import java.awt.Font; 4 | import java.io.IOException; 5 | 6 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; 7 | import org.fife.ui.rsyntaxtextarea.Theme; 8 | 9 | public class DecompilerTextArea extends RSyntaxTextArea { 10 | private static final long serialVersionUID = 1L; 11 | 12 | public DecompilerTextArea() { 13 | this.setSyntaxEditingStyle("text/java"); 14 | this.setCodeFoldingEnabled(true); 15 | this.setAntiAliasingEnabled(true); 16 | this.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); 17 | this.setEditable(false); 18 | 19 | // change theme to java 20 | try { 21 | Theme theme = Theme.load(getClass().getResourceAsStream("/org/fife/ui/rsyntaxtextarea/themes/eclipse.xml")); 22 | theme.apply(this); 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/editor/Editor.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.editor; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | import java.awt.Component; 6 | import java.awt.Dimension; 7 | import java.awt.Font; 8 | import java.awt.Toolkit; 9 | 10 | import javax.swing.Icon; 11 | import javax.swing.JFrame; 12 | import javax.swing.JMenu; 13 | import javax.swing.JMenuBar; 14 | import javax.swing.JMenuItem; 15 | import javax.swing.JScrollPane; 16 | import javax.swing.WindowConstants; 17 | 18 | import com.alee.extended.tab.DocumentData; 19 | import com.alee.extended.tab.DocumentListener; 20 | import com.alee.extended.tab.PaneData; 21 | import com.alee.extended.tab.WebDocumentPane; 22 | import com.alee.utils.TextUtils; 23 | 24 | import me.nov.cafebabe.Cafebabe; 25 | import me.nov.cafebabe.translations.Translations; 26 | 27 | @SuppressWarnings({ "rawtypes", "unchecked" }) 28 | public class Editor extends JFrame { 29 | private static final long serialVersionUID = 1L; 30 | private WebDocumentPane pane; 31 | 32 | public Editor() { 33 | this.setTitle("Editor"); 34 | initBounds(); 35 | this.setIconImage(Cafebabe.gui.getIconImage()); 36 | this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 37 | this.setLayout(new BorderLayout()); 38 | this.setAlwaysOnTop(true); 39 | this.pane = new WebDocumentPane(); 40 | pane.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); 41 | pane.setCloseable(true); 42 | pane.setTabMenuEnabled(true); 43 | pane.setWebColoredBackground(true); 44 | pane.addDocumentListener(new DocumentListener() { 45 | 46 | @Override 47 | public void closed(DocumentData arg0, PaneData arg1, int arg2) { 48 | if (pane.getDocumentsCount() == 0) { 49 | setVisible(false); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean closing(DocumentData arg0, PaneData arg1, int arg2) { 55 | return true; 56 | } 57 | 58 | @Override 59 | public void opened(DocumentData arg0, PaneData arg1, int arg2) { 60 | setTitle(arg0.getTitle()); 61 | } 62 | 63 | @Override 64 | public void selected(DocumentData arg0, PaneData arg1, int arg2) { 65 | setTitle(arg0.getTitle()); 66 | } 67 | }); 68 | pane.setUndecorated(false); 69 | this.add(pane, BorderLayout.CENTER); 70 | this.setJMenuBar(createMenu()); 71 | 72 | } 73 | 74 | private void initBounds() { 75 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 76 | int mainFrameWidth = (int) (screenSize.width * 0.3515625); // 675 77 | 78 | int mainFrameX = (int) (screenSize.width * 0.013); 79 | 80 | int width = (int) (screenSize.width * 0.622395833); // 1195 81 | int height = (int) (screenSize.height * 0.833333333); // 900 82 | 83 | setBounds(mainFrameX + mainFrameWidth, screenSize.height / 2 - height / 2, width, height); 84 | } 85 | 86 | private JMenuBar createMenu() { 87 | JMenuBar mb = new JMenuBar(); 88 | JMenu actions = new JMenu(Translations.get("Actions")); 89 | JMenuItem close = new JMenuItem(Translations.get("Close all")); 90 | close.addActionListener(l -> { 91 | pane.closeAll(); 92 | }); 93 | 94 | actions.add(close); 95 | mb.add(actions); 96 | return mb; 97 | } 98 | 99 | public void open(Component c, String title, Icon icon, Color color) { 100 | if (c instanceof JScrollPane) { 101 | JScrollPane sp = (JScrollPane) c; 102 | sp.getVerticalScrollBar().setUnitIncrement(16); 103 | } 104 | for (int i = 0; i < pane.getDocumentsCount(); i++) { 105 | DocumentData dd = pane.getDocument(i); 106 | if (dd.getTitle().equals(title)) { 107 | pane.setSelected(dd); 108 | return; 109 | } 110 | } 111 | pane.openDocument(new DocumentData(TextUtils.generateId(), icon, title, color, c)); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/editor/InstructionPanel.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.editor; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | 6 | import javax.swing.BorderFactory; 7 | import javax.swing.JPanel; 8 | 9 | import org.objectweb.asm.tree.ClassNode; 10 | import org.objectweb.asm.tree.MethodNode; 11 | 12 | import me.nov.cafebabe.gui.editor.list.AdressList; 13 | import me.nov.cafebabe.gui.editor.list.InstructionList; 14 | 15 | public class InstructionPanel extends JPanel { 16 | private static final long serialVersionUID = 1L; 17 | 18 | public InstructionPanel(ClassNode cn, MethodNode mn) { 19 | this.setFocusable(false); 20 | this.setLayout(new BorderLayout()); 21 | InstructionList il = new InstructionList(cn, mn); 22 | this.add(il, BorderLayout.CENTER); 23 | JPanel p = new JPanel(); 24 | p.setLayout(new BorderLayout()); 25 | p.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.gray)); 26 | p.add(new AdressList(il), BorderLayout.CENTER); 27 | this.add(p, BorderLayout.WEST); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/editor/list/AdressList.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.editor.list; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Graphics; 6 | import java.util.HashMap; 7 | 8 | import javax.swing.DefaultListModel; 9 | import javax.swing.DefaultListSelectionModel; 10 | import javax.swing.JList; 11 | import javax.swing.plaf.ListUI; 12 | 13 | import org.objectweb.asm.tree.AbstractInsnNode; 14 | import org.objectweb.asm.tree.JumpInsnNode; 15 | 16 | import com.alee.laf.list.WebListUI; 17 | 18 | import me.nov.cafebabe.gui.node.InstructionNode; 19 | import me.nov.cafebabe.utils.ui.LazyListModel; 20 | 21 | public class AdressList extends JList { 22 | private static final long serialVersionUID = 1L; 23 | private InstructionList il; 24 | 25 | public AdressList(InstructionList il) { 26 | super(new DefaultListModel()); 27 | this.il = il; 28 | il.addressList = this; 29 | this.setFont(new Font(Font.SERIF, Font.PLAIN, 13)); 30 | this.setFocusable(false); 31 | this.setSelectionModel(new DefaultListSelectionModel() { 32 | private static final long serialVersionUID = 1L; 33 | 34 | @Override 35 | public void setSelectionInterval(int index0, int index1) { 36 | super.setSelectionInterval(-1, -1); 37 | } 38 | }); 39 | this.setPrototypeCellValue("0000"); 40 | this.setEnabled(true); 41 | this.setFocusable(false); 42 | this.setModel(new DefaultListModel() { 43 | private static final long serialVersionUID = 1L; 44 | 45 | @Override 46 | public int getSize() { 47 | return il.getModel().getSize(); 48 | } 49 | 50 | @Override 51 | protected void fireIntervalAdded(Object source, int index0, int index1) { 52 | } 53 | 54 | @Override 55 | public String getElementAt(int index) { 56 | String hex = String.valueOf(index); 57 | return "0000".substring(hex.length()) + hex; // "" 58 | } 59 | }); 60 | ListUI ui = this.getUI(); 61 | if (ui instanceof WebListUI) { 62 | WebListUI wlui = (WebListUI) ui; 63 | wlui.setHighlightRolloverCell(false); 64 | wlui.setDecorateSelection(false); 65 | } 66 | } 67 | 68 | @Override 69 | protected void paintComponent(Graphics g) { 70 | double size = il.getModel().getSize(); 71 | if (size > 1000) { 72 | super.paintComponent(g); 73 | return; 74 | } 75 | super.paintComponent(g); 76 | HashMap mvout = new HashMap<>(); 77 | for (AbstractInsnNode ain : il.mn.instructions.toArray()) { 78 | if (ain.getType() == AbstractInsnNode.JUMP_INSN) { 79 | int moveOut = 0; 80 | int from = ((LazyListModel) il.getModel()).indexOf(ain); 81 | int to = ((LazyListModel) il.getModel()).indexOf(((JumpInsnNode) ain).label); 82 | for (int j = from; j < to; j++) { 83 | moveOut = Math.max(mvout.getOrDefault(j, 0) + 4, moveOut); 84 | } 85 | for (int j = from; j < to; j++) { 86 | mvout.put(j, moveOut); 87 | } 88 | int start = (from * getFixedCellHeight() + getFixedCellHeight() / 2); 89 | int end = (to * getFixedCellHeight() + getFixedCellHeight() / 2); 90 | Color c = Color.getHSBColor(getHue(moveOut), 1, 0.6f); 91 | g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 127)); 92 | g.drawLine(getWidth() - moveOut, start, getWidth() - moveOut, end); 93 | g.drawLine(getWidth() - moveOut, start, getWidth(), start); 94 | g.drawLine(getWidth() - moveOut, end, getWidth(), end); 95 | } 96 | } 97 | } 98 | 99 | private float getHue(int moveOut) { 100 | float hue = moveOut / (float) (getWidth() / 2) + 0.5f; 101 | return hue % 1.0f; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/graph/CFGraph.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.graph; 2 | 3 | import java.awt.Color; 4 | import java.awt.event.MouseWheelEvent; 5 | import java.awt.event.MouseWheelListener; 6 | import java.util.Map; 7 | 8 | import javax.swing.JScrollPane; 9 | import javax.swing.border.EmptyBorder; 10 | 11 | import com.mxgraph.swing.mxGraphComponent; 12 | import com.mxgraph.util.mxConstants; 13 | import com.mxgraph.util.mxRectangle; 14 | import com.mxgraph.view.mxGraph; 15 | import com.mxgraph.view.mxGraphView; 16 | import com.mxgraph.view.mxStylesheet; 17 | 18 | public class CFGraph extends mxGraph { 19 | private CFGComponent component; 20 | 21 | public CFGraph() { 22 | this.component = new CFGComponent(this); 23 | this.setAutoOrigin(true); 24 | this.setAutoSizeCells(true); 25 | this.setHtmlLabels(true); 26 | this.setAllowDanglingEdges(true); 27 | this.setStyles(); 28 | this.resetEdgesOnMove = true; 29 | } 30 | 31 | public CFGComponent getComponent() { 32 | return component; 33 | } 34 | 35 | @Override 36 | public mxRectangle getPreferredSizeForCell(Object arg0) { 37 | mxRectangle size = super.getPreferredSizeForCell(arg0); 38 | size.setWidth(size.getWidth() + 10); // some items touch the border 39 | return size; 40 | } 41 | 42 | private void setStyles() { 43 | Map edgeStyle = this.getStylesheet().getDefaultEdgeStyle(); 44 | edgeStyle.put(mxConstants.STYLE_ROUNDED, true); 45 | edgeStyle.put(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL); 46 | edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OPEN); 47 | edgeStyle.put(mxConstants.STYLE_TARGET_PERIMETER_SPACING, 1d); 48 | 49 | Map vertexStyle = this.getStylesheet().getDefaultVertexStyle(); 50 | vertexStyle.put(mxConstants.STYLE_SHADOW, true); 51 | mxStylesheet stylesheet = new mxStylesheet(); 52 | stylesheet.setDefaultEdgeStyle(edgeStyle); 53 | stylesheet.setDefaultVertexStyle(vertexStyle); 54 | this.setStylesheet(stylesheet); 55 | 56 | } 57 | 58 | public static class CFGComponent extends mxGraphComponent { 59 | private static final long serialVersionUID = 1L; 60 | 61 | public JScrollPane scp; 62 | 63 | public CFGComponent(mxGraph g) { 64 | super(g); 65 | this.getViewport().setBackground(Color.WHITE); 66 | this.setEnabled(false); 67 | this.setBorder(new EmptyBorder(0, 0, 0, 0)); 68 | this.setZoomFactor(1.1); 69 | this.getGraphControl().addMouseWheelListener(new MouseWheelListener() { 70 | @Override 71 | public void mouseWheelMoved(MouseWheelEvent e) { 72 | if (e.isControlDown()) { 73 | if (e.getWheelRotation() < 0) { 74 | zoomIn(); 75 | } else { 76 | zoomOut(); 77 | } 78 | repaint(); 79 | revalidate(); 80 | } else if (scp != null) { 81 | // do we need this on linux too? 82 | scp.getVerticalScrollBar().setValue(scp.getVerticalScrollBar().getValue() 83 | + e.getUnitsToScroll() * scp.getVerticalScrollBar().getUnitIncrement()); 84 | } 85 | } 86 | }); 87 | } 88 | 89 | @Override 90 | public void zoomIn() { 91 | mxGraphView view = graph.getView(); 92 | double scale = view.getScale(); 93 | if (scale < 4) { 94 | zoom(zoomFactor); 95 | } 96 | } 97 | 98 | @Override 99 | public void zoomOut() { 100 | mxGraphView view = graph.getView(); 101 | double scale = view.getScale(); 102 | if (scp != null && (scp.getVerticalScrollBar().isVisible() || scale >= 1) && scale > 0.3) { 103 | zoom(1 / zoomFactor); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/graph/layout/PatchedHierarchicalLayout.java: -------------------------------------------------------------------------------- 1 | // Copyright GFI 2017 - Data Systemizer 2 | package me.nov.cafebabe.gui.graph.layout; 3 | 4 | import com.mxgraph.layout.hierarchical.mxHierarchicalLayout; 5 | import com.mxgraph.layout.hierarchical.stage.mxCoordinateAssignment; 6 | import com.mxgraph.view.mxGraph; 7 | 8 | /** 9 | * Patched hierarchical layout to route directly cross-group edges 10 | * 11 | * @author Loison 12 | * 13 | */ 14 | public class PatchedHierarchicalLayout extends mxHierarchicalLayout { 15 | 16 | public PatchedHierarchicalLayout(mxGraph graph) { 17 | super(graph); 18 | } 19 | 20 | public PatchedHierarchicalLayout(mxGraph graph, int orientation) { 21 | super(graph, orientation); 22 | } 23 | 24 | /** 25 | * Executes the placement stage using mxCoordinateAssignment. 26 | *

27 | * Use a patched mxCoordinateAssignment class 28 | */ 29 | @Override 30 | public double placementStage(double initialX, Object parent) { 31 | mxCoordinateAssignment placementStage = new PatchedCoordinateAssignment(this, intraCellSpacing, interRankCellSpacing, orientation, initialX, 32 | parallelEdgeSpacing); 33 | placementStage.setFineTuning(fineTuning); 34 | placementStage.execute(parent); 35 | 36 | return placementStage.getLimitX() + interHierarchySpacing; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/graph/vertex/BlockVertex.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.graph.vertex; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.objectweb.asm.tree.AbstractInsnNode; 6 | import org.objectweb.asm.tree.LabelNode; 7 | import org.objectweb.asm.tree.MethodNode; 8 | 9 | import me.nov.cafebabe.analysis.blocks.Block; 10 | import me.nov.cafebabe.utils.formatting.InstructionFormatting; 11 | 12 | public class BlockVertex { 13 | public MethodNode mn; 14 | public ArrayList nodes; 15 | 16 | public LabelNode label; 17 | public int listIndex; 18 | 19 | public Block block; 20 | public ArrayList inputBlocks = new ArrayList<>(); 21 | 22 | public BlockVertex(MethodNode mn, Block block, ArrayList nodes, LabelNode label, int listIndex) { 23 | super(); 24 | this.mn = mn; 25 | this.block = block; 26 | this.nodes = nodes; 27 | this.label = label; 28 | this.listIndex = listIndex; 29 | } 30 | 31 | public void addInput(BlockVertex v) { 32 | if (!inputBlocks.contains(v)) { 33 | this.inputBlocks.add(v); 34 | } 35 | } 36 | 37 | private String text = null; 38 | 39 | @Override 40 | public String toString() { 41 | if (text == null) { 42 | StringBuilder sb = new StringBuilder(); 43 | for (AbstractInsnNode ain : nodes) { 44 | if(ain.getType() == AbstractInsnNode.FRAME) { 45 | continue; 46 | } 47 | sb.append(InstructionFormatting.nodeToString(mn, ain)); 48 | sb.append("\n"); 49 | } 50 | text = sb.toString(); 51 | } 52 | return text; 53 | } 54 | } -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/node/InstructionNode.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.node; 2 | 3 | import org.objectweb.asm.tree.AbstractInsnNode; 4 | import org.objectweb.asm.tree.MethodNode; 5 | 6 | import me.nov.cafebabe.utils.formatting.InstructionFormatting; 7 | 8 | public class InstructionNode { 9 | public MethodNode mn; 10 | public AbstractInsnNode ain; 11 | 12 | public InstructionNode(MethodNode mn, AbstractInsnNode ain) { 13 | super(); 14 | this.mn = mn; 15 | this.ain = ain; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return InstructionFormatting.nodeToString(mn, ain); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/node/MethodListNode.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.node; 2 | 3 | import javax.swing.tree.DefaultMutableTreeNode; 4 | 5 | import org.objectweb.asm.tree.ClassNode; 6 | import org.objectweb.asm.tree.MethodNode; 7 | 8 | import me.nov.cafebabe.translations.Translations; 9 | import me.nov.cafebabe.utils.asm.Descriptors; 10 | import me.nov.cafebabe.utils.formatting.EscapedString; 11 | 12 | public class MethodListNode extends DefaultMutableTreeNode { 13 | private static final long serialVersionUID = 1L; 14 | 15 | private MethodNode mn; 16 | private ClassNode cn; 17 | 18 | private String text; 19 | 20 | public MethodListNode(ClassNode cn, MethodNode mn) { 21 | super(); 22 | this.cn = cn; 23 | this.mn = mn; 24 | if (mn != null) { 25 | initText(); 26 | } 27 | } 28 | 29 | private void initText() { 30 | this.text = ""; 31 | // unnecessary because the icon shows the access 32 | // this.text += Descriptors.getDisplayAccess(mn.access); 33 | String[] descSplit = mn.desc.split("\\)"); 34 | switch (mn.name) { 35 | case "": 36 | this.text += "" + Translations.get("class initializer method") + ""; 37 | break; 38 | case "": 39 | this.text += " "; 40 | this.text += new EscapedString(Descriptors.lastSlash(cn.name)).getEscapedText(); 41 | this.text += "("; 42 | this.text += Descriptors.getDisplayType(descSplit[0].substring(1)); 43 | this.text += ")"; 44 | break; 45 | default: 46 | this.text += Descriptors.getDisplayType(descSplit[1]); 47 | this.text += " "; 48 | this.text += new EscapedString(mn.name).getEscapedText(); 49 | this.text += "("; 50 | this.text += Descriptors.getDisplayType(descSplit[0].substring(1)); 51 | this.text += ")"; 52 | } 53 | } 54 | 55 | public ClassNode getClazz() { 56 | return cn; 57 | } 58 | 59 | public void setClazz(ClassNode cn) { 60 | this.cn = cn; 61 | } 62 | 63 | public MethodNode getMethod() { 64 | return mn; 65 | } 66 | 67 | public void setMethod(MethodNode mn) { 68 | this.mn = mn; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return text; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/node/OpcodeNode.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.node; 2 | 3 | import me.nov.cafebabe.utils.asm.Hints; 4 | import me.nov.cafebabe.utils.asm.OpcodeLink; 5 | import me.nov.cafebabe.utils.formatting.Colors; 6 | import me.nov.cafebabe.utils.formatting.Html; 7 | import me.nov.cafebabe.utils.formatting.OpcodeFormatting; 8 | 9 | public class OpcodeNode { 10 | 11 | public int opcode; 12 | public String help; 13 | private String text; 14 | 15 | public OpcodeNode(int opcode) { 16 | this.opcode = opcode; 17 | this.help = Hints.hints[opcode]; 18 | this.text = "" 19 | + Html.color(Colors.getColor(OpcodeLink.getOpcodeType(opcode), opcode), 20 | Html.bold(OpcodeFormatting.getOpcodeText(opcode).toLowerCase())) 21 | + "
" + Html.italics(Html.color(Colors.debug_grey, this.help)); 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return text; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/node/SettingNode.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.node; 2 | 3 | import me.nov.cafebabe.setting.Setting; 4 | import me.nov.cafebabe.utils.formatting.Colors; 5 | import me.nov.cafebabe.utils.formatting.Html; 6 | 7 | public class SettingNode { 8 | public String title; 9 | public String description; 10 | private String text; 11 | 12 | private Setting setting; 13 | 14 | public SettingNode(Setting s) { 15 | this.setting = s; 16 | this.title = s.title; 17 | this.description = s.description; 18 | this.text = "" + Html.bold(title) + "
" 19 | + Html.italics(Html.color(Colors.debug_grey, description)); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return text; 25 | } 26 | 27 | public void setUserSelected(boolean b) { 28 | setting.set(b); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/node/SortedTreeClassNode.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.node; 2 | 3 | import java.util.Collections; 4 | import java.util.Comparator; 5 | 6 | import javax.swing.tree.DefaultMutableTreeNode; 7 | 8 | import org.objectweb.asm.tree.ClassNode; 9 | 10 | import me.nov.cafebabe.utils.formatting.EscapedString; 11 | 12 | public class SortedTreeClassNode extends DefaultMutableTreeNode { 13 | private static final long serialVersionUID = 1L; 14 | 15 | private ClassNode cn; 16 | private EscapedString text; 17 | 18 | public SortedTreeClassNode(ClassNode cn) { 19 | this.cn = cn; 20 | setClassName(); 21 | } 22 | 23 | public SortedTreeClassNode(String path) { 24 | this.cn = null; 25 | this.text = new EscapedString(path); 26 | } 27 | 28 | private void setClassName() { 29 | if (cn != null) { 30 | String[] split = cn.name.split("/"); 31 | this.text = new EscapedString(split[split.length - 1]); 32 | } 33 | } 34 | 35 | public ClassNode getClazz() { 36 | return cn; 37 | } 38 | 39 | public void setClazz(ClassNode c) { 40 | this.cn = c; 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | public void sort() { 45 | if (children != null) 46 | Collections.sort(children, comparator()); 47 | } 48 | 49 | private Comparator comparator() { 50 | return new Comparator() { 51 | @Override 52 | public int compare(SortedTreeClassNode node1, SortedTreeClassNode node2) { 53 | boolean leaf1 = node1.cn != null; 54 | boolean leaf2 = node2.cn != null; 55 | 56 | if (leaf1 && !leaf2) { 57 | return 1; 58 | } 59 | if (!leaf1 && leaf2) { 60 | return -1; 61 | } 62 | return node1.getText().compareTo(node2.getText()); 63 | } 64 | }; 65 | } 66 | 67 | public String getText() { 68 | return text.getText(); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return text.getEscapedText(); 74 | } 75 | } -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/opchooser/OpcodeChooserDialog.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.opchooser; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | import java.awt.Toolkit; 7 | import java.awt.event.WindowAdapter; 8 | import java.awt.event.WindowEvent; 9 | 10 | import javax.swing.JButton; 11 | import javax.swing.JPanel; 12 | import javax.swing.WindowConstants; 13 | 14 | import org.objectweb.asm.tree.AbstractInsnNode; 15 | 16 | import com.alee.laf.rootpane.WebDialog; 17 | 18 | import me.nov.cafebabe.Cafebabe; 19 | import me.nov.cafebabe.translations.Translations; 20 | 21 | public class OpcodeChooserDialog extends WebDialog { 22 | private static final long serialVersionUID = 1L; 23 | private int opcode; 24 | private OpcodeChooserPane ocp; 25 | 26 | public OpcodeChooserDialog(AbstractInsnNode ain) { 27 | super(Cafebabe.gui, true); 28 | this.setRound(5); 29 | this.setShadeWidth(20); 30 | this.setShowResizeCorner(false); 31 | this.opcode = ain.getOpcode(); 32 | this.initBounds(); 33 | this.setTitle(Translations.get("Choose an opcode")); 34 | this.setIconImage(Cafebabe.gui.getIconImage()); 35 | this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 36 | this.addWindowListener(new WindowAdapter() { 37 | @Override 38 | public void windowClosing(WindowEvent e) { 39 | opcode = ain.getOpcode(); // reset opcode 40 | setVisible(false); 41 | } 42 | }); 43 | this.setLayout(new BorderLayout()); 44 | this.add(ocp = new OpcodeChooserPane(this, ain)); 45 | JPanel buttons = new JPanel(new FlowLayout(4)); 46 | this.add(buttons, BorderLayout.SOUTH); 47 | 48 | JButton ok = new JButton(Translations.get("OK")); 49 | buttons.add(ok); 50 | ok.addActionListener(e -> { 51 | setVisible(false); 52 | }); 53 | 54 | JButton cancel = new JButton(Translations.get("Cancel")); 55 | buttons.add(cancel); 56 | cancel.addActionListener(e -> { 57 | opcode = ain.getOpcode(); // reset opcode 58 | setVisible(false); 59 | }); 60 | setLocationRelativeTo(getParent()); 61 | this.setVisible(true); 62 | 63 | } 64 | 65 | private void initBounds() { 66 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 67 | int width = (int) (screenSize.width * 0.25); 68 | int height = (int) (screenSize.height * 0.5); 69 | 70 | setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height); 71 | } 72 | 73 | public void setOpcode(int opcode) { 74 | this.opcode = opcode; 75 | } 76 | 77 | public int getOpcode() { 78 | return opcode; 79 | } 80 | 81 | public void refresh() { 82 | ocp.refresh(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/opchooser/OpcodeChooserPane.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.opchooser; 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.swing.JScrollPane; 6 | 7 | import org.objectweb.asm.Opcodes; 8 | import org.objectweb.asm.tree.AbstractInsnNode; 9 | 10 | import com.alee.laf.tabbedpane.WebTabbedPane; 11 | 12 | import me.nov.cafebabe.gui.smalleditor.list.OpList; 13 | import me.nov.cafebabe.translations.Translations; 14 | 15 | public class OpcodeChooserPane extends WebTabbedPane implements Opcodes { 16 | private static final long serialVersionUID = 1L; 17 | private ArrayList lists = new ArrayList<>(); 18 | 19 | public OpcodeChooserPane(OpcodeChooserDialog chooser, AbstractInsnNode ain) { 20 | this.setTabPlacement(WebTabbedPane.LEFT); 21 | this.addTab(Translations.get("Variables"), new JScrollPane( 22 | addList(new OpList(chooser, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE, ILOAD, LLOAD, FLOAD, DLOAD, ALOAD)))); 23 | this.addTab(Translations.get("Types"), 24 | new JScrollPane(addList(new OpList(chooser, NEW, CHECKCAST, INSTANCEOF, NEWARRAY, ANEWARRAY, MULTIANEWARRAY)))); 25 | this.addTab(Translations.get("Methods"), new JScrollPane( 26 | addList(new OpList(chooser, INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE, INVOKEDYNAMIC)))); 27 | this.addTab(Translations.get("Fields"), new JScrollPane(addList(new OpList(chooser, GETSTATIC, PUTSTATIC, GETFIELD, PUTFIELD)))); 28 | this.addTab(Translations.get("Jumps"), new JScrollPane(addList(new OpList(chooser, GOTO, IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, 29 | IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, IFNULL, IFNONNULL)))); 30 | this.addTab(Translations.get("End Nodes"), 31 | new JScrollPane(addList(new OpList(chooser, ATHROW, RETURN, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN)))); 32 | this.addTab(Translations.get("Calculation"), 33 | new JScrollPane(addList(new OpList(chooser, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, 34 | DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, 35 | LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR)))); 36 | this.addTab(Translations.get("Comparison"), new JScrollPane(addList(new OpList(chooser, LCMP, FCMPL, FCMPG, DCMPL, DCMPG)))); 37 | this.addTab(Translations.get("Conversion"), new JScrollPane( 38 | addList(new OpList(chooser, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S)))); 39 | this.addTab("Stack", 40 | new JScrollPane(addList(new OpList(chooser, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP)))); 41 | this.addTab(Translations.get("Constants"), 42 | new JScrollPane( 43 | addList(new OpList(chooser, LDC, BIPUSH, SIPUSH, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, 44 | ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1)))); 45 | this.addTab(Translations.get("Arrays"), new JScrollPane(addList(new OpList(chooser, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, 46 | CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE)))); 47 | this.addTab(Translations.get("Other"), new JScrollPane( 48 | addList(new OpList(chooser, TABLESWITCH, LOOKUPSWITCH, MONITORENTER, MONITOREXIT, IINC, NOP, JSR, RET)))); 49 | this.refresh(); 50 | } 51 | 52 | private OpList addList(OpList opList) { 53 | lists.add(opList); 54 | return opList; 55 | } 56 | 57 | public void refresh() { 58 | for (int i = 0; i < lists.size(); i++) { 59 | OpList ol = lists.get(i); 60 | if(ol.refresh()) { 61 | setSelectedIndex(i); 62 | } 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/preferences/AboutPanel.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.preferences; 2 | 3 | import javax.swing.JEditorPane; 4 | import javax.swing.border.EmptyBorder; 5 | 6 | import me.nov.cafebabe.Cafebabe; 7 | import me.nov.cafebabe.utils.io.Scanning; 8 | 9 | public class AboutPanel extends JEditorPane { 10 | private static final long serialVersionUID = 1L; 11 | 12 | public AboutPanel() { 13 | this.setContentType("text/html"); 14 | this.setEditable(false); 15 | String license = Scanning.readInputStream(AboutPanel.class.getResourceAsStream("/resources/license.txt")).replace("\n", "
"); 16 | this.setText(String.format(Scanning.readInputStream(AboutPanel.class.getResourceAsStream("/resources/about.txt")), Cafebabe.title, Cafebabe.version) + license); 17 | this.setFocusable(false); 18 | this.setOpaque(true); 19 | putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); 20 | setBorder(new EmptyBorder(16, 16, 16, 16)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/preferences/PreferencesDialog.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.preferences; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | import java.awt.Toolkit; 7 | 8 | import javax.swing.JButton; 9 | import javax.swing.JPanel; 10 | import javax.swing.WindowConstants; 11 | 12 | import com.alee.laf.rootpane.WebDialog; 13 | 14 | import me.nov.cafebabe.Cafebabe; 15 | import me.nov.cafebabe.translations.Translations; 16 | 17 | public class PreferencesDialog extends WebDialog { 18 | private static final long serialVersionUID = 1L; 19 | 20 | public PreferencesDialog() { 21 | super(Cafebabe.gui, true); 22 | this.setRound(5); 23 | this.setShadeWidth(20); 24 | this.setShowResizeCorner(false); 25 | this.initBounds(); 26 | this.setTitle(Translations.get("Preferences")); 27 | this.setIconImage(Cafebabe.gui.getIconImage()); 28 | this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 29 | this.setLayout(new BorderLayout()); 30 | try { 31 | this.add(new PreferencesPane()); 32 | } catch (Exception e1) { 33 | e1.printStackTrace(); 34 | } 35 | JPanel buttons = new JPanel(new FlowLayout(4)); 36 | this.add(buttons, BorderLayout.SOUTH); 37 | 38 | JButton close = new JButton(Translations.get("Close")); 39 | buttons.add(close); 40 | close.addActionListener(e -> { 41 | setVisible(false); 42 | }); 43 | setLocationRelativeTo(getParent()); 44 | this.setVisible(true); 45 | } 46 | 47 | private void initBounds() { 48 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 49 | int width = (int) (screenSize.width * 0.25); 50 | int height = (int) (screenSize.height * 0.5); 51 | 52 | setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/preferences/PreferencesPane.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.preferences; 2 | 3 | import javax.swing.JScrollPane; 4 | 5 | import org.objectweb.asm.Opcodes; 6 | 7 | import com.alee.laf.tabbedpane.WebTabbedPane; 8 | 9 | import me.nov.cafebabe.gui.preferences.list.SettingList; 10 | import me.nov.cafebabe.setting.Setting; 11 | import me.nov.cafebabe.setting.Settings; 12 | import me.nov.cafebabe.translations.Translations; 13 | 14 | public class PreferencesPane extends WebTabbedPane implements Opcodes { 15 | private static final long serialVersionUID = 1L; 16 | 17 | public PreferencesPane() throws Exception { 18 | this.setTabPlacement(WebTabbedPane.LEFT); 19 | for (String key : Settings.settings.keySet()) { 20 | this.addTab(Translations.get(key + " Settings"), 21 | new JScrollPane(new SettingList((Setting[]) Settings.settings.get(key).toArray()))); 22 | } 23 | this.addTab(Translations.get("About"), new JScrollPane(new AboutPanel())); 24 | } 25 | } -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/preferences/list/SettingList.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.preferences.list; 2 | 3 | import java.awt.Font; 4 | import java.awt.event.MouseAdapter; 5 | import java.awt.event.MouseEvent; 6 | import java.awt.event.MouseListener; 7 | 8 | import javax.swing.ListSelectionModel; 9 | 10 | import com.alee.extended.list.CheckBoxCellData; 11 | import com.alee.extended.list.CheckBoxListModel; 12 | import com.alee.extended.list.WebCheckBoxList; 13 | 14 | import me.nov.cafebabe.gui.node.SettingNode; 15 | import me.nov.cafebabe.setting.Setting; 16 | 17 | public class SettingList extends WebCheckBoxList { 18 | private static final long serialVersionUID = 1L; 19 | 20 | @SuppressWarnings("unchecked") 21 | public SettingList(Setting... settings) { 22 | this.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); 23 | CheckBoxListModel clm = new CheckBoxListModel(); 24 | for (Setting setting : settings) { 25 | clm.addCheckBoxElement(new SettingNode(setting), setting.get()); 26 | } 27 | this.setModel(clm); 28 | this.repaint(); 29 | for (MouseListener ml : this.getMouseListeners()) 30 | this.removeMouseListener(ml); 31 | addMouseListener(new MouseAdapter() { 32 | public void mousePressed(MouseEvent e) { 33 | int index = locationToIndex(e.getPoint()); 34 | if (index != -1) { 35 | CheckBoxCellData checkbox = (CheckBoxCellData) getModel().getElementAt(index); 36 | SettingNode sn = (SettingNode) checkbox.getUserObject(); 37 | checkbox.invertSelection(); 38 | repaint(); 39 | sn.setUserSelected(checkbox.isSelected()); 40 | } 41 | } 42 | }); 43 | setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/smalleditor/ChangelogPanel.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.smalleditor; 2 | 3 | import javax.swing.JEditorPane; 4 | import javax.swing.border.EmptyBorder; 5 | 6 | import me.nov.cafebabe.utils.io.Scanning; 7 | 8 | public class ChangelogPanel extends JEditorPane { 9 | private static final long serialVersionUID = 1L; 10 | 11 | public ChangelogPanel() { 12 | this.setContentType("text/html"); 13 | this.setEditable(false); 14 | this.setText(Scanning.readInputStream(ChangelogPanel.class.getResourceAsStream("/resources/changelog.txt"))); 15 | this.setFocusable(false); 16 | this.setOpaque(true); 17 | putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); 18 | setBorder(new EmptyBorder(16, 16, 16, 16)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/smalleditor/list/OpList.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.smalleditor.list; 2 | 3 | import java.awt.Font; 4 | import java.awt.event.MouseAdapter; 5 | import java.awt.event.MouseEvent; 6 | import java.awt.event.MouseListener; 7 | 8 | import javax.swing.JList; 9 | 10 | import me.nov.cafebabe.gui.node.OpcodeNode; 11 | import me.nov.cafebabe.gui.opchooser.OpcodeChooserDialog; 12 | import me.nov.cafebabe.utils.ui.LazyListModel; 13 | 14 | public class OpList extends JList { 15 | private static final long serialVersionUID = 1L; 16 | private int[] opcodes = {}; 17 | private OpcodeChooserDialog chooser; 18 | 19 | public OpList(OpcodeChooserDialog chooser, int... opcodes) { 20 | this.chooser = chooser; 21 | this.opcodes = opcodes; 22 | this.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); 23 | LazyListModel llm = new LazyListModel(); 24 | for (int opcode : opcodes) { 25 | llm.addElement(new OpcodeNode(opcode)); 26 | } 27 | this.setModel(llm); 28 | for (MouseListener ml : this.getMouseListeners()) 29 | this.removeMouseListener(ml); 30 | this.addMouseListener(new MouseAdapter() { 31 | public void mouseClicked(MouseEvent evt) { 32 | if (evt.getClickCount() >= 1) { 33 | int index = locationToIndex(evt.getPoint()); 34 | OpcodeNode on = llm.getElementAt(index); 35 | chooser.setOpcode(on.opcode); 36 | setSelectedIndex(index); 37 | chooser.refresh(); 38 | } 39 | } 40 | }); 41 | 42 | } 43 | 44 | public boolean refresh() { 45 | clearSelection(); 46 | int i = 0; 47 | if (opcodes != null) 48 | for (int opcode : opcodes) { 49 | if (chooser.getOpcode() == opcode) { 50 | setSelectedIndex(i); 51 | super.repaint(); 52 | return true; 53 | } 54 | i++; 55 | } 56 | super.repaint(); 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/translations/TranslationEditor.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.translations; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.Toolkit; 6 | 7 | import javax.swing.BorderFactory; 8 | import javax.swing.JLabel; 9 | import javax.swing.JPanel; 10 | import javax.swing.WindowConstants; 11 | import javax.swing.table.DefaultTableModel; 12 | 13 | import com.alee.laf.rootpane.WebDialog; 14 | import com.alee.laf.scroll.WebScrollPane; 15 | import com.alee.laf.table.WebTable; 16 | 17 | import me.nov.cafebabe.Cafebabe; 18 | import me.nov.cafebabe.translations.Translations; 19 | 20 | public class TranslationEditor extends WebDialog { 21 | private static final long serialVersionUID = 1L; 22 | 23 | public TranslationEditor() { 24 | super(Cafebabe.gui, true); 25 | this.setRound(5); 26 | this.setShadeWidth(20); 27 | this.setShowResizeCorner(false); 28 | this.initBounds(); 29 | this.setTitle(Translations.get("Translation editor")); 30 | this.setIconImage(Cafebabe.gui.getIconImage()); 31 | this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 32 | WebTable table = new WebTable() { 33 | private static final long serialVersionUID = 1L; 34 | 35 | @Override 36 | public boolean isCellEditable(int row, int column) { 37 | return column > 0; 38 | } 39 | }; 40 | DefaultTableModel model = new DefaultTableModel(new Object[] { "Hash code", "Translation" }, 0); 41 | for (int hashCode : Translations.translations.keySet()) { 42 | String translation = Translations.translations.get(hashCode); 43 | model.addRow(new Object[] { hashCode, translation }); 44 | } 45 | table.setColumnSelectionAllowed(false); 46 | table.getTableHeader().setReorderingAllowed(false); 47 | table.setModel(model); 48 | model.addTableModelListener(l -> { 49 | for (int row = 0; row < model.getRowCount(); row++) 50 | Translations.translations.put((Integer) model.getValueAt(row, 0), (String) model.getValueAt(row, 1)); 51 | Translations.saveTranslations(); 52 | }); 53 | JPanel pane = new JPanel(); 54 | pane.setLayout(new BorderLayout()); 55 | pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 56 | pane.add(new WebScrollPane(table), BorderLayout.CENTER); 57 | pane.add( 58 | new JLabel( 59 | "Please open an issue on the official github-repo and send in your tranlations!
Translations are stored in %userprofile%/.cafebabe/translations/
Make sure you don't miss out any translations.
Translations are added to the table when they were shown at least once!"), 60 | BorderLayout.NORTH); 61 | this.setContentPane(pane); 62 | setLocationRelativeTo(getParent()); 63 | this.setVisible(true); 64 | } 65 | 66 | private void initBounds() { 67 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 68 | int width = (int) (screenSize.width * 0.25); 69 | int height = (int) (screenSize.height * 0.5); 70 | setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/gui/ui/ClassTreeCellRenderer.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.gui.ui; 2 | 3 | import java.awt.Component; 4 | import java.awt.Font; 5 | import java.awt.Toolkit; 6 | 7 | import javax.swing.ImageIcon; 8 | import javax.swing.JTree; 9 | import javax.swing.tree.DefaultMutableTreeNode; 10 | import javax.swing.tree.DefaultTreeCellRenderer; 11 | 12 | import org.objectweb.asm.Opcodes; 13 | import org.objectweb.asm.tree.ClassNode; 14 | 15 | import me.nov.cafebabe.gui.node.SortedTreeClassNode; 16 | import me.nov.cafebabe.utils.asm.Access; 17 | import me.nov.cafebabe.utils.ui.Images; 18 | 19 | public class ClassTreeCellRenderer extends DefaultTreeCellRenderer implements Opcodes { 20 | private static final long serialVersionUID = 1L; 21 | 22 | private ImageIcon pack, clazz, enu, itf; 23 | 24 | public ClassTreeCellRenderer() { 25 | this.pack = new ImageIcon( 26 | Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/tree/package.png"))); 27 | this.clazz = new ImageIcon( 28 | Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/classtype/class.png"))); 29 | this.enu = Images.combine(clazz, new ImageIcon( 30 | Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/classtype/enum.png")))); 31 | this.itf = Images.combine(clazz, new ImageIcon( 32 | Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/classtype/interface.png")))); 33 | } 34 | 35 | @Override 36 | public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, 37 | final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { 38 | super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 39 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 40 | if (node instanceof SortedTreeClassNode) { 41 | SortedTreeClassNode stn = (SortedTreeClassNode) node; 42 | ClassNode cn = stn.getClazz(); 43 | if (cn != null) { 44 | if (Access.isInterface(cn.access)) { 45 | this.setIcon(this.itf); 46 | } else if (Access.isEnum(cn.access)) { 47 | this.setIcon(this.enu); 48 | } else { 49 | this.setIcon(this.clazz); 50 | } 51 | } else { 52 | this.setIcon(this.pack); 53 | } 54 | } 55 | return this; 56 | } 57 | 58 | @Override 59 | public Font getFont() { 60 | return new Font(Font.SANS_SERIF, Font.PLAIN, 12); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/loading/FrameHack.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.loading; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.objectweb.asm.ClassReader; 9 | import org.objectweb.asm.ClassWriter; 10 | import org.objectweb.asm.tree.AbstractInsnNode; 11 | import org.objectweb.asm.tree.ClassNode; 12 | import org.objectweb.asm.tree.FrameNode; 13 | import org.objectweb.asm.tree.LabelNode; 14 | import org.objectweb.asm.tree.MethodNode; 15 | 16 | public class FrameHack extends ClassWriter { 17 | 18 | public FrameHack() { 19 | super(COMPUTE_FRAMES); 20 | } 21 | 22 | private HashMap ugly = new HashMap<>(); 23 | 24 | public static void findCommonParents(Map knownCommons, ClassNode cn) { 25 | // TODO: avoid nonsense labels 26 | FrameHack cw = new FrameHack(); 27 | cn.accept(cw); 28 | ClassReader cr = new ClassReader(cw.toByteArray()); 29 | ClassNode dirty = new ClassNode(); 30 | cr.accept(dirty, ClassReader.EXPAND_FRAMES); 31 | for (int i = 0; i < cn.methods.size(); i++) { 32 | MethodNode dirtyMethod = dirty.methods.get(i); 33 | MethodNode realMethod = cn.methods.get(i); 34 | try { 35 | for (int j = 0; j < dirtyMethod.instructions.size(); j++) { 36 | AbstractInsnNode ain = dirtyMethod.instructions.get(j); 37 | if (ain.getType() == AbstractInsnNode.FRAME) { 38 | FrameNode dirtyFrame = (FrameNode) ain; 39 | FrameNode realFrame = findRealFrame(dirtyFrame, realMethod); 40 | if (realFrame == null) 41 | continue; 42 | for (int k = 0; k < dirtyFrame.stack.size(); k++) { 43 | Object stack = dirtyFrame.stack.get(k); 44 | if (stack.toString().startsWith("CAFEBABE")) { 45 | int hash = Integer.parseInt(stack.toString().substring(8)); 46 | String key = cw.ugly.get(hash); 47 | knownCommons.put(key, realFrame.stack.get(k).toString()); 48 | } 49 | } 50 | 51 | for (int k = 0; k < dirtyFrame.local.size(); k++) { 52 | Object localDirty = dirtyFrame.local.get(k); 53 | if (localDirty.toString().startsWith("CAFEBABE")) { 54 | int hash = Integer.parseInt(localDirty.toString().substring(8)); 55 | String key = cw.ugly.get(hash); 56 | if (k < realFrame.local.size()) { 57 | knownCommons.put(key, realFrame.local.get(k).toString()); 58 | } else { 59 | knownCommons.put(key, "java/lang/Object"); 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } catch (RuntimeException e) { 66 | // do nothing and continue 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | } 71 | } 72 | 73 | public static List debug = Arrays.asList(AbstractInsnNode.LABEL, AbstractInsnNode.LINE); 74 | 75 | private static FrameNode findRealFrame(FrameNode dirtyFrame, MethodNode realMethod) { 76 | LabelNode dirtyLabel = null; 77 | AbstractInsnNode ain = dirtyFrame.getPrevious(); 78 | while (ain.getType() != AbstractInsnNode.LABEL) { 79 | ain = ain.getPrevious(); 80 | } 81 | dirtyLabel = (LabelNode) ain; 82 | int dirtyIndex = labelIndex(dirtyLabel); 83 | 84 | for (AbstractInsnNode realAin : realMethod.instructions.toArray()) { 85 | if (realAin.getType() == AbstractInsnNode.LABEL) { 86 | if (dirtyIndex == 0) { 87 | // label found 88 | AbstractInsnNode next = realAin.getNext(); 89 | while (next != null && debug.contains(next.getType())) { 90 | next = next.getNext(); 91 | } 92 | if (next instanceof FrameNode) { 93 | return (FrameNode) next; 94 | } else { 95 | return null; 96 | } 97 | } 98 | dirtyIndex--; 99 | } 100 | } 101 | throw new RuntimeException(); 102 | } 103 | 104 | private static int labelIndex(LabelNode label) { 105 | int i = 0; 106 | AbstractInsnNode ain = label.getPrevious(); 107 | while (ain != null) { 108 | if (ain.getType() == AbstractInsnNode.LABEL) { 109 | i++; 110 | } 111 | ain = ain.getPrevious(); 112 | } 113 | return i; 114 | } 115 | 116 | @Override 117 | protected String getCommonSuperClass(String type1, String type2) { 118 | if (type1.startsWith("CAFEBABE") || type2.startsWith("CAFEBABE")) { 119 | return "java/lang/Object"; 120 | } 121 | if (type1.equals("java/lang/Object") || type2.equals("java/lang/Object")) { 122 | return "java/lang/Object"; 123 | } 124 | String key = (type1 + ":" + type2); 125 | int hash = key.hashCode(); 126 | ugly.put(hash, key); 127 | return "CAFEBABE" + hash; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/loading/Loader.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.loading; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.Arrays; 7 | import java.util.Enumeration; 8 | import java.util.HashMap; 9 | import java.util.jar.JarEntry; 10 | import java.util.jar.JarFile; 11 | 12 | import org.objectweb.asm.ClassReader; 13 | import org.objectweb.asm.tree.ClassNode; 14 | 15 | public class Loader { 16 | public static final byte[] javaMagic = { -54, -2, -70, -66 }; 17 | 18 | public static HashMap loadClasses(JarFile jf) { 19 | HashMap classes = new HashMap<>(); 20 | Enumeration entries = jf.entries(); 21 | 22 | while (entries.hasMoreElements()) { 23 | try { 24 | JarEntry entry = entries.nextElement(); 25 | if (entry.getSize() < 3) { 26 | continue; 27 | } 28 | InputStream stream = jf.getInputStream(entry); 29 | 30 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 31 | 32 | int read = 0; 33 | byte[] cafebabe = new byte[4]; 34 | stream.read(cafebabe); 35 | bos.write(cafebabe, 0, 4); 36 | if (Arrays.equals(bos.toByteArray(), javaMagic)) { 37 | byte[] buff = new byte[1024]; 38 | 39 | while ((read = stream.read(buff)) != -1) { 40 | bos.write(buff, 0, read); 41 | } 42 | byte[] data = bos.toByteArray(); 43 | classes.put(entry, convertToASM(data)); 44 | } 45 | } catch (IOException e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | return classes; 50 | } 51 | 52 | public static ClassNode convertToASM(final byte[] bytes) { 53 | if (bytes == null) { 54 | return null; 55 | } 56 | ClassReader cr = new ClassReader(bytes); 57 | ClassNode cn = new ClassNode(); 58 | cr.accept(cn, ClassReader.EXPAND_FRAMES); 59 | return cn; 60 | } 61 | 62 | public static ClassNode loadLocalClass(String type) throws IOException { 63 | return convertToASM(loadFromClasspath(type)); 64 | } 65 | 66 | public static byte[] loadFromClasspath(String type) throws IOException { 67 | if (type == null) { 68 | return null; 69 | } 70 | InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(type + ".class"); 71 | if (is == null) { 72 | return null; 73 | } 74 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 75 | byte[] buffer = new byte[4096]; 76 | int n; 77 | while ((n = is.read(buffer)) > 0) { 78 | baos.write(buffer, 0, n); 79 | } 80 | return baos.toByteArray(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/loading/Saver.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.loading; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.Arrays; 8 | import java.util.Enumeration; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | import java.util.jar.JarEntry; 12 | import java.util.jar.JarFile; 13 | import java.util.jar.JarOutputStream; 14 | 15 | import org.objectweb.asm.ClassWriter; 16 | import org.objectweb.asm.tree.ClassNode; 17 | 18 | import me.nov.cafebabe.gui.ClassTree; 19 | import me.nov.cafebabe.utils.asm.LibClassWriter; 20 | 21 | public class Saver { 22 | public static final byte[] javaMagic = { -54, -2, -70, -66 }; 23 | 24 | public static void saveClasses(HashMap nodes, JarFile inputFile, String outputFile) 25 | throws IOException { 26 | FileOutputStream fos = new FileOutputStream(outputFile); 27 | JarOutputStream out = new JarOutputStream(fos); 28 | Enumeration inputEntries = inputFile.entries(); 29 | while (inputEntries.hasMoreElements()) { 30 | try { 31 | JarEntry entry = inputEntries.nextElement(); 32 | InputStream stream = inputFile.getInputStream(entry); 33 | 34 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 35 | 36 | int read = 0; 37 | if (entry.getSize() > 3) { 38 | byte[] cafebabe = new byte[4]; 39 | stream.read(cafebabe); 40 | bos.write(cafebabe, 0, 4); 41 | if (Arrays.equals(bos.toByteArray(), javaMagic)) { 42 | continue; 43 | } 44 | } 45 | byte[] buff = new byte[1024]; 46 | 47 | while ((read = stream.read(buff)) != -1) { 48 | bos.write(buff, 0, read); 49 | } 50 | byte[] data = bos.toByteArray(); 51 | packFile(out, entry, entry.getName(), data); 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | Map classes = new HashMap<>(); 57 | for (JarEntry oldEntry : nodes.keySet()) { 58 | ClassNode cn = nodes.get(oldEntry); 59 | classes.put(cn.name, cn); 60 | } 61 | for (JarEntry oldEntry : nodes.keySet()) { 62 | packFile(out, oldEntry, nodes.get(oldEntry).name + ".class", 63 | exportNode(nodes.get(oldEntry), classes, new HashMap<>(), new HashMap<>())); 64 | } 65 | } 66 | 67 | public static void packFile(JarOutputStream out, JarEntry oldEntry, String path, byte[] data) throws IOException { 68 | JarEntry newEntry = new JarEntry(path); 69 | newEntry.setTime(oldEntry.getTime()); 70 | // newEntry.setMethod(oldEntry.getMethod()); 71 | newEntry.setComment(oldEntry.getComment()); 72 | newEntry.setExtra(oldEntry.getExtra()); 73 | 74 | out.putNextEntry(newEntry); 75 | out.write(data, 0, data.length); 76 | out.closeEntry(); 77 | } 78 | 79 | public static byte[] exportNode(ClassNode cn, Map classes, Map libraries, 80 | Map knownCommons) { 81 | ClassWriter cw = ClassTree.useFrameRegeneration 82 | ? new LibClassWriter(ClassWriter.COMPUTE_FRAMES, classes, libraries, knownCommons) 83 | : new ClassWriter(ClassWriter.COMPUTE_MAXS); 84 | cn.accept(cw); 85 | byte[] b = cw.toByteArray(); 86 | return b; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/setting/Setting.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.setting; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import me.nov.cafebabe.translations.Translations; 6 | import me.nov.cafebabe.utils.interfaces.BooleanAction; 7 | 8 | public class Setting { 9 | public String id; 10 | public String title; 11 | public String description; 12 | public Field field; 13 | public boolean defaultValue; 14 | private BooleanAction updateAction; 15 | 16 | public Setting(String id, String title, String description, Field field, boolean defaultValue, 17 | BooleanAction updateAction) { 18 | super(); 19 | this.id = id; 20 | this.title = Translations.get(title); 21 | this.description = Translations.get(description); 22 | this.field = field; 23 | this.defaultValue = defaultValue; 24 | this.updateAction = updateAction; 25 | } 26 | 27 | public void setInitial(boolean b) { 28 | try { 29 | field.setBoolean(null, b); 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | public void set(boolean b) { 36 | try { 37 | field.setBoolean(null, b); 38 | Settings.saveProperties(); 39 | new Thread(() -> { 40 | try { 41 | // call later to update ui 42 | Thread.sleep(500); 43 | if (updateAction != null) { 44 | updateAction.action(b); 45 | } 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | }).start(); 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | 55 | public boolean get() { 56 | try { 57 | return field.getBoolean(null); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | return defaultValue; 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/translations/Translations.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.translations; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.net.URLEncoder; 8 | import java.nio.file.Files; 9 | import java.util.HashMap; 10 | import java.util.Properties; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | 14 | import com.alee.laf.WebLookAndFeel; 15 | 16 | import me.nov.cafebabe.Cafebabe; 17 | import me.nov.cafebabe.gui.smalleditor.ChangelogPanel; 18 | import me.nov.cafebabe.utils.io.Scanning; 19 | import me.nov.cafebabe.utils.ui.WebLaF; 20 | import me.nov.cafebabe.utils.web.URLReader; 21 | 22 | public class Translations { 23 | public static final HashMap translations = new HashMap<>(); 24 | public static final String language = System.getProperty("user.language"); 25 | 26 | public static boolean translate = false; 27 | 28 | private static File translationsFile; 29 | 30 | public static String get(String i) { 31 | if (!translate) { 32 | return i; 33 | } 34 | if (translations.containsKey(i.hashCode())) { 35 | return translations.get(i.hashCode()); 36 | } 37 | 38 | translations.put(i.hashCode(), i); 39 | return i; 40 | } 41 | 42 | @SuppressWarnings("unused") 43 | @Deprecated 44 | private static String translateGoogle(String i) { 45 | String translation; 46 | try { 47 | translation = translate(i); 48 | if (translation == null || translation.trim().length() < 3) { 49 | return i; 50 | } 51 | translation = translation.substring(1, translation.length() - 1); 52 | translations.put(i.hashCode(), translation); 53 | return translation; 54 | } catch (Exception e) { 55 | return i; 56 | } 57 | } 58 | 59 | @Deprecated 60 | private static String translate(String i) throws IOException { 61 | Matcher m = Pattern.compile("\"(.*?)\"") 62 | .matcher(URLReader.getURLContent("https://translate.googleapis.com/translate_a/single?client=gtx&sl=eng&tl=" 63 | + language + "&dt=t&q=" + URLEncoder.encode(i, "UTF-8"))); 64 | return m.find() ? m.group() : i; 65 | } 66 | 67 | public static void saveTranslations() { 68 | Properties properties = new Properties(); 69 | for (Integer key : translations.keySet()) { 70 | properties.setProperty(String.valueOf(key), translations.get(key)); 71 | } 72 | try { 73 | properties.store(new FileOutputStream(translationsFile), null); 74 | } catch (IOException e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | 79 | private static void loadTranslations() { 80 | boolean needFontUpdate = false; 81 | String fileName = language + ".translation"; 82 | translationsFile = new File(new File(Cafebabe.folder, "translations"), fileName); 83 | // TODO warn about old translation? 84 | Properties properties = new Properties(); 85 | if (translationsFile.exists()) { 86 | try { 87 | properties.load(new FileInputStream(translationsFile)); 88 | 89 | for (Object key : properties.keySet()) { 90 | String translation = String.valueOf(properties.get(key)); 91 | if(!needFontUpdate && WebLookAndFeel.globalControlFont.canDisplayUpTo(translation) != -1) { 92 | needFontUpdate = true; //check for chinese or similar characters 93 | } 94 | translations.put(Integer.valueOf(String.valueOf(key)), translation); 95 | 96 | } 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | } else { 101 | try { 102 | Files.write(translationsFile.toPath(), 103 | Scanning 104 | .readInputStream( 105 | ChangelogPanel.class.getResourceAsStream("/resources/default_translations/" + fileName)) 106 | .getBytes()); 107 | loadTranslations(); 108 | } catch (Exception e) { 109 | try { 110 | translationsFile.getParentFile().mkdirs(); 111 | translationsFile.createNewFile(); 112 | } catch (IOException e1) { 113 | e1.printStackTrace(); 114 | } 115 | } 116 | } 117 | if(needFontUpdate) { 118 | WebLaF.fixUnicodeSupport(); 119 | } 120 | } 121 | 122 | static { 123 | loadTranslations(); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/asm/Code.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.asm; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.objectweb.asm.tree.AbstractInsnNode; 6 | import org.objectweb.asm.tree.InsnList; 7 | import org.objectweb.asm.tree.JumpInsnNode; 8 | import org.objectweb.asm.tree.LabelNode; 9 | 10 | public class Code { 11 | public static AbstractInsnNode cloneNode(AbstractInsnNode ain) { 12 | if (ain instanceof LabelNode) { 13 | return new LabelNode(); 14 | } else if (ain instanceof JumpInsnNode) { 15 | return new JumpInsnNode(ain.getOpcode(), ((JumpInsnNode) ain).label); 16 | } else { 17 | return ain.clone(new HashMap<>()); 18 | } 19 | } 20 | 21 | public static int getLabelCount(InsnList instructions) { 22 | int i = 0; 23 | for (AbstractInsnNode ain : instructions.toArray()) { 24 | if (ain instanceof LabelNode) { 25 | i++; 26 | } 27 | } 28 | return i; 29 | } 30 | 31 | public static LabelNode getLabelByIndex(InsnList instructions, int index) { 32 | int i = 0; 33 | for (AbstractInsnNode ain : instructions.toArray()) { 34 | if (ain instanceof LabelNode) { 35 | if(i == index) { 36 | return (LabelNode) ain; 37 | } 38 | i++; 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/asm/LibClassWriter.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.asm; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.Toolkit; 5 | import java.io.IOException; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import javax.swing.JFrame; 10 | import javax.swing.JOptionPane; 11 | 12 | import org.objectweb.asm.ClassWriter; 13 | import org.objectweb.asm.tree.ClassNode; 14 | 15 | import me.nov.cafebabe.loading.Loader; 16 | import me.nov.cafebabe.translations.Translations; 17 | 18 | public class LibClassWriter extends ClassWriter { 19 | 20 | private Map classes; 21 | private ParentUtils util; 22 | private Map knownCommons; 23 | 24 | public LibClassWriter(int flags, Map classes, Map libraries, 25 | Map knownCommons) { 26 | super(flags); 27 | this.classes = new HashMap<>(classes); 28 | this.util = new ParentUtils(classes); 29 | if (libraries != null) { 30 | classes.putAll(libraries); 31 | } 32 | this.knownCommons = knownCommons; 33 | } 34 | 35 | @Override 36 | protected String getCommonSuperClass(String type1, String type2) { 37 | if (knownCommons.containsKey(type1 + ":" + type2)) { 38 | return knownCommons.get(type1 + ":" + type2); 39 | } 40 | if (type1.length() <= 1 || type2.length() <= 1) { 41 | return "java/lang/Object"; 42 | } 43 | if (type1.equals("java/lang/Object") || type2.equals("java/lang/Object")) { 44 | return "java/lang/Object"; 45 | } 46 | try { 47 | ClassNode cn1 = get(type1); 48 | ClassNode cn2 = get(type2); 49 | if (cn1 == null || cn2 == null) { 50 | System.err.println((cn1 == null ? (cn2 == null ? (type1 + " and " + type2) : type1) : type2) 51 | + " not found. Check your classpath!"); 52 | try { 53 | return super.getCommonSuperClass(type1, type2); 54 | } catch (Exception e) { 55 | } 56 | return "java/lang/Object"; 57 | } 58 | ClassNode common = findCommonParent(cn1, cn2); 59 | if (common == null) { 60 | try { 61 | System.err.println("Couldn't get common superclass of the classes " + type1 + " " + type2); 62 | return super.getCommonSuperClass(type1, type2); 63 | } catch (Exception e) { 64 | } 65 | return "java/lang/Object"; 66 | } 67 | return common.name; 68 | } catch (Exception e) { 69 | System.err 70 | .println("Couldn't find out common superclass of the classes " + type1 + " " + type2 + ", asking user!"); 71 | JFrame dummy = new JFrame(); 72 | dummy.setVisible(true); 73 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 74 | dummy.setLocation(screenSize.width / 2, screenSize.height / 2); 75 | dummy.setAlwaysOnTop(true); 76 | String superclass = JOptionPane.showInputDialog(dummy, 77 | Translations.get("Please enter a common super class of those classes:") + " " + type1 + " " + type2, 78 | "java/lang/Object"); 79 | dummy.dispose(); 80 | if (superclass == null || superclass.isEmpty()) { 81 | return "java/lang/Object"; 82 | } 83 | knownCommons.put(type1 + ":" + type2, superclass.trim()); 84 | return superclass.trim(); 85 | } 86 | } 87 | 88 | public ClassNode findCommonParent(ClassNode cn1, ClassNode cn2) { 89 | if (cn1.name.equals(cn2.name)) { 90 | return cn1; 91 | } 92 | if (util.isAssignableFrom(cn1, cn2)) { 93 | return cn1; 94 | } 95 | if (util.isAssignableFrom(cn2, cn1)) { 96 | return cn2; 97 | } 98 | if (Access.isInterface(cn1.access) || Access.isInterface(cn2.access) || cn1.superName == null 99 | || cn1.superName == null) { 100 | return get("java/lang/Object"); 101 | } else { 102 | do { 103 | cn1 = get(cn1.superName); 104 | } while (cn1.superName != null && !util.isAssignableFrom(cn1, cn2)); 105 | return cn1; 106 | } 107 | } 108 | 109 | private ClassNode get(String name) { 110 | if (classes.containsKey(name)) { 111 | return classes.get(name); 112 | } 113 | try { 114 | ClassNode cn = Loader.loadLocalClass(name); 115 | if (cn != null) { 116 | classes.put(name, cn); 117 | return cn; 118 | } 119 | } catch (IOException e) { 120 | e.printStackTrace(); 121 | } 122 | throw new RuntimeException(name + " not found in your classpath"); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/asm/ParentUtils.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.asm; 2 | 3 | import java.util.Map; 4 | 5 | import org.objectweb.asm.tree.ClassNode; 6 | 7 | public class ParentUtils { 8 | private Map classes; 9 | 10 | public ParentUtils(Map classes) { 11 | this.classes = classes; 12 | } 13 | 14 | public boolean isAssignableFrom(ClassNode cn, ClassNode cn2) { 15 | if (cn2.name.equals(cn.name)) { 16 | return true; 17 | } 18 | for (String itfn : cn2.interfaces) { 19 | ClassNode itf = classes.get(itfn); 20 | if (itf == null) 21 | continue; 22 | if (isAssignableFrom(cn, itf)) { 23 | return true; 24 | } 25 | } 26 | if (cn2.superName != null) { 27 | ClassNode sn = classes.get(cn2.superName); 28 | if (sn != null) 29 | if (isAssignableFrom(cn, sn)) { 30 | return true; 31 | } 32 | } 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/drop/IDropUser.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.drop; 2 | 3 | import java.io.File; 4 | 5 | public interface IDropUser { 6 | public void preLoadJars(int id); 7 | 8 | public void onJarLoad(int id, File input); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/drop/JarDropHandler.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.drop; 2 | 3 | import java.awt.datatransfer.DataFlavor; 4 | import java.awt.datatransfer.Transferable; 5 | import java.io.File; 6 | import java.util.List; 7 | 8 | import javax.swing.TransferHandler; 9 | 10 | public class JarDropHandler extends TransferHandler { 11 | private static final long serialVersionUID = 1232L; 12 | private final IDropUser user; 13 | private final int id; 14 | 15 | public JarDropHandler(IDropUser user, int id) { 16 | this.user = user; 17 | this.id = id; 18 | } 19 | 20 | @Override 21 | public boolean canImport(TransferHandler.TransferSupport info) { 22 | info.setShowDropLocation(false); 23 | return info.isDrop() && info.isDataFlavorSupported(DataFlavor.javaFileListFlavor); 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | @Override 28 | public boolean importData(TransferHandler.TransferSupport info) { 29 | if (!info.isDrop()) 30 | return false; 31 | Transferable t = info.getTransferable(); 32 | List data = null; 33 | try { 34 | data = (List) t.getTransferData(DataFlavor.javaFileListFlavor); 35 | } catch (Exception e) { 36 | return false; 37 | } 38 | user.preLoadJars(id); 39 | for (File jar : data) { 40 | if (jar.getName().toLowerCase().endsWith(".jar")) { 41 | user.onJarLoad(id, jar); 42 | break; 43 | } 44 | } 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/formatting/Colors.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.formatting; 2 | 3 | import java.awt.Color; 4 | 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.tree.AbstractInsnNode; 7 | 8 | public class Colors implements Opcodes { 9 | public static final String eclipse_keyword = "#7f0055"; 10 | public static final String debug_grey = "#878787"; 11 | public static final String fields = "#0000c0"; 12 | public static final String methods = "#c00000"; 13 | public static final String strings = "#090"; 14 | public static final String local_vars = "#6a3e3e"; 15 | public static final String comment = "#3f7f5f"; 16 | 17 | // graph 18 | public static final String edgeColor = "#111111"; 19 | public static final String jumpColor = "#39698a"; 20 | public static final String jumpColorGreen = "#388a47"; 21 | public static final String jumpColorRed = "#8a3e38"; 22 | public static final String jumpColorPurple = "#ff71388a"; 23 | public static final String jumpColorPink = "#ba057a"; // #8a386d 24 | 25 | // editor tab colors 26 | public static final Color methodTabColor = new Color(0xffffcc); 27 | public static final Color decompilerTabColor = new Color(0x89c4f4); 28 | public static final Color graphTabColor = new Color(0xc8f7c5); 29 | 30 | public static final Color highlightColor = new Color(0x0078d7); 31 | 32 | public static String getColor(int type, int opcode) { 33 | switch (opcode) { 34 | case ATHROW: 35 | case IRETURN: 36 | case LRETURN: 37 | case FRETURN: 38 | case DRETURN: 39 | case ARETURN: 40 | case RETURN: 41 | return "#4d0000"; 42 | case ACONST_NULL: 43 | case ICONST_M1: 44 | case ICONST_0: 45 | case ICONST_1: 46 | case ICONST_2: 47 | case ICONST_3: 48 | case ICONST_4: 49 | case ICONST_5: 50 | case LCONST_0: 51 | case LCONST_1: 52 | case FCONST_0: 53 | case FCONST_1: 54 | case FCONST_2: 55 | case DCONST_0: 56 | case DCONST_1: 57 | return "#005733"; 58 | } 59 | switch (type) { 60 | case AbstractInsnNode.FIELD_INSN: 61 | return "#44004d"; 62 | case AbstractInsnNode.METHOD_INSN: 63 | return "#14004d"; 64 | case AbstractInsnNode.INT_INSN: 65 | case AbstractInsnNode.LDC_INSN: 66 | return "#004d40"; 67 | case AbstractInsnNode.VAR_INSN: 68 | return "#6a3e3e"; 69 | case AbstractInsnNode.JUMP_INSN: 70 | return "#003d4d"; 71 | case AbstractInsnNode.TYPE_INSN: 72 | return "#474d00"; 73 | default: 74 | return "#000"; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/formatting/EscapedString.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.formatting; 2 | 3 | public class EscapedString { 4 | private String text; 5 | private String escapedText; 6 | 7 | public EscapedString(String text) { 8 | super(); 9 | if (text == null) { 10 | text = ""; 11 | } 12 | this.text = text; 13 | if (text.length() > 127) { 14 | text = text.substring(0, 124) + "..."; 15 | } 16 | this.escapedText = text.replace("&", "&").replace("<", "<").replace(">", ">"); 17 | } 18 | 19 | public EscapedString(String text, int max, boolean html) { 20 | super(); 21 | if (text == null) { 22 | text = ""; 23 | } 24 | this.text = text; 25 | if (text.length() > max) { 26 | text = text.substring(0, max - 3) + "..."; 27 | } 28 | if (html) { 29 | this.escapedText = text.replace("&", "&").replace("<", "<").replace(">", ">"); 30 | } else { 31 | this.escapedText = text; 32 | } 33 | } 34 | 35 | public String getText() { 36 | return text; 37 | } 38 | 39 | public void setText(String text) { 40 | this.text = text; 41 | } 42 | 43 | public String getEscapedText() { 44 | return escapedText; 45 | } 46 | 47 | public void setEscapedText(String escapedText) { 48 | this.escapedText = escapedText; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | return text.equals(obj); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return escapedText; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/formatting/Html.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.formatting; 2 | 3 | public class Html { 4 | public static String color(String color, String text) { 5 | return "" + text + ""; 6 | } 7 | 8 | public static String bold(String text) { 9 | return "" + text + ""; 10 | } 11 | 12 | public static String italics(String text) { 13 | return "" + text + ""; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/interfaces/Action.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.interfaces; 2 | 3 | public interface Action { 4 | void action(); 5 | } -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/interfaces/BooleanAction.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.interfaces; 2 | 3 | public interface BooleanAction { 4 | void action(boolean b); 5 | } -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/io/Scanning.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.io; 2 | 3 | import java.io.InputStream; 4 | import java.util.Scanner; 5 | 6 | public class Scanning { 7 | @SuppressWarnings("resource") 8 | public static String readInputStream(InputStream is) { 9 | return new Scanner(is).useDelimiter("\\A").next(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/ui/Images.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.ui; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.FontMetrics; 6 | import java.awt.Graphics; 7 | import java.awt.Graphics2D; 8 | import java.awt.Image; 9 | import java.awt.image.BufferedImage; 10 | 11 | import javax.swing.ImageIcon; 12 | 13 | import me.nov.cafebabe.Cafebabe; 14 | 15 | public class Images { 16 | public static ImageIcon combine(ImageIcon icon1, ImageIcon icon2) { 17 | Image img1 = icon1.getImage(); 18 | Image img2 = icon2.getImage(); 19 | 20 | int w = icon1.getIconWidth(); 21 | int h = icon1.getIconHeight(); 22 | BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 23 | Graphics2D g2 = image.createGraphics(); 24 | g2.drawImage(img1, 0, 0, null); 25 | g2.drawImage(img2, 0, 0, null); 26 | g2.dispose(); 27 | 28 | return new ImageIcon(image); 29 | } 30 | 31 | public static BufferedImage watermark(BufferedImage old) { 32 | BufferedImage copy = broadenImage(old); 33 | Graphics2D g2d = copy.createGraphics(); 34 | g2d.setPaint(Color.black); 35 | g2d.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); 36 | FontMetrics fm = g2d.getFontMetrics(); 37 | String watermark = Cafebabe.gui.getTitle(); 38 | int x = copy.getWidth() - fm.stringWidth(watermark) - 5; 39 | int y = fm.getHeight(); 40 | g2d.drawString(watermark, x, y); 41 | g2d.dispose(); 42 | return copy; 43 | } 44 | 45 | private static BufferedImage broadenImage(BufferedImage source) { 46 | BufferedImage b = new BufferedImage(source.getWidth() + 60, source.getHeight() + 60, source.getType()); 47 | Graphics g = b.createGraphics(); 48 | g.setColor(Color.WHITE); 49 | g.fillRect(0, 0, source.getWidth() + 60, source.getHeight() + 60); 50 | g.setColor(Color.BLACK); 51 | g.drawImage(source, 30, 30, null); 52 | g.dispose(); 53 | return b; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/ui/LazyListModel.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.ui; 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.swing.AbstractListModel; 6 | 7 | import org.objectweb.asm.tree.AbstractInsnNode; 8 | 9 | import me.nov.cafebabe.gui.node.InstructionNode; 10 | 11 | public class LazyListModel extends AbstractListModel { 12 | private static final long serialVersionUID = 1L; 13 | 14 | private ArrayList list; 15 | 16 | public LazyListModel() { 17 | this.list = new ArrayList(); 18 | } 19 | 20 | public void addElement(E e) { 21 | list.add(e); 22 | } 23 | 24 | @Override 25 | public int getSize() { 26 | return list.size(); 27 | } 28 | 29 | @Override 30 | protected void fireIntervalAdded(Object source, int index0, int index1) { 31 | } 32 | 33 | @Override 34 | public E getElementAt(int index) { 35 | return list.get(index); 36 | } 37 | 38 | public int indexOf(AbstractInsnNode ain) { 39 | for (int i = 0; i < list.size(); i++) { 40 | InstructionNode ie = (InstructionNode) list.get(i); 41 | if (ie.ain.equals(ain)) { 42 | return i; 43 | } 44 | } 45 | return -1; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/ui/Listeners.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.ui; 2 | 3 | import java.awt.Component; 4 | import java.awt.event.MouseEvent; 5 | import java.awt.event.MouseListener; 6 | import java.beans.PropertyChangeEvent; 7 | import java.util.Objects; 8 | 9 | import javax.swing.JComponent; 10 | import javax.swing.SwingUtilities; 11 | import javax.swing.event.ChangeEvent; 12 | import javax.swing.event.ChangeListener; 13 | import javax.swing.event.DocumentEvent; 14 | import javax.swing.event.DocumentListener; 15 | import javax.swing.text.Document; 16 | import javax.swing.text.JTextComponent; 17 | 18 | import me.nov.cafebabe.utils.interfaces.Action; 19 | 20 | public class Listeners { 21 | public static void addChangeListener(JTextComponent text, ChangeListener changeListener) { 22 | Objects.requireNonNull(text); 23 | Objects.requireNonNull(changeListener); 24 | DocumentListener dl = new DocumentListener() { 25 | private int lastChange = 0, lastNotifiedChange = 0; 26 | 27 | @Override 28 | public void insertUpdate(DocumentEvent e) { 29 | changedUpdate(e); 30 | } 31 | 32 | @Override 33 | public void removeUpdate(DocumentEvent e) { 34 | changedUpdate(e); 35 | } 36 | 37 | @Override 38 | public void changedUpdate(DocumentEvent e) { 39 | lastChange++; 40 | SwingUtilities.invokeLater(() -> { 41 | if (lastNotifiedChange != lastChange) { 42 | lastNotifiedChange = lastChange; 43 | changeListener.stateChanged(new ChangeEvent(text)); 44 | } 45 | }); 46 | } 47 | }; 48 | text.addPropertyChangeListener("document", (PropertyChangeEvent e) -> { 49 | Document d1 = (Document) e.getOldValue(); 50 | Document d2 = (Document) e.getNewValue(); 51 | if (d1 != null) 52 | d1.removeDocumentListener(dl); 53 | if (d2 != null) 54 | d2.addDocumentListener(dl); 55 | dl.changedUpdate(null); 56 | }); 57 | Document d = text.getDocument(); 58 | if (d != null) 59 | d.addDocumentListener(dl); 60 | } 61 | 62 | public static void addMouseReleasedListener(JComponent c, Action action, boolean childs) { 63 | c.addMouseListener(new MouseListener() { 64 | 65 | @Override 66 | public void mouseReleased(MouseEvent e) { 67 | action.action(); 68 | } 69 | 70 | @Override 71 | public void mousePressed(MouseEvent e) { 72 | } 73 | 74 | @Override 75 | public void mouseExited(MouseEvent e) { 76 | } 77 | 78 | @Override 79 | public void mouseEntered(MouseEvent e) { 80 | } 81 | 82 | @Override 83 | public void mouseClicked(MouseEvent e) { 84 | } 85 | }); 86 | if (childs) { 87 | for (Component child : c.getComponents()) { 88 | addMouseReleasedListener((JComponent) child, action, true); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/ui/WebLaF.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.ui; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.Font; 5 | import java.awt.Toolkit; 6 | 7 | import javax.swing.BorderFactory; 8 | import javax.swing.ImageIcon; 9 | import javax.swing.JLabel; 10 | import javax.swing.JSeparator; 11 | import javax.swing.SwingConstants; 12 | import javax.swing.border.EtchedBorder; 13 | 14 | import com.alee.extended.image.WebImage; 15 | import com.alee.extended.panel.GroupPanel; 16 | import com.alee.extended.panel.WebOverlay; 17 | import com.alee.laf.WebLookAndFeel; 18 | import com.alee.managers.language.data.TooltipWay; 19 | import com.alee.managers.tooltip.TooltipManager; 20 | 21 | public class WebLaF { 22 | 23 | private static ImageIcon info; 24 | static { 25 | info = new ImageIcon(Toolkit.getDefaultToolkit().getImage(WebLaF.class.getResource("/resources/overlay/info.png"))); 26 | } 27 | 28 | public static GroupPanel createInfoLabel(JLabel nameLabel, String overlayText) { 29 | WebOverlay overlayPanel = new WebOverlay(); 30 | overlayPanel.setComponent(nameLabel); 31 | WebImage overlay = new WebImage(info); 32 | TooltipManager.setTooltip(overlay, overlayText, TooltipWay.trailing, 0); 33 | overlayPanel.addOverlay(overlay, SwingConstants.TRAILING, SwingConstants.TOP); 34 | overlayPanel.setComponentMargin(0, 0, 0, overlay.getPreferredSize().width); 35 | return new GroupPanel(overlayPanel); 36 | } 37 | 38 | public static JSeparator createSeparator() { 39 | JSeparator sep = new JSeparator(); 40 | sep.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 41 | sep.setPreferredSize(new Dimension(5, 2)); 42 | return sep; 43 | } 44 | 45 | public static void fixUnicodeSupport() { 46 | WebLookAndFeel.globalControlFont = fixFont(WebLookAndFeel.globalControlFont); 47 | WebLookAndFeel.globalTooltipFont = fixFont(WebLookAndFeel.globalTooltipFont); 48 | WebLookAndFeel.globalAlertFont = fixFont(WebLookAndFeel.globalAlertFont); 49 | WebLookAndFeel.globalMenuFont = fixFont(WebLookAndFeel.globalMenuFont); 50 | WebLookAndFeel.globalAcceleratorFont = fixFont(WebLookAndFeel.globalAcceleratorFont); 51 | WebLookAndFeel.globalTitleFont = fixFont(WebLookAndFeel.globalTitleFont); 52 | WebLookAndFeel.globalTextFont = fixFont(WebLookAndFeel.globalTextFont); 53 | } 54 | 55 | private static Font fixFont(Font font) { 56 | return new Font(Font.SANS_SERIF, font.getStyle(), font.getSize()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/me/nov/cafebabe/utils/web/URLReader.java: -------------------------------------------------------------------------------- 1 | package me.nov.cafebabe.utils.web; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | 8 | public class URLReader { 9 | public static String getURLContent(String url) { 10 | try { 11 | URL website = new URL(url); 12 | HttpURLConnection connection = (HttpURLConnection) website.openConnection(); 13 | connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); 14 | connection.setConnectTimeout(4000); 15 | connection.setRequestMethod("GET"); 16 | connection.connect(); 17 | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); 18 | StringBuilder response = new StringBuilder(); 19 | String inputLine; 20 | while ((inputLine = in.readLine()) != null) 21 | response.append(inputLine); 22 | in.close(); 23 | return response.toString(); 24 | } catch (Exception e) { 25 | return null; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/ClassTooLargeException.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm; 29 | 30 | /** 31 | * Exception thrown when the constant pool of a class produced by a {@link ClassWriter} is too large. 32 | * 33 | * @author Jason Zaugg 34 | */ 35 | public final class ClassTooLargeException extends IndexOutOfBoundsException { 36 | private static final long serialVersionUID = 160715609518896765L; 37 | 38 | private final String className; 39 | private final int constantPoolCount; 40 | 41 | /** 42 | * Constructs a new {@link ClassTooLargeException}. 43 | * 44 | * @param className 45 | * the internal name of the class. 46 | * @param constantPoolCount 47 | * the number of constant pool items of the class. 48 | */ 49 | public ClassTooLargeException(final String className, final int constantPoolCount) { 50 | super("Class too large: " + className); 51 | this.className = className; 52 | this.constantPoolCount = constantPoolCount; 53 | } 54 | 55 | /** 56 | * Returns the internal name of the class. 57 | * 58 | * @return the internal name of the class. 59 | */ 60 | public String getClassName() { 61 | return className; 62 | } 63 | 64 | /** 65 | * Returns the number of constant pool items of the class. 66 | * 67 | * @return the number of constant pool items of the class. 68 | */ 69 | public int getConstantPoolCount() { 70 | return constantPoolCount; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/CurrentFrame.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package org.objectweb.asm; 30 | 31 | /** 32 | * Information about the input stack map frame at the "current" instruction of a method. This is implemented as a Frame subclass for a "basic block" containing only one instruction. 33 | * 34 | * @author Eric Bruneton 35 | */ 36 | final class CurrentFrame extends Frame { 37 | 38 | CurrentFrame(final Label owner) { 39 | super(owner); 40 | } 41 | 42 | /** 43 | * Sets this CurrentFrame to the input stack map frame of the next "current" instruction, i.e. the instruction just after the given one. It is assumed that the value of this object when this method is called is the stack map frame status just before the given instruction is executed. 44 | */ 45 | @Override 46 | void execute(final int opcode, final int arg, final Symbol symbolArg, final SymbolTable symbolTable) { 47 | super.execute(opcode, arg, symbolArg, symbolTable); 48 | Frame successor = new Frame(null); 49 | merge(symbolTable, successor, 0); 50 | copyFrom(successor); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/Edge.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm; 29 | 30 | /** 31 | * An edge in the control flow graph of a method. Each node of this graph is a basic block, represented with the Label corresponding to its first instruction. Each edge goes from one node to another, i.e. from one basic block to another (called the predecessor and successor blocks, respectively). An edge corresponds either to a jump or ret instruction or to an exception handler. 32 | * 33 | * @see Label 34 | * @author Eric Bruneton 35 | */ 36 | final class Edge { 37 | 38 | /** 39 | * A control flow graph edge corresponding to a jump or ret instruction. Only used with {@link ClassWriter#COMPUTE_FRAMES}. 40 | */ 41 | static final int JUMP = 0; 42 | 43 | /** 44 | * A control flow graph edge corresponding to an exception handler. Only used with {@link ClassWriter#COMPUTE_MAXS}. 45 | */ 46 | static final int EXCEPTION = 0x7FFFFFFF; 47 | 48 | /** 49 | * Information about this control flow graph edge. 50 | * 51 | *

    52 | *
  • If {@link ClassWriter#COMPUTE_MAXS} is used, this field contains either a stack size delta (for an edge corresponding to a jump instruction), or the value EXCEPTION (for an edge corresponding to an exception handler). The stack size delta is the stack size just after the jump instruction, minus the stack size at the beginning of the predecessor basic block, i.e. the one containing the jump instruction. 53 | *
  • If {@link ClassWriter#COMPUTE_FRAMES} is used, this field contains either the value JUMP (for an edge corresponding to a jump instruction), or the index, in the {@link ClassWriter} type table, of the exception type that is handled (for an edge corresponding to an exception handler). 54 | *
55 | */ 56 | final int info; 57 | 58 | /** The successor block of this control flow graph edge. */ 59 | final Label successor; 60 | 61 | /** 62 | * The next edge in the list of outgoing edges of a basic block. See {@link Label#outgoingEdges}. 63 | */ 64 | Edge nextEdge; 65 | 66 | /** 67 | * Constructs a new Edge. 68 | * 69 | * @param info 70 | * see {@link #info}. 71 | * @param successor 72 | * see {@link #successor}. 73 | * @param nextEdge 74 | * see {@link #nextEdge}. 75 | */ 76 | Edge(final int info, final Label successor, final Edge nextEdge) { 77 | this.info = info; 78 | this.successor = successor; 79 | this.nextEdge = nextEdge; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/MethodTooLargeException.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm; 29 | 30 | /** 31 | * Exception thrown when the Code attribute of a method produced by a {@link ClassWriter} is too large. 32 | * 33 | * @author Jason Zaugg 34 | */ 35 | public final class MethodTooLargeException extends IndexOutOfBoundsException { 36 | private static final long serialVersionUID = 6807380416709738314L; 37 | 38 | private final String className; 39 | private final String methodName; 40 | private final String descriptor; 41 | private final int codeSize; 42 | 43 | /** 44 | * Constructs a new {@link MethodTooLargeException}. 45 | * 46 | * @param className 47 | * the internal name of the owner class. 48 | * @param methodName 49 | * the name of the method. 50 | * @param descriptor 51 | * the descriptor of the method. 52 | * @param codeSize 53 | * the size of the method's Code attribute, in bytes. 54 | */ 55 | public MethodTooLargeException(final String className, final String methodName, final String descriptor, 56 | final int codeSize) { 57 | super("Method too large: " + className + "." + methodName + " " + descriptor); 58 | this.className = className; 59 | this.methodName = methodName; 60 | this.descriptor = descriptor; 61 | this.codeSize = codeSize; 62 | } 63 | 64 | /** 65 | * Returns the internal name of the owner class. 66 | * 67 | * @return the internal name of the owner class. 68 | */ 69 | public String getClassName() { 70 | return className; 71 | } 72 | 73 | /** 74 | * Returns the name of the method. 75 | * 76 | * @return the name of the method. 77 | */ 78 | public String getMethodName() { 79 | return methodName; 80 | } 81 | 82 | /** 83 | * Returns the descriptor of the method. 84 | * 85 | * @return the descriptor of the method. 86 | */ 87 | public String getDescriptor() { 88 | return descriptor; 89 | } 90 | 91 | /** 92 | * Returns the size of the method's Code attribute, in bytes. 93 | * 94 | * @return the size of the method's Code attribute, in bytes. 95 | */ 96 | public int getCodeSize() { 97 | return codeSize; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides a small and fast bytecode manipulation framework. 33 | 34 |

35 | The ASM framework is organized 36 | around the {@link org.objectweb.asm.ClassVisitor ClassVisitor}, 37 | {@link org.objectweb.asm.FieldVisitor FieldVisitor}, 38 | {@link org.objectweb.asm.MethodVisitor MethodVisitor} and 39 | {@link org.objectweb.asm.AnnotationVisitor AnnotationVisitor} abstract classes, 40 | which allow one to visit the fields, methods and annotations of a class, 41 | including the bytecode instructions of each method. 42 | 43 |

44 | In addition to these main abstract classes, ASM provides a {@link 45 | org.objectweb.asm.ClassReader ClassReader} class, that can parse an 46 | existing class and make a given visitor visit it. ASM also provides 47 | a {@link org.objectweb.asm.ClassWriter ClassWriter} class, which is 48 | a visitor that generates Java class files. 49 | 50 |

51 | In order to generate a class from scratch, only the {@link 52 | org.objectweb.asm.ClassWriter ClassWriter} class is necessary. Indeed, 53 | in order to generate a class, one must just call its visitXxx 54 | methods with the appropriate arguments to generate the desired fields 55 | and methods. 56 | 57 |

58 | In order to modify existing classes, one must use a {@link 59 | org.objectweb.asm.ClassReader ClassReader} class to analyze 60 | the original class, a class modifier, and a {@link org.objectweb.asm.ClassWriter 61 | ClassWriter} to construct the modified class. The class modifier 62 | is just a {@link org.objectweb.asm.ClassVisitor ClassVisitor} 63 | that delegates most of the work to another {@link org.objectweb.asm.ClassVisitor 64 | ClassVisitor}, but that sometimes changes some parameter values, 65 | or call additional methods, in order to implement the desired 66 | modification process. In order to make it easier to implement such 67 | class modifiers, the {@link org.objectweb.asm.ClassVisitor 68 | ClassVisitor} and {@link org.objectweb.asm.MethodVisitor MethodVisitor} 69 | classes delegate by default all the method calls they receive to an 70 | optional visitor. 71 | 72 | @since ASM 1.3 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/signature/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides support for type signatures. 33 | 34 | @since ASM 2.0 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/FieldInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a field instruction. A field instruction is an instruction that loads or stores the value of a field of an object. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class FieldInsnNode extends AbstractInsnNode { 39 | 40 | /** 41 | * The internal name of the field's owner class (see {@link org.objectweb.asm.Type#getInternalName}). 42 | */ 43 | public String owner; 44 | 45 | /** The field's name. */ 46 | public String name; 47 | 48 | /** The field's descriptor (see {@link org.objectweb.asm.Type}). */ 49 | public String desc; 50 | 51 | /** 52 | * Constructs a new {@link FieldInsnNode}. 53 | * 54 | * @param opcode 55 | * the opcode of the type instruction to be constructed. This opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. 56 | * @param owner 57 | * the internal name of the field's owner class (see {@link org.objectweb.asm.Type#getInternalName}). 58 | * @param name 59 | * the field's name. 60 | * @param descriptor 61 | * the field's descriptor (see {@link org.objectweb.asm.Type}). 62 | */ 63 | public FieldInsnNode(final int opcode, final String owner, final String name, final String descriptor) { 64 | super(opcode); 65 | this.owner = owner; 66 | this.name = name; 67 | this.desc = descriptor; 68 | } 69 | 70 | /** 71 | * Sets the opcode of this instruction. 72 | * 73 | * @param opcode 74 | * the new instruction opcode. This opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. 75 | */ 76 | public void setOpcode(final int opcode) { 77 | this.opcode = opcode; 78 | } 79 | 80 | @Override 81 | public int getType() { 82 | return FIELD_INSN; 83 | } 84 | 85 | @Override 86 | public void accept(final MethodVisitor methodVisitor) { 87 | methodVisitor.visitFieldInsn(opcode, owner, name, desc); 88 | acceptAnnotations(methodVisitor); 89 | } 90 | 91 | @Override 92 | public AbstractInsnNode clone(final Map clonedLabels) { 93 | return new FieldInsnNode(opcode, owner, name, desc).cloneAnnotations(this); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/IincInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | import org.objectweb.asm.Opcodes; 33 | 34 | /** 35 | * A node that represents an IINC instruction. 36 | * 37 | * @author Eric Bruneton 38 | */ 39 | public class IincInsnNode extends AbstractInsnNode { 40 | 41 | /** Index of the local variable to be incremented. */ 42 | public int var; 43 | 44 | /** Amount to increment the local variable by. */ 45 | public int incr; 46 | 47 | /** 48 | * Constructs a new {@link IincInsnNode}. 49 | * 50 | * @param var 51 | * index of the local variable to be incremented. 52 | * @param incr 53 | * increment amount to increment the local variable by. 54 | */ 55 | public IincInsnNode(final int var, final int incr) { 56 | super(Opcodes.IINC); 57 | this.var = var; 58 | this.incr = incr; 59 | } 60 | 61 | @Override 62 | public int getType() { 63 | return IINC_INSN; 64 | } 65 | 66 | @Override 67 | public void accept(final MethodVisitor methodVisitor) { 68 | methodVisitor.visitIincInsn(var, incr); 69 | acceptAnnotations(methodVisitor); 70 | } 71 | 72 | @Override 73 | public AbstractInsnNode clone(final Map clonedLabels) { 74 | return new IincInsnNode(var, incr).cloneAnnotations(this); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/InnerClassNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import org.objectweb.asm.ClassVisitor; 31 | 32 | /** 33 | * A node that represents an inner class. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | public class InnerClassNode { 38 | 39 | /** The internal name of an inner class (see {@link org.objectweb.asm.Type#getInternalName()}). */ 40 | public String name; 41 | 42 | /** 43 | * The internal name of the class to which the inner class belongs (see {@link org.objectweb.asm.Type#getInternalName()}). May be {@literal null}. 44 | */ 45 | public String outerName; 46 | 47 | /** 48 | * The (simple) name of the inner class inside its enclosing class. May be {@literal null} for anonymous inner classes. 49 | */ 50 | public String innerName; 51 | 52 | /** The access flags of the inner class as originally declared in the enclosing class. */ 53 | public int access; 54 | 55 | /** 56 | * Constructs a new {@link InnerClassNode}. 57 | * 58 | * @param name 59 | * the internal name of an inner class (see {@link org.objectweb.asm.Type#getInternalName()}). 60 | * @param outerName 61 | * the internal name of the class to which the inner class belongs (see {@link org.objectweb.asm.Type#getInternalName()}). May be {@literal null}. 62 | * @param innerName 63 | * the (simple) name of the inner class inside its enclosing class. May be {@literal null} for anonymous inner classes. 64 | * @param access 65 | * the access flags of the inner class as originally declared in the enclosing class. 66 | */ 67 | public InnerClassNode(final String name, final String outerName, final String innerName, final int access) { 68 | this.name = name; 69 | this.outerName = outerName; 70 | this.innerName = innerName; 71 | this.access = access; 72 | } 73 | 74 | /** 75 | * Makes the given class visitor visit this inner class. 76 | * 77 | * @param classVisitor 78 | * a class visitor. 79 | */ 80 | public void accept(final ClassVisitor classVisitor) { 81 | classVisitor.visitInnerClass(name, outerName, innerName, access); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/InsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a zero operand instruction. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class InsnNode extends AbstractInsnNode { 39 | 40 | /** 41 | * Constructs a new {@link InsnNode}. 42 | * 43 | * @param opcode 44 | * the opcode of the instruction to be constructed. This opcode must be NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT. 45 | */ 46 | public InsnNode(final int opcode) { 47 | super(opcode); 48 | } 49 | 50 | @Override 51 | public int getType() { 52 | return INSN; 53 | } 54 | 55 | @Override 56 | public void accept(final MethodVisitor methodVisitor) { 57 | methodVisitor.visitInsn(opcode); 58 | acceptAnnotations(methodVisitor); 59 | } 60 | 61 | @Override 62 | public AbstractInsnNode clone(final Map clonedLabels) { 63 | return new InsnNode(opcode).cloneAnnotations(this); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/IntInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents an instruction with a single int operand. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class IntInsnNode extends AbstractInsnNode { 39 | 40 | /** The operand of this instruction. */ 41 | public int operand; 42 | 43 | /** 44 | * Constructs a new {@link IntInsnNode}. 45 | * 46 | * @param opcode 47 | * the opcode of the instruction to be constructed. This opcode must be BIPUSH, SIPUSH or NEWARRAY. 48 | * @param operand 49 | * the operand of the instruction to be constructed. 50 | */ 51 | public IntInsnNode(final int opcode, final int operand) { 52 | super(opcode); 53 | this.operand = operand; 54 | } 55 | 56 | /** 57 | * Sets the opcode of this instruction. 58 | * 59 | * @param opcode 60 | * the new instruction opcode. This opcode must be BIPUSH, SIPUSH or NEWARRAY. 61 | */ 62 | public void setOpcode(final int opcode) { 63 | this.opcode = opcode; 64 | } 65 | 66 | @Override 67 | public int getType() { 68 | return INT_INSN; 69 | } 70 | 71 | @Override 72 | public void accept(final MethodVisitor methodVisitor) { 73 | methodVisitor.visitIntInsn(opcode, operand); 74 | acceptAnnotations(methodVisitor); 75 | } 76 | 77 | @Override 78 | public AbstractInsnNode clone(final Map clonedLabels) { 79 | return new IntInsnNode(opcode, operand).cloneAnnotations(this); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/InvokeDynamicInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.Handle; 32 | import org.objectweb.asm.MethodVisitor; 33 | import org.objectweb.asm.Opcodes; 34 | 35 | /** 36 | * A node that represents an invokedynamic instruction. 37 | * 38 | * @author Remi Forax 39 | */ 40 | public class InvokeDynamicInsnNode extends AbstractInsnNode { 41 | 42 | /** The method's name. */ 43 | public String name; 44 | 45 | /** The method's descriptor (see {@link org.objectweb.asm.Type}). */ 46 | public String desc; 47 | 48 | /** The bootstrap method. */ 49 | public Handle bsm; 50 | 51 | /** The bootstrap method constant arguments. */ 52 | public Object[] bsmArgs; 53 | 54 | /** 55 | * Constructs a new {@link InvokeDynamicInsnNode}. 56 | * 57 | * @param name 58 | * the method's name. 59 | * @param descriptor 60 | * the method's descriptor (see {@link org.objectweb.asm.Type}). 61 | * @param bootstrapMethodHandle 62 | * the bootstrap method. 63 | * @param bootstrapMethodArguments 64 | * the bootstrap method constant arguments. Each argument must be an {@link Integer}, {@link Float}, {@link Long}, {@link Double}, {@link String}, {@link org.objectweb.asm.Type} or {@link Handle} value. This method is allowed to modify the content of the array so a caller should expect that this array may change. 65 | */ 66 | public InvokeDynamicInsnNode(final String name, final String descriptor, final Handle bootstrapMethodHandle, 67 | final Object... bootstrapMethodArguments) { // NOPMD(ArrayIsStoredDirectly): public field. 68 | super(Opcodes.INVOKEDYNAMIC); 69 | this.name = name; 70 | this.desc = descriptor; 71 | this.bsm = bootstrapMethodHandle; 72 | this.bsmArgs = bootstrapMethodArguments; 73 | } 74 | 75 | @Override 76 | public int getType() { 77 | return INVOKE_DYNAMIC_INSN; 78 | } 79 | 80 | @Override 81 | public void accept(final MethodVisitor methodVisitor) { 82 | methodVisitor.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 83 | acceptAnnotations(methodVisitor); 84 | } 85 | 86 | @Override 87 | public AbstractInsnNode clone(final Map clonedLabels) { 88 | return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs).cloneAnnotations(this); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/JumpInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a jump instruction. A jump instruction is an instruction that may jump to another instruction. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class JumpInsnNode extends AbstractInsnNode { 39 | 40 | /** 41 | * The operand of this instruction. This operand is a label that designates the instruction to which this instruction may jump. 42 | */ 43 | public LabelNode label; 44 | 45 | /** 46 | * Constructs a new {@link JumpInsnNode}. 47 | * 48 | * @param opcode 49 | * the opcode of the type instruction to be constructed. This opcode must be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. 50 | * @param label 51 | * the operand of the instruction to be constructed. This operand is a label that designates the instruction to which the jump instruction may jump. 52 | */ 53 | public JumpInsnNode(final int opcode, final LabelNode label) { 54 | super(opcode); 55 | this.label = label; 56 | } 57 | 58 | /** 59 | * Sets the opcode of this instruction. 60 | * 61 | * @param opcode 62 | * the new instruction opcode. This opcode must be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. 63 | */ 64 | public void setOpcode(final int opcode) { 65 | this.opcode = opcode; 66 | } 67 | 68 | @Override 69 | public int getType() { 70 | return JUMP_INSN; 71 | } 72 | 73 | @Override 74 | public void accept(final MethodVisitor methodVisitor) { 75 | methodVisitor.visitJumpInsn(opcode, label.getLabel()); 76 | acceptAnnotations(methodVisitor); 77 | } 78 | 79 | @Override 80 | public AbstractInsnNode clone(final Map clonedLabels) { 81 | return new JumpInsnNode(opcode, clone(label, clonedLabels)).cloneAnnotations(this); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LabelNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.Label; 32 | import org.objectweb.asm.MethodVisitor; 33 | 34 | /** An {@link AbstractInsnNode} that encapsulates a {@link Label}. */ 35 | public class LabelNode extends AbstractInsnNode { 36 | 37 | private Label value; 38 | 39 | public LabelNode() { 40 | super(-1); 41 | } 42 | 43 | public LabelNode(final Label label) { 44 | super(-1); 45 | this.value = label; 46 | } 47 | 48 | @Override 49 | public int getType() { 50 | return LABEL; 51 | } 52 | 53 | /** 54 | * Returns the label encapsulated by this node. A new label is created and associated with this node if it was created without an encapsulated label. 55 | * 56 | * @return the label encapsulated by this node. 57 | */ 58 | public Label getLabel() { 59 | if (value == null) { 60 | value = new Label(); 61 | } 62 | return value; 63 | } 64 | 65 | @Override 66 | public void accept(final MethodVisitor methodVisitor) { 67 | methodVisitor.visitLabel(getLabel()); 68 | } 69 | 70 | @Override 71 | public AbstractInsnNode clone(final Map clonedLabels) { 72 | return clonedLabels.get(this); 73 | } 74 | 75 | public void resetLabel() { 76 | value = null; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LdcInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | import org.objectweb.asm.Opcodes; 33 | 34 | /** 35 | * A node that represents an LDC instruction. 36 | * 37 | * @author Eric Bruneton 38 | */ 39 | public class LdcInsnNode extends AbstractInsnNode { 40 | 41 | /** 42 | * The constant to be loaded on the stack. This parameter must be a non null {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double}, a {@link String} or a {@link org.objectweb.asm.Type}. 43 | */ 44 | public Object cst; 45 | 46 | /** 47 | * Constructs a new {@link LdcInsnNode}. 48 | * 49 | * @param value 50 | * the constant to be loaded on the stack. This parameter must be a non null {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double} or a {@link String}. 51 | */ 52 | public LdcInsnNode(final Object value) { 53 | super(Opcodes.LDC); 54 | this.cst = value; 55 | } 56 | 57 | @Override 58 | public int getType() { 59 | return LDC_INSN; 60 | } 61 | 62 | @Override 63 | public void accept(final MethodVisitor methodVisitor) { 64 | methodVisitor.visitLdcInsn(cst); 65 | acceptAnnotations(methodVisitor); 66 | } 67 | 68 | @Override 69 | public AbstractInsnNode clone(final Map clonedLabels) { 70 | return new LdcInsnNode(cst).cloneAnnotations(this); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LineNumberNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a line number declaration. These nodes are pseudo instruction nodes in order to be inserted in an instruction list. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class LineNumberNode extends AbstractInsnNode { 39 | 40 | /** A line number. This number refers to the source file from which the class was compiled. */ 41 | public int line; 42 | 43 | /** The first instruction corresponding to this line number. */ 44 | public LabelNode start; 45 | 46 | /** 47 | * Constructs a new {@link LineNumberNode}. 48 | * 49 | * @param line 50 | * a line number. This number refers to the source file from which the class was compiled. 51 | * @param start 52 | * the first instruction corresponding to this line number. 53 | */ 54 | public LineNumberNode(final int line, final LabelNode start) { 55 | super(-1); 56 | this.line = line; 57 | this.start = start; 58 | } 59 | 60 | @Override 61 | public int getType() { 62 | return LINE; 63 | } 64 | 65 | @Override 66 | public void accept(final MethodVisitor methodVisitor) { 67 | methodVisitor.visitLineNumber(line, start.getLabel()); 68 | } 69 | 70 | @Override 71 | public AbstractInsnNode clone(final Map clonedLabels) { 72 | return new LineNumberNode(line, clone(start, clonedLabels)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LocalVariableNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import org.objectweb.asm.MethodVisitor; 31 | 32 | /** 33 | * A node that represents a local variable declaration. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | public class LocalVariableNode { 38 | 39 | /** The name of a local variable. */ 40 | public String name; 41 | 42 | /** The type descriptor of this local variable. */ 43 | public String desc; 44 | 45 | /** The signature of this local variable. May be {@literal null}. */ 46 | public String signature; 47 | 48 | /** The first instruction corresponding to the scope of this local variable (inclusive). */ 49 | public LabelNode start; 50 | 51 | /** The last instruction corresponding to the scope of this local variable (exclusive). */ 52 | public LabelNode end; 53 | 54 | /** The local variable's index. */ 55 | public int index; 56 | 57 | /** 58 | * Constructs a new {@link LocalVariableNode}. 59 | * 60 | * @param name 61 | * the name of a local variable. 62 | * @param descriptor 63 | * the type descriptor of this local variable. 64 | * @param signature 65 | * the signature of this local variable. May be {@literal null}. 66 | * @param start 67 | * the first instruction corresponding to the scope of this local variable (inclusive). 68 | * @param end 69 | * the last instruction corresponding to the scope of this local variable (exclusive). 70 | * @param index 71 | * the local variable's index. 72 | */ 73 | public LocalVariableNode(final String name, final String descriptor, final String signature, final LabelNode start, 74 | final LabelNode end, final int index) { 75 | this.name = name; 76 | this.desc = descriptor; 77 | this.signature = signature; 78 | this.start = start; 79 | this.end = end; 80 | this.index = index; 81 | } 82 | 83 | /** 84 | * Makes the given visitor visit this local variable declaration. 85 | * 86 | * @param methodVisitor 87 | * a method visitor. 88 | */ 89 | public void accept(final MethodVisitor methodVisitor) { 90 | methodVisitor.visitLocalVariable(name, desc, signature, start.getLabel(), end.getLabel(), index); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/LookupSwitchInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.List; 31 | import java.util.Map; 32 | import org.objectweb.asm.Label; 33 | import org.objectweb.asm.MethodVisitor; 34 | import org.objectweb.asm.Opcodes; 35 | 36 | /** 37 | * A node that represents a LOOKUPSWITCH instruction. 38 | * 39 | * @author Eric Bruneton 40 | */ 41 | public class LookupSwitchInsnNode extends AbstractInsnNode { 42 | 43 | /** Beginning of the default handler block. */ 44 | public LabelNode dflt; 45 | 46 | /** The values of the keys. */ 47 | public List keys; 48 | 49 | /** Beginnings of the handler blocks. */ 50 | public List labels; 51 | 52 | /** 53 | * Constructs a new {@link LookupSwitchInsnNode}. 54 | * 55 | * @param dflt 56 | * beginning of the default handler block. 57 | * @param keys 58 | * the values of the keys. 59 | * @param labels 60 | * beginnings of the handler blocks. {@code labels[i]} is the beginning of the handler block for the {@code keys[i]} key. 61 | */ 62 | public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) { 63 | super(Opcodes.LOOKUPSWITCH); 64 | this.dflt = dflt; 65 | this.keys = Util.asArrayList(keys); 66 | this.labels = Util.asArrayList(labels); 67 | } 68 | 69 | @Override 70 | public int getType() { 71 | return LOOKUPSWITCH_INSN; 72 | } 73 | 74 | @Override 75 | public void accept(final MethodVisitor methodVisitor) { 76 | int[] keysArray = new int[this.keys.size()]; 77 | for (int i = 0, n = keysArray.length; i < n; ++i) { 78 | keysArray[i] = this.keys.get(i).intValue(); 79 | } 80 | Label[] labelsArray = new Label[this.labels.size()]; 81 | for (int i = 0, n = labelsArray.length; i < n; ++i) { 82 | labelsArray[i] = this.labels.get(i).getLabel(); 83 | } 84 | methodVisitor.visitLookupSwitchInsn(dflt.getLabel(), keysArray, labelsArray); 85 | acceptAnnotations(methodVisitor); 86 | } 87 | 88 | @Override 89 | public AbstractInsnNode clone(final Map clonedLabels) { 90 | LookupSwitchInsnNode clone = new LookupSwitchInsnNode(clone(dflt, clonedLabels), null, clone(labels, clonedLabels)); 91 | clone.keys.addAll(keys); 92 | return clone.cloneAnnotations(this); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ModuleExportNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.List; 31 | import org.objectweb.asm.ModuleVisitor; 32 | 33 | /** 34 | * A node that represents an exported package with its name and the module that can access to it. 35 | * 36 | * @author Remi Forax 37 | */ 38 | public class ModuleExportNode { 39 | 40 | /** The internal name of the exported package. */ 41 | public String packaze; 42 | 43 | /** 44 | * The access flags (see {@link org.objectweb.asm.Opcodes}). Valid values are {@code 45 | * ACC_SYNTHETIC} and {@code ACC_MANDATED}. 46 | */ 47 | public int access; 48 | 49 | /** 50 | * The list of modules that can access this exported package, specified with fully qualified names (using dots). May be {@literal null}. 51 | */ 52 | public List modules; 53 | 54 | /** 55 | * Constructs a new {@link ModuleExportNode}. 56 | * 57 | * @param packaze 58 | * the internal name of the exported package. 59 | * @param access 60 | * the package access flags, one or more of {@code ACC_SYNTHETIC} and {@code 61 | * ACC_MANDATED}. 62 | * @param modules 63 | * a list of modules that can access this exported package, specified with fully qualified names (using dots). 64 | */ 65 | public ModuleExportNode(final String packaze, final int access, final List modules) { 66 | this.packaze = packaze; 67 | this.access = access; 68 | this.modules = modules; 69 | } 70 | 71 | /** 72 | * Makes the given module visitor visit this export declaration. 73 | * 74 | * @param moduleVisitor 75 | * a module visitor. 76 | */ 77 | public void accept(final ModuleVisitor moduleVisitor) { 78 | moduleVisitor.visitExport(packaze, access, modules == null ? null : modules.toArray(new String[0])); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ModuleOpenNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.List; 31 | import org.objectweb.asm.ModuleVisitor; 32 | 33 | /** 34 | * A node that represents an opened package with its name and the module that can access it. 35 | * 36 | * @author Remi Forax 37 | */ 38 | public class ModuleOpenNode { 39 | 40 | /** The internal name of the opened package. */ 41 | public String packaze; 42 | 43 | /** 44 | * The access flag of the opened package, valid values are among {@code ACC_SYNTHETIC} and {@code 45 | * ACC_MANDATED}. 46 | */ 47 | public int access; 48 | 49 | /** 50 | * The fully qualified names (using dots) of the modules that can use deep reflection to the classes of the open package, or {@literal null}. 51 | */ 52 | public List modules; 53 | 54 | /** 55 | * Constructs a new {@link ModuleOpenNode}. 56 | * 57 | * @param packaze 58 | * the internal name of the opened package. 59 | * @param access 60 | * the access flag of the opened package, valid values are among {@code 61 | * ACC_SYNTHETIC} and {@code ACC_MANDATED}. 62 | * @param modules 63 | * the fully qualified names (using dots) of the modules that can use deep reflection to the classes of the open package, or {@literal null}. 64 | */ 65 | public ModuleOpenNode(final String packaze, final int access, final List modules) { 66 | this.packaze = packaze; 67 | this.access = access; 68 | this.modules = modules; 69 | } 70 | 71 | /** 72 | * Makes the given module visitor visit this opened package. 73 | * 74 | * @param moduleVisitor 75 | * a module visitor. 76 | */ 77 | public void accept(final ModuleVisitor moduleVisitor) { 78 | moduleVisitor.visitOpen(packaze, access, modules == null ? null : modules.toArray(new String[0])); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ModuleProvideNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.List; 31 | import org.objectweb.asm.ModuleVisitor; 32 | 33 | /** 34 | * A node that represents a service and its implementation provided by the current module. 35 | * 36 | * @author Remi Forax 37 | */ 38 | public class ModuleProvideNode { 39 | 40 | /** The internal name of the service. */ 41 | public String service; 42 | 43 | /** The internal names of the implementations of the service (there is at least one provider). */ 44 | public List providers; 45 | 46 | /** 47 | * Constructs a new {@link ModuleProvideNode}. 48 | * 49 | * @param service 50 | * the internal name of the service. 51 | * @param providers 52 | * the internal names of the implementations of the service (there is at least one provider). 53 | */ 54 | public ModuleProvideNode(final String service, final List providers) { 55 | this.service = service; 56 | this.providers = providers; 57 | } 58 | 59 | /** 60 | * Makes the given module visitor visit this require declaration. 61 | * 62 | * @param moduleVisitor 63 | * a module visitor. 64 | */ 65 | public void accept(final ModuleVisitor moduleVisitor) { 66 | moduleVisitor.visitProvide(service, providers.toArray(new String[0])); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ModuleRequireNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import org.objectweb.asm.ModuleVisitor; 31 | 32 | /** 33 | * A node that represents a required module with its name and access of a module descriptor. 34 | * 35 | * @author Remi Forax 36 | */ 37 | public class ModuleRequireNode { 38 | 39 | /** The fully qualified name (using dots) of the dependence. */ 40 | public String module; 41 | 42 | /** 43 | * The access flag of the dependence among {@code ACC_TRANSITIVE}, {@code ACC_STATIC_PHASE}, {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. 44 | */ 45 | public int access; 46 | 47 | /** The module version at compile time, or {@literal null}. */ 48 | public String version; 49 | 50 | /** 51 | * Constructs a new {@link ModuleRequireNode}. 52 | * 53 | * @param module 54 | * the fully qualified name (using dots) of the dependence. 55 | * @param access 56 | * the access flag of the dependence among {@code ACC_TRANSITIVE}, {@code 57 | * ACC_STATIC_PHASE}, {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. 58 | * @param version 59 | * the module version at compile time, or {@literal null}. 60 | */ 61 | public ModuleRequireNode(final String module, final int access, final String version) { 62 | this.module = module; 63 | this.access = access; 64 | this.version = version; 65 | } 66 | 67 | /** 68 | * Makes the given module visitor visit this require directive. 69 | * 70 | * @param moduleVisitor 71 | * a module visitor. 72 | */ 73 | public void accept(final ModuleVisitor moduleVisitor) { 74 | moduleVisitor.visitRequire(module, access, version); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/MultiANewArrayInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | import org.objectweb.asm.Opcodes; 33 | 34 | /** 35 | * A node that represents a MULTIANEWARRAY instruction. 36 | * 37 | * @author Eric Bruneton 38 | */ 39 | public class MultiANewArrayInsnNode extends AbstractInsnNode { 40 | 41 | /** An array type descriptor (see {@link org.objectweb.asm.Type}). */ 42 | public String desc; 43 | 44 | /** Number of dimensions of the array to allocate. */ 45 | public int dims; 46 | 47 | /** 48 | * Constructs a new {@link MultiANewArrayInsnNode}. 49 | * 50 | * @param descriptor 51 | * an array type descriptor (see {@link org.objectweb.asm.Type}). 52 | * @param numDimensions 53 | * the number of dimensions of the array to allocate. 54 | */ 55 | public MultiANewArrayInsnNode(final String descriptor, final int numDimensions) { 56 | super(Opcodes.MULTIANEWARRAY); 57 | this.desc = descriptor; 58 | this.dims = numDimensions; 59 | } 60 | 61 | @Override 62 | public int getType() { 63 | return MULTIANEWARRAY_INSN; 64 | } 65 | 66 | @Override 67 | public void accept(final MethodVisitor methodVisitor) { 68 | methodVisitor.visitMultiANewArrayInsn(desc, dims); 69 | acceptAnnotations(methodVisitor); 70 | } 71 | 72 | @Override 73 | public AbstractInsnNode clone(final Map clonedLabels) { 74 | return new MultiANewArrayInsnNode(desc, dims).cloneAnnotations(this); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/ParameterNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import org.objectweb.asm.MethodVisitor; 31 | 32 | /** 33 | * A node that represents a parameter of a method. 34 | * 35 | * @author Remi Forax 36 | */ 37 | public class ParameterNode { 38 | 39 | /** The parameter's name. */ 40 | public String name; 41 | 42 | /** 43 | * The parameter's access flags (see {@link org.objectweb.asm.Opcodes}). Valid values are {@code 44 | * ACC_FINAL}, {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. 45 | */ 46 | public int access; 47 | 48 | /** 49 | * Constructs a new {@link ParameterNode}. 50 | * 51 | * @param access 52 | * The parameter's access flags. Valid values are {@code ACC_FINAL}, {@code 53 | * ACC_SYNTHETIC} or/and {@code ACC_MANDATED} (see {@link org.objectweb.asm.Opcodes}). 54 | * @param name 55 | * the parameter's name. 56 | */ 57 | public ParameterNode(final String name, final int access) { 58 | this.name = name; 59 | this.access = access; 60 | } 61 | 62 | /** 63 | * Makes the given visitor visit this parameter declaration. 64 | * 65 | * @param methodVisitor 66 | * a method visitor. 67 | */ 68 | public void accept(final MethodVisitor methodVisitor) { 69 | methodVisitor.visitParameter(name, access); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/TableSwitchInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.List; 31 | import java.util.Map; 32 | import org.objectweb.asm.Label; 33 | import org.objectweb.asm.MethodVisitor; 34 | import org.objectweb.asm.Opcodes; 35 | 36 | /** 37 | * A node that represents a TABLESWITCH instruction. 38 | * 39 | * @author Eric Bruneton 40 | */ 41 | public class TableSwitchInsnNode extends AbstractInsnNode { 42 | 43 | /** The minimum key value. */ 44 | public int min; 45 | 46 | /** The maximum key value. */ 47 | public int max; 48 | 49 | /** Beginning of the default handler block. */ 50 | public LabelNode dflt; 51 | 52 | /** Beginnings of the handler blocks. This list is a list of {@link LabelNode} objects. */ 53 | public List labels; 54 | 55 | /** 56 | * Constructs a new {@link TableSwitchInsnNode}. 57 | * 58 | * @param min 59 | * the minimum key value. 60 | * @param max 61 | * the maximum key value. 62 | * @param dflt 63 | * beginning of the default handler block. 64 | * @param labels 65 | * beginnings of the handler blocks. {@code labels[i]} is the beginning of the handler block for the {@code min + i} key. 66 | */ 67 | public TableSwitchInsnNode(final int min, final int max, final LabelNode dflt, final LabelNode... labels) { 68 | super(Opcodes.TABLESWITCH); 69 | this.min = min; 70 | this.max = max; 71 | this.dflt = dflt; 72 | this.labels = Util.asArrayList(labels); 73 | } 74 | 75 | @Override 76 | public int getType() { 77 | return TABLESWITCH_INSN; 78 | } 79 | 80 | @Override 81 | public void accept(final MethodVisitor methodVisitor) { 82 | Label[] labelsArray = new Label[this.labels.size()]; 83 | for (int i = 0, n = labelsArray.length; i < n; ++i) { 84 | labelsArray[i] = this.labels.get(i).getLabel(); 85 | } 86 | methodVisitor.visitTableSwitchInsn(min, max, dflt.getLabel(), labelsArray); 87 | acceptAnnotations(methodVisitor); 88 | } 89 | 90 | @Override 91 | public AbstractInsnNode clone(final Map clonedLabels) { 92 | return new TableSwitchInsnNode(min, max, clone(dflt, clonedLabels), clone(labels, clonedLabels)) 93 | .cloneAnnotations(this); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/TypeAnnotationNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import org.objectweb.asm.Opcodes; 31 | import org.objectweb.asm.TypePath; 32 | 33 | /** 34 | * A node that represents a type annotation. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class TypeAnnotationNode extends AnnotationNode { 39 | 40 | /** A reference to the annotated type. See {@link org.objectweb.asm.TypeReference}. */ 41 | public int typeRef; 42 | 43 | /** 44 | * The path to the annotated type argument, wildcard bound, array element type, or static outer type within the referenced type. May be {@literal null} if the annotation targets 'typeRef' as a whole. 45 | */ 46 | public TypePath typePath; 47 | 48 | /** 49 | * Constructs a new {@link AnnotationNode}. Subclasses must not use this constructor. Instead, they must use the {@link #TypeAnnotationNode(int, int, TypePath, String)} version. 50 | * 51 | * @param typeRef 52 | * a reference to the annotated type. See {@link org.objectweb.asm.TypeReference}. 53 | * @param typePath 54 | * the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be {@literal null} if the annotation targets 'typeRef' as a whole. 55 | * @param descriptor 56 | * the class descriptor of the annotation class. 57 | * @throws IllegalStateException 58 | * If a subclass calls this constructor. 59 | */ 60 | public TypeAnnotationNode(final int typeRef, final TypePath typePath, final String descriptor) { 61 | this(Opcodes.ASM7, typeRef, typePath, descriptor); 62 | if (getClass() != TypeAnnotationNode.class) { 63 | throw new IllegalStateException(); 64 | } 65 | } 66 | 67 | /** 68 | * Constructs a new {@link AnnotationNode}. 69 | * 70 | * @param api 71 | * the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}. 72 | * @param typeRef 73 | * a reference to the annotated type. See {@link org.objectweb.asm.TypeReference}. 74 | * @param typePath 75 | * the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be {@literal null} if the annotation targets 'typeRef' as a whole. 76 | * @param descriptor 77 | * the class descriptor of the annotation class. 78 | */ 79 | public TypeAnnotationNode(final int api, final int typeRef, final TypePath typePath, final String descriptor) { 80 | super(api, descriptor); 81 | this.typeRef = typeRef; 82 | this.typePath = typePath; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/TypeInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a type instruction. A type instruction is an instruction that takes a type descriptor as parameter. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class TypeInsnNode extends AbstractInsnNode { 39 | 40 | /** 41 | * The operand of this instruction. This operand is an internal name (see {@link org.objectweb.asm.Type}). 42 | */ 43 | public String desc; 44 | 45 | /** 46 | * Constructs a new {@link TypeInsnNode}. 47 | * 48 | * @param opcode 49 | * the opcode of the type instruction to be constructed. This opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. 50 | * @param descriptor 51 | * the operand of the instruction to be constructed. This operand is an internal name (see {@link org.objectweb.asm.Type}). 52 | */ 53 | public TypeInsnNode(final int opcode, final String descriptor) { 54 | super(opcode); 55 | this.desc = descriptor; 56 | } 57 | 58 | /** 59 | * Sets the opcode of this instruction. 60 | * 61 | * @param opcode 62 | * the new instruction opcode. This opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. 63 | */ 64 | public void setOpcode(final int opcode) { 65 | this.opcode = opcode; 66 | } 67 | 68 | @Override 69 | public int getType() { 70 | return TYPE_INSN; 71 | } 72 | 73 | @Override 74 | public void accept(final MethodVisitor methodVisitor) { 75 | methodVisitor.visitTypeInsn(opcode, desc); 76 | acceptAnnotations(methodVisitor); 77 | } 78 | 79 | @Override 80 | public AbstractInsnNode clone(final Map clonedLabels) { 81 | return new TypeInsnNode(opcode, desc).cloneAnnotations(this); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/UnsupportedClassVersionException.java: -------------------------------------------------------------------------------- 1 | package org.objectweb.asm.tree; 2 | 3 | /** 4 | * Exception thrown in {@link AnnotationNode#check}, {@link ClassNode#check}, {@link FieldNode#check} and {@link MethodNode#check} when these nodes (or their children, recursively) contain elements that were introduced in more recent versions of the ASM API than version passed to these methods. 5 | * 6 | * @author Eric Bruneton 7 | */ 8 | public class UnsupportedClassVersionException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = -3502347765891805831L; 11 | } 12 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/VarInsnNode.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree; 29 | 30 | import java.util.Map; 31 | import org.objectweb.asm.MethodVisitor; 32 | 33 | /** 34 | * A node that represents a local variable instruction. A local variable instruction is an instruction that loads or stores the value of a local variable. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class VarInsnNode extends AbstractInsnNode { 39 | 40 | /** The operand of this instruction. This operand is the index of a local variable. */ 41 | public int var; 42 | 43 | /** 44 | * Constructs a new {@link VarInsnNode}. 45 | * 46 | * @param opcode 47 | * the opcode of the local variable instruction to be constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET. 48 | * @param var 49 | * the operand of the instruction to be constructed. This operand is the index of a local variable. 50 | */ 51 | public VarInsnNode(final int opcode, final int var) { 52 | super(opcode); 53 | this.var = var; 54 | } 55 | 56 | /** 57 | * Sets the opcode of this instruction. 58 | * 59 | * @param opcode 60 | * the new instruction opcode. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET. 61 | */ 62 | public void setOpcode(final int opcode) { 63 | this.opcode = opcode; 64 | } 65 | 66 | @Override 67 | public int getType() { 68 | return VAR_INSN; 69 | } 70 | 71 | @Override 72 | public void accept(final MethodVisitor methodVisitor) { 73 | methodVisitor.visitVarInsn(opcode, var); 74 | acceptAnnotations(methodVisitor); 75 | } 76 | 77 | @Override 78 | public AbstractInsnNode clone(final Map clonedLabels) { 79 | return new VarInsnNode(opcode, var).cloneAnnotations(this); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/AnalyzerException.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree.analysis; 29 | 30 | import org.objectweb.asm.tree.AbstractInsnNode; 31 | 32 | /** 33 | * An exception thrown if a problem occurs during the analysis of a method. 34 | * 35 | * @author Bing Ran 36 | * @author Eric Bruneton 37 | */ 38 | public class AnalyzerException extends Exception { 39 | 40 | private static final long serialVersionUID = 3154190448018943333L; 41 | 42 | /** The bytecode instruction where the analysis failed. */ 43 | public final transient AbstractInsnNode node; 44 | 45 | /** 46 | * Constructs a new {@link AnalyzerException}. 47 | * 48 | * @param insn 49 | * the bytecode instruction where the analysis failed. 50 | * @param message 51 | * the reason why the analysis failed. 52 | */ 53 | public AnalyzerException(final AbstractInsnNode insn, final String message) { 54 | super(message); 55 | this.node = insn; 56 | } 57 | 58 | /** 59 | * Constructs a new {@link AnalyzerException}. 60 | * 61 | * @param insn 62 | * the bytecode instruction where the analysis failed. 63 | * @param message 64 | * the reason why the analysis failed. 65 | * @param cause 66 | * the cause of the failure. 67 | */ 68 | public AnalyzerException(final AbstractInsnNode insn, final String message, final Throwable cause) { 69 | super(message, cause); 70 | this.node = insn; 71 | } 72 | 73 | /** 74 | * Constructs a new {@link AnalyzerException}. 75 | * 76 | * @param insn 77 | * the bytecode instruction where the analysis failed. 78 | * @param message 79 | * the reason why the analysis failed. 80 | * @param expected 81 | * an expected value. 82 | * @param actual 83 | * the actual value, different from the expected one. 84 | */ 85 | public AnalyzerException(final AbstractInsnNode insn, final String message, final Object expected, 86 | final Value actual) { 87 | super((message == null ? "Expected " : message + ": expected ") + expected + ", but found " + actual); 88 | this.node = insn; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/SourceValue.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree.analysis; 29 | 30 | import java.util.Set; 31 | import org.objectweb.asm.tree.AbstractInsnNode; 32 | 33 | /** 34 | * A {@link Value} which keeps track of the bytecode instructions that can produce it. 35 | * 36 | * @author Eric Bruneton 37 | */ 38 | public class SourceValue implements Value { 39 | 40 | /** 41 | * The size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 42 | */ 43 | public final int size; 44 | 45 | /** 46 | * The instructions that can produce this value. For example, for the Java code below, the instructions that can produce the value of {@code i} at line 5 are the two ISTORE instructions at line 1 and 3: 47 | * 48 | *

 49 | 	 * 1: i = 0;
 50 | 	 * 2: if (...) {
 51 | 	 * 3:   i = 1;
 52 | 	 * 4: }
 53 | 	 * 5: return i;
 54 | 	 * 
55 | */ 56 | public final Set insns; 57 | 58 | /** 59 | * Constructs a new {@link SourceValue}. 60 | * 61 | * @param size 62 | * the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 63 | */ 64 | public SourceValue(final int size) { 65 | this(size, new SmallSet()); 66 | } 67 | 68 | /** 69 | * Constructs a new {@link SourceValue}. 70 | * 71 | * @param size 72 | * the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 73 | * @param insnNode 74 | * an instruction that can produce this value. 75 | */ 76 | public SourceValue(final int size, final AbstractInsnNode insnNode) { 77 | this.size = size; 78 | this.insns = new SmallSet<>(insnNode); 79 | } 80 | 81 | /** 82 | * Constructs a new {@link SourceValue}. 83 | * 84 | * @param size 85 | * the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 86 | * @param insnSet 87 | * the instructions that can produce this value. 88 | */ 89 | public SourceValue(final int size, final Set insnSet) { 90 | this.size = size; 91 | this.insns = insnSet; 92 | } 93 | 94 | /** 95 | * Returns the size of this value. 96 | * 97 | * @return the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 98 | */ 99 | @Override 100 | public int getSize() { 101 | return size; 102 | } 103 | 104 | @Override 105 | public boolean equals(final Object value) { 106 | if (!(value instanceof SourceValue)) { 107 | return false; 108 | } 109 | SourceValue sourceValue = (SourceValue) value; 110 | return size == sourceValue.size && insns.equals(sourceValue.insns); 111 | } 112 | 113 | @Override 114 | public int hashCode() { 115 | return insns.hashCode(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/Subroutine.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree.analysis; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | import org.objectweb.asm.tree.JumpInsnNode; 33 | import org.objectweb.asm.tree.LabelNode; 34 | 35 | /** 36 | * A method subroutine (corresponds to a JSR instruction). 37 | * 38 | * @author Eric Bruneton 39 | */ 40 | final class Subroutine { 41 | 42 | /** The start of this subroutine. */ 43 | final LabelNode start; 44 | 45 | /** 46 | * The local variables that are read or written by this subroutine. The i-th element is true if and only if the local variable at index i is read or written by this subroutine. 47 | */ 48 | final boolean[] localsUsed; 49 | 50 | /** The JSR instructions that jump to this subroutine. */ 51 | final List callers; 52 | 53 | /** 54 | * Constructs a new {@link Subroutine}. 55 | * 56 | * @param start 57 | * the start of this subroutine. 58 | * @param maxLocals 59 | * the local variables that are read or written by this subroutine. 60 | * @param caller 61 | * a JSR instruction that jump to this subroutine. 62 | */ 63 | Subroutine(final LabelNode start, final int maxLocals, final JumpInsnNode caller) { 64 | this.start = start; 65 | this.localsUsed = new boolean[maxLocals]; 66 | this.callers = new ArrayList<>(); 67 | callers.add(caller); 68 | } 69 | 70 | /** 71 | * Constructs a copy of the given {@link Subroutine}. 72 | * 73 | * @param subroutine 74 | * the subroutine to copy. 75 | */ 76 | Subroutine(final Subroutine subroutine) { 77 | this.start = subroutine.start; 78 | this.localsUsed = new boolean[subroutine.localsUsed.length]; 79 | this.callers = new ArrayList<>(subroutine.callers); 80 | System.arraycopy(subroutine.localsUsed, 0, this.localsUsed, 0, subroutine.localsUsed.length); 81 | } 82 | 83 | /** 84 | * Merges the given subroutine into this subroutine. The local variables read or written by the given subroutine are marked as read or written by this one, and the callers of the given subroutine are added as callers of this one (if both have the same start). 85 | * 86 | * @param subroutine 87 | * another subroutine. This subroutine is left unchanged by this method. 88 | * @return whether this subroutine has been modified by this method. 89 | */ 90 | public boolean merge(final Subroutine subroutine) { 91 | boolean changed = false; 92 | for (int i = 0; i < localsUsed.length; ++i) { 93 | if (subroutine.localsUsed[i] && !localsUsed[i]) { 94 | localsUsed[i] = true; 95 | changed = true; 96 | } 97 | } 98 | if (subroutine.start == start) { 99 | for (int i = 0; i < subroutine.callers.size(); ++i) { 100 | JumpInsnNode caller = subroutine.callers.get(i); 101 | if (!callers.contains(caller)) { 102 | callers.add(caller); 103 | changed = true; 104 | } 105 | } 106 | } 107 | return changed; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/Value.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | package org.objectweb.asm.tree.analysis; 29 | 30 | /** 31 | * An immutable symbolic value for the semantic interpretation of bytecode. 32 | * 33 | * @author Eric Bruneton 34 | */ 35 | public interface Value { 36 | 37 | /** 38 | * Returns the size of this value in 32 bits words. This size should be 1 for byte, boolean, char, short, int, float, object and array types, and 2 for long and double. 39 | * 40 | * @return either 1 or 2. 41 | */ 42 | int getSize(); 43 | } 44 | -------------------------------------------------------------------------------- /src/org/objectweb/asm/tree/analysis/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | 33 |

34 | Provides a framework for static code analysis based on the asm.tree package. 35 |

36 | 37 |

38 | Basic usage: 39 |

40 | 41 |
42 | ClassReader classReader = new ClassReader(bytecode);
43 | ClassNode classNode = new ClassNode();
44 | classReader.accept(classNode, ClassReader.SKIP_DEBUG);
45 | 
46 | for (MethodNode method : classNode.methods) {
47 |   if (method.instructions.size() > 0) {
48 |     Analyzer analyzer = new Analyzer(new BasicInterpreter());
49 |     analyzer.analyze(classNode.name, method);
50 |     Frame[] frames = analyzer.getFrames();
51 |     // Elements of the frames array now contains info for each instruction
52 |     // from the analyzed method. BasicInterpreter creates BasicValue, that
53 |     // is using simplified type system that distinguishes the UNINITIALZED,
54 |     // INT, FLOAT, LONG, DOUBLE, REFERENCE and RETURNADDRESS types.
55 |     ...
56 |   }
57 | }
58 | 
59 | 60 |

61 | @since ASM 1.4.3 62 |

63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/resources/about.txt: -------------------------------------------------------------------------------- 1 | 2 |

%s 3 |
4 |

Version %s

5 |

Copyright 2019 - GraxCode - All rights reserved

6 | 7 |
-------------------------------------------------------------------------------- /src/resources/access/abstract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/abstract.png -------------------------------------------------------------------------------- /src/resources/access/constructor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/constructor.png -------------------------------------------------------------------------------- /src/resources/access/final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/final.png -------------------------------------------------------------------------------- /src/resources/access/native.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/native.png -------------------------------------------------------------------------------- /src/resources/access/static.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/static.png -------------------------------------------------------------------------------- /src/resources/access/synchronized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/synchronized.png -------------------------------------------------------------------------------- /src/resources/access/synthetic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/synthetic.png -------------------------------------------------------------------------------- /src/resources/access/transient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/transient.png -------------------------------------------------------------------------------- /src/resources/access/volatile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/access/volatile.png -------------------------------------------------------------------------------- /src/resources/changelog.txt: -------------------------------------------------------------------------------- 1 | 2 |

Changelog 3 |
4 |

Version 0.1.2

5 |

More editor improvements, the most used opcodes and need functions are working now! Special nodes like invokedynamic or switches will be implemented later!

6 |
7 |
8 |

Version 0.1.1

9 |

Editing now supports the most important instructions, reordering, inserting, copying, etc. Obfuscated jar files are not that much of a problem anymore (in terms of GUI) and some small bugs were corrected. Unicode characters should also be working by now.

10 |
11 |
12 |

Version 0.1.0

13 |

Fully implemented the decompiler and some code-editing. Also made a new editor for translations, that you can use to make your own (or even for everybody)! You can also change cfr settings from the preferences page.

14 |
15 |
16 |

Version 0.0.6

17 |

Added the old control flow graph, cfr decompiler and exit confirmation.

18 |
19 |
20 |

Version 0.0.5

21 |

Changed the color scheme and made some slight ui adjustments. Also worked on instruction editing.

22 |
23 |
24 |

Version 0.0.4

25 |

Added a mini control-flow connection line into the bytecode editor.

26 |
27 |
28 |

Version 0.0.3

29 |

First bytecode editing implementation, not editable.

30 |
31 |
32 |

Version 0.0.2

33 |

Implementation of FrameHack to avoid getCommonSuperClass troubles. By saving frames will automatically get regenerated. Cafebabe will ask if an unseen super class is unclear.

34 |
35 |
36 |

Version 0.0.1

37 |

Overall implementation of the project. Some functionalities were adopted from JByteMod-Beta, mainly GUI-Elements. In comparison to JBM, this tool features multi-view now. The intention is to keep bytecode editing simple and the user interface easy to use.

38 |
39 |
40 |
Copyright (c) GraxCode
-------------------------------------------------------------------------------- /src/resources/classtype/class.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/classtype/class.png -------------------------------------------------------------------------------- /src/resources/classtype/enum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/classtype/enum.png -------------------------------------------------------------------------------- /src/resources/classtype/interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/classtype/interface.png -------------------------------------------------------------------------------- /src/resources/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/file.png -------------------------------------------------------------------------------- /src/resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/icon.png -------------------------------------------------------------------------------- /src/resources/method/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/method/default.png -------------------------------------------------------------------------------- /src/resources/method/private.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/method/private.png -------------------------------------------------------------------------------- /src/resources/method/protected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/method/protected.png -------------------------------------------------------------------------------- /src/resources/method/public.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/method/public.png -------------------------------------------------------------------------------- /src/resources/overlay/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/overlay/info.png -------------------------------------------------------------------------------- /src/resources/tree/package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GraxCode/Cafebabe/9a22009f5f380b7d485b9a3f31c57194f20e51f5/src/resources/tree/package.png --------------------------------------------------------------------------------