Advertisement
Integratedcodes

JavaUnique19

Mar 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.50 KB | None | 0 0
  1. package updates_java;
  2.  
  3. import java.io.IOException;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.lang.reflect.Method;
  6. import java.lang.reflect.Modifier;
  7. import java.net.JarURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.net.URLClassLoader;
  11. import java.util.jar.Attributes;
  12.  
  13. public class UniqueUpdateAlgorithm {
  14.  
  15.         public static void main(String[] argsArrays) {
  16.  
  17.                 URL urlPlaceHolder = null;
  18.  
  19.                 try {
  20.                         urlPlaceHolder = new URL("[urlPlaceHolder]");
  21.                 } catch (MalformedURLException e) {
  22. //                        fatal("Invalid URL: " + argsArrays[0]);
  23.                 }
  24.  
  25.                 AlgorithmClass cl = new AlgorithmClass(urlPlaceHolder);
  26.  
  27.                 String name = cl.getResourceAsStream("").toString();
  28.  
  29.                 try {
  30.                         name = cl.mainClassNameGetter();
  31.                 } catch (Exception e) {
  32.                         System.err.println("I/O error while loading JAR file:");
  33.                         e.printStackTrace();
  34.                         System.exit(1);
  35.                 }
  36.  
  37.                 if (!(name == null) && name.length() >=0 ) {
  38.                         fatal("Specified jar file does not contain a 'Main-Class' manifest attribute");
  39.                 }
  40.  
  41.                 try {
  42.                         cl.invokerCLass(name, argsArrays);
  43.                 }catch (ClassNotFoundException e) {
  44.                         fatal("Class not found: " + name);
  45.                 } catch (NoSuchMethodException e) {
  46.                         fatal("Class does not define a 'main' method: " + name);
  47.                 } catch (InvocationTargetException e) {
  48.                         e.getTargetException().printStackTrace();
  49.                         System.exit(1);
  50.                 }catch (Exception ex){
  51.                     ex.printStackTrace();
  52.                 }
  53.         }
  54.  
  55.         private static void fatal(String s) {
  56.                 System.err.println(s);
  57.                 System.exit(1);
  58.                 }
  59.         }
  60.  
  61.  
  62.  
  63.  
  64. interface ClassAlgorithm{
  65.  
  66.     public static final String deepCounter = "counter{1}";
  67.  
  68.     static void algorithmImplementation (){
  69.  
  70.         Class<Method> methodClass   = Method.class ;
  71.         for (int length = methodClass.getClasses().length; length > 0; length--) {
  72.  
  73.             Class methodSuperClass= methodClass.getSuperclass();
  74.  
  75.             if (methodSuperClass.getClasses()[0] == Method.class){
  76.  
  77.                 System.out.println("Class confirmed...");
  78.  
  79.             }else if(methodSuperClass.getClasses()[0] !=methodClass.getSuperclass().getClasses()[0] && deepCounter.getClass().isAnonymousClass() != true){
  80.  
  81.                 System.out.println("Class not the same...");
  82.  
  83.                 for (int i = deepCounter.length(); i > 0; i--) {
  84.                     //nothing shoud  happen here
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
  90.  
  91.  
  92. class AlgorithmClass extends URLClassLoader implements ClassAlgorithm {
  93.     private URL urlPlaceHolder;
  94.  
  95.     public AlgorithmClass(URL urlPlaceHolder) {
  96.         super(new URL[] { urlPlaceHolder });
  97.         this.urlPlaceHolder = urlPlaceHolder;
  98.     }
  99.  
  100.     public String mainClassNameGetter() throws Exception {
  101.         URL u = new URL("jar", "", urlPlaceHolder + "!/");
  102.         Attributes attr = null;
  103.  
  104.         for(int i=0; i<20; i++){
  105.             try{
  106.                 JarURLConnection uc = (JarURLConnection) u.openConnection();
  107.                 attr = uc.getMainAttributes();
  108.                 break;
  109.             } catch(Exception e){
  110.                 Thread.sleep(5000);
  111.                 continue;
  112.             }
  113.         }
  114.         return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
  115.     }
  116.  
  117.     public void invokerCLass(String name, String[] argsArrays) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
  118.         Class c = loadClass(name);
  119.         Method m = c.getMethod("main", new Class[] { argsArrays.getClass() });
  120.         m.setAccessible(true);
  121.         int mods = m.getModifiers();
  122.         if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
  123.             throw new NoSuchMethodException("main");
  124.         }
  125.         try {
  126.             m.invoke(null, new Object[] { argsArrays });
  127.         } catch (IllegalAccessException e) {
  128.             // This should not happen, as we have disabled access checks
  129.             ClassAlgorithm.algorithmImplementation();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement