How fesh0r/fernflower works
Main Components
• Command-Line Interface (CLI) & Input Handling: According to the README, users run the tool via a “java -jar” command with various options and source/destination paths. Represent this as a distinct entry point that parses input arguments (e.g., options like -ren, -hes, -hdc, etc.) and distinguishes between “source” (files or directories) and “library” inputs.
• Decompilation Core Engine: This comprises the main classes under packages such as “src/org/jetbrains/java/decompiler/main” (e.g. Fernflower.java, DecompilerContext.java, ClassesProcessor.java, etc.). This engine orchestrates reading bytecode, interpreting it and initiating decompilation.
• Code Analysis & Transformation Modules: There are several nested packages (e.g. “code”, “modules/decompiler”, “modules/code”) that perform bytecode analysis, control flow analysis, CFG generation (see packages such as cfg), expression reconstruction, exception handling, and various optimization tasks. Include modules for:
• Instruction parsing and processing (the “code” package)
• Control Flow Graph (CFG) construction and analysis (cfg sub-package)
• Expression and statement decompilation (modules/decompiler/exps and stats)
• Specialized deobfuscation routines (modules/decompiler/deobfuscator) and code renaming (modules/renamer)
• External Interfaces & Extension Points: The project supports plug-in renaming of identifiers via an external implementation (the IIdentifierRenamer interface) and accepts “library” files for analysis. Represent this integration point where external classes/interfaces interact.
• Test Suite: Although not a production component, having a distinct test suite (the “test” directory along with “testData”) helps verify core functionality. You may represent these as supporting modules that simulate inputs, verify correct output (decompiled source) and check edge cases in the decompilation process.
Their Relationships and Interactions
• The input files go to (or are scanned by) file access utilities.
• The “DecompilerContext” is set up based on user options and then injected into various processing stages.
• The engine then sequentially calls on the code analysis modules, CFG builders, expression processors, renaming helpers, and exception handling routines.
• External Dependencies: Include a connection from the command-line options to configuration/parameters that affect how each module operates (for example, turning off decompilation of generic signatures or handling lambda expressions).
Architectural Patterns and Design Principles
• Layered Architecture: Show a separation between the input-handling layer (CLI), core processing (engine, decompilation, and analyzers), and supporting utilities (renamers, collectors, and exception handlers).
• Modular Design: Emphasize that distinct packages handle specific tasks (e.g., “code”, “cfg”, “decompiler”, “deobfuscator”) and interact through well-defined interfaces.
• Extensibility: Note the extension point provided by the “IIdentifierRenamer” interface and similar mechanisms that allow plugging in custom behavior during decompilation.
• Robust Error Handling: Indicate that exception processing (found in modules like “ExceptionHandler.java” and various catch and finally handlers) is a crucial aspect of the design.
• If possible, add annotations or notes that mention key command-line options or configuration parameters from the README that affect the processing (e.g., “-ren activates renaming”, “-dgs processes generic signatures”).
• Error pathways or fallback mechanisms (such as when decompilation fails or when library files are used purely for reference).