android.content.Context#getPackageCodePath ( )源码实例Demo

下面列出了android.content.Context#getPackageCodePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: XposedHider   文件: InitInjector.java

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 *
 * @param context           context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
private File findApkFile(Context context, String modulePackageName) {
    if (context == null) {
        return null;
    }
    try {
        Context moduleContext = context.createPackageContext(
                modulePackageName,
                Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        String apkPath = moduleContext.getPackageCodePath();
        return new File(apkPath);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码2 项目: SecuritySample   文件: Utils.java

private static long getApkFileChecksum(Context context) {
    String apkPath = context.getPackageCodePath();
    Long chksum = null;
    try {
        // Open the file and build a CRC32 checksum.
        FileInputStream fis = new FileInputStream(new File(apkPath));
        CRC32 chk = new CRC32();
        CheckedInputStream cis = new CheckedInputStream(fis, chk);
        byte[] buff = new byte[80];
        while (cis.read(buff) >= 0) ;
        chksum = chk.getValue();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return chksum;
}
 
源代码3 项目: Aria   文件: CommonUtil.java

/**
 * 获取某包下所有类
 *
 * @param className 过滤的类名
 * @return 类的完整名称
 */
public static List<String> getPkgClassNames(Context context, String className) {
  List<String> classNameList = new ArrayList<>();
  String pPath = context.getPackageCodePath();
  File dir = new File(pPath).getParentFile();
  String[] paths = dir.list();
  if (paths == null) {
    classNameList.addAll(getPkgClassName(pPath, className));
  } else {
    String dPath = dir.getPath();
    for (String path : dir.list()) {
      String fPath = dPath + "/" + path;
      if (!fPath.endsWith(".apk")) {
        continue;
      }
      classNameList.addAll(getPkgClassName(fPath, className));
    }
  }
  return classNameList;
}
 
源代码4 项目: ParcelCheck   文件: ObjectHelper.java

/**
 * 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;
}
 
源代码5 项目: framework   文件: ModelRegistryUtils.java

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();
    }
}
 
源代码6 项目: Cangol-appcore   文件: ClassUtils.java

/**
 * 获取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;
}
 
源代码7 项目: QNotified   文件: HookLoader.java

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 *
 * @param context           context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
@TargetApi(Build.VERSION_CODES.FROYO)
private File findApkFile(Context context, String modulePackageName) {
    if (context == null) {
        return null;
    }
    try {
        Context moudleContext = context.createPackageContext(modulePackageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        String apkPath = moudleContext.getPackageCodePath();
        return new File(apkPath);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码8 项目: ZhihuXposed   文件: HookLoader.java

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 * @param context context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
private File findApkFile(Context context,String modulePackageName){
    if (context==null){
        return null;
    }
    try {
        Context moudleContext = context.createPackageContext(modulePackageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        String apkPath = moudleContext.getPackageCodePath();
        return new File(apkPath);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码9 项目: fuckView   文件: InitInjector.java

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 *
 * @param context           context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
private File findApkFile(Context context, String modulePackageName) {
    if (context == null) {
        return null;
    }
    try {
        Context moudleContext = context.createPackageContext(modulePackageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        String apkPath = moudleContext.getPackageCodePath();
        return new File(apkPath);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码10 项目: SecuritySample   文件: Utils.java

private static byte[] getApkFileDigest(Context context) {
    String apkPath = context.getPackageCodePath();
    try {
        return getDigest(new FileInputStream(apkPath), "SHA-256");
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return null;
}
 

static synchronized Context loadNativeLib(Context context) {
    try {
        if (nativeLibLoaded) return context;
        ApplicationInfo otherAppInfo = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), 0);

        String primaryCpuAbi = (String) ApplicationInfo.class.getField("primaryCpuAbi").get(otherAppInfo);
        if (primaryCpuAbi != null) {
            String path = "lib/" + primaryCpuAbi + "/libvtm-jni.so";
            File cacheFile = new File(context.getApplicationContext().getCacheDir().getAbsolutePath() + "/.gmscore/" + path);
            cacheFile.getParentFile().mkdirs();
            File apkFile = new File(context.getPackageCodePath());
            if (!cacheFile.exists() || cacheFile.lastModified() < apkFile.lastModified()) {
                ZipFile zipFile = new ZipFile(apkFile);
                ZipEntry entry = zipFile.getEntry(path);
                if (entry != null) {
                    copyInputStream(zipFile.getInputStream(entry), new FileOutputStream(cacheFile));
                } else {
                    Log.d(TAG, "Can't load native library: " + path + " does not exist in " + apkFile);
                }
            }
            Log.d(TAG, "Loading vtm-jni from " + cacheFile.getPath());
            System.load(cacheFile.getAbsolutePath());
            nativeLibLoaded = true;
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    }
    if (!nativeLibLoaded) {
        Log.d(TAG, "Loading native vtm-jni");
        System.loadLibrary("vtm-jni");
        nativeLibLoaded = true;
    }
    return context;
}
 
 方法所在类
 同类方法