Skip to content

Commit

Permalink
refactor(GmsCore support): Remove unnecessary constants and disable u…
Browse files Browse the repository at this point in the history
…nused services (#119)

* fix(GmsCore support): Firebase installations error

* feat: Remove unnecessary Constants (Match with uDrop)

* feat: Remove signature spoofing that degrades performance (No longer resolves playback issues)

* Move `SSLGuard disabler` to `GmsCore support` patch

* feat: Disable `PrimeApi`

* revert: Do not disable Cast V2

* feat: Disable ECatcher spam logging

* revert: Disable Advertising Id (Advertising Id can no longer be fetched from GmsCore)

---------

Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
  • Loading branch information
YT-Advanced and inotia00 authored Jan 15, 2025
1 parent 3604e92 commit 36141d0
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class GmsCoreSupport {
private static final String DONT_KILL_MY_APP_LINK
= "https://dontkillmyapp.com";

private static final String META_SPOOF_PACKAGE_NAME =
GMS_CORE_PACKAGE_NAME + ".SPOOFED_PACKAGE_NAME";

private static void open(Activity mActivity, String queryOrLink) {
Intent intent;
try {
Expand Down Expand Up @@ -178,52 +175,6 @@ private static boolean batteryOptimizationsEnabled(Context context) {
return false;
}

/**
* Injection point.
*/
public static String spoofPackageName(Context context) {
// Package name of ReVanced.
final String packageName = context.getPackageName();

try {
final PackageManager packageManager = context.getPackageManager();

// Package name of YouTube or YouTube Music.
String originalPackageName;

try {
originalPackageName = packageManager
.getPackageInfo(packageName, PackageManager.GET_META_DATA)
.applicationInfo
.metaData
.getString(META_SPOOF_PACKAGE_NAME);
} catch (PackageManager.NameNotFoundException exception) {
Logger.printDebug(() -> "Failed to parsing metadata");
return packageName;
}

if (StringUtils.isBlank(originalPackageName)) {
Logger.printDebug(() -> "Failed to parsing spoofed package name");
return packageName;
}

try {
packageManager.getPackageInfo(originalPackageName, PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException exception) {
Logger.printDebug(() -> "Original app '" + originalPackageName + "' was not found");
return packageName;
}

Logger.printDebug(() -> "Package name of '" + packageName + "' spoofed to '" + originalPackageName + "'");

return originalPackageName;
} catch (Exception ex) {
Logger.printException(() -> "spoofPackageName failure", ex);
}

return packageName;
}

private static boolean isAndroidAutomotive(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ fun baseAdsPatch(
)
}

val getAdvertisingIdMethod = with (advertisingIdFingerprint.methodOrThrow()) {
val getAdvertisingIdIndex = indexOfGetAdvertisingIdInstruction(this)
getWalkerMethod(getAdvertisingIdIndex)
}

getAdvertisingIdMethod.addInstructionsWithLabels(
0, """
invoke-static {}, $classDescriptor->$methodDescriptor()Z
move-result v0
if-nez v0, :ignore
return-void
:ignore
nop
"""
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
package app.revanced.patches.shared.ads

import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil

internal val advertisingIdFingerprint = legacyFingerprint(
name = "advertisingIdFingerprint",
returnType = "V",
strings = listOf("a."),
customFingerprint = { method, classDef ->
MethodUtil.isConstructor(method) &&
classDef.fields.find { it.type == "Ljava/util/Random;" } != null &&
indexOfGetAdvertisingIdInstruction(method) >= 0
}
)

internal fun indexOfGetAdvertisingIdInstruction(method: Method) =
method.indexOfFirstInstructionReversed {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "V" &&
reference.parameterTypes.isEmpty()
}


internal val musicAdsFingerprint = legacyFingerprint(
name = "musicAdsFingerprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import com.android.tools.smali.dexlib2.util.MethodUtil

const val GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME = "getGmsCoreVendorGroupId"

Expand All @@ -22,14 +25,24 @@ internal val castContextFetchFingerprint = legacyFingerprint(
strings = listOf("Error fetching CastContext.")
)

internal val castDynamiteModuleFingerprint = legacyFingerprint(
name = "castDynamiteModuleFingerprint",
strings = listOf("com.google.android.gms.cast.framework.internal.CastDynamiteModuleImpl")
)

internal val castDynamiteModuleV2Fingerprint = legacyFingerprint(
name = "castDynamiteModuleV2Fingerprint",
strings = listOf("Failed to load module via V2: ")
)

internal val googlePlayUtilityFingerprint = legacyFingerprint(
name = "castContextFetchFingerprint",
name = "googlePlayUtilityFingerprint",
returnType = "I",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L", "I"),
strings = listOf(
"This should never happen.",
"MetadataValueReader"
"MetadataValueReader",
)
)

Expand All @@ -41,23 +54,57 @@ internal val serviceCheckFingerprint = legacyFingerprint(
strings = listOf("Google Play Services not available")
)

internal val primeMethodFingerprint = legacyFingerprint(
name = "primeMethodFingerprint",
strings = listOf("com.google.android.GoogleCamera", "com.android.vending")
internal val sslGuardFingerprint = legacyFingerprint(
name = "sslGuardFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
strings = listOf("Cannot initialize SslGuardSocketFactory will null"),
)

internal val certificateFingerprint = legacyFingerprint(
name = "certificateFingerprint",
returnType = "Ljava/lang/String;",
accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = emptyList(),
strings = listOf("X.509", "user", "S"),
internal val eCatcherFingerprint = legacyFingerprint(
name = "eCatcherFingerprint",
returnType = "V",
opcodes = listOf(Opcode.NEW_ARRAY),
strings = listOf("ECatcher disabled: level: %s, category: %s, message: %s"),
customFingerprint = { method, _ ->
indexOfGetPackageNameInstruction(method) >= 0
method.parameterTypes.contains("Ljava/util/function/Function;")
},
)

internal val primesApiFingerprint = legacyFingerprint(
name = "primesApiFingerprint",
returnType = "V",
strings = listOf("PrimesApiImpl.java"),
customFingerprint = { method, _ ->
MethodUtil.isConstructor(method)
}
)

internal val primesBackgroundInitializationFingerprint = legacyFingerprint(
name = "primesBackgroundInitializationFingerprint",
opcodes = listOf(Opcode.NEW_INSTANCE),
customFingerprint = { method, _ ->
method.indexOfFirstInstruction {
opcode == Opcode.CONST_STRING &&
getReference<StringReference>()
?.string.toString()
.startsWith("Primes init triggered from background in package:")
} >= 0
}
)

fun indexOfGetPackageNameInstruction(method: Method) =
method.indexOfFirstInstruction {
getReference<MethodReference>()?.toString() == "Landroid/content/Context;->getPackageName()Ljava/lang/String;"
}
internal val primesLifecycleEventFingerprint = legacyFingerprint(
name = "primesLifecycleEventFingerprint",
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
returnType = "V",
parameters = emptyList(),
opcodes = listOf(Opcode.NEW_INSTANCE),
customFingerprint = { method, _ ->
method.indexOfFirstInstruction {
opcode == Opcode.CONST_STRING &&
getReference<StringReference>()
?.string.toString()
.startsWith("Primes did not observe lifecycle events in the expected order.")
} >= 0
}
)
Loading

0 comments on commit 36141d0

Please sign in to comment.