Re: What is the syntax to call DalvikNativeMethod types (exported in libdvm.so) from JNI?

336 views
Skip to first unread message

David Turner

unread,
May 2, 2013, 4:28:53 AM5/2/13
to andro...@googlegroups.com
You can't do that, this is an implementation detail of Dalvik that can change between platform versions. There is no guarantee that these functions will continue working as you expect, or even still be there. You should use JNI instead to call the corresponding SDK-exposed Java function.



On Tue, Apr 30, 2013 at 8:42 PM, Greg Walls <f...@charter.net> wrote:
I want to call dalvik's openDexFile() function from JNI.  I see it is exported as index "1" as static function in dalvik/vm/native/dalvik_system_DexFile.cpp
const DalvikNativeMethod dvm_dalvik_system_DexFile[] =
{ 
{ "openDexFile", "(Ljava/lang/String;Ljava/lang/String;I)I", Dalvik_dalvik_system_DexFile_openDexFile },
{ "openDexFile", "([B)I", Dalvik_dalvik_system_DexFile_openDexFile_bytearray },
{ "closeDexFile", "(I)V", Dalvik_dalvik_system_DexFile_closeDexFile },
{ "defineClass", "Ljava/lang/String;Ljava/lang/ClassLoader;I)Ljava/lang/Class;", Dalvik_dalvik_system_DexFile_defineClass },
{ "getClassNameList",   "(I)[Ljava/lang/String;", Dalvik_dalvik_system_DexFile_getClassNameList },
{ "isDexOptNeeded",     "(Ljava/lang/String;)Z", Dalvik_dalvik_system_DexFile_isDexOptNeeded },
{ NULL, NULL, NULL },
};

I'm trying to figure out what is the syntax to call this function from JNI and what header files (if any) do I need to include to get this dalvik structure defined in my JNI code. During my search, I located something similar in Appendix "A" of this write-up http://net.cs.uni-bonn.de/fileadmin/user_upload/plohmann/2012-Schulz-Code_Protection_in_Android.pdf  but I am not sure what to include to get this JNI code to compile

jint Java_com_test_mainactivity_openDexFile( JNIEnv* env, jobject thiz, jbyteArray dexData)
{
	jvalue pResult;
	jint result;
	u4 args[] = {(ArrayObject*)dexData};                      <<<< is "u4" from dalvik\common.h?  What is ArrayObject?
	dvm_dalvik_system_DexFile[1].fnPtr(args, &pResult);   <<<< how do I declare dvm_dalvik_system_DexFile?
result = pResult.l; return result; }

Any help is appreciated.  Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Greg Walls

unread,
May 6, 2013, 6:42:34 PM5/6/13
to andro...@googlegroups.com
Thanks Digit.  Is this the SDK-exposed java code you're refering too?
 
/ dalvik / src / main / java / dalvik / system / DexFile.java
 
If so, how can I refer to that "DexFile" class from JNI?  (appologies if this is a amaturish question but I'm new to JNI and I don't see the connectivity)

gadget

unread,
May 7, 2013, 12:14:23 PM5/7/13
to andro...@googlegroups.com
the public api: http://developer.android.com/reference/dalvik/system/DexFile.html

here's a brief pseudo-code for using via JNI

for custom classes:
0. Get Activity's class loader
1. LoadClass

for built-in classes:
1. FindClass

common:
2. InstantiateClass
3. Cache methods/fields
4. Use via JNIEnv->Call*Method
Reply all
Reply to author
Forward
0 new messages