geforkt von Mirrors/Velocity
I have sinned but it feels good
Dieser Commit ist enthalten in:
Ursprung
01c6777948
Commit
4b1cdbcb31
@ -21,5 +21,5 @@ ARCH=$(uname -m)
|
|||||||
mkdir -p src/main/resources/linux_$ARCH
|
mkdir -p src/main/resources/linux_$ARCH
|
||||||
$CC $CFLAGS -Ilibdeflate src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \
|
$CC $CFLAGS -Ilibdeflate src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \
|
||||||
libdeflate/libdeflate.a -o src/main/resources/linux_$ARCH/velocity-compress.so
|
libdeflate/libdeflate.a -o src/main/resources/linux_$ARCH/velocity-compress.so
|
||||||
$CC $CFLAGS -shared src/main/c/jni_util.c src/main/c/jni_cipher.c \
|
$CC $CFLAGS -shared src/main/c/jni_util.c src/main/c/jni_cipher_openssl.c \
|
||||||
-o src/main/resources/linux_$ARCH/velocity-cipher.so -lcrypto
|
-o src/main/resources/linux_$ARCH/velocity-cipher.so -lcrypto
|
23
native/compile-macos.sh
Ausführbare Datei
23
native/compile-macos.sh
Ausführbare Datei
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! "$CC" ]; then
|
||||||
|
export CC=clang
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d libdeflate ]; then
|
||||||
|
echo "Cloning libdeflate..."
|
||||||
|
git clone https://github.com/ebiggers/libdeflate.git
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Compiling libdeflate..."
|
||||||
|
cd libdeflate || exit
|
||||||
|
CFLAGS="-fPIC -O2 -fomit-frame-pointer" make
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
CFLAGS="-O2 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin/ -fPIC -shared -Wall -Werror -fomit-frame-pointer"
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
mkdir -p src/main/resources/linux_$ARCH
|
||||||
|
$CC $CFLAGS -Ilibdeflate src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \
|
||||||
|
libdeflate/libdeflate.a -o src/main/resources/macos_$ARCH/velocity-compress.dylib
|
||||||
|
$CC $CFLAGS -shared src/main/c/jni_util.c src/main/c/jni_cipher_macos.c \
|
||||||
|
-o src/main/resources/macos_$ARCH/velocity-cipher.dylib -lSystem
|
66
native/src/main/c/jni_cipher_macos.c
Normale Datei
66
native/src/main/c/jni_cipher_macos.c
Normale Datei
@ -0,0 +1,66 @@
|
|||||||
|
#include <CommonCrypto/CommonCryptor.h>
|
||||||
|
#include <jni.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "jni_util.h"
|
||||||
|
|
||||||
|
typedef unsigned char byte;
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL
|
||||||
|
Java_com_velocitypowered_natives_encryption_OpenSslCipherImpl_init(JNIEnv *env,
|
||||||
|
jclass clazz,
|
||||||
|
jbyteArray key,
|
||||||
|
jboolean encrypt)
|
||||||
|
{
|
||||||
|
jsize keyLen = (*env)->GetArrayLength(env, key);
|
||||||
|
if (keyLen != 16) {
|
||||||
|
throwException(env, "java/lang/IllegalArgumentException", "cipher not 16 bytes");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since we know the array size is always bounded, we can just use Get<Primitive>ArrayRegion
|
||||||
|
// and save ourselves some error-checking headaches.
|
||||||
|
jbyte keyBytes[16];
|
||||||
|
(*env)->GetByteArrayRegion(env, key, 0, keyLen, (jbyte*) keyBytes);
|
||||||
|
if ((*env)->ExceptionCheck(env)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCCryptorRef cryptor = NULL;
|
||||||
|
CCCryptorStatus result = CCCryptorCreateWithMode(encrypt ? kCCEncrypt : kCCDecrypt,
|
||||||
|
kCCModeCFB8,
|
||||||
|
kCCAlgorithmAES128,
|
||||||
|
ccNoPadding,
|
||||||
|
keyBytes,
|
||||||
|
keyBytes,
|
||||||
|
16,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
&cryptor);
|
||||||
|
if (result != kCCSuccess) {
|
||||||
|
throwException(env, "java/security/GeneralSecurityException", "openssl initialize cipher");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (jlong) cryptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_velocitypowered_natives_encryption_OpenSslCipherImpl_free(JNIEnv *env,
|
||||||
|
jclass clazz,
|
||||||
|
jlong ptr)
|
||||||
|
{
|
||||||
|
CCCryptorRelease((CCCryptorRef) ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_velocitypowered_natives_encryption_OpenSslCipherImpl_process(JNIEnv *env,
|
||||||
|
jclass clazz,
|
||||||
|
jlong ptr,
|
||||||
|
jlong source,
|
||||||
|
jint len,
|
||||||
|
jlong dest)
|
||||||
|
{
|
||||||
|
CCCryptorUpdate((CCCryptorRef) ptr, (byte*) source, len, (byte*) dest, len, NULL);
|
||||||
|
}
|
@ -40,7 +40,6 @@ public class NativeConstraints {
|
|||||||
// give amd64.
|
// give amd64.
|
||||||
IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
|
IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
|
||||||
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
||||||
System.out.println(System.getProperty("os.name", ""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS;
|
static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS;
|
||||||
|
@ -85,6 +85,10 @@ public class Natives {
|
|||||||
copyAndLoadNative("/linux_aarch64/velocity-compress.so"),
|
copyAndLoadNative("/linux_aarch64/velocity-compress.so"),
|
||||||
"libdeflate (Linux aarch64)",
|
"libdeflate (Linux aarch64)",
|
||||||
LibdeflateVelocityCompressor.FACTORY),
|
LibdeflateVelocityCompressor.FACTORY),
|
||||||
|
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS_AARCH64,
|
||||||
|
copyAndLoadNative("/macos_arm64/velocity-compress.dylib"),
|
||||||
|
"libdeflate (macOS ARM64 / Apple Silicon)",
|
||||||
|
LibdeflateVelocityCompressor.FACTORY),
|
||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
||||||
}, "Java", JavaVelocityCompressor.FACTORY)
|
}, "Java", JavaVelocityCompressor.FACTORY)
|
||||||
)
|
)
|
||||||
@ -104,6 +108,10 @@ public class Natives {
|
|||||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64,
|
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64,
|
||||||
copyAndLoadNative("/linux_aarch64/velocity-cipher.so"),
|
copyAndLoadNative("/linux_aarch64/velocity-cipher.so"),
|
||||||
"OpenSSL (Linux aarch64)", NativeVelocityCipher.FACTORY),
|
"OpenSSL (Linux aarch64)", NativeVelocityCipher.FACTORY),
|
||||||
|
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS_AARCH64,
|
||||||
|
copyAndLoadNative("/macos_arm64/velocity-cipher.dylib"),
|
||||||
|
"native (macOS ARM64 / Apple Silicon)",
|
||||||
|
NativeVelocityCipher.FACTORY),
|
||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
||||||
}, "Java", JavaVelocityCipher.FACTORY)
|
}, "Java", JavaVelocityCipher.FACTORY)
|
||||||
)
|
)
|
||||||
|
BIN
native/src/main/resources/macos_arm64/velocity-cipher.dylib
Ausführbare Datei
BIN
native/src/main/resources/macos_arm64/velocity-cipher.dylib
Ausführbare Datei
Binäre Datei nicht angezeigt.
BIN
native/src/main/resources/macos_arm64/velocity-compress.dylib
Ausführbare Datei
BIN
native/src/main/resources/macos_arm64/velocity-compress.dylib
Ausführbare Datei
Binäre Datei nicht angezeigt.
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren