1library SimpleFC;
2
3uses
4  NSIS, Windows, FirewallControl, SysUtils;
5
6function ResultToStr(Value: Boolean): String;
7begin
8  if Value then
9    result := '0'
10  else
11    result := '1';
12end;
13
14function BoolToStr(Value: Boolean): String;
15begin
16  if Value then
17    result := '1'
18  else
19    result := '0';
20end;
21
22function StrToBool(Value: String): Boolean;
23begin
24  if Value = '1' then
25    result := True
26  else
27    result := False;
28end;
29
30procedure AddPort(const hwndParent: HWND; const string_size: integer;
31  const variables: PChar; const stacktop: pointer); cdecl;
32var
33  Port: Integer;
34  Name: String;
35  Protocol: NET_FW_IP_PROTOCOL;
36  Scope: NET_FW_SCOPE;
37  Enabled: Boolean;
38  IpVersion: NET_FW_IP_VERSION;
39  RemoteAddresses: String;
40  FirewallResult: String;
41begin
42  Init(hwndParent, string_size, variables, stacktop);
43
44  Port := StrToInt(PopString);
45  Name := PopString;
46  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
47  Scope := NET_FW_SCOPE(StrToInt(PopString));
48  IpVersion := NET_FW_IP_VERSION(StrToInt(PopString));
49  RemoteAddresses := PopString;
50  Enabled := StrToBool(PopString);
51
52  FirewallResult := ResultToStr(FirewallControl.AddPort(Port,
53                                                        Name,
54                                                        Protocol,
55                                                        Scope,
56                                                        IpVersion,
57                                                        RemoteAddresses,
58                                                        Enabled) = 0);
59  PushString(FirewallResult);
60end;
61
62procedure RemovePort(const hwndParent: HWND; const string_size: integer;
63  const variables: PChar; const stacktop: pointer); cdecl;
64var
65  Port: Integer;
66  Protocol: NET_FW_IP_PROTOCOL;
67  FirewallResult: String;
68begin
69  Init(hwndParent, string_size, variables, stacktop);
70
71  Port := StrToInt(PopString);
72  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
73
74  FirewallResult := ResultToStr(FirewallControl.RemovePort(Port, Protocol) = 0);
75  PushString(FirewallResult);
76end;
77
78procedure AddApplication(const hwndParent: HWND; const string_size: integer;
79  const variables: PChar; const stacktop: pointer); cdecl;
80var
81  Name: String;
82  BinaryPath: String;
83  IpVersion: NET_FW_IP_VERSION;
84  Scope: NET_FW_SCOPE;
85  RemoteAdresses: String;
86  Enabled: Boolean;
87  FirewallResult: String;
88begin
89  Init(hwndParent, string_size, variables, stacktop);
90
91  Name := PopString;
92  BinaryPath := PopString;
93  Scope := NET_FW_SCOPE(StrToInt(PopString));
94  IpVersion := NET_FW_IP_VERSION(StrToInt(PopString));
95  RemoteAdresses := PopString;
96  Enabled := StrToBool(PopString);
97
98  FirewallResult := ResultToStr(FirewallControl.AddApplication(Name,
99                                                               BinaryPath,
100                                                               Scope,
101                                                               IpVersion,
102                                                               RemoteAdresses,
103                                                               Enabled) = 0);
104  PushString(FirewallResult);
105end;
106
107procedure RemoveApplication(const hwndParent: HWND; const string_size: integer;
108  const variables: PChar; const stacktop: pointer); cdecl;
109var
110  BinaryPath: String;
111  FirewallResult: String;
112begin
113  Init(hwndParent, string_size, variables, stacktop);
114
115  BinaryPath := PopString;
116
117  FirewallResult := ResultToStr(FirewallControl.RemoveApplication(BinaryPath) = 0);
118  PushString(FirewallResult);
119end;
120
121procedure IsPortAdded(const hwndParent: HWND; const string_size: integer;
122  const variables: PChar; const stacktop: pointer); cdecl;
123var
124  Port: Integer;
125  Protocol: NET_FW_IP_PROTOCOL;
126  Added: Boolean;
127  FirewallResult: String;
128begin
129  Init(hwndParent, string_size, variables, stacktop);
130
131  Port := StrToInt(PopString);
132  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
133
134  FirewallResult := ResultToStr(FirewallControl.IsPortAdded(Port, Protocol, Added) = 0);
135  PushString(BoolToStr(Added));
136  PushString(FirewallResult);
137end;
138
139procedure IsApplicationAdded(const hwndParent: HWND; const string_size: integer;
140  const variables: PChar; const stacktop: pointer); cdecl;
141var
142  BinaryPath: String;
143  Added: Boolean;
144  FirewallResult: String;
145begin
146  Init(hwndParent, string_size, variables, stacktop);
147
148  BinaryPath := PopString;
149
150  FirewallResult := ResultToStr(FirewallControl.IsApplicationAdded(BinaryPath, Added) = 0);
151  PushString(BoolToStr(Added));
152  PushString(FirewallResult);
153end;
154
155procedure IsPortEnabled(const hwndParent: HWND; const string_size: integer;
156  const variables: PChar; const stacktop: pointer); cdecl;
157var
158  Port: Integer;
159  Protocol: NET_FW_IP_PROTOCOL;
160  Enabled: Boolean;
161  FirewallResult: String;
162begin
163  Init(hwndParent, string_size, variables, stacktop);
164
165  Port := StrToInt(PopString);
166  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
167
168  FirewallResult := ResultToStr(FirewallControl.IsPortEnabled(Port, Protocol, Enabled) = 0);
169  PushString(BoolToStr(Enabled));
170  PushString(FirewallResult);
171end;
172
173procedure IsApplicationEnabled(const hwndParent: HWND; const string_size: integer;
174  const variables: PChar; const stacktop: pointer); cdecl;
175var
176  BinaryPath: String;
177  Enabled: Boolean;
178  FirewallResult: String;
179begin
180  Init(hwndParent, string_size, variables, stacktop);
181
182  BinaryPath := PopString;
183
184  FirewallResult := ResultToStr(FirewallControl.IsApplicationEnabled(BinaryPath, Enabled) = 0);
185  PushString(BoolToStr(Enabled));
186  PushString(FirewallResult);
187end;
188
189procedure EnableDisablePort(const hwndParent: HWND; const string_size: integer;
190  const variables: PChar; const stacktop: pointer); cdecl;
191var
192  Port: Integer;
193  Protocol: NET_FW_IP_PROTOCOL;
194  Enabled: Boolean;
195  FirewallResult: String;
196begin
197  Init(hwndParent, string_size, variables, stacktop);
198
199  Port := StrToInt(PopString);
200  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
201  Enabled := StrToBool(PopString);
202
203  FirewallResult := ResultToStr(FirewallControl.EnableDisablePort(Port, Protocol, Enabled) = 0);
204  PushString(FirewallResult);
205end;
206
207procedure EnableDisableApplication(const hwndParent: HWND; const string_size: integer;
208  const variables: PChar; const stacktop: pointer); cdecl;
209var
210  BinaryPath: String;
211  Enabled: Boolean;
212  FirewallResult: String;
213begin
214  Init(hwndParent, string_size, variables, stacktop);
215
216  BinaryPath := PopString;
217  Enabled := StrToBool(PopString);
218
219  FirewallResult := ResultToStr(FirewallControl.EnableDisableApplication(BinaryPath, Enabled) = 0);
220  PushString(FirewallResult);
221end;
222
223procedure IsFirewallEnabled(const hwndParent: HWND; const string_size: integer;
224  const variables: PChar; const stacktop: pointer); cdecl;
225var
226  Enabled: Boolean;
227  FirewallResult: String;
228begin
229  Init(hwndParent, string_size, variables, stacktop);
230
231  FirewallResult := ResultToStr(FirewallControl.IsFirewallEnabled(Enabled) = 0);
232  PushString(BoolToStr(Enabled));
233  PushString(FirewallResult);
234end;
235
236procedure EnableDisableFirewall(const hwndParent: HWND; const string_size: integer;
237  const variables: PChar; const stacktop: pointer); cdecl;
238var
239  Enabled: Boolean;
240  FirewallResult: String;
241begin
242  Init(hwndParent, string_size, variables, stacktop);
243
244  Enabled := StrToBool(PopString);
245
246  FirewallResult := ResultToStr(FirewallControl.EnableDisableFirewall(Enabled) = 0);
247  PushString(FirewallResult);
248end;
249
250procedure AllowDisallowExceptionsNotAllowed(const hwndParent: HWND; const string_size: integer;
251  const variables: PChar; const stacktop: pointer); cdecl;
252var
253  NotAllowed: Boolean;
254  FirewallResult: String;
255begin
256  Init(hwndParent, string_size, variables, stacktop);
257
258  NotAllowed := StrToBool(PopString);
259
260  FirewallResult := ResultToStr(FirewallControl.AllowDisallowExceptionsNotAllowed(NotAllowed) = 0);
261  PushString(FirewallResult);
262end;
263
264procedure AreExceptionsNotAllowed(const hwndParent: HWND; const string_size: integer;
265  const variables: PChar; const stacktop: pointer); cdecl;
266var
267  NotAllowed: Boolean;
268  FirewallResult: String;
269begin
270  Init(hwndParent, string_size, variables, stacktop);
271
272  FirewallResult := ResultToStr(FirewallControl.AreExceptionsNotAllowed(NotAllowed) = 0);
273  PushString(BoolToStr(NotAllowed));
274  PushString(FirewallResult);
275end;
276
277procedure EnableDisableNotifications(const hwndParent: HWND; const string_size: integer;
278  const variables: PChar; const stacktop: pointer); cdecl;
279var
280  Enabled: Boolean;
281  FirewallResult: String;
282begin
283  Init(hwndParent, string_size, variables, stacktop);
284
285  Enabled := StrToBool(PopString);
286
287  FirewallResult := ResultToStr(FirewallControl.EnableDisableNotifications(Enabled) = 0);
288  PushString(BoolToStr(Enabled));
289  PushString(FirewallResult);
290end;
291
292procedure AreNotificationsEnabled(const hwndParent: HWND; const string_size: integer;
293  const variables: PChar; const stacktop: pointer); cdecl;
294var
295  Enabled: Boolean;
296  FirewallResult: String;
297begin
298  Init(hwndParent, string_size, variables, stacktop);
299
300  FirewallResult := ResultToStr(FirewallControl.AreNotificationsEnabled(Enabled) = 0);
301  PushString(BoolToStr(Enabled));
302  PushString(FirewallResult);
303end;
304
305procedure StartStopFirewallService(const hwndParent: HWND; const string_size: integer;
306  const variables: PChar; const stacktop: pointer); cdecl;
307var
308  Enabled: Boolean;
309  FirewallResult: String;
310begin
311  Init(hwndParent, string_size, variables, stacktop);
312
313  Enabled := StrToBool(PopString);
314
315  FirewallResult := ResultToStr(FirewallControl.StartStopFirewallService(Enabled));
316  PushString(FirewallResult);
317end;
318
319procedure IsFirewallServiceRunning(const hwndParent: HWND; const string_size: integer;
320  const variables: PChar; const stacktop: pointer); cdecl;
321var
322  IsRunning: Boolean;
323  FirewallResult: String;
324begin
325  Init(hwndParent, string_size, variables, stacktop);
326
327  FirewallResult := ResultToStr(FirewallControl.IsFirewallServiceRunning(IsRunning));
328  PushString(BoolToStr(IsRunning));
329  PushString(FirewallResult);
330end;
331
332procedure RestoreDefaults(const hwndParent: HWND; const string_size: integer;
333  const variables: PChar; const stacktop: pointer); cdecl;
334var
335  FirewallResult: String;
336begin
337  Init(hwndParent, string_size, variables, stacktop);
338
339  FirewallResult := ResultToStr(FirewallControl.RestoreDefaults = 0);
340  PushString(FirewallResult);
341end;
342
343procedure AllowDisallowIcmpOutboundDestinationUnreachable(const hwndParent: HWND; const string_size: integer;
344  const variables: PChar; const stacktop: pointer); cdecl;
345var
346  Allow: Boolean;
347  FirewallResult: String;
348begin
349  Init(hwndParent, string_size, variables, stacktop);
350
351  Allow := StrToBool(PopString);
352
353  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpOutboundDestinationUnreachable(Allow) = 0);
354  PushString(FirewallResult);
355end;
356
357procedure AllowDisallowIcmpRedirect(const hwndParent: HWND; const string_size: integer;
358  const variables: PChar; const stacktop: pointer); cdecl;
359var
360  Allow: Boolean;
361  FirewallResult: String;
362begin
363  Init(hwndParent, string_size, variables, stacktop);
364
365  Allow := StrToBool(PopString);
366
367  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpRedirect(Allow) = 0);
368  PushString(FirewallResult);
369end;
370
371procedure AllowDisallowIcmpInboundEchoRequest(const hwndParent: HWND; const string_size: integer;
372  const variables: PChar; const stacktop: pointer); cdecl;
373var
374  Allow: Boolean;
375  FirewallResult: String;
376begin
377  Init(hwndParent, string_size, variables, stacktop);
378
379  Allow := StrToBool(PopString);
380
381  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpInboundEchoRequest(Allow) = 0);
382  PushString(FirewallResult);
383end;
384
385procedure AllowDisallowIcmpOutboundTimeExceeded(const hwndParent: HWND; const string_size: integer;
386  const variables: PChar; const stacktop: pointer); cdecl;
387var
388  Allow: Boolean;
389  FirewallResult: String;
390begin
391  Init(hwndParent, string_size, variables, stacktop);
392
393  Allow := StrToBool(PopString);
394
395  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpOutboundTimeExceeded(Allow) = 0);
396  PushString(FirewallResult);
397end;
398
399procedure AllowDisallowIcmpOutboundParameterProblem(const hwndParent: HWND; const string_size: integer;
400  const variables: PChar; const stacktop: pointer); cdecl;
401var
402  Allow: Boolean;
403  FirewallResult: String;
404begin
405  Init(hwndParent, string_size, variables, stacktop);
406
407  Allow := StrToBool(PopString);
408
409  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpOutboundParameterProblem(Allow) = 0);
410  PushString(FirewallResult);
411end;
412
413procedure AllowDisallowIcmpOutboundSourceQuench(const hwndParent: HWND; const string_size: integer;
414  const variables: PChar; const stacktop: pointer); cdecl;
415var
416  Allow: Boolean;
417  FirewallResult: String;
418begin
419  Init(hwndParent, string_size, variables, stacktop);
420
421  Allow := StrToBool(PopString);
422
423  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpOutboundSourceQuench(Allow) = 0);
424  PushString(FirewallResult);
425end;
426
427procedure AllowDisallowIcmpInboundRouterRequest(const hwndParent: HWND; const string_size: integer;
428  const variables: PChar; const stacktop: pointer); cdecl;
429var
430  Allow: Boolean;
431  FirewallResult: String;
432begin
433  Init(hwndParent, string_size, variables, stacktop);
434
435  Allow := StrToBool(PopString);
436
437  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpInboundRouterRequest(Allow) = 0);
438  PushString(FirewallResult);
439end;
440
441procedure AllowDisallowIcmpInboundTimestampRequest(const hwndParent: HWND; const string_size: integer;
442  const variables: PChar; const stacktop: pointer); cdecl;
443var
444  Allow: Boolean;
445  FirewallResult: String;
446begin
447  Init(hwndParent, string_size, variables, stacktop);
448
449  Allow := StrToBool(PopString);
450
451  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpInboundTimestampRequest(Allow) = 0);
452  PushString(FirewallResult);
453end;
454
455procedure AllowDisallowIcmpInboundMaskRequest(const hwndParent: HWND; const string_size: integer;
456  const variables: PChar; const stacktop: pointer); cdecl;
457var
458  Allow: Boolean;
459  FirewallResult: String;
460begin
461  Init(hwndParent, string_size, variables, stacktop);
462
463  Allow := StrToBool(PopString);
464
465  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpInboundMaskRequest(Allow) = 0);
466  PushString(FirewallResult);
467end;
468
469procedure AllowDisallowIcmpOutboundPacketTooBig(const hwndParent: HWND; const string_size: integer;
470  const variables: PChar; const stacktop: pointer); cdecl;
471var
472  Allow: Boolean;
473  FirewallResult: String;
474begin
475  Init(hwndParent, string_size, variables, stacktop);
476
477  Allow := StrToBool(PopString);
478
479  FirewallResult := ResultToStr(FirewallControl.AllowDisallowIcmpOutboundPacketTooBig(Allow) = 0);
480  PushString(FirewallResult);
481end;
482
483procedure IsIcmpTypeAllowed(const hwndParent: HWND; const string_size: integer;
484  const variables: PChar; const stacktop: pointer); cdecl;
485var
486  IpVersion: NET_FW_IP_VERSION;
487  LocalAddress: String;
488  IcmpType: NET_FW_ICMP_TYPE;
489  Allowed: Boolean;
490  Restricted: Boolean;
491  FirewallResult: String;
492begin
493  Init(hwndParent, string_size, variables, stacktop);
494
495  IpVersion := NET_FW_IP_VERSION(StrToInt(PopString));
496  LocalAddress := PopString;
497  IcmpType := NET_FW_ICMP_TYPE(StrToInt(PopString));
498
499  FirewallResult := ResultToStr(FirewallControl.IsIcmpTypeAllowed(IpVersion,
500                                                                  LocalAddress,
501                                                                  IcmpType,
502                                                                  Allowed,
503                                                                  Restricted) = 0);
504  PushString(BoolToStr(Allowed));
505  PushString(BoolToStr(Restricted));
506  PushString(FirewallResult);
507end;
508
509procedure AdvAddRule(const hwndParent: HWND; const string_size: integer;
510  const variables: PChar; const stacktop: pointer); cdecl;
511var
512  Name: String;
513  Description: String;
514  Protocol: NET_FW_IP_PROTOCOL;
515  IcmpTypesAndCodes: String;
516  ApplicationName: String;
517  Direction: NET_FW_RULE_DIRECTION;
518  Enabled: Boolean;
519  Group: String;
520  Profile: NET_FW_PROFILE_TYPE2;
521  Action: NET_FW_ACTION;
522  LocalPorts: String;
523  RemotePorts: String;
524  LocalAddress: String;
525  RemoteAddress: String;
526  FirewallResult: String;
527begin
528  Init(hwndParent, string_size, variables, stacktop);
529
530  Name := PopString;
531  Description := PopString;
532  Protocol := NET_FW_IP_PROTOCOL(StrToInt(PopString));
533  Direction := NET_FW_RULE_DIRECTION(StrToInt(PopString));
534  Enabled := StrToBool(PopString);
535  Profile := NET_FW_PROFILE_TYPE2(StrToInt(PopString));
536  Action := NET_FW_ACTION(StrToInt(PopString));
537  ApplicationName := PopString;
538  IcmpTypesAndCodes := PopString;
539  Group := PopString;
540  LocalPorts := PopString;
541  RemotePorts := PopString;
542  LocalAddress := PopString;
543  RemoteAddress := PopString;
544
545  FirewallResult := ResultToStr(FirewallControl.AdvAddRule(Name,
546                                                           Description,
547                                                           Protocol,
548                                                           Direction,
549                                                           Enabled,
550                                                           Profile,
551                                                           Action,
552                                                           ApplicationName,
553                                                           IcmpTypesAndCodes,
554                                                           Group,
555                                                           LocalPorts,
556                                                           RemotePorts,
557                                                           LocalAddress,
558                                                           RemoteAddress) = 0);
559  PushString(FirewallResult);
560end;
561
562procedure AdvRemoveRule(const hwndParent: HWND; const string_size: integer;
563  const variables: PChar; const stacktop: pointer); cdecl;
564var
565  Name: String;
566  FirewallResult: String;
567begin
568  Init(hwndParent, string_size, variables, stacktop);
569
570  Name := PopString;
571
572  FirewallResult := ResultToStr(FirewallControl.AdvRemoveRule(Name) = 0);
573  PushString(FirewallResult);
574end;
575
576procedure AdvExistsRule(const hwndParent: HWND; const string_size: integer;
577  const variables: PChar; const stacktop: pointer); cdecl;
578var
579  Name: String;
580  Exists: Boolean;
581  FirewallResult: String;
582begin
583  Init(hwndParent, string_size, variables, stacktop);
584
585  Name := PopString;
586
587  FirewallResult := ResultToStr(FirewallControl.AdvExistsRule(Name, Exists) = 0);
588  PushString(BoolToStr(Exists));
589  PushString(FirewallResult);
590end;
591
592exports AddPort;
593exports RemovePort;
594exports AddApplication;
595exports RemoveApplication;
596exports IsPortAdded;
597exports IsApplicationAdded;
598exports IsPortEnabled;
599exports IsApplicationEnabled;
600exports EnableDisablePort;
601exports EnableDisableApplication;
602exports IsFirewallEnabled;
603exports EnableDisableFirewall;
604exports AllowDisallowExceptionsNotAllowed;
605exports AreExceptionsNotAllowed;
606exports EnableDisableNotifications;
607exports AreNotificationsEnabled;
608exports StartStopFirewallService;
609exports IsFirewallServiceRunning;
610exports RestoreDefaults;
611exports AllowDisallowIcmpOutboundDestinationUnreachable;
612exports AllowDisallowIcmpRedirect;
613exports AllowDisallowIcmpInboundEchoRequest;
614exports AllowDisallowIcmpOutboundTimeExceeded;
615exports AllowDisallowIcmpOutboundParameterProblem;
616exports AllowDisallowIcmpOutboundSourceQuench;
617exports AllowDisallowIcmpInboundRouterRequest;
618exports AllowDisallowIcmpInboundTimestampRequest;
619exports AllowDisallowIcmpInboundMaskRequest;
620exports AllowDisallowIcmpOutboundPacketTooBig;
621exports IsIcmpTypeAllowed;
622exports AdvAddRule;
623exports AdvRemoveRule;
624exports AdvExistsRule;
625
626end.
627