iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.42k stars 3.6k forks source link

1px tall/wide 9patch images decoding fails. #1522

Closed argraur closed 5 years ago

argraur commented 7 years ago

Information

  1. apktool 2.2.3-dirty -
  2. Windows -
  3. Android O -

Stacktrace

PS E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI> java -jar .\apktool-2.2.3-dirty-small.jar b .\SystemUI --no-src
I: Using Apktool 2.2.3-dirty
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: ERROR: 9-patch image E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\res\drawable-xxhdpi\pip_dismiss_scrim.9.png malformed.
W:        No marked region found along edge.
W:        Found along left edge.
W: ERROR: Failure processing PNG image E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\res\drawable-xxhdpi\pip_dismiss_scrim.9.png
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\8523~1\AppData\Local\Temp\brut_util_Jar_6815133651981008170.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, C:\Users\8523~1\AppData\Local\Temp\APKTOOL1879548677653248317.tmp, -0, arsc, -0, arsc, -I, C:\Users\Александр\AppData\Local\apktool\framework\1.apk, -S, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\res, -M, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:493)
        at brut.androlib.Androlib.buildResources(Androlib.java:427)
        at brut.androlib.Androlib.build(Androlib.java:326)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:231)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\8523~1\AppData\Local\Temp\brut_util_Jar_6815133651981008170.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, C:\Users\8523~1\AppData\Local\Temp\APKTOOL1879548677653248317.tmp, -0, arsc, -0, arsc, -I, C:\Users\Александр\AppData\Local\apktool\framework\1.apk, -S, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\res, -M, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:441)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:479)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\8523~1\AppData\Local\Temp\brut_util_Jar_6815133651981008170.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, C:\Users\8523~1\AppData\Local\Temp\APKTOOL1879548677653248317.tmp, -0, arsc, -0, arsc, -I, C:\Users\Александр\AppData\Local\apktool\framework\1.apk, -S, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\res, -M, E:\image-bullhead-opp2.170420.019\system_\priv-app\SystemUI\.\SystemUI\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:435)
        ... 6 more

Steps to Reproduce

  1. java -jar apktool-2.2.3-dirty-small.jar b SystemUI --no-src

APK

GDrive

Questions to ask before submission

  1. Yeah
  2. Yes
argraur commented 7 years ago

Yeah it's me again, and I have one more issue :(

iBotPeaches commented 7 years ago

Please try reverting this commit - https://github.com/iBotPeaches/Apktool/commit/6e47d3687bce8ae3cafed0846de68635076a8a16 and let me know if the problem persists.

argraur commented 7 years ago

Sure

argraur commented 7 years ago

Hmm can't revert commit. Shows error: error: commit 6e47d3687bce8ae3cafed0846de68635076a8a16 - commit-merge, but -m option is not defined.

iBotPeaches commented 7 years ago

Revert this https://github.com/iBotPeaches/Apktool/commit/a00da345b2b699cf8255ea3fd33fb889be79346a

then this https://github.com/iBotPeaches/Apktool/commit/dd32f9414d897f6369aabcfcd4ad08366056533c

argraur commented 7 years ago

still cant revert that commit error: commit 6e47d3687bce8ae3cafed0846de68635076a8a16 is a merge but no -m option was given.
fatal: revert failed

iBotPeaches commented 7 years ago

Okay just hold then. I won't have time till the weekend to investigate.

argraur commented 7 years ago

Finally I reverted that commit by git rebase -i. And after test, It's failed again.

I: Using Apktool 2.2.3-1f1758-SNAPSHOT
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
W: ERROR: 9-patch image /home/argraur/working_directoru/sign_o/SystemUI/res/drawable-xxhdpi/pip_dismiss_scrim.9.png malformed.
W:        No marked region found along edge.
W:        Found along left edge.
W: ERROR: Failure processing PNG image /home/argraur/working_directoru/sign_o/SystemUI/res/drawable-xxhdpi/pip_dismiss_scrim.9.png
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_5128022422052930085.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, /tmp/APKTOOL7440049650671455157.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /home/argraur/working_directoru/sign_o/SystemUI/res, -M, /home/argraur/working_directoru/sign_o/SystemUI/AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:493)
        at brut.androlib.Androlib.buildResources(Androlib.java:427)
        at brut.androlib.Androlib.build(Androlib.java:326)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:231)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_5128022422052930085.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, /tmp/APKTOOL7440049650671455157.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /home/argraur/working_directoru/sign_o/SystemUI/res, -M, /home/argraur/working_directoru/sign_o/SystemUI/AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:441)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:479)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_5128022422052930085.tmp, p, --forced-package-id, 127, --min-sdk-version, O, --target-sdk-version, O, --version-code, 25, --version-name, O, --no-version-vectors, -F, /tmp/APKTOOL7440049650671455157.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /home/argraur/working_directoru/sign_o/SystemUI/res, -M, /home/argraur/working_directoru/sign_o/SystemUI/AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:435)
        ... 6 more
argraur commented 7 years ago

?

iBotPeaches commented 7 years ago

This 9patch image is a 1px wide image which I've never seen before.

https://github.com/android/platform_frameworks_base/blob/master/libs/androidfw/include/androidfw/ResourceTypes.h#L53

https://stackoverflow.com/questions/23858098/nine-patch-images-with-1px-width-or-height-special-case-or-faulty-files

However, it reports only 1 patch data blob that is 1 pixel long, which you can see from the below image is inserted in between the 3 pixel wide image. (The size grew from 1px to 3px due to adding 2 pixel for 9patch data)

screenshot from 2017-06-09 08-25-26

Since this is affecting only 1px wide/tall images, I'm hesitant to spend any more time on this besides the initial research. It is confirmed, so any additional research or PRs are accepted.

argraur commented 7 years ago

Why you don't want to fix it? This issue appears with SystemUI on stock Android O DP4 only, so it is Android O issue. This bug stops my ROM development

iBotPeaches commented 7 years ago

I never said that. I said, "I'm hesitant". This is a 1 pixel image in which we have to insert 9patch data which is very time consuming and I don't yet truly understand when it comes to 1 pixel images.

Read this 3-4 paragraph doc block about the encoded 9patch data - https://github.com/android/platform_frameworks_base/blob/master/libs/androidfw/include/androidfw/ResourceTypes.h#L53

Then apply that to a 1 pixel wide image.

charlescl commented 7 years ago

Just test the 2.2.4 self-build, can build the systemUI.apk DP4 after patch the 1px png with draw9patch.jar, but the re-builded systemUI.apk did not work.

churchmice commented 7 years ago

@charlescl could you share your self-built apktool ?

iBotPeaches commented 7 years ago

@charlescl 2.2.4 (renamed to 2.3.0) was officially released a few days ago. There would be no gain using a custom old build of 2.2.4.

churchmice commented 7 years ago

@iBotPeaches Great, but I tried the 2.2.4 and 2.3.0 and still got the 'No marked region found along edge' error when trying to recompile SystemUIGoogle.apk without modification.

syrm commented 6 years ago

So far there is no solution ?

iBotPeaches commented 6 years ago

@syrm Fix the affected images so they are proper 9patch images is a temporary solution. If you have the time you can jump into Apktool's 9Patch decoder and investigate if we are making any incorrect assumptions decoding these images.

AncalagonTheBlack commented 6 years ago

How can i fix the images i tried to resave them with the 9patch.jar but it still throws the same error above at me. im using an oreo rom (resurection remix) and i have no idea how get this one stupid image to compile.

Mi2Sir commented 6 years ago

I meet the same 9patch malformed error. Is there any solution?

exelix11 commented 6 years ago

@Mi2Sir I've been stuck with this error for a few hours with pip_dismiss_scrim.9.png to fix it I just manually added the marker with an image editor. Don't use mspaint or any other tool that discards alpha. I had the same image iBotPeaches posted, a line was clearly missing on the left side

daduke commented 6 years ago

you just added a vertical white line in the first column? I tried that but still get the error.

exelix11 commented 6 years ago

Leave the first and last pixels blank, if you have the same image just copy the right pixel column into the left, that did the trick for me. Still I can't get my patched SystemUI to work, it crashes every time, don't know if it's because of this or i'm missing some steps

daduke commented 6 years ago

thanks! This part worked, now I'm having new issues...

daduke commented 6 years ago

same here now: modded SystemUI crashes, log doesn't help much.

daduke commented 6 years ago

@exelix11 did you ever manage to compile a working SystemUI?

exelix11 commented 6 years ago

Unfortunately no,every time I flash my build with magisk the notifications bar and task switcher stop working, and when I remove it from magisk I get a bootloop with systemUI has stopped, restoring a data backup fixes it. I just got back on Android modding probably there is something I'm missing (odex maybe?)

daduke commented 6 years ago

same here.. I tried the 'copy META-INF and AndroidManifest.xml from original apk' that everybody mentions + zipalign but it just keeps crashing sigh

exelix11 commented 6 years ago

Yeah tried that as well, still no luck

ihfandicahyo commented 6 years ago

So there is a solution or not? 2 days I was stranded and didn't find any solution.

AncalagonTheBlack commented 6 years ago

i gave up on it. i did it the dirty way. i unpacked the apk created a zip archive and changed the extension to apk. its not optimal but its working.

exelix11 commented 6 years ago

Unfortunately it's not possible to edit all of the resources this way

saboooor commented 6 years ago

I have this problem too, anyone have a temporary solution for this? EDIT: i found the fix, nvm

exelix11 commented 6 years ago

Ok so, i couldn't get apktool to patch my systemUI so i made an Xposed module to change what i needed and it's working like a charm. Maybe it's not the optimal solution for everyone but it's ok for me and wasn't even that hard to get it working, so if you're still stuck on this give Xposed a try

lastant commented 5 years ago

I have this problem too, anyone have a temporary solution for this? EDIT: i found the fix, nvm

How did you manage to fix this?

jkryanchou commented 5 years ago

Is there any solution on the issue. I have tried on apktool 2.3.4, it doesn't work well yet. Raise same issue as issuer mention.

iBotPeaches commented 5 years ago

There is a solution (by @IgorEisberg) in review right now. - https://github.com/iBotPeaches/Apktool/pull/2003/commits/132a370f40377329512f0c3c5c89e82795a76e3c

Been busy.

jkryanchou commented 5 years ago

@iBotPeaches I have searched for the same issue. and found the solution from the issue https://github.com/iBotPeaches/Apktool/issues/2001, While I rebuild with --use-aapt2 It raised another issue as below.

.... res/values/ids.xml:3: error: <item> inner element must either be a resource reference or empty.
.... res/values/ids.xml:4: error: <item> inner element must either be a resource reference or empty.
.... res/values/ids.xml:5: error: <item> inner element must either be a resource reference or empty.
jkryanchou commented 5 years ago

@iBotPeaches When the latest version could be released?

iBotPeaches commented 5 years ago

I'm already 4 months behind. Windows builds are broken and I have a stack (2) of pending PRs to merge and a backlog that grows daily. I am hoping to find some weekend time to handle this.

jkryanchou commented 5 years ago

@iBotPeaches OK, Got it. Wish it release soon.