Class CommonQueries
- java.lang.Object
-
- com.ensoftcorp.open.commons.analysis.CommonQueries
-
public final class CommonQueries extends java.lang.Object
Common queries which are useful for writing larger language agnostic analysis programs, and for using on the shell. This also acts as a wrapper around relevantcom.ensoftcorp.atlas.core.script.CommonQueries
API functions.- Author:
- Ben Holland, Tom Deering, Jon Mathews
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.ensoftcorp.atlas.core.query.Q
advancedIntersection(com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String[] nodeTags, java.lang.String[] edgeTags)
Given two query expressions, intersects the given node and edge kinds to produce a new expression.static com.ensoftcorp.atlas.core.query.Q
called(com.ensoftcorp.atlas.core.query.Q origin)
Returns the subset of the given functions which are called.static com.ensoftcorp.atlas.core.query.Q
called(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the subset of the given functions which are called.static com.ensoftcorp.atlas.core.query.Q
calledBy(com.ensoftcorp.atlas.core.query.Q callers, com.ensoftcorp.atlas.core.query.Q called)
Returns the given functions which were called by the given callers.static com.ensoftcorp.atlas.core.query.Q
calledBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q callers, com.ensoftcorp.atlas.core.query.Q called)
Returns the given functions which were called by the given callers.static com.ensoftcorp.atlas.core.query.Q
callers(com.ensoftcorp.atlas.core.query.Q origin)
Returns the direct callers of the given functions.static com.ensoftcorp.atlas.core.query.Q
callers(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the direct callers of the given functions.static com.ensoftcorp.atlas.core.query.Q
cfg(com.ensoftcorp.atlas.core.db.graph.Node function)
static com.ensoftcorp.atlas.core.query.Q
cfg(com.ensoftcorp.atlas.core.query.Q functions)
static com.ensoftcorp.atlas.core.query.Q
classLiterals(com.ensoftcorp.atlas.core.query.Q types)
Returns all references to class literals (Type.class) for the given types.static com.ensoftcorp.atlas.core.query.Q
classLiterals(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q types)
Returns all references to class literals (Type.class) for the given types.static com.ensoftcorp.atlas.core.query.Q
conditionsAbove(com.ensoftcorp.atlas.core.query.Q origin)
Returns the control flow graph between conditional nodes and the given origin.static com.ensoftcorp.atlas.core.query.Q
conditionsAbove(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the control flow graph between conditional nodes and the given origin.static com.ensoftcorp.atlas.core.query.Q
declarations(com.ensoftcorp.atlas.core.query.Q origin)
Produces a declarations (contains) graph.static com.ensoftcorp.atlas.core.query.Q
declarations(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Produces a declarations (contains) graph.static com.ensoftcorp.atlas.core.query.Q
dfg(com.ensoftcorp.atlas.core.db.graph.Node function)
static com.ensoftcorp.atlas.core.query.Q
dfg(com.ensoftcorp.atlas.core.query.Q functions)
static long
edgeSize(com.ensoftcorp.atlas.core.query.Q toCount)
Returns the number of edges contained.static com.ensoftcorp.atlas.core.query.Q
excfg(com.ensoftcorp.atlas.core.db.graph.Node function)
static com.ensoftcorp.atlas.core.query.Q
excfg(com.ensoftcorp.atlas.core.query.Q functions)
static com.ensoftcorp.atlas.core.query.Q
firstDeclarator(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q declared, java.lang.String... declaratorTypes)
Returns the first declaring node of the given Q which is tagged with one of the given types.static com.ensoftcorp.atlas.core.query.Q
firstDeclarator(com.ensoftcorp.atlas.core.query.Q declared, java.lang.String... declaratorTypes)
Returns the first declaring node of the given Q which is tagged with one of the given types.static com.ensoftcorp.atlas.core.query.Q
functionParameter(com.ensoftcorp.atlas.core.query.Q functions)
Returns the parameters of the given functions.static com.ensoftcorp.atlas.core.query.Q
functionParameter(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
Returns the parameters of the given functions.static com.ensoftcorp.atlas.core.query.Q
functionParameter(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions, java.lang.Integer... index)
Returns the parameters of the given functions at the given indices.static com.ensoftcorp.atlas.core.query.Q
functionParameter(com.ensoftcorp.atlas.core.query.Q functions, java.lang.Integer... index)
Returns the parameters of the given functions at the given indices.static com.ensoftcorp.atlas.core.query.Q
functionReturn(com.ensoftcorp.atlas.core.query.Q functions)
Returns the return nodes for the given functions.static com.ensoftcorp.atlas.core.query.Q
functionReturn(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
Returns the return nodes for the given functions.static com.ensoftcorp.atlas.core.query.Q
functions(java.lang.String... functionNames)
Returns the set of functions where their names matches the any of the names given (functionNames) list.static com.ensoftcorp.atlas.core.query.Q
functionsOf(com.ensoftcorp.atlas.core.query.Q types)
Returns the functions declared by the given types.static com.ensoftcorp.atlas.core.query.Q
functionsOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q types)
Returns the functions declared by the given types.static com.ensoftcorp.atlas.core.db.graph.Node
getContainingControlFlowNode(com.ensoftcorp.atlas.core.db.graph.Node node)
Returns the nearest parent that is a control flow nodestatic com.ensoftcorp.atlas.core.db.graph.Node
getContainingFunction(com.ensoftcorp.atlas.core.db.graph.Node node)
Returns the containing function of a given graph element or null if one is not foundstatic com.ensoftcorp.atlas.core.query.Q
getContainingFunctions(com.ensoftcorp.atlas.core.query.Q nodes)
Returns the containing function of a given Q or empty if one is not foundstatic com.ensoftcorp.atlas.core.db.graph.Node
getContainingNode(com.ensoftcorp.atlas.core.db.graph.Node node, java.lang.String containingTag)
Find the next immediate containing node with the given tag.static com.ensoftcorp.atlas.core.db.graph.Edge
getEdgeByAddress(java.lang.String address)
Selects the Atlas edge graph element given a serialized graph element address Returns null if the address does not correspond to a edgestatic com.ensoftcorp.atlas.core.db.graph.GraphElement
getGraphElementByAddress(java.lang.String address)
Selects the Atlas graph element given a serialized graph element address Returns null if the address does not correspond to a graph elementstatic com.ensoftcorp.atlas.core.db.graph.Node
getNodeByAddress(java.lang.String address)
Selects the Atlas node graph element given a serialized graph element address Returns null if the address does not correspond to a nodestatic java.lang.String
getQualifiedFunctionName(com.ensoftcorp.atlas.core.db.graph.Node function)
Helper function to get the stringified qualified name of the functionstatic java.lang.String
getQualifiedName(com.ensoftcorp.atlas.core.db.graph.Node node)
Helper function to get the stringified qualified name of the functionstatic java.lang.String
getQualifiedName(com.ensoftcorp.atlas.core.db.graph.Node node, java.lang.String... stopAfterTags)
Helper function to get the stringified qualified name of the class Stop after tags specify parent containers to stop qualifying at (example packages or jars)static java.lang.String
getQualifiedTypeName(com.ensoftcorp.atlas.core.db.graph.Node type)
Helper function to get the stringified qualified name of the classstatic com.ensoftcorp.atlas.core.query.Q
globals(java.lang.String... names)
Returns the nodes representing the global variable(s) given by the parameter list (names).static com.ensoftcorp.atlas.core.query.Q
interactions(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... edgeTags)
Returns direct edges of the given kinds which lay immediately between the first group and second group of nodes.static com.ensoftcorp.atlas.core.query.Q
interactions(com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... edgeTags)
Returns direct edges of the given kinds which lay immediately between the first group and second group of nodes.static java.util.List<com.ensoftcorp.atlas.core.query.Q>
interactions2(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... tags)
For each Node in second, return a Q containing all Edges immediately incident on Nodes in first.static boolean
isEmpty(com.ensoftcorp.atlas.core.query.Q test)
Returns whether the given Q is empty.static boolean
isGoverningBranch(com.ensoftcorp.atlas.core.db.graph.Node branch, com.ensoftcorp.atlas.core.db.graph.Node event)
Given a function, a branch, and an event of interest returns true if the branch governs whether or not the event of interest could be executed.static boolean
isGoverningBranch(com.ensoftcorp.atlas.core.db.graph.Node branch, com.ensoftcorp.atlas.core.db.graph.Node event, boolean includeExceptionalPaths)
Given a function, a branch, and an event of interest returns true if the branch governs whether or not the event of interest could be executed.static boolean
isNotEmpty(com.ensoftcorp.atlas.core.query.Q test)
Returns whether the given Q is not emptystatic com.ensoftcorp.atlas.core.db.graph.Node
leastCommonAncestor(com.ensoftcorp.atlas.core.db.graph.Node child1, com.ensoftcorp.atlas.core.db.graph.Node child2, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common ancestor of both child1 and child2 within the given graphstatic com.ensoftcorp.atlas.core.db.graph.Node
leastCommonAncestor(com.ensoftcorp.atlas.core.db.graph.Node child1, com.ensoftcorp.atlas.core.db.graph.Node child2, com.ensoftcorp.atlas.core.query.Q graph)
Returns the least common ancestor of both child1 and child2 within the given graphstatic com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node>
leastCommonAncestors(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> children, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common children of of the given parents within the given graphstatic com.ensoftcorp.atlas.core.db.graph.Node
leastCommonChild(com.ensoftcorp.atlas.core.db.graph.Node parent1, com.ensoftcorp.atlas.core.db.graph.Node parent2, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common child of both parent1 and parent2 within the given graphstatic com.ensoftcorp.atlas.core.db.graph.Node
leastCommonChild(com.ensoftcorp.atlas.core.db.graph.Node parent1, com.ensoftcorp.atlas.core.db.graph.Node parent2, com.ensoftcorp.atlas.core.query.Q graph)
Returns the least common ancestor of both parent1 and parent2 within the given graphstatic com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node>
leastCommonChildren(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> parents, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common children of of the given parents within the given graphstatic com.ensoftcorp.atlas.core.query.Q
libraryDeclarations()
Returns those nodes which are declared by a library.static com.ensoftcorp.atlas.core.query.Q
libraryDeclarations(com.ensoftcorp.atlas.core.query.Q context)
Returns those nodes which are declared by a library.static com.ensoftcorp.atlas.core.query.Q
libraryDeclarations(com.ensoftcorp.atlas.core.query.Q context, java.lang.String name)
Returns those nodes which are declared by a library with the given name.static com.ensoftcorp.atlas.core.query.Q
libraryDeclarations(java.lang.String name)
Returns those nodes which are declared by a library with the given name.static com.ensoftcorp.atlas.core.query.Q
localDeclarations(com.ensoftcorp.atlas.core.query.Q functions)
All nodes declared under the given functions, but NOT declared under additional functions or types.static com.ensoftcorp.atlas.core.query.Q
localDeclarations(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
All nodes declared under the given functions, but NOT declared under additional functions or types.static com.ensoftcorp.atlas.core.query.Q
mutatedBy(com.ensoftcorp.atlas.core.query.Q mutators, com.ensoftcorp.atlas.core.query.Q origin)
Returns those elements in the origin which were called by or written by elements in the mutators set.static com.ensoftcorp.atlas.core.query.Q
mutatedBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q mutators, com.ensoftcorp.atlas.core.query.Q origin)
Returns those elements in the origin which were called by or written by elements in the mutators set.static com.ensoftcorp.atlas.core.query.Q
mutators(com.ensoftcorp.atlas.core.query.Q origin)
Given a Q containing functions or data flow nodes, returns a Q of things which write to or call things in the Q.static com.ensoftcorp.atlas.core.query.Q
mutators(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Given a Q containing functions or data flow nodes, returns a Q of things which write to or call things in the Q.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesContaining(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String substring)
Returns the nodes whose attribute values contain the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesContaining(java.lang.String attribute, java.lang.String substring)
Returns the nodes whose attribute values contain the given string.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesEndingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String suffix)
Returns the nodes whose attribute values end with the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesEndingWith(java.lang.String attribute, java.lang.String suffix)
Returns the nodes whose attribute values end with the given string.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesMatchingRegex(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String regex)
Returns the nodes whose attribute values match the given regular expression within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesMatchingRegex(java.lang.String attribute, java.lang.String regex)
Returns the nodes whose attribute values match the given regular expression.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesStartingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String prefix)
Returns the nodes whose attribute values start with the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesAttributeValuesStartingWith(java.lang.String attribute, java.lang.String prefix)
Returns the nodes whose attribute values start with the given string.static com.ensoftcorp.atlas.core.query.Q
nodesContaining(com.ensoftcorp.atlas.core.query.Q context, java.lang.String substring)
Returns the nodes whose names contain the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesContaining(java.lang.String substring)
Returns the nodes whose names contain the given string.static com.ensoftcorp.atlas.core.query.Q
nodesEndingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String suffix)
Returns the nodes whose names end with the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesEndingWith(java.lang.String suffix)
Returns the nodes whose names end with the given string.static long
nodeSize(com.ensoftcorp.atlas.core.query.Q toCount)
Returns the number of nodes contained.static com.ensoftcorp.atlas.core.query.Q
nodesMatchingRegex(com.ensoftcorp.atlas.core.query.Q context, java.lang.String regex)
Returns the nodes whose names match the given regular expression within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesMatchingRegex(java.lang.String regex)
Returns the nodes whose names match the given regular expression.static com.ensoftcorp.atlas.core.query.Q
nodesStartingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String prefix)
Returns the nodes whose names start with the given string within the given context.static com.ensoftcorp.atlas.core.query.Q
nodesStartingWith(java.lang.String prefix)
Returns the nodes whose names start with the given string.static com.ensoftcorp.atlas.core.query.Q
nodesWithSelfEdges(com.ensoftcorp.atlas.core.query.Q context)
Returns those nodes in the context which have self edges.static com.ensoftcorp.atlas.core.query.Q
readBy(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes from which nodes in the origin read.static com.ensoftcorp.atlas.core.query.Q
readBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes from which nodes in the origin read.static com.ensoftcorp.atlas.core.query.Q
readersOf(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly read from nodes in origin.static com.ensoftcorp.atlas.core.query.Q
readersOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly read from nodes in origin.static com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node>
syncPoints(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> roots, com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> leaves, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns points where there are no competing branch pointsstatic com.ensoftcorp.atlas.core.query.Q
types(java.lang.String... names)
Returns the nodes representing the types given by the names.static com.ensoftcorp.atlas.core.query.Q
writersOf(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly write to nodes in origin.static com.ensoftcorp.atlas.core.query.Q
writersOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly write to nodes in origin.static com.ensoftcorp.atlas.core.query.Q
writtenBy(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes to which nodes in origin write.static com.ensoftcorp.atlas.core.query.Q
writtenBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes to which nodes in origin write.
-
-
-
Method Detail
-
classLiterals
public static com.ensoftcorp.atlas.core.query.Q classLiterals(com.ensoftcorp.atlas.core.query.Q types)
Returns all references to class literals (Type.class) for the given types. Equivalent to classLiterals(universe(), types).- Parameters:
types
-- Returns:
- the query expression
-
classLiterals
public static com.ensoftcorp.atlas.core.query.Q classLiterals(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q types)
Returns all references to class literals (Type.class) for the given types.- Parameters:
types
-- Returns:
- the query expression
-
declarations
public static com.ensoftcorp.atlas.core.query.Q declarations(com.ensoftcorp.atlas.core.query.Q origin)
Produces a declarations (contains) graph. Equivalent to declarations(universe(), origin).- Parameters:
origin
-- Returns:
- the query expression
-
declarations
public static com.ensoftcorp.atlas.core.query.Q declarations(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Produces a declarations (contains) graph. Uses only the given context for the traversal.- Parameters:
context
-origin
-- Returns:
- the query expression
-
interactions
public static com.ensoftcorp.atlas.core.query.Q interactions(com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... edgeTags)
Returns direct edges of the given kinds which lay immediately between the first group and second group of nodes.- Parameters:
first
-second
-edgeTags
-- Returns:
- the query expression
-
interactions
public static com.ensoftcorp.atlas.core.query.Q interactions(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... edgeTags)
Returns direct edges of the given kinds which lay immediately between the first group and second group of nodes.- Parameters:
context
-first
-second
-edgeTags
-- Returns:
- the query expression
-
interactions2
public static java.util.List<com.ensoftcorp.atlas.core.query.Q> interactions2(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String... tags)
For each Node in second, return a Q containing all Edges immediately incident on Nodes in first. Omit results which are empty.- Parameters:
context
- result is a subset of the contextfirst
-second
-tags
- edges with at least one of the given tags- Returns:
- list of one Q per Node in second which has some incidence to Nodes in first
-
libraryDeclarations
public static com.ensoftcorp.atlas.core.query.Q libraryDeclarations()
Returns those nodes which are declared by a library.- Returns:
- the query expression
-
libraryDeclarations
public static com.ensoftcorp.atlas.core.query.Q libraryDeclarations(com.ensoftcorp.atlas.core.query.Q context)
Returns those nodes which are declared by a library. Results are only returned if they are within the given context. Equivalent to libraryDeclarations(universe())- Parameters:
context
-- Returns:
- the query expression
-
libraryDeclarations
public static com.ensoftcorp.atlas.core.query.Q libraryDeclarations(java.lang.String name)
Returns those nodes which are declared by a library with the given name.- Parameters:
name
-- Returns:
- the query expression
-
libraryDeclarations
public static com.ensoftcorp.atlas.core.query.Q libraryDeclarations(com.ensoftcorp.atlas.core.query.Q context, java.lang.String name)
Returns those nodes which are declared by a library with the given name. Results are only returned if they are within the given context. Equivalent to libraryDeclarations(universe(), name)- Parameters:
context
-name
-- Returns:
- the query expression
-
nodesContaining
public static com.ensoftcorp.atlas.core.query.Q nodesContaining(java.lang.String substring)
Returns the nodes whose names contain the given string. Equivalent to nodesContaining(universe(), substring).- Parameters:
substring
-- Returns:
- the query expression
-
nodesContaining
public static com.ensoftcorp.atlas.core.query.Q nodesContaining(com.ensoftcorp.atlas.core.query.Q context, java.lang.String substring)
Returns the nodes whose names contain the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesEndingWith
public static com.ensoftcorp.atlas.core.query.Q nodesEndingWith(java.lang.String suffix)
Returns the nodes whose names end with the given string. Equivalent to nodesEndingWith(universe(), suffix).- Parameters:
substring
-- Returns:
- the query expression
-
nodesEndingWith
public static com.ensoftcorp.atlas.core.query.Q nodesEndingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String suffix)
Returns the nodes whose names end with the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesMatchingRegex
public static com.ensoftcorp.atlas.core.query.Q nodesMatchingRegex(java.lang.String regex)
Returns the nodes whose names match the given regular expression. Equivalent to nodesMatchingRegex(universe(), regex).- Parameters:
substring
-- Returns:
- the query expression
-
nodesStartingWith
public static com.ensoftcorp.atlas.core.query.Q nodesStartingWith(java.lang.String prefix)
Returns the nodes whose names start with the given string. Equivalent to nodesStartingWith(universe(), prefix).- Parameters:
substring
-- Returns:
- the query expression
-
nodesStartingWith
public static com.ensoftcorp.atlas.core.query.Q nodesStartingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String prefix)
Returns the nodes whose names start with the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesMatchingRegex
public static com.ensoftcorp.atlas.core.query.Q nodesMatchingRegex(com.ensoftcorp.atlas.core.query.Q context, java.lang.String regex)
Returns the nodes whose names match the given regular expression within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesAttributeValuesContaining
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesContaining(java.lang.String attribute, java.lang.String substring)
Returns the nodes whose attribute values contain the given string. Equivalent to nodesAttributeValuesContaining(universe(), attribute, substring).- Parameters:
substring
-- Returns:
- the query expression
-
nodesAttributeValuesContaining
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesContaining(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String substring)
Returns the nodes whose attribute values contain the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesAttributeValuesEndingWith
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesEndingWith(java.lang.String attribute, java.lang.String suffix)
Returns the nodes whose attribute values end with the given string. Equivalent to nodesAttributeValuesEndingWith(universe(), attribute, suffix).- Parameters:
substring
-- Returns:
- the query expression
-
nodesAttributeValuesEndingWith
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesEndingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String suffix)
Returns the nodes whose attribute values end with the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesAttributeValuesMatchingRegex
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesMatchingRegex(java.lang.String attribute, java.lang.String regex)
Returns the nodes whose attribute values match the given regular expression. Equivalent to nodesAttributeValuesMatchingRegex(universe(), attribute, regex).- Parameters:
substring
-- Returns:
- the query expression
-
nodesAttributeValuesStartingWith
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesStartingWith(java.lang.String attribute, java.lang.String prefix)
Returns the nodes whose attribute values start with the given string. Equivalent to nodesAttributeValuesStartingWith(universe(), attribute, prefix).- Parameters:
substring
-- Returns:
- the query expression
-
nodesAttributeValuesStartingWith
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesStartingWith(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String prefix)
Returns the nodes whose attribute values start with the given string within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
nodesAttributeValuesMatchingRegex
public static com.ensoftcorp.atlas.core.query.Q nodesAttributeValuesMatchingRegex(com.ensoftcorp.atlas.core.query.Q context, java.lang.String attribute, java.lang.String regex)
Returns the nodes whose attribute values match the given regular expression within the given context.- Parameters:
context
-substring
-- Returns:
- the query expression
-
edgeSize
public static long edgeSize(com.ensoftcorp.atlas.core.query.Q toCount)
Returns the number of edges contained.- Parameters:
toCount
-- Returns:
-
nodeSize
public static long nodeSize(com.ensoftcorp.atlas.core.query.Q toCount)
Returns the number of nodes contained.- Parameters:
toCount
-- Returns:
-
isEmpty
public static boolean isEmpty(com.ensoftcorp.atlas.core.query.Q test)
Returns whether the given Q is empty.- Parameters:
test
-- Returns:
-
isNotEmpty
public static boolean isNotEmpty(com.ensoftcorp.atlas.core.query.Q test)
Returns whether the given Q is not empty- Parameters:
test
-- Returns:
-
functions
public static com.ensoftcorp.atlas.core.query.Q functions(java.lang.String... functionNames)
Returns the set of functions where their names matches the any of the names given (functionNames) list. A (*) in (functionNames) represents a wildcard that matches any string.- Parameters:
functionNames
- : A list of function names as Strings- Returns:
- A set of functions
-
globals
public static com.ensoftcorp.atlas.core.query.Q globals(java.lang.String... names)
Returns the nodes representing the global variable(s) given by the parameter list (names). A (*) in any string in the list (names) represents a wildcard that matches any string.- Parameters:
names
- : A list of global variable names as Strings- Returns:
- A set of global variable nodes
-
types
public static com.ensoftcorp.atlas.core.query.Q types(java.lang.String... names)
Returns the nodes representing the types given by the names. A (*) is a wildcard that matches any string.- Parameters:
names
- A list of type names- Returns:
- A set of global variable nodes
-
getGraphElementByAddress
public static com.ensoftcorp.atlas.core.db.graph.GraphElement getGraphElementByAddress(java.lang.String address)
Selects the Atlas graph element given a serialized graph element address Returns null if the address does not correspond to a graph element- Parameters:
address
-- Returns:
-
getNodeByAddress
public static com.ensoftcorp.atlas.core.db.graph.Node getNodeByAddress(java.lang.String address)
Selects the Atlas node graph element given a serialized graph element address Returns null if the address does not correspond to a node- Parameters:
address
-- Returns:
-
getEdgeByAddress
public static com.ensoftcorp.atlas.core.db.graph.Edge getEdgeByAddress(java.lang.String address)
Selects the Atlas edge graph element given a serialized graph element address Returns null if the address does not correspond to a edge- Parameters:
address
-- Returns:
-
functionParameter
public static com.ensoftcorp.atlas.core.query.Q functionParameter(com.ensoftcorp.atlas.core.query.Q functions)
Returns the parameters of the given functions. Equivalent to functionParameter(universe(), functions)- Parameters:
functions
-- Returns:
- the query expression
-
functionParameter
public static com.ensoftcorp.atlas.core.query.Q functionParameter(com.ensoftcorp.atlas.core.query.Q functions, java.lang.Integer... index)
Returns the parameters of the given functions at the given indices. Equivalent to functionParameter(universe(), functions, index)- Parameters:
functions
-index
-- Returns:
- the query expression
-
functionParameter
public static com.ensoftcorp.atlas.core.query.Q functionParameter(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
Returns the parameters of the given functions. Results are only returned if they are within the given context.- Parameters:
context
-functions
-- Returns:
- the query expression
-
functionParameter
public static com.ensoftcorp.atlas.core.query.Q functionParameter(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions, java.lang.Integer... index)
Returns the parameters of the given functions at the given indices. Results are only returned if they are within the given context.- Parameters:
context
-functions
-index
-- Returns:
- the query expression
-
functionReturn
public static com.ensoftcorp.atlas.core.query.Q functionReturn(com.ensoftcorp.atlas.core.query.Q functions)
Returns the return nodes for the given functions. Equivalent to functionReturn(universe(), functions).- Parameters:
functions
-- Returns:
- the query expression
-
functionReturn
public static com.ensoftcorp.atlas.core.query.Q functionReturn(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
Returns the return nodes for the given functions.- Parameters:
context
-functions
-- Returns:
- the query expression
-
functionsOf
public static com.ensoftcorp.atlas.core.query.Q functionsOf(com.ensoftcorp.atlas.core.query.Q types)
Returns the functions declared by the given types. Equivalent to functionsOf(universe(), types).- Parameters:
params
-- Returns:
- the query expression
-
functionsOf
public static com.ensoftcorp.atlas.core.query.Q functionsOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q types)
Returns the functions declared by the given types.- Parameters:
context
-types
-- Returns:
- the query expression
-
dfg
public static com.ensoftcorp.atlas.core.query.Q dfg(com.ensoftcorp.atlas.core.query.Q functions)
- Parameters:
functions
-- Returns:
- the data flow graph under the function
-
dfg
public static com.ensoftcorp.atlas.core.query.Q dfg(com.ensoftcorp.atlas.core.db.graph.Node function)
- Parameters:
function
-- Returns:
- the data flow graph under the function
-
cfg
public static com.ensoftcorp.atlas.core.query.Q cfg(com.ensoftcorp.atlas.core.query.Q functions)
- Parameters:
functions
-- Returns:
- the control flow graph under the function
-
cfg
public static com.ensoftcorp.atlas.core.query.Q cfg(com.ensoftcorp.atlas.core.db.graph.Node function)
- Parameters:
function
-- Returns:
- the control flow graph under the function
-
excfg
public static com.ensoftcorp.atlas.core.query.Q excfg(com.ensoftcorp.atlas.core.query.Q functions)
- Parameters:
functions
-- Returns:
- the control flow graph (including exceptional control flow) under the function
-
excfg
public static com.ensoftcorp.atlas.core.query.Q excfg(com.ensoftcorp.atlas.core.db.graph.Node function)
- Parameters:
function
-- Returns:
- the control flow graph (including exceptional control flow) under the function
-
localDeclarations
public static com.ensoftcorp.atlas.core.query.Q localDeclarations(com.ensoftcorp.atlas.core.query.Q functions)
All nodes declared under the given functions, but NOT declared under additional functions or types. Retrieves declarations of only this function. Results are only returned if they are within the given context.- Parameters:
functions
-- Returns:
-
localDeclarations
public static com.ensoftcorp.atlas.core.query.Q localDeclarations(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q functions)
All nodes declared under the given functions, but NOT declared under additional functions or types. Retrieves declarations of only this function. Results are only returned if they are within the given context.- Parameters:
context
-functions
-- Returns:
-
callers
public static com.ensoftcorp.atlas.core.query.Q callers(com.ensoftcorp.atlas.core.query.Q origin)
Returns the direct callers of the given functions. Operates in the index context.- Parameters:
origin
-- Returns:
-
callers
public static com.ensoftcorp.atlas.core.query.Q callers(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the direct callers of the given functions. Operates in the given context.- Parameters:
context
-origin
-- Returns:
-
called
public static com.ensoftcorp.atlas.core.query.Q called(com.ensoftcorp.atlas.core.query.Q origin)
Returns the subset of the given functions which are called. Operates in the index context.- Parameters:
origin
-- Returns:
-
called
public static com.ensoftcorp.atlas.core.query.Q called(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the subset of the given functions which are called. Results are only returned if they are within the given context.- Parameters:
context
-origin
-- Returns:
-
calledBy
public static com.ensoftcorp.atlas.core.query.Q calledBy(com.ensoftcorp.atlas.core.query.Q callers, com.ensoftcorp.atlas.core.query.Q called)
Returns the given functions which were called by the given callers. Operates in the index context.- Parameters:
callers
-called
-- Returns:
-
calledBy
public static com.ensoftcorp.atlas.core.query.Q calledBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q callers, com.ensoftcorp.atlas.core.query.Q called)
Returns the given functions which were called by the given callers. Results are only returned if they are within the given context.- Parameters:
context
-callers
-called
-- Returns:
-
firstDeclarator
public static com.ensoftcorp.atlas.core.query.Q firstDeclarator(com.ensoftcorp.atlas.core.query.Q declared, java.lang.String... declaratorTypes)
Returns the first declaring node of the given Q which is tagged with one of the given types. Operates in the index context.- Parameters:
declared
-declaratorTypes
-- Returns:
-
firstDeclarator
public static com.ensoftcorp.atlas.core.query.Q firstDeclarator(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q declared, java.lang.String... declaratorTypes)
Returns the first declaring node of the given Q which is tagged with one of the given types. Results are only returned if they are within the given context.- Parameters:
context
-declared
-declaratorTypes
-- Returns:
-
advancedIntersection
public static com.ensoftcorp.atlas.core.query.Q advancedIntersection(com.ensoftcorp.atlas.core.query.Q first, com.ensoftcorp.atlas.core.query.Q second, java.lang.String[] nodeTags, java.lang.String[] edgeTags)
Given two query expressions, intersects the given node and edge kinds to produce a new expression.- Parameters:
first
-second
-nodeTags
-edgeTags
-- Returns:
-
readersOf
public static com.ensoftcorp.atlas.core.query.Q readersOf(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly read from nodes in origin. Operates in the index context.- Parameters:
origin
-- Returns:
-
readersOf
public static com.ensoftcorp.atlas.core.query.Q readersOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly read from nodes in origin. Operates in the given context.- Parameters:
context
-origin
-- Returns:
-
writersOf
public static com.ensoftcorp.atlas.core.query.Q writersOf(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly write to nodes in origin. Operates in the index context.- Parameters:
origin
-- Returns:
-
writersOf
public static com.ensoftcorp.atlas.core.query.Q writersOf(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes which directly write to nodes in origin. Operates in the given context.- Parameters:
context
-origin
-- Returns:
-
readBy
public static com.ensoftcorp.atlas.core.query.Q readBy(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes from which nodes in the origin read. Operates in the index context.- Parameters:
origin
-- Returns:
-
readBy
public static com.ensoftcorp.atlas.core.query.Q readBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes from which nodes in the origin read. Operates in the given context.- Parameters:
context
-origin
-- Returns:
-
writtenBy
public static com.ensoftcorp.atlas.core.query.Q writtenBy(com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes to which nodes in origin write. Operates in the index context.- Parameters:
origin
-- Returns:
-
writtenBy
public static com.ensoftcorp.atlas.core.query.Q writtenBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the nodes to which nodes in origin write. Operates in the given context.- Parameters:
context
-origin
-- Returns:
-
syncPoints
public static com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> syncPoints(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> roots, com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> leaves, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns points where there are no competing branch points- Parameters:
roots
-leaves
-graph
-- Returns:
-
leastCommonAncestors
public static com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> leastCommonAncestors(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> children, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common children of of the given parents within the given graph- Parameters:
child1
-child2
-graph
-- Returns:
-
leastCommonChildren
public static com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> leastCommonChildren(com.ensoftcorp.atlas.core.db.set.AtlasSet<com.ensoftcorp.atlas.core.db.graph.Node> parents, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common children of of the given parents within the given graph- Parameters:
child1
-child2
-graph
-- Returns:
-
leastCommonChild
public static com.ensoftcorp.atlas.core.db.graph.Node leastCommonChild(com.ensoftcorp.atlas.core.db.graph.Node parent1, com.ensoftcorp.atlas.core.db.graph.Node parent2, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common child of both parent1 and parent2 within the given graph- Parameters:
child1
-child2
-graph
-- Returns:
-
leastCommonChild
public static com.ensoftcorp.atlas.core.db.graph.Node leastCommonChild(com.ensoftcorp.atlas.core.db.graph.Node parent1, com.ensoftcorp.atlas.core.db.graph.Node parent2, com.ensoftcorp.atlas.core.query.Q graph)
Returns the least common ancestor of both parent1 and parent2 within the given graph- Parameters:
parent1
-parent2
-graph
-- Returns:
-
leastCommonAncestor
public static com.ensoftcorp.atlas.core.db.graph.Node leastCommonAncestor(com.ensoftcorp.atlas.core.db.graph.Node child1, com.ensoftcorp.atlas.core.db.graph.Node child2, com.ensoftcorp.atlas.core.db.graph.Graph graph)
Returns the least common ancestor of both child1 and child2 within the given graph- Parameters:
child1
-child2
-graph
-- Returns:
-
leastCommonAncestor
public static com.ensoftcorp.atlas.core.db.graph.Node leastCommonAncestor(com.ensoftcorp.atlas.core.db.graph.Node child1, com.ensoftcorp.atlas.core.db.graph.Node child2, com.ensoftcorp.atlas.core.query.Q graph)
Returns the least common ancestor of both child1 and child2 within the given graph- Parameters:
child1
-child2
-graph
-- Returns:
-
getContainingFunctions
public static com.ensoftcorp.atlas.core.query.Q getContainingFunctions(com.ensoftcorp.atlas.core.query.Q nodes)
Returns the containing function of a given Q or empty if one is not found- Parameters:
nodes
-- Returns:
-
getContainingControlFlowNode
public static com.ensoftcorp.atlas.core.db.graph.Node getContainingControlFlowNode(com.ensoftcorp.atlas.core.db.graph.Node node)
Returns the nearest parent that is a control flow node- Parameters:
node
-- Returns:
-
getContainingFunction
public static com.ensoftcorp.atlas.core.db.graph.Node getContainingFunction(com.ensoftcorp.atlas.core.db.graph.Node node)
Returns the containing function of a given graph element or null if one is not found- Parameters:
node
-- Returns:
-
getContainingNode
public static com.ensoftcorp.atlas.core.db.graph.Node getContainingNode(com.ensoftcorp.atlas.core.db.graph.Node node, java.lang.String containingTag)
Find the next immediate containing node with the given tag.- Parameters:
node
-containingTag
-- Returns:
- the next immediate containing node, or null if none exists; never returns the given node
-
isGoverningBranch
public static boolean isGoverningBranch(com.ensoftcorp.atlas.core.db.graph.Node branch, com.ensoftcorp.atlas.core.db.graph.Node event)
Given a function, a branch, and an event of interest returns true if the branch governs whether or not the event of interest could be executed. If true the branch could prevent the event from being executed. The branch and event must both be contained in the same function. This method does not consider exceptional control flow paths.- Parameters:
function
-branch
-event
-- Returns:
-
isGoverningBranch
public static boolean isGoverningBranch(com.ensoftcorp.atlas.core.db.graph.Node branch, com.ensoftcorp.atlas.core.db.graph.Node event, boolean includeExceptionalPaths)
Given a function, a branch, and an event of interest returns true if the branch governs whether or not the event of interest could be executed. If true the branch could prevent the event from being executed. The branch and event must both be contained in the same function.- Parameters:
branch
- An XCSG.ControlFlowCondition nodeevent
- An ControlFlow_Node nodeincludeExceptionalPaths
- If true considers exceptional control flow paths- Returns:
-
conditionsAbove
public static com.ensoftcorp.atlas.core.query.Q conditionsAbove(com.ensoftcorp.atlas.core.query.Q origin)
Returns the control flow graph between conditional nodes and the given origin. Operates within the index context.- Parameters:
origin
-- Returns:
-
conditionsAbove
public static com.ensoftcorp.atlas.core.query.Q conditionsAbove(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Returns the control flow graph between conditional nodes and the given origin. Operates within the given context.- Parameters:
context
-origin
-- Returns:
-
mutators
public static com.ensoftcorp.atlas.core.query.Q mutators(com.ensoftcorp.atlas.core.query.Q origin)
Given a Q containing functions or data flow nodes, returns a Q of things which write to or call things in the Q. Operates within the index context.- Parameters:
origin
-- Returns:
-
nodesWithSelfEdges
public static com.ensoftcorp.atlas.core.query.Q nodesWithSelfEdges(com.ensoftcorp.atlas.core.query.Q context)
Returns those nodes in the context which have self edges.- Parameters:
context
-- Returns:
-
mutators
public static com.ensoftcorp.atlas.core.query.Q mutators(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q origin)
Given a Q containing functions or data flow nodes, returns a Q of things which write to or call things in the Q. Operates within the index context.- Parameters:
context
-origin
-- Returns:
-
mutatedBy
public static com.ensoftcorp.atlas.core.query.Q mutatedBy(com.ensoftcorp.atlas.core.query.Q mutators, com.ensoftcorp.atlas.core.query.Q origin)
Returns those elements in the origin which were called by or written by elements in the mutators set. Operates within the index context.- Parameters:
mutators
-origin
-- Returns:
-
mutatedBy
public static com.ensoftcorp.atlas.core.query.Q mutatedBy(com.ensoftcorp.atlas.core.query.Q context, com.ensoftcorp.atlas.core.query.Q mutators, com.ensoftcorp.atlas.core.query.Q origin)
Returns those elements in the origin which were called by or written by elements in the mutators set. Operates within the given context.- Parameters:
context
-mutators
-origin
-- Returns:
-
getQualifiedTypeName
public static java.lang.String getQualifiedTypeName(com.ensoftcorp.atlas.core.db.graph.Node type)
Helper function to get the stringified qualified name of the class- Parameters:
type
-- Returns:
-
getQualifiedFunctionName
public static java.lang.String getQualifiedFunctionName(com.ensoftcorp.atlas.core.db.graph.Node function)
Helper function to get the stringified qualified name of the function- Parameters:
function
-- Returns:
-
getQualifiedName
public static java.lang.String getQualifiedName(com.ensoftcorp.atlas.core.db.graph.Node node)
Helper function to get the stringified qualified name of the function- Parameters:
function
-- Returns:
-
getQualifiedName
public static java.lang.String getQualifiedName(com.ensoftcorp.atlas.core.db.graph.Node node, java.lang.String... stopAfterTags)
Helper function to get the stringified qualified name of the class Stop after tags specify parent containers to stop qualifying at (example packages or jars)- Parameters:
node
-- Returns:
-
-