Class DecompilerExporter
java.lang.Object
com.pnfsoftware.jeb.core.units.code.DecompilerExporter
- Direct Known Subclasses:
DexDecompilerExporter,NativeDecompilerExporter
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());
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IProgressCallbackProgress callback.protected IDecompilerUnitDecompiler unit.protected booleanTrue to discard decompiled items after processing.Decompilation errors.protected StringHeader prepended to generated files.protected static final ILoggerLogger.protected longPer-method timeout, in milliseconds.protected FileOutput folder.protected PatternOptional signature pattern.protected longTotal timeout, in milliseconds.protected booleanTrue if a custom decompilation writer is used.protected AtomicIntegerGenerated file count.protected AtomicIntegerGenerated file error count. -
Constructor Summary
ConstructorsConstructorDescriptionDecompilerExporter(IDecompilerUnit decompiler) Create an exporter with default settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcustomizeOptions(boolean decompilingClasses, DecompilationOptions.Builder optbld) Optional method used to customize the options of the decompilation context.final booleanexport()A synonym forprocess().protected StringgenerateClassFileName(String address) Generate a file name for a decompiled class.protected StringgenerateMethodFileName(String address) Generate a file name for a decompiled method.Get the progress callback.Get the decompiler.Retrieve a map "address -> error string" for all methods that failed the decompilation.Retrieve the number of generated source files.Get the header string prepended to generated files.longGet the method timeout.Get the output folder.Get the signature pattern.longGet the total timeout.booleanDetermine whether decompiled items are discarded after processing.abstract booleanprocess()Decompile and export all meaningful elements.booleanDecompile and export all internal methods.booleanDecompile and export all top-level classes (i.e., non member classes).protected voidreset()Reset exporter counters and errors.voidsetCallback(IProgressCallback callback) Set an optional callback to receive progress information on the decompilation.voidsetDiscardDecompiledItemsAfterProcessing(boolean discardDecompiledItemsAfterProcessing) Specify whether decompiled items should be kept or discarded after the decompilation process is complete.voidSet an optional single-line header string, prepended to all decompiled classes.voidsetMethodTimeout(long methodTimeoutMs) Set an optional timeout for method decompilation.voidsetOutputFolder(File folder) Set the output folder.voidsetOutputFolder(File folder, Boolean discardDecompiledItemsAfterProcessing) Set an optional output folder.voidsetSignaturePattern(Pattern pattern) Set an optional matcher for classes or methods to be decompiled.voidsetTotalTimeout(long totalTimeoutMs) Set an optional timeout for the entire decompilation process.protected voidWrite a class decompilation to disk.protected voidWrite a method decompilation to disk.
-
Field Details
-
logger
Logger. -
decomp
Decompiler unit. -
outputFolder
Output folder. -
headerString
Header prepended to generated files. -
pattern
Optional signature pattern. -
methodTimeoutMs
protected long methodTimeoutMsPer-method timeout, in milliseconds. -
totalTimeoutMs
protected long totalTimeoutMsTotal timeout, in milliseconds. -
callback
Progress callback. -
discardDecompiledItemsAfterProcessing
protected boolean discardDecompiledItemsAfterProcessingTrue to discard decompiled items after processing. -
usesCustomDecompWriter
protected boolean usesCustomDecompWriterTrue if a custom decompilation writer is used. -
writeCount
Generated file count. -
writeErrorCount
Generated file error count. -
errormap
Decompilation errors.
-
-
Constructor Details
-
DecompilerExporter
Create an exporter with default settings.- Parameters:
decompiler- a decompiler
-
-
Method Details
-
reset
protected void reset()Reset exporter counters and errors. -
getDecompiler
Get the decompiler.- Returns:
- decompiler
-
setOutputFolder
Set the output folder.- Parameters:
folder- output folder- Throws:
IOException- if the output folder cannot be created
-
setOutputFolder
public void setOutputFolder(File folder, Boolean discardDecompiledItemsAfterProcessing) throws IOException Set an optional output folder. If the folder exists and contents is already present, it will NOT be removed.- Parameters:
folder- output folderdiscardDecompiledItemsAfterProcessing- optional; if non-null, also updatesetDiscardDecompiledItemsAfterProcessing(boolean)- Throws:
IOException- if some error occurred when creating the output folder
-
getOutputFolder
Get the output folder.- Returns:
- output folder, or null
-
setHeaderString
Set an optional single-line header string, prepended to all decompiled classes. The default header string is:Decompiled by JEB v[VERSION]- Parameters:
s- header string
-
getHeaderString
Get the header string prepended to generated files.- Returns:
- header string, or null
-
setSignaturePattern
Set an optional matcher for classes or methods to be decompiled.- Parameters:
pattern- a regex pattern
-
getSignaturePattern
Get the signature pattern.- Returns:
- signature pattern, or null
-
setMethodTimeout
public void setMethodTimeout(long methodTimeoutMs) Set an optional timeout for method decompilation.- Parameters:
methodTimeoutMs- timeout in milliseconds
-
getMethodTimeout
public long getMethodTimeout()Get the method timeout.- Returns:
- timeout in milliseconds
-
setTotalTimeout
public void setTotalTimeout(long totalTimeoutMs) Set an optional timeout for the entire decompilation process.- Parameters:
totalTimeoutMs- timeout in milliseconds
-
getTotalTimeout
public long getTotalTimeout()Get the total timeout.- Returns:
- timeout in milliseconds
-
setCallback
Set an optional callback to receive progress information on the decompilation.- Parameters:
callback- progress callback
-
getCallback
Get the progress callback.- Returns:
- progress callback, or null
-
setDiscardDecompiledItemsAfterProcessing
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.- Parameters:
discardDecompiledItemsAfterProcessing- true to discard decompiled items after processing
-
isDiscardDecompiledItemsAfterProcessing
public boolean isDiscardDecompiledItemsAfterProcessing()Determine whether decompiled items are discarded after processing.- Returns:
- true if decompiled items are discarded after processing
-
export
public final boolean export()A synonym forprocess().- Returns:
- true if no error occurred
-
process
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
-
customizeOptions
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 methodsoptbld- the current option builder
-
processTopLevelClasses
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
-
processMethods
public boolean processMethods()Decompile and export all internal methods. Refer toprocessTopLevelClasses()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
-
generateMethodFileName
Generate a file name for a decompiled method.- Parameters:
address- method address- Returns:
- file name
-
writeMethodDecompilation
Write a method decompilation to disk.- Parameters:
addr- method address
-
generateClassFileName
Generate a file name for a decompiled class.- Parameters:
address- class address- Returns:
- file name
-
writeClassDecompilation
Write a class decompilation to disk.- Parameters:
addr- class address
-
getGeneratedFileCount
Retrieve the number of generated source files.- Returns:
- generated file count
-
getErrors
Retrieve a map "address -> error string" for all methods that failed the decompilation. Call afterprocess().- Returns:
- error map
-