Ejemplo n.º 1
0
 public void execute(String[] parameters) throws Exception {
   Injector injector = (Injector) Module.load(Injector.class, parameters[0] + "Injector");
   final String[] injectorArgs = new String[injector.getParameters().length];
   System.arraycopy(parameters, 1, injectorArgs, 0, injectorArgs.length);
   final String[] stagerArgs = shiftArray(parameters, injectorArgs.length + 1);
   StagerHandler.Loader loader = new StagerHandler.Loader(stagerArgs);
   initIO(loader);
   injector.inject(injectorArgs, loader, stagerArgs);
   finishIO(loader);
 }
Ejemplo n.º 2
0
 private static Class[] findExtraArgClasses() throws Exception {
   List /* <Class> */ result = new ArrayList();
   Module[] injectors = Module.loadAll(Injector.class);
   for (int i = 0; i < injectors.length; i++) {
     Class[] classes = ((Injector) injectors[i]).getSupportedExtraArgClasses();
     for (int j = 0; j < classes.length; j++) {
       if (!result.contains(classes[j])) result.add(classes[j]);
     }
   }
   return (Class[]) result.toArray(new Class[result.size()]);
 }
Ejemplo n.º 3
0
 public void runBuilder(String[] args) throws Exception {
   runner.runBuilder(args);
   String jarName = this.jarName;
   if (jarName.indexOf('*') != -1) jarName = Module.replaceString(jarName, "*", args[0]);
   new File(jarName).renameTo(new File("uncrypted.jar"));
   String[] crypterArgs =
       new String[] {
         "uncrypted.jar", jarName, "RnR", "HashNames", jarLayout.getName(),
       };
   if (layoutArgs.length > 0) {
     String[] tmp = crypterArgs;
     crypterArgs = new String[tmp.length + layoutArgs.length];
     System.arraycopy(tmp, 0, crypterArgs, 0, tmp.length);
     System.arraycopy(layoutArgs, 0, crypterArgs, tmp.length, layoutArgs.length);
   }
   new CryptedJarBuilder().build(crypterArgs);
   if (!new File("uncrypted.jar").delete()) throw new IOException("Unable to delete file");
 }
Ejemplo n.º 4
0
 public static void main(String[] args) throws Exception {
   if (args.length != 2) {
     System.out.println("Usage: java jpmfsbridge.Generator <outDir> <javaExecutable>");
     return;
   }
   File outDir = new File(args[0]).getAbsoluteFile();
   if (!outDir.exists() || !outDir.isDirectory()) {
     System.out.println("output dir must be an existing directory");
     return;
   }
   File javaExecutable = new File(args[1]).getAbsoluteFile();
   if (!javaExecutable.exists() || !javaExecutable.isFile()) {
     System.out.println("Java executable must be an existing executable file (like java.exe)");
     return;
   }
   Globals.instance.setJavaExecutable(javaExecutable.getPath());
   Module[] dynstagers = Module.loadAll(DynStagerHandler.class);
   List /*<DynStagerHandler>*/ remainingDynstagers = new ArrayList();
   for (int i = 0; i < dynstagers.length; i++) {
     DynStagerHandler d = (DynStagerHandler) dynstagers[i];
     if ((d.getExtraArg() == null ? 0 : 1) + d.getParameters().length > 1) continue;
     remainingDynstagers.add(d);
   }
   List /*<DynStagerHandler>*/ dynstagerList = new ArrayList();
   while (remainingDynstagers.size() > 0) {
     boolean changed = false;
     for (int i = 0; i < remainingDynstagers.size(); i++) {
       DynStagerHandler d1 = (DynStagerHandler) remainingDynstagers.get(i);
       boolean mustWait = false;
       for (int j = 0; j < remainingDynstagers.size(); j++) {
         DynStagerHandler d2 = (DynStagerHandler) remainingDynstagers.get(j);
         if (d2.isDynstagerUsableWith(new DynStagerHandler[] {d1})
             && !d1.isDynstagerUsableWith(new DynStagerHandler[] {d2})) {
           mustWait = true;
           break;
         }
       }
       if (!mustWait) {
         changed = true;
         dynstagerList.add(d1);
         remainingDynstagers.remove(i);
         i--;
       }
     }
     if (!changed)
       throw new RuntimeException(
           "Dynstagers cannot be created due to circular dependencies between "
               + remainingDynstagers);
   }
   Globals.instance.setDynstagers(
       (DynStagerHandler[]) dynstagerList.toArray(new DynStagerHandler[dynstagerList.size()]));
   TemplateTransformer transformer =
       new TemplateTransformer(new File("template").getAbsoluteFile(), outDir);
   System.out.println("Parsing global templates...");
   transformer.transformDirectory("global/", ".", null);
   Module[] stages = Module.loadAll(StageHandler.class);
   for (int i = 0; i < stages.length; i++) {
     StageHandler stage = (StageHandler) stages[i];
     if (stage.isHandlerUsable() && stage.isTargetUsable()) {
       System.out.println("Parsing templates for stage " + stage.getName() + "...");
       transformer.transformDirectory("stage/", ".", new ModuleInfo(stage));
     }
   }
   Class[] extraArgClasses = findExtraArgClasses();
   Module[] stagers = Module.loadAll(StagerHandler.class);
   Method canHandleExtraArg =
       StagerHandler.class.getDeclaredMethod("canHandleExtraArg", new Class[] {Class.class});
   canHandleExtraArg.setAccessible(true);
   Method needHandleBeforeStart =
       StagerHandler.class.getDeclaredMethod("needHandleBeforeStart", new Class[0]);
   needHandleBeforeStart.setAccessible(true);
   for (int i = 0; i < stagers.length; i++) {
     StagerHandler stager = (StagerHandler) stagers[i];
     if (!stager.isHandlerUsable() || !stager.isTargetUsable()) continue;
     if (!stager.isStagerUsableWith(new DynStagerHandler[0])) continue;
     String generatedConnectionType = null;
     for (int j = 0; j < extraArgClasses.length; j++) {
       if (((Boolean) canHandleExtraArg.invoke(stager, new Object[] {extraArgClasses[j]}))
           .booleanValue()) {
         String connectionType;
         if (extraArgClasses[j] == null) {
           connectionType =
               ((Boolean) needHandleBeforeStart.invoke(stager, new Object[0])).booleanValue()
                   ? "reverse"
                   : "bind";
         } else {
           connectionType =
               "javapayload_" + extraArgClasses[j].getName().replace('.', '_').toLowerCase();
         }
         if (generatedConnectionType == null) {
           System.out.println(
               "Parsing templates for stager "
                   + stager.getName()
                   + " (connection type "
                   + connectionType
                   + ")...");
           transformer.transformDirectory("stager/", ".", new StagerInfo(stager, connectionType));
           generatedConnectionType = connectionType;
         } else if (!generatedConnectionType.equals(connectionType)) {
           System.out.println(
               "Warning: "
                   + stager.getName()
                   + " supports both "
                   + generatedConnectionType
                   + " and "
                   + connectionType
                   + ", using the former.");
         }
       }
     }
   }
   System.out.println("Done.");
   Logger.logEntry(
       "Templates regenerated.\r\nJava exectutable: "
           + Globals.instance.getJavaExecutable()
           + "\r\nClassPath: "
           + Globals.instance.getClassPath());
 }