I have been following the angeAPK talk. However ,I faced with some issues when I tried to use DexClassLoader.
I would like to unpack and load the dynamic code in the application activity, I was able to get the payloadapk, however when I try to load in the next method loadAPK(): the application crashes and gives me this exception:
String className = "com.example.cryptedv2.StringXORed"; //modify to new one
String methodToInvoke = "getFlagEncrypt"; //Modificar to new one
Log.v("loadDexClasses", "Dex Preparing to loadDexClasses!");
File dexOpt = this.getDir("dexOpt", MODE_PRIVATE);
final DexClassLoader classloader = new DexClassLoader(
apkPath,
dexOpt.getAbsolutePath(),
null,
this.getClassLoader());
Log.v("loadDexClasses", "Searching for class : "
+ "com.registry.Registry");
try {
Class<?> classToLoad = (Class<?>) classloader.loadClass(className);
Object instance = classToLoad.newInstance();
Method method = classToLoad.getMethod(methodToInvoke);
String flag = (String) method.invoke(instance);
} catch (IllegalAccessException e) {
e.printStackTrace ();
} catch (ClassNotFoundException e) {
e.printStackTrace ();
} catch (NoSuchMethodException e) {
e.printStackTrace ();
} catch (InvocationTargetException e) {
e.printStackTrace ();
} catch (InstantiationException e) {
e.printStackTrace ();
}
I tried to obfuscated also a .dex file of the application but it is also throwing the same exception.