diff --git a/src/main/java/com/crack/MaFengWo.java b/src/main/java/com/crack/MaFengWo.java index d05a505..668dcbe 100644 --- a/src/main/java/com/crack/MaFengWo.java +++ b/src/main/java/com/crack/MaFengWo.java @@ -56,6 +56,9 @@ public static Map mfwObj(){ Map obj= new HashMap<>(); return obj; } + public void destroy() throws IOException { + emulator.close(); + } public MaFengWo() { emulator = new AndroidARMEmulator("com.mfw.roadbook"); // 创建模拟器实例,要模拟32位或者64位,在这里区分 diff --git a/src/main/java/com/spider/unidbgserver/controller/MFWController.java b/src/main/java/com/spider/unidbgserver/controller/MFWController.java index 79075ac..62ac48a 100644 --- a/src/main/java/com/spider/unidbgserver/controller/MFWController.java +++ b/src/main/java/com/spider/unidbgserver/controller/MFWController.java @@ -1,8 +1,10 @@ package com.spider.unidbgserver.controller; import com.alibaba.fastjson.JSON; -import com.crack.DouyinSign; -import com.crack.MaFengWo; +import com.github.unidbg.arm.backend.dynarmic.DynarmicLoader; +import com.github.unidbg.worker.WorkerPool; +import com.github.unidbg.worker.WorkerPoolFactory; +import com.worker.MFWWorker; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -11,16 +13,65 @@ import java.io.IOException; import java.util.Map; +import java.util.concurrent.*; + +//@Controller +//@RequestMapping("/unidbg") +//public class MFWController { +// @RequestMapping(value="mfwSign",method = {RequestMethod.GET,RequestMethod.POST}) +// @ResponseBody +// public String mfwSign(@RequestParam("url") String url) throws IOException { +// MaFengWo mfw = new MaFengWo(); +// Map result=mfw.xPreAuthencode(url); +// String jsonString = JSON.toJSONString(result); +// return jsonString; +// } +//} @Controller @RequestMapping("/unidbg") public class MFWController { + + static { + DynarmicLoader.forceUseDynarmic(); + } + + final int processors = Runtime.getRuntime().availableProcessors()/2 +2; + final WorkerPool xgPool = WorkerPoolFactory.create(MFWWorker::new, processors); + + final static ExecutorService executor = new ThreadPoolExecutor(10, 20, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10), new ThreadPoolExecutor.CallerRunsPolicy()); + @RequestMapping(value="mfwSign",method = {RequestMethod.GET,RequestMethod.POST}) @ResponseBody - public String mfwSign(@RequestParam("url") String url) throws IOException { - MaFengWo mfw = new MaFengWo(); - Map result=mfw.xPreAuthencode(url); - String jsonString = JSON.toJSONString(result); - return jsonString; + public String mfwSign(@RequestParam("url") String url) { + try{ + System.out.println("url: "+url); + Future> submit = executor.submit(() -> { + MFWWorker worker = xgPool.borrow(1, TimeUnit.MINUTES); + if (worker != null) { + try { + return worker.worker(url); + }catch (Throwable throwable){ + System.err.println("MFWWorker error: "+throwable); + } + finally { + xgPool.release(worker); + } + } else { + System.err.println("MFWWorker Borrow failed"); + } + + return null; + }); + Map result= submit.get(); + return JSON.toJSONString(result); + + }catch (Throwable throwable){ + throwable.printStackTrace(); + System.out.println("mfwSign throwable: "+throwable.toString()); + return null; + } + } -} \ No newline at end of file +} + diff --git a/src/main/java/com/worker/DYWorker.java b/src/main/java/com/worker/DYWorker.java index 12fd3b5..71c8ae2 100644 --- a/src/main/java/com/worker/DYWorker.java +++ b/src/main/java/com/worker/DYWorker.java @@ -11,17 +11,17 @@ public class DYWorker implements Worker { public DYWorker() { douyinSign = new DouyinSign(); - System.out.println("Create: " + douyinSign); +// System.out.println("Create: " + douyinSign); } + @Override public void close() throws IOException { - System.out.println("DYWorker close()"); +// System.out.println("DYWorker close()"); douyinSign.destroy(); } - public Map worker(String... args) { - System.out.println("DYWorker worker: " + Thread.currentThread().getName() + Thread.currentThread().getId()); +// System.out.println("DYWorker worker: " + Thread.currentThread().getName() + Thread.currentThread().getId()); String url = args[0]; return douyinSign.crack(url); } diff --git a/src/main/java/com/worker/MFWWorker.java b/src/main/java/com/worker/MFWWorker.java new file mode 100644 index 0000000..1e36f60 --- /dev/null +++ b/src/main/java/com/worker/MFWWorker.java @@ -0,0 +1,28 @@ +package com.worker; + +import com.crack.MaFengWo; +import com.github.unidbg.worker.Worker; + +import java.io.IOException; +import java.util.Map; + +public class MFWWorker implements Worker { + private final MaFengWo mafengwo ; + + public MFWWorker() { + mafengwo = new MaFengWo(); +// System.out.println("Create: " + mafengwo); + } + + @Override + public void close() throws IOException { +// System.out.println("MFWWorker close()"); + mafengwo.destroy(); + } + + public Map worker(String... args) { +// System.out.println("MFWWorker worker: " + Thread.currentThread().getName() + Thread.currentThread().getId()); + String url = args[0]; + return mafengwo.xPreAuthencode(url); + } +} \ No newline at end of file