You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#TODO: Refactor this now that I'm better at Powershell :)
78
57
# Build Services property. What a mess...but exclude non-open/non-open|filtered ports and blank service info, and exclude servicefp too for the sake of tidiness.
79
58
if ($_.state.state-like"open*"-and ($_.service.tunnel.length-gt2-or$_.service.product.length-gt2-or$_.service.proto.length-gt2)) {
#If strings were passed via pipeline, assume it is output from nmap XML which is multiple lines and coalesce them into one large document.
25
-
$InputObjectBundle+=$InputString
23
+
begin {
24
+
$xmlDocument= [Collections.ArrayList]@()
25
+
$hostEntry= [Collections.ArrayList]@()
26
26
}
27
27
28
-
end {
29
-
try {
30
-
[XML]$CombinedDocument=$InputObjectBundle
31
-
} catch [InvalidCastException] {
32
-
$exception= [System.Management.Automation.PSInvalidCastException]::New("The input provided is not valid XML. If you are piping from nmap, did you use 'nmap -oX -'?")
33
-
throwUser $exception
34
-
}
28
+
process {
29
+
#Unwrap $InputObject if it was passed as an array
30
+
foreach ($nmapLineItemin$inputObject) {
31
+
#If the output format is not PoshNmap, we will coalesce into a single document and process at the end, otherwise we will do it in real time for the pipeline
32
+
if ($OutFormat-ne'PoshNmap') {
33
+
$xmlDocument+=$nmapLineItem
34
+
#If this is a host entry, start capturing a host buffer
$exception= [System.Management.Automation.PSInvalidCastException]::New("The input provided is not valid XML. If you are piping from nmap, did you use 'nmap -oX -'?")
64
+
throwUser $exception
65
+
}
66
+
}
67
+
68
+
if (-not$xmlDocument.nmaprun) {
69
+
throwUser "The provided document is not a valid NMAP XML document (doesn't have an nmaprun element)"
49
70
}
50
71
72
+
$nmapRun=$xmlDocument.selectSingleNode('nmaprun')
73
+
51
74
switch ($OutFormat) {
52
75
'JSON' {
53
-
return$jsonResult
76
+
ConvertFromXml $nmapRun-AsJSON
54
77
}
55
78
'PSObject' {
56
-
return$jsonResult|ConvertFrom-Json
79
+
(ConvertFromXml $nmapRun).nmaprun
57
80
}
58
-
'HashTable' {
59
-
#TODO: PSCore Method, add as potential feature flag but for now use same method for both to avoid incompatibilities
0 commit comments