public abstract class

DecompilerExporter

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.DecompilerExporter
Known Direct Subclasses

Class Overview

Helper class used to decompile and export to source files all or a subset of classes or methods of a code unit.

Example: export all top-level items to an output folder:

 IDecompilerUnit decomp = ...; // retrieved from the current IRuntimeProject
 File outdir = ...;
 DecompilerExporter exp = decomp.getExporter();
 exp.setOutputFolder(outdir, false);
 exp.setMethodTimeout(60_000L);  // safety
 exp.setTotalTimeout(15 * 60_000L);  // safety
 exp.setCallback(new ProgressCallbackAdapter() {
     @Override
     public void message(String msg) {
         System.out.println(msg);
     }
 });
 boolean success = exp.process();
 System.out.println("Errors: " + exp.getErrors());
 

Summary

Fields
protected IProgressCallback callback
protected IDecompilerUnit decomp
protected boolean discardDecompiledItemsAfterProcessing
protected Map<String, String> errormap
protected String headerString
protected static final ILogger logger
protected long methodTimeoutMs
protected File outputFolder
protected Pattern pattern
protected long totalTimeoutMs
protected boolean usesCustomDecompWriter
protected AtomicInteger writeCount
protected AtomicInteger writeErrorCount
Public Constructors
DecompilerExporter(IDecompilerUnit decompiler)
Create an exporter with default settings.
Public Methods
final boolean export()
A synonym for process().
IProgressCallback getCallback()
IDecompilerUnit getDecompiler()
Map<String, String> getErrors()
Retrieve a map "address -> error string" for all methods that failed the decompilation.
Integer getGeneratedFileCount()
Retrieve the number of generated source files.
String getHeaderString()
long getMethodTimeout()
File getOutputFolder()
Pattern getSignaturePattern()
long getTotalTimeout()
boolean isKeepDecompiledItemsAfterProcessing()
abstract boolean process()
Decompile and export all meaningful elements.
boolean processMethods()
Decompile and export all internal methods.
boolean processTopLevelClasses()
Decompile and export all top-level classes (i.e., non member classes).
void setCallback(IProgressCallback callback)
Set an optional callback to receive progress information on the decompilation.
void setDiscardDecompiledItemsAfterProcessing(boolean discardDecompiledItemsAfterProcessing)
Specify whether decompiled items should be kept or discarded after the decompilation process is complete.
void setHeaderString(String s)
Set an optional single-line header string, prepended to all decompiled classes.
void setMethodTimeout(long methodTimeoutMs)
Set an optional timeout for method decompilation.
void setOutputFolder(File folder, Boolean discardDecompiledItemsAfterProcessing)
Set an optional output folder.
void setOutputFolder(File folder)
void setSignaturePattern(Pattern pattern)
Set an optional matcher for classes or methods to be decompiled.
void setTotalTimeout(long totalTimeoutMs)
Set an optional timeout for the entire decompilation process.
Protected Methods
void customizeOptions(boolean decompilingClasses, DecompilationOptions.Builder optbld)
Optional method used to customize the options of the decompilation context.
String generateClassFileName(String address)
String generateMethodFileName(String address)
void reset()
void writeClassDecompilation(String addr)
void writeMethodDecompilation(String addr)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected IProgressCallback callback

protected IDecompilerUnit decomp

protected boolean discardDecompiledItemsAfterProcessing

protected Map<String, String> errormap

protected String headerString

protected static final ILogger logger

protected long methodTimeoutMs

protected File outputFolder

protected Pattern pattern

protected long totalTimeoutMs

protected boolean usesCustomDecompWriter

protected AtomicInteger writeCount

protected AtomicInteger writeErrorCount

Public Constructors

public DecompilerExporter (IDecompilerUnit decompiler)

Create an exporter with default settings.

Parameters
decompiler a decompiler

Public Methods

public final boolean export ()

A synonym for process().

public IProgressCallback getCallback ()

public IDecompilerUnit getDecompiler ()

public Map<String, String> getErrors ()

Retrieve a map "address -> error string" for all methods that failed the decompilation. Call after process().

public Integer getGeneratedFileCount ()

Retrieve the number of generated source files.

public String getHeaderString ()

public long getMethodTimeout ()

public File getOutputFolder ()

public Pattern getSignaturePattern ()

public long getTotalTimeout ()

public boolean isKeepDecompiledItemsAfterProcessing ()

public abstract boolean process ()

Decompile and export all meaningful elements. This is the recommended method to call. Top-level classes and their constituents will be exported; orphaned methods and other items will be exported as well.

If an output folder was specified, the resulting source files will be stored in a folder hierarchy that matches their namespace or package name.

Returns
  • true if no error occurred; false if some errors occurred

public boolean processMethods ()

Decompile and export all internal methods. Refer to processTopLevelClasses() to export classes hierarchically.

If an output folder was specified, the resulting source files will be stored in that folder. No folder hierarchy is created. File names are uniquely derived from method signatures.

Returns
  • true if no error occurred; false if some errors occurred

public boolean processTopLevelClasses ()

Decompile and export all top-level classes (i.e., non member classes).

If an output folder was specified, the resulting source files will be stored in a folder hierarchy that matches their namespace or package name.

Returns
  • true if no error occurred; false if some errors occurred

public void setCallback (IProgressCallback callback)

Set an optional callback to receive progress information on the decompilation.

public void setDiscardDecompiledItemsAfterProcessing (boolean discardDecompiledItemsAfterProcessing)

Specify whether decompiled items should be kept or discarded after the decompilation process is complete. Unless you are planning to examine decompiled items later, it is recommended to discard them.

public void setHeaderString (String s)

Set an optional single-line header string, prepended to all decompiled classes. The default header string is: Decompiled by JEB v[VERSION]

public void setMethodTimeout (long methodTimeoutMs)

Set an optional timeout for method decompilation.

public void setOutputFolder (File folder, Boolean discardDecompiledItemsAfterProcessing)

Set an optional output folder. If the folder exists and contents is already present, it will NOT be removed.

Parameters
discardDecompiledItemsAfterProcessing optional; if non-null, also update setDiscardDecompiledItemsAfterProcessing(boolean)
Throws
IOException if some error occurred when creating the output folder

public void setOutputFolder (File folder)

Throws
IOException

public void setSignaturePattern (Pattern pattern)

Set an optional matcher for classes or methods to be decompiled.

Parameters
pattern a regex pattern

public void setTotalTimeout (long totalTimeoutMs)

Set an optional timeout for the entire decompilation process.

Protected Methods

protected void customizeOptions (boolean decompilingClasses, DecompilationOptions.Builder optbld)

Optional method used to customize the options of the decompilation context. The custom implementation may modify or set new options. The default implementation does nothing.

Parameters
decompilingClasses true if the exporter will decompile classes; false if it will decompile methods
optbld the current option builder

protected String generateClassFileName (String address)

protected String generateMethodFileName (String address)

protected void reset ()

protected void writeClassDecompilation (String addr)

protected void writeMethodDecompilation (String addr)