Skip to content

Commit

Permalink
update SignController add ThreadPool
Browse files Browse the repository at this point in the history
  • Loading branch information
cxapython committed Aug 2, 2021
1 parent 290adea commit e5416aa
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/crack/MaFengWo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public static Map<String,String> mfwObj(){
Map<String,String> obj= new HashMap<>();
return obj;
}
public void destroy() throws IOException {
emulator.close();
}

public MaFengWo() {
emulator = new AndroidARMEmulator("com.mfw.roadbook"); // 创建模拟器实例,要模拟32位或者64位,在这里区分
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String,String> 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<String,String> 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<Map<String, String>> 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<String,String> result= submit.get();
return JSON.toJSONString(result);

}catch (Throwable throwable){
throwable.printStackTrace();
System.out.println("mfwSign throwable: "+throwable.toString());
return null;
}

}
}
}

8 changes: 4 additions & 4 deletions src/main/java/com/worker/DYWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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);
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/worker/MFWWorker.java
Original file line number Diff line number Diff line change
@@ -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<String, String> worker(String... args) {
// System.out.println("MFWWorker worker: " + Thread.currentThread().getName() + Thread.currentThread().getId());
String url = args[0];
return mafengwo.xPreAuthencode(url);
}
}

0 comments on commit e5416aa

Please sign in to comment.