Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit ae5285e

Browse files
committed
linux support
1 parent 38f5535 commit ae5285e

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

native/encryptor.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_y4sec_encryptor_core_CodeEncryptor_encrypt
5757
jbyte *data = (*env)->GetByteArrayElements(env, text, NULL);
5858
unsigned char *chars = (unsigned char *) malloc(length);
5959
memcpy(chars, data, length);
60+
6061
// 1. asm encrypt
6162
encrypt(chars, length);
6263
EN_LOG("ASM ENCRYPT FINISH");
64+
6365
// 2. tea encrypt
64-
if (length < 34) {
66+
if (length < 18) {
6567
EN_LOG("ERROR: BYTE CODE TOO SHORT");
6668
return text;
6769
}
@@ -71,15 +73,12 @@ JNIEXPORT jbyteArray JNICALL Java_org_y4sec_encryptor_core_CodeEncryptor_encrypt
7173
memcpy(tea_key, j_tea_key, 16);
7274
printf("KEY: %s\n", tea_key);
7375

74-
// {[10:14],[14:18]}
75-
internal(chars, 10, tea_key);
76-
EN_LOG("TEA ENCRYPT #1");
77-
// {[18:22],[22:26]}
78-
internal(chars, 18, tea_key);
79-
EN_LOG("TEA ENCRYPT #2");
80-
// {[26:30],[30:34]}
81-
internal(chars, 26, tea_key);
82-
EN_LOG("TEA ENCRYPT #3");
76+
EN_LOG("ALL TEA ENCRYPT");
77+
int total = (length - 10) / 8;
78+
for (int i = 0; i < total; i++) {
79+
internal(chars, 10 + i * 8,tea_key);
80+
}
81+
8382
(*env)->SetByteArrayRegion(env, text, 0, length, (jbyte *) chars);
8483
return text;
8584
}

native/start_linux.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
}

src/main/resources/libdecrypter.so

256 Bytes
Binary file not shown.

src/main/resources/libencryptor.so

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)