@Override public String getPackageCodePath() { return mBase.getPackageCodePath(); }
String packageCodePath = context.getPackageCodePath(); Process process = null; DataOutputStream os = null;
@Override public String getPackageCodePath() { return mBase.getPackageCodePath(); }
@TargetApi(8) private String getContextPackageCodePath() { //getPackageCodePath() was hidden return getContext().getPackageCodePath(); }
@TargetApi(8) private String getTargetContextPackageCodePath() { //getPackageCodePath() was hidden return getTargetContext().getPackageCodePath(); }
@TargetApi(8) private String getTargetContextPackageCodePath() { //getPackageCodePath() was hidden return getTargetContext().getPackageCodePath(); }
@TargetApi(8) private String getContextPackageCodePath() { //getPackageCodePath() was hidden return getContext().getPackageCodePath(); }
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; }
/** * 根据包名构建目标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; }
/** * 根据包名构建目标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; }
public static String getApkFileDigest(Context context) { String apkPath = context.getPackageCodePath(); try { byte[] hashed= getDigest(new FileInputStream(apkPath), "SHA-256"); return Base64.encodeToString(hashed, Base64.DEFAULT); } catch (Throwable throwable) { throwable.printStackTrace(); } return null; } public static final int BUFFER_SIZE = 2048; public static byte[] getDigest(InputStream in, String algorithm) throws Throwable { MessageDigest md = MessageDigest.getInstance(algorithm); try { DigestInputStream dis = new DigestInputStream(in, md); byte[] buffer = new byte[BUFFER_SIZE]; while (dis.read(buffer) != -1) { } dis.close(); } finally { in.close(); } return md.digest(); }
String packageCodePath = context.getPackageCodePath(); Process process = null; DataOutputStream os = null;
public static String getApkDigest() throws Exception { String apkDigest = null; String apkPath = ClientProperties.getApplicationContext().getPackageCodePath(); InputStream inputStream = null; try { inputStream = new FileInputStream(new File(apkPath)); apkDigest = Utilities.Sha256(inputStream); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { } } return apkDigest; }
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(); } }
/** * Given a package and class name, check if the class exists or not. * * @param package_name * @param class_name * @return true if exists, false otherwise */ public static boolean isClassAvailable(Context context, String package_name, String class_name) { if (context.getResources().getBoolean(R.bool.standalone)) { try { Class.forName(package_name + "." + class_name); return true; } catch (ClassNotFoundException e) { return false; } } else { try { Context package_context = context.createPackageContext(package_name, Context.CONTEXT_IGNORE_SECURITY + Context.CONTEXT_INCLUDE_CODE); DexFile df = new DexFile(package_context.getPackageCodePath()); for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) { String className = iter.nextElement(); if (className.contains(class_name)) return true; } return false; } catch (IOException | NameNotFoundException e) { return false; } } }
/** * @param context * @param basepath * @param callback * @param filter */ public static void doScannerFilter(Context context, String basepath, CallbackTemplate<String> callback, FilterTemplate<String> filter) { try { DexFile dexFile = new DexFile(context.getPackageCodePath()); Enumeration<String> it = dexFile.entries(); while (it.hasMoreElements()) { String classname = it.nextElement(); if (classname.startsWith(basepath) && (filter == null || filter.doWith(classname))) { callback.doWith(classname); } } } catch (BreakException e) { } catch (IOException e) { e.printStackTrace(); } } }
/** * 对虚拟机中的类名进行过滤 * * @author gdpancheng@gmail.com 2013-9-20 下午11:41:05 * @param context * @param callback * @param filter * @return void */ public static void doScannerFilter(Context context, CallbackBreak<String> callback, FilterTemplate<String> filter) { try { // cont.getPackageCodePath() 获取自身APK的路径 DexFile dexFile = new DexFile(context.getPackageCodePath()); // Enumeration<String> entries ()迭代其中的类名 Enumeration<String> it = dexFile.entries(); while (it.hasMoreElements()) { String classname = it.nextElement(); if (filter == null || filter.doWith(classname)) { callback.doWith(classname); } classname = null; } if (dexFile != null) { dexFile.close(); } dexFile = null; } catch (BreakException e) { } catch (IOException e) { } }
Log.e(mContext.getPackageCodePath(), "ResId is wrong ."); return;
nativeLibraryDir = applicationInfo.nativeLibraryDir; classLoader = new ZeusClassLoader(mBaseContext.getPackageCodePath(), mBaseContext.getClassLoader(), nativeLibraryDir);
nativeLibraryDir = applicationInfo.nativeLibraryDir; ZeusClassLoader classLoader = new ZeusClassLoader(mBaseContext.getPackageCodePath(), cl, nativeLibraryDir); classLoader.addAPKPath(pluginId, pluginApkPath, PluginUtil.getLibFileInside(pluginId)); PluginUtil.setField(mPackageInfo, "mClassLoader", classLoader);