mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 06:34:25 +02:00
Closing Framework and APK after use
This commit should fix https://github.com/iBotPeaches/Apktool/issues/1160
This commit is contained in:
parent
4800bd7b44
commit
66c1b46865
@ -187,6 +187,11 @@ public class Main {
|
|||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException ex) {
|
||||||
System.err.println("Could not modify internal dex files. Please ensure you have permission.");
|
System.err.println("Could not modify internal dex files. Please ensure you have permission.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
decoder.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -741,6 +741,10 @@ public class Androlib {
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
mAndRes.close();
|
||||||
|
}
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(Androlib.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(Androlib.class.getName());
|
||||||
|
|
||||||
private final static String SMALI_DIRNAME = "smali";
|
private final static String SMALI_DIRNAME = "smali";
|
||||||
|
@ -60,6 +60,14 @@ public class ApkDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setApkFile(File apkFile) {
|
public void setApkFile(File apkFile) {
|
||||||
|
if (mApkFile != null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
mApkFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mApkFile = new ExtFile(apkFile);
|
mApkFile = new ExtFile(apkFile);
|
||||||
mResTable = null;
|
mResTable = null;
|
||||||
}
|
}
|
||||||
@ -73,6 +81,7 @@ public class ApkDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void decode() throws AndrolibException, IOException, DirectoryException {
|
public void decode() throws AndrolibException, IOException, DirectoryException {
|
||||||
|
try {
|
||||||
File outDir = getOutDir();
|
File outDir = getOutDir();
|
||||||
AndrolibResources.sKeepBroken = mKeepBrokenResources;
|
AndrolibResources.sKeepBroken = mKeepBrokenResources;
|
||||||
|
|
||||||
@ -160,6 +169,12 @@ public class ApkDecoder {
|
|||||||
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
||||||
mAndrolib.writeOriginalFiles(mApkFile, outDir);
|
mAndrolib.writeOriginalFiles(mApkFile, outDir);
|
||||||
writeMetaFile();
|
writeMetaFile();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
mApkFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDecodeSources(short mode) throws AndrolibException {
|
public void setDecodeSources(short mode) throws AndrolibException {
|
||||||
@ -273,6 +288,10 @@ public class ApkDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
mAndrolib.close();
|
||||||
|
}
|
||||||
|
|
||||||
public final static short DECODE_SOURCES_NONE = 0x0000;
|
public final static short DECODE_SOURCES_NONE = 0x0000;
|
||||||
public final static short DECODE_SOURCES_SMALI = 0x0001;
|
public final static short DECODE_SOURCES_SMALI = 0x0001;
|
||||||
|
|
||||||
|
@ -121,7 +121,8 @@ final public class AndrolibResources {
|
|||||||
File apk = getFrameworkApk(id, frameTag);
|
File apk = getFrameworkApk(id, frameTag);
|
||||||
|
|
||||||
LOGGER.info("Loading resource table from file: " + apk);
|
LOGGER.info("Loading resource table from file: " + apk);
|
||||||
ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true);
|
mFramework = new ExtFile(apk);
|
||||||
|
ResPackage[] pkgs = getResPackagesFromApk(mFramework, resTable, true);
|
||||||
|
|
||||||
ResPackage pkg;
|
ResPackage pkg;
|
||||||
if (pkgs.length > 1) {
|
if (pkgs.length > 1) {
|
||||||
@ -555,8 +556,16 @@ final public class AndrolibResources {
|
|||||||
private ResPackage[] getResPackagesFromApk(ExtFile apkFile,ResTable resTable, boolean keepBroken)
|
private ResPackage[] getResPackagesFromApk(ExtFile apkFile,ResTable resTable, boolean keepBroken)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
try {
|
try {
|
||||||
BufferedInputStream bfi = new BufferedInputStream(apkFile.getDirectory().getFileInput("resources.arsc"));
|
Directory dir = apkFile.getDirectory();
|
||||||
|
BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"));
|
||||||
|
try {
|
||||||
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
|
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
bfi.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException ex) {
|
||||||
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
||||||
}
|
}
|
||||||
@ -810,6 +819,10 @@ final public class AndrolibResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
mFramework.close();
|
||||||
|
}
|
||||||
|
|
||||||
public ApkOptions apkOptions;
|
public ApkOptions apkOptions;
|
||||||
|
|
||||||
// TODO: dirty static hack. I have to refactor decoding mechanisms.
|
// TODO: dirty static hack. I have to refactor decoding mechanisms.
|
||||||
@ -819,6 +832,8 @@ final public class AndrolibResources {
|
|||||||
|
|
||||||
private File mFrameworkDirectory = null;
|
private File mFrameworkDirectory = null;
|
||||||
|
|
||||||
|
private ExtFile mFramework = null;
|
||||||
|
|
||||||
private String mMinSdkVersion = null;
|
private String mMinSdkVersion = null;
|
||||||
private String mMaxSdkVersion = null;
|
private String mMaxSdkVersion = null;
|
||||||
private String mTargetSdkVersion = null;
|
private String mTargetSdkVersion = null;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package brut.directory;
|
package brut.directory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -235,6 +236,11 @@ public abstract class AbstractDirectory implements Directory {
|
|||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private SubPath getSubPath(String path) throws PathNotExist {
|
private SubPath getSubPath(String path) throws PathNotExist {
|
||||||
ParsedPath parsed = parsePath(path);
|
ParsedPath parsed = parsePath(path);
|
||||||
if (parsed.dir == null) {
|
if (parsed.dir == null) {
|
||||||
|
@ -50,5 +50,8 @@ public interface Directory {
|
|||||||
public int getCompressionLevel(String fileName)
|
public int getCompressionLevel(String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
|
|
||||||
|
|
||||||
|
public void close() throws IOException;
|
||||||
|
|
||||||
public final char separator = '/';
|
public final char separator = '/';
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package brut.directory;
|
package brut.directory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,5 +55,9 @@ public class ExtFile extends File {
|
|||||||
return mDirectory;
|
return mDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
mDirectory.close();
|
||||||
|
}
|
||||||
|
|
||||||
private Directory mDirectory;
|
private Directory mDirectory;
|
||||||
}
|
}
|
||||||
|
@ -151,4 +151,8 @@ public class ZipRODirectory extends AbstractDirectory {
|
|||||||
return mZipFile;
|
return mZipFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
mZipFile.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user