blob: c9478de157ee36dc958ea9017b4d5b53d7c23757 (
plain)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.Firewall
{
#if TODO_CONSIDER_DECOMPILER
using System;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using WixToolset.Data;
using WixToolset.Extensibility;
using Firewall = WixToolset.Extensions.Serialize.Firewall;
using Wix = WixToolset.Data.Serialize;
/// <summary>
/// The decompiler for the WiX Toolset Firewall Extension.
/// </summary>
public sealed class FirewallDecompiler : DecompilerExtension
{
/// <summary>
/// Creates a decompiler for Firewall Extension.
/// </summary>
public FirewallDecompiler()
{
this.TableDefinitions = FirewallExtensionData.GetExtensionTableDefinitions();
}
/// <summary>
/// Get the extensions library to be removed.
/// </summary>
/// <param name="tableDefinitions">Table definitions for library.</param>
/// <returns>Library to remove from decompiled output.</returns>
public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions)
{
return FirewallExtensionData.GetExtensionLibrary(tableDefinitions);
}
/// <summary>
/// Decompiles an extension table.
/// </summary>
/// <param name="table">The table to decompile.</param>
public override void DecompileTable(Table table)
{
switch (table.Name)
{
case "WixFirewallException":
this.DecompileWixFirewallExceptionTable(table);
break;
default:
base.DecompileTable(table);
break;
}
}
/// <summary>
/// Decompile the WixFirewallException table.
/// </summary>
/// <param name="table">The table to decompile.</param>
private void DecompileWixFirewallExceptionTable(Table table)
{
foreach (Row row in table.Rows)
{
Firewall.FirewallException fire = new Firewall.FirewallException();
fire.Id = (string)row[0];
fire.Name = (string)row[1];
string[] addresses = ((string)row[2]).Split(',');
if (1 == addresses.Length)
{
// special-case the Scope attribute values
if ("*" == addresses[0])
{
fire.Scope = Firewall.FirewallException.ScopeType.any;
}
else if ("LocalSubnet" == addresses[0])
{
fire.Scope = Firewall.FirewallException.ScopeType.localSubnet;
}
else
{
FirewallDecompiler.AddRemoteAddress(fire, addresses[0]);
}
}
else
{
foreach (string address in addresses)
{
FirewallDecompiler.AddRemoteAddress(fire, address);
}
}
if (!row.IsColumnEmpty(3))
{
fire.Port = (string)row[3];
}
if (!row.IsColumnEmpty(4))
{
switch (Convert.ToInt32(row[4]))
{
case FirewallConstants.NET_FW_IP_PROTOCOL_TCP:
fire.Protocol = Firewall.FirewallException.ProtocolType.tcp;
break;
case FirewallConstants.NET_FW_IP_PROTOCOL_UDP:
fire.Protocol = Firewall.FirewallException.ProtocolType.udp;
break;
}
}
if (!row.IsColumnEmpty(5))
{
fire.Program = (string)row[5];
}
if (!row.IsColumnEmpty(6))
{
int attr = Convert.ToInt32(row[6]);
if (0x1 == (attr & 0x1)) // feaIgnoreFailures
{
fire.IgnoreFailure = Firewall.YesNoType.yes;
}
}
if (!row.IsColumnEmpty(7))
{
switch (Convert.ToInt32(row[7]))
{
case FirewallConstants.NET_FW_PROFILE2_DOMAIN:
fire.Profile = Firewall.FirewallException.ProfileType.domain;
break;
case FirewallConstants.NET_FW_PROFILE2_PRIVATE:
fire.Profile = Firewall.FirewallException.ProfileType.@private;
break;
case FirewallConstants.NET_FW_PROFILE2_PUBLIC:
fire.Profile = Firewall.FirewallException.ProfileType.@public;
break;
case FirewallConstants.NET_FW_PROFILE2_ALL:
fire.Profile = Firewall.FirewallException.ProfileType.all;
break;
}
}
// Description column is new in v3.6
if (9 < row.Fields.Length && !row.IsColumnEmpty(9))
{
fire.Description = (string)row[9];
}
if (!row.IsColumnEmpty(10))
{
switch (Convert.ToInt32(row[10]))
{
case FirewallConstants.NET_FW_RULE_DIR_IN:
fire.Direction = Firewall.FirewallException.DirectionType.@in;
break;
case FirewallConstants.NET_FW_RULE_DIR_OUT:
fire.Direction = Firewall.FirewallException.DirectionType.@out;
break;
}
}
Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[8]);
if (null != component)
{
component.AddChild(fire);
}
else
{
this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[6], "Component"));
}
}
}
private static void AddRemoteAddress(Firewall.FirewallException fire, string address)
{
Firewall.RemoteAddress remote = new Firewall.RemoteAddress();
remote.Content = address;
fire.AddChild(remote);
}
}
#endif
}
|