Use the signature mechanism for program self-check-Android anti-cracking and self-check android

Source: Internet
Author: User

Use the signature mechanism for program self-check-Android anti-cracking and self-check android

Self-check program 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 Java in cpp to call the c interface

#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, 64);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


The hashCode in HelloWorld is the result of our self-check. When the program is running, check whether the hashCode is consistent with the signature.

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.