diff --git a/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java b/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java index d1f8cecc..d3acf000 100644 --- a/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java +++ b/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java @@ -17,37 +17,38 @@ public final class EntryPoint { static { try { - KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); - keyStore.load(null); + spoofProvider(); + } catch (Throwable t) { + LOG("spoofProvider exception: " + t); + } + } - Field f = keyStore.getClass().getDeclaredField("keyStoreSpi"); - f.setAccessible(true); - CustomKeyStoreSpi.keyStoreSpi = (KeyStoreSpi) f.get(keyStore); - f.setAccessible(false); + private static void spoofProvider() throws Exception { + KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); + keyStore.load(null); - Provider provider = Security.getProvider("AndroidKeyStore"); + Field f = keyStore.getClass().getDeclaredField("keyStoreSpi"); + f.setAccessible(true); + CustomKeyStoreSpi.keyStoreSpi = (KeyStoreSpi) f.get(keyStore); + f.setAccessible(false); - Provider customProvider = new CustomProvider(provider); + Provider provider = Security.getProvider("AndroidKeyStore"); - Security.removeProvider("AndroidKeyStore"); - Security.insertProviderAt(customProvider, 1); + Provider customProvider = new CustomProvider(provider); - LOG("Spoof KeyStoreSpi and Provider done!"); + Security.removeProvider("AndroidKeyStore"); + Security.insertProviderAt(customProvider, 1); - } catch (Throwable t) { - LOG("spoofProvider exception: " + t); - } + LOG("Spoof KeyStoreSpi and Provider done!"); } public static void init(String json) { - try { jsonObject = new JSONObject(json); + spoofDevice(); } catch (JSONException e) { LOG("Couldn't parse JSON from Zygisk"); } - - spoofDevice(); } static void LOG(String msg) { @@ -69,27 +70,15 @@ private static void setFieldValue(String name, Object value) { if (value instanceof String str) if (str.isEmpty() || str.isBlank()) return; - Field field = null; - - try { - field = Build.class.getDeclaredField(name); - } catch (NoSuchFieldException e) { - try { - field = Build.VERSION.class.getDeclaredField(name); - } catch (NoSuchFieldException ex) { - LOG("Couldn't find field: " + e); - } - } + Field field = getField(name); if (field == null) return; field.setAccessible(true); try { - Object oldValue = field.get(null); if (!value.equals(oldValue)) { - field.set(null, value); LOG("Set [" + name + "] field value to [" + value + "]"); } @@ -99,4 +88,20 @@ private static void setFieldValue(String name, Object value) { } field.setAccessible(false); } -} \ No newline at end of file + + private static Field getField(String name) { + Field field = null; + + try { + field = Build.class.getDeclaredField(name); + } catch (NoSuchFieldException e) { + try { + field = Build.VERSION.class.getDeclaredField(name); + } catch (NoSuchFieldException ex) { + LOG("Couldn't find field: " + e); + } + } + + return field; + } +}