@@ -11,6 +11,9 @@ private import codeql.rust.internal.PathResolutionConsistency as PathResolutionC
1111private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
1212private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
1313private import codeql.rust.Concepts
14+ private import codeql.rust.Diagnostics
15+ private import codeql.rust.security.SensitiveData
16+ private import TaintReach
1417// import all query extensions files, so that all extensions of `QuerySink` are found
1518private import codeql.rust.security.CleartextLoggingExtensions
1619private import codeql.rust.security.SqlInjectionExtensions
@@ -72,3 +75,92 @@ int getTaintEdgesCount() {
7275 * Gets a count of the total number of query sinks in the database.
7376 */
7477int getQuerySinksCount ( ) { result = count ( QuerySink s ) }
78+
79+ class CrateElement extends Element {
80+ CrateElement ( ) {
81+ this instanceof Crate or
82+ this instanceof NamedCrate or
83+ this .( AstNode ) .getParentNode * ( ) = any ( Crate c ) .getModule ( )
84+ }
85+ }
86+
87+ /**
88+ * Gets summary statistics about individual elements in the database.
89+ */
90+ predicate elementStats ( string key , int value ) {
91+ key = "Elements extracted" and
92+ value = count ( Element e | not e instanceof Unextracted and not e instanceof CrateElement )
93+ or
94+ key = "Elements unextracted" and value = count ( Unextracted e )
95+ }
96+
97+ /**
98+ * Gets summary statistics about extraction.
99+ */
100+ predicate extractionStats ( string key , int value ) {
101+ key = "Extraction errors" and value = count ( ExtractionError e )
102+ or
103+ key = "Extraction warnings" and value = count ( ExtractionWarning w )
104+ or
105+ key = "Files extracted - total" and value = count ( ExtractedFile f | exists ( f .getRelativePath ( ) ) )
106+ or
107+ key = "Files extracted - with errors" and
108+ value =
109+ count ( ExtractedFile f |
110+ exists ( f .getRelativePath ( ) ) and not f instanceof SuccessfullyExtractedFile
111+ )
112+ or
113+ key = "Files extracted - without errors" and
114+ value = count ( SuccessfullyExtractedFile f | exists ( f .getRelativePath ( ) ) )
115+ or
116+ key = "Files extracted - without errors %" and
117+ value =
118+ ( count ( SuccessfullyExtractedFile f | exists ( f .getRelativePath ( ) ) ) * 100 ) /
119+ count ( ExtractedFile f | exists ( f .getRelativePath ( ) ) )
120+ or
121+ key = "Lines of code extracted" and value = getLinesOfCode ( )
122+ or
123+ key = "Lines of user code extracted" and value = getLinesOfUserCode ( )
124+ or
125+ key = "Macro calls - total" and value = count ( MacroCall mc )
126+ or
127+ key = "Macro calls - resolved" and value = count ( MacroCall mc | mc .hasExpanded ( ) )
128+ or
129+ key = "Macro calls - unresolved" and value = count ( MacroCall mc | not mc .hasExpanded ( ) )
130+ }
131+
132+ /**
133+ * Gets summary statistics about inconsistencies.
134+ */
135+ predicate inconsistencyStats ( string key , int value ) {
136+ key = "Inconsistencies - AST" and value = getTotalAstInconsistencies ( )
137+ or
138+ key = "Inconsistencies - Path resolution" and value = getTotalPathResolutionInconsistencies ( )
139+ or
140+ key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies ( )
141+ or
142+ key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies ( )
143+ }
144+
145+ /**
146+ * Gets summary statistics about taint.
147+ */
148+ predicate taintStats ( string key , int value ) {
149+ key = "Taint sources - active" and value = count ( ActiveThreatModelSource s )
150+ or
151+ key = "Taint sources - disabled" and
152+ value = count ( ThreatModelSource s | not s instanceof ActiveThreatModelSource )
153+ or
154+ key = "Taint sources - sensitive data" and value = count ( SensitiveData d )
155+ or
156+ key = "Taint edges - number of edges" and value = getTaintEdgesCount ( )
157+ or
158+ key = "Taint reach - nodes tainted" and value = getTaintedNodesCount ( )
159+ or
160+ key = "Taint reach - per million nodes" and value = getTaintReach ( ) .floor ( )
161+ or
162+ key = "Taint sinks - query sinks" and value = getQuerySinksCount ( )
163+ or
164+ key = "Taint sinks - cryptographic operations" and
165+ value = count ( Cryptography:: CryptographicOperation o )
166+ }
0 commit comments