diff --git a/rasp/jvm/JVMAgent/src/main/java/com/security/smithloader/SmithAgent.java b/rasp/jvm/JVMAgent/src/main/java/com/security/smithloader/SmithAgent.java index 2e750d8dc..4f7b3d0d2 100644 --- a/rasp/jvm/JVMAgent/src/main/java/com/security/smithloader/SmithAgent.java +++ b/rasp/jvm/JVMAgent/src/main/java/com/security/smithloader/SmithAgent.java @@ -56,7 +56,15 @@ public static void PreProxy(Object MethodNameObj,int classID, int methodID, Obje if(SmithProberProxyObj != null) { String MethodName = (String)MethodNameObj; Class[] argType = new Class[]{int.class,int.class,Object[].class}; - Reflection.invokeMethod(SmithProberProxyObj,MethodName,argType,classID,methodID,args); + try { + Reflection.invokeMethod(SmithProberProxyObj,MethodName,argType,classID,methodID,args); + } catch (Throwable e) { + if (checkRecursive != null && checkRecursive.get() == true) { + checkRecursive.set(false); + } + throw e; + } + } if (checkRecursive != null && checkRecursive.get() == true) { checkRecursive.set(false); @@ -254,6 +262,7 @@ private static class MyCallable implements Callable { public String call() throws Exception { xLoaderLock.lock(); try { + System.setProperty("smith.rasp", ""); if(SmithProberObj != null) { String agent = System.getProperty("rasp.probe"); @@ -268,7 +277,7 @@ public String call() throws Exception { SmithProberClazz = null; } - System.setProperty("smith.rasp", ""); + if (!checkMemoryAvailable()) { System.setProperty("smith.status", "memory not enough"); SmithAgentLogger.logger.warning("checkMemory failed"); diff --git a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterDeserializer.java b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterDeserializer.java index 12c68350d..e2117d927 100644 --- a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterDeserializer.java +++ b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterDeserializer.java @@ -31,18 +31,23 @@ private StackTraceElement[] convertStackTrace(String[] stackTrace) { if (stackTrace == null) return new StackTraceElement[0]; - StackTraceElement[] result = new StackTraceElement[stackTrace.length]; - for (int i = 0; i < stackTrace.length; i++) { - String[] parts = stackTrace[i].split(","); - if (parts.length != 4) { - continue; + try { + StackTraceElement[] result = new StackTraceElement[stackTrace.length]; + for (int i = 0; i < stackTrace.length; i++) { + String[] parts = stackTrace[i].split(","); + if (parts.length != 4) { + continue; + } + String className = parts[0].trim(); + String methodName = parts[1].trim(); + String fileName = parts[2].trim(); + int lineNumber = Integer.parseInt(parts[3].trim()); + result[i] = new StackTraceElement(className, methodName, fileName, lineNumber); } - String className = parts[0].trim(); - String methodName = parts[1].trim(); - String fileName = parts[2].trim(); - int lineNumber = Integer.parseInt(parts[3].trim()); - result[i] = new StackTraceElement(className, methodName, fileName, lineNumber); + return result; + } catch (Exception e) { } - return result; + + return new StackTraceElement[0]; } } \ No newline at end of file diff --git a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterSerializer.java b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterSerializer.java index 3555aaa91..6cc7546ff 100644 --- a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterSerializer.java +++ b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/ClassFilterSerializer.java @@ -32,14 +32,17 @@ public JsonElement serialize(ClassFilter src, Type typeOfSrc, JsonSerializationC private String[] convertStackTrace(StackTraceElement[] stackTrace) { if (stackTrace.length <= 2) return new String[0]; + try { + StackTraceElement[] elements = Arrays.copyOfRange(stackTrace, 2, stackTrace.length); + String[] result = new String[elements.length]; - StackTraceElement[] elements = Arrays.copyOfRange(stackTrace, 2, stackTrace.length); - String[] result = new String[elements.length]; + for (int i = 0; i < elements.length; i++) { + result[i] = elements[i].toString(); + } - for (int i = 0; i < elements.length; i++) { - result[i] = elements[i].toString(); + return result; + } catch (Exception e) { } - - return result; + return new String[0]; } } \ No newline at end of file diff --git a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceDeserializer.java b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceDeserializer.java index 7a01accf7..d753adc80 100644 --- a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceDeserializer.java +++ b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceDeserializer.java @@ -23,21 +23,26 @@ public Trace deserialize(JsonElement json, Type typeOfT, com.google.gson.JsonDes } private StackTraceElement[] convertStackTrace(String[] stackTrace) { + StackTraceElement[] ret = new StackTraceElement[0]; if (stackTrace == null) - return new StackTraceElement[0]; + return ret; - StackTraceElement[] result = new StackTraceElement[stackTrace.length]; - for (int i = 0; i < stackTrace.length; i++) { - String[] parts = stackTrace[i].split(","); - if (parts.length != 4) { - continue; + try { + StackTraceElement[] result = new StackTraceElement[stackTrace.length]; + for (int i = 0; i < stackTrace.length; i++) { + String[] parts = stackTrace[i].split(","); + if (parts.length != 4) { + continue; + } + String className = parts[0].trim(); + String methodName = parts[1].trim(); + String fileName = parts[2].trim(); + int lineNumber = Integer.parseInt(parts[3].trim()); + result[i] = new StackTraceElement(className, methodName, fileName, lineNumber); } - String className = parts[0].trim(); - String methodName = parts[1].trim(); - String fileName = parts[2].trim(); - int lineNumber = Integer.parseInt(parts[3].trim()); - result[i] = new StackTraceElement(className, methodName, fileName, lineNumber); + return result; + } catch (Exception e) { } - return result; + return ret; } } \ No newline at end of file diff --git a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceSerializer.java b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceSerializer.java index d033551cd..4204fd0ee 100644 --- a/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceSerializer.java +++ b/rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/message/TraceSerializer.java @@ -25,30 +25,47 @@ public JsonElement serialize(Trace src, Type typeOfSrc, JsonSerializationContext } private String convertRet(Object value) { - return String.valueOf(value); + String ret = ""; + if (value == null) + return ret; + try { + ret = String.valueOf(value); + } catch (Exception e) { + } + return ret; } private String[] convertArgs(Object[] value) { + String[] ret = new String[0]; if (value == null) - return new String[0]; + return ret; String[] result = new String[value.length]; - for (int i = 0; i < value.length; i++) { - result[i] = String.valueOf(value[i]); + try { + for (int i = 0; i < value.length; i++) { + result[i] = String.valueOf(value[i]); + } + } catch (Exception e) { } + return result; } private String[] convertStackTrace(StackTraceElement[] stackTrace) { + String[] ret = new String[0]; if (stackTrace == null || stackTrace.length <= 2) - return new String[0]; + return ret; - StackTraceElement[] elements = Arrays.copyOfRange(stackTrace, 2, stackTrace.length); - String[] result = new String[elements.length]; + try { + StackTraceElement[] elements = Arrays.copyOfRange(stackTrace, 2, stackTrace.length); + String[] result = new String[elements.length]; - for (int i = 0; i < elements.length; i++) { - result[i] = elements[i].toString(); - } + for (int i = 0; i < elements.length; i++) { + result[i] = elements[i].toString(); + } - return result; + return result; + } catch (Exception e) { + } + return ret; } } \ No newline at end of file