I would like to execute opcodes directly against the running Dalvik VM instance from within my application on Android. I'm looking for something similar to the C asm function. I have a list of opcodes for dalvik, but I am unfamiliar with how to either execute them directly, or write them out to .class files and execute them against some sort of VM CLI command like dalvikvm from within a running application.
Asked
Active
Viewed 1,364 times
2 Answers
5
its not possible. See the Google IO 2008 presentation on youtube about Dalvik internals for details. Mobile VMs including both Java and MS .NET are not full VMs and due to memory and performance constraints thus leave out parts that allow to accomplish what you have described.

Fred Grott
- 3,505
- 1
- 23
- 18
-
As I dug further into it, I see that this is unfortunately true... Thanks! – Heat Miser Jun 03 '09 at 22:20
-
[I originally posted this as a separate answer, before I had commenting rights.] You do not need root access to load dex files. There is a system class, dalvik.system.DexClassLoader, which is built to make it reasonably straightforward to load dex files. – danfuzz Jan 06 '12 at 17:24
1
In the past it was impossible, but now it is possible:
http://android-developers.blogspot.sg/2011/07/custom-class-loading-in-dalvik.html
Essentially you can create your customized dex file and load and execute it.

Peter Teoh
- 6,337
- 4
- 42
- 58