Skip to content

Commit

Permalink
feat: support unidbg 0.9.7
Browse files Browse the repository at this point in the history
Signed-off-by: AnJia <[email protected]>
  • Loading branch information
anjia0532 committed Aug 28, 2023
1 parent 340e166 commit 2268112
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
27 changes: 18 additions & 9 deletions src/test/resources/templates/ServiceWorker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,58 @@ 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);
log.info("是否启用动态引擎:{},是否打印详细信息:{}", dynarmic, verbose);
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<Object> doWork(Object param) {
[[${ServiceName}]]ServiceWorker worker;
Expand All @@ -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) {
Expand Down

0 comments on commit 2268112

Please sign in to comment.