Commit a19895ec authored by swift_gan's avatar swift_gan

fix hook wrapper switch logic

parent 8966cd99
package com.swift.sandhook.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface SkipParamCheck {
}
...@@ -10,6 +10,7 @@ import com.swift.sandhook.annotation.HookReflectClass; ...@@ -10,6 +10,7 @@ import com.swift.sandhook.annotation.HookReflectClass;
import com.swift.sandhook.annotation.MethodParams; import com.swift.sandhook.annotation.MethodParams;
import com.swift.sandhook.annotation.MethodReflectParams; import com.swift.sandhook.annotation.MethodReflectParams;
import com.swift.sandhook.annotation.Param; import com.swift.sandhook.annotation.Param;
import com.swift.sandhook.annotation.SkipParamCheck;
import com.swift.sandhook.annotation.ThisObject; import com.swift.sandhook.annotation.ThisObject;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
...@@ -99,7 +100,9 @@ public class HookWrapper { ...@@ -99,7 +100,9 @@ public class HookWrapper {
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new HookErrorException("can not find target method: " + methodName, e); throw new HookErrorException("can not find target method: " + methodName, e);
} }
if (!method.isAnnotationPresent(SkipParamCheck.class)) {
checkSignature(foundMethod, method, pars); checkSignature(foundMethod, method, pars);
}
HookEntity entity = hookEntityMap.get(foundMethod); HookEntity entity = hookEntityMap.get(foundMethod);
if (entity == null) { if (entity == null) {
entity = new HookEntity(foundMethod); entity = new HookEntity(foundMethod);
...@@ -119,7 +122,9 @@ public class HookWrapper { ...@@ -119,7 +122,9 @@ public class HookWrapper {
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new HookErrorException("can not find target method: " + methodName, e); throw new HookErrorException("can not find target method: " + methodName, e);
} }
if (!method.isAnnotationPresent(SkipParamCheck.class)) {
checkSignature(foundMethod, method, pars); checkSignature(foundMethod, method, pars);
}
HookEntity entity = hookEntityMap.get(foundMethod); HookEntity entity = hookEntityMap.get(foundMethod);
if (entity == null) { if (entity == null) {
entity = new HookEntity(foundMethod); entity = new HookEntity(foundMethod);
...@@ -153,7 +158,7 @@ public class HookWrapper { ...@@ -153,7 +158,7 @@ public class HookWrapper {
return pars; return pars;
} else if (getParsCount(method) > 0) { } else if (getParsCount(method) > 0) {
if (getParsCount(method) == 1) { if (getParsCount(method) == 1) {
if (hasThisObject(method)) { if (hasThisObject(method) || Modifier.isStatic(method.getModifiers())) {
return parseMethodParsNew(classLoader, method); return parseMethodParsNew(classLoader, method);
} else { } else {
return null; return null;
...@@ -209,7 +214,7 @@ public class HookWrapper { ...@@ -209,7 +214,7 @@ public class HookWrapper {
} }
} }
try { try {
realPars[parIndex] = getRealParType(classLoader, hookPar, methodAnnos); realPars[parIndex] = getRealParType(classLoader, hookPar, methodAnnos, method.isAnnotationPresent(SkipParamCheck.class));
} catch (Exception e) { } catch (Exception e) {
throw new HookErrorException("hook method <" + method.getName() + "> parser pars error", e); throw new HookErrorException("hook method <" + method.getName() + "> parser pars error", e);
} }
...@@ -218,7 +223,7 @@ public class HookWrapper { ...@@ -218,7 +223,7 @@ public class HookWrapper {
return realPars; return realPars;
} }
private static Class getRealParType(ClassLoader classLoader, Class hookPar, Annotation[] annotations) throws Exception { private static Class getRealParType(ClassLoader classLoader, Class hookPar, Annotation[] annotations, boolean skipCheck) throws Exception {
if (annotations == null || annotations.length == 0) if (annotations == null || annotations.length == 0)
return hookPar; return hookPar;
for (Annotation annotation:annotations) { for (Annotation annotation:annotations) {
...@@ -227,7 +232,7 @@ public class HookWrapper { ...@@ -227,7 +232,7 @@ public class HookWrapper {
if (TextUtils.isEmpty(param.value())) if (TextUtils.isEmpty(param.value()))
return hookPar; return hookPar;
Class realPar = classNameToClass(param.value(), classLoader); Class realPar = classNameToClass(param.value(), classLoader);
if (realPar.equals(hookPar) || hookPar.isAssignableFrom(realPar)) { if (skipCheck || realPar.equals(hookPar) || hookPar.isAssignableFrom(realPar)) {
return realPar; return realPar;
} else { } else {
throw new ClassCastException("hook method par cast error!"); throw new ClassCastException("hook method par cast error!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment