bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java

101 lines
3.5 KiB
Java
Raw Normal View History

package the.bytecode.club.bytecodeviewer.api;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
2015-11-19 03:30:59 +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 plugin class, it will run the plugin in a background thread.
2018-01-31 15:41:24 +00:00
*
* @author Konloch
*/
2021-07-06 22:38:37 +00:00
public abstract class Plugin extends Thread
{
//as long as your code is being called from the execute function
// this will be the current container
public ResourceContainer activeContainer = null;
2018-01-31 15:41:24 +00:00
@Override
2021-07-06 22:38:37 +00:00
public void run()
{
2021-07-06 22:57:42 +00:00
BytecodeViewer.updateBusyStatus(true);
2021-07-06 22:38:37 +00:00
try
{
2021-07-07 02:46:12 +00:00
if (BytecodeViewer.promptIfNoLoadedClasses())
2018-01-31 15:41:24 +00:00
return;
executeContainer();
2018-01-31 15:41:24 +00:00
} catch (Exception e) {
2021-07-07 02:51:10 +00:00
BytecodeViewer.handleException(e);
2018-01-31 15:41:24 +00:00
} finally {
finished = true;
2021-07-06 22:57:42 +00:00
BytecodeViewer.updateBusyStatus(false);
2018-01-31 15:41:24 +00:00
}
}
2018-01-31 15:41:24 +00:00
private boolean finished = false;
2018-01-31 15:41:24 +00:00
/**
* When the plugin is finally finished, this will return true
*
* @return true if the plugin is finished executing
*/
public boolean isFinished() {
return finished;
}
2018-01-31 15:41:24 +00:00
/**
* If for some reason your plugin needs to keep the thread alive, yet will
* still be considered finished (EZ-Injection), you can call this function
* and it will set the finished boolean to true.
*/
public void setFinished() {
finished = true;
}
/**
* On plugin start each resource container is iterated through
*/
public void executeContainer()
{
BytecodeViewer.getResourceContainers().forEach(container -> {
//set the active container
activeContainer = container;
//call on the plugin code
execute(new ArrayList<>(container.resourceClasses.values()));
});
}
2018-01-31 15:41:24 +00:00
/**
* On plugin start each resource container is iterated through,
* then this is called with the resource container classes
2018-01-31 15:41:24 +00:00
*
* @param classNodeList all of the loaded classes for easy access.
*/
public abstract void execute(ArrayList<ClassNode> classNodeList);
}