Android JNI Get app Signature

Source: Internet
Author: User

Use Android JNI to get an app signature.

Generate your own password based on the signature you get, which prevents others from recompiling their source code and looking for a password.

Jstring java_com_masonsdk_jni_jniutil_getpwd (jnienv* env, Jobject thizz,jobject thiz) {Jclass Native_clazz = env->    Getobjectclass (Thiz); Get the ID of the Getpackagemanager method Jmethodid Methodid_func =env->getmethodid (Native_clazz, "Getpackagemanager", "() Landr    Oid/content/pm/packagemanager; ");    Get the App Package Manager jobject Package_manager = Env->callobjectmethod (Thiz, Methodid_func);    Get Packagemanager class Jclass Pm_clazz = Env->getobjectclass (Package_manager); Get the ID of the Getpackageinfo method Jmethodid methodid_pm = Env->getmethodid (Pm_clazz, "Getpackageinfo", "(Ljava    /lang/string;i) landroid/content/pm/packageinfo; ");    Get the package name Jmethodid methodid_packagename =env->getmethodid (Native_clazz, "Getpackagename", "() Ljava/lang/String;");    Jstring name_str = static_cast<jstring> (Env->callobjectmethod (Thiz, methodid_packagename)); Get information about the app package Jobject package_info = Env->callobjectmethod (Package_manager, METHODID_PM, NAME_STR, 64);//Env->newstringutf ("COM.EXAMPLE.CONTASDF")//Get PackageInfo class Jclass Pi_clazz = Env->getobjectclass (package_i    NFO); Gets the ID of the signature array property Jfieldid Fieldid_signatures = Env->getfieldid (Pi_clazz, "signatures", "[Landroid/content    /pm/signature; ");    Get signature Array, pending modification jobject Signatur = Env->getobjectfield (Package_info, fieldid_signatures);    Jobjectarray signatures = reinterpret_cast<jobjectarray> (Signatur);    Get signed Jobject signature = env->getobjectarrayelement (signatures, 0);    Get Signature class, pending modification Jclass S_clazz = Env->getobjectclass (Signature);    Get the ID of the Hashcode method Jmethodid METHODID_HC = Env->getmethodid (S_clazz, "Hashcode", "() I");    Get the application Package Manager, pending modification int hash_code = Env->callintmethod (signature, METHODID_HC);    Char str[100];    sprintf (str, "%u", hash_code); return Env->newstringutf (str);}

Source:

Https://github.com/mentor811/AndroidUltimateEncrypt


"Disclaimer: Copyright, welcome reprint, please do not use for commercial purposes. --SkyTeam "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.