Skip to content
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

[BUG] Can't compile WhatsApp: No resource identifier found for attribute #3129

Open
andrewille opened this issue Jul 7, 2023 · 26 comments
Open

Comments

@andrewille
Copy link

Information

  1. Apktool Version (apktool -version) - 2.7.1-2b8121-SNAPSHOT (also tried 2.7.0)
  2. Operating System (Mac, Linux, Windows) - Linux
  3. APK From? (Playstore, ROM, Other) - Playstore
  4. Java Version (java --version) - openjdk 11.0.19 2023-04-18

Description

I tried to re-compile WhatsApp, but this time I get the following errors. It worked for years, but now they seem to have changed something with their resource packer. The unpacked files are correct though, JADX is giving me the same XMLs. I found the issue #1663 that seems to be a duplicate, but I got confused about the answers, just like some others in the comments.
Why does this happen? Does the attribute have a different, obfuscated name that I can find out and replace manually?

Stacktrace using aapt1:

I: Building resources...
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f02000b.xml:7: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f02000c.xml:7: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f020016.xml:4: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/drawable/mtrl_switch_thumb.xml:6: error: No resource identifier found for attribute 'state_with_icon' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06064e.xml:5: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084a.xml:5: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084a.xml:6: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084b.xml:5: error: No resource identifier found for attribute 'state_dragged' in package 'com.whatsapp'
W: 
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_100789196559354913966323838559374761553.tmp, p, --forced-package-id, 127, --min-sdk-version, 23, --version-code, 231278007, --version-name, 2.23.12.78, --no-version-vectors, -F, /tmp/APKTOOL7347569595200723227.tmp, -e, /tmp/APKTOOL3147889887535317417.tmp, -0, arsc, -I, /home/andre/.local/share/apktool/framework/1.apk, -S, /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res, -M, /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/AndroidManifest.xml]

Stacktrace using aapt2:

I: Building resources...
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f02000b.xml:7: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f02000c.xml:7: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/animator/APKTOOL_DUMMYVAL_0x7f020016.xml:4: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06064e.xml:5: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084a.xml:5: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084a.xml:6: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/color/APKTOOL_DUMMYVAL_0x7f06084b.xml:5: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/res/drawable/mtrl_switch_thumb.xml:6: error: attribute state_with_icon (aka com.whatsapp:state_with_icon) not found.
W: error: failed linking file resources.
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_66861882540706906105295532666519204475.tmp, link, -o, /tmp/APKTOOL16193917248874868592.tmp, --package-id, 127, --min-sdk-version, 23, --version-code, 231278007, --version-name, 2.23.12.78, --no-auto-version, --no-version-vectors, --no-version-transitions, --no-resource-deduping, --allow-reserved-package-id, -e, /tmp/APKTOOL864166811073607284.tmp, -0, arsc, -I, /home/andre/.local/share/apktool/framework/1.apk, --manifest, /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/AndroidManifest.xml, /home/andre/Programme/APKTool/Fixes/Apktool/WhatsApp/build/resources.zip]

Steps to Reproduce

  1. Decompile latest WhatsApp (including resources)
  2. Try to recompile it

APK

WhatsApp 2.23.12.78 from Google Play Store. I'd rather not re-upload it for legal reasons.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? Yes
  2. If you are trying to install a modified apk, did you resign it? It's Not compiling
  3. Are you using the latest apktool version? Yes
@iBotPeaches
Copy link
Owner

Lost at the moment as we have (what I thought was) the latest Whatsapp crashing before even getting the point of reassembly in this issue - #3036

@andrewille
Copy link
Author

Lost at the moment as we have (what I thought was) the latest Whatsapp crashing before even getting the point of reassembly in this issue - #3036

Hi, thanks for your response. I did reproduce #3036 and it does only happen with the WhatsApp version mentioned in this issue (2.23.8.4), which is outdated. Updating to the most recent version fixes the issue.
But still this issue here is happening :(

@byomi
Copy link

byomi commented Jul 26, 2023

@iBotPeaches is there any update in this ,plus i downloaded the source code of the apktool trying to find the issue and fix it is there any docs or hints on where i can find the issue which part of code or do i need to read the whole source code to figure it out :/

btw after updating my apktool do i need to decompile the apk again or can i compile the one i used the old apktool version decompiled i don't know if it makes any errors or something

@iBotPeaches
Copy link
Owner

@byomi - This repo has had more activity from myself in the past 2 weeks than the last 4 years combined - so yes plenty of updates, but nothing for this ticket.

The best hint I have is looking at the AXML parser between the namespace association and how it handles with value comparisons between the string pool and resource table.

Its always good behavior to decode an application again with a newer apktool in case it was decoded improperly prior.

@byomi
Copy link

byomi commented Jul 26, 2023

@iBotPeaches thank for the hint i see after quite time of search i found that the issue is i need to add this 2 lines to the attrs.xml

<attr name="state_dragged" format="boolean" />
<attr name="state_with_icon" format="boolean" />

still didnt figure out what part of the code does this job but i get this soultion for now but still failed to build with this error
AndroidManifest.xml:82: error: Error: Integer types not allowed (at 'usesPermissionFlags' with value '0x00010000').

not quite getting why this error happens

i removed the line but still got other errors
the good thing its 1 error
res/values-v31/colors.xml:3: error: Error: No resource found that matches the given name (at 'APKTOOL_DUMMYVAL_0x7f0606a0' with value '@android:color/Teal_700')

@andrewille here a fix for the errors for now add these 2 lines to attrs.xml and if u get the error in androidmanifest just delete the lines

if i found anymore solution i will update u with details

@andrewille
Copy link
Author

@andrewille here a fix for the errors for now add these 2 lines to attrs.xml and if u get the error in androidmanifest just delete the lines

if i found anymore solution i will update u with details

Thank you so much for sharing this! After updating to ApkTool 2.8.1 and applying your fix to the attrs.xml I can compile it without any problems! I haven't installed it to my device yet, but I think it should work fine.
I don't get the second error that you get and I suspect that you just need to update to the latest ApkTool.

@byomi
Copy link

byomi commented Jul 27, 2023

@andrewille it should work fine but let me know if u can register in whatsapp normaly test it i tried change package name but idk it says problem with whatsapp idk if its the package name it self or it verify signature can u test it and tell me what comes up with u

@iBotPeaches if an apk crashes after compile and sign it or just show corrupted installation after just decompile and build does it cause because the app protected from sign with different key and if it is i searched alot on how t bypass but there is no good guide for that or info about what is the thing i need to search any help will be appreciated (ik its out of the ticket body but i hope anything could help me ) finally thanks alot

@andrewille
Copy link
Author

@andrewille it should work fine but let me know if u can register in whatsapp normaly test it i tried change package name but idk it says problem with whatsapp idk if its the package name it self or it verify signature can u test it and tell me what comes up with u

I have never tried to re-register using one of my custom versions. My phone is rooted and I use a backup App (Swift Backup in my case) to restore the App's data after installing my modded version. This way WhatsApp would think you just updated the App and you don't have to register (again).
They might have put some kind of protection in place when starting it for the first time / registering.

So if your phone is rooted, just restore the data. If not, then you probably have to figure out what they do and how to bypass it, which might be much more complicated than just removing a small part of the code. Good luck tho!

@byomi
Copy link

byomi commented Jul 27, 2023

@andrewille oh ok i got my answer so whatsapp working fine with u hmm looks like its package name issue which make my whatsapp not working thanks for info ,nah my phone not rooted and actually i am not gonna like uninstall and install whatsapp million times everytime i change something or else ,anyway thanks and have a nice day.

Note: i remember lets say a new version of whatsapp cameout and this outdated mod need an update how do i update my mod do i rewrite the files to the new apk or what u have anyideas?

@andrewille
Copy link
Author

@andrewille oh ok i got my answer so whatsapp working fine with u hmm looks like its package name issue which make my whatsapp not working thanks for info ,nah my phone not rooted and actually i am not gonna like uninstall and install whatsapp million times everytime i change something or else ,anyway thanks and have a nice day.

Glad that it worked for you!

Note: i remember lets say a new version of whatsapp cameout and this outdated mod need an update how do i update my mod do i rewrite the files to the new apk or what u have anyideas?

If you need to update to a newer WhatsApp version, you have to decompile the latest WhatsApp Apk, then apply all of your changes again to the new version (you may need to change different things as they might change the structure of their code/resources). Then you can build and install the new modded Apk just over the old one on your phone. You do not need to uninstall it before as long as you use the same signature. This way you also keep all your app data.

@byomi
Copy link

byomi commented Jul 27, 2023

@andrewille ok thanks alot i appreciate that one more question how does these modded whatsapp change the package name to install it side by side with other version or any another app not only whatsapp do u have any idea?

@andrewille
Copy link
Author

@andrewille ok thanks alot i appreciate that one more question how does these modded whatsapp change the package name to install it side by side with other version or any another app not only whatsapp do u have any idea?

I have never attempted to rename it, but you could try to set a different name in the apktool.yml. Change renameManifestPackage inside packageInfo to a string with a different name. But as I said, I never tried it so idk if it works.
But as mentioned in #3011, this might need further changes in the code because it will rename the package but not change the code so this still references the old packages.

Maybe there's a simpler solution, but I think I can't help you with it

@byomi
Copy link

byomi commented Jul 27, 2023

@andrewille but how u install it on the old version when u cant sign your build with a different key?? and i just found that if i signed whatsapp it fails registeration because it says problem with whatsapp install from playstore and if i did as u said the original then my build i cant install it because its signed with different key so how u do it?

@andrewille
Copy link
Author

andrewille commented Jul 27, 2023

@andrewille but how u install it on the old version when u cant sign your build with a different key??

Maybe I misunderstood you. I thought you got it working now and you can register. Of course you can only install your apk over an installed version if it is signed using the same key. You will never be able to sign with the same key that original WhatsApp uses. You have to create your own one and sign with it. I just meant that if you had it running once, signed with YOUR key, then you can easily update the mod and install it over YOUR old versions without having to register ever again.

and i just found that if i signed whatsapp it fails registeration because it says problem with whatsapp install from playstore and if i did as u said the original then my build i cant install it because its signed with different key so how u do it?

As I said, I never faced that problem because I backup everything, then uninstall WhatsApp and install my mod and then I restore only the data. This way I never have to register again and everything just works.

This is what I meant when I said they may have a protection. I don't know what they do exactly, but it comes down to three ways they could have achieved it:

  1. The App locally checks the signature and checks if it is some hardcoded value. If not, it refuses to work. This could be easily bypassed
  2. They send the signature 1:1 to the server which rejects different signatures. This could also be bypassed easily, just replace the signature that is sent with the correct one (hardcoded).
  3. They do some hacky crypto stuff that relies on the signature so it stops working with a different one. I don't want to dive too deep into this because it is very hard to break this anyway.

It might be the easiest way to just root your phone and do the same as I do. Another hacky way I can think of is to get (the original) WhatsApp running in an emulator or someone else's rooted phone, then backup the data and then package the app data right into your mod (or make it restore it at the first start). This way you should be able to keep your session and be logged in on your phone, without another registration.

In the end, the registration is the point where the protection is in place, so you have to bypass the protection itself or get around the registration. I use the second way and it's much simpler.

@byomi
Copy link

byomi commented Jul 27, 2023

@andrewille i am using emulator now which is rooted so basicaly u backup it then restore oh so u didnt register in your mod before u just restore it which instantly get u to chat ok i get it now i thought u install your mod on the original whatsapp ok thanks .(when it comes to hardcoded i have np i like to learn) btw do u recommended any java decompilers like jadx its kinda heavey i dont want to use it do u have any?

@andrewille
Copy link
Author

@andrewille i am using emulator now which is rooted so basicaly u backup it then restore oh so u didnt register in your mod before u just restore it which instantly get u to chat ok i get it now i thought u install your mod on the original whatsapp ok thanks

Yes, exactly.

btw do u recommended any java decompilers like jadx its kinda heavey i dont want to use it do u have any?

I actually like JadX (the graphical program) and use it often. You could also try Bytecode Viewer, which has multiple decompilers built-in. But I think this one uses much resources too.

@cpereirarafa
Copy link

@iBotPeaches I ran into the same problem with the version 2.8.1 and the latest version of whatsapp from their website, 2.23.17.73.

When decoding the named animators those attributes come from the app xmlns. apart from the 4 animators mentioned in the log, there is another one (0x7f020000) that has the namespace, but the resource asked appears in the java code too, maybe that's why they appear in the attrs.xml, and the state_dragged or state_with_icon doesn't.

In brut-apktool/apktool-lib/src/main/java/brut/androidlib/res/decoder/AXmlResourceParser.java the function decodeFromResourceId generates an exception that is ignored, caused because the mResTable doesn't have the ResSpec for the id 2130970312 (state_dragged).

After this ignored error the attribute comes named as they normally came (state_dragged) but I believe that by the time of compile is not finding in any res table. That's why adding to the attrs.xml works (I have also compiled like this and fixed the problem).

I didn't fully understood the creation of the resource tables, to understand better why the package app doesn't have this resource in their list, but I hope to have contributed in finding the solution faster. The exception being raised:

image

@linuxct
Copy link

linuxct commented Oct 4, 2023

I can see the exact same behaviour in this thread happening on Pixel 8's AiWallpaper. Except, it also happens for more attributes other than state_dragged, like what should be known attrs like com.google.android.apps.aiwallpapers:layout_constraintBottom_toBottomOf, to put an example. Seems like the AXML compiler is misinterpreting what should be a known standard xmls layout_constraint attribute to be defined as part of the application itself? Or maybe I am misunderstanding this last part.

@iBotPeaches
Copy link
Owner

@linuxct - Attributes/properties did have some flaws. Upcoming release takes an aim at many of those:

Just waiting on AOSP Android 14 sources to add the new qualifiers and I'll release 2.9.0

@linuxct
Copy link

linuxct commented Oct 4, 2023

Got it, thanks a bunch! I was running the latest build from master as of a week ago, so I should have those changes in my local build already. Will wait for your release with Android 14 fixes regardless before proceeding

@linuxct
Copy link

linuxct commented Oct 8, 2023

Hey again, congrats on the 2.9.0 release! I have tried again to decompile and then rebuild the Google AiWallpapers APK that's floating around lately, and it still wouldn't work (clean frameworks dir, or using an Android 14 Pixel's framework). I figured maybe it'd be useful to send you the file to see if you can reproduce it? The issue seems similar to the one in this thread, except the attributes are "known" ones, as I was saying the other day... or perhaps the OP can be rewritten to make it clear it's not just WhatsApp that's affected by this issue

@iBotPeaches
Copy link
Owner

Okay, lets take a look at this application again and see whats going on.

Start with the error that I replicate.

I: Checking whether resources has changed...
I: Building resources...
W: /media/ibotpeaches/AOSP/Apktool/3129/3129/res/animator/APKTOOL_DUMMYVAL_0x7f02000b.xml:7: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.
W: /media/ibotpeaches/AOSP/Apktool/3129/3129/res/animator/APKTOOL_DUMMYVAL_0x7f02000c.xml:7: error: attribute state_dragged (aka com.whatsapp:state_dragged) not found.

So lets check if that attribute exists.

➜  3129 grep -r -i 'state_dragged' *
3129/res/animator/APKTOOL_DUMMYVAL_0x7f020016.xml:    <item android:state_enabled="true" app:state_dragged="true">
3129/res/animator/APKTOOL_DUMMYVAL_0x7f02000b.xml:    <item android:state_enabled="true" app:state_dragged="true">
3129/res/animator/APKTOOL_DUMMYVAL_0x7f02000c.xml:    <item android:state_enabled="true" app:state_dragged="true">
...

So the issue is apparent - we are referencing an attribute that we did not disassemble. However, it could be there under a different name, so lets further investigate. We want to ask aapt2 what it thinks about this file, but going from the name of the file - its name has been stripped. So first lets reverse that lookup either using apktool verbose mode or aapt2.

➜  3129 aapt2 d resources 3129.apk | grep -i '7f02000b' -a1
      () (file) res/cc.xml type=XML
    resource 0x7f02000b animator/(name removed)
      () (file) res/cd.xml type=XML
➜  3129 

So we know we want the file res/cd.xml. So now lets dump that.

➜  3129 aapt2 d xmltree 3129.apk --file res/cd.xml         
N: android=http://schemas.android.com/apk/res/android (line=18)
  N: app=http://schemas.android.com/apk/res-auto (line=18)
    E: selector (line=18)
        E: item (line=24)
          A: http://schemas.android.com/apk/res/android:state_enabled(0x0101009e)=true
          A: http://schemas.android.com/apk/res/android:state_hovered(0x01010367)=true
            E: objectAnimator (line=25)
              A: http://schemas.android.com/apk/res/android:interpolator(0x01010141)=?0x7f0404c7
              A: http://schemas.android.com/apk/res/android:duration(0x01010198)=?0x7f0404bd
              A: http://schemas.android.com/apk/res/android:valueTo(0x010102df)=@0x7f070625
              A: http://schemas.android.com/apk/res/android:valueType(0x010102e0)=0
              A: http://schemas.android.com/apk/res/android:propertyName(0x010102e1)="translationZ" (Raw: "translationZ")
              A: http://schemas.android.com/apk/res/android:startDelay(0x010103e2)=?0x7f0404ba
        E: item (line=36)
          A: http://schemas.android.com/apk/res/android:state_enabled(0x0101009e)=true
          A: http://schemas.android.com/apk/res-auto:state_dragged(0x7f040634)=true
            E: objectAnimator (line=37)
              A: http://schemas.android.com/apk/res/android:interpolator(0x01010141)=?0x7f0404c7
              A: http://schemas.android.com/apk/res/android:duration(0x01010198)=?0x7f0404bd
              A: http://schemas.android.com/apk/res/android:valueTo(0x010102df)=@0x7f070623
              A: http://schemas.android.com/apk/res/android:valueType(0x010102e0)=0
              A: http://schemas.android.com/apk/res/android:propertyName(0x010102e1)="translationZ" (Raw: "translationZ")
              A: http://schemas.android.com/apk/res/android:startDelay(0x010103e2)=?0x7f0404ba
        E: item (line=48)

The name is preserved (state_dragged), but its not like an Android resource that is discernible from the resourceId. So lets look up that resourceId and see whats up.

➜  3129 aapt2 d resources 3129.apk | grep -i '0x7f040634'
➜  3129 

No results :/

So that explains the error. The only option I see here is making the disassembler a bit greedier and remove attributes if we cannot resolve, but thats also a can of worms.

So this will probably sit a bit - unsure on path forward.

@ujjwalkirorimal
Copy link

ujjwalkirorimal commented Nov 13, 2023

@iBotPeaches Apparently the root cause of these resource issues is resource shrinking optimization. It removes unused resources after optimizing app code which is why they seem to be missing / are missing. These resource shrinking is getting used by more and more apps lately and even most of the AOSP seems to have been migrated to use this shrinking in udc.

To test this I compiled same Traceur app from AOSP with and without commit [1]* and then tried recompiling them using apktool.
The one without res shrinking recompiled perfectly fine and other one threw same error of missing resources like

res\animator\mtrl_card_state_list_anim.xml:4: error: attribute state_dragged (aka com.android.traceur:state_dragged) not found.
and so on...

The resolution I can think of about this is adding a flag or something for ignoring or removing the missing attribute outright as done by optimization in first place likely suggested by you above . But since the cause is now known I guess you can now think of better solutions.

Test APKs:
Without resource shrinking
With resource shrinking enabled
[1]: https://android.googlesource.com/platform/packages/apps/Traceur/+/3d2b58ad0766eeb39a51d2066fdfaa7601b215eb%5E%21/

@gcandrade10
Copy link

@andrewille but how u install it on the old version when u cant sign your build with a different key??

Maybe I misunderstood you. I thought you got it working now and you can register. Of course you can only install your apk over an installed version if it is signed using the same key. You will never be able to sign with the same key that original WhatsApp uses. You have to create your own one and sign with it. I just meant that if you had it running once, signed with YOUR key, then you can easily update the mod and install it over YOUR old versions without having to register ever again.

and i just found that if i signed whatsapp it fails registeration because it says problem with whatsapp install from playstore and if i did as u said the original then my build i cant install it because its signed with different key so how u do it?

As I said, I never faced that problem because I backup everything, then uninstall WhatsApp and install my mod and then I restore only the data. This way I never have to register again and everything just works.

This is what I meant when I said they may have a protection. I don't know what they do exactly, but it comes down to three ways they could have achieved it:

  1. The App locally checks the signature and checks if it is some hardcoded value. If not, it refuses to work. This could be easily bypassed
  2. They send the signature 1:1 to the server which rejects different signatures. This could also be bypassed easily, just replace the signature that is sent with the correct one (hardcoded).
  3. They do some hacky crypto stuff that relies on the signature so it stops working with a different one. I don't want to dive too deep into this because it is very hard to break this anyway.

It might be the easiest way to just root your phone and do the same as I do. Another hacky way I can think of is to get (the original) WhatsApp running in an emulator or someone else's rooted phone, then backup the data and then package the app data right into your mod (or make it restore it at the first start). This way you should be able to keep your session and be logged in on your phone, without another registration.

In the end, the registration is the point where the protection is in place, so you have to bypass the protection itself or get around the registration. I use the second way and it's much simpler.

Hi andrewille

how do you back up eveything?
I was trying with adb backup com.whatsapp and then restoring with adb restore backup.ab but it won't work

I tried then copying full content of /data/data/com.whatsapp and had some issues with permissions and with /data/user/0/com.whatsapp

I then tried copying that folder also and setting the correct permissions but now I have this exception when I uninstall the oficial apk and install my version:

Failed to ensure /data/user/0/com.whatsapp/files: mkdir failed: EACCES (Permission denied)
2023-12-30 15:30:58.425  7100-7100  Compatibil...geReporter com.whatsapp                         D  Compat change id reported: 171228096; UID 10087; state: ENABLED
2023-12-30 15:30:58.553  7100-7147  WM-PackageManagerHelper com.whatsapp                         D  androidx.work.impl.background.systemjob.SystemJobService enabled
2023-12-30 15:30:58.553  7100-7147  WM-Schedulers           com.whatsapp                         D  Created SystemJobScheduler and enabled SystemJobService
2023-12-30 15:30:58.577  7100-7130  SharedPreferencesImpl   com.whatsapp                         E  Couldn't create directory for SharedPreferences file /data/user/0/com.whatsapp/shared_prefs/com.whatsapp_preferences_light.xml
2023-12-30 15:30:58.588  7100-7154  WM-ForceStopRunnable    com.whatsapp                         D  The default process name was not specified.
2023-12-30 15:30:58.593  7100-7154  ContextImpl             com.whatsapp                         W  Failed to ensure /data/user/0/com.whatsapp/databases: mkdir failed: EACCES (Permission denied)
2023-12-30 15:30:58.594  7100-7154  WM-ForceStopRunnable    com.whatsapp                         D  Performing cleanup operations.
2023-12-30 15:30:58.610  7100-7154  ContextImpl             com.whatsapp                         W  Failed to ensure /data/user/0/com.whatsapp/no_backup: mkdir failed: EACCES (Permission denied)
2023-12-30 15:30:58.614  7100-7154  ContextImpl             com.whatsapp                         W  Failed to ensure /data/user/0/com.whatsapp/cache: mkdir failed: EACCES (Permission denied)
2023-12-30 15:30:58.614  7100-7154  ContextImpl             com.whatsapp                         W  Failed to update user.inode_cache: stat failed: EACCES (Permission denied)
Unable to grab file lock.
                                                                                                    java.io.FileNotFoundException: /data/user/0/com.whatsapp/cache/data/user/0/com.whatsapp/no_backup/androidx.work.workdb.lck: open failed: EACCES (Permission denied)
                                                                                                    	at libcore.io.IoBridge.open(IoBridge.java:575)

I also noticed that when app is uninstalled it will remove the permissions:

Uninstalling extras=Bundle[{com.android.packageinstaller.extra.APP_LABEL=WhatsApp, com.android.packageinstaller.applicationInfo=ApplicationInfo{a0ac9b7 com.whatsapp}, android.intent.extra.UNINSTALL_ALL_USERS=false, com.android.packageinstaller.extra.UNINSTALL_ID=-2147483641}]
2023-12-30 15:23:55.267   730-788   ActivityManager         system_process                       I  Force stopping com.whatsapp appid=10086 user=0: deletePackageX
2023-12-30 15:23:55.268   730-788   ActivityManager         system_process                       I  Killing 6623:com.whatsapp/u0a86 (adj 905): stop com.whatsapp due to deletePackageX
2023-12-30 15:23:55.268   480-746   installd                installd                             E  Couldn't opendir /data/data/com.whatsapp: No such file or directory
2023-12-30 15:23:55.268   480-746   installd                installd                             E  Failed to delete /data/data/com.whatsapp: No such file or directory
2023-12-30 15:23:55.270   730-805   PackageManager          system_process                       W  com.android.server.pm.Installer$InstallerException: android.os.ServiceSpecificException: Failed to delete /data/data/com.whatsapp (code 2)
2023-12-30 15:23:55.273   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.permission.MAPS_RECEIVE that used to be declared by com.whatsapp
2023-12-30 15:23:55.273   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.permission.MIGRATION_CONTENT_PROVIDER that used to be declared by com.whatsapp
2023-12-30 15:23:55.274   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.permission.BROADCAST that used to be declared by com.whatsapp
2023-12-30 15:23:55.274   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.sticker.READ that used to be declared by com.whatsapp
2023-12-30 15:23:55.274   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION that used to be declared by com.whatsapp
2023-12-30 15:23:55.274   730-805   PackageManager          system_process                       I  Removing permission com.whatsapp.permission.REGISTRATION that used to be declared by com.whatsapp
2023-12-30 15:23:55.274   730-805   PackageManager          system_process                       I  Permission ownership changed. Updating all permissions.
2023-12-30 15:23:55.275  2534-3693  OpenGLRenderer          com.android.packageinstaller         D  endAllActiveAnimators on 0x78318f73bad0 (RippleDrawable) with handle 0x78309f7621b0
2023-12-30 15:23:55.278   730-4357  InputManager-JNI        system_process                       W  Input channel object 'b204f9d com.android.packageinstaller/com.android.packageinstaller.UninstallerActivity (client)' was disposed without first being removed with the input manager!
2023-12-30 15:23:55.288  2534-2543  ackageinstalle          com.android.packageinstaller         W  Reducing the number of considered missed Gc histogram windows from 106 to 100
2023-12-30 15:23:55.308   730-790   libprocessgroup         system_process                       I  Successfully killed process cgroup uid 10086 pid 6623 in 30ms
2023-12-30 15:23:55.312   418-517   gralloc_ranchu          and...raphics.allocator@2.0-service  D  gralloc_alloc: Creating ashmem region of size 14749696
2023-12-30 15:23:55.343   418-517   android.ha....0-service and...raphics.allocator@2.0-service  E  open_verbose_path:50: Could not open '/dev/goldfish_pipe': No such file or directory
2023-12-30 15:23:55.343   418-517   android.ha....0-service and...raphics.allocator@2.0-service  E  open_verbose:121: both vsock and goldfish_pipe paths failed
2023-12-30 15:23:55.352   382-382   Zygote                  app_process64                        I  Process 6623 exited due to signal 9 (Killed)
2023-12-30 15:23:55.352   730-1867  ConnectivityService     system_process                       D  ConnectivityService NetworkRequestInfo binderDied(uid/pid:10086/6623, android.os.BinderProxy@8fcf6d4)
2023-12-30 15:23:53.301     0-0     logd                    kernel                               I  start watching /data/system/packages.list ...
2023-12-30 15:23:53.301     0-0     logd                    kernel                               I  ReadPackageList, total packages: 88
2023-12-30 15:23:55.376   730-775   Looper                  system_process                       W  Slow dispatch took 101ms android.fg h=android.os.Handler c=<recycled PooledLambda@a40db72> m=0
2023-12-30 15:23:55.427   730-805   PackageManager          system_process                       D  Instant App installer not found with android.intent.action.INSTALL_INSTANT_APP_PACKAGE
2023-12-30 15:23:55.427   730-805   PackageManager          system_process                       D  Clear ephemeral installer activity
2023-12-30 15:23:55.514   730-2326  TaskPersister           system_process                       E  File error accessing recents directory (directory doesn't exist?).
2023-12-30 15:23:55.627   730-730   NotificationHistory     system_process                       W  Attempted to add notif for locked/gone/disabled user 0
2023-12-30 15:23:55.645   730-730   Looper                  system_process                       W  Slow dispatch took 171ms main h=com.android.server.notification.NotificationManagerService$WorkerHandler c=com.android.server.notification.NotificationManagerService$PostNotificationRunnable@fa5c0e9 m=0
2023-12-30 15:23:55.683  1006-1006  Interrupti...teProvider com.android.systemui                 D  No bubble up: not allowed to bubble: 0|com.android.packageinstaller|-2147483641|null|10018
2023-12-30 15:23:55.684  1006-1006  Interrupti...teProvider com.android.systemui                 D  No heads up: unimportant notification: 0|com.android.packageinstaller|-2147483641|null|10018
2023-12-30 15:23:55.688  1006-1124  PeopleSpaceWidgetMgr    com.android.systemui                 D  Sbn doesn't contain valid PeopleTileKey: null/0/com.android.packageinstaller
2023-12-30 15:23:55.745  1344-1839  EGL_emulation           com.android.launcher3                D  app_time_stats: avg=111.08ms min=6.46ms max=1832.16ms count=22
2023-12-30 15:23:55.770   730-2661  InputManager-JNI        system_process                       W  Input channel object 'b7eb75e com.android.packageinstaller/com.android.packageinstaller.UninstallerActivity (client)' was disposed without first being removed with the input manager!
2023-12-30 15:23:55.838   730-805   system_server           system_process                       W  Suspending all threads took: 8.574ms
2023-12-30 15:23:55.873   730-805   system_server           system_process                       I  Explicit concurrent copying GC freed 132403(7508KB) AllocSpace objects, 13(452KB) LOS objects, 49% free, 12MB/24MB, paused 17.136ms,8.700ms total 388.349ms
2023-12-30 15:23:55.882   730-779   ActivityTaskManager     system_process                       W  Can't find TaskDisplayArea to determine support for multi window. Task id=37 attached=false
2023-12-30 15:23:55.882   730-779   ActivityTaskManager     system_process                       W  Can't find TaskDisplayArea to determine support for multi window. Task id=37 attached=false
2023-12-30 15:23:55.952   730-805   ActivityManager         system_process                       I  Force stopping com.whatsapp appid=10086 user=0: pkg removed
2023-12-30 15:23:55.991  2534-2534  UninstallFinish         com.android.packageinstaller         I  Uninstall

Do Iahve to then modify the apk to request this permissions first thing?
Sounds like a lot of work :c
Do you have any advice?

@andrewille
Copy link
Author

andrewille commented Dec 30, 2023

Hi @gcandrade10,

how do you back up eveything?

I just use Swift Backup to backup and restore the app's data as well as media. It will take care of the permissions and will also restore runtime permissions (the ones you have to accept like accessing your contacts etc).
Note that it requires root access, but I think there is no way around this anyways.

I tried then copying full content of /data/data/com.whatsapp and had some issues with permissions and with /data/user/0/com.whatsapp

Your errors say that you have not properly set the file permissions. Android creates a separate user for every installed app. If you would really want to do it manually, you would have to find out which user was created for WhatsApp. You can find it out with ls -l /data/data | grep com.whatsapp. Then you would have to change the ownership for all files you copied using chown and reset the original permissions of each file using chmod (in case that it was changed during the copying somehow).

That said, I would not bother with doing this manually cause you can have it way easier as I wrote above.

I also noticed that when app is uninstalled it will remove the permissions

This is about Android runtime permissions. Don't confuse it with file permissions. Those runtime permissions were declared by WhatsApp and are removed globally therefore if you uninstall it. This does not break anything, it is just fine.

@gcandrade10
Copy link

Hey @andrewille I owe you a beer, it worked like a charm! thanks!

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

No branches or pull requests

7 participants