Skip to content

Commit

Permalink
Change how assets/xposed_init is read
Browse files Browse the repository at this point in the history
The previous way ended up loading the file via a jar: URL, which caches
the file internally (i.e. keeps it open). That's not desired here, so
let's just read the file via the ZipFile API and decide ourselves when
to close it.
  • Loading branch information
rovo89 committed Nov 24, 2016
1 parent 84bbee4 commit 9e88044
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/de/robv/android/xposed/XposedHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipFile;

import dalvik.system.DexFile;
import external.org.apache.commons.lang3.ClassUtils;
Expand Down Expand Up @@ -1511,6 +1512,17 @@ public static byte[] assetAsByteArray(Resources res, String path) throws IOExcep
}
}

/**
* Invokes the {@link ZipFile#close()} method, ignoring IOExceptions.
*/
/*package*/ static void closeSilently(ZipFile zipFile) {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException ignored) {}
}
}

/**
* Returns the lowercase hex string representation of a file's MD5 hash sum.
*/
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/java/de/robv/android/xposed/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import dalvik.system.DexFile;
import dalvik.system.PathClassLoader;
Expand Down Expand Up @@ -400,13 +402,24 @@ private static void loadModule(String apk, ClassLoader topClassLoader) {

closeSilently(dexFile);

ClassLoader mcl = new PathClassLoader(apk, XposedBridge.BOOTCLASSLOADER);
InputStream is = mcl.getResourceAsStream("assets/xposed_init");
if (is == null) {
Log.e(TAG, "assets/xposed_init not found in the APK");
ZipFile zipFile = null;
InputStream is;
try {
zipFile = new ZipFile(apk);
ZipEntry zipEntry = zipFile.getEntry("assets/xposed_init");
if (zipEntry == null) {
Log.e(TAG, " assets/xposed_init not found in the APK");
closeSilently(zipFile);
return;
}
is = zipFile.getInputStream(zipEntry);
} catch (IOException e) {
Log.e(TAG, " Cannot read assets/xposed_init in the APK", e);
closeSilently(zipFile);
return;
}

ClassLoader mcl = new PathClassLoader(apk, XposedBridge.BOOTCLASSLOADER);
BufferedReader moduleClassesReader = new BufferedReader(new InputStreamReader(is));
try {
String moduleClassName;
Expand Down Expand Up @@ -457,6 +470,7 @@ private static void loadModule(String apk, ClassLoader topClassLoader) {
Log.e(TAG, " Failed to load module from " + apk, e);
} finally {
closeSilently(is);
closeSilently(zipFile);
}
}
}

0 comments on commit 9e88044

Please sign in to comment.