Skip to content

Commit 8d07810

Browse files
committed
feat: Handle packages not installed when spoofed to them
If a package being spoofed is not installed on the device, GmsCore rejects it. This can only occur when spoofing is present, which means that handling this case should be allowed as a package that does not exist and can only happen when spoofing.
1 parent 5bd31ec commit 8d07810

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

play-services-base/core/src/main/java/org/microg/gms/common/PackageUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public static boolean callerHasGooglePackagePermission(Context context, GooglePa
8181
packageCandidate
8282
);
8383

84+
// See https://github.com/ReVanced/GmsCore/issues/10.
85+
ExtendedPackageInfo extendedPackageInfo = new ExtendedPackageInfo(context, packageName);
86+
if (!extendedPackageInfo.isInstalled())
87+
return true;
88+
8489
if (new ExtendedPackageInfo(context, packageName).hasGooglePackagePermission(permission)) {
8590
return true;
8691
}
@@ -241,7 +246,7 @@ public static String getAndCheckPackage(Context context, String suggestedPackage
241246
if (packageName != null && suggestedPackageName != null && !packageName.equals(suggestedPackageName)) {
242247
throw new SecurityException("UID [" + callingUid + "] is not related to packageName [" + suggestedPackageName + "] (seems to be " + packageName + ")");
243248
}
244-
return PackageSpoofUtils.spoofPackageName(context.getPackageManager(), packageName);
249+
return packageName;
245250
}
246251

247252
@Nullable

play-services-base/core/src/main/kotlin/org/microg/gms/common/PackageSpoofUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.util.*
1010
/**
1111
* Utilities to spoof package information.
1212
*/
13-
internal object PackageSpoofUtils {
13+
object PackageSpoofUtils {
1414
private const val TAG = "SpoofUtils"
1515
private const val META_SPOOF_PACKAGE_NAME =
1616
BuildConfig.BASE_PACKAGE_NAME + ".android.gms.SPOOFED_PACKAGE_NAME"

play-services-core/src/main/java/org/microg/gms/auth/AuthManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import androidx.annotation.RequiresPermission;
1717
import com.google.android.gms.base.BuildConfig;
18+
import org.microg.gms.common.PackageSpoofUtils;
1819
import org.microg.gms.common.PackageUtils;
1920
import org.microg.gms.settings.SettingsContract;
2021

@@ -269,7 +270,10 @@ public AuthResponse requestAuth(boolean legacy) throws IOException {
269270
}
270271
AuthRequest request = new AuthRequest().fromContext(context)
271272
.source("android")
272-
.app(packageName, getPackageSignature())
273+
.app(
274+
PackageSpoofUtils.spoofPackageName(context.getPackageManager(), packageName),
275+
PackageSpoofUtils.spoofStringSignature(context.getPackageManager(), packageName, getPackageSignature())
276+
)
273277
.email(accountName)
274278
.token(getAccountManager().getPassword(account))
275279
.service(service)

play-services-core/src/main/java/org/microg/gms/auth/loginservice/AccountAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.microg.gms.auth.AuthManager;
3535
import org.microg.gms.auth.AuthResponse;
3636
import org.microg.gms.auth.login.LoginActivity;
37+
import org.microg.gms.common.PackageSpoofUtils;
3738
import org.microg.gms.common.PackageUtils;
3839

3940
import java.util.Arrays;
@@ -107,7 +108,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account accoun
107108
Intent i = new Intent(context, AskPermissionActivity.class);
108109
i.putExtras(options);
109110
i.putExtra(KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
110-
i.putExtra(KEY_ANDROID_PACKAGE_NAME, app);
111+
i.putExtra(KEY_ANDROID_PACKAGE_NAME, PackageSpoofUtils.spoofPackageName(context.getPackageManager(), app));
111112
i.putExtra(KEY_ACCOUNT_TYPE, account.type);
112113
i.putExtra(KEY_ACCOUNT_NAME, account.name);
113114
i.putExtra(KEY_AUTHTOKEN, authTokenType);

0 commit comments

Comments
 (0)