Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PROSKEY/272664b59ba430189ec92b285dfe622a to your computer and use it in GitHub Desktop.
Save PROSKEY/272664b59ba430189ec92b285dfe622a to your computer and use it in GitHub Desktop.
get signature with jni
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_gist_SignatureChecker */
#ifndef _Included_com_example_gist_SignatureChecker
#define _Included_com_example_gist_SignatureChecker
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_gist_SignatureChecker
* Method: getKey
* Signature: ()V
*/
JNIEXPORT jstring JNICALL Java_com_example_gist_SignatureChecker_getKey(JNIEnv* env, jobject thizz, jobject thiz)
{
// context
jclass native_context = env->GetObjectClass(thiz);
// context.getPackageManager()
jmethodID methodID_func = env->GetMethodID(native_context, "getPackageManager", "()Landroid/content/pm/PackageManager;");
jobject package_manager = env->CallObjectMethod(thiz,methodID_func);
jclass pm_clazz = env->GetObjectClass(package_manager);
//packageManager.getPackageInfo()
jmethodID methodId_pm = env->GetMethodID(pm_clazz,"getPackageInfo","(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;");
//context.getPackageName()
jmethodID methodID_packagename = env->GetMethodID(native_context,"getPackageName","()Ljava/lang/String;");
jstring name_str = static_cast<jstring>(env->CallObjectMethod(thiz,methodID_packagename));
jobject package_info = env->CallObjectMethod(package_manager,methodId_pm,name_str,64);
jclass pi_clazz = env->GetObjectClass(package_info);
//packageInfo.signatures
jfieldID fieldID_signatures = env->GetFieldID(pi_clazz,"signatures","[Landroid/content/pm/Signature;");
jobject signatur = env->GetObjectField(package_info,fieldID_signatures);
jobjectArray signatures = reinterpret_cast<jobjectArray>(signatur);
//signatures[0]
jobject signature = env->GetObjectArrayElement(signatures,0);
jclass s_clazz = env->GetObjectClass(signature);
//signatures[0].toCharString()
jmethodID methodId_ts = env->GetMethodID(s_clazz,"toCharsString","()Ljava/lang/String;");
jobject ts = env->CallObjectMethod(signature,methodId_ts);
//return signature
return reinterpret_cast<jstring>(ts);
}
#ifdef __cplusplus
}
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment