diff --git a/app/src/main/java/leon/qujing/api/wsMethodView.java b/app/src/main/java/leon/qujing/api/wsMethodView.java index df49cfa..967c16c 100644 --- a/app/src/main/java/leon/qujing/api/wsMethodView.java +++ b/app/src/main/java/leon/qujing/api/wsMethodView.java @@ -3,7 +3,6 @@ import android.os.Process; import com.alibaba.fastjson.JSON; - import org.json.JSONArray; import org.json.JSONObject; diff --git a/app/src/main/java/leon/qujing/api/wsPacketView.java b/app/src/main/java/leon/qujing/api/wsPacketView.java index 2f50d1d..2edd5f0 100644 --- a/app/src/main/java/leon/qujing/api/wsPacketView.java +++ b/app/src/main/java/leon/qujing/api/wsPacketView.java @@ -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; @@ -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); } diff --git a/app/src/main/java/leon/qujing/objectparser/StoredObjectParser.java b/app/src/main/java/leon/qujing/objectparser/StoredObjectParser.java index 85b1367..5228f95 100644 --- a/app/src/main/java/leon/qujing/objectparser/StoredObjectParser.java +++ b/app/src/main/java/leon/qujing/objectparser/StoredObjectParser.java @@ -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() ); diff --git a/app/src/main/java/leon/qujing/utils/Utils.java b/app/src/main/java/leon/qujing/utils/Utils.java index 2228ec2..57cc7ff 100644 --- a/app/src/main/java/leon/qujing/utils/Utils.java +++ b/app/src/main/java/leon/qujing/utils/Utils.java @@ -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; @@ -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?! }