Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.itzsomebody.packer;
- import java.io.ByteArrayInputStream;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.lang.reflect.Method;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.zip.GZIPInputStream;
- public class EntryPoint extends ClassLoader {
- private static final Map<String, byte[]> resourceMap = new HashMap<>();
- private EntryPoint() throws IOException {
- GZIPInputStream gzipInput = new GZIPInputStream(EntryPoint.class.getResourceAsStream(".radon"));
- DataInputStream input = new DataInputStream(gzipInput);
- int nEntries = input.readInt();
- for (int i = 0; i < nEntries; i++) {
- String name = input.readUTF();
- byte[] b = new byte[input.readInt()];
- for (int j = 0; j < b.length; j++)
- b[j] = input.readByte();
- resourceMap.put(name, b);
- }
- }
- protected Class findClass(String name) throws ClassNotFoundException {
- byte[] bytes;
- if ((bytes = resourceMap.get(name.replace('.', '/') + ".class")) != null)
- return defineClass(name, bytes, 0, bytes.length);
- return super.findClass(name);
- }
- public InputStream getResourceAsStream(String name) {
- byte[] bytes;
- if ((bytes = resourceMap.get(name)) != null)
- return new ByteArrayInputStream(bytes);
- return super.getResourceAsStream(name);
- }
- public static void main(String... args) throws Throwable {
- EntryPoint entryPoint = new EntryPoint();
- Class<?> clazz = entryPoint.findClass("me.itzsomebody.counter.Counter");
- Method method = clazz.getMethod("main", String[].class);
- method.setAccessible(true);
- method.invoke(null, args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement