Skip to content

Commit 16084eb

Browse files
committed
Merge branch 'fail-and-eval-fast' into develop
2 parents 92c0615 + 2381f5a commit 16084eb

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

private/Invoke-PackageCommand.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@
115115
$process.StartInfo.WorkingDirectory = $WorkingDirectory
116116
$process.StartInfo.FileName = $Executable
117117
$process.StartInfo.Arguments = $Arguments
118+
$process.StartInfo.RedirectStandardInput = $true
118119
$process.StartInfo.RedirectStandardOutput = $true
119120
$process.StartInfo.RedirectStandardError = $true
120121

121122
if ($FallbackToShellExecute) {
122123
$process.StartInfo.UseShellExecute = $true
124+
$process.StartInfo.RedirectStandardInput = $false
123125
$process.StartInfo.RedirectStandardOutput = $false
124126
$process.StartInfo.RedirectStandardError = $false
125127
}
@@ -154,6 +156,8 @@
154156
# See issue #25 and https://stackoverflow.com/questions/11531068/powershell-capturing-standard-out-and-error-with-process-object
155157
$StdOutAsync = $process.StandardOutput.ReadToEndAsync()
156158
$StdErrAsync = $process.StandardError.ReadToEndAsync()
159+
# https://github.com/jantari/LSUClient/issues/103
160+
$process.StandardInput.Close()
157161
}
158162

159163
$process.WaitForExit()

private/Resolve-XMLDependencies.ps1

+35-23
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,62 @@
66
[Parameter( Mandatory = $true )]
77
[string]$PackagePath,
88
[switch]$TreatUnsupportedAsPassed,
9-
[switch]$FailInboxDrivers
9+
[switch]$FailInboxDrivers,
10+
[switch]$ParentNodeIsAnd
1011
)
1112

1213
$XMLTreeDepth++
1314
[DependencyParserState]$ParserState = 0
1415

16+
$i = 0
1517
foreach ($XMLTREE in $XMLIN) {
18+
$i++
1619
Write-Debug "$('- ' * $XMLTreeDepth )|> Node: $($XMLTREE.SchemaInfo.Name)"
1720

1821
if ($XMLTREE.SchemaInfo.Name -eq 'Not') {
1922
$ParserState = $ParserState -bxor 1
2023
Write-Debug "$('- ' * $XMLTreeDepth)Switched state to: $ParserState"
2124
}
2225

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+
}
3439
}
3540
}
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 }
4750
}
4851
}
4952

5053
Write-Debug "$('- ' * $XMLTreeDepth)< Returning $($Result -bxor $ParserState) from node $($XMLTREE.SchemaInfo.Name)"
5154

5255
$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+
}
5365
$ParserState = 0 # DO_HAVE
5466
}
5567

0 commit comments

Comments
 (0)