Created
March 9, 2024 17:07
-
-
Save duncte123/b45574d44f4a22e9fc8c2b3a30c78084 to your computer and use it in GitHub Desktop.
Storing a string in an integer
This file contains 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
package me.duncte123.fuck; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.Field; | |
import sun.misc.Unsafe; | |
public class Main { | |
private static Integer integer; | |
public static void main(String[] args) throws Throwable { | |
Constructor<Unsafe> c = Unsafe.class.getDeclaredConstructor(); | |
c.setAccessible(true); | |
Unsafe u = c.newInstance(); | |
Field f = Main.class.getDeclaredField("integer"); | |
Object b = u.staticFieldBase(f); | |
long o = u.staticFieldOffset(f); | |
u.putObject(b, o, "this is a string"); | |
String s = (String)(Object)integer; | |
System.out.println(s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment