diff --git a/src/main/java/com/anjia/unidbgserver/service/TTEncryptServiceWorker.java b/src/main/java/com/anjia/unidbgserver/service/TTEncryptServiceWorker.java index ed6c643..a1ed3ba 100644 --- a/src/main/java/com/anjia/unidbgserver/service/TTEncryptServiceWorker.java +++ b/src/main/java/com/anjia/unidbgserver/service/TTEncryptServiceWorker.java @@ -22,21 +22,27 @@ public class TTEncryptServiceWorker extends Worker { private WorkerPool pool; private TTEncryptService ttEncryptService; + @Autowired + public void init(UnidbgProperties unidbgProperties) { + this.unidbgProperties = unidbgProperties; + } + + public TTEncryptServiceWorker() { + super(WorkerPoolFactory.create(TTEncryptServiceWorker::new, Runtime.getRuntime().availableProcessors())); + } public TTEncryptServiceWorker(WorkerPool pool) { super(pool); - } @Autowired public TTEncryptServiceWorker(UnidbgProperties unidbgProperties, @Value("${spring.task.execution.pool.core-size:4}") int poolSize) { - super(null); + super(WorkerPoolFactory.create(TTEncryptServiceWorker::new, Runtime.getRuntime().availableProcessors())); this.unidbgProperties = unidbgProperties; if (this.unidbgProperties.isAsync()) { - pool = WorkerPoolFactory.create((pool) -> - new TTEncryptServiceWorker(unidbgProperties.isDynarmic(), unidbgProperties.isVerbose(),pool), - Math.max(poolSize, 4)); + pool = WorkerPoolFactory.create(pool -> new TTEncryptServiceWorker(unidbgProperties.isDynarmic(), + unidbgProperties.isVerbose(), pool), Math.max(poolSize, 4)); log.info("线程池为:{}", Math.max(poolSize, 4)); } else { this.ttEncryptService = new TTEncryptService(unidbgProperties); @@ -79,7 +85,8 @@ private byte[] doWork(String key1, String body) { return ttEncryptService.ttEncrypt(body); } - @SneakyThrows @Override public void destroy() { + @SneakyThrows + @Override public void destroy() { ttEncryptService.destroy(); } } diff --git a/src/test/java/com/anjia/unidbgserver/JnitraceHelperTest.java b/src/test/java/com/anjia/unidbgserver/JnitraceHelperTest.java index 936b6a7..4fb63b5 100644 --- a/src/test/java/com/anjia/unidbgserver/JnitraceHelperTest.java +++ b/src/test/java/com/anjia/unidbgserver/JnitraceHelperTest.java @@ -33,7 +33,7 @@ public class JnitraceHelperTest { @Test public void testTpl() throws DecoderException, IOException { // jnitrace log 文件 路径 - String mt = "meituan.txt"; + String mt = "src/test/resources/frida/mt.txt"; // 名字 String serviceName = "MeiTuan"; diff --git a/src/test/resources/templates/ServiceWorker.tpl b/src/test/resources/templates/ServiceWorker.tpl index 63a40bb..0cc08e9 100644 --- a/src/test/resources/templates/ServiceWorker.tpl +++ b/src/test/resources/templates/ServiceWorker.tpl @@ -4,41 +4,46 @@ import com.anjia.unidbgserver.config.UnidbgProperties; import com.github.unidbg.worker.Worker; import com.github.unidbg.worker.WorkerPool; import com.github.unidbg.worker.WorkerPoolFactory; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @Slf4j @Service("[(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]ServiceWorker") -public class [[${ServiceName}]]ServiceWorker implements Worker { +public class [[${ServiceName}]]ServiceWorker extends Worker { private UnidbgProperties unidbgProperties; private WorkerPool pool; private [[${ServiceName}]]Service [(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]Service; - public [[${ServiceName}]]ServiceWorker() { + super(WorkerPoolFactory.create([[${ServiceName}]]ServiceWorker::new, Runtime.getRuntime().availableProcessors())); + } + public [[${ServiceName}]]ServiceWorker(WorkerPool pool) { + super(pool); } @Autowired public [[${ServiceName}]]ServiceWorker(UnidbgProperties unidbgProperties, @Value("${spring.task.execution.pool.core-size:4}") int poolSize) { + super(WorkerPoolFactory.create([[${ServiceName}]]ServiceWorker::new, Runtime.getRuntime().availableProcessors())); this.unidbgProperties = unidbgProperties; this.[(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]Service = new [[${ServiceName}]]Service(unidbgProperties); - pool = WorkerPoolFactory.create(() -> - new [[${ServiceName}]]ServiceWorker(unidbgProperties.isDynarmic(), unidbgProperties.isVerbose()), + pool = WorkerPoolFactory.create((pool) -> + new MeiTuanServiceWorker(unidbgProperties.isDynarmic(), unidbgProperties.isVerbose(),pool), Math.max(poolSize, 4)); log.info("线程池为:{}", Math.max(poolSize, 4)); } - public [[${ServiceName}]]ServiceWorker(boolean dynarmic, boolean verbose) { + public [[${ServiceName}]]ServiceWorker(boolean dynarmic, boolean verbose, WorkerPool pool) { + super(pool); this.unidbgProperties = new UnidbgProperties(); unidbgProperties.setDynarmic(dynarmic); unidbgProperties.setVerbose(verbose); @@ -46,6 +51,11 @@ public class [[${ServiceName}]]ServiceWorker implements Worker { this.[(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]Service = new [[${ServiceName}]]Service(unidbgProperties); } + @Autowired + public void init(UnidbgProperties unidbgProperties) { + this.unidbgProperties = unidbgProperties; + } + @Async public CompletableFuture doWork(Object param) { [[${ServiceName}]]ServiceWorker worker; @@ -67,10 +77,9 @@ public class [[${ServiceName}]]ServiceWorker implements Worker { return CompletableFuture.completedFuture(data); } - @Override - public void close() throws IOException { + @SneakyThrows + @Override public void destroy() { [(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]Service.destroy(); - log.debug("Destroy: {}", [(${#strings.toLowerCase(#strings.substring(ServiceName,0,1))})][(${#strings.substring(ServiceName,1)})]Service); } private Object exec(Object param) {