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

Commit a245438

Browse files
committed
bug
1 parent 2b321da commit a245438

File tree

12 files changed

+167
-18
lines changed

12 files changed

+167
-18
lines changed

native/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,9 @@ else ()
179179
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/decrypt_linux.obj
180180
)
181181

182+
target_link_libraries(decrypt_test
183+
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/encrypt_linux.obj
184+
)
185+
182186
endif ()
183187

native/core_de.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#endif //NATIVE_CORE_DE_H
55

6-
#define LOG(msg) printf("[JVMTI-LOG] %s\n", msg)
6+
#define DE_LOG(msg) printf("[JVMTI-LOG] %s\n", msg)
77

88
// SEE decrypt.asm
99
extern void decrypt(unsigned char *, long);

native/core_en.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#endif //NATIVE_CORE_EN_H
55

6-
#define LOG(msg) printf("[ENCRYPT] %s\n", msg)
6+
#define EN_LOG(msg) printf("[ENCRYPT] %s\n", msg)
77

88
// SEE encrypt.asm
99
extern void encrypt(unsigned char *, long);

native/decrypt.asm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ decrypt PROC
55
push rbp
66
mov rbp, rsp
77
; save
8+
push rax
89
push rbx
10+
push rcx
11+
push rdx
912
push rsi
1013
push rdi
1114
; char* str
@@ -53,7 +56,10 @@ magic:
5356
; recover
5457
pop rdi
5558
pop rsi
59+
pop rdx
60+
pop rcx
5661
pop rbx
62+
pop rax
5763
; recover rbp
5864
pop rbp
5965
ret

native/decrypt_linux.asm

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,66 @@ section .text
22
global decrypt
33

44
decrypt:
5-
; NOP
5+
; init
6+
push rbp
7+
mov rbp, rsp
8+
; save
9+
push rax
10+
push rbx
11+
push rcx
12+
push rdx
13+
push rsi
14+
push rdi
15+
; char* str -> rdi
16+
mov rdi, rdi
17+
; long length -> rsi
18+
mov rsi, rsi
19+
mov rcx, rsi
20+
; rbx = 0
21+
xor rbx, rbx
22+
; rbx = rbx + 4
23+
add rbx, 004h
24+
; signature
25+
mov rsi, rcx
26+
sub rsi, 001h
27+
mov al, byte [rdi+rsi]
28+
mov ah, byte [rdi+004h]
29+
mov byte [rdi+004h], al
30+
mov byte [rdi+rsi], ah
31+
; reset
32+
xor ah, ah
33+
xor al, al
34+
xor rsi, rsi
35+
link_start:
36+
; if ebx >= ecx goto end
37+
cmp rbx, rcx
38+
jge magic
39+
; al = str[rdi+rbx]
40+
mov al, byte [rdi+rbx]
41+
; al = al ^ 22
42+
xor al, 022h
43+
; al = al -1
44+
sub al, 001h
45+
; al = ~al
46+
not al
47+
; al = al ^ 11h
48+
xor al, 011h
49+
; al = al + 2
50+
add al, 002h
51+
; str[rdi+rbx] = al
52+
mov byte [rdi+rbx], al
53+
; ebx ++
54+
inc ebx
55+
; loop
56+
jmp link_start
57+
magic:
58+
; recover
59+
pop rdi
60+
pop rsi
61+
pop rdx
62+
pop rcx
63+
pop rbx
64+
pop rax
65+
; recover rbp
66+
pop rbp
667
ret

native/decrypt_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "core_de.h"
2+
#include "core_en.h"
23
#include "stdio.h"
34

45
void printHex(const unsigned char *arr, int length) {
@@ -14,6 +15,8 @@ int main() {
1415
0x00, 0x00, 0x00, 0x05,
1516
0x01, 0x02, 0x03, 0x04,
1617
};
18+
encrypt(code,12);
19+
printHex(code,12);
1720
decrypt(code,12);
1821
printHex(code,12);
1922
}

native/encrypt.asm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ encrypt PROC
55
push rbp
66
mov rbp, rsp
77
; save
8+
push rax
89
push rbx
10+
push rcx
11+
push rdx
912
push rsi
1013
push rdi
1114
; char* str
@@ -60,7 +63,10 @@ magic:
6063
; recover
6164
pop rdi
6265
pop rsi
66+
pop rdx
67+
pop rcx
6368
pop rbx
69+
pop rax
6470
; recover rbp
6571
pop rbp
6672
ret

native/encrypt_linux.asm

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,74 @@ section .text
22
global encrypt
33

44
encrypt:
5-
; NOP
5+
; init
6+
push rbp
7+
mov rbp, rsp
8+
9+
push rax
10+
push rbx
11+
push rcx
12+
push rdx
13+
push rsi
14+
push rdi
15+
16+
; char* str
17+
mov rdi, rdi
18+
; long length
19+
mov rcx, rsi
20+
; rbx = 0
21+
xor rbx, rbx
22+
link_start:
23+
; if rbx >= rcx goto end
24+
cmp rbx, rcx
25+
jge magic
26+
; al = str[rdi+rbx]
27+
mov al, byte [rdi+rbx]
28+
; al = al - 2
29+
sub al, 0x02
30+
; al = al ^ 11h
31+
xor al, 0x11
32+
; al = ~al
33+
not al
34+
; al = al + 1
35+
add al, 0x01
36+
; al = al ^ 22
37+
xor al, 0x22
38+
; str[rdi+rbx] = al
39+
mov byte [rdi+rbx], al
40+
; ebx ++
41+
inc rbx
42+
; loop
43+
jmp link_start
44+
magic:
45+
; magic
46+
mov al, 0xca
47+
mov byte [rdi+0x00], al
48+
mov al, 0xfe
49+
mov byte [rdi+0x01], al
50+
mov al, 0xba
51+
mov byte [rdi+0x02], al
52+
mov al, 0xbe
53+
mov byte [rdi+0x03], al
54+
; signature
55+
mov rsi, rcx
56+
sub rsi, 0x01
57+
mov al, byte [rdi+rsi]
58+
mov ah, byte [rdi+0x04]
59+
mov byte [rdi+0x04], al
60+
mov byte [rdi+rsi], ah
61+
; reset
62+
xor ah, ah
63+
xor al, al
64+
xor rsi, rsi
65+
66+
pop rdi
67+
pop rsi
68+
pop rdx
69+
pop rcx
70+
pop rbx
71+
pop rax
72+
73+
; recover rbp
74+
pop rbp
675
ret

native/encryptor.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ JNIEXPORT jbyteArray JNICALL Java_org_y4sec_encryptor_core_CodeEncryptor_encrypt
5252
memcpy(chars, data, length);
5353
// 1. asm encrypt
5454
encrypt(chars, length);
55-
LOG("ASM ENCRYPT FINISH");
55+
EN_LOG("ASM ENCRYPT FINISH");
5656
// 2. tea encrypt
5757
if (length < 34) {
58-
LOG("ERROR: BYTE CODE TOO SHORT");
58+
EN_LOG("ERROR: BYTE CODE TOO SHORT");
5959
return text;
6060
}
6161
// {[10:14],[14:18]}
6262
internal(chars, 10);
63-
LOG("TEA ENCRYPT #1");
63+
EN_LOG("TEA ENCRYPT #1");
6464
// {[18:22],[22:26]}
6565
internal(chars, 18);
66-
LOG("TEA ENCRYPT #2");
66+
EN_LOG("TEA ENCRYPT #2");
6767
// {[26:30],[30:34]}
6868
internal(chars, 26);
69-
LOG("TEA ENCRYPT #3");
69+
EN_LOG("TEA ENCRYPT #3");
7070
(*env)->SetByteArrayRegion(env, text, 0, length, (jbyte *) chars);
7171
return text;
7272
}

native/start_linux.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void JNICALL ClassDecryptHook(
7575
}
7676

7777
JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
78-
LOG("UNLOAD AGENT");
78+
DE_LOG("UNLOAD AGENT");
7979
}
8080

8181
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
@@ -107,7 +107,7 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
107107
}
108108

109109
if (value == NULL) {
110-
LOG("NEED PACKAGE_NAME PARAMS\n");
110+
DE_LOG("NEED PACKAGE_NAME PARAMS\n");
111111
return 0;
112112
}
113113

@@ -119,44 +119,44 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
119119
printf("PACKAGE-LENGTH: %lu\n", strlen(PACKAGE_NAME));
120120

121121
jvmtiEnv *jvmti;
122-
LOG("INIT JVMTI ENVIRONMENT");
122+
DE_LOG("INIT JVMTI ENVIRONMENT");
123123
jint ret = (*vm)->GetEnv(vm, (void **) &jvmti, JVMTI_VERSION);
124124
if (JNI_OK != ret) {
125125
printf("ERROR: Unable to access JVMTI!\n");
126126
printf("PLEASE USE JVM VERSION 8");
127127
return ret;
128128
}
129-
LOG("INIT JVMTI CAPABILITIES");
129+
DE_LOG("INIT JVMTI CAPABILITIES");
130130
jvmtiCapabilities capabilities;
131131
(void) memset(&capabilities, 0, sizeof(capabilities));
132132

133133
capabilities.can_generate_all_class_hook_events = 1;
134134

135-
LOG("ADD JVMTI CAPABILITIES");
135+
DE_LOG("ADD JVMTI CAPABILITIES");
136136
jvmtiError error = (*jvmti)->AddCapabilities(jvmti, &capabilities);
137137
if (JVMTI_ERROR_NONE != error) {
138138
printf("ERROR: Unable to AddCapabilities JVMTI!\n");
139139
return error;
140140
}
141141

142-
LOG("INIT JVMTI CALLBACKS");
142+
DE_LOG("INIT JVMTI CALLBACKS");
143143
jvmtiEventCallbacks callbacks;
144144
(void) memset(&callbacks, 0, sizeof(callbacks));
145145

146-
LOG("SET JVMTI CLASS FILE LOAD HOOK");
146+
DE_LOG("SET JVMTI CLASS FILE LOAD HOOK");
147147
callbacks.ClassFileLoadHook = &ClassDecryptHook;
148148
error = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
149149
if (JVMTI_ERROR_NONE != error) {
150150
printf("ERROR: Unable to SetEventCallbacks JVMTI!\n");
151151
return error;
152152
}
153-
LOG("SET EVENT NOTIFICATION MODE");
153+
DE_LOG("SET EVENT NOTIFICATION MODE");
154154
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
155155
if (JVMTI_ERROR_NONE != error) {
156156
printf("ERROR: Unable to SetEventNotificationMode JVMTI!\n");
157157
return error;
158158
}
159159

160-
LOG("INIT JVMTI SUCCESS");
160+
DE_LOG("INIT JVMTI SUCCESS");
161161
return JNI_OK;
162162
}

0 commit comments

Comments
 (0)