diff --git a/jadx-core/src/main/java/jadx/api/ResourcesLoader.java b/jadx-core/src/main/java/jadx/api/ResourcesLoader.java index be3672fda94b8d07ecd0cc5f843c935ee8363514..43e01c6c2a2b022712bca5a799ab25c5dda5e344 100644 --- a/jadx-core/src/main/java/jadx/api/ResourcesLoader.java +++ b/jadx-core/src/main/java/jadx/api/ResourcesLoader.java @@ -126,8 +126,9 @@ public final class ResourcesLoader { if (name.endsWith(".9.png")) { try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { Res9patchStreamDecoder decoder = new Res9patchStreamDecoder(); - decoder.decode(inputStream, os); - return ResContainer.decodedData(rf.getDeobfName(), os.toByteArray()); + if (decoder.decode(inputStream, os)) { + return ResContainer.decodedData(rf.getDeobfName(), os.toByteArray()); + } } catch (Exception e) { LOG.error("Failed to decode 9-patch png image, path: {}", name, e); } diff --git a/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java b/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java index 1c674aac8317c811f5464bd0bbed616d3bc5f1a2..7b407d5550674958552c5b546904e4735d410f83 100644 --- a/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java +++ b/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java @@ -24,6 +24,8 @@ import java.io.OutputStream; import javax.imageio.ImageIO; +import org.jetbrains.annotations.Nullable; + import jadx.core.utils.exceptions.JadxRuntimeException; /** @@ -31,16 +33,19 @@ import jadx.core.utils.exceptions.JadxRuntimeException; */ public class Res9patchStreamDecoder { - public void decode(InputStream in, OutputStream out) { + public boolean decode(InputStream in, OutputStream out) { try { BufferedImage im = ImageIO.read(in); + NinePatch np = getNinePatch(in); + if (np == null) { + return false; + } int w = im.getWidth(); int h = im.getHeight(); BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB); im2.createGraphics().drawImage(im, 1, 1, w, h, null); - NinePatch np = getNinePatch(in); drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); @@ -55,28 +60,32 @@ public class Res9patchStreamDecoder { } ImageIO.write(im2, "png", out); + return true; } catch (Exception e) { throw new JadxRuntimeException("9patch image decode error", e); } } + @Nullable private NinePatch getNinePatch(InputStream in) throws IOException { ExtDataInput di = new ExtDataInput(in); - find9patchChunk(di); + if (!find9patchChunk(di)) { + return null; + } return NinePatch.decode(di); } - private void find9patchChunk(DataInput di) throws IOException { + private boolean find9patchChunk(DataInput di) throws IOException { di.skipBytes(8); while (true) { int size; try { size = di.readInt(); } catch (IOException ex) { - throw new JadxRuntimeException("Cant find nine patch chunk", ex); + return false; } if (di.readInt() == NP_CHUNK_TYPE) { - return; + return true; } di.skipBytes(size + 4); } diff --git a/jadx-gui/src/main/java/jadx/gui/utils/search/ResourceIndex.java b/jadx-gui/src/main/java/jadx/gui/utils/search/ResourceIndex.java index fe3493852aa3c971737e7256ebba81ace996da0a..fc6fc2bb3ee1a70d7f9a3e47cd91655ff9a6cfd5 100644 --- a/jadx-gui/src/main/java/jadx/gui/utils/search/ResourceIndex.java +++ b/jadx-gui/src/main/java/jadx/gui/utils/search/ResourceIndex.java @@ -203,7 +203,7 @@ public class ResourceIndex { resNodes.add(resNode); } } else { - LOG.debug("Resource skipped because of size limit: {} res size {} bytes", resNode, size); + LOG.debug("Resource index skipped because of size limit: {} res size {} bytes", resNode, size); } } }