mirror of
https://github.com/revanced/smali.git
synced 2025-05-06 09:24:33 +02:00
Add support for class path entries that look like dalvik-cache entries
This commit is contained in:
parent
2887ade533
commit
fd258ad543
@ -48,6 +48,8 @@ import java.io.IOException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ClassPath {
|
public class ClassPath {
|
||||||
@Nonnull private final TypeProto unknownClass;
|
@Nonnull private final TypeProto unknownClass;
|
||||||
@ -159,13 +161,25 @@ public class ClassPath {
|
|||||||
return new ClassPath(dexFiles);
|
return new ClassPath(dexFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Pattern dalvikCacheOdexPattern = Pattern.compile("@([^@]+)@classes.dex$");
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static DexFile loadClassPathEntry(Iterable<String> classPathDirs, String bootClassPathEntry) {
|
private static DexFile loadClassPathEntry(Iterable<String> classPathDirs, String bootClassPathEntry) {
|
||||||
for (String classPathDir: classPathDirs) {
|
|
||||||
File rawEntry = new File(bootClassPathEntry);
|
File rawEntry = new File(bootClassPathEntry);
|
||||||
// strip off the path - we only care about the filename
|
// strip off the path - we only care about the filename
|
||||||
String entryName = rawEntry.getName();
|
String entryName = rawEntry.getName();
|
||||||
|
|
||||||
|
// if it's a dalvik-cache entry, grab the name of the jar/apk
|
||||||
|
if (entryName.endsWith("@classes.dex")) {
|
||||||
|
Matcher m = dalvikCacheOdexPattern.matcher(entryName);
|
||||||
|
|
||||||
|
if (!m.find()) {
|
||||||
|
throw new ExceptionWithContext(String.format("Cannot parse dependency value %s", bootClassPathEntry));
|
||||||
|
}
|
||||||
|
|
||||||
|
entryName = m.group(1);
|
||||||
|
}
|
||||||
|
|
||||||
int extIndex = entryName.lastIndexOf(".");
|
int extIndex = entryName.lastIndexOf(".");
|
||||||
|
|
||||||
String baseEntryName;
|
String baseEntryName;
|
||||||
@ -175,6 +189,7 @@ public class ClassPath {
|
|||||||
baseEntryName = entryName.substring(0, extIndex);
|
baseEntryName = entryName.substring(0, extIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String classPathDir: classPathDirs) {
|
||||||
for (String ext: new String[]{"", ".odex", ".jar", ".apk", ".zip"}) {
|
for (String ext: new String[]{"", ".odex", ".jar", ".apk", ".zip"}) {
|
||||||
File file = new File(classPathDir, baseEntryName + ext);
|
File file = new File(classPathDir, baseEntryName + ext);
|
||||||
|
|
||||||
@ -184,7 +199,9 @@ public class ClassPath {
|
|||||||
"warning: cannot open %s for reading. Will continue looking.", file.getPath()));
|
"warning: cannot open %s for reading. Will continue looking.", file.getPath()));
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return DexFileFactory.loadDexFile(file);
|
DexFile dexfile = DexFileFactory.loadDexFile(file);
|
||||||
|
System.out.println(file.toString());
|
||||||
|
return dexfile;
|
||||||
} catch (DexFileFactory.NoClassesDexException ex) {
|
} catch (DexFileFactory.NoClassesDexException ex) {
|
||||||
// ignore and continue
|
// ignore and continue
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user