我想知道我是否可以将加密的类或jar文件附加到我的apk并在应用程序内解密类/ jar文件,然后使用DexClassLoader加载该类?
答案 0 :(得分:2)
有可能,请参考here获取更多基本信息,我所做的是更改prepareDex函数以解密文件并将其保存在本地。下面是通过反射加载类的代码的一部分:
final File optimizedDexOutputPath = getDir("outdex", Context.MODE_PRIVATE);
final File dexInternalStoragePath = new File(getDir("dex", Context.MODE_PRIVATE),
SECONDARY_DEX_NAME);
// Initialize the class loader with the secondary dex file.
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader());
try {
@SuppressWarnings("unchecked")
final Class<Object> obj = (Class<Object>) cl.loadClass("com.packagename.Classname");
final Constructor<Object> constr = obj.getConstructor(Activity.class, String.class, Handler.class);
myInstance = constr.newInstance(this, mString, mHandler);
Method doSomething;
try {
doSomething = v.getMethod("YOURMETHOD");
doSomething.invoke(myInstance);
}
}
我也忽略了所有捕获量,但这些应该很容易生成/处理。