-
Notifications
You must be signed in to change notification settings - Fork 17
/
Invoke-RegRipper.ps1
166 lines (137 loc) · 4.09 KB
/
Invoke-RegRipper.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
function Invoke-RegRipper()
{
[CmdletBinding(SupportsShouldProcess=$True)]
param(
[string]
$Hive,
[string]
$ComputerName,
[string]
$UserName,
[switch]
$Automatic,
[switch]
$Print,
[switch]
$List
)
DynamicParam
{
Get-DynamicFlowParamRR -Params $PSBoundParameters
}
Process
{
if ($Print)
{
write-verbose "Printing profile or plugins"
foreach ($p in $PSBoundParameters.Plugins)
{
write $p
get-content .\plugins\$p.pl
write ""
}
foreach ($p in ($PSBoundParameters.Profile))
{
get-content .\plugins\$p
write ""
}
return
}
elseif ($PSBoundParameters.Profile -or $PSBoundParameters.Plugins)
{
write-verbose "Run RR..."
foreach ($p in $PSBoundParameters.Plugins)
{
write "Processing hive $Hive using plugin $p"
& ".\rip.exe" -r $Hive -p $p
write ""
}
if ($PSBoundParameters.Profile)
{
write "Processing hive $Hive using profile $($PSBoundParameters.Profile)"
& ".\rip.exe" -r $Hive -f $PSBoundParameters.Profile
write ""
}
}
}
}
# Below is the code for the dynamic parameters for plugins
function Get-DynamicFlowParamRR()
{
$Dictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
New-DynamicParam -Name Plugins -type string[] -ValidateSet $(((gci .\plugins\*.pl).name) -replace "\.pl","") -DPDictionary $Dictionary
New-DynamicParam -Name Profile -type string -ValidateSet $(((gci .\plugins\* | ? {!($_.Extension)}).name)) -DPDictionary $Dictionary
$Dictionary
}
# Generic dynamic param function
Function New-DynamicParam ()
{
param(
[string]
$Name,
[System.Type]
$Type = [string],
[string[]]
$Alias = @(),
[string[]]
$ValidateSet,
[switch]
$Mandatory,
[string]
$ParameterSetName="__AllParameterSets",
[int]
$Position,
[switch]
$ValueFromPipelineByPropertyName,
[string]
$HelpMessage,
[validatescript({
if(-not ( $_ -is [System.Management.Automation.RuntimeDefinedParameterDictionary] -or -not $_) )
{
Throw "DPDictionary must be a System.Management.Automation.RuntimeDefinedParameterDictionary object, or not exist"
}
$True
})]
$DPDictionary = $false
)
$ParamAttr = New-Object System.Management.Automation.ParameterAttribute
$ParamAttr.ParameterSetName = $ParameterSetName
if($Mandatory)
{
$ParamAttr.Mandatory = $True
}
if($Position -ne $null)
{
$ParamAttr.Position=$Position
}
if($ValueFromPipelineByPropertyName)
{
$ParamAttr.ValueFromPipelineByPropertyName = $True
}
if($HelpMessage)
{
$ParamAttr.HelpMessage = $HelpMessage
}
$AttributeCollection = New-Object -type System.Collections.ObjectModel.Collection[System.Attribute]
$AttributeCollection.Add($ParamAttr)
if($ValidateSet)
{
$ParamOptions = New-Object System.Management.Automation.ValidateSetAttribute -ArgumentList $ValidateSet
$AttributeCollection.Add($ParamOptions)
}
if($Alias.count -gt 0) {
$ParamAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList $Alias
$AttributeCollection.Add($ParamAlias)
}
$Parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList @($Name, $Type, $AttributeCollection)
if($DPDictionary)
{
$DPDictionary.Add($Name, $Parameter)
}
else
{
$Dictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$Dictionary.Add($Name, $Parameter)
$Dictionary
}
}