Created
March 21, 2014 15:28
-
-
Save mcy/9688797 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 java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.InputStream; | |
import java.lang.reflect.Method; | |
import com.xorinc.foo.Foo; | |
public class Main { | |
public static void main(String... args) throws Exception{ | |
Foo.mash(); | |
InputStream classIn = new FileInputStream(new File("foo/Foo.class")); | |
ByteArrayOutputStream bais = new ByteArrayOutputStream(); | |
Method define = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); | |
define.setAccessible(true); | |
while(true){ | |
int datum = classIn.read(); | |
if(datum == -1) | |
break; | |
bais.write(datum); | |
} | |
classIn.close(); | |
byte[] data = bais.toByteArray(); | |
define.invoke(ClassLoader.getSystemClassLoader(), "com.xorinc.foo.Foo", data, 0, data.length); | |
Foo.mash(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment