mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 14:38:50 +00:00
Public Release
This commit is contained in:
1 parent
666398e480
commit
61bb497a22
126 files changed
+8435
-1240
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package com.moulberry.flashback;
|
||||
|
||||
import org.lwjgl.system.Pointer;
|
||||
import org.lwjgl.system.jni.JNINativeInterface;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongPredicate;
|
||||
|
||||
public class UnsafeWrapper {
|
||||
|
||||
public static final Unsafe UNSAFE;
|
||||
|
||||
static {
|
||||
UNSAFE = getUnsafeInstance();
|
||||
}
|
||||
|
||||
private static Unsafe getUnsafeInstance() {
|
||||
// Try getting theUnsafe
|
||||
try {
|
||||
final Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
return (Unsafe) theUnsafe.get(null);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
// Try searching for fields
|
||||
Field[] fields = Unsafe.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (!field.getType().equals(Unsafe.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int modifiers = field.getModifiers();
|
||||
if (!Modifier.isStatic(modifiers) || !Modifier.isFinal(modifiers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
return (Unsafe) field.get(null);
|
||||
} catch (Exception ignored) {}
|
||||
break;
|
||||
}
|
||||
|
||||
// Unavailable! :(
|
||||
throw new Error("Flashback requires sun.misc.Unsafe to be available.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user