Open ms1995 opened 6 years ago
My prototype for fixing this problem in a not-that-elegant way:
public abstract class EllaWrapper {
private static Method m_method;
static {
try {
Class<?> ella_class = Class.forName("com.apposcopy.ella.runtime.Ella");
m_method = ella_class.getDeclaredMethod("m", int.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void m(int mId) {
try {
m_method.invoke(null, mId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Basically, I use Java reflection to get the reference to the main class at very beginning, and subsequent calls to m
will use the reference directly.
Modify Ella instrumentation to merge the main Ella classes to classes.dex
and wrapper classes to classes2.dex
, classes3.dex
, etc. This should make sure that main Ella classes are always loaded first (before wrapper classes try to find them via reflection).
Modify Ella instrumentation to target the Ella classes that are included in the respective DEX files when instrumenting each method in the app. Otherwise the instrumentor will say that it cannot find reference to the Ella main class.
One issue of this approach is that, if classes.dex
already has too many methods (already reaching the 64K limitation), the approach will not work since main Ella classes cannot be merged into the main DEX file.
Hope this helps.
@ms1995 Hi, I'm facing the same problem. Do you have a working prototype? Could you kindly share your code? Thanks a lot!
@yisun92 I do have a working prototype and will release it later. Thanks.
@yisun92
Please see my working version at,
Thanks! I'll have a try
It seems that current implementation supports instrumenting only one dex in an app.