1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*******************************************************************************
* Copyright (c) 2014 Jeff Martin.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Jeff Martin - initial API and implementation
******************************************************************************/
package cuchaz.enigma.gui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.text.BadLocationException;
import jsyntaxpane.DefaultSyntaxKit;
import jsyntaxpane.Token;
import cuchaz.enigma.ClassFile;
import cuchaz.enigma.analysis.SourceIndex;
public class Gui
{
private static final String Name = "Enigma";
// controls
private JFrame m_frame;
private JList<ClassFile> m_obfClasses;
private JList<ClassFile> m_deobfClasses;
private JEditorPane m_editor;
// handlers
private ClassSelectionHandler m_classSelectionHandler;
private BoxHighlightPainter m_highlightPainter;
public Gui( )
{
// init frame
m_frame = new JFrame( Name );
final Container pane = m_frame.getContentPane();
pane.setLayout( new BorderLayout() );
// init obfuscated classes list
m_obfClasses = new JList<ClassFile>();
m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
m_obfClasses.setLayoutOrientation( JList.VERTICAL );
m_obfClasses.setCellRenderer( new ObfuscatedClassListCellRenderer() );
m_obfClasses.addMouseListener( new MouseAdapter()
{
public void mouseClicked( MouseEvent event )
{
if( event.getClickCount() == 2 )
{
if( m_classSelectionHandler != null )
{
ClassFile selected = m_obfClasses.getSelectedValue();
if( selected != null )
{
m_classSelectionHandler.classSelected( selected );
}
}
}
}
} );
JScrollPane obfScroller = new JScrollPane( m_obfClasses );
JPanel obfPanel = new JPanel();
obfPanel.setLayout( new BorderLayout() );
obfPanel.add( new JLabel( "Obfuscated Classes" ), BorderLayout.NORTH );
obfPanel.add( obfScroller, BorderLayout.CENTER );
// init deobfuscated classes list
m_deobfClasses = new JList<ClassFile>();
m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
m_obfClasses.setLayoutOrientation( JList.VERTICAL );
JScrollPane deobfScroller = new JScrollPane( m_deobfClasses );
JPanel deobfPanel = new JPanel();
deobfPanel.setLayout( new BorderLayout() );
deobfPanel.add( new JLabel( "De-obfuscated Classes" ), BorderLayout.NORTH );
deobfPanel.add( deobfScroller, BorderLayout.CENTER );
// init editor
DefaultSyntaxKit.initKit();
m_editor = new JEditorPane();
m_editor.setEditable( false );
JScrollPane sourceScroller = new JScrollPane( m_editor );
m_editor.setContentType( "text/java" );
// layout controls
JSplitPane splitLeft = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel );
JSplitPane splitMain = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, sourceScroller );
pane.add( splitMain, BorderLayout.CENTER );
// show the frame
pane.doLayout();
m_frame.setSize( 800, 600 );
m_frame.setVisible( true );
m_frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
// init handlers
m_classSelectionHandler = null;
m_highlightPainter = new BoxHighlightPainter();
}
public void setTitle( String title )
{
m_frame.setTitle( Name + " - " + title );
}
public void setObfClasses( List<ClassFile> classes )
{
m_obfClasses.setListData( new Vector<ClassFile>( classes ) );
}
public void setSource( String source )
{
setSource( source, null );
}
public void setSource( String source, SourceIndex index )
{
m_editor.setText( source );
// remove any old highlighters
m_editor.getHighlighter().removeAllHighlights();;
if( index != null )
{
// color things based on the index
for( Token token : index.tokens() )
{
try
{
m_editor.getHighlighter().addHighlight( token.start, token.end(), m_highlightPainter );
}
catch( BadLocationException ex )
{
throw new Error( ex );
}
}
}
}
public void setClassSelectionHandler( ClassSelectionHandler val )
{
m_classSelectionHandler = val;
}
}
|