From 97e7952c85237fa7a8b090af10cdf8bd3afd247e Mon Sep 17 00:00:00 2001 From: Aleksey Zotov <30636242+azotzot@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:42:19 +0300 Subject: [PATCH 1/2] add missing stream closing --- .../brut/androlib/res/ResourcesDecoder.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java index 7ee7f77ea0..6ea5eca350 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java @@ -77,6 +77,8 @@ public void decodeManifest(File outDir) throws AndrolibException { XmlPullStreamDecoder fileDecoder = new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()); Directory inApk, out; + InputStream inputStream = null; + OutputStream outputStream = null; try { inApk = mApkInfo.getApkFile().getDirectory(); out = new FileDirectory(outDir); @@ -86,12 +88,15 @@ public void decodeManifest(File outDir) throws AndrolibException { } else { LOGGER.info("Decoding AndroidManifest.xml with only framework resources..."); } - InputStream inputStream = inApk.getFileInput("AndroidManifest.xml"); - OutputStream outputStream = out.getFileOutput("AndroidManifest.xml"); + inputStream = inApk.getFileInput("AndroidManifest.xml"); + outputStream = out.getFileOutput("AndroidManifest.xml"); fileDecoder.decodeManifest(inputStream, outputStream); } catch (DirectoryException ex) { throw new AndrolibException(ex); + } finally { + closeQuietly(inputStream); + closeQuietly(outputStream); } if (mApkInfo.hasResources()) { @@ -113,6 +118,16 @@ public void decodeManifest(File outDir) throws AndrolibException { } } + private void closeQuietly(Closeable toClose) { + if (toClose != null) { + try { + toClose.close(); + } catch (IOException e) { + LOGGER.warning(String.format("Can`t close: %s!!!", toClose)); + } + } + } + public void updateApkInfo(File outDir) throws AndrolibException { mResTable.initApkInfo(mApkInfo, outDir); } From 880e1128f2a83f5edc2acdf1f75bc8db65099d5e Mon Sep 17 00:00:00 2001 From: Aleksey Zotov <30636242+azotzot@users.noreply.github.com> Date: Sat, 6 Jul 2024 16:23:50 +0300 Subject: [PATCH 2/2] replace custom close with apache --- .../java/brut/androlib/res/ResourcesDecoder.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java index 6ea5eca350..f74f6a9312 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java @@ -28,6 +28,7 @@ import brut.directory.Directory; import brut.directory.DirectoryException; import brut.directory.FileDirectory; +import org.apache.commons.io.IOUtils; import org.xmlpull.v1.XmlSerializer; import java.io.*; @@ -95,8 +96,8 @@ public void decodeManifest(File outDir) throws AndrolibException { } catch (DirectoryException ex) { throw new AndrolibException(ex); } finally { - closeQuietly(inputStream); - closeQuietly(outputStream); + IOUtils.closeQuietly(inputStream); + IOUtils.closeQuietly(outputStream); } if (mApkInfo.hasResources()) { @@ -118,16 +119,6 @@ public void decodeManifest(File outDir) throws AndrolibException { } } - private void closeQuietly(Closeable toClose) { - if (toClose != null) { - try { - toClose.close(); - } catch (IOException e) { - LOGGER.warning(String.format("Can`t close: %s!!!", toClose)); - } - } - } - public void updateApkInfo(File outDir) throws AndrolibException { mResTable.initApkInfo(mApkInfo, outDir); }