From 1e68bb0ede84fbe4263c5c719fda5ca34fd1eb79 Mon Sep 17 00:00:00 2001 From: IgorEisberg Date: Sun, 10 Feb 2019 14:01:26 +0200 Subject: [PATCH] feat: Fill missing 9patch lines to fix recompile Somehow Google manages to compile MiuiSystemUI.apk (and a few other APKs I encountered) with a misformed pip_dismiss_scrim.9.png. Either way, every time I encountered such 9.patch images, the missing lines always indicated a single full div or padding. Apktool already fills missing padding lines, now it can also fill missing divs. --- .../res/decoder/Res9patchStreamDecoder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java index a4d4285e..a8ed5f16 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java @@ -65,13 +65,21 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; - for (int i = 0; i < xDivs.length; i += 2) { - drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); + if (xDivs.length == 0) { + drawHLine(im2, 0, 1, w); + } else { + for (int i = 0; i < xDivs.length; i += 2) { + drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); + } } int[] yDivs = np.yDivs; - for (int i = 0; i < yDivs.length; i += 2) { - drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); + if (yDivs.length == 0) { + drawVLine(im2, 0, 1, h); + } else { + for (int i = 0; i < yDivs.length; i += 2) { + drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); + } } // Some images additionally use Optical Bounds