diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..c950c4c5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "native/mbedtls"] + path = native/mbedtls + url = https://github.com/ARMmbed/mbedtls.git +[submodule "native/zlib"] + path = native/zlib + url = https://github.com/cloudflare/zlib.git diff --git a/native/compile-native.sh b/native/compile-native.sh index 98baf0e2..f37c9fdd 100755 --- a/native/compile-native.sh +++ b/native/compile-native.sh @@ -1,6 +1,14 @@ #!/bin/sh -CXX="g++ -shared -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/" +set -eu -$CXX src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so -lcrypto -$CXX src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so -lz +echo "Compiling mbedtls" +(cd mbedtls && make no_test) + +echo "Compiling zlib" +(cd zlib && CFLAGS=-fPIC ./configure --static && make) + +CXX="g++ -shared -fPIC -Wl,--wrap=memcpy -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/" + +$CXX -Imbedtls/include src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so mbedtls/library/libmbedcrypto.a +$CXX -Izlib src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so zlib/libz.a diff --git a/native/mbedtls b/native/mbedtls new file mode 160000 index 00000000..e483a77c --- /dev/null +++ b/native/mbedtls @@ -0,0 +1 @@ +Subproject commit e483a77c85e1f9c1dd2eb1c5a8f552d2617fe400 diff --git a/native/src/main/c/NativeCipherImpl.cpp b/native/src/main/c/NativeCipherImpl.cpp index aa7a12b4..22c7f00c 100644 --- a/native/src/main/c/NativeCipherImpl.cpp +++ b/native/src/main/c/NativeCipherImpl.cpp @@ -1,12 +1,15 @@ -// Support for CentOS 6 -__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); - #include #include #include #include "net_md_5_bungee_jni_cipher_NativeCipherImpl.h" +// Support for CentOS 6 +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n) { + return memcpy(dest, src, n); +} + typedef unsigned char byte; struct crypto_context { diff --git a/native/src/main/c/NativeCompressImpl.cpp b/native/src/main/c/NativeCompressImpl.cpp index 9bda6300..4574ccf1 100644 --- a/native/src/main/c/NativeCompressImpl.cpp +++ b/native/src/main/c/NativeCompressImpl.cpp @@ -1,7 +1,15 @@ #include +#include + #include #include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h" +// Support for CentOS 6 +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n) { + return memcpy(dest, src, n); +} + typedef unsigned char byte; static jfieldID consumedID; diff --git a/native/src/main/resources/native-cipher.so b/native/src/main/resources/native-cipher.so index 8f1717b9..78c26f28 100755 Binary files a/native/src/main/resources/native-cipher.so and b/native/src/main/resources/native-cipher.so differ diff --git a/native/src/main/resources/native-compress.so b/native/src/main/resources/native-compress.so index e83e4d2d..d5e04782 100755 Binary files a/native/src/main/resources/native-compress.so and b/native/src/main/resources/native-compress.so differ diff --git a/native/zlib b/native/zlib new file mode 160000 index 00000000..959b4ea3 --- /dev/null +++ b/native/zlib @@ -0,0 +1 @@ +Subproject commit 959b4ea305821e753385e873ec4edfaa9a5d49b7