Java源码示例:org.jetbrains.java.decompiler.struct.lazy.LazyLoader

示例1
public void reload(LazyLoader loader) throws IOException {
  List<StructClass> lstClasses = new ArrayList<>();

  for (StructClass cl : classes) {
    String oldName = cl.qualifiedName;

    StructClass newCl;
    try (DataInputFullStream in = loader.getClassStream(oldName)) {
      newCl = new StructClass(in, cl.isOwn(), loader);
    }

    lstClasses.add(newCl);

    Link lnk = loader.getClassLink(oldName);
    loader.removeClassLink(oldName);
    loader.addClassLink(newCl.qualifiedName, lnk);
  }

  classes = lstClasses;
}
 
示例2
public Fernflower(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> customProperties, IFernflowerLogger logger) {
    Map<String, Object> properties = new HashMap<>(IFernflowerPreferences.DEFAULTS);
    if (customProperties != null) {
        properties.putAll(customProperties);
    }

    String level = (String) properties.get(IFernflowerPreferences.LOG_LEVEL);
    if (level != null) {
        try {
            logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US)));
        } catch (IllegalArgumentException ignore) {
        }
    }

    structContext = new StructContext(saver, this, new LazyLoader(provider));
    classProcessor = new ClassesProcessor(structContext);

    PoolInterceptor interceptor = null;
    if ("1".equals(properties.get(IFernflowerPreferences.RENAME_ENTITIES))) {
        helper = loadHelper((String) properties.get(IFernflowerPreferences.USER_RENAMER_CLASS), logger);
        interceptor = new PoolInterceptor();
        converter = new IdentifierConverter(structContext, helper, interceptor);
    } else {
        helper = null;
        converter = null;
    }

    DecompilerContext context = new DecompilerContext(properties, logger, structContext, classProcessor, interceptor);
    DecompilerContext.setCurrentContext(context);
}
 
示例3
private void addResource(JavaResource resource, LazyLoader loader) throws IOException {
	// Iterate resource class entries
	for(Map.Entry<String, byte[]> entry : copySet(resource.getClasses().entrySet())) {
		String name = entry.getKey();
		byte[] code = entry.getValue();
		// register class in the map and lazy-loader.
		getClasses().put(name, new StructClass(code, true, loader));
		loader.addClassLink(name, new LazyLoader.Link(null, name + ".class"));
	}
}
 
示例4
/**
 * Constructs a FernFlower decompiler instance.
 *
 * @param provider
 * 		Class file provider.
 * @param saver
 * 		Decompilation output saver <i>(Unused/noop)</i>
 * @param properties
 * 		FernFlower options.
 * @param logger
 * 		FernFlower logger instance.
 */
public FernFlowerAccessor(IBytecodeProvider provider, IResultSaver saver, Map<String, Object>
		properties, IFernflowerLogger logger) {
	String level = (String) properties.get(IFernflowerPreferences.LOG_LEVEL);
	if(level != null) {
		logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.ENGLISH)));
	}
	structContext = new StructContextDecorator(saver, this, new LazyLoader(provider));
	classProcessor = new ClassesProcessor(structContext);
	DecompilerContext context = new DecompilerContext(properties, logger, structContext,
			classProcessor, null);
	DecompilerContext.setCurrentContext(context);
}
 
示例5
public StructContext(IResultSaver saver, IDecompiledData decompiledData, LazyLoader loader) {
  this.saver = saver;
  this.decompiledData = decompiledData;
  this.loader = loader;
  ContextUnit defaultUnit = new ContextUnit(ContextUnit.TYPE_FOLDER, null, "", true, saver, decompiledData);
  units.put("", defaultUnit);
}
 
示例6
private void addArchive(String path, File file, int type, boolean isOwn) throws IOException {
  //noinspection IOResourceOpenedButNotSafelyClosed
  try (ZipFile archive = type == ContextUnit.TYPE_JAR ? new JarFile(file) : new ZipFile(file)) {
    Enumeration<? extends ZipEntry> entries = archive.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();

      ContextUnit unit = units.get(path + "/" + file.getName());
      if (unit == null) {
        unit = new ContextUnit(type, path, file.getName(), isOwn, saver, decompiledData);
        if (type == ContextUnit.TYPE_JAR) {
          unit.setManifest(((JarFile) archive).getManifest());
        }
        units.put(path + "/" + file.getName(), unit);
      }

      String name = entry.getName();
      if (!entry.isDirectory()) {
        if (name.endsWith(".class")) {
          byte[] bytes = InterpreterUtil.getBytes(archive, entry);
          StructClass cl = new StructClass(bytes, isOwn, loader);
          classes.put(cl.qualifiedName, cl);
          unit.addClass(cl, name);
          loader.addClassLink(cl.qualifiedName, new LazyLoader.Link(LazyLoader.Link.ENTRY, file.getAbsolutePath(), name));
        } else {
          unit.addOtherEntry(file.getAbsolutePath(), name);
        }
      } else {
        unit.addDirEntry(name);
      }
    }
  }
}
 
示例7
public String decompile(byte[] b, MethodNode mn) {
  try {
  	//TODO decompile method only
    this.bytes = b;
    HashMap<String, Object> map = new HashMap<>();
    for (String key : options.keySet()) {
      map.put(key, JByteMod.ops.get("ff_" + key).getBoolean() ? "1" : "0");
    }
    Fernflower f = new Fernflower(this, this, map, new PrintStreamLogger(JByteMod.LOGGER));
    StructContext sc = f.getStructContext();
    StructClass cl = new StructClass(b, true, sc.getLoader());
    sc.getClasses().put(cn.name, cl);
    //instead of loading a file use custom bridge, created a few getters
    String fakePath = new File("none.class").getAbsolutePath();
    ContextUnit unit = new ContextUnit(ContextUnit.TYPE_FOLDER, null, fakePath, true, sc.getSaver(), sc.getDecompiledData());
    sc.getUnits().put(fakePath, unit);
    unit.addClass(cl, "none.class");
    sc.getLoader().addClassLink(cn.name, new LazyLoader.Link(LazyLoader.Link.CLASS, fakePath, null));

    f.decompileContext();
    return returned;
  } catch (Exception e) {
    e.printStackTrace();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    return sw.toString();
  }
}
 
示例8
private LazyLoader getLoader() throws ReflectiveOperationException {
	// Hack to access private parent loader
	Field floader = StructContext.class.getDeclaredField("loader");
	floader.setAccessible(true);
	return (LazyLoader) floader.get(this);
}
 
示例9
public Fernflower(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> options, IFernflowerLogger logger) {
  structContext = new StructContext(saver, this, new LazyLoader(provider));
  DecompilerContext.initContext(options);
  DecompilerContext.setCounterContainer(new CounterContainer());
  DecompilerContext.setLogger(logger);
}
 
示例10
public StructClass(byte[] bytes, boolean own, LazyLoader loader) throws IOException {
  this(new DataInputFullStream(bytes), own, loader);
}
 
示例11
public StructClass(DataInputFullStream in, boolean own, LazyLoader loader) throws IOException {
  this.own = own;
  this.loader = loader;

  in.discard(4);

  minorVersion = in.readUnsignedShort();
  majorVersion = in.readUnsignedShort();

  pool = new ConstantPool(in);

  accessFlags = in.readUnsignedShort();
  int thisClassIdx = in.readUnsignedShort();
  int superClassIdx = in.readUnsignedShort();
  qualifiedName = pool.getPrimitiveConstant(thisClassIdx).getString();
  superClass = pool.getPrimitiveConstant(superClassIdx);

  // interfaces
  int length = in.readUnsignedShort();
  interfaces = new int[length];
  interfaceNames = new String[length];
  for (int i = 0; i < length; i++) {
    interfaces[i] = in.readUnsignedShort();
    interfaceNames[i] = pool.getPrimitiveConstant(interfaces[i]).getString();
  }

  // fields
  length = in.readUnsignedShort();
  fields = new VBStyleCollection<>();
  for (int i = 0; i < length; i++) {
    StructField field = new StructField(in, this);
    fields.addWithKey(field, InterpreterUtil.makeUniqueKey(field.getName(), field.getDescriptor()));
  }

  // methods
  length = in.readUnsignedShort();
  methods = new VBStyleCollection<>();
  for (int i = 0; i < length; i++) {
    StructMethod method = new StructMethod(in, this);
    methods.addWithKey(method, InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor()));
  }

  // attributes
  attributes = readAttributes(in, pool);

  releaseResources();
}
 
示例12
public LazyLoader getLoader() {
  return loader;
}
 
示例13
public LazyLoader getLoader() {
  return loader;
}
 
示例14
/**
 * @param workspace
 * 		Recaf workspace to pull classes from.
 *
 * @throws IOException
 * 		Thrown if a class cannot be read.
 * @throws ReflectiveOperationException
 * 		Thrown if the parent loader could not be fetched.
 * @throws IndexOutOfBoundsException
 * 		Thrown if FernFlower can't read the class.
 * 		<i>(IE: It fails on newer Java class files)</i>
 */
public void addWorkspace(Workspace workspace) throws IOException,
		ReflectiveOperationException {
	LazyLoader loader = getLoader();
	// Add primary resource classes
	addResource(workspace.getPrimary(), loader);
	for (JavaResource resource : workspace.getLibraries())
		addResource(resource, loader);
}
 
示例15
/**
 * Constructs a StructContext.
 *
 * @param saver
 * 		Result saver <i>(Unused/noop)</i>
 * @param data
 * 		Data instance, should be an instance of
 * 		{@link me.coley.recaf.decompile.fernflower.FernFlowerAccessor}.
 * @param loader
 * 		LazyLoader to hold links to class resources.
 */
public StructContextDecorator(IResultSaver saver, IDecompiledData data, LazyLoader loader) {
	super(saver, data, loader);
}