Example usage for org.objectweb.asm.tree InsnList toArray

List of usage examples for org.objectweb.asm.tree InsnList toArray

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList toArray.

Prototype

public AbstractInsnNode[] toArray() 

Source Link

Document

Returns an array containing all the instructions in this list.

Usage

From source file:the.bytecode.club.bytecodeviewer.plugin.preinstalled.ShowAllStrings.java

License:Open Source License

@Override
public void execute(final ArrayList<ClassNode> classNodeList) {
    final PluginConsole frame = new PluginConsole("Show All Strings");
    final AtomicBoolean complete = new AtomicBoolean(false);
    final Thread backgroundThread = new Thread() {
        public void run() {
            try {
                for (ClassNode classNode : classNodeList) {
                    for (Object o : classNode.fields.toArray()) {
                        FieldNode f = (FieldNode) o;
                        Object v = f.value;
                        if (v instanceof String) {
                            String s = (String) v;
                            if (!s.isEmpty()) {
                                frame.appendText(String.format("%s.%s%s -> \"%s\"", classNode.name, f.name,
                                        f.desc, s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")));
                            }//  w w  w  . ja  va 2 s  . co  m
                        }
                        if (v instanceof String[]) {
                            for (int i = 0; i < ((String[]) v).length; i++) {
                                String s = ((String[]) v)[i];
                                if (!s.isEmpty()) {
                                    frame.appendText(String.format("%s.%s%s[%s] -> \"%s\"", classNode.name,
                                            f.name, f.desc, i,
                                            s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")));
                                }
                            }
                        }
                    }
                    for (Object o : classNode.methods.toArray()) {
                        MethodNode m = (MethodNode) o;
                        InsnList iList = m.instructions;
                        for (AbstractInsnNode a : iList.toArray()) {
                            if (a instanceof LdcInsnNode) {
                                if (((LdcInsnNode) a).cst instanceof String) {
                                    final String s = (String) ((LdcInsnNode) a).cst;
                                    if (!s.isEmpty()) {
                                        frame.appendText(String.format("%s.%s%s -> \"%s\"", classNode.name,
                                                m.name, m.desc,
                                                s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")));
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                new ExceptionUI(e, "konloch@gmail.com");
            } finally {
                complete.set(true);
            }
        }
    };
    frame.setVisible(true);
    frame.addWindowListener(new WindowListener() {
        @Override
        public void windowClosing(WindowEvent e) {
            backgroundThread.stop();
            complete.set(true);
        }

        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });
    backgroundThread.start();
    while (!complete.get())
        ;
}