Skip to content

Commit

Permalink
feat:新增实验功能-抓包
Browse files Browse the repository at this point in the history
  • Loading branch information
pengboli committed Jun 23, 2021
1 parent 8e6f091 commit a541e01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/leon/qujing/api/wsMethodView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Process;

import com.alibaba.fastjson.JSON;

import org.json.JSONArray;
import org.json.JSONObject;

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/leon/qujing/api/wsPacketView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package leon.qujing.api;

import android.annotation.SuppressLint;
import android.text.Html;
import android.util.Base64;

import com.alibaba.fastjson.JSON;
Expand Down Expand Up @@ -81,9 +82,9 @@ private void collectAndPack(Socket socket, byte[] body, int byteCount, String fl
msg.put("remote_ip", inetAddr.getHostAddress());
msg.put("remote_host", inetAddr.getHostName());
msg.put("remote_port", socket.getPort()+"");
msg.put("body_plain", new String(body, "UTF-8"));
msg.put("body_hexdump", Utils.formatHexDump(body, 0, body.length));;
msg.put("body_base64", Base64.encodeToString(body, Base64.NO_WRAP));
msg.put("body_plain", Html.escapeHtml(new String(body, 0, byteCount,"UTF-8")));
msg.put("body_hexdump", Utils.formatHexDump(body, 0, byteCount));;
msg.put("body_base64", Base64.encodeToString(body, 0, byteCount, Base64.NO_WRAP));
msg.put("body_length", byteCount+"");
sendMsg("add", msg);
}
Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/leon/qujing/objectparser/StoredObjectParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,14 @@ public String generate(Object obj) {
try{
Field fields[] = obj.getClass().getDeclaredFields();
for (Field field:fields) {
// 只处理public属性
// Handle public field only
//if(field.isAccessible()){
field.setAccessible(true);
Object fieldObj = field.get(obj);
Log.e("QuJingServer", "SOParser Field: " + field.getName() + "@" + Utils.getTypeSignature(fieldObj.getClass()));
// 只处理原始类型,避免循环引用
// Handle primitive type only, avoid cell.
if(fieldObj.getClass().isPrimitive()||parsers.get(Utils.getTypeSignature(fieldObj.getClass()))!=null){
fieldmap.put(field.getName(),ObjectHandler.saveObject(fieldObj));
}
//}
field.setAccessible(true);
Object fieldObj = field.get(obj);
Log.e("QuJingServer", "SOParser Field: " + field.getName() + "@" + Utils.getTypeSignature(fieldObj.getClass()));
// 只处理原始类型,避免循环引用
// Handle primitive type only, avoid cell.
if(fieldObj.getClass().isPrimitive()||parsers.get(Utils.getTypeSignature(fieldObj.getClass()))!=null){
fieldmap.put(field.getName(),ObjectHandler.saveObject(fieldObj));
}
}
}catch (Exception e){
Log.e("QuJingServer", "SOParser: " + e.getLocalizedMessage() );
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/leon/qujing/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.text.Html;
import android.util.Base64;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -251,21 +252,21 @@ public static String formatHexDump(byte[] array, int offset, int length) {
StringBuilder builder = new StringBuilder();

for (int rowOffset = offset; rowOffset < offset + length; rowOffset += width) {
builder.append(String.format("%06X ", rowOffset));
builder.append(String.format("%06X | ", rowOffset));

for (int index = 0; index < width; index++) {
if (rowOffset + index < array.length) {
if (rowOffset + index < offset + length) {
builder.append(String.format("%02x ", array[rowOffset + index]));
} else {
builder.append(" ");
}
}

if (rowOffset < array.length) {
int asciiWidth = Math.min(width, array.length - rowOffset);
if (rowOffset < offset + length) {
int asciiWidth = Math.min(width, offset + length - rowOffset);
builder.append(" | ");
try {
builder.append(new String(array, rowOffset, asciiWidth, "UTF-8").replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " "));
builder.append(Html.escapeHtml(new String(array, rowOffset, asciiWidth, "UTF-8").replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " ")));
} catch (UnsupportedEncodingException ignored) {
//If UTF-8 isn't available as an encoding then what can we do?!
}
Expand Down

0 comments on commit a541e01

Please sign in to comment.