|
6 | 6 | [Parameter( Mandatory = $true )]
|
7 | 7 | [string]$PackagePath,
|
8 | 8 | [switch]$TreatUnsupportedAsPassed,
|
9 |
| - [switch]$FailInboxDrivers |
| 9 | + [switch]$FailInboxDrivers, |
| 10 | + [switch]$ParentNodeIsAnd |
10 | 11 | )
|
11 | 12 |
|
12 | 13 | $XMLTreeDepth++
|
13 | 14 | [DependencyParserState]$ParserState = 0
|
14 | 15 |
|
| 16 | + $i = 0 |
15 | 17 | foreach ($XMLTREE in $XMLIN) {
|
| 18 | + $i++ |
16 | 19 | Write-Debug "$('- ' * $XMLTreeDepth )|> Node: $($XMLTREE.SchemaInfo.Name)"
|
17 | 20 |
|
18 | 21 | if ($XMLTREE.SchemaInfo.Name -eq 'Not') {
|
19 | 22 | $ParserState = $ParserState -bxor 1
|
20 | 23 | Write-Debug "$('- ' * $XMLTreeDepth)Switched state to: $ParserState"
|
21 | 24 | }
|
22 | 25 |
|
23 |
| - $Result = if ($XMLTREE.SchemaInfo.Name -like "_*") { |
24 |
| - switch (Test-MachineSatisfiesDependency -Dependency $XMLTREE -PackagePath $PackagePath -DebugIndent $XMLTreeDepth -FailInboxDrivers:$FailInboxDrivers) { |
25 |
| - 0 { |
26 |
| - $true |
27 |
| - } |
28 |
| - -1 { |
29 |
| - $false |
30 |
| - } |
31 |
| - -2 { |
32 |
| - Write-Debug "$('- ' * $XMLTreeDepth)Something unsupported encountered in: $($XMLTREE.SchemaInfo.Name)" |
33 |
| - if ($TreatUnsupportedAsPassed) { $true } else { $false } |
| 26 | + $Result = switch -Wildcard ($XMLTREE.SchemaInfo.Name) { |
| 27 | + '_*' { |
| 28 | + switch (Test-MachineSatisfiesDependency -Dependency $XMLTREE -PackagePath $PackagePath -DebugIndent $XMLTreeDepth -FailInboxDrivers:$FailInboxDrivers) { |
| 29 | + 0 { |
| 30 | + $true |
| 31 | + } |
| 32 | + -1 { |
| 33 | + $false |
| 34 | + } |
| 35 | + -2 { |
| 36 | + Write-Debug "$('- ' * $XMLTreeDepth)Something unsupported encountered in: $($XMLTREE.SchemaInfo.Name)" |
| 37 | + if ($TreatUnsupportedAsPassed) { $true } else { $false } |
| 38 | + } |
34 | 39 | }
|
35 | 40 | }
|
36 |
| - } else { |
37 |
| - $SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers |
38 |
| - switch ($XMLTREE.SchemaInfo.Name) { |
39 |
| - 'And' { |
40 |
| - Write-Debug "$('- ' * $XMLTreeDepth)Tree was AND: Results: $subtreeresults" |
41 |
| - if ($subtreeresults -contains $false) { $false } else { $true } |
42 |
| - } |
43 |
| - default { |
44 |
| - Write-Debug "$('- ' * $XMLTreeDepth)Tree was OR: Results: $subtreeresults" |
45 |
| - if ($subtreeresults -contains $true ) { $true } else { $false } |
46 |
| - } |
| 41 | + 'And' { |
| 42 | + $SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers -ParentNodeIsAnd |
| 43 | + Write-Debug "$('- ' * $XMLTreeDepth)Tree was AND: Results: $SubtreeResults" |
| 44 | + if ($SubtreeResults -contains $false) { $false } else { $true } |
| 45 | + } |
| 46 | + default { |
| 47 | + $SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers |
| 48 | + Write-Debug "$('- ' * $XMLTreeDepth)Tree was OR: Results: $SubtreeResults" |
| 49 | + if ($SubtreeResults -contains $true ) { $true } else { $false } |
47 | 50 | }
|
48 | 51 | }
|
49 | 52 |
|
50 | 53 | Write-Debug "$('- ' * $XMLTreeDepth)< Returning $($Result -bxor $ParserState) from node $($XMLTREE.SchemaInfo.Name)"
|
51 | 54 |
|
52 | 55 | $Result -bxor $ParserState
|
| 56 | + |
| 57 | + # If we're evaluating the children of an And-node, and we get a negative result before the last child-element, |
| 58 | + # we can stop and don't have to process the remaining children anymore as the And-result will always be false. |
| 59 | + # This speeds things up but it can also avoid even running problematic tests, e.g. some ExternalDetections. |
| 60 | + if ($ParentNodeIsAnd -and $i -ne $XMLIN.Count -and -not ($Result -bxor $ParserState)) { |
| 61 | + Write-Debug "$('- ' * $XMLTreeDepth)Stopping AND evaluation early" |
| 62 | + $ParserState = 0 # DO_HAVE |
| 63 | + break; |
| 64 | + } |
53 | 65 | $ParserState = 0 # DO_HAVE
|
54 | 66 | }
|
55 | 67 |
|
|
0 commit comments