Application of signature mechanism to self-test--android anti-cracking

Source: Internet
Author: User

The self-test program is written in so.

Main code

Import in file header

#if (Cc_target_platform = = cc_platform_android) #include <jni.h> #include <android/log.h> #include < string.h> #include <unistd.h> #endif

Then write to the interface of Java call C in CPP

#if (Cc_target_platform = = cc_platform_android) extern "C" {jniexport jint jnicall java_org_cocos2dx_cpp_appactivity_ checkapk (jnienv *env, Jclass jcl,jobject context_object) {Jclass Context_class = Env->getobjectclass (context_object );//context.getpackagemanager () Jmethodid Methodid = Env->getmethodid (Context_class, "GetPackageManager", "() Landroid/content/pm/packagemanager; "); Jobject package_manager_object = Env->callobjectmethod (Context_object, Methodid); if (Package_manager_object = = NULL) {__android_log_print (Android_log_info, "Jnitag", "Getpackagemanager () failed!"); return NULL;} Context.getpackagename () Methodid = Env->getmethodid (Context_class, "Getpackagename", "() Ljava/lang/String;"); Jstring package_name_string = (jstring) env->callobjectmethod (Context_object, Methodid); if (package_name_string = = NULL) {__android_log_print (Android_log_info, "Jnitag", "Getpackagename () failed!"); return NULL;} Env->deletelocalref (Context_class);//packagemanager.getpackageinfo (Sting, int) Jclass Pack_manager_class = Env->getobjectclass (package_manager_object); methodid = Env->GetMethodID (pack_ Manager_class, "Getpackageinfo", "(ljava/lang/string;i) landroid/content/pm/packageinfo;"); Env->deletelocalref (Pack_manager_class); Jobject package_info_object = Env->callobjectmethod (package_manager _object, Methodid, package_name_string, +); if (package_info_object = = NULL) {__android_log_print (Android_log_info, " Jnitag "," Getpackageinfo () failed! "); return NULL;} Env->deletelocalref (package_manager_object);//packageinfo.signatures[0]jclass Package_info_class = env-> Getobjectclass (package_info_object); Jfieldid FieldID = Env->getfieldid (Package_info_class, "signatures", "[ Landroid/content/pm/signature; "); Env->deletelocalref (Package_info_class); Jobjectarray Signature_object_array = (jobjectarray) env-> Getobjectfield (Package_info_object, FieldID), if (Signature_object_array = = NULL) {__android_log_print (ANDROID_LOG_ INFO, "Jnitag", "packageinfo.signatures[" is null "); return NULL;} Jobject signature_object = env->getobjectarrayelement (signature_object_array, 0); Env->deletelocalref (Package _info_object);//signature.tocharsstring () Jclass signature_class = Env->getobjectclass (Signature_object); Methodid = Env->getmethodid (Signature_class, "Hashcode", "() I"); Env->deletelocalref (signature_class); int signature_string = Env->callintmethod (Signature_object, Methodid); Helloworld::hashcode = Signature_string;return signature_string;}} #endif


HelloWorld in the hashcode is the result of our self-test, the program run time to detect whether hashcode is consistent with the signature

Application of signature mechanism to self-test--android anti-cracking

Related Article

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.