feat(core): 重构主类并添加新功能
- 重构 Main 类,添加新属性和方法- 新增 RegistrationTool 类,用于注册工具类别 - 添加 StartupEvent 事件,用于程序启动时触发 - 修改插件加载逻辑,使用 Main.getMain() 获取主类实例
This commit is contained in:
@@ -12,7 +12,7 @@ if (currentJavaVersion != requiredJavaVersion) {
|
||||
}
|
||||
|
||||
group = 'com.axis.innovators.box'
|
||||
version = '1.0-SNAPSHOT'
|
||||
version = '0.0.1'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.axis.innovators.box;
|
||||
|
||||
import com.axis.innovators.box.events.GlobalEventBus;
|
||||
import com.axis.innovators.box.events.SettingsLoadEvents;
|
||||
import com.axis.innovators.box.events.StartupEvent;
|
||||
import com.axis.innovators.box.events.SubscribeEvent;
|
||||
import com.axis.innovators.box.gui.*;
|
||||
import com.axis.innovators.box.plugins.PluginLoader;
|
||||
import com.axis.innovators.box.register.RegistrationTool;
|
||||
import com.axis.innovators.box.tools.LibraryLoad;
|
||||
import com.axis.innovators.box.tools.SystemInfoUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -13,7 +15,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 主类
|
||||
@@ -26,10 +27,20 @@ public class Main {
|
||||
"tzdwindows 7"
|
||||
};
|
||||
/** 我是总任务数 **/
|
||||
public static int totalTasks = 0;
|
||||
public int totalTasks = 1;
|
||||
/** 我是当前任务数 **/
|
||||
public static int completedTasks = 0;
|
||||
public static ProgressBarManager progressBarManager = new ProgressBarManager("加载中...", totalTasks);
|
||||
private int completedTasks = 0;
|
||||
public ProgressBarManager progressBarManager = new ProgressBarManager("加载中...", totalTasks);
|
||||
private static Main main;
|
||||
private MainWindow ex;
|
||||
private Thread thread;
|
||||
private final String[] args;
|
||||
private boolean isWindow = false;
|
||||
private RegistrationTool registrationTool;
|
||||
|
||||
public Main(String[] args){
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -40,16 +51,32 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSettingsLoad(SettingsLoadEvents event) {
|
||||
JLabel placeholder = new JLabel("设置功能开发中...", SwingConstants.CENTER);
|
||||
placeholder.setFont(new Font("微软雅黑", Font.PLAIN, 24));
|
||||
placeholder.setForeground(new Color(127, 140, 153));
|
||||
event.content().add(placeholder, BorderLayout.CENTER);
|
||||
|
||||
/**
|
||||
* 获取主类
|
||||
* @return 主类
|
||||
*/
|
||||
public static Main getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/**
|
||||
* 获取主窗口
|
||||
* @return 主窗口
|
||||
*/
|
||||
public MainWindow getMainWindow() {
|
||||
return ex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出程序
|
||||
*/
|
||||
public void quit() {
|
||||
logger.info("Application is shutting down...");
|
||||
thread.interrupt();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void initLog4j2() {
|
||||
Log4j2OutputStream.redirectSystemStreams();
|
||||
// 输出版本和作者信息
|
||||
logger.info("Application Version: {}", VERSIONS);
|
||||
@@ -65,9 +92,24 @@ public class Main {
|
||||
logger.info("Java Home: {}", System.getProperty("java.home"));
|
||||
logger.info("Java Class Path: {}", System.getProperty("java.class.path"));
|
||||
logger.info("ClassLoader.getSystemClassLoader(): {}", ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSettingsLoad(SettingsLoadEvents event) {
|
||||
JLabel placeholder = new JLabel("设置功能开发中...", SwingConstants.CENTER);
|
||||
placeholder.setFont(new Font("微软雅黑", Font.PLAIN, 24));
|
||||
placeholder.setForeground(new Color(127, 140, 153));
|
||||
event.content().add(placeholder, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
main = new Main(args);
|
||||
// 注册事件
|
||||
GlobalEventBus.EVENT_BUS.register(new Main());
|
||||
GlobalEventBus.EVENT_BUS.register(main);
|
||||
|
||||
main.initLog4j2();
|
||||
|
||||
// 设置系统外观
|
||||
try {
|
||||
@@ -75,55 +117,20 @@ public class Main {
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to load the system facade class", e);
|
||||
}
|
||||
Thread thread = new Thread(() -> {
|
||||
main.thread = new Thread(() -> {
|
||||
try {
|
||||
// 主任务1:加载插件
|
||||
progressBarManager.updateMainProgress(++completedTasks);
|
||||
main.progressBarManager.updateMainProgress(++main.completedTasks);
|
||||
PluginLoader.loadPlugins();
|
||||
logger.info("Loaded plugins");
|
||||
|
||||
progressBarManager.close();
|
||||
main.progressBarManager.close();
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
MainWindow ex = new MainWindow();
|
||||
int id = 0;
|
||||
MainWindow.ToolCategory debugCategory = new MainWindow.ToolCategory("调试工具",
|
||||
"debug/debug.png",
|
||||
"用于调试指定Windows工具的一个分类");
|
||||
|
||||
debugCategory.addTool(new MainWindow.ToolItem("Frida注入工具", "debug/frida/frida_main.png",
|
||||
"使用frida注入目标进程的脚本程序 " +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
FridaWindow fridaWindow = new FridaWindow(owner);
|
||||
fridaWindow.setVisible(true);
|
||||
}
|
||||
}));
|
||||
|
||||
ex.addToolCategory(debugCategory);
|
||||
|
||||
MainWindow.ToolCategory aICategory = new MainWindow.ToolCategory("AI工具",
|
||||
"ai/ai.png",
|
||||
"人工智能/大语言模型");
|
||||
|
||||
aICategory.addTool(new MainWindow.ToolItem("本地AI执行工具", "ai/local/local_main.png",
|
||||
"在本机对开源大语言模型进行推理" +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
LocalWindow dialog = new LocalWindow(owner);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}));
|
||||
|
||||
ex.addToolCategory(aICategory);
|
||||
|
||||
ex.initUI();
|
||||
ex.setVisible(true);
|
||||
main.ex = new MainWindow();
|
||||
GlobalEventBus.EVENT_BUS.post(new StartupEvent(main));
|
||||
main.runWindow();
|
||||
} catch (Exception e) {
|
||||
logger.error("There was a problem starting the main thread", e);
|
||||
throw new RuntimeException(e);
|
||||
@@ -134,7 +141,80 @@ public class Main {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
thread.setName("Main Thread");
|
||||
thread.start();
|
||||
main.thread.setName("Main Thread");
|
||||
main.thread.start();
|
||||
}
|
||||
|
||||
public void runWindow() {
|
||||
int id = 0;
|
||||
MainWindow.ToolCategory debugCategory = new MainWindow.ToolCategory("调试工具",
|
||||
"debug/debug.png",
|
||||
"用于调试指定Windows工具的一个分类");
|
||||
|
||||
debugCategory.addTool(new MainWindow.ToolItem("Frida注入工具", "debug/frida/frida_main.png",
|
||||
"使用frida注入目标进程的脚本程序 " +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
FridaWindow fridaWindow = new FridaWindow(owner);
|
||||
fridaWindow.setVisible(true);
|
||||
}
|
||||
}));
|
||||
|
||||
ex.addToolCategory(debugCategory);
|
||||
|
||||
MainWindow.ToolCategory aICategory = new MainWindow.ToolCategory("AI工具",
|
||||
"ai/ai.png",
|
||||
"人工智能/大语言模型");
|
||||
|
||||
aICategory.addTool(new MainWindow.ToolItem("本地AI执行工具", "ai/local/local_main.png",
|
||||
"在本机对开源大语言模型进行推理" +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
LocalWindow dialog = new LocalWindow(owner);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}));
|
||||
|
||||
ex.addToolCategory(aICategory);
|
||||
|
||||
// 主任务2:加载工具栏
|
||||
progressBarManager.updateMainProgress(++completedTasks);
|
||||
|
||||
for (int i = 0; i < registrationTool.getToolCategories()
|
||||
.size(); i++) {
|
||||
ex.addToolCategory(registrationTool.getToolCategories()
|
||||
.get(i));
|
||||
progressBarManager.updateSubProgress(
|
||||
"add tools",i,
|
||||
registrationTool.getToolCategories().size());
|
||||
}
|
||||
|
||||
ex.initUI();
|
||||
isWindow = true;
|
||||
ex.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取注册工具
|
||||
* @return 注册工具
|
||||
*/
|
||||
public RegistrationTool getRegistrationTool() {
|
||||
return registrationTool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取命令行参数
|
||||
* @return 命令行参数
|
||||
*/
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public boolean isWindow() {
|
||||
return isWindow;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.axis.innovators.box.events;
|
||||
|
||||
import com.axis.innovators.box.Main;
|
||||
|
||||
/**
|
||||
* 当程序启动时触发
|
||||
*
|
||||
* @author tzdwindows 7
|
||||
*/
|
||||
public record StartupEvent(Main main) {
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class PluginLoader {
|
||||
}
|
||||
for (int i = 0; i < jars.length; i++) {
|
||||
processJarFile(jars[i]);
|
||||
Main.progressBarManager.updateSubProgress(
|
||||
Main.getMain().progressBarManager.updateSubProgress(
|
||||
"Loading Plugin " + i,
|
||||
i,
|
||||
jars.length);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.axis.innovators.box.register;
|
||||
|
||||
import com.axis.innovators.box.Main;
|
||||
import com.axis.innovators.box.gui.MainWindow;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 负责注册Registration项(限定时机,在执行.run之前可设置)
|
||||
* @author tzdwindows 7
|
||||
*/
|
||||
public class RegistrationTool {
|
||||
private static final Logger logger = LogManager.getLogger(RegistrationTool.class);
|
||||
private final List<MainWindow.ToolCategory> toolCategories = new ArrayList<>();
|
||||
private final Main main;
|
||||
|
||||
public RegistrationTool(Main mainWindow){
|
||||
this.main = mainWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册ToolCategory
|
||||
* @param toolCategory ToolCategory
|
||||
*/
|
||||
void addToolCategory(MainWindow.ToolCategory toolCategory){
|
||||
if (!main.isWindow()) {
|
||||
toolCategories.add(toolCategory);
|
||||
} else {
|
||||
logger.warn("Wrong time to add tools");
|
||||
}
|
||||
}
|
||||
|
||||
public List<MainWindow.ToolCategory> getToolCategories() {
|
||||
return toolCategories;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user