Javascript plugin support
This commit is contained in:
parent
f5f510a2e0
commit
7214aa1bde
3 changed files with 63 additions and 15 deletions
|
@ -92,7 +92,9 @@ public class FileViewer extends ResourceViewer
|
|||
nameLowerCase.endsWith(".gif") || nameLowerCase.endsWith(".tif") || nameLowerCase.endsWith(".bmp"))
|
||||
{
|
||||
canRefresh = true;
|
||||
|
||||
image = MiscUtils.loadImage(image, contents); //gifs fail because of this
|
||||
|
||||
mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER);
|
||||
mainPanel.addMouseWheelListener(e ->
|
||||
{
|
||||
|
|
|
@ -7,11 +7,7 @@ import java.util.Set;
|
|||
import javax.swing.filechooser.FileFilter;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.api.Plugin;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.CompiledJavaPluginLaunchStrategy;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.GroovyPluginLaunchStrategy;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.JavaPluginLaunchStrategy;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.PythonPluginLaunchStrategy;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.RubyPluginLaunchStrategy;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.strategies.*;
|
||||
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
|
||||
|
||||
/***************************************************************************
|
||||
|
@ -47,9 +43,11 @@ public final class PluginManager {
|
|||
private static final PluginFileFilter filter = new PluginFileFilter();
|
||||
private static Plugin pluginInstance;
|
||||
|
||||
static {
|
||||
static
|
||||
{
|
||||
launchStrategies.put("jar", new CompiledJavaPluginLaunchStrategy());
|
||||
launchStrategies.put("java", new JavaPluginLaunchStrategy());
|
||||
launchStrategies.put("js", new JavascriptPluginLaunchStrategy());
|
||||
|
||||
GroovyPluginLaunchStrategy groovy = new GroovyPluginLaunchStrategy();
|
||||
launchStrategies.put("gy", groovy);
|
||||
|
@ -85,20 +83,18 @@ public final class PluginManager {
|
|||
* @param f the file of the plugin
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void runPlugin(File f) throws Throwable {
|
||||
public static void runPlugin(File f) throws Throwable
|
||||
{
|
||||
String ext = f.getName().substring(f.getName().lastIndexOf('.') + 1);
|
||||
PluginLaunchStrategy strategy = launchStrategies.get(ext);
|
||||
|
||||
if (strategy == null) {
|
||||
throw new RuntimeException(String.format("No launch strategy for extension %s (%s)", ext,
|
||||
f.getAbsolutePath()));
|
||||
}
|
||||
if (strategy == null)
|
||||
throw new RuntimeException(String.format("No launch strategy for extension %s (%s)", ext, f.getAbsolutePath()));
|
||||
|
||||
Plugin p = strategy.run(f);
|
||||
|
||||
if (p != null) {
|
||||
if (p != null)
|
||||
runPlugin(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void register(String name, PluginLaunchStrategy strat) {
|
||||
|
@ -113,8 +109,8 @@ public final class PluginManager {
|
|||
return filter;
|
||||
}
|
||||
|
||||
public static class PluginFileFilter extends FileFilter {
|
||||
|
||||
public static class PluginFileFilter extends FileFilter
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory())
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package the.bytecode.club.bytecodeviewer.plugin.strategies;
|
||||
|
||||
import the.bytecode.club.bytecodeviewer.api.Plugin;
|
||||
import the.bytecode.club.bytecodeviewer.plugin.PluginLaunchStrategy;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.Reader;
|
||||
|
||||
/***************************************************************************
|
||||
* 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/>. *
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @author Konloch
|
||||
* @author Bibl (don't ban me pls)
|
||||
* @since 06/25/2021
|
||||
*/
|
||||
public class JavascriptPluginLaunchStrategy implements PluginLaunchStrategy {
|
||||
|
||||
@Override
|
||||
public Plugin run(File file) throws Throwable {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
ScriptEngine engine = manager.getEngineByName("rhino");
|
||||
|
||||
if (engine == null)
|
||||
throw new Exception("Cannot find Rhino script engine! Please contact Konloch.");
|
||||
|
||||
Reader reader = new FileReader(file);
|
||||
engine.eval(reader);
|
||||
|
||||
return (Plugin) engine.eval(file.getName().replace(".js", "") + ".new");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue