use of dalvik.system.DexFile in project Auto.js by hyb1996.
the class AndroidClassLoader method dexJar.
private DexFile dexJar() throws IOException {
if (!classFile.exists()) {
classFile.createNewFile();
}
final Main.Arguments arguments = new Main.Arguments();
arguments.fileNames = new String[] { classFile.getPath() };
arguments.outName = dexFile.getPath();
arguments.jarOutput = true;
Main.run(arguments);
DexFile dex = DexFile.loadDex(dexFile.getPath(), odexOatFile.getPath(), 0);
dx.add(dex);
return dex;
}
use of dalvik.system.DexFile in project AndroidLife by CaMnter.
the class ClassUtils method getFileNameByPackageName.
public static List<String> getFileNameByPackageName(Context context, String packageName) throws PackageManager.NameNotFoundException, IOException {
List<String> classNames = new ArrayList<>();
for (String path : getSourcePaths(context)) {
DexFile dexfile = null;
try {
if (path.endsWith(EXTRACTED_SUFFIX)) {
// NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache"
dexfile = DexFile.loadDex(path, path + ".tmp", 0);
} else {
dexfile = new DexFile(path);
}
Enumeration<String> dexEntries = dexfile.entries();
while (dexEntries.hasMoreElements()) {
String className = dexEntries.nextElement();
if (className.contains(packageName)) {
classNames.add(className);
}
}
} catch (Throwable ignore) {
Log.e("ARouter", "Scan map file in dex files made error.", ignore);
} finally {
if (null != dexfile) {
try {
dexfile.close();
} catch (Throwable ignore) {
}
}
}
}
Log.d("ClassUtils", "Filter " + classNames.size() + " classes by packageName <" + packageName + ">");
return classNames;
}
use of dalvik.system.DexFile in project ARouter by alibaba.
the class ClassUtils method tryLoadInstantRunDexFile.
/**
* Get instant run dex path, used to catch the branch usingApkSplits=false.
*/
private static List<String> tryLoadInstantRunDexFile(ApplicationInfo applicationInfo) {
List<String> instantRunSourcePaths = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && null != applicationInfo.splitSourceDirs) {
// add the split apk, normally for InstantRun, and newest version.
instantRunSourcePaths.addAll(Arrays.asList(applicationInfo.splitSourceDirs));
Log.d(Consts.TAG, "Found InstantRun support");
} else {
try {
// This man is reflection from Google instant run sdk, he will tell me where the dex files go.
Class pathsByInstantRun = Class.forName("com.android.tools.fd.runtime.Paths");
Method getDexFileDirectory = pathsByInstantRun.getMethod("getDexFileDirectory", String.class);
String instantRunDexPath = (String) getDexFileDirectory.invoke(null, applicationInfo.packageName);
File instantRunFilePath = new File(instantRunDexPath);
if (instantRunFilePath.exists() && instantRunFilePath.isDirectory()) {
File[] dexFile = instantRunFilePath.listFiles();
for (File file : dexFile) {
if (null != file && file.exists() && file.isFile() && file.getName().endsWith(".dex")) {
instantRunSourcePaths.add(file.getAbsolutePath());
}
}
Log.d(Consts.TAG, "Found InstantRun support");
}
} catch (Exception e) {
Log.e(Consts.TAG, "InstantRun support error, " + e.getMessage());
}
}
return instantRunSourcePaths;
}
use of dalvik.system.DexFile in project QuantumFlux by himanshu-soni.
the class ReflectionHelper method getAllClasses.
private static List<String> getAllClasses(Context context) throws PackageManager.NameNotFoundException, IOException {
String packageName = ManifestHelper.getPackageName(context);
String path = getSourcePath(context);
List<String> classNames = new ArrayList<String>();
DexFile dexfile = null;
try {
dexfile = new DexFile(path);
Enumeration<String> dexEntries = dexfile.entries();
while (dexEntries.hasMoreElements()) {
String className = dexEntries.nextElement();
if (className.startsWith(packageName))
classNames.add(className);
}
} catch (NullPointerException e) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> urls = classLoader.getResources("");
while (urls.hasMoreElements()) {
List<String> fileNames = new ArrayList<String>();
String classDirectoryName = urls.nextElement().getFile();
if (classDirectoryName.contains("bin") || classDirectoryName.contains("classes")) {
File classDirectory = new File(classDirectoryName);
for (File filePath : classDirectory.listFiles()) {
populateFiles(filePath, fileNames, "");
}
for (String fileName : fileNames) {
if (fileName.startsWith(packageName))
classNames.add(fileName);
}
}
}
} finally {
if (null != dexfile)
dexfile.close();
}
return classNames;
}
use of dalvik.system.DexFile in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class SystemPropertiesReflection method set.
/**
* Set the value for the given key.
*
* @throws IllegalArgumentException if the key exceeds 32 characters
* OR if the value exceeds 92 characters
*/
public static void set(Context context, String key, String val) throws IllegalArgumentException {
try {
@SuppressWarnings("unused") DexFile df = new DexFile(new File("/system/app/Settings.apk"));
@SuppressWarnings("unused") ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes") Class SystemProperties = Class.forName("android.os.SystemProperties");
// Parameters Types
@SuppressWarnings("rawtypes") Class[] paramTypes = new Class[2];
paramTypes[0] = String.class;
paramTypes[1] = String.class;
Method set = SystemProperties.getMethod("set", paramTypes);
// Parameters
Object[] params = new Object[2];
params[0] = key;
params[1] = val;
set.invoke(SystemProperties, params);
} catch (IllegalArgumentException iae) {
log.error(iae.getMessage(), iae);
throw iae;
} catch (Exception ignored) {
log.debug(ignored.getMessage(), ignored);
}
}
Aggregations