Created
April 30, 2025 13:21
-
-
Save burningtnt/e8f43d6917a60a3c2be59f41b2b2e653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sun.misc.Unsafe; | |
import java.lang.invoke.MethodHandles; | |
import java.lang.reflect.Field; | |
public final class TrustedLookupAccessor { | |
public static MethodHandles.Lookup get() throws Throwable { | |
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); | |
theUnsafe.setAccessible(true); | |
Unsafe U = (Unsafe) theUnsafe.get(null); | |
Field implLookup = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); | |
Object base = U.staticFieldBase(implLookup); | |
long l = U.staticFieldOffset(implLookup); | |
return (MethodHandles.Lookup) U.getObject(base, l); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment