Skip to content

Commit

Permalink
fix: standalone: do not perform CHA lookup in invokeOriginalMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Oct 24, 2024
1 parent 087cf54 commit b1c490d
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,16 @@ private static Object invokeOriginalMemberImpl(@NonNull Member method, @Nullable
Objects.requireNonNull(method, "method");
Objects.requireNonNull(args, "args");
checkMemberValid(method);
boolean hasThis = (method instanceof Constructor) || !Modifier.isStatic(method.getModifiers());
// Constructors may have a static modifier, for <clinit>()V, if anyone is trying to hook it.
boolean hasThis = !Modifier.isStatic(method.getModifiers());
if (hasThis && thisObject == null) {
throw new NullPointerException("thisObject is null for method " + method);
}
// CHA lookup
method = Reflex.virtualMethodLookup(method, thisObject);
if (Modifier.isAbstract(method.getModifiers())) {
// Anyone trying to call invokeOriginalMethod on an abstract method?
// CHA lookup in case anyone really does that
method = Reflex.virtualMethodLookup(method, thisObject);
}
// perform a lookup
Class<?> declaringClass = method.getDeclaringClass();
declaringClass.cast(thisObject);
Expand All @@ -403,7 +407,7 @@ private static Object invokeOriginalMemberImpl(@NonNull Member method, @Nullable
Method backup = token.getBackupMember();
return backup.invoke(thisObject, args);
} else {
// method is not hooked, invoke the original method/copnstructor directly
// method is not hooked, invoke the original method/constructor directly
return Natives.invokeNonVirtualArtMethodNoDeclaringClassCheck(method, declaringClass, thisObject, args);
}
}
Expand Down

0 comments on commit b1c490d

Please sign in to comment.