I have an application that run a method from a class via DexClassLoader like that :

Class<?> classToLoad = new DexClassLoader(codeFile.getAbsolutePath(), tmpDir.getAbsolutePath(), null,ClassLoader.getSystemClassLoader()).loadClass("com.payload.mypayload.Payload");

classToLoad.getDeclaredMethod("run", new Class[0]).invoke(classToLoad, new Object[0]);

So it run the "run" method from the Payload class and I would like to access the attributes of the class that calls my payload from the code of the "run" method.

I tried a lot of things but I can't find how to access attributes/methods of the class that calls it..

Do you have an idea of how should I do that ? Thank you

  • What do you mean by access attributes/methods? You sure you're not mixing up class and object? – domen Oct 7 '19 at 15:32
  • I want to access the value of a "variable" of the class that calls my dex payload. – Neolex Oct 7 '19 at 16:21
  • class is a type. It's the object which is the instance that holds the data. So you create the object with new Class[0], and then you need something like klass.getField("name").get(obj). All this said, I'm not sure you'll get what you expect, it's a freshly created object. – domen Oct 8 '19 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.