Java Code Examples for dalvik.system.DexFile#entries()

The following examples show how to use dalvik.system.DexFile#entries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From QNotified with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 仅仅为群发器而使用本模块的用户往往有两个鲜明的特征
 * 1.使用某个虚拟框架
 * 2.显而易见的昵称,见{@link #isBadNick(String)}
 * 仍然提供本模块的全部功能
 * 只是隐藏我的联系方式
 * 未必是完全正确的方法, but just do it.
 **/
private static boolean isExp() {
    try {
        Object pathList = iget_object_or_null(XposedBridge.class.getClassLoader(), "pathList");
        Object[] dexElements = (Object[]) iget_object_or_null(pathList, "dexElements");
        for (Object entry : dexElements) {
            DexFile dexFile = (DexFile) iget_object_or_null(entry, "dexFile");
            Enumeration<String> entries = dexFile.entries();
            while (entries.hasMoreElements()) {
                String className = entries.nextElement();
                if (className.matches(".+?(epic|weishu).+")) {
                    return true;
                }
            }
        }
    } catch (Throwable e) {
        if (!(e instanceof NullPointerException) &&
                !(e instanceof NoClassDefFoundError)) {
            log(e);
        }
    }
    return false;
}
 
Example 2
Source File: BundleReleaser.java    From atlas with Apache License 2.0 6 votes vote down vote up
public boolean checkDexValid(DexFile odexFile) throws IOException {
    if (DexReleaser.isArt()) {
        String applicationName = KernalConstants.RAW_APPLICATION_NAME;
        try {
            Enumeration<String> enumeration = odexFile.entries();
            while (enumeration.hasMoreElements()) {
                if (enumeration.nextElement().replace("/", ".").equals(applicationName)) {
                    return true;
                }
            }
            return false;
        } catch (Throwable e) {
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: ObjectHelper.java    From ParcelCheck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets all of the classes within a package
 * @param context the context
 * @param packageName the package name to fetch classes from
 * @return an list of named classes within package
 */
public static ArrayList<String> getClassesOfPackage(Context context, String packageName) {
    ArrayList<String> classes = new ArrayList<>();
    try {
        String packageCodePath = context.getPackageCodePath();
        DexFile df = new DexFile(packageCodePath);
        for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
            String className = iter.nextElement();
            if (className.contains(packageName)) {
                classes.add(className.substring(className.lastIndexOf(".") + 1, className.length()));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return classes;
}
 
Example 4
Source File: DroidNubeKit.java    From DroidNubeKit with MIT License 6 votes vote down vote up
private Set<Class<?>> getClasspathClasses() throws IOException, ClassNotFoundException {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    DexFile dex = new DexFile(getContext().getApplicationInfo().sourceDir);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Enumeration<String> entries = dex.entries();
    while (entries.hasMoreElements()) {
        String entry = entries.nextElement();
        if (entry.toLowerCase().startsWith(getContext().getPackageName().toLowerCase())) {

            Class<?> clazz = classLoader.loadClass(entry);
            if(clazz.isAnnotationPresent(RecordType.class)) {
                modelClasses.add(clazz);
            }
            classes.add(clazz);
        }
    }
    return classes;
}
 
Example 5
Source File: AndroidPrototypeFactorySetup.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Scans all classes accessible from the context class loader which belong to the given package and subpackages.
 */
public static List<String> getClasses(Context c)
        throws IOException {
    ArrayList<String> classNames = new ArrayList<>();

    String zpath = c.getApplicationInfo().sourceDir;


    if (zpath == null) {
        zpath = "/data/app/org.commcare.android.apk";
    }

    DexFile df = new DexFile(new File(zpath));
    for (Enumeration<String> en = df.entries(); en.hasMoreElements(); ) {
        String cn = en.nextElement();
        loadClass(cn, classNames);
    }
    df.close();

    return classNames;
}
 
Example 6
Source File: ModelRegistryUtils.java    From framework with GNU Affero General Public License v3.0 6 votes vote down vote up
public void makeReady(Context context) {
    try {
        DexFile dexFile = new DexFile(context.getPackageCodePath());
        for (Enumeration<String> item = dexFile.entries(); item.hasMoreElements(); ) {
            String element = item.nextElement();
            if (element.startsWith(App.class.getPackage().getName())) {
                Class<? extends OModel> clsName = (Class<? extends OModel>) Class.forName(element);
                if (clsName != null && clsName.getSuperclass() != null &&
                        OModel.class.isAssignableFrom(clsName.getSuperclass())) {
                    String modelName = getModelName(context, clsName);
                    if (modelName != null) {
                        this.models.put(modelName, clsName);
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: DelegatingClassLoader.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Clear the existing delegate and return the new one, populated with the given dex files
 *
 * @param dexJars the .dex.jar files which will be managed by our delegate
 */
void resetDelegate(List<File> dexJars) {
  mDelegate = new PathClassLoader("", "", this);
  mManagedClassesToDexFile.clear();
  for (File dexJar : dexJars) {
    try {
      final File optFile = new File(mDexOptDir, dexJar.getName());
      DexFile dexFile = DexFile.loadDex(dexJar.getCanonicalPath(), optFile.getCanonicalPath(), 0);
      final Enumeration<String> entries = dexFile.entries();
      while (entries.hasMoreElements()) {
        mManagedClassesToDexFile.put(entries.nextElement(), dexFile);
      }
    } catch (IOException e) {
      // Pass for now
    }
  }
}
 
Example 8
Source File: ClassUtils.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
/**
 * 获取dexFile所有类
 *
 * @param context
 * @return
 */
public static List<String> getAllClassNameFromDexFile(Context context, String packageName) {
    final List<String> classList = new ArrayList<>();
    try {
        final DexFile df = new DexFile(context.getPackageCodePath());
        String str;
        for (final Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
            str = iter.nextElement();
            if ((packageName != null && str.startsWith(packageName))
                    || (packageName == null || "".equals(packageName))) {
                classList.add(str);
            }
        }
        df.close();
    } catch (IOException e) {
        Log.e("IOException " + e.getMessage());
    }
    return classList;
}
 
Example 9
Source File: AndroidComponentScanner.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@Override
public void scan(String[] packageNames) throws IOException {
	if (applicationContext == null) {
		throw new NullPointerException(
				AndroidComponentScanner.class.getSimpleName()
						+ ".APPLICATION_CONTEXT needs to be set before initialising "
						+ DependencyInjection.class.getSimpleName());
	}

	DexFile dex = new DexFile(
			applicationContext.getApplicationInfo().sourceDir);
	ClassLoader classLoader = Thread.currentThread()
			.getContextClassLoader();
	Enumeration<String> entries = dex.entries();
	while (entries.hasMoreElements()) {
		String className = entries.nextElement();
		if (classNameContainsPackage(packageNames, className)) {
			try {
				checkClassForAnnotations(classLoader.loadClass(className));
			} catch (Exception e) {
				Log.wtf(TAG, e);
			}
		}
	}
}
 
Example 10
Source File: SSJDescriptor.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param dexFile DexFile
 */
private void scanDex(DexFile dexFile)
{
	Enumeration<String> classNames = dexFile.entries();
	while (classNames.hasMoreElements())
	{
		String className = classNames.nextElement();
		if (className.startsWith("hcm.ssj.") && !className.contains("$"))
		{
			hsClassNames.add(className);
		}
	}
}
 
Example 11
Source File: DexUtils.java    From zone-sdk with MIT License 5 votes vote down vote up
public static List<Class> getClassByPackage(String packageName){
	try {
		DexFile df = new DexFile(packageName);
		Enumeration<String> ite = df.entries();
		while (ite.hasMoreElements()) {
			String str = (String) ite.nextElement();
			System.out.println("잚츰:"+str);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 12
Source File: CommonUtil.java    From Aria with Apache License 2.0 5 votes vote down vote up
/**
 * 获取指定包名下的所有类
 *
 * @param path dex路径
 * @param filterClass 需要过滤的类
 */
public static List<String> getPkgClassName(String path, String filterClass) {
  List<String> list = new ArrayList<>();
  try {
    File file = new File(path);
    if (!file.exists()) {
      ALog.w(TAG, String.format("路径【%s】下的Dex文件不存在", path));
      return list;
    }

    DexFile df = new DexFile(path);//通过DexFile查找当前的APK中可执行文件
    Enumeration<String> enumeration = df.entries();//获取df中的元素  这里包含了所有可执行的类名 该类名包含了包名+类名的方式
    while (enumeration.hasMoreElements()) {
      String _className = enumeration.nextElement();
      if (!_className.contains(filterClass)) {
        continue;
      }
      if (_className.contains(filterClass)) {
        list.add(_className);
      }
    }
    df.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return list;
}
 
Example 13
Source File: ClassesListActivity.java    From android-classyshark with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {

    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

        File incomeFile = File.createTempFile("classes" + Thread.currentThread().getId(), ".dex", getCacheDir());

        IOUtils.bytesToFile(bytes, incomeFile);

        File optimizedFile = File.createTempFile("opt" + Thread.currentThread().getId(), ".dex", getCacheDir());

        DexFile dx = DexFile.loadDex(incomeFile.getPath(),
                optimizedFile.getPath(), 0);

        for (Enumeration<String> classNames = dx.entries(); classNames.hasMoreElements(); ) {
            String className = classNames.nextElement();
            classesList.add(className);
        }

    } catch (Exception e) {
        // ODEX, need to see how to handle
        e.printStackTrace();
    }


    ClassesListActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {

            final ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < classesList.getClassNames().size(); ++i) {
                list.add(classesList.getClassNames().get(i));
            }
            final StableArrayAdapter adapter = new StableArrayAdapter(ClassesListActivity.this,
                    android.R.layout.simple_list_item_1, list);
            lv.setAdapter(adapter);

            mProgressDialog.dismiss();

            if(classesList.getClassNames().isEmpty()) {
                Toast.makeText(ClassesListActivity.this, "Sorry don't support ODEX", Toast.LENGTH_LONG).show();
            }
        }
    });
}