Skip to content

Commit

Permalink
Fix java.lang.ClassCastException in verifyV1Signature (#37)
Browse files Browse the repository at this point in the history
java.lang.ClassCastException: Cannot cast android.content.pm.PackageParser$SigningDetails to android.util.apk.ApkSignatureVerifier$SigningDetailsWithDigests

Signed-off-by: sekaiacg <[email protected]>
  • Loading branch information
sekaiacg authored Dec 9, 2021
1 parent b4102e3 commit 204ba1d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/src/main/java/toolkit/coderstory/CorePatchForR.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;

import de.robv.android.xposed.IXposedHookLoadPackage;
Expand Down Expand Up @@ -152,14 +153,23 @@ public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable
signingDetailsArgs[0] = lastSigs;
} else {
signingDetailsArgs[0] = new Signature[]{new Signature(SIGNATURE)};
}
final Object newInstance = findConstructorExact.newInstance(signingDetailsArgs);
Throwable cause = throwable.getCause();
if (throwable.getClass() == packageParserException) {
if (error.getInt(throwable) == -103) {
methodHookParam.setResult(newInstance);
}
}
}
Object newInstance = findConstructorExact.newInstance(signingDetailsArgs);

//修复 java.lang.ClassCastException: Cannot cast android.content.pm.PackageParser$SigningDetails to android.util.apk.ApkSignatureVerifier$SigningDetailsWithDigests
Class<?> signingDetailsWithDigests = XposedHelpers.findClassIfExists("android.util.apk.ApkSignatureVerifier.SigningDetailsWithDigests", loadPackageParam.classLoader);
if (signingDetailsWithDigests != null) {
Constructor<?> signingDetailsWithDigestsConstructorExact = XposedHelpers.findConstructorExact(signingDetailsWithDigests, signingDetails, Map.class);
signingDetailsWithDigestsConstructorExact.setAccessible(true);
newInstance = signingDetailsWithDigestsConstructorExact.newInstance(new Object[]{newInstance, null});
}

Throwable cause = throwable.getCause();
if (throwable.getClass() == packageParserException) {
if (error.getInt(throwable) == -103) {
methodHookParam.setResult(newInstance);
}
}
if (cause != null && cause.getClass() == packageParserException) {
if (error.getInt(cause) == -103) {
methodHookParam.setResult(newInstance);
Expand Down

0 comments on commit 204ba1d

Please sign in to comment.