2021-06-26 01:13:46 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.gui.resourceviewer;
|
|
|
|
|
2021-07-05 02:07:34 +00:00
|
|
|
import org.objectweb.asm.tree.ClassNode;
|
|
|
|
import the.bytecode.club.bytecodeviewer.compilers.Compiler;
|
2021-07-04 05:59:42 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
|
2021-06-26 01:13:46 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.SearchableRSyntaxTextArea;
|
2021-07-07 04:21:06 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.SystemConsole;
|
2021-06-26 01:13:46 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
|
2021-07-14 11:33:20 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.util.BytecodeViewPanelUpdater;
|
2021-07-07 09:00:14 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
|
2021-07-05 02:07:34 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.util.JarUtils;
|
2021-06-26 01:13:46 +00:00
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
2021-07-05 02:07:34 +00:00
|
|
|
import static the.bytecode.club.bytecodeviewer.Constants.nl;
|
|
|
|
|
2021-06-26 03:33:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2021-06-26 01:13:46 +00:00
|
|
|
/**
|
2021-07-14 11:33:20 +00:00
|
|
|
* Represents a Bytecode/ClassFile View Panel
|
|
|
|
*
|
2021-06-26 01:13:46 +00:00
|
|
|
* @author Konloch
|
|
|
|
* @since 6/24/2021
|
|
|
|
*/
|
2021-07-14 11:33:20 +00:00
|
|
|
public class BytecodeViewPanel
|
2021-06-26 01:13:46 +00:00
|
|
|
{
|
|
|
|
public final JPanel panel = new JPanel(new BorderLayout());
|
|
|
|
|
2021-07-05 02:07:34 +00:00
|
|
|
public final int panelIndex;
|
|
|
|
public final ClassViewer viewer;
|
2021-06-26 01:13:46 +00:00
|
|
|
public SearchableRSyntaxTextArea textArea;
|
2021-07-14 11:33:20 +00:00
|
|
|
public BytecodeViewPanelUpdater updateThread;
|
|
|
|
public Decompiler decompiler = Decompiler.NONE;
|
|
|
|
public Compiler compiler = Compiler.JAVA_COMPILER;
|
2021-06-26 01:13:46 +00:00
|
|
|
|
2021-07-14 11:33:20 +00:00
|
|
|
public BytecodeViewPanel(int panelIndex, ClassViewer viewer)
|
|
|
|
{
|
|
|
|
this.panelIndex = panelIndex;
|
2021-07-05 02:07:34 +00:00
|
|
|
this.viewer = viewer;
|
|
|
|
}
|
2021-06-26 01:13:46 +00:00
|
|
|
|
|
|
|
public void createPane(ClassViewer viewer)
|
|
|
|
{
|
|
|
|
panel.removeAll();
|
|
|
|
textArea = null;
|
|
|
|
|
2021-07-14 11:09:46 +00:00
|
|
|
if(viewer.viewerClassNode == null)
|
|
|
|
panel.add(new JLabel("ERROR: Resource Viewer Corrupt ClassNode"));
|
2021-06-26 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePane(ClassViewer cv, byte[] b, JButton button, boolean isPanelEditable)
|
|
|
|
{
|
2021-07-14 11:33:20 +00:00
|
|
|
updateThread = new BytecodeViewPanelUpdater(this, cv, b, isPanelEditable, button);
|
2021-06-26 01:13:46 +00:00
|
|
|
}
|
2021-07-05 02:07:34 +00:00
|
|
|
|
|
|
|
public boolean compile()
|
|
|
|
{
|
2021-07-06 00:06:05 +00:00
|
|
|
if(textArea == null || !textArea.isEditable())
|
2021-07-05 02:07:34 +00:00
|
|
|
return true;
|
|
|
|
|
2021-07-07 04:21:06 +00:00
|
|
|
SystemConsole errConsole = new SystemConsole("Java Compile Issues");
|
2021-07-14 11:09:46 +00:00
|
|
|
errConsole.setText("Error compiling class: " + viewer.viewerClassNode.name +
|
2021-07-05 02:07:34 +00:00
|
|
|
nl + "Keep in mind most decompilers cannot produce compilable classes" +
|
2021-07-07 09:00:14 +00:00
|
|
|
nl + nl + TranslatedStrings.SUGGESTED_FIX_COMPILER_ERROR +
|
2021-07-05 02:07:34 +00:00
|
|
|
nl + nl);
|
|
|
|
|
2021-07-07 06:11:49 +00:00
|
|
|
try
|
2021-07-05 02:07:34 +00:00
|
|
|
{
|
2021-07-07 06:11:49 +00:00
|
|
|
String text = textArea.getText();
|
2021-07-14 11:33:20 +00:00
|
|
|
byte[] compiledClass = compiler.getCompiler().compile(text, viewer.viewerClassNode.name);
|
2021-07-07 06:11:49 +00:00
|
|
|
|
|
|
|
if (compiledClass != null)
|
|
|
|
{
|
2021-07-05 02:07:34 +00:00
|
|
|
ClassNode newNode = JarUtils.getNode(compiledClass);
|
2021-07-14 11:33:20 +00:00
|
|
|
viewer.container.updateNode(viewer.name, newNode);
|
2021-07-06 00:06:05 +00:00
|
|
|
errConsole.finished();
|
|
|
|
return true;
|
2021-07-05 02:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-07 06:11:49 +00:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-07-06 00:06:05 +00:00
|
|
|
|
|
|
|
errConsole.setVisible(true);
|
|
|
|
errConsole.finished();
|
|
|
|
return false;
|
2021-07-05 02:07:34 +00:00
|
|
|
}
|
2021-06-26 01:13:46 +00:00
|
|
|
}
|