Method executeRequest =RefInvoke.findMethodExact("org.apache.http.impl.client.AbstractHttpClient",ClassLoader.getSystemClassLoader(),
"execute", HttpHost.class, HttpRequest.class,HttpContext.class);
hookhelper.hookMethod(executeRequest, newAbstractBahaviorHookCallBack(){
@Override
publicvoiddescParam(HookParam param) {
// TODO Auto-generated method stub
Logger.log_behavior("Apache Connect to URL ->");
HttpHost host = (HttpHost) param.args[0];
HttpRequest request = (HttpRequest) param.args[1];
if(request instanceoforg.apache.http.client.methods.HttpGet) {
org.apache.http.client.methods.HttpGet httpGet =(org.apache.http.client.methods.HttpGet) request;
Logger.log_behavior("HTTP Method : "+ httpGet.getMethod());
Logger.log_behavior("HTTP GET URL : "+httpGet.getURI().toString());
Header[] headers = request.getAllHeaders();
if(headers != null) {
for(inti = 0; i < headers.length;i++) {
Logger.log_behavior(headers.getName() + ":"+headers.getName());
}
}
} elseif(request instanceofHttpPost) {
HttpPost httpPost = (HttpPost) request;
Logger.log_behavior("HTTP Method : "+ httpPost.getMethod());
Logger.log_behavior("HTTP URL : "+httpPost.getURI().toString());
Header[] headers = request.getAllHeaders();
if(headers != null) {
for(inti = 0; i <headers.length; i++) {
Logger.log_behavior(headers.getName() + ":"+headers.getValue());
}
}
HttpEntity entity = httpPost.getEntity();
String contentType = null;
if(entity.getContentType() != null) {
contentType =entity.getContentType().getValue();
if(URLEncodedUtils.CONTENT_TYPE.equals(contentType)) {
try{
byte[] data =newbyte[(int) entity.getContentLength()];
entity.getContent().read(data);
String content =newString(data, HTTP.DEFAULT_CONTENT_CHARSET);
Logger.log_behavior("HTTP POST Content : "+ content);
}catch(IllegalStateException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
} catch(IOException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
}elseif(contentType.startsWith(HTTP.DEFAULT_CONTENT_TYPE)) {
try{
byte[] data =newbyte[(int) entity.getContentLength()];
entity.getContent().read(data);
String content =newString(data, contentType.substring(contentType.lastIndexOf("=") +1));
Logger.log_behavior("HTTP POST Content : "+ content);
}catch(IllegalStateException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
} catch(IOException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
}
}else{
byte[] data = newbyte[(int)entity.getContentLength()];
try{
entity.getContent().read(data);
String content =newString(data, HTTP.DEFAULT_CONTENT_CHARSET);
Logger.log_behavior("HTTP POST Content : "+ content);
} catch(IllegalStateException e){
// TODO Auto-generatedcatch block
e.printStackTrace();
} catch(IOException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
}
}
}
@Override
publicvoidafterHookedMethod(HookParam param) {
// TODO Auto-generated method stub
super.afterHookedMethod(param);
HttpResponse resp = (HttpResponse) param.getResult();
if(resp != null) {
Logger.log_behavior("Status Code = "+resp.getStatusLine().getStatusCode());
Header[] headers = resp.getAllHeaders();
if(headers != null) {
for(inti = 0; i <headers.length; i++) {
Logger.log_behavior(headers.getName() + ":"+headers.getValue());
}
}
}
}
});
对 HttpURLConnection 的 hook Zjdroid 未能提供完美的解决方案,想要取得除了 URL 之外的 data 字段必须对I/O流操作.
Method openConnectionMethod =RefInvoke.findMethodExact("java.net.URL",ClassLoader.getSystemClassLoader(), "openConnection");
hookhelper.hookMethod(openConnectionMethod,newAbstractBahaviorHookCallBack() {
@Override
publicvoiddescParam(HookParam param) {
// TODO Auto-generated method stub
URL url = (URL) param.thisObject;
Logger.log_behavior("Connect to URL ->");
Logger.log_behavior("The URL = "+ url.toString());
}
});