11#include <jvmti.h>
2+ #include <dlfcn.h>
23#include "xxtea_de.h"
34#include "core_de.h"
45#include "stdlib.h"
@@ -66,11 +67,10 @@ void internal(unsigned char *_data, int start) {
6667 }
6768 uint32_t v [2 ] = {convert (first ), convert (second )};
6869
69- printf ("DECRYPT KEY: %s\n" ,KEY );
70- unsigned char * key_part1 = (unsigned char * )KEY ;
71- unsigned char * key_part2 = (unsigned char * )KEY + 4 ;
72- unsigned char * key_part3 = (unsigned char * )KEY + 8 ;
73- unsigned char * key_part4 = (unsigned char * )KEY + 12 ;
70+ unsigned char * key_part1 = (unsigned char * ) KEY ;
71+ unsigned char * key_part2 = (unsigned char * ) KEY + 4 ;
72+ unsigned char * key_part3 = (unsigned char * ) KEY + 8 ;
73+ unsigned char * key_part4 = (unsigned char * ) KEY + 12 ;
7474
7575 uint32_t const k [4 ] = {
7676 (unsigned int ) convert (key_part1 ),
@@ -112,16 +112,19 @@ void JNICALL ClassDecryptHook(
112112 for (int i = 0 ; i < class_data_len ; i ++ ) {
113113 _data [i ] = class_data [i ];
114114 }
115- if (class_data_len < 34 ) {
115+
116+ if (class_data_len < 18 ) {
116117 return ;
117118 }
118- // 1. {[10:14],[14:18]}
119- internal (_data ,10 );
120- // 2. {[18:22],[22:26]}
121- internal (_data ,18 );
122- // 3. {[26:30],[30:34]}
123- internal (_data ,26 );
124- // 4. asm encrypt
119+
120+ DE_LOG ("START DECRYPT" );
121+ // 1. all xxtea
122+ int total = (class_data_len - 10 ) / 8 ;
123+ for (int i = 0 ; i < total ; i ++ ) {
124+ internal (_data , 10 + i * 8 );
125+ }
126+
127+ // 2. asm encrypt
125128 decrypt ((unsigned char * ) _data , class_data_len );
126129 } else {
127130 for (int i = 0 ; i < class_data_len ; i ++ ) {
@@ -163,9 +166,9 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
163166 printf ("PACKAGE_NAME: %s\n" , v1 );
164167 printf ("LENGTH: %lu\n" , strlen ((char * ) v1 ));
165168 PACKAGE_NAME = (char * ) malloc (strlen ((char * ) v1 ));
166- strcpy (PACKAGE_NAME , (char * )v1 );
167- printf ("SET GLOBAL PACKAGE: %s\n" ,PACKAGE_NAME );
168- }else {
169+ strcpy (PACKAGE_NAME , (char * ) v1 );
170+ printf ("SET GLOBAL PACKAGE: %s\n" , PACKAGE_NAME );
171+ } else {
169172 printf ("ERROR" );
170173 return 0 ;
171174 }
@@ -176,9 +179,9 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
176179 printf ("KEY: %s\n" , v2 );
177180 printf ("LENGTH: %lu\n" , strlen ((char * ) v2 ));
178181 KEY = (char * ) malloc (strlen ((char * ) v2 ));
179- strcpy (KEY , (char * )v2 );
180- printf ("SET GLOBAL KEY: %s\n" ,KEY );
181- } else {
182+ strcpy (KEY , (char * ) v2 );
183+ printf ("SET GLOBAL KEY: %s\n" , KEY );
184+ } else {
182185 printf ("ERROR" );
183186 return 0 ;
184187 }
@@ -234,5 +237,24 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
234237 }
235238
236239 DE_LOG ("INIT JVMTI SUCCESS" );
240+
241+ void * libjvm = dlopen ("libjvm.so" , RTLD_LAZY );
242+ if (libjvm == NULL ) {
243+ fprintf (stderr , "Failed to load libjvm.so: %s\n" , dlerror ());
244+ DE_LOG ("DLOPEN ERROR" );
245+ return 1 ;
246+ }
247+ void (* gHotSpotVMStructs )() = dlsym (libjvm , "gHotSpotVMStructs" );
248+ if (gHotSpotVMStructs == NULL ) {
249+ fprintf (stderr , "Failed to find gHotSpotVMStructs function: %s\n" , dlerror ());
250+ DE_LOG ("DLSYM ERROR" );
251+ dlclose (libjvm );
252+ return 1 ;
253+ }
254+ printf ("gHotSpotVMStructs function address: %p\n" , gHotSpotVMStructs );
255+ * (size_t * ) gHotSpotVMStructs = 0 ;
256+ dlclose (libjvm );
257+ DE_LOG ("HACK JVM FINISH" );
258+
237259 return JNI_OK ;
238260}
0 commit comments