diff options
Diffstat (limited to 'src/ext/Firewall/wixext/FirewallDecompiler.cs')
-rw-r--r-- | src/ext/Firewall/wixext/FirewallDecompiler.cs | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/src/ext/Firewall/wixext/FirewallDecompiler.cs b/src/ext/Firewall/wixext/FirewallDecompiler.cs new file mode 100644 index 00000000..c9478de1 --- /dev/null +++ b/src/ext/Firewall/wixext/FirewallDecompiler.cs | |||
@@ -0,0 +1,182 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.Firewall | ||
4 | { | ||
5 | #if TODO_CONSIDER_DECOMPILER | ||
6 | using System; | ||
7 | using System.Collections; | ||
8 | using System.Diagnostics; | ||
9 | using System.Globalization; | ||
10 | using WixToolset.Data; | ||
11 | using WixToolset.Extensibility; | ||
12 | using Firewall = WixToolset.Extensions.Serialize.Firewall; | ||
13 | using Wix = WixToolset.Data.Serialize; | ||
14 | |||
15 | /// <summary> | ||
16 | /// The decompiler for the WiX Toolset Firewall Extension. | ||
17 | /// </summary> | ||
18 | public sealed class FirewallDecompiler : DecompilerExtension | ||
19 | { | ||
20 | /// <summary> | ||
21 | /// Creates a decompiler for Firewall Extension. | ||
22 | /// </summary> | ||
23 | public FirewallDecompiler() | ||
24 | { | ||
25 | this.TableDefinitions = FirewallExtensionData.GetExtensionTableDefinitions(); | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Get the extensions library to be removed. | ||
30 | /// </summary> | ||
31 | /// <param name="tableDefinitions">Table definitions for library.</param> | ||
32 | /// <returns>Library to remove from decompiled output.</returns> | ||
33 | public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions) | ||
34 | { | ||
35 | return FirewallExtensionData.GetExtensionLibrary(tableDefinitions); | ||
36 | } | ||
37 | |||
38 | /// <summary> | ||
39 | /// Decompiles an extension table. | ||
40 | /// </summary> | ||
41 | /// <param name="table">The table to decompile.</param> | ||
42 | public override void DecompileTable(Table table) | ||
43 | { | ||
44 | switch (table.Name) | ||
45 | { | ||
46 | case "WixFirewallException": | ||
47 | this.DecompileWixFirewallExceptionTable(table); | ||
48 | break; | ||
49 | default: | ||
50 | base.DecompileTable(table); | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Decompile the WixFirewallException table. | ||
57 | /// </summary> | ||
58 | /// <param name="table">The table to decompile.</param> | ||
59 | private void DecompileWixFirewallExceptionTable(Table table) | ||
60 | { | ||
61 | foreach (Row row in table.Rows) | ||
62 | { | ||
63 | Firewall.FirewallException fire = new Firewall.FirewallException(); | ||
64 | fire.Id = (string)row[0]; | ||
65 | fire.Name = (string)row[1]; | ||
66 | |||
67 | string[] addresses = ((string)row[2]).Split(','); | ||
68 | if (1 == addresses.Length) | ||
69 | { | ||
70 | // special-case the Scope attribute values | ||
71 | if ("*" == addresses[0]) | ||
72 | { | ||
73 | fire.Scope = Firewall.FirewallException.ScopeType.any; | ||
74 | } | ||
75 | else if ("LocalSubnet" == addresses[0]) | ||
76 | { | ||
77 | fire.Scope = Firewall.FirewallException.ScopeType.localSubnet; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | FirewallDecompiler.AddRemoteAddress(fire, addresses[0]); | ||
82 | } | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | foreach (string address in addresses) | ||
87 | { | ||
88 | FirewallDecompiler.AddRemoteAddress(fire, address); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | if (!row.IsColumnEmpty(3)) | ||
93 | { | ||
94 | fire.Port = (string)row[3]; | ||
95 | } | ||
96 | |||
97 | if (!row.IsColumnEmpty(4)) | ||
98 | { | ||
99 | switch (Convert.ToInt32(row[4])) | ||
100 | { | ||
101 | case FirewallConstants.NET_FW_IP_PROTOCOL_TCP: | ||
102 | fire.Protocol = Firewall.FirewallException.ProtocolType.tcp; | ||
103 | break; | ||
104 | case FirewallConstants.NET_FW_IP_PROTOCOL_UDP: | ||
105 | fire.Protocol = Firewall.FirewallException.ProtocolType.udp; | ||
106 | break; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | if (!row.IsColumnEmpty(5)) | ||
111 | { | ||
112 | fire.Program = (string)row[5]; | ||
113 | } | ||
114 | |||
115 | if (!row.IsColumnEmpty(6)) | ||
116 | { | ||
117 | int attr = Convert.ToInt32(row[6]); | ||
118 | if (0x1 == (attr & 0x1)) // feaIgnoreFailures | ||
119 | { | ||
120 | fire.IgnoreFailure = Firewall.YesNoType.yes; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | if (!row.IsColumnEmpty(7)) | ||
125 | { | ||
126 | switch (Convert.ToInt32(row[7])) | ||
127 | { | ||
128 | case FirewallConstants.NET_FW_PROFILE2_DOMAIN: | ||
129 | fire.Profile = Firewall.FirewallException.ProfileType.domain; | ||
130 | break; | ||
131 | case FirewallConstants.NET_FW_PROFILE2_PRIVATE: | ||
132 | fire.Profile = Firewall.FirewallException.ProfileType.@private; | ||
133 | break; | ||
134 | case FirewallConstants.NET_FW_PROFILE2_PUBLIC: | ||
135 | fire.Profile = Firewall.FirewallException.ProfileType.@public; | ||
136 | break; | ||
137 | case FirewallConstants.NET_FW_PROFILE2_ALL: | ||
138 | fire.Profile = Firewall.FirewallException.ProfileType.all; | ||
139 | break; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | // Description column is new in v3.6 | ||
144 | if (9 < row.Fields.Length && !row.IsColumnEmpty(9)) | ||
145 | { | ||
146 | fire.Description = (string)row[9]; | ||
147 | } | ||
148 | |||
149 | if (!row.IsColumnEmpty(10)) | ||
150 | { | ||
151 | switch (Convert.ToInt32(row[10])) | ||
152 | { | ||
153 | case FirewallConstants.NET_FW_RULE_DIR_IN: | ||
154 | fire.Direction = Firewall.FirewallException.DirectionType.@in; | ||
155 | break; | ||
156 | case FirewallConstants.NET_FW_RULE_DIR_OUT: | ||
157 | fire.Direction = Firewall.FirewallException.DirectionType.@out; | ||
158 | break; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[8]); | ||
163 | if (null != component) | ||
164 | { | ||
165 | component.AddChild(fire); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[6], "Component")); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | private static void AddRemoteAddress(Firewall.FirewallException fire, string address) | ||
175 | { | ||
176 | Firewall.RemoteAddress remote = new Firewall.RemoteAddress(); | ||
177 | remote.Content = address; | ||
178 | fire.AddChild(remote); | ||
179 | } | ||
180 | } | ||
181 | #endif | ||
182 | } | ||