Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

JVMTI功能兼容Windows 32位和MacOS #26

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,91 @@ if (WIN32)
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/native_encrypt_asm.obj
)

elseif (APPLE)
MESSAGE("BUILD APPLE")

enable_language(ASM_NASM)

add_custom_target(
native_encrypt_asm ALL
COMMAND nasm -f macho64 ${CMAKE_CURRENT_SOURCE_DIR}/encrypt_linux.asm
-o ${CMAKE_CURRENT_BINARY_DIR}/encrypt_linux.obj
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/encrypt_linux.obj
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_custom_target(
native_decrypt_asm ALL
COMMAND nasm -f macho64 ${CMAKE_CURRENT_SOURCE_DIR}/decrypt_linux.asm
-o ${CMAKE_CURRENT_BINARY_DIR}/decrypt_linux.obj
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/decrypt_linux.obj
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

MESSAGE("BUILD ENCRYPT DECRYPT ASM FINISH")

add_library(
encryptor SHARED
core_en.h
jni_encryptor.h
jni_encryptor.c

xxtea_common.c
xxtea_common.h
xxtea_en.h
xxtea_de.h
xxtea.c
)

add_library(
decrypter SHARED
core_de.h
start_linux.c

xxtea_common.c
xxtea_common.h
xxtea_en.h
xxtea_de.h
xxtea.c
)

add_dependencies(encryptor native_encrypt_asm)

add_dependencies(decrypter native_decrypt_asm)

target_link_libraries(encryptor
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/encrypt_linux.obj
)

target_link_libraries(decrypter
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/decrypt_linux.obj
)

add_executable(
xxtea_test
xxtea_common.h
xxtea_common.c
xxtea_en.h
xxtea_de.h
xxtea.c
xxtea_test.c
)

add_executable(
decrypt_test
core_de.h
core_en.h
decrypt_test.c
)

target_link_libraries(decrypt_test
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/decrypt_linux.obj
)

target_link_libraries(decrypt_test
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/encrypt_linux.obj
)

else ()
MESSAGE("BUILD LINUX")

Expand Down
70 changes: 70 additions & 0 deletions native/CMakeLists_for_decrypt_win32_x86.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.25)

################ JNI CONFIG START ################

project(native C)

set(CMAKE_C_STANDARD 11)

# INCLUDE JNI

find_package(JNI REQUIRED)

include_directories(${JNI_INCLUDE_DIRS})

################ JNI CONFIG END ##################

MESSAGE("BUILD WINDOWS")

enable_language(ASM_MASM)

add_custom_target(
native_decrypt_asm ALL
COMMAND ml /c /Fo${CMAKE_CURRENT_BINARY_DIR}/native_decrypt_asm.obj
${CMAKE_CURRENT_SOURCE_DIR}/decrypt_windows.asm
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/native_decrypt_asm.obj
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_library(
decrypter SHARED
core_de.h
start_windows.c

xxtea_common.c
xxtea_common.h
xxtea_en.h
xxtea_de.h
xxtea.c
)

set_property(TARGET native_decrypt_asm PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

add_dependencies(decrypter native_decrypt_asm)

target_link_libraries(decrypter
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/native_decrypt_asm.obj
)

add_executable(
xxtea_test
xxtea_common.h
xxtea_common.c
xxtea_en.h
xxtea_de.h
xxtea.c
xxtea_test.c
)

add_executable(
decrypt_test
core_de.h
core_en.h
decrypt_test.c
)

target_link_libraries(decrypt_test
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/native_decrypt_asm.obj
)
67 changes: 67 additions & 0 deletions native/decrypt_macos.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
section .text
global _decrypt

_decrypt:
; init
push rbp
mov rbp, rsp
; save
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
; char* str -> rdi
mov rdi, rdi
; long length -> rsi
mov rsi, rsi
mov rcx, rsi
; rbx = 0
xor rbx, rbx
; rbx = rbx + 4
add rbx, 004h
; signature
mov rsi, rcx
sub rsi, 001h
mov al, byte [rdi+rsi]
mov ah, byte [rdi+004h]
mov byte [rdi+004h], al
mov byte [rdi+rsi], ah
; reset
xor ah, ah
xor al, al
xor rsi, rsi
link_start:
; if ebx >= ecx goto end
cmp rbx, rcx
jge magic
; al = str[rdi+rbx]
mov al, byte [rdi+rbx]
; al = al ^ 22
xor al, 022h
; al = al -1
sub al, 001h
; al = ~al
not al
; al = al ^ 11h
xor al, 011h
; al = al + 2
add al, 002h
; str[rdi+rbx] = al
mov byte [rdi+rbx], al
; ebx ++
inc ebx
; loop
jmp link_start
magic:
; recover
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
; recover rbp
pop rbp
ret
54 changes: 54 additions & 0 deletions native/decrypt_windows_x86.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.386
.model flat, c
option casemap:none

.code

; FUNCTION decrypt
decrypt PROC USES edi esi ebx, pStr:DWORD, strLength:DWORD
; char* str
mov edi, pStr
; long length
mov ecx, strLength
; ebx = 0
xor ebx, ebx
; ebx = ebx + 4
add ebx, 004h
; signature
mov esi, ecx
sub esi, 001h
mov al, byte ptr [edi+esi]
mov ah, byte ptr [edi+004h]
mov byte ptr [edi+004h], al
mov byte ptr [edi+esi], ah
; reset
xor ah, ah
xor al, al
xor esi, esi
link_start:
; if ebx >= ecx goto end
cmp ebx, ecx
jge magic
; al = str[edi+ebx]
mov al, byte ptr [edi+ebx]
; al = al ^ 22
xor al, 022h
; al = al -1
sub al, 001h
; al = ~al
not al
; al = al ^ 11h
xor al, 011h
; al = al + 2
add al, 002h
; str[edi+ebx] = al
mov byte ptr [edi+ebx], al
; ebx ++
inc ebx
; loop
jmp link_start
magic:
ret
decrypt ENDP

END
75 changes: 75 additions & 0 deletions native/encrypt_macos.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
section .text
global _encrypt

_encrypt:
; init
push rbp
mov rbp, rsp

push rax
push rbx
push rcx
push rdx
push rsi
push rdi

; char* str
mov rdi, rdi
; long length
mov rcx, rsi
; rbx = 0
xor rbx, rbx
link_start:
; if rbx >= rcx goto end
cmp rbx, rcx
jge magic
; al = str[rdi+rbx]
mov al, byte [rdi+rbx]
; al = al - 2
sub al, 0x02
; al = al ^ 11h
xor al, 0x11
; al = ~al
not al
; al = al + 1
add al, 0x01
; al = al ^ 22
xor al, 0x22
; str[rdi+rbx] = al
mov byte [rdi+rbx], al
; ebx ++
inc rbx
; loop
jmp link_start
magic:
; magic
mov al, 0xca
mov byte [rdi+0x00], al
mov al, 0xfe
mov byte [rdi+0x01], al
mov al, 0xba
mov byte [rdi+0x02], al
mov al, 0xbe
mov byte [rdi+0x03], al
; signature
mov rsi, rcx
sub rsi, 0x01
mov al, byte [rdi+rsi]
mov ah, byte [rdi+0x04]
mov byte [rdi+0x04], al
mov byte [rdi+rsi], ah
; reset
xor ah, ah
xor al, al
xor rsi, rsi

pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax

; recover rbp
pop rbp
ret
Loading
Loading