Class AbstractMasterOptimizer<T extends IOptimizerTarget>
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.decompiler.opt.AbstractMasterOptimizer<T>
- All Implemented Interfaces:
IMasterOptimizer<T>
- Direct Known Subclasses:
CMasterOptimizer,EMasterOptimizer
public abstract class AbstractMasterOptimizer<T extends IOptimizerTarget>
extends Object
implements IMasterOptimizer<T>
Standard implementation of a generic master optimizer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intdisabled (0) by default; client code must explicitly set to non-zero to allow the execution of decryptors.protected booleanfalse by default; client code must explicitly set to true to allow the execution of deobfuscators.protected booleanfalse by default; client code must explicitly set to true to allow the execution of unsafe optimizers.protected intmaximum run count for the group [1..N] (<0 means no limit)protected List<IMasterOptimizerInstrumenter<T>>instrumentersprotected SortedMap<Integer,List<OptimizerEntry<T>>> groups of optimizers; groups 0 and -1 are entry and exit groups, respectivelyprotected List<OptimizerEntry<T>>list of all optimizersprotected Tdefault targetFields inherited from interface com.pnfsoftware.jeb.core.units.code.asm.decompiler.opt.IMasterOptimizer
DEFAULT_GROUP -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMasterOptimizer(T t, int grp1NMaxRunCount) Create a master optimizer. -
Method Summary
Modifier and TypeMethodDescriptionintgetMode()Retrieve the current operating mode for this MO.intgetOptimizationCount(boolean deobfuscationOnly) getOptimizer(Class<? extends IOptimizer<T>> clazz) getOptimizerObject(Class<? extends IOptimizer<T>> clazz) Get a copy of the list of optimizer entries registered with this MO.getRegisteredOptimizers(int groupId) Get a copy of the lists of optimizer entries registered with this MO and belonging to the provided optimizer group.Get the target onto which the optimizations will be performed.protected abstract StringgetTargetAddress(T target) intbooleanbooleanprotected booleanonOptimizerException(T target, IOptimizer<T> opt, Exception ex) This method is called when an optimizer hard-failed and generated an exception.intperform()Perform an optimization pass.intperformMultiple(List<OptimizerEntry<T>> list) Run the list of optimizers, in sequence.intPerform a single optimization, using the provided optimizer (which must have been previously registered).protected intprotected intperformV2(boolean rerunFromStartAfterOpt) protected voidpostAllOptimizationsCallback(T target) This method might be overridden, but the parent should be called first.protected voidpostOptimizationCallback(T target, OptimizerEntry<T> e, int cnt, long executionTimeMs) This method might be overridden, but the parent should be called first.protected voidpreAllOptimizationsCallback(T target) This method might be overridden, but the parent should be called first.protected voidpreOptimizationCallback(T target, OptimizerEntry<T> e) This method might be overridden, but the parent should be called first.voidregisterInstrumenter(IMasterOptimizerInstrumenter<T> instrumenter) Register an instrumenter.registerOptimizer(int group, IOptimizer<T> opt) Register an optimizer, using the optimizer's provided default priority.registerOptimizer(IOptimizer<T> opt) Register an optimizer to themain group, using the optimizer's provided default priority.voidsetDecryptorSupport(int value) voidsetEnableDeobfuscators(boolean enabled) voidsetEnableUnsafeOptimizers(boolean enabled) setMode(OptimizerMode mode) voidsetPolicyForOptimizerTag(String tag, boolean allowed) Set the running policy associated to a tag or group of tags.voidSet the optimizer's target.voidbooleanunregisterInstrumenter(IMasterOptimizerInstrumenter<T> instrumenter) Unregister an instrumenterbooleanRemove an optimizer.
-
Field Details
-
t
default target -
optGrpMap
groups of optimizers; groups 0 and -1 are entry and exit groups, respectively -
optList
list of all optimizers -
grp1NMaxRunCount
protected int grp1NMaxRunCountmaximum run count for the group [1..N] (<0 means no limit) -
instrumenters
instrumenters -
enableUnsafeOptimizers
protected boolean enableUnsafeOptimizersfalse by default; client code must explicitly set to true to allow the execution of unsafe optimizers. -
enableDeobfuscators
protected boolean enableDeobfuscatorsfalse by default; client code must explicitly set to true to allow the execution of deobfuscators. -
decryptorSupport
protected int decryptorSupportdisabled (0) by default; client code must explicitly set to non-zero to allow the execution of decryptors.
-
-
Constructor Details
-
AbstractMasterOptimizer
Create a master optimizer.- Parameters:
t- the default target, may be nullgrp1NMaxRunCount- maximum run count for the group [1..N]
-
-
Method Details
-
getTarget
Description copied from interface:IMasterOptimizerGet the target onto which the optimizations will be performed.- Specified by:
getTargetin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
setTarget
Description copied from interface:IMasterOptimizerSet the optimizer's target.- Specified by:
setTargetin interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
setMode
- Specified by:
setModein interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
- the previous mode
-
getMode
Description copied from interface:IMasterOptimizerRetrieve the current operating mode for this MO.- Specified by:
getModein interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
- the current operating mode
-
setEnableUnsafeOptimizers
public void setEnableUnsafeOptimizers(boolean enabled) -
isEnableUnsafeOptimizers
public boolean isEnableUnsafeOptimizers() -
setEnableDeobfuscators
public void setEnableDeobfuscators(boolean enabled) -
isEnableDeobfuscators
public boolean isEnableDeobfuscators() -
setDecryptorSupport
public void setDecryptorSupport(int value) -
getDecryptorSupport
public int getDecryptorSupport() -
setPolicyForOptimizerTag
Description copied from interface:IMasterOptimizerSet the running policy associated to a tag or group of tags. Policy checks when deciding whether an optimizer should be run works as follow: 1) the tag must be allowed, 2) if passed, the tag must not be blocked. By default, all tags are allowed, none are blocked. To reset to that default policy: first invoke this method with("*", true), then invoke it with(null, false).- Specified by:
setPolicyForOptimizerTagin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Parameters:
tag- tag name; the special name"*"means all tags; the special name""(empty string) or null string means no tagallowed- true to allow the master optimizer to run the optimizer with the specified tag; false to block it
-
registerOptimizer
Description copied from interface:IMasterOptimizerRegister an optimizer to themain group, using the optimizer's provided default priority. Refer toIOptimizer#getDefaultPriority().- Specified by:
registerOptimizerin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
registerOptimizer
Description copied from interface:IMasterOptimizerRegister an optimizer, using the optimizer's provided default priority. Refer toIOptimizer#getDefaultPriority().- Specified by:
registerOptimizerin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
unregisterOptimizer
Description copied from interface:IMasterOptimizerRemove an optimizer.- Specified by:
unregisterOptimizerin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
unregisterAllOptimizers
public void unregisterAllOptimizers() -
getRegisteredOptimizers
Description copied from interface:IMasterOptimizerGet a copy of the list of optimizer entries registered with this MO.- Specified by:
getRegisteredOptimizersin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
getRegisteredOptimizers
Description copied from interface:IMasterOptimizerGet a copy of the lists of optimizer entries registered with this MO and belonging to the provided optimizer group.- Specified by:
getRegisteredOptimizersin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
getOptimizer
- Specified by:
getOptimizerin interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
getTotalOptimizationCount
public int getTotalOptimizationCount()- Specified by:
getTotalOptimizationCountin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
getOptimizationCount
public int getOptimizationCount(boolean deobfuscationOnly) - Specified by:
getOptimizationCountin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
-
getOptimizerObject
- Specified by:
getOptimizerObjectin interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
perform
public int perform()Description copied from interface:IMasterOptimizerPerform an optimization pass. All the optimizers will be run according to this master's schedule. They may be run multiple times.- Specified by:
performin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
- the total number of optimizations performed
-
performV1
protected int performV1() -
performV2
protected int performV2(boolean rerunFromStartAfterOpt) -
performMultiple
Description copied from interface:IMasterOptimizerRun the list of optimizers, in sequence. Each optimizer is run once.- Specified by:
performMultiplein interfaceIMasterOptimizer<T extends IOptimizerTarget>- Parameters:
list- a list of optimizers- Returns:
- the total number of optimizations performed
-
performSingle
Description copied from interface:IMasterOptimizerPerform a single optimization, using the provided optimizer (which must have been previously registered).- Specified by:
performSinglein interfaceIMasterOptimizer<T extends IOptimizerTarget>- Parameters:
e- an optimizer- Returns:
- the total number of optimizations performed
-
preAllOptimizationsCallback
This method might be overridden, but the parent should be called first. -
preOptimizationCallback
This method might be overridden, but the parent should be called first. Note that this method might have a big impact on decompilation performance, so override carefully. -
postAllOptimizationsCallback
This method might be overridden, but the parent should be called first. -
postOptimizationCallback
protected void postOptimizationCallback(T target, OptimizerEntry<T> e, int cnt, long executionTimeMs) This method might be overridden, but the parent should be called first. Note that this method might have a big impact on decompilation performance, so override carefully. -
registerInstrumenter
Description copied from interface:IMasterOptimizerRegister an instrumenter. Instrumenters will be called following their registration order.- Specified by:
registerInstrumenterin interfaceIMasterOptimizer<T extends IOptimizerTarget>
-
unregisterInstrumenter
Description copied from interface:IMasterOptimizerUnregister an instrumenter- Specified by:
unregisterInstrumenterin interfaceIMasterOptimizer<T extends IOptimizerTarget>- Returns:
- true if the instrumenter was removed, false otherwise
-
onOptimizerException
This method is called when an optimizer hard-failed and generated an exception.- Parameters:
target- the target that being optimizedopt- the failing optimizerex- the generated exception- Returns:
- if true, the exception will be neutered and the master optimizer will resume the optimizing process; else, the exception will be thrown
-
retrievePerformanceCounters
-
getTargetAddress
-