feat(box): 升级版本号并优化代码执行功能
-将版本号从 0.0.2 修改为 0.1.2 - 移除了异常时抛出的 RuntimeException - 新增了 C 语言和 Java代码的执行功能 - 优化了 Python 代码的执行方式- 添加了代码编辑器的前端界面 - 新增了 QQ音乐文件解密工具的 UI 界面 - 添加了 C++ 解密库的框架
This commit is contained in:
@@ -37,7 +37,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class AxisInnovatorsBox {
|
||||
private static final Logger logger = LogManager.getLogger(AxisInnovatorsBox.class);
|
||||
private static final String VERSIONS = "0.0.2";
|
||||
private static final String VERSIONS = "0.1.2";
|
||||
private static final String[] AUTHOR = new String[]{
|
||||
"tzdwindows 7"
|
||||
};
|
||||
@@ -71,7 +71,6 @@ public class AxisInnovatorsBox {
|
||||
LibraryLoad.loadLibrary("ThrowSafely");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to load the 'FridaNative' library", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +420,6 @@ public class AxisInnovatorsBox {
|
||||
logger.error("In unexpected errors", e);
|
||||
main.ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
main.organizingCrashReports(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.axis.innovators.box;
|
||||
|
||||
import com.axis.innovators.box.browser.MainApplication;
|
||||
import com.axis.innovators.box.browser.WindowRegistry;
|
||||
import com.axis.innovators.box.decompilation.gui.ModernJarViewer;
|
||||
import com.axis.innovators.box.tools.ArgsParser;
|
||||
import com.axis.innovators.box.tools.FolderCleaner;
|
||||
|
||||
@@ -57,6 +57,9 @@ public class CefAppManager {
|
||||
try {
|
||||
settings.windowless_rendering_enabled = false;
|
||||
settings.javascript_flags = "--expose-gc";
|
||||
settings.cache_path = FolderCreator.getLibraryFolder() + "/jcef/cache";
|
||||
settings.root_cache_path = FolderCreator.getLibraryFolder() + "/jcef/cache";
|
||||
settings.persist_session_cookies = true;
|
||||
settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_VERBOSE;
|
||||
|
||||
String subprocessPath = FolderCreator.getLibraryFolder() + "/jcef/lib/win64/jcef_helper.exe";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.axis.innovators.box.browser;
|
||||
|
||||
import com.axis.innovators.box.browser.util.CodeExecutor;
|
||||
import com.axis.innovators.box.tools.FolderCreator;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
@@ -8,6 +9,11 @@ import org.cef.browser.CefFrame;
|
||||
import org.cef.browser.CefMessageRouter;
|
||||
import org.cef.callback.CefQueryCallback;
|
||||
import org.cef.handler.CefMessageRouterHandlerAdapter;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.PolyglotException;
|
||||
import org.graalvm.polyglot.Value;
|
||||
import org.json.JSONObject;
|
||||
import org.python.util.PythonInterpreter;
|
||||
import org.tzd.lm.LM;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -28,13 +34,14 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* 这是一个简单的示例程序,用于展示如何使用JCEF来创建一个简单的浏览器窗口。
|
||||
* @author tzdwindows 7
|
||||
*/
|
||||
|
||||
public class MainApplication {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
private static long modelHandle;
|
||||
private static long ctxHandle;
|
||||
private static boolean isSystem = true;
|
||||
public static void main(String[] args) {
|
||||
//popupHTMLWindow();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +86,118 @@ public class MainApplication {
|
||||
});
|
||||
}
|
||||
|
||||
public static void popupCCodeEditorWindow() {
|
||||
AtomicReference<BrowserWindow> window = new AtomicReference<>();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
WindowRegistry.getInstance().createNewWindow("main", builder ->
|
||||
window.set(builder.title("TzdC 代码编辑器")
|
||||
.icon(new ImageIcon(Objects.requireNonNull(MainApplication.class.getClassLoader().getResource("icons/logo.png"))).getImage())
|
||||
.size(1487, 836)
|
||||
.htmlPath(FolderCreator.getJavaScriptFolder() + "\\" + "CCodeEditor.html")
|
||||
.operationHandler(createOperationHandler())
|
||||
.build())
|
||||
);
|
||||
|
||||
CefMessageRouter msgRouter = window.get().getMsgRouter();
|
||||
if (msgRouter != null) {
|
||||
msgRouter.addHandler(new CefMessageRouterHandlerAdapter() {
|
||||
@Override
|
||||
public boolean onQuery(CefBrowser browser, CefFrame frame, long queryId,
|
||||
String request, boolean persistent, CefQueryCallback callback) {
|
||||
try {
|
||||
JSONObject requestJson = new JSONObject(request);
|
||||
if ("executeCode".equals(requestJson.optString("type"))) {
|
||||
String code = requestJson.optString("code");
|
||||
String language = requestJson.optString("language");
|
||||
|
||||
// 调用代码执行逻辑
|
||||
String result = CodeExecutor.executeCode(code, language,null);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("status", "success");
|
||||
response.put("output", result);
|
||||
callback.success(response.toString());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("status", "error");
|
||||
error.put("message", e.getMessage());
|
||||
callback.failure(500, error.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueryCanceled(CefBrowser browser, CefFrame frame, long queryId) {
|
||||
// 处理请求取消
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void popupCodeEditorWindow() {
|
||||
AtomicReference<BrowserWindow> window = new AtomicReference<>();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
WindowRegistry.getInstance().createNewWindow("main", builder ->
|
||||
window.set(builder.title("代码编辑器")
|
||||
.icon(new ImageIcon(Objects.requireNonNull(MainApplication.class.getClassLoader().getResource("icons/logo.png"))).getImage())
|
||||
.size(1487, 836)
|
||||
.htmlPath(FolderCreator.getJavaScriptFolder() + "\\" + "CodeEditor.html")
|
||||
.operationHandler(createOperationHandler())
|
||||
.build())
|
||||
);
|
||||
|
||||
CefMessageRouter msgRouter = window.get().getMsgRouter();
|
||||
if (msgRouter != null) {
|
||||
msgRouter.addHandler(new CefMessageRouterHandlerAdapter() {
|
||||
@Override
|
||||
public boolean onQuery(CefBrowser browser, CefFrame frame, long queryId,
|
||||
String request, boolean persistent, CefQueryCallback callback) {
|
||||
try {
|
||||
JSONObject requestJson = new JSONObject(request);
|
||||
if ("executeCode".equals(requestJson.optString("type"))) {
|
||||
String code = requestJson.optString("code");
|
||||
String language = requestJson.optString("language");
|
||||
|
||||
// 调用代码执行逻辑
|
||||
String result = executeCode(code, language);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("status", "success");
|
||||
response.put("output", result);
|
||||
callback.success(response.toString());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("status", "error");
|
||||
error.put("message", e.getMessage());
|
||||
callback.failure(500, error.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueryCanceled(CefBrowser browser, CefFrame frame, long queryId) {
|
||||
// 处理请求取消
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String executeCode(String code, String language) {
|
||||
return CodeExecutor.executeCode(code, language,new CodeExecutor.OutputListener() {
|
||||
@Override
|
||||
public void onOutput(String newOutput) {}
|
||||
});
|
||||
}
|
||||
|
||||
private static Value executeC(Context context, String code) {
|
||||
return context.eval("c", code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出html预览窗口
|
||||
*/
|
||||
@@ -107,11 +226,11 @@ public class MainApplication {
|
||||
|
||||
Path filePath = Paths.get(path);
|
||||
|
||||
//// 验证文件存在性
|
||||
//if (!Files.exists(filePath)) {
|
||||
// callback.failure(404, "{\"code\":404,\"message\":\"文件未找到\"}");
|
||||
// return true;
|
||||
//}
|
||||
// 验证文件存在性
|
||||
if (!Files.exists(filePath)) {
|
||||
callback.failure(404, "{\"code\":404,\"message\":\"文件未找到\"}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 读取文件内容
|
||||
String content = Files.readString(filePath, StandardCharsets.UTF_8);
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package com.axis.innovators.box.browser;
|
||||
|
||||
import com.axis.innovators.box.tools.FolderCreator;
|
||||
import org.cef.CefApp;
|
||||
import org.cef.browser.CefBrowser;
|
||||
import org.cef.browser.CefFrame;
|
||||
import org.cef.handler.CefLoadHandlerAdapter;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
@@ -58,6 +67,8 @@ public class WindowRegistry {
|
||||
config.accept(builder);
|
||||
BrowserWindow window = builder.build();
|
||||
registerWindow(window);
|
||||
|
||||
loadExtLibsPath(window);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,5 +81,59 @@ public class WindowRegistry {
|
||||
config.accept(builder);
|
||||
BrowserWindowJDialog window = builder.build();
|
||||
registerChildWindow(window);
|
||||
|
||||
loadExtLibsPath(window);
|
||||
}
|
||||
|
||||
private void loadExtLibsPath(BrowserWindow window) {
|
||||
CefBrowser cefBrowser = window.getBrowser();
|
||||
|
||||
if (cefBrowser != null)
|
||||
|
||||
// 使用 CefClient 的调度方法(如果可用)或直接添加 LoadHandler
|
||||
cefBrowser.getClient().addLoadHandler(new CefLoadHandlerAdapter() {
|
||||
@Override
|
||||
public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
|
||||
if (frame.isMain()) {
|
||||
try {
|
||||
String extLibsPath = FolderCreator.getJavaScriptFolder() + "\\" + "extLibs";
|
||||
File extLibsDir = new File(extLibsPath);
|
||||
if (!extLibsDir.exists() || !extLibsDir.isDirectory()) {
|
||||
throw new IOException("extLibs目录无效: " + extLibsPath);
|
||||
}
|
||||
String script = "window.extLibsPath = " + JSONObject.valueToString(extLibsPath) + ";";
|
||||
browser.executeJavaScript(script, frame.getURL(), 0);
|
||||
} catch (Exception e) {
|
||||
System.err.println("注入extLibsPath失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private void loadExtLibsPath(BrowserWindowJDialog window) {
|
||||
CefBrowser cefBrowser = window.getBrowser();
|
||||
|
||||
if (cefBrowser != null)
|
||||
// 使用 CefClient 的调度方法(如果可用)或直接添加 LoadHandler
|
||||
cefBrowser.getClient().addLoadHandler(new CefLoadHandlerAdapter() {
|
||||
@Override
|
||||
public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
|
||||
if (frame.isMain()) {
|
||||
try {
|
||||
String extLibsPath = FolderCreator.getJavaScriptFolder() + "\\" + "extLibs";
|
||||
File extLibsDir = new File(extLibsPath);
|
||||
if (!extLibsDir.exists() || !extLibsDir.isDirectory()) {
|
||||
throw new IOException("extLibs目录无效: " + extLibsPath);
|
||||
}
|
||||
String script = "window.extLibsPath = " + JSONObject.valueToString(extLibsPath) + ";";
|
||||
browser.executeJavaScript(script, frame.getURL(), 0);
|
||||
} catch (Exception e) {
|
||||
System.err.println("注入extLibsPath失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,392 @@
|
||||
package com.axis.innovators.box.browser.util;
|
||||
|
||||
import com.axis.innovators.box.tools.LibraryLoad;
|
||||
import org.jnc.DllExtractor;
|
||||
import org.jnc.windows.JncNative;
|
||||
import org.python.util.PythonInterpreter;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class CodeExecutor {
|
||||
// 用于捕获输出的回调接口
|
||||
public interface OutputListener {
|
||||
void onOutput(String newOutput);
|
||||
}
|
||||
|
||||
public static String executeCode(String code, String language, OutputListener listener) {
|
||||
switch (language.toLowerCase()) {
|
||||
case "python":
|
||||
return executePythonNative(code, listener);
|
||||
case "c":
|
||||
case "cpp":
|
||||
return executeC(code, listener);
|
||||
case "java":
|
||||
return executeJavaCode(code, listener);
|
||||
default:
|
||||
return "不支持的语言类型: " + language;
|
||||
}
|
||||
}
|
||||
|
||||
public static String executeJavaCode(String code, OutputListener listener) {
|
||||
Path tempDir = null;
|
||||
try {
|
||||
// ===== 1. 创建临时目录 =====
|
||||
tempDir = Files.createTempDirectory("javaCode");
|
||||
|
||||
// ===== 2. 写入Java源文件(强制UTF-8)=====
|
||||
Path javaFile = tempDir.resolve("Main.java");
|
||||
Files.writeString(javaFile,
|
||||
code,
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
|
||||
// ===== 3. 编译时指定编码 =====
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8);
|
||||
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
options.add("-d");
|
||||
options.add(tempDir.toString());
|
||||
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(
|
||||
null,
|
||||
fileManager,
|
||||
null,
|
||||
options,
|
||||
null,
|
||||
fileManager.getJavaFileObjects(javaFile)
|
||||
);
|
||||
|
||||
if (!task.call()) {
|
||||
return "编译失败";
|
||||
}
|
||||
|
||||
// ===== 4. 执行配置 =====
|
||||
String javaExe = Path.of(System.getProperty("java.home"), "bin", "java").toString();
|
||||
ProcessBuilder pb = new ProcessBuilder(
|
||||
javaExe,
|
||||
"-Dfile.encoding=UTF-8",
|
||||
"-Dsun.stdout.encoding=UTF-8", // 针对OpenJDK的特殊设置
|
||||
"-Dsun.stderr.encoding=UTF-8",
|
||||
"-cp",
|
||||
tempDir.toString(),
|
||||
"Main"
|
||||
);
|
||||
|
||||
// ===== 5. 设置环境变量 =====
|
||||
Map<String, String> env = pb.environment();
|
||||
env.put("JAVA_TOOL_OPTIONS", "-Dfile.encoding=UTF-8");
|
||||
env.put("LANG", "en_US.UTF-8"); // Linux/macOS
|
||||
env.put("LC_ALL", "en_US.UTF-8");
|
||||
|
||||
// ===== 6. 输出处理 =====
|
||||
pb.redirectErrorStream(true);
|
||||
Process process = pb.start();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
char[] buffer = new char[4096];
|
||||
int charsRead;
|
||||
|
||||
while ((charsRead = reader.read(buffer)) != -1) {
|
||||
String chunk = new String(buffer, 0, charsRead);
|
||||
output.append(chunk);
|
||||
if (listener != null) {
|
||||
// 处理控制台编码转换(Windows专用)
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
chunk = new String(chunk.getBytes(StandardCharsets.UTF_8), "GBK");
|
||||
}
|
||||
listener.onOutput(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
return output.toString() + "\n退出码: " + exitCode;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return "执行错误: " + e.getMessage();
|
||||
} finally {
|
||||
// 清理代码...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 需要用户安装python环境
|
||||
*/
|
||||
private static String executePythonNative(String code, OutputListener listener) {
|
||||
try {
|
||||
Path pythonFile = Files.createTempFile("script_", ".py");
|
||||
Files.writeString(pythonFile,
|
||||
"# -*- coding: utf-8 -*-\n" + code,
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder("python", pythonFile.toString())
|
||||
.redirectErrorStream(true);
|
||||
|
||||
Map<String, String> env = pb.environment();
|
||||
env.put("PYTHONIOENCODING", "UTF-8");
|
||||
env.put("PYTHONUTF8", "1");
|
||||
|
||||
Process process = pb.start();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
Thread outputThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String finalLine = line + "\n";
|
||||
output.append(finalLine);
|
||||
if (listener != null) {
|
||||
listener.onOutput(finalLine);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
outputThread.start();
|
||||
|
||||
// 等待执行完成
|
||||
int exitCode = process.waitFor();
|
||||
outputThread.join();
|
||||
|
||||
// 清理文件
|
||||
Files.deleteIfExists(pythonFile);
|
||||
|
||||
return String.format("退出码: %d\n输出内容:\n%s", exitCode, output);
|
||||
|
||||
} catch (Exception e) {
|
||||
return "执行错误: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private static String executeC(String code, OutputListener listener) {
|
||||
Path tempDir = null;
|
||||
Path cFile = null;
|
||||
Path exeFile = null;
|
||||
try {
|
||||
// 创建临时工作目录
|
||||
tempDir = Files.createTempDirectory("c_compile_");
|
||||
|
||||
// 生成C源代码文件
|
||||
cFile = tempDir.resolve("program.c");
|
||||
Files.writeString(cFile, code, StandardCharsets.UTF_8);
|
||||
|
||||
// 生成可执行文件路径
|
||||
exeFile = tempDir.resolve("program.exe");
|
||||
|
||||
// 1. 编译代码 -------------------------------------------------
|
||||
String tccPath =System.getProperty("user.dir") + "/library/tcc/tcc.exe";
|
||||
|
||||
Process compileProcess;
|
||||
|
||||
if (listener != null) {
|
||||
compileProcess = new ProcessBuilder(
|
||||
tccPath,
|
||||
"-o", exeFile.toString(),
|
||||
cFile.toString()
|
||||
)
|
||||
.directory(tempDir.toFile())
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
// 捕获编译输出
|
||||
StringBuilder compileOutput = new StringBuilder();
|
||||
Thread compileOutputThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(compileProcess.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
compileOutput.append(line).append("\n");
|
||||
if (listener != null) {
|
||||
listener.onOutput("[编译输出] " + line + "\n");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
compileOutputThread.start();
|
||||
|
||||
// 等待编译完成
|
||||
int compileExitCode = compileProcess.waitFor();
|
||||
compileOutputThread.join(1000);
|
||||
|
||||
if (compileExitCode != 0) {
|
||||
return "编译失败:\n" + compileOutput;
|
||||
}
|
||||
|
||||
// 2. 执行程序 -------------------------------------------------
|
||||
Process executeProcess = new ProcessBuilder(exeFile.toString())
|
||||
.directory(tempDir.toFile())
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
// 实时输出处理
|
||||
AtomicReference<StringBuilder> execOutput = new AtomicReference<>(new StringBuilder());
|
||||
Thread executeOutputThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(executeProcess.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
char[] buffer = new char[1024];
|
||||
int charsRead;
|
||||
while ((charsRead = reader.read(buffer)) != -1) {
|
||||
String outputChunk = new String(buffer, 0, charsRead);
|
||||
execOutput.get().append(outputChunk);
|
||||
if (listener != null) {
|
||||
listener.onOutput(outputChunk);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
executeOutputThread.start();
|
||||
|
||||
// 等待执行完成(最多10秒)
|
||||
boolean finished = executeProcess.waitFor(10, TimeUnit.SECONDS);
|
||||
executeOutputThread.join(1000);
|
||||
|
||||
if (!finished) {
|
||||
executeProcess.destroyForcibly();
|
||||
return "执行超时\n部分输出:\n" + execOutput.get();
|
||||
}
|
||||
|
||||
// 获取最终输出
|
||||
String finalOutput = execOutput.get().toString();
|
||||
int exitCode = executeProcess.exitValue();
|
||||
return String.format("执行结果: %s\n退出码: %d\n输出内容:\n%s",
|
||||
exitCode == 0 ? "成功" : "失败",
|
||||
exitCode,
|
||||
finalOutput);
|
||||
} else {
|
||||
new ProcessBuilder(
|
||||
tccPath,
|
||||
"-o", exeFile.toString(),
|
||||
cFile.toString()
|
||||
)
|
||||
.directory(tempDir.toFile())
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
new ProcessBuilder(
|
||||
"cmd.exe",
|
||||
"/c",
|
||||
"start",
|
||||
"\"Tzd输出窗口\"",
|
||||
"cmd.exe",
|
||||
"/K",
|
||||
"chcp 65001 & ",
|
||||
exeFile.toString()
|
||||
).start();
|
||||
return String.format("执行结果: %s\n退出码: %d\n输出内容:\n%s",
|
||||
"成功",
|
||||
0,
|
||||
"");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return "执行错误: " + e.getMessage();
|
||||
} finally {
|
||||
// 清理临时文件
|
||||
try {
|
||||
if (listener != null){
|
||||
if (cFile != null) Files.deleteIfExists(cFile);
|
||||
if (exeFile != null) Files.deleteIfExists(exeFile);
|
||||
if (tempDir != null) Files.deleteIfExists(tempDir);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("临时文件清理失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String captureProcessOutput(Process process, OutputListener listener)
|
||||
throws IOException {
|
||||
StringBuilder totalOutput = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()))) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
totalOutput.append(line).append("\n");
|
||||
if (listener != null) {
|
||||
listener.onOutput(line + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalOutput.toString();
|
||||
}
|
||||
|
||||
// 输出监控线程
|
||||
private static class OutputMonitor implements Runnable {
|
||||
private final BufferedReader reader;
|
||||
private final OutputListener listener;
|
||||
private volatile boolean running = true;
|
||||
private final StringBuilder totalOutput = new StringBuilder();
|
||||
|
||||
public OutputMonitor(BufferedReader reader, OutputListener listener) {
|
||||
this.reader = reader;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (running) {
|
||||
if (reader.ready()) {
|
||||
String line = reader.readLine();
|
||||
if (line != null) {
|
||||
totalOutput.append(line).append("\n");
|
||||
if (listener != null) {
|
||||
listener.onOutput(line + "\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
public String getTotalOutput() {
|
||||
return totalOutput.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// 使用方法
|
||||
public static void main(String[] args) {
|
||||
String pythonCode = "#include <stdio.h>\n" +
|
||||
"\n" +
|
||||
"int main() {\n" +
|
||||
" while (1){\n" +
|
||||
" printf(\"Hello World\\n\");\n" +
|
||||
"}\n" +
|
||||
" return 0;\n" +
|
||||
"}";
|
||||
executeCode(pythonCode, "c", null);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ public class RegistrationTool {
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
MainWindow.ToolCategory programmingToolsCategory = new MainWindow.ToolCategory("编程工具",
|
||||
"programming/programming.png",
|
||||
"编程工具");
|
||||
@@ -62,6 +63,26 @@ public class RegistrationTool {
|
||||
}
|
||||
}));
|
||||
|
||||
programmingToolsCategory.addTool(new MainWindow.ToolItem("C语言编辑器", "programming/LanguageEditor/file-editing.png",
|
||||
"C语言编译器,智能化的idea" +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
MainApplication.popupCCodeEditorWindow();
|
||||
}
|
||||
}));
|
||||
|
||||
programmingToolsCategory.addTool(new MainWindow.ToolItem("多语言在线执行(当遇到无限循环时会抛出错误)", "programming/LanguageEditor/file-editing.png",
|
||||
"多语言在线执行,当遇到无限循环时会抛出错误" +
|
||||
"\n作者:tzdwindows 7", ++id, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Window owner = SwingUtilities.windowForComponent((Component) e.getSource());
|
||||
MainApplication.popupCodeEditorWindow();
|
||||
}
|
||||
}));
|
||||
|
||||
MainWindow.ToolCategory aICategory = new MainWindow.ToolCategory("AI工具",
|
||||
"ai/ai.png",
|
||||
"人工智能/大语言模型");
|
||||
|
||||
96
src/main/java/org/QQdecryption/QQMusicAutoDecryptor.java
Normal file
96
src/main/java/org/QQdecryption/QQMusicAutoDecryptor.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package org.QQdecryption;
|
||||
|
||||
import com.axis.innovators.box.tools.FolderCreator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QQMusicAutoDecryptor {
|
||||
|
||||
/**
|
||||
* 解密QQ加密的文件
|
||||
* @param inputPath 源文件路径
|
||||
* @param outputDir 标准输出目录路径
|
||||
*/
|
||||
public static void decrypt(String inputPath, String outputDir) {
|
||||
try {
|
||||
// 构建UnlockQQ.exe路径
|
||||
String unlockExe = FolderCreator.getLibraryFolder() + File.separator + "UnlockQQ.exe";
|
||||
|
||||
// 处理输出文件名和路径
|
||||
File inputFile = new File(inputPath);
|
||||
String originalName = inputFile.getName();
|
||||
|
||||
// 创建扩展名映射表(可根据需要扩展)
|
||||
Map<String, String> formatMap = new HashMap<>() {{
|
||||
put(".mflac", ".flac");
|
||||
put(".mgg", ".ogg");
|
||||
put(".qmc0", ".mp3");
|
||||
put(".qmc3", ".mp3");
|
||||
put(".qmcflac", ".flac");
|
||||
put(".qmcogg", ".ogg");
|
||||
put(".tkm", ".mp3");
|
||||
put(".qmc2", ".mp3");
|
||||
put(".bkcmp3", ".mp3");
|
||||
put(".bkcflac", ".flac");
|
||||
put(".ogg", ".ogg");
|
||||
}};
|
||||
|
||||
// 自动识别并转换文件格式
|
||||
String outputFileName = originalName;
|
||||
int lastDotIndex = originalName.lastIndexOf('.');
|
||||
if (lastDotIndex > 0) {
|
||||
String ext = originalName.substring(lastDotIndex).toLowerCase();
|
||||
if (formatMap.containsKey(ext)) {
|
||||
outputFileName = originalName.substring(0, lastDotIndex)
|
||||
+ formatMap.get(ext);
|
||||
} else {
|
||||
throw new RuntimeException("未知文件格式: " + ext);
|
||||
}
|
||||
}
|
||||
|
||||
File outputFile = new File(outputDir, outputFileName);
|
||||
|
||||
// 构建命令参数(处理带空格的路径)
|
||||
String[] cmd = {
|
||||
unlockExe,
|
||||
"\"" + inputFile.getAbsolutePath() + "\"",
|
||||
"\"" + outputFile.getAbsolutePath() + "\""
|
||||
};
|
||||
|
||||
// 执行解密命令
|
||||
Process process = Runtime.getRuntime().exec(cmd);
|
||||
int exitCode = process.waitFor();
|
||||
|
||||
// 检查执行结果
|
||||
if (exitCode == 0) {
|
||||
System.out.println("解密成功: " + outputFile.getAbsolutePath());
|
||||
|
||||
} else {
|
||||
System.err.println("解密失败,错误码: " + exitCode);
|
||||
printProcessError(process);
|
||||
}
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
System.err.println("解密过程中出现异常: ");
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("解密过程中出现异常: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加错误流打印方法
|
||||
private static void printProcessError(Process process) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getErrorStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.err.println("[EXE ERROR] " + line);
|
||||
throw new RuntimeException("解密失败: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
167
src/main/java/org/QQdecryption/ui/DecryptionUI.java
Normal file
167
src/main/java/org/QQdecryption/ui/DecryptionUI.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package org.QQdecryption.ui;
|
||||
|
||||
import org.QQdecryption.QQMusicAutoDecryptor;
|
||||
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.DropTargetAdapter;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class DecryptionUI extends JFrame {
|
||||
private JProgressBar progressBar;
|
||||
private JTextArea logArea;
|
||||
|
||||
public DecryptionUI() {
|
||||
initUI();
|
||||
setupDnD();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
setTitle("QQ音乐文件解锁工具 v2.1");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
setupModernLookAndFeel();
|
||||
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
|
||||
|
||||
// 拖放区域
|
||||
JPanel dropZone = createDropZone();
|
||||
mainPanel.add(dropZone, BorderLayout.CENTER);
|
||||
|
||||
// 控制面板
|
||||
JPanel controlPanel = createControlPanel();
|
||||
mainPanel.add(controlPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 日志区域
|
||||
logArea = new JTextArea();
|
||||
logArea.setEditable(false);
|
||||
JScrollPane scrollPane = new JScrollPane(logArea);
|
||||
scrollPane.setPreferredSize(new Dimension(0, 150));
|
||||
mainPanel.add(scrollPane, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
}
|
||||
|
||||
private void setupModernLookAndFeel() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(new FlatIntelliJLaf());
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private JPanel createDropZone() {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setBorder(BorderFactory.createDashedBorder(null, 3, 5));
|
||||
panel.setBackground(UIManager.getColor("Panel.background").darker());
|
||||
|
||||
JLabel dropLabel = new JLabel("拖放QQ音乐文件到此区域", SwingConstants.CENTER);
|
||||
dropLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
|
||||
dropLabel.setForeground(new Color(0x666666));
|
||||
panel.add(dropLabel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel createControlPanel() {
|
||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
|
||||
// 进度条
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setPreferredSize(new Dimension(200, 20));
|
||||
progressBar.setStringPainted(true);
|
||||
panel.add(progressBar);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void setupDnD() {
|
||||
new DropTarget(this, new DropTargetAdapter() {
|
||||
@Override
|
||||
public void drop(DropTargetDropEvent dtde) {
|
||||
try {
|
||||
dtde.acceptDrop(DnDConstants.ACTION_COPY);
|
||||
List<File> files = (List<File>) dtde.getTransferable()
|
||||
.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
processFiles(files);
|
||||
} catch (Exception ex) {
|
||||
logError("文件拖放错误: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processFiles(List<File> files) {
|
||||
SwingWorker<Void, Void> worker = new SwingWorker<>() {
|
||||
@Override
|
||||
protected Void doInBackground() {
|
||||
progressBar.setIndeterminate(true);
|
||||
for (File file : files) {
|
||||
decryptFile(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
progressBar.setIndeterminate(false);
|
||||
JOptionPane.showMessageDialog(DecryptionUI.this,
|
||||
"处理完成!",
|
||||
"完成",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
private void decryptFile(File inputFile) {
|
||||
try {
|
||||
logMessage("开始处理: " + inputFile.getName());
|
||||
|
||||
// 自动获取源文件所在目录
|
||||
File outputDir = inputFile.getParentFile();
|
||||
|
||||
QQMusicAutoDecryptor.decrypt(
|
||||
inputFile.getAbsolutePath(),
|
||||
outputDir.getAbsolutePath()
|
||||
);
|
||||
|
||||
logMessage("✓ 成功解密保存到: " + outputDir.getAbsolutePath());
|
||||
} catch (Exception ex) {
|
||||
logError("解密失败: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(String message) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
logArea.append("[INFO] " + message + "\n");
|
||||
logArea.setCaretPosition(logArea.getDocument().getLength());
|
||||
});
|
||||
}
|
||||
|
||||
private void logError(String error) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
logArea.append("[ERROR] " + error + "\n");
|
||||
logArea.setCaretPosition(logArea.getDocument().getLength());
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(() -> {
|
||||
try {
|
||||
UIManager.setLookAndFeel(new FlatIntelliJLaf());
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
new DecryptionUI().setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user