2015-11-11 04:16:45 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.api;
|
|
|
|
|
2021-08-26 21:59:07 +00:00
|
|
|
import java.awt.CardLayout;
|
|
|
|
import java.awt.Dimension;
|
2021-07-25 16:54:08 +00:00
|
|
|
import java.io.IOException;
|
2015-11-11 04:16:45 +00:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
2021-07-21 14:50:09 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
2021-06-29 18:24:47 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.Configuration;
|
2021-07-21 14:50:09 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsole;
|
2021-07-24 03:26:23 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
|
2021-07-11 14:10:42 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.resources.IconResources;
|
2021-07-23 16:20:23 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
|
2018-01-31 15:03:53 +00:00
|
|
|
|
2021-08-26 21:59:07 +00:00
|
|
|
import static the.bytecode.club.bytecodeviewer.Constants.FAT_JAR;
|
|
|
|
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
|
|
|
|
import static the.bytecode.club.bytecodeviewer.Constants.nl;
|
2021-06-21 09:45:31 +00:00
|
|
|
|
2015-11-11 04:16:45 +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/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple class designed to show exceptions in the UI.
|
2018-01-31 15:41:24 +00:00
|
|
|
*
|
2015-11-11 04:16:45 +00:00
|
|
|
* @author Konloch
|
|
|
|
*/
|
|
|
|
|
2021-07-21 14:50:09 +00:00
|
|
|
public class ExceptionUI extends JFrameConsole
|
2021-07-06 22:10:50 +00:00
|
|
|
{
|
2021-07-23 05:17:20 +00:00
|
|
|
public static final String KONLOCH = "https://github.com/Konloch/bytecode-viewer/issues or Konloch at https://the.bytecode.club or konloch@gmail.com";
|
2021-07-07 01:10:09 +00:00
|
|
|
public static final String SEND_STACKTRACE_TO = buildErrorLogHeader(KONLOCH);
|
2021-07-11 16:52:07 +00:00
|
|
|
public static final String SEND_STACKTRACE_TO_NL = SEND_STACKTRACE_TO + nl + nl;
|
2021-07-07 00:52:00 +00:00
|
|
|
|
2018-01-31 15:41:24 +00:00
|
|
|
/**
|
|
|
|
* @param e The exception to be shown
|
|
|
|
*/
|
|
|
|
public ExceptionUI(Throwable e) {
|
2021-07-07 01:10:09 +00:00
|
|
|
setupException(e, KONLOCH);
|
2018-01-31 15:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param e The exception to be shown
|
|
|
|
*/
|
|
|
|
public ExceptionUI(String e) {
|
2021-07-07 01:10:09 +00:00
|
|
|
setupFrame(e, KONLOCH);
|
2018-01-31 15:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param e The exception to be shown
|
|
|
|
* @param author the author of the plugin throwing this exception.
|
|
|
|
*/
|
|
|
|
public ExceptionUI(Throwable e, String author) {
|
2021-07-06 22:10:50 +00:00
|
|
|
setupException(e, author);
|
2018-01-31 15:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param e The exception to be shown
|
|
|
|
* @param author the author of the plugin throwing this exception.
|
|
|
|
*/
|
|
|
|
public ExceptionUI(String e, String author) {
|
2021-07-06 22:10:50 +00:00
|
|
|
setupFrame(e, author);
|
2018-01-31 15:41:24 +00:00
|
|
|
}
|
2021-07-07 01:10:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles error suppression and prints stacktraces to strings
|
|
|
|
*/
|
2021-07-06 22:10:50 +00:00
|
|
|
private void setupException(Throwable error, String author)
|
2021-06-29 18:24:47 +00:00
|
|
|
{
|
|
|
|
//exceptions are completely hidden
|
|
|
|
if(Configuration.silenceExceptionGUI > 0)
|
|
|
|
return;
|
2021-07-06 22:10:50 +00:00
|
|
|
|
2021-06-29 18:24:47 +00:00
|
|
|
//exception GUI is disabled but printstack is still enabled
|
|
|
|
if(Configuration.pauseExceptionGUI > 0)
|
|
|
|
{
|
2021-07-06 22:10:50 +00:00
|
|
|
error.printStackTrace();
|
2021-06-29 18:24:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-25 16:54:08 +00:00
|
|
|
try (StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw)) {
|
|
|
|
error.printStackTrace(pw);
|
|
|
|
error.printStackTrace();
|
|
|
|
|
|
|
|
setupFrame(sw.toString(), author);
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
}
|
2021-07-06 22:10:50 +00:00
|
|
|
}
|
2021-07-07 01:10:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new frame and fills it with the error log
|
|
|
|
*/
|
2021-07-06 22:10:50 +00:00
|
|
|
private void setupFrame(String error, String author)
|
|
|
|
{
|
2021-07-23 22:12:53 +00:00
|
|
|
setIconImages(IconResources.iconList);
|
2018-01-31 15:41:24 +00:00
|
|
|
setSize(new Dimension(600, 400));
|
2021-07-07 01:10:09 +00:00
|
|
|
setTitle("Bytecode Viewer " + VERSION + " - Error Log - Send this to " + author);
|
2018-01-31 15:41:24 +00:00
|
|
|
getContentPane().setLayout(new CardLayout(0, 0));
|
2021-07-06 22:10:50 +00:00
|
|
|
|
2021-07-21 14:50:09 +00:00
|
|
|
getTextArea().setText(buildErrorLogHeader(author) + nl + nl + error);
|
|
|
|
getTextArea().setCaretPosition(0);
|
|
|
|
|
2021-07-23 22:12:53 +00:00
|
|
|
//embed error log as a new tab
|
|
|
|
if(Configuration.errorLogsAsNewTab)
|
2021-07-24 03:51:55 +00:00
|
|
|
PluginManager.addExceptionUI(this);
|
|
|
|
|
2021-07-23 22:12:53 +00:00
|
|
|
//pop open a new window frame
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setLocationRelativeTo(BytecodeViewer.viewer);
|
|
|
|
setVisible(true);
|
|
|
|
}
|
2018-01-31 15:41:24 +00:00
|
|
|
}
|
2021-07-06 22:10:50 +00:00
|
|
|
|
2021-07-07 01:10:09 +00:00
|
|
|
/**
|
|
|
|
* Returns the error log header
|
|
|
|
*/
|
|
|
|
public static String buildErrorLogHeader(String author)
|
|
|
|
{
|
2021-07-21 14:44:25 +00:00
|
|
|
String fatJar = FAT_JAR ? " [Fat Jar]" : "";
|
2021-07-07 01:10:09 +00:00
|
|
|
|
2021-09-16 11:56:26 +00:00
|
|
|
return TranslatedStrings.PLEASE_SEND_THIS_ERROR_LOG_TO + " " + author +
|
|
|
|
"\n" + TranslatedStrings.PLEASE_SEND_RESOURCES +
|
2021-07-10 13:46:45 +00:00
|
|
|
"\nBytecode Viewer Version: " + VERSION + fatJar +
|
2021-07-07 01:10:09 +00:00
|
|
|
", OS: " + System.getProperty("os.name") +
|
|
|
|
", Java: " + System.getProperty("java.version");
|
|
|
|
}
|
|
|
|
|
2021-07-06 22:10:50 +00:00
|
|
|
private static final long serialVersionUID = -5230501978224926296L;
|
2021-08-26 21:59:07 +00:00
|
|
|
}
|