Skip to content

Commit

Permalink
Merge pull request #208 from tryigit/patch-2
Browse files Browse the repository at this point in the history
Update EntryPoint.java
  • Loading branch information
chiteroman authored Jan 15, 2024
2 parents a246eb8 + 5e6f43e commit 931fd3d
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 + "]");
}
Expand All @@ -99,4 +88,20 @@ private static void setFieldValue(String name, Object value) {
}
field.setAccessible(false);
}
}

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;
}
}

0 comments on commit 931fd3d

Please sign in to comment.