Skip to content

Commit

Permalink
feat: Handle packages not installed when spoofed to them
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oSumAtrIX authored and WSTxda committed Mar 27, 2024
1 parent db9c07f commit 1da0634
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public static boolean callerHasGooglePackagePermission(Context context, GooglePa
packageCandidate
);

// See https://github.com/ReVanced/GmsCore/issues/10.
ExtendedPackageInfo extendedPackageInfo = new ExtendedPackageInfo(context, packageName);
if (!extendedPackageInfo.isInstalled())
return true;

if (new ExtendedPackageInfo(context, packageName).hasGooglePackagePermission(permission)) {
return true;
}
Expand Down Expand Up @@ -241,7 +246,7 @@ public static String getAndCheckPackage(Context context, String suggestedPackage
if (packageName != null && suggestedPackageName != null && !packageName.equals(suggestedPackageName)) {
throw new SecurityException("UID [" + callingUid + "] is not related to packageName [" + suggestedPackageName + "] (seems to be " + packageName + ")");
}
return PackageSpoofUtils.spoofPackageName(context.getPackageManager(), packageName);
return packageName;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.*
/**
* Utilities to spoof package information.
*/
internal object PackageSpoofUtils {
object PackageSpoofUtils {
private const val TAG = "SpoofUtils"
private const val META_SPOOF_PACKAGE_NAME =
BuildConfig.BASE_PACKAGE_NAME + ".android.gms.SPOOFED_PACKAGE_NAME"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import androidx.annotation.RequiresPermission;
import com.google.android.gms.base.BuildConfig;
import org.microg.gms.common.PackageSpoofUtils;
import org.microg.gms.common.PackageUtils;
import org.microg.gms.settings.SettingsContract;

Expand Down Expand Up @@ -269,7 +270,10 @@ public AuthResponse requestAuth(boolean legacy) throws IOException {
}
AuthRequest request = new AuthRequest().fromContext(context)
.source("android")
.app(packageName, getPackageSignature())
.app(
PackageSpoofUtils.spoofPackageName(context.getPackageManager(), packageName),
PackageSpoofUtils.spoofStringSignature(context.getPackageManager(), packageName, getPackageSignature())
)
.email(accountName)
.token(getAccountManager().getPassword(account))
.service(service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.microg.gms.auth.AuthManager;
import org.microg.gms.auth.AuthResponse;
import org.microg.gms.auth.login.LoginActivity;
import org.microg.gms.common.PackageSpoofUtils;
import org.microg.gms.common.PackageUtils;

import java.util.Arrays;
Expand Down Expand Up @@ -107,7 +108,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account accoun
Intent i = new Intent(context, AskPermissionActivity.class);
i.putExtras(options);
i.putExtra(KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
i.putExtra(KEY_ANDROID_PACKAGE_NAME, app);
i.putExtra(KEY_ANDROID_PACKAGE_NAME, PackageSpoofUtils.spoofPackageName(context.getPackageManager(), app));
i.putExtra(KEY_ACCOUNT_TYPE, account.type);
i.putExtra(KEY_ACCOUNT_NAME, account.name);
i.putExtra(KEY_AUTHTOKEN, authTokenType);
Expand Down

0 comments on commit 1da0634

Please sign in to comment.