org.jetbrains.java.decompiler.main.extern.IFernflowerLogger Java Examples

The following examples show how to use org.jetbrains.java.decompiler.main.extern.IFernflowerLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericMain.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
public static GenericClassDescriptor parseClassSignature(String signature) {
  String original = signature;
  try {
    GenericClassDescriptor descriptor = new GenericClassDescriptor();

    signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);

    String superCl = GenericType.getNextType(signature);
    descriptor.superclass = new GenericType(superCl);

    signature = signature.substring(superCl.length());
    while (signature.length() > 0) {
      String superIf = GenericType.getNextType(signature);
      descriptor.superinterfaces.add(new GenericType(superIf));
      signature = signature.substring(superIf.length());
    }

    return descriptor;
  } catch (RuntimeException e) {
    DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN);
    return null;
  }
}
 
Example #2
Source File: Fernflower.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: GenericMain.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public static GenericFieldDescriptor parseFieldSignature(String signature) {
  try {
    GenericFieldDescriptor descriptor = new GenericFieldDescriptor();
    descriptor.type = new GenericType(signature);
    return descriptor;
  } catch (RuntimeException e) {
    DecompilerContext.getLogger().writeMessage("Invalid signature: " + signature, IFernflowerLogger.Severity.WARN);
    return null;
  }
}
 
Example #4
Source File: DecompilerContext.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public static void setLogger(IFernflowerLogger logger) {
  if (logger != null) {
    String level = (String) getProperty(IFernflowerPreferences.LOG_LEVEL);
    if (level != null) {
      try {
        logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US)));
      } catch (IllegalArgumentException ignore) {
      }
    }
  }
  getCurrentContext().logger = logger;
}
 
Example #5
Source File: ConsoleDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void closeArchive(String path, String archiveName) {
  String file = new File(getAbsolutePath(path), archiveName).getPath();
  try {
    mapArchiveEntries.remove(file);
    mapArchiveStreams.remove(file).close();
  } catch (IOException ex) {
    DecompilerContext.getLogger().writeMessage("Cannot close " + file, IFernflowerLogger.Severity.WARN);
  }
}
 
Example #6
Source File: ConsoleDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkEntry(String entryName, String file) {
  Set<String> set = mapArchiveEntries.get(file);
  if (set == null) {
    mapArchiveEntries.put(file, set = new HashSet<>());
  }

  boolean added = set.add(entryName);
  if (!added) {
    String message = "Zip entry " + entryName + " already exists in " + file;
    DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
  }
  return added;
}
 
Example #7
Source File: DecompilerContext.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public DecompilerContext(Map<String, Object> properties,
                         IFernflowerLogger logger,
                         StructContext structContext,
                         ClassesProcessor classProcessor,
                         PoolInterceptor interceptor) {

    this.properties = properties;
    this.logger = logger;
    this.structContext = structContext;
    this.classProcessor = classProcessor;
    this.poolInterceptor = interceptor;
    this.counterContainer = new CounterContainer();
}
 
Example #8
Source File: ConsoleDecompiler.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void closeArchive(String path, String archiveName) {
    String file = new File(getAbsolutePath(path), archiveName).getPath();
    try {
        mapArchiveEntries.remove(file);
        mapArchiveStreams.remove(file).close();
    } catch (IOException ex) {
        DecompilerContext.getLogger().writeMessage("Cannot close " + file, IFernflowerLogger.Severity.WARN);
    }
}
 
Example #9
Source File: ConsoleDecompiler.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkEntry(String entryName, String file) {
    Set<String> set = DMap.computeIfAbsent(mapArchiveEntries, file, new Function<String, Set<String>>() {
        @Override
        public Set<String> apply(String k) {
            return new HashSet<>();
        }
    });

    boolean added = set.add(entryName);
    if (!added) {
        String message = "Zip entry " + entryName + " already exists in " + file;
        DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
    }
    return added;
}
 
Example #10
Source File: Fernflower.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private static IIdentifierRenamer loadHelper(String className, IFernflowerLogger logger) {
    if (className != null) {
        try {
            Class<?> renamerClass = Fernflower.class.getClassLoader().loadClass(className);
            return (IIdentifierRenamer) renamerClass.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            logger.writeMessage("Cannot load renamer '" + className + "'", IFernflowerLogger.Severity.WARN, e);
        }
    }

    return new ConverterHelper();
}
 
Example #11
Source File: BaseDecompiler.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public BaseDecompiler(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> options, IFernflowerLogger logger) {
    engine = new Fernflower(provider, saver, options, logger);
}
 
Example #12
Source File: DecompilerContext.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static IFernflowerLogger getLogger() {
    return getCurrentContext().logger;
}
 
Example #13
Source File: Fernflower.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example #14
Source File: ConsoleDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
protected ConsoleDecompiler(File destination, Map<String, Object> options, IFernflowerLogger logger) {
  root = destination;
  fernflower = new Fernflower(this, this, options, logger);
}
 
Example #15
Source File: BaseDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public BaseDecompiler(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> options, IFernflowerLogger logger) {
  fernflower = new Fernflower(provider, saver, options, logger);
}
 
Example #16
Source File: DecompilerContext.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public static IFernflowerLogger getLogger() {
  return getCurrentContext().logger;
}
 
Example #17
Source File: ConsoleDecompiler.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
protected ConsoleDecompiler(File destination, Map<String, Object> options, IFernflowerLogger logger) {
    root = destination;
    engine = new Fernflower(this, this, options, logger);
}
 
Example #18
Source File: ClassWriter.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static void methodLambdaToJava(ClassNode lambdaNode,
                                       ClassWrapper classWrapper,
                                       StructMethod mt,
                                       TextBuffer buffer,
                                       int indent,
                                       boolean codeOnly, BytecodeMappingTracer tracer) {
    MethodWrapper methodWrapper = classWrapper.getMethodWrapper(mt.getName(), mt.getDescriptor());

    MethodWrapper outerWrapper = (MethodWrapper) DecompilerContext.getProperty(DecompilerContext.CURRENT_METHOD_WRAPPER);
    DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_WRAPPER, methodWrapper);

    try {
        String method_name = lambdaNode.lambdaInformation.method_name;
        MethodDescriptor md_content = MethodDescriptor.parseDescriptor(lambdaNode.lambdaInformation.content_method_descriptor);
        MethodDescriptor md_lambda = MethodDescriptor.parseDescriptor(lambdaNode.lambdaInformation.method_descriptor);

        if (!codeOnly) {
            buffer.appendIndent(indent);
            buffer.append("public ");
            buffer.append(method_name);
            buffer.append("(");

            boolean firstParameter = true;
            int index = lambdaNode.lambdaInformation.is_content_method_static ? 0 : 1;
            int start_index = md_content.params.length - md_lambda.params.length;

            for (int i = 0; i < md_content.params.length; i++) {
                if (i >= start_index) {
                    if (!firstParameter) {
                        buffer.append(", ");
                    }

                    String typeName = ExprProcessor.getCastTypeName(md_content.params[i].copy());
                    if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
                            DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
                        typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
                    }

                    buffer.append(typeName);
                    buffer.append(" ");

                    String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
                    buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors

                    firstParameter = false;
                }

                index += md_content.params[i].stackSize;
            }

            buffer.append(") {").appendLineSeparator();

            indent += 1;
        }

        RootStatement root = classWrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root;
        if (!methodWrapper.decompiledWithErrors) {
            if (root != null) { // check for existence
                try {
                    buffer.append(root.toJava(indent, tracer));
                } catch (Throwable t) {
                    String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written.";
                    DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t);
                    methodWrapper.decompiledWithErrors = true;
                }
            }
        }

        if (methodWrapper.decompiledWithErrors) {
            buffer.appendIndent(indent);
            buffer.append("// $FF: Couldn't be decompiled");
            buffer.appendLineSeparator();
        }

        if (root != null) {
            tracer.addMapping(root.getDummyExit().bytecode);
        }

        if (!codeOnly) {
            indent -= 1;
            buffer.appendIndent(indent).append('}').appendLineSeparator();
        }
    } finally {
        DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_WRAPPER, outerWrapper);
    }
}