public void writeMessage(String message, Throwable t) { writeMessage(message, Severity.ERROR, t); }
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); }
public void init() { DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct); DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS_WRAPPER, this); DecompilerContext.getLogger().startClass(classStruct.qualifiedName); DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor()); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR); killThread(mtThread); isError = true; DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t); isError = true; DecompilerContext.getLogger().endMethod(); DecompilerContext.getLogger().endClass();
StructClass cl = wrapper.getClassStruct(); DecompilerContext.getLogger().startWriteClass(node.simpleName); DecompilerContext.getLogger().endWriteClass();
DecompilerContext.getLogger().startReadingClass(cl.qualifiedName); try { ImportCollector importCollector = new ImportCollector(root); DecompilerContext.getLogger().endReadingClass();
public void init() throws IOException { DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct); DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS_WRAPPER, this); DecompilerContext.getLogger().startClass(classStruct.qualifiedName); DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor()); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR); killThread(mtThread); isError = true; DecompilerContext.getLogger().writeMessage("Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be decompiled.", IFernflowerLogger.Severity.WARN, ex); DecompilerContext.getLogger().endMethod(); DecompilerContext.getLogger().endClass();
StructClass cl = wrapper.getClassStruct(); DecompilerContext.getLogger().startWriteClass(cl.qualifiedName); DecompilerContext.getLogger().endWriteClass();
DecompilerContext.getLogger().startReadingClass(cl.qualifiedName); try { ImportCollector importCollector = new ImportCollector(root); DecompilerContext.getLogger().endReadingClass();
private boolean checkEntry(String entryName, String file) { Set<String> set = mapArchiveEntries.computeIfAbsent(file, k -> 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; }
StructClass cl = wrapper.getClassStruct(); DecompilerContext.getLogger().startWriteClass(node.simpleName); DecompilerContext.getLogger().endWriteClass();
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; }
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(); }
StructClass cl = wrapper.getClassStruct(); DecompilerContext.getLogger().startWriteClass(cl.qualifiedName); DecompilerContext.getLogger().endWriteClass();
@Override public void saveClassFile(String path, String qualifiedName, String entryName, String content, int[] mapping) { File file = new File(getAbsolutePath(path), entryName); try (Writer out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { out.write(content); } catch (IOException ex) { DecompilerContext.getLogger().writeMessage("Cannot write class file " + file, ex); } }
@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); } } }
@Override public void createArchive(String path, String archiveName, Manifest manifest) { File file = new File(getAbsolutePath(path), archiveName); try { if (!(file.createNewFile() || file.isFile())) { throw new IOException("Cannot create file " + file); } FileOutputStream fileStream = new FileOutputStream(file); ZipOutputStream zipStream = manifest != null ? new JarOutputStream(fileStream, manifest) : new ZipOutputStream(fileStream); mapArchiveStreams.put(file.getPath(), zipStream); } catch (IOException ex) { DecompilerContext.getLogger().writeMessage("Cannot create archive " + file, ex); } }
@Override public void copyFile(String source, String path, String entryName) { try { InterpreterUtil.copyFile(new File(source), new File(getAbsolutePath(path), entryName)); } catch (IOException ex) { DecompilerContext.getLogger().writeMessage("Cannot copy " + source + " to " + entryName, ex); } }
@Override public void saveClassEntry(String path, String archiveName, String qualifiedName, String entryName, String content) { String file = new File(getAbsolutePath(path), archiveName).getPath(); if (!checkEntry(entryName, file)) { return; } try { ZipOutputStream out = mapArchiveStreams.get(file); out.putNextEntry(new ZipEntry(entryName)); if (content != null) { out.write(content.getBytes(StandardCharsets.UTF_8)); } } catch (IOException ex) { String message = "Cannot write entry " + entryName + " to " + file; DecompilerContext.getLogger().writeMessage(message, ex); } }
@Override public void copyEntry(String source, String path, String archiveName, String entryName) { String file = new File(getAbsolutePath(path), archiveName).getPath(); if (!checkEntry(entryName, file)) { return; } try (ZipFile srcArchive = new ZipFile(new File(source))) { ZipEntry entry = srcArchive.getEntry(entryName); if (entry != null) { try (InputStream in = srcArchive.getInputStream(entry)) { ZipOutputStream out = mapArchiveStreams.get(file); out.putNextEntry(new ZipEntry(entryName)); InterpreterUtil.copyStream(in, out); } } } catch (IOException ex) { String message = "Cannot copy entry " + entryName + " from " + source + " to " + file; DecompilerContext.getLogger().writeMessage(message, ex); } }
DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN); return null;