@@ -64,132 +64,13 @@ alias_ref<jclass> nativeEngineClass;
6464
6565const char hexcode[] = {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' A' , ' B' , ' C' , ' D' , ' E' ,
6666 ' F' };
67- // 君子坦荡荡,小人常戚戚
68- // 这个类没有别的用途,就是用来防止别人直接通过我编译好的APK进行修改操作
69- // 如果你是源码编译,删掉即可
70- // The gentleman is frank and the villains are often sad
71- // This class has no other purpose. It is used to prevent others from directly modifying the compiled APK.
72- // If you are compiling source code, delete it
73-
74- void verifySignature (JNIEnv *env) {
75- jclass context_class = env->FindClass (" android/content/Context" );
76-
77- jclass xpp_class = env->FindClass (" io/virtualapp/XApp" );
78- jmethodID get_app = env->GetStaticMethodID (xpp_class, " getApp" , " ()Lio/virtualapp/XApp;" );
79- jobject context_object = env->CallStaticObjectMethod (xpp_class, get_app);
80- env->DeleteLocalRef (xpp_class);
81-
82- jmethodID methodId = env->GetMethodID (context_class, " getPackageManager" ,
83- " ()Landroid/content/pm/PackageManager;" );
84- jobject package_manager = env->CallObjectMethod (context_object, methodId);
85- if (package_manager == NULL ) {
86- ALOGD (" package_manager is NULL!!!" );
87- return ;
88- }
89-
90- methodId = env->GetMethodID (context_class, " getPackageName" , " ()Ljava/lang/String;" );
91- jstring package_name = (jstring) env->CallObjectMethod (context_object, methodId);
92- if (package_name == NULL ) {
93- ALOGD (" package_name is NULL!!!" );
94- return ;
95- }
96- env->DeleteLocalRef (context_class);
97-
98- // 获取PackageInfo对象
99- jclass pack_manager_class = env->GetObjectClass (package_manager);
100- methodId = env->GetMethodID (pack_manager_class, " getPackageInfo" ,
101- " (Ljava/lang/String;I)Landroid/content/pm/PackageInfo;" );
102- env->DeleteLocalRef (pack_manager_class);
103- jobject package_info = env->CallObjectMethod (package_manager, methodId, package_name, 0x40 );
104- if (package_info == NULL ) {
105- ALOGD (" getPackageInfo() is NULL!!!" );
106- return ;
107- }
108- env->DeleteLocalRef (package_manager);
109-
110- // 获取签名信息
111- jclass package_info_class = env->GetObjectClass (package_info);
112- jfieldID fieldId = env->GetFieldID (package_info_class, " signatures" ,
113- " [Landroid/content/pm/Signature;" );
114- env->DeleteLocalRef (package_info_class);
115- jobjectArray signature_object_array = (jobjectArray) env->GetObjectField (package_info, fieldId);
116- if (signature_object_array == NULL ) {
117- ALOGD (" signature is NULL!!!" );
118- return ;
119- }
120- jobject signature_object = env->GetObjectArrayElement (signature_object_array, 0 );
121- env->DeleteLocalRef (package_info);
122-
123- // 签名信息转换成sha1值
124- jclass signature_class = env->GetObjectClass (signature_object);
125- methodId = env->GetMethodID (signature_class, " toByteArray" , " ()[B" );
126- env->DeleteLocalRef (signature_class);
127- jbyteArray signature_byte = (jbyteArray) env->CallObjectMethod (signature_object, methodId);
128- jclass byte_array_input_class = env->FindClass (" java/io/ByteArrayInputStream" );
129- methodId = env->GetMethodID (byte_array_input_class, " <init>" , " ([B)V" );
130- jobject byte_array_input = env->NewObject (byte_array_input_class, methodId, signature_byte);
131- jclass certificate_factory_class = env->FindClass (" java/security/cert/CertificateFactory" );
132- methodId = env->GetStaticMethodID (certificate_factory_class, " getInstance" ,
133- " (Ljava/lang/String;)Ljava/security/cert/CertificateFactory;" );
134- jstring x_509_jstring = env->NewStringUTF (" X.509" );
135- jobject cert_factory = env->CallStaticObjectMethod (certificate_factory_class, methodId,
136- x_509_jstring);
137- methodId = env->GetMethodID (certificate_factory_class, " generateCertificate" ,
138- (" (Ljava/io/InputStream;)Ljava/security/cert/Certificate;" ));
139- jobject x509_cert = env->CallObjectMethod (cert_factory, methodId, byte_array_input);
140- env->DeleteLocalRef (certificate_factory_class);
141- jclass x509_cert_class = env->GetObjectClass (x509_cert);
142- methodId = env->GetMethodID (x509_cert_class, " getEncoded" , " ()[B" );
143- jbyteArray cert_byte = (jbyteArray) env->CallObjectMethod (x509_cert, methodId);
144- env->DeleteLocalRef (x509_cert_class);
145- jclass message_digest_class = env->FindClass (" java/security/MessageDigest" );
146- methodId = env->GetStaticMethodID (message_digest_class, " getInstance" ,
147- " (Ljava/lang/String;)Ljava/security/MessageDigest;" );
148- jstring sha1_jstring = env->NewStringUTF (" SHA1" );
149- jobject sha1_digest = env->CallStaticObjectMethod (message_digest_class, methodId, sha1_jstring);
150- methodId = env->GetMethodID (message_digest_class, " digest" , " ([B)[B" );
151- jbyteArray sha1_byte = (jbyteArray) env->CallObjectMethod (sha1_digest, methodId, cert_byte);
152- env->DeleteLocalRef (message_digest_class);
153-
154- // 转换成char
155- jsize array_size = env->GetArrayLength (sha1_byte);
156- jbyte *sha1 = env->GetByteArrayElements (sha1_byte, NULL );
157- char *hex_sha = new char [array_size * 2 + 1 ];
158- for (int i = 0 ; i < array_size; ++i) {
159- hex_sha[2 * i] = hexcode[((unsigned char ) sha1[i]) / 16 ];
160- hex_sha[2 * i + 1 ] = hexcode[((unsigned char ) sha1[i]) % 16 ];
161- }
162- hex_sha[array_size * 2 ] = ' \0 ' ;
163-
164- if (strcmp (" 739A2395C962B54285D9D2B9F418F23BAA175EDD" , hex_sha) != 0 ) {
165- env->ExceptionDescribe ();
166- env->ExceptionClear ();
167- jclass newExcCls = env->FindClass (" java/lang/IllegalArgumentException" );
168- srand ((unsigned ) time (0 ));
169- int random = rand () % 4 ;
170- // ALOGE("random: %d", random);
171- if (random <= 0 ) {
172- // set VirtualCore to null to cause a random crash.
173- jclass virtual_core_class = env->FindClass (" com/lody/virtual/client/core/VirtualCore" );
174- jfieldID gCore = env->GetStaticFieldID (virtual_core_class, " gCore" , " Lcom/lody/virtual/client/core/VirtualCore;" );
175- env->SetStaticObjectField (virtual_core_class, gCore , NULL );
176- env->DeleteLocalRef (virtual_core_class);
177-
178- env->ThrowNew (newExcCls, " " );
179- }
180- env->DeleteLocalRef (newExcCls);
181- }
182- }
183-
18467
18568JNIEXPORT jint JNICALL JNI_OnLoad (JavaVM *vm, void *) {
18669 JNIEnv* env;
18770 if (vm->GetEnv ((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
18871 return -1 ;
18972 }
19073
191- verifySignature (env);
192-
19374 return initialize (vm, [] {
19475 nativeEngineClass = findClassStatic (" com/lody/virtual/client/NativeEngine" );
19576 nativeEngineClass->registerNatives ({
0 commit comments