Skip to content

Commit

Permalink
重构了批量跟踪功能。
Browse files Browse the repository at this point in the history
可以实时地根据正则表达式调整被Hook的方法列表,更加智能和方便了。
  • Loading branch information
Monkeylord committed Jul 24, 2019
1 parent 45434ef commit 7fabf96
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions app/src/main/java/monkeylord/XServer/XServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Process;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
Expand All @@ -22,6 +23,7 @@
import monkeylord.XServer.api.wsTracerNew;
import monkeylord.XServer.handler.ObjectHandler;
import monkeylord.XServer.objectparser.ByteArrayParser;
import monkeylord.XServer.objectparser.GenericParser;
import monkeylord.XServer.objectparser.IntParser;
import monkeylord.XServer.objectparser.StoredObjectParser;
import monkeylord.XServer.objectparser.StringParser;
Expand All @@ -40,7 +42,8 @@ public XServer(int port) {
public XServer(int port, Hashtable<String, Operation> route) {
super(port);
//注册对象序列化/反序列化处理器
parsers.put("general", new StoredObjectParser());
parsers.put("store", new StoredObjectParser());
parsers.put("generic", new GenericParser());
parsers.put("string", new StringParser());
parsers.put("int", new IntParser());
parsers.put("Ljava.lang.Integer;", new IntParser());
Expand Down Expand Up @@ -92,7 +95,12 @@ public Response serveHttp(IHTTPSession session) {
String uri = session.getUri();
//处理路由
Operation operation = route.get(uri.toLowerCase());
if (operation == null) operation = route.get("/");
if (operation == null)try{
XposedEntry.res.getAssets().open(uri.substring(1));
operation = new assets();
}catch (IOException e){
operation = route.get("/");
}
return newFixedLengthResponse(operation.handle(uri, session.getParms(), headers, files));
}
//供动态注册路由使用
Expand All @@ -110,6 +118,15 @@ public static String render(Map<String, Object> model, String page) throws IOExc
tmp.process(model, sw);
return sw.toString();
}
public static String file(String page) throws IOException, TemplateException {
InputStreamReader reader = new InputStreamReader(XposedEntry.res.getAssets().open(page));
int ch;
StringWriter sw = new StringWriter();
while ((ch = reader.read())!=-1){
sw.write(ch);
}
return sw.toString();
}

//定义序列化/反序列化器
public interface ObjectParser {
Expand Down Expand Up @@ -143,4 +160,16 @@ public String handle(String url, Map<String, String> parms, Map<String, String>
}
}
}
// 资源文件
public class assets implements XServer.Operation {
@Override
public String handle(String url, Map<String, String> parms, Map<String, String> headers, Map<String, String> files) {
try {
Map<String, Object> map = new HashMap<String, Object>();
return file(url.substring(1));
} catch (Exception e) {
return e.getLocalizedMessage();
}
}
}
}

0 comments on commit 7fabf96

Please sign in to comment.