Skip to content

feat: Add Spoof app signature patch #5158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

MarkusTieger
Copy link
Contributor

@MarkusTieger MarkusTieger commented Jun 10, 2025

Some custom roms have a patch, that adds a "FAKE_PACKAGE_SIGNATURE" permission, which allows the app to be seen with an other signature by other apps.
It is used for example by MicroG (to pretend to be GooglePlayServices).

Not every custom rom has it by default, and some only with the microg signature hardcoded. If it is supported though, I think its a better alternative to the "Mount install".

@oSumAtrIX
Copy link
Member

By patch you can read the app manifest forvm the signature. Please try that

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 11, 2025

By patch you can read the app manifest forvm thwee signature. Please try that

Only in signature version below 3 (there are 4 different versions how to sign an apk by now). Try to look into the youtube.apk, you will notice no certs in META-INF (it uses version 3)

If I had missed something, let me know

Site note: the source stamp which exists in the apk root is something entirely different than the signer certificate

@oSumAtrIX
Copy link
Member

In this case add a patch option to manually input the signature for the patch

@MarkusTieger
Copy link
Contributor Author

In this case add a patch option to manually input the signature for the patch

In addition or as replacement?

@oSumAtrIX
Copy link
Member

I dont know what you mean by in addition but if v4 cant be obtained from inside a patch, you can still ask user to manually input it in a patch option

@MarkusTieger MarkusTieger force-pushed the spoof_signature branch 2 times, most recently from 793c0f2 to b112417 Compare June 11, 2025 13:53
@MarkusTieger MarkusTieger changed the title Added spoof signature patch for youtube Added spoof signature patch Jun 11, 2025
@MarkusTieger MarkusTieger changed the base branch from main to dev June 11, 2025 14:47
@MarkusTieger MarkusTieger changed the title Added spoof signature patch feat: Added spoof signature patch Jun 11, 2025
@Nuckyz Nuckyz changed the title feat: Added spoof signature patch feat: Add Spoof signature patch Jun 11, 2025
@Nuckyz Nuckyz changed the title feat: Add Spoof signature patch feat: Add spoof signature patch Jun 11, 2025
@LisoUseInAIKyrios LisoUseInAIKyrios changed the title feat: Add spoof signature patch feat: Add Spoof app signature patch Jun 12, 2025
@MarkusTieger MarkusTieger force-pushed the spoof_signature branch 2 times, most recently from e0407aa to 8752d06 Compare June 12, 2025 20:09
@MarkusTieger MarkusTieger requested a review from oSumAtrIX June 12, 2025 20:09
@LisoUseInAIKyrios
Copy link
Contributor

Yes a fix is needed.

@LisoUseInAIKyrios
Copy link
Contributor

It might be proguard stripping away the library.

Try running a full release (proguard is run there) and the issue may show up with using CLI tools.

@MarkusTieger
Copy link
Contributor Author

It might be proguard stripping away the library.

Try running a full release (proguard is run there) and the issue may show up with using CLI tools.

It probably doesn't get shaded in and only works, because the exact same lib is present in https://github.com/ReVanced/revanced-library, used by revanced-cli.
Revanced Manager also uses "revanced-library", but there it probably hasn't the same package name, because proguard.

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 28, 2025

It might be proguard stripping away the library.

Try running a full release (proguard is run there) and the issue may show up with using CLI tools.

Should I try to shade the dependency in or should I rather declare "apksig" as dependency that has to be present unobfuscated all the time?

@LisoUseInAIKyrios
Copy link
Contributor

@oSumAtrIX what do you think?

Comment on lines +89 to +93
} catch (_: IOException) {
} catch (_: InvalidPathException) {
} catch (_: ApkFormatException) {
} catch (_: NoSuchAlgorithmException) {
} catch (_: IllegalArgumentException) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldve just used runCatching { }

val manifest = document.getNode("manifest") as Element

val fakeSignaturePermission = document.createElement("uses-permission")
fakeSignaturePermission.setAttribute("android:name", "android.permission.FAKE_PACKAGE_SIGNATURE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.apply shouldve been used


val fakeSignaturePermission = document.createElement("uses-permission")
fakeSignaturePermission.setAttribute("android:name", "android.permission.FAKE_PACKAGE_SIGNATURE")
manifest.appendChild(fakeSignaturePermission)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.let(manifest::appendChild) shouldve been used

Comment on lines +44 to +46
val child = document.createElement("application")
manifest.appendChild(child)
child
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.also(manifest::appendChild) shouldve been used

Comment on lines +49 to +52
val fakeSignatureMetadata = document.createElement("meta-data")
fakeSignatureMetadata.setAttribute("android:name", "fake-signature")
fakeSignatureMetadata.setAttribute("android:value", optionToSignature(signature))
application.appendChild(fakeSignatureMetadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply and let shouldve been used here

}
}

internal fun optionToSignature(signature: String?): String? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldve been private

@LisoUseInAIKyrios
Copy link
Contributor

I meant, what do you think about the apksig issue with Manager.

}
}

internal fun optionToSignature(signature: String?): String? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator should just check if input is a valid path, because a path is never a signature, not sure what is going on here.

@oSumAtrIX
Copy link
Member

I meant, what do you think about the apksig issue with Manager.

https://github.com/ReVanced/revanced-patches/pull/5158/files#diff-ce28239b6580555cc53f4c64582939f753c84d0bb42e44dd1a601a6fa6829a0dR19

This line shades apksig into the patches and thus is accessible from the patches classloader.

@oSumAtrIX
Copy link
Member

I don't understand how it can be class not found

@LisoUseInAIKyrios
Copy link
Contributor

Is proguard stripping away the library during release?

@oSumAtrIX
Copy link
Member

The dependency is added to the gradle module where the java plugin is applied, not the android plugin, so I don't think proguard strips it away. Check the .dex file classes

@MarkusTieger
Copy link
Contributor Author

The dependency is added to the gradle module where the java plugin is applied, not the android plugin, so I don't think proguard strips it away. Check the .dex file classes

There are no dependencies in patches/build/revanced/classes.dex, haven't been able to open the .rvp file.
It seems to be, again, that the dependency isn't shaded in. Also by default, the "java" plugin doesn't shade dependencies.

@oSumAtrIX
Copy link
Member

Run the buildAndroid task, the final rvp has the dex in it

@MarkusTieger
Copy link
Contributor Author

Run the buildAndroid task, the final rvp has the dex in it

Nope, the "rvp" from my build, nor the one from the release contains the dependency (or dependencies at all)

@oSumAtrIX
Copy link
Member

Check the rvp file for .class files

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 28, 2025

Check the rvp file for .class files

Nope, not in the classes.dex and also not as .class files.

Steps to reproduce my results:

  • ./gradlew :patches:buildAndroid
  • cd patches/build/libs
  • mkdir extracted
  • unzip patches-<version>.rvp -d extracted
  • cd extracted
  • Notice no dependencies as .class files
  • Open the classes.dex with jadx
  • Notice, only "app.revanced.*" packages

@kitadai31
Copy link
Contributor

kitadai31 commented Jun 28, 2025

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar.
For this reason, afaik ReVanced Patches would not normally be able to use external libraries.

The reason that this patch is currently working on the ReVanced CLI is due to the coincidence that the ReVanced CLI depends on apksig.

ReVanced Manager also depends on apksig, but unlike ReVanced CLI, ProGuard shrinks and obfuscates the apksig library except for "internal" package.
https://github.com/ReVanced/revanced-manager/blob/875ce6439d7692d6678c0fd3173452fbff162137/android/app/proguard-rules.pro#L7
Therefore, apksig library cannot be used from patches on the ReVanced Manager.

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 28, 2025

It might be proguard stripping away the library.
Try running a full release (proguard is run there) and the issue may show up with using CLI tools.

Should I try to shade the dependency in or should I rather declare "apksig" as dependency that has to be present unobfuscated all the time?

Now to this question again

I would prefer the second option. It is present anyway, it just has to be removed from every project (because then it would be duplicate) and added to the "revanced-patcher" as dependency, making it available to the patches as well as the cli and manager. It then also needs to be whitelisted in the revanced-manager in the proguard rules.

@oSumAtrIX
Copy link
Member

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar. For this reason, afaik ReVanced Patches would not normally be able to use external libraries.

The reason that this patch is currently working on the ReVanced CLI is due to the coincidence that the ReVanced CLI depends on apksig.

ReVanced Manager also depends on apksig, but unlike ReVanced CLI, ProGuard shrinks and obfuscates the apksig library except for "internal" package. ReVanced/revanced-manager@875ce64/android/app/proguard-rules.pro#L7 Therefore, apksig library cannot be used from patches on the ReVanced Manager.

Patches is using the java plugin:

https://github.com/ReVanced/revanced-patches-gradle-plugin/blob/dev/src/main/kotlin/app/revanced/patches/gradle/PatchesPlugin.kt#L80

So all dependencies are shaded into the JAR.

@oSumAtrIX
Copy link
Member

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar.

I am not sure, but applying the shadow plugin should make patches contain all dependencies. This can be added to the patches gradle plugin. However, how are duplicate classes handled? If its shaded into patches jar and cli also has it, I am not sure if any issues would occur.

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 28, 2025

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar. For this reason, afaik ReVanced Patches would not normally be able to use external libraries.
The reason that this patch is currently working on the ReVanced CLI is due to the coincidence that the ReVanced CLI depends on apksig.
ReVanced Manager also depends on apksig, but unlike ReVanced CLI, ProGuard shrinks and obfuscates the apksig library except for "internal" package. ReVanced/revanced-manager@875ce64/android/app/proguard-rules.pro#L7 Therefore, apksig library cannot be used from patches on the ReVanced Manager.

Patches is using the java plugin:

https://github.com/ReVanced/revanced-patches-gradle-plugin/blob/dev/src/main/kotlin/app/revanced/patches/gradle/PatchesPlugin.kt#L80

So all dependencies are shaded into the JAR.

The java plugin doesn't shade dependencies. Thats why the "shadow" plugin exists.

@MarkusTieger
Copy link
Contributor Author

MarkusTieger commented Jun 28, 2025

It might be proguard stripping away the library.
Try running a full release (proguard is run there) and the issue may show up with using CLI tools.

Should I try to shade the dependency in or should I rather declare "apksig" as dependency that has to be present unobfuscated all the time?

Now to this question again

I would prefer the second option. It is present anyway, it just has to be removed from every project (because then it would be duplicate) and added to the "revanced-patcher" as dependency, making it available to the patches as well as the cli and manager. It then also needs to be whitelisted in the revanced-manager in the proguard rules.

Now it would be great if this question could be answered

@LisoUseInAIKyrios
Copy link
Contributor

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar.

I am not sure, but applying the shadow plugin should make patches contain all dependencies. This can be added to the patches gradle plugin. However, how are duplicate classes handled? If its shaded into patches jar and cli also has it, I am not sure if any issues would occur.

Why not try using shadow plugin, and if it works with CLI then go with that.

@MarkusTieger
Copy link
Contributor Author

A patches jar is not a fat jar, so it is not containing the classes from dependencies jar.

I am not sure, but applying the shadow plugin should make patches contain all dependencies. This can be added to the patches gradle plugin. However, how are duplicate classes handled? If its shaded into patches jar and cli also has it, I am not sure if any issues would occur.

Why not try using shadow plugin, and if it works with CLI then go with that.

Ok, then with shadow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants