Class JavaOutputSink
java.lang.Object
com.pnfsoftware.jeb.core.output.code.CodeDocumentPart
com.pnfsoftware.jeb.core.output.code.CppLikeDocumentPart
com.pnfsoftware.jeb.core.units.code.java.JavaOutputSink
- All Implemented Interfaces:
ICodeDocument,ITextDocumentPart
This output sink is the recipient for the generation of a decompiled Java Abstract Syntax Tree
(AST). The sink also contains configuration elements that will guide how certain AST elements are
generated. Typically, a sink receives the output for a class or a method element.
Generating an AST yields a special type of elements, called items, that a client (such as the decompiler UI) may want to track to achieve higher level purpose such as xrefs building, renaming, easy syntax coloring, etc. Items include keywords, class/field/method/variable names, labels, etc. The type of items generated depends on the item factory provided to JavaOutputSink constructors.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCaptured constructor information for an anonymous class. -
Field Summary
Fields inherited from class com.pnfsoftware.jeb.core.output.code.CppLikeDocumentPart
commentBlockBegin, commentBlockEnd, commentInline -
Constructor Summary
ConstructorsConstructorDescriptionJavaOutputSink(int baseAnchorId) Create an output sink.JavaOutputSink(int baseAnchorId, JavaDocument doc, IDexDecompilerUnit dexdec) Create an output sink for a Java document. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGeneratedAnon(IJavaElement container, IJavaClass c) Register an anonymous type (most likely a class) that's about to be rendered as inline code, inside a method or another class.voidappendAnnotationsList(List<IJavaAnnotation> annotations, char charAfterAnno) Append annotations.voidappendAnnotationsList(List<IJavaAnnotation> annotations, char charAfterAnno, Set<String> skiplist) Append annotations, skipping selected annotation types.voidappendKeyword(JavaKeyword keyword) Append a Java keyword.voidappendKeyword(JavaKeyword keyword, long itemId) Append a Java keyword with an item identifier.intastDepth()Retrieve the current AST generation depth.Make sure to call beforegenerateEnter.astPop()Pop the current AST element from the generation stack.astPush(IJavaElement elt) Push an AST element on the generation stack.voidMark replacement generation as complete.Retrieve the containing method stack.Retrieve the current anonymous-class base type.Retrieve current anonymous-class capture information.Retrieve the current containing class.Retrieve the current containing method.intGet the method index of the method being generatedRetrieve the list of addresses of the decompilable (classes, fields, methods) items generated in this part.Retrieve the owning dex decompiler.intRetrieve the method-internals comment rendering mode.booleanDetermine whether private methods should be rendered last.booleanDetermine whether collapse metadata should be ignored.Retrieve the owning Java document.booleanDetermine whetherthisshould be omitted when possible.Retrieve the dynamic content manager.booleanDetermine whether annotations should be rendered.getGeneratedAnon(IJavaElement container) Retrieve anonymous classes generated in a container.booleanDetermine whether lambdas should be rendered when possible.booleanDetermine whether additional@Overrideannotations should be rendered.booleanDetermine whether synthetic fields should be rendered.booleanDetermine whether synthetic methods should be rendered.Retrieve recorded identifier coordinates.booleanDetermine whether blank lines should be inserted after compound statements.getReplacementFor(IJavaIdentifier ident) Retrieve a replacement expression for an identifier.booleanDetermine whether field-access targets should be resolved.booleanDetermine whether method-call targets should be resolved.intRetrieve the source-item sorting mode.intRetrieve the argument-count threshold for split call rendering.Retrieve the top-level containing class.booleanDetermine whether dex debug-information names should be used.booleanDetermine whethervarshould be rendered when possible.booleanDetermine whether an AST element is currently being generated.voidloadCommentInline(ICodeCoordinates insnCoord) Load an inline comment as the current end-of-line comment.Pop the current anonymous-class base type.Pop anonymous-class capture information.Pop the current containing class.Pop the current containing method.Pop the current identifier replacement map.voidPush an anonymous-class base type.voidPush anonymous-class capture information.voidPush a containing class on the generation stack.voidPush a containing method on the generation stack.voidpushReplacements(Map<IJavaIdentifier, IJavaExpression> replmap) Push an identifier replacement map.voidrecordGeneratedDecompilable(String signature) Record a generated decompilable item.voidrecordIdentifierCoordinates(long objectId, ICodeCoordinates coordinates) Record coordinates for an identifier item.voidrenderInlineComment(ICodeCoordinates coord, boolean appendEOL) Render an inline comment for code coordinates.voidrenderPreComment(ICodeCoordinates coord) Render a pre-comment for code coordinates.booleanRequest entry into replacement generation.intsetCurrentMethodIndex(int index) Set the method index of the method being generatedvoidSet the dynamic content manager.voidsetGeneratingReplacement(boolean generatingReplacement) Set the replacement-generation state.voidvalidate()Methods inherited from class com.pnfsoftware.jeb.core.output.code.CppLikeDocumentPart
appendMultiLineComment, appendMultiLineCommentAuto, eol, eol, getEolComment, getEolCoordinates, onEolAddComment, setEolComment, setEolComment, setEolCoordinatesMethods inherited from class com.pnfsoftware.jeb.core.output.code.CodeDocumentPart
append, append, append, appendAndRecord, appendAndRecord, appendAndRecord, appendComment, appendComment, appendCommentAuto, appendKeyword, appendKeyword, appendKeyword, appendMulti, appendParameterSeparator, brace, braceClose, bracket, bracketClose, decrementIndentationLevel, disablePadding, enablePadding, enableTokenFlattening, format, getAnchor, getAnchors, getCountOfAnchors, getCountOfLines, getCurrentAnchor, getCurrentCoordinates, getCurrentLine, getCurrentLineCoordinates, getCurrentLineIndex, getCurrentLineLength, getCurrentMarginLength, getCurrentMostPreciseCodeCoordinates, getIndentationLevel, getIndentationString, getLastLineIndex, getLine, getLineCount, getLines, getObjectLocations, incrementIndentationLevel, indentReset, isCurrentLineEmpty, markCurrentPosition, moveLastLine, moveLine, paren, parenClose, prependCodePart, recordCurrentCoordinates, recordLineCoordinates, recordObjectLocation, registerAnchor, registerAnchor, registerKeyword, resetPaddingString, setIndentationLevel, setIndentationString, setPaddingString, setParameterSeparator, space, space, toString, unrecordCurrentCoordinates, unrecordLineCoordinates
-
Constructor Details
-
JavaOutputSink
public JavaOutputSink(int baseAnchorId) Create an output sink.- Parameters:
baseAnchorId- base anchor identifier
-
JavaOutputSink
Create an output sink for a Java document.- Parameters:
baseAnchorId- base anchor identifierdoc- Java document, or nulldexdec- dex decompiler, or null
-
-
Method Details
-
getDocument
Retrieve the owning Java document.- Returns:
- Java document, or null
-
getDecompilerUnit
Retrieve the owning dex decompiler.- Returns:
- dex decompiler, or null
-
getSortItemsForRendering
public int getSortItemsForRendering()Retrieve the source-item sorting mode.- Returns:
- sorting mode
-
getUseDebugInfoNames
public boolean getUseDebugInfoNames()Determine whether dex debug-information names should be used.- Returns:
- true if debug-information names should be used
-
getDisplayPrivateMethodsLast
public boolean getDisplayPrivateMethodsLast()Determine whether private methods should be rendered last.- Returns:
- true if private methods should be rendered last
-
getInsertBlankLinesAfterCompounds
public boolean getInsertBlankLinesAfterCompounds()Determine whether blank lines should be inserted after compound statements.- Returns:
- true if blank lines should be inserted
-
getGenerateSyntheticFields
public boolean getGenerateSyntheticFields()Determine whether synthetic fields should be rendered.- Returns:
- true if synthetic fields should be rendered
-
getGenerateSyntheticMethods
public boolean getGenerateSyntheticMethods()Determine whether synthetic methods should be rendered.- Returns:
- true if synthetic methods should be rendered
-
getGenerateAnnotations
public boolean getGenerateAnnotations()Determine whether annotations should be rendered.- Returns:
- true if annotations should be rendered
-
getDisplayMethodInternalsAsComment
public int getDisplayMethodInternalsAsComment()Retrieve the method-internals comment rendering mode.- Returns:
- method-internals rendering mode
-
getResolveMethodCallTargets
public boolean getResolveMethodCallTargets()Determine whether method-call targets should be resolved.- Returns:
- true if method-call targets should be resolved
-
getResolveFieldAccessTargets
public boolean getResolveFieldAccessTargets()Determine whether field-access targets should be resolved.- Returns:
- true if field-access targets should be resolved
-
getGenerateOverrideAnnotations
public boolean getGenerateOverrideAnnotations()Determine whether additional@Overrideannotations should be rendered.- Returns:
- true if override annotations should be rendered
-
getGenerateLambdas
public boolean getGenerateLambdas()Determine whether lambdas should be rendered when possible.- Returns:
- true if lambdas should be rendered
-
getUseVarReservedType
public boolean getUseVarReservedType()Determine whethervarshould be rendered when possible.- Returns:
- true if
varshould be used when possible
-
getSplitCallArgThreshold
public int getSplitCallArgThreshold()Retrieve the argument-count threshold for split call rendering.- Returns:
- split-call argument threshold
-
getDoNotGenerateThisIfPossible
public boolean getDoNotGenerateThisIfPossible()Determine whetherthisshould be omitted when possible.- Returns:
- true if
thisshould be omitted when possible
-
getDisregardCollapse
public boolean getDisregardCollapse()Determine whether collapse metadata should be ignored.- Returns:
- true if collapse metadata should be ignored
-
pushContainingClass
Push a containing class on the generation stack.- Parameters:
c- containing class
-
popContainingClass
Pop the current containing class.- Returns:
- popped containing class
-
getCurrentContainingClass
Retrieve the current containing class.- Returns:
- current containing class, or null
-
getTopLevelClass
Retrieve the top-level containing class.- Returns:
- top-level class, or null
-
isBeingGenerated
Determine whether an AST element is currently being generated.- Parameters:
elt- AST element- Returns:
- true if the element is on the generation stack
-
astPush
Push an AST element on the generation stack.- Parameters:
elt- AST element- Returns:
- previous parent element, or null
-
astPop
Pop the current AST element from the generation stack.- Returns:
- popped AST element
-
astParent
Make sure to call beforegenerateEnter.- Returns:
- the parent of the element AST about to be rendered or null if there is none or none can be found
-
astDepth
public int astDepth()Retrieve the current AST generation depth.- Returns:
- AST stack depth
-
pushContainingMethod
Push a containing method on the generation stack.- Parameters:
m- containing method
-
popContainingMethod
Pop the current containing method.- Returns:
- popped containing method
-
getCurrentContainingMethod
Retrieve the current containing method.- Returns:
- current containing method, or null
-
getContainingMethods
Retrieve the containing method stack.- Returns:
- read-only containing methods
-
setDynamicContentManager
Set the dynamic content manager.- Parameters:
dcm- dynamic content manager, or null
-
getDynamicContentManager
Retrieve the dynamic content manager.- Returns:
- dynamic content manager, or null
-
setCurrentMethodIndex
public int setCurrentMethodIndex(int index) Set the method index of the method being generated- Parameters:
index- the current method index- Returns:
- the previous index
-
getCurrentMethodIndex
public int getCurrentMethodIndex()Get the method index of the method being generated- Returns:
- a negative value if the index cannot be determined or is invalid
-
appendKeyword
Append a Java keyword.- Parameters:
keyword- keyword to append
-
appendKeyword
Append a Java keyword with an item identifier.- Parameters:
keyword- keyword to appenditemId- item identifier
-
renderPreComment
Render a pre-comment for code coordinates.An end-of-line marker is always appended.
- Parameters:
coord- code coordinates
-
renderInlineComment
Render an inline comment for code coordinates.- Parameters:
coord- code coordinatesappendEOL- true to append an end-of-line marker
-
loadCommentInline
Load an inline comment as the current end-of-line comment.- Parameters:
insnCoord- instruction coordinates
-
appendAnnotationsList
Append annotations.- Parameters:
annotations- annotations to appendcharAfterAnno- character to append after each annotation
-
appendAnnotationsList
public void appendAnnotationsList(List<IJavaAnnotation> annotations, char charAfterAnno, Set<String> skiplist) Append annotations, skipping selected annotation types.- Parameters:
annotations- annotations to appendcharAfterAnno- character to append after each annotationskiplist- type signatures to skip, or null
-
recordIdentifierCoordinates
Record coordinates for an identifier item.- Parameters:
objectId- identifier item idcoordinates- code coordinates
-
getIdentifierCoordinates
Retrieve recorded identifier coordinates.- Returns:
- identifier coordinates keyed by item id
-
pushAnonymousBaseType
Push an anonymous-class base type.- Parameters:
type- base type, possibly null
-
popAnonymousBaseType
Pop the current anonymous-class base type.- Returns:
- popped base type, possibly null
-
getCurrentAnonymousBaseType
Retrieve the current anonymous-class base type.- Returns:
- current base type, or null
-
pushAnonymousCaptureInfo
Push anonymous-class capture information.- Parameters:
info- capture information
-
popAnonymousCaptureInfo
Pop anonymous-class capture information.- Returns:
- popped capture information
-
getCurrentAnonymousCaptureInfo
Retrieve current anonymous-class capture information.- Returns:
- capture information, or null
-
addGeneratedAnon
Register an anonymous type (most likely a class) that's about to be rendered as inline code, inside a method or another class. We use this multi-map to track anonymous types that were actually rendered, and those that were not. That can happen in obfuscated files where anonymous inner classes are used by third-party (not the container) classes only.- Parameters:
container- method or classc- an anonymous that's about to be generated (recorded to avoid generated it later)
-
getGeneratedAnon
Retrieve anonymous classes generated in a container.- Parameters:
container- method or class container- Returns:
- generated anonymous classes, possibly empty
-
pushReplacements
Push an identifier replacement map.- Parameters:
replmap- replacement map
-
popReplacements
Pop the current identifier replacement map.- Returns:
- replacement map
-
getReplacementFor
Retrieve a replacement expression for an identifier.- Parameters:
ident- identifier- Returns:
- replacement expression, or null
-
setGeneratingReplacement
public void setGeneratingReplacement(boolean generatingReplacement) Set the replacement-generation state.- Parameters:
generatingReplacement- true if a replacement is being generated
-
requestGeneratingReplacement
public boolean requestGeneratingReplacement()Request entry into replacement generation.- Returns:
- true if replacement generation may proceed
-
doneGeneratingReplacement
public void doneGeneratingReplacement()Mark replacement generation as complete. -
recordGeneratedDecompilable
Record a generated decompilable item.- Parameters:
signature- decompilable item signature
-
getDecompilables
Retrieve the list of addresses of the decompilable (classes, fields, methods) items generated in this part.- Returns:
- a list of items, ordered as they appear in the decompiled output
-
validate
public void validate()- Overrides:
validatein classCppLikeDocumentPart
-