Skip to content

Commit 41f60d1

Browse files
committed
Added callout key.
1 parent 766c718 commit 41f60d1

4 files changed

Lines changed: 63 additions & 3 deletions

File tree

NtApiDotNet/Net/Firewall/FirewallUtils.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public static Guid GetKnownLayerGuid(string name)
147147
return NamedGuidDictionary.LayerGuids.Value.GuidFromName(name);
148148
}
149149

150+
/// <summary>
151+
/// Get a known callout GUID from its name.
152+
/// </summary>
153+
/// <param name="name">The name of the callout.</param>
154+
/// <returns>The known callout GUID.</returns>
155+
public static Guid GetKnownCalloutGuid(string name)
156+
{
157+
return NamedGuidDictionary.CalloutGuids.Value.GuidFromName(name);
158+
}
159+
150160
/// <summary>
151161
/// Get a list of known sub-layer names.
152162
/// </summary>
@@ -156,6 +166,15 @@ public static IEnumerable<string> GetKnownSubLayerNames()
156166
return NamedGuidDictionary.SubLayerGuids.Value.Values;
157167
}
158168

169+
/// <summary>
170+
/// Get a list of known callout names.
171+
/// </summary>
172+
/// <returns>The list of known callout names.</returns>
173+
public static IEnumerable<string> GetKnownCalloutNames()
174+
{
175+
return NamedGuidDictionary.CalloutGuids.Value.Values;
176+
}
177+
159178
/// <summary>
160179
/// Get a list of known sub-layer guids.
161180
/// </summary>

NtObjectManager/FirewallFunctions.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ $sublayer_completer = {
2222
[NtApiDotNet.Net.Firewall.FirewallUtils]::GetKnownSubLayerNames() | Where-Object { $_ -like "$wordToComplete*" }
2323
}
2424

25+
$callout_completer = {
26+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
27+
[NtApiDotNet.Net.Firewall.FirewallUtils]::GetKnownCalloutNames() | Where-Object { $_ -like "$wordToComplete*" }
28+
}
29+
2530
$Script:GlobalFwEngine = $null
2631

2732
function Get-FwEngineSingleton {
@@ -1393,7 +1398,7 @@ function Get-FwCallout {
13931398
param(
13941399
[NtApiDotNet.Net.Firewall.FirewallEngine]$Engine,
13951400
[parameter(Mandatory, ParameterSetName="FromKey")]
1396-
[Guid]$Key
1401+
[NtObjectManager.Utils.Firewall.FirewallCalloutGuid]$Key
13971402
)
13981403

13991404
try {
@@ -1404,10 +1409,12 @@ function Get-FwCallout {
14041409
$Engine.EnumerateCallouts() | Write-Output
14051410
}
14061411
"FromKey" {
1407-
$Engine.GetCallout($Key)
1412+
$Engine.GetCallout($Key.Id)
14081413
}
14091414
}
14101415
} catch {
14111416
Write-Error $_
14121417
}
1413-
}
1418+
}
1419+
1420+
Register-ArgumentCompleter -CommandName Get-FwCallout -ParameterName Key -ScriptBlock $callout_completer

NtObjectManager/NtObjectManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="Cmdlets\Win32\ClearAuthZSidCmdlet.cs" />
8282
<Compile Include="Cmdlets\Win32\GetWin32GrantedAccessCmdlet.cs" />
8383
<Compile Include="Cmdlets\Win32\SetWin32ServiceConfigCmdlet.cs" />
84+
<Compile Include="Utils\Firewall\FirewallCalloutGuid.cs" />
8485
<Compile Include="Utils\Firewall\FirewallLayerGuid.cs" />
8586
<Compile Include="Utils\Firewall\FirewallObjectGuid.cs" />
8687
<Compile Include="Utils\Firewall\FirewallPackageSid.cs" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Google LLC. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using NtApiDotNet.Net.Firewall;
16+
17+
namespace NtObjectManager.Utils.Firewall
18+
{
19+
/// <summary>
20+
/// Firewall callout GUID.
21+
/// </summary>
22+
public sealed class FirewallCalloutGuid : FirewallObjectGuid
23+
{
24+
/// <summary>
25+
/// Constructor.
26+
/// </summary>
27+
/// <param name="name">Name of the callout or a GUID</param>
28+
public FirewallCalloutGuid(string name)
29+
: base(name, FirewallUtils.GetKnownCalloutGuid)
30+
{
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)