Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package me.itzsomebody.packer;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.DataInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.lang.reflect.Method;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. import java.util.zip.GZIPInputStream;
  11.  
  12. public class EntryPoint extends ClassLoader {
  13. private static final Map<String, byte[]> resourceMap = new HashMap<>();
  14.  
  15. private EntryPoint() throws IOException {
  16. GZIPInputStream gzipInput = new GZIPInputStream(EntryPoint.class.getResourceAsStream(".radon"));
  17. DataInputStream input = new DataInputStream(gzipInput);
  18.  
  19. int nEntries = input.readInt();
  20.  
  21. for (int i = 0; i < nEntries; i++) {
  22. String name = input.readUTF();
  23. byte[] b = new byte[input.readInt()];
  24.  
  25. for (int j = 0; j < b.length; j++)
  26. b[j] = input.readByte();
  27.  
  28. resourceMap.put(name, b);
  29. }
  30. }
  31.  
  32. protected Class findClass(String name) throws ClassNotFoundException {
  33. byte[] bytes;
  34. if ((bytes = resourceMap.get(name.replace('.', '/') + ".class")) != null)
  35. return defineClass(name, bytes, 0, bytes.length);
  36.  
  37. return super.findClass(name);
  38. }
  39.  
  40. public InputStream getResourceAsStream(String name) {
  41. byte[] bytes;
  42. if ((bytes = resourceMap.get(name)) != null)
  43. return new ByteArrayInputStream(bytes);
  44.  
  45. return super.getResourceAsStream(name);
  46. }
  47.  
  48. public static void main(String... args) throws Throwable {
  49. EntryPoint entryPoint = new EntryPoint();
  50. Class<?> clazz = entryPoint.findClass("me.itzsomebody.counter.Counter");
  51. Method method = clazz.getMethod("main", String[].class);
  52. method.setAccessible(true);
  53. method.invoke(null, args);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement