2021-07-06 23:08:08 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer;
|
|
|
|
|
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
|
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.RunOptions;
|
2021-07-21 15:20:38 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.util.DialogUtils;
|
2021-07-06 23:08:08 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.util.JarUtils;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whenever a key is pressed on the swing UI it should get logged here
|
|
|
|
*
|
|
|
|
* @author Konloch
|
|
|
|
* @since 7/6/2021
|
|
|
|
*/
|
|
|
|
public class GlobalHotKeys
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Checks the hotkeys
|
|
|
|
*/
|
2021-07-07 03:07:55 +00:00
|
|
|
public static void keyPressed(KeyEvent e)
|
|
|
|
{
|
2021-07-07 09:00:14 +00:00
|
|
|
if (System.currentTimeMillis() - Configuration.lastHotKeyExecuted <= (600))
|
2021-07-06 23:08:08 +00:00
|
|
|
return;
|
|
|
|
|
2021-07-07 03:07:55 +00:00
|
|
|
//CTRL + O
|
|
|
|
//open resource
|
2021-07-06 23:08:08 +00:00
|
|
|
if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
|
|
|
|
2021-07-21 15:20:38 +00:00
|
|
|
final File file = DialogUtils.fileChooser("Select File or Folder to open in BCV",
|
2021-07-06 23:08:08 +00:00
|
|
|
"APKs, DEX, Class Files or Zip/Jar/War Archives",
|
|
|
|
Constants.SUPPORTED_FILE_EXTENSIONS);
|
|
|
|
|
|
|
|
if(file == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
BytecodeViewer.updateBusyStatus(true);
|
|
|
|
BytecodeViewer.openFiles(new File[]{file}, true);
|
|
|
|
BytecodeViewer.updateBusyStatus(false);
|
2021-07-07 03:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//CTRL + N
|
|
|
|
//new workspace
|
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
2021-07-06 23:08:08 +00:00
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
|
|
|
BytecodeViewer.resetWorkspace(true);
|
2021-07-07 03:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//CTRL + T
|
|
|
|
//compile
|
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
2021-07-06 23:08:08 +00:00
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
|
|
|
Thread t = new Thread(() -> BytecodeViewer.compile(true, false), "Compile");
|
|
|
|
t.start();
|
2021-07-07 03:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//CTRL + R
|
|
|
|
//Run remote code
|
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
2021-07-06 23:08:08 +00:00
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
2021-07-07 02:46:12 +00:00
|
|
|
|
|
|
|
if (BytecodeViewer.promptIfNoLoadedClasses())
|
2021-07-06 23:08:08 +00:00
|
|
|
return;
|
2021-07-07 02:46:12 +00:00
|
|
|
|
2021-07-06 23:08:08 +00:00
|
|
|
new RunOptions().setVisible(true);
|
2021-07-07 03:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//CTRL + S
|
|
|
|
//Export resources
|
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
2021-07-06 23:08:08 +00:00
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
|
|
|
|
2021-07-16 20:55:03 +00:00
|
|
|
if (BytecodeViewer.promptIfNoLoadedResources())
|
2021-07-06 23:08:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Thread resourceExport = new Thread(() ->
|
|
|
|
{
|
2021-07-11 13:55:30 +00:00
|
|
|
if (!BytecodeViewer.autoCompileSuccessful())
|
2021-07-06 23:08:08 +00:00
|
|
|
return;
|
|
|
|
|
2021-07-18 19:53:30 +00:00
|
|
|
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
|
2021-07-06 23:08:08 +00:00
|
|
|
"Select Zip Export",
|
|
|
|
"Zip Archives",
|
|
|
|
"zip");
|
|
|
|
|
|
|
|
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
|
|
|
|
if (returnVal == JFileChooser.APPROVE_OPTION)
|
|
|
|
{
|
2021-07-19 14:11:14 +00:00
|
|
|
Configuration.setLastSaveDirectory(fc.getSelectedFile());
|
|
|
|
|
2021-07-06 23:08:08 +00:00
|
|
|
File file = fc.getSelectedFile();
|
|
|
|
|
|
|
|
if (!file.getAbsolutePath().endsWith(".zip"))
|
|
|
|
file = new File(file.getAbsolutePath() + ".zip");
|
|
|
|
|
2021-07-21 15:20:38 +00:00
|
|
|
if (!DialogUtils.canOverwriteFile(file))
|
2021-07-06 23:08:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
final File file2 = file;
|
|
|
|
|
|
|
|
BytecodeViewer.updateBusyStatus(true);
|
|
|
|
Thread jarExport = new Thread(() -> {
|
|
|
|
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(),
|
|
|
|
file2.getAbsolutePath());
|
|
|
|
BytecodeViewer.updateBusyStatus(false);
|
|
|
|
}, "Jar Export");
|
|
|
|
jarExport.start();
|
|
|
|
}
|
|
|
|
}, "Resource Export");
|
|
|
|
resourceExport.start();
|
|
|
|
}
|
2021-07-07 03:07:55 +00:00
|
|
|
|
|
|
|
//CTRL + W
|
|
|
|
//close active resource (currently opened tab)
|
2021-07-06 23:08:08 +00:00
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
2021-07-07 03:05:35 +00:00
|
|
|
|
|
|
|
if (BytecodeViewer.hasActiveResource())
|
|
|
|
BytecodeViewer.viewer.workPane.tabs.remove(BytecodeViewer.viewer.workPane.getActiveResource());
|
2021-07-06 23:08:08 +00:00
|
|
|
}
|
2021-07-07 05:38:47 +00:00
|
|
|
|
|
|
|
//CTRL + L
|
|
|
|
//open last opened resource
|
|
|
|
else if ((e.getKeyCode() == KeyEvent.VK_L) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
|
|
|
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
|
|
|
|
|
|
|
|
String recentFile = Settings.getRecentFile();
|
|
|
|
|
|
|
|
if(!BytecodeViewer.hasResources() && recentFile != null)
|
2021-07-07 05:56:29 +00:00
|
|
|
{
|
|
|
|
File file = new File(recentFile);
|
|
|
|
if(file.exists())
|
|
|
|
{
|
|
|
|
BytecodeViewer.openFiles(new File[]{file}, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BytecodeViewer.showMessage("The file " + file.getAbsolutePath() + " could not be found.");
|
|
|
|
Settings.removeRecentFile(file);
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 05:38:47 +00:00
|
|
|
}
|
2021-07-06 23:08:08 +00:00
|
|
|
}
|
|
|
|
}
|