Last active
December 10, 2015 16:59
-
-
Save tylertreat/4464869 to your computer and use it in GitHub Desktop.
Method used to extract classes.dex from an APK and copy it to a cache directory for processing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void extractDex(String apk) { | |
try { | |
JarFile file = new JarFile(apk); | |
Enumeration<JarEntry> entries = file.entries(); | |
while (entries.hasMoreElements()) { | |
JarEntry entry = entries.nextElement(); | |
if (entry.getName().equals("classes.dex")) { | |
File cache = getDir("dex_cache", Context.MODE_PRIVATE); | |
if (!cache.exists()) | |
cache.mkdirs(); | |
File classes = new File(cache + File.separator + "classes.dex"); | |
InputStream stream = file.getInputStream(entry); | |
FileOutputStream fos = new FileOutputStream(classes); | |
while (stream.available() > 0) | |
fos.write(stream.read()); | |
fos.close(); | |
stream.close(); | |
} | |
} | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment