ReVanced / revanced-manager

💊 Application to use ReVanced on Android
https://revanced.app
GNU General Public License v3.0
18.11k stars 746 forks source link

bug: When patching fails you're stuck with a broken YT app on every reboot even when reinstalling stock and/or uninstalling manager #425

Closed Nodens- closed 10 months ago

Nodens- commented 2 years ago

Type

Other

Bug description

I tried a few patches on the latest supported version on my device (rooted method without microg). I eventually found a combination that worked. After a restore to stock and trying a different patch combination it started crashing and my original patch combination was also not working anymore. After reboot Youtube app kept crashing even when restored to stock prior to reboot, to my surprise. I kept uninstalling and reinstalling a clean version and always on reboot it would be replaced with a non-working version.

I went ahead and cleaned the tmp directory from within the app. No effect. Then I uninstalled the manager and again no effect. Always on reboot the working version would be replaced with a non working one.

I finally started digging around to debug and I figured out what was happening. There are some scripts installed that run on boot and replace the installed version with the patched version. I assume this is done in order to workaround auto app upgrade. BUT, there are several issues at play here.

  1. For some reason the file written on the tmp directory was not being replaced, so no matter how I patched again I was always getting the same broken version.
  2. Deleting the tmp directory from the manager had no effect as well. Both .apk files were still there. (This points to a write error? Permissions?)
  3. Uninstalling the manager, leaves the replace script in place, in both locations, which means that an unsuspecting user, one that can't debug this by looking at the code, is absolutely stuck with a broken youtube app every time they reboot the device.

I believe https://github.com/revanced/revanced-manager/issues/237 is also related in part to this.

Steps to reproduce

Not sure if this is 100% reproducible (the write/delete tmp directory part) or something that triggers intermittently. In my case it was always impossible to delete the tmp directory from the manager and uninstalling always left the script in both locations and the tmp directory in place.

Android version

12

Manager version

0.0.36

Target package name

Youtube

Target package version.

17.36.37

Installation type

Root

Patches selected.

I tried several patch combinations. I got it to work with just background and the 2 ad patches but it was after trying different combination of patches (that I can't remember right now) and getting a crashing youtube app, that I couldn't get the original 3 patch combo to work either and ending with an always broken version replacement on reboot.

Device logs (exported using Manager settings).

Did not manage to save logs as I started debugging this after uninstalling and figuring out that I still get a broken app replacement on reboot.

Installer logs (exported using Installer menu option) [unneeded if issue is not during patching].

No response

Screenshots or videos

No response

Solution

Manually delete revanced files in /data/local/tmp, in /data/adb/service.d and in /data/adb/post-fs-data.d to recover.

Additional context

No response

Acknowledgements

ayZagen commented 2 years ago

This is the same thing happened to me but the solution you have mentioned is not working at all. Clearing those folders has no effect. Reinstalling youtube not working too.

I have installed the app using root method maybe that's why your solution didn't work for me.

Clearly this is a bug.

Nodens- commented 2 years ago

You probably missed it but I also use the root method. Perhaps there is a third script in your case or you did not remove the proper files.

Kavindu-Deshapriya commented 2 years ago

In my case I patched YouTube successfully but after some days YouTube app is renamed to "Apply" and can't start the app

RKPlane commented 2 years ago

I fixed this by a clunky method, basically the revanced manager installs a broken YT app at system startup (in my case Twitter and Reddit too) so instead of updating or uninstalling it, I disabled signature verification in the package manager (Lucky patcher method with Xposed settings), then install on top of the modded one the official one and that fixed both Twitter and Reddit, for YouTube I only update in Google play and starts working again.

Good luck trying my method

PD: Manager should have an option to undo that startup script I hope OP reads this it's annoying to deal with this every startup.

ipdev99 commented 2 years ago

A little history..

A few years ago, due to updates in Android security, modified versions of apk files would fail verification on boot. You could adjust the permissions, owner/group, security, .. but, no guarantee it would survive verification. What works on one device might fail on another. The only sure way was to compromise device security by disabling the verification.

Instead, we can use the mount command to overlay the modified version. Work around the security instead of disabling it.

This allows the stock version to be found and verified on boot. Once verified, we can then overlay the modified version.

This is what the boot script(s) are for.


When you use the patcher app to install the root version. It will create a modified apk file with the patch(s) you selected.

The permissions of the modified apk file needs to be set correctly. This can not be done in a normal user level like /sdcard/ so /data/local/tmp is used since it has heighten permission levels.

Note: Vanced used Magisk's /data/adb/ directory. Seems ReVanced might follow suit. - commit


In my testing, I found I have to include the Client Spoof patch for YouTube. I am not sure if it is required for every device/system but, for me, it fails when I do not include that patch.

Cheers. :cowboy_hat_face:

_PS: I am using the "root" method but, I do not use the ReVanced script(s) or install. I use my own script(s) and a slightly different way to install. :upside_downface:

Nodens- commented 1 year ago

I understand perfectly why the scripts are there, although I don't actually need that method as I'm patching android for other reasons. The problem here though is that the Manager does not cleanup. Neither the tmp directory or the scripts on uninstall. There's also an issue with overwriting the files in the tmp directory that along with inability to clean, leaves you completely stuck with a broken app if you can't figure out how it's implemented in order to manually clean it. And the vast majority of users fall into that category. Ideally the root method should just switch to a magisk module.

bassmadrigal commented 1 year ago

Due to the issues I have documented in #519, I have to "fix" a broken so frequently. I've found the only way to guarantee proper startup is to clear the app data and "uninstall updates" for YouTube in the Play Store. After that, I'm back to a completely stock YouTube with all settings reverted to their original values as if you first opened YouTube.

From there, I'm able to upgrade YouTube to my preferred version and then use ReVanced Manager to patch it.

This will work until my device is rebooted again, then I have to do the above all over again. I have not needed to go into /data/ and manually delete anything.

Maybe it'll work for you as well. Good luck!

Nodens- commented 1 year ago

@bassmadrigal it's exactly because you have not manually deleted anything coupled with the issue reported here that you have to redo everything after reboot. This IS the actual issue reported which you have not understood.

A broken patched version is being copied from /data/local/tmp over your working patched version (and even over the stock unpatched one) on every reboot by the scripts installed in /data/adb/service.d and /data/adb/post-fs-data.d which is forcing you to redo everything after reboot. Is it more clear now?

Manually deleting the broken version from /data/local/tmp will prevent the overwrite and removing the 2 scripts will clear the copy on boot behavior entirely.

bassmadrigal commented 1 year ago

@Nodens- This happened on two different devices months apart from each other with the exact same symptoms. I've only had my Pixel 7 for a month and ReVanced was a brand new install on a freshly rooted device (ie, those folders and files would've been empty/non-existent).

The issue also existed previously with my Pixel 6 with both revanced-cli (which I used before the Manager was released) and ReVanced Manager.

And if this is the problem, why isn't ReVanced Manager clearing those folders/files as well and replacing them with non-broken versions?


BTW, looking into those folders, my /data/local/tmp files are from yesterday. Are you saying that ReVanced Manager is still making broken apks and installing scripts that install those broken apks after every reboot or that I have older versions that were broken that modern installs don't have to deal with?

Either way, this is looking like a ReVanced bug and shouldn't require manually deleting anything.

Nodens- commented 1 year ago

There are at least 2 different interrelated issues. First is that Revanced Manager doesn't clean either the scripts and the patched files from tmp on uninstall or the patched files from tmp on the delete temp files option. And the second is that something is preventing the Manager from writing properly in the tmp directory so the files there are broken and the scripts keep overwriting your youtube even if you uninstall Revanced Manager. Could be SELinux related, I didn't investigate further. But yes it is a bug.

If you want as a workaround to stop redoing patches at reboot, do this: Patch with the manager properly so you have a working patched youtube. Uninstall the manager Delete the files from tmp and the 2 scripts. Tada no more broken youtube on reboots.

EDIT: Forgot to mention but if you missed it, read ipdev99's comment above regarding why the scripts and the copy on boot implementation is there to begin with.

bassmadrigal commented 1 year ago

If you want as a workaround to stop redoing patches at reboot, do this: Patch with the manager properly so you have a working patched youtube. Uninstall the manager Delete the files from tmp and the 2 scripts. Tada no more broken youtube on reboots.

This did not work (edit, or I we misunderstood each other and what I wanted to happen after a reboot). This reverted YouTube back to the stock version on reboot.

There was a benefit to this method in that the stock version that shows up on reboot (which I wanted to be ReVanced) did not crash when trying to open it up. And when reinstalling ReVanced Manager and repatching YouTube, all my custom settings were retained.

This doesn't surprise me knowing the basics behind how systemless changes work to retain SafetyNet approval, which I get into below.

EDIT: Forgot to mention but if you missed it, read ipdev99's comment above regarding why the scripts and the copy on boot implementation is there to begin with.

How would ReVanced survive a reboot if you're removing the scripts that overwrite the stock YouTube after initial checks occur during boot?

This is what they wrote:

This allows the stock version to be found and verified on boot. Once verified, we can then overlay the modified version.

This is what the boot script(s) are for.

Removing those scripts would then prevent the ReVanced version from overlaying the stock version on bootup.

ipdev99 commented 1 year ago

This did not work (edit, or I we misunderstood each other and what I wanted to happen after a reboot). This reverted YouTube back to the stock version on reboot. This is what they wrote:

This allows the stock version to be found and verified on boot. Once verified, we can then overlay the modified version.

This is what the boot script(s) are for.

Removing those scripts would then prevent the ReVanced version from overlaying the stock version on bootup.

The problems seems to be the prevoius files are not being replaced by the new version(s).

To overcome this you need to remove (delete) the current boot scripts and patched version before you patch and install again using the Manager. You might want to clear data and cache of the Magnager app also before patching.

This should give your device a clean slate and the new scripts will be written and the patched apk file place properly.

Example YouTube: Remove the boot scripts. /data/adb/post-fs-data.d/com.google.android.youtube.sh /data/adb/service.d/com.google.android.youtube.sh

Remove the ReVanced YouTube mount directory. /data/local/tmp/revanced-manager/com.google.android.youtube

Then use ReVanced Manager to patch and install as root again. :wink:

Hope it helps more than confuse. :upside_down_face:

:cowboy_hat_face:

bassmadrigal commented 1 year ago

I had already done that and that's what reverted YouTube to the stock version after a reboot instead of the patched ReVanced version I had just installed.

To give you the rundown, to prep, I deleted the boot scripts, the revanced-manager/com.google.android.youtube folders, ReVanced Manager, and reverted YouTube back to stock (uninstalled updates, cleared data, then reinstalled/upgraded the stock YouTube to 17.49.37 with the apk).

Then I rebooted, installed ReVanced Manager, patched YouTube, then removed the boot scripts, the revanced-manager/com.google.android.youtube folders, and ReVanced Manager. Rebooted and I was greeted with the stock YouTube.

Reinstalled ReVanced Manager, patched again, rebooted without deleting those newly generated scripts and apks, and YouTube crashes on opening and I have to uninstall updates and clear data to allow me to open YouTube again (which I then need to patch and reset all my settings).


There is one good thing I've found through this testing and that's to delete the scripts and folder before rebooting, because then I just need to repatch to get ReVanced back but my YouTube settings (both stock and ReVanced) stay untouched. It sucks needing to reset them every time you reboot your phone.

Nodens- commented 1 year ago

Yeah this is why I said that this needs to be a magisk module. The current method is rather messy and it seems like something prevents proper writes causing all this. I didn't pursue debugging this as I have moved to using wanam's lsposed module which just works for what want it to do.

oSumAtrIX commented 10 months ago

This should be fixed as the installation process is now separated from the patching process