forked from nmap/npcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPcap-for-nmap.nsi
1220 lines (1030 loc) · 42.8 KB
/
NPcap-for-nmap.nsi
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; Custom winpcap for nmap
;; Recognizes the options (case sensitive):
;; /S silent install
;; /NPFSTARTUP=NO start NPF now and at startup (only has effect with /S)
;; Started by Doug Hoyte, April 2006
;; Eddie Bell
;; Updated to 4.0, June 2007
;; Updated to 4.01, July 2007
;; Updated to 4.02, November 2007
;; Rob Nicholls
;; Updated to 4.1.1, October 2009
;; Updated to 4.1.2, July 2010
;; Yang Luo
;; Updated to 4.1.3, August 2013
;; Yang Luo
;; Updated to 0.01, June 2015
;; Yang Luo
;; Updated to 0.02, July 2015
;; Yang Luo
;; Updated to 0.03, July 2015
;; Yang Luo
;; Updated to 0.04, August 2015
;; Yang Luo
;; Updated to 0.05, September 2015
;; Yang Luo
;; Updated to 0.06, March 2016
;; Yang Luo
;; Updated to 0.07, April 2016
SetCompressor /SOLID /FINAL lzma
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
!include "FileFunc.nsh"
!include "EnvVarUpdate.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
;--------------------------------
;General
; The version of Npcap
!define VERSION "0.07"
!define WIN_VERSION "5.0.7.424"
; The system restore point name created by Npcap installer
!define RESTORE_POINT_NAME_INSTALL "Before installation of Npcap ${VERSION}"
!define RESTORE_POINT_NAME_UNINSTALL "Before uninstallation of Npcap ${VERSION}"
; The name of the installer
Name "Npcap ${VERSION} (beta)"
; The file to write
OutFile "npcap-${VERSION}.exe"
Var /GLOBAL os_ver
Var /GLOBAL cmd_line
Var /GLOBAL admin_only
Var /GLOBAL winpcap_mode
Var /GLOBAL driver_name
Var /GLOBAL loopback_support
Var /GLOBAL dlt_null
Var /GLOBAL dot11_support
Var /GLOBAL vlan_support
Var /GLOBAL restore_point_success
RequestExecutionLevel admin
; These leave either "1" or "0" in $0.
Function is64bit
System::Call "kernel32::GetCurrentProcess() i .s"
System::Call "kernel32::IsWow64Process(i s, *i .r0)"
FunctionEnd
Function un.is64bit
System::Call "kernel32::GetCurrentProcess() i .s"
System::Call "kernel32::IsWow64Process(i s, *i .r0)"
FunctionEnd
VIProductVersion "${WIN_VERSION}"
VIAddVersionKey /LANG=1033 "FileVersion" "${VERSION}"
VIAddVersionKey /LANG=1033 "ProductName" "Npcap"
VIAddVersionKey /LANG=1033 "ProductVersion" "${VERSION}"
VIAddVersionKey /LANG=1033 "FileDescription" "Npcap ${VERSION} installer"
VIAddVersionKey /LANG=1033 "LegalCopyright" "Copyright 2016 Insecure.Com LLC ($\"The Nmap Project$\")"
;--------------------------------
; Windows API Definitions
!define SC_MANAGER_ALL_ACCESS 0x3F
!define SERVICE_ALL_ACCESS 0xF01FF
; Service Types
!define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
!define SERVICE_KERNEL_DRIVER 0x00000001
!define SERVICE_WIN32_OWN_PROCESS 0x00000010
!define SERVICE_WIN32_SHARE_PROCESS 0x00000020
!define SERVICE_INTERACTIVE_PROCESS 0x00000100
; Service start options
!define SERVICE_AUTO_START 0x00000002
!define SERVICE_BOOT_START 0x00000000
!define SERVICE_DEMAND_START 0x00000003
!define SERVICE_DISABLED 0x00000004
!define SERVICE_SYSTEM_START 0x00000001
; Service Error control
!define SERVICE_ERROR_CRITICAL 0x00000003
!define SERVICE_ERROR_IGNORE 0x00000000
!define SERVICE_ERROR_NORMAL 0x00000001
!define SERVICE_ERROR_SEVERE 0x00000002
; Service Control Options
!define SERVICE_CONTROL_STOP 0x00000001
!define SERVICE_CONTROL_PAUSE 0x00000002
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Logo
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "logo.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "logo.bmp"
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
Page custom adminOnlyOptionsPage doAdminOnlyOptions
; Don't let user choose where to install the files. WinPcap doesn't let people, and it's one less thing for us to worry about.
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
Page custom optionsPage doOptions
Page custom finalPage doFinal
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Reserves
ReserveFile "options_admin_only.ini"
ReserveFile "options.ini"
ReserveFile "final.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;--------------------------------
!insertmacro GetParameters
!insertmacro GetOptions
Function getInstallOptions
StrCpy $admin_only "no"
StrCpy $loopback_support "yes"
StrCpy $dlt_null "no"
StrCpy $dot11_support "no"
StrCpy $vlan_support "no"
StrCpy $winpcap_mode "no"
${GetParameters} $cmd_line ; $cmd_line = '/admin_only=no /loopback_support=yes /dlt_null=no /dot11_support=no /vlan_support=no /winpcap_mode=no'
${GetOptions} $cmd_line "/admin_only=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $admin_only $R0
${EndIf}
${GetOptions} $cmd_line "/loopback_support=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $loopback_support $R0
${EndIf}
${GetOptions} $cmd_line "/dlt_null=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $dlt_null $R0
${EndIf}
${GetOptions} $cmd_line "/dot11_support=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $dot11_support $R0
${EndIf}
${GetOptions} $cmd_line "/vlan_support=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $vlan_support $R0
${EndIf}
${GetOptions} $cmd_line "/winpcap_mode=" $R0
${If} $R0 S== "yes"
${OrIf} $R0 S== "no"
StrCpy $winpcap_mode $R0
${EndIf}
${If} $winpcap_mode == "no"
StrCpy $driver_name "npcap"
${Else}
StrCpy $driver_name "npf"
${EndIf}
FunctionEnd
; This function is called on startup. IfSilent checks
; if the flag /S was specified. If so, it sets the installer
; to run in "silent mode" which displays no windows and accepts
; all defaults.
; We also check if there is a previously installed winpcap
; on this system. If it's the same as the version we're installing,
; abort the install. If not, prompt the user about whether to
; replace it or not.
Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "options_admin_only.ini"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "options.ini"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "final.ini"
var /GLOBAL inst_ver
var /GLOBAL my_ver
var /GLOBAL npf_startup
StrCpy $my_ver "${WIN_VERSION}"
StrCpy $npf_startup "YES"
; Always use the requested /D= $INSTDIR if given.
StrCmp $INSTDIR "" "" instdir_nochange
; On 64-bit Windows, $PROGRAMFILES is "C:\Program Files (x86)" and
; $PROGRAMFILES64 is "C:\Program Files". We want "C:\Program Files"
; on 32-bit or 64-bit.
StrCpy $INSTDIR "$PROGRAMFILES\Npcap"
Call is64bit
StrCmp $0 "0" instdir_nochange
StrCpy $INSTDIR "$PROGRAMFILES64\Npcap"
instdir_nochange:
${GetParameters} $R0
ClearErrors
${GetOptions} $R0 "/NPFSTARTUP=" $npf_startup
IfSilent do_silent no_silent
do_silent:
SetSilent silent
Call getInstallOptions
IfFileExists "$INSTDIR\NPFInstall.exe" silent_checks
return
silent_checks:
; check for the presence of Nmap's custom WinPcapInst registry key:
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "InstalledBy"
StrCmp $0 "Nmap" silent_uninstall winpcap_installedby_keys_not_present
winpcap_installedby_keys_not_present:
; check for the presence of WinPcapInst's UninstallString
; and manually cleanup registry entries to avoid running
; the GUI uninstaller and assume our installer will overwrite
; the files. Needs to be checked in case someone (force)
; installs WinPcap over the top of our installation
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString"
StrCmp $0 "" winpcap_keys_not_present
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst"
ReadRegStr $0 "HKLM" "Software\Npcap" ""
StrCmp $0 "" winpcap_keys_not_present
Delete $0\rpcapd.exe
Delete $0\LICENSE
Delete $0\uninstall.exe
; Official 4.1 installer creates an install.log
Delete $0\install.log
RMDir "$0"
DeleteRegKey HKLM "Software\Npcap"
; because we've deleted their uninstaller, skip the next
; registry key check (we'll still need to overwrite stuff)
Goto winpcap-nmap_keys_not_present
winpcap_keys_not_present:
; if our old registry key is present then assume all is well
; (we got this far so the official WinPcap wasn't installed)
; and use our uninstaller to (magically) silently uninstall
; everything cleanly and avoid having to overwrite files
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\npcap-nmap" "UninstallString"
StrCmp $0 "" winpcap-nmap_keys_not_present silent_uninstall
winpcap-nmap_keys_not_present:
; setoverwrite on to try and avoid any problems when trying to install the files
; wpcap.dll is still present at this point, but unclear where it came from
SetOverwrite on
; try to ensure that npf has been stopped before we install/overwrite files
ExecWait '"net stop $driver_name"'
return
silent_uninstall:
; Our InstalledBy string is present, UninstallString should have quotes and uninstall.exe location
; and this file should support a silent uninstall by passing /S to it.
; we could read QuietUninstallString, but this should be exactly the same as UninstallString with /S on the end.
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString"
ExecWait '$0 /S _?=$INSTDIR'
return
no_silent:
IfFileExists "$INSTDIR\NPFInstall.exe" do_version_check
Call getInstallOptions
return
do_version_check:
GetDllVersion "$INSTDIR\NPFInstall.exe" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $inst_ver "$R2.$R3.$R4.$R5"
StrCmp $inst_ver $my_ver same_ver
MessageBox MB_YESNO|MB_ICONQUESTION "Npcap version $inst_ver exists on this system. Replace with version $my_ver?" IDYES try_uninstallers
quit
same_ver:
MessageBox MB_YESNO|MB_ICONQUESTION "Npcap version $inst_ver already exists on this system. Reinstall this version?" IDYES try_uninstallers
quit
try_uninstallers:
; check for UninstallString and use that in preference (should already have double quotes and uninstall.exe)
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString"
StrCmp $0 "" no_uninstallstring
IfFileExists "$0" uninstaller_exists no_uninstallstring
uninstaller_exists:
ExecWait '$0 _?=$INSTDIR'
; If the uninstaller fails, then quit the installation.
; ${If} ${FileExists} "$INSTDIR\NPFInstall.exe"
; quit
; ${EndIf}
return
no_uninstallstring:
; didn't find an UninstallString, check for our old UninstallString and if uninstall.exe exists:
ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\npcap-nmap" "UninstallString"
StrCmp $0 "" still_no_uninstallstring
IfFileExists "$0" old_uninstaller_exists still_no_uninstallstring
old_uninstaller_exists:
MessageBox MB_OK "Using our old UninstallString, file exists"
ExecWait '$0 _?=$INSTDIR'
; If the uninstaller fails, then quit the installation.
; ${If} ${FileExists} "$INSTDIR\NPFInstall.exe"
; quit
; ${EndIf}
return
still_no_uninstallstring:
; still didn't find anything, try looking for an uninstall.exe file at:
ReadRegStr $0 "HKLM" "Software\Npcap" ""
; Strip any surrounding double quotes from around the install string,
; as WinPcap hasn't used quotes in the past, but our old installers did.
; Check the first and last character for safety!
StrCpy $1 $0 1
StrCmp $1 "$\"" maybestripquotes nostrip
maybestripquotes:
StrLen $1 $0
IntOp $1 $1 - 1
StrCpy $1 $0 1 $1
StrCmp $1 "$\"" stripquotes nostrip
stripquotes:
StrCpy $0 $0 -1 1
nostrip:
IfFileExists "$0\uninstall.exe" run_last_uninstaller no_uninstall_exe
run_last_uninstaller:
ExecWait '"$0\Uninstall.exe" _?=$INSTDIR'
; If the uninstaller fails, then quit the installation.
; ${If} ${FileExists} "$INSTDIR\NPFInstall.exe"
; quit
; ${EndIf}
no_uninstall_exe:
; give up now, we've tried our hardest to determine a valid uninstaller!
return
FunctionEnd
Function adminOnlyOptionsPage
${If} $admin_only == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 1" "State" 0
${ElseIf} $admin_only == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 1" "State" 1
${EndIf}
${If} $loopback_support == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 2" "State" 0
${ElseIf} $loopback_support == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 2" "State" 1
${EndIf}
${If} $dlt_null == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 3" "State" 0
${ElseIf} $dlt_null == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 3" "State" 1
${EndIf}
${If} $dot11_support == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 4" "State" 0
${ElseIf} $dot11_support == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 4" "State" 1
${EndIf}
${If} $vlan_support == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 5" "State" 0
${ElseIf} $vlan_support == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 5" "State" 1
${EndIf}
${If} $winpcap_mode == "no"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 6" "State" 0
${ElseIf} $winpcap_mode == "yes"
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 6" "State" 1
${EndIf}
IfFileExists "$SYSDIR\wpcap.dll" winpcap_exist no_winpcap_exist
winpcap_exist:
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 7" "Text" "Npcap detected you have installed WinPcap, in order to Install Npcap \r\nin WinPcap API-compatible Mode, you must uninstall WinPcap first."
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 6" "State" 0
WriteINIStr "$PLUGINSDIR\options_admin_only.ini" "Field 6" "Flags" "DISABLED"
no_winpcap_exist:
!insertmacro MUI_HEADER_TEXT "Installation Options" "Please review the following options before installing Npcap ${VERSION}"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "options_admin_only.ini"
FunctionEnd
Function doAdminOnlyOptions
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Settings" "State"
${If} $0 == 2
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 2" "State"
${If} $0 == "0"
ReadINIStr $1 "$PLUGINSDIR\options_admin_only.ini" "Field 3" "HWND"
EnableWindow $1 0
${Else}
ReadINIStr $1 "$PLUGINSDIR\options_admin_only.ini" "Field 3" "HWND"
EnableWindow $1 1
${EndIf}
abort
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 1" "State"
${If} $0 == "0"
StrCpy $admin_only "no" ; by default
${Else}
StrCpy $admin_only "yes"
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 2" "State"
${If} $0 == "0"
StrCpy $loopback_support "no"
StrCpy $dlt_null "no" ; if even loopback feature is not enabled, there's no need to care whether it's DLT_NULL or not
${Else}
StrCpy $loopback_support "yes" ; by default
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 3" "State"
${If} $0 == "0"
StrCpy $dlt_null "no" ; by default
${Else}
StrCpy $dlt_null "yes"
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 4" "State"
${If} $0 == "0"
StrCpy $dot11_support "no" ; by default
${Else}
StrCpy $dot11_support "yes"
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 5" "State"
${If} $0 == "0"
StrCpy $vlan_support "no" ; by default
${Else}
StrCpy $vlan_support "yes"
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\options_admin_only.ini" "Field 6" "State"
${If} $0 == "0"
StrCpy $winpcap_mode "no" ; by default
StrCpy $driver_name "npcap" ; by default
${Else}
StrCpy $winpcap_mode "yes"
StrCpy $driver_name "npf"
${EndIf}
FunctionEnd
Function optionsPage
!insertmacro MUI_HEADER_TEXT "Driver Options" ""
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "options.ini"
FunctionEnd
Function doOptions
ReadINIStr $0 "$PLUGINSDIR\options.ini" "Field 1" "State"
StrCmp $0 "0" do_options_start do_options_end
do_options_start:
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Start" 3
do_options_end:
FunctionEnd
Function finalPage
; diplay a page saying everything's finished
!insertmacro MUI_HEADER_TEXT "Finished" "Thank you for installing Npcap"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "final.ini"
FunctionEnd
Function doFinal
; don't need to do anything
FunctionEnd
Function registerServiceAPI_xp_vista
; delete the npf service to avoid an error message later if it already exists
System::Call 'advapi32::OpenSCManagerA(,,i ${SC_MANAGER_ALL_ACCESS})i.r0'
System::Call 'advapi32::OpenServiceA(i r0,t "npf", i ${SERVICE_ALL_ACCESS}) i.r1'
System::Call 'advapi32::DeleteService(i r1) i.r6'
System::Call 'advapi32::CloseServiceHandle(i r1) n'
System::Call 'advapi32::CloseServiceHandle(i r0) n'
; create the new npf service
System::Call 'advapi32::OpenSCManagerA(,,i ${SC_MANAGER_ALL_ACCESS})i.R0'
System::Call 'advapi32::CreateServiceA(i R0,t "npf",t "NetGroup Packet Filter Driver",i ${SERVICE_ALL_ACCESS},i ${SERVICE_KERNEL_DRIVER}, i ${SERVICE_DEMAND_START},i ${SERVICE_ERROR_NORMAL}, t "system32\drivers\npf.sys",,,,,) i.r1'
StrCmp $1 "0" register_xp_vista_fail register_xp_vista_success
register_xp_vista_fail:
DetailPrint "Failed to create the npf service for XP"
IfSilent close_register_xp_vista_handle register_xp_vista_fail_messagebox
register_xp_vista_fail_messagebox:
MessageBox MB_OK "Failed to create the npf service for XP. Please try installing Npcap again, or use the official Npcap installer from https://github.com/nmap/npcap/releases"
Goto close_register_xp_vista_handle
register_xp_vista_success:
DetailPrint "The npf service for XP was successfully created"
close_register_xp_vista_handle:
System::Call 'advapi32::CloseServiceHandle(i R0) n'
FunctionEnd
Function un.registerServiceAPI_xp_vista
System::Call 'advapi32::OpenSCManagerA(,,i ${SC_MANAGER_ALL_ACCESS})i.r0'
System::Call 'advapi32::OpenServiceA(i r0,t "npf", i ${SERVICE_ALL_ACCESS}) i.r1'
System::Call 'advapi32::DeleteService(i r1) i.r6'
StrCmp $6 "0" unregister_xp_vista_fail unregister_xp_vista_success
unregister_xp_vista_fail:
DetailPrint "Failed to delete the npf service for XP"
Goto close_unregister_xp_vista_handle
unregister_xp_vista_success:
DetailPrint "The npf service for XP was successfully deleted"
close_unregister_xp_vista_handle:
System::Call 'advapi32::CloseServiceHandle(i r1) n'
System::Call 'advapi32::CloseServiceHandle(i r0) n'
FunctionEnd
Function registerServiceAPI_win7
; delete the npf service to avoid an error message later if it already exists
${If} $loopback_support == "yes"
; create the Npcap Loopback Adapter, used for capturing loopback packets
ExecWait '"$INSTDIR\NPFInstall.exe" -il'
${Endif}
; clear the driver cache in Driver Store
ExecWait '"$INSTDIR\NPFInstall.exe" -c' $0
DetailPrint "The cache in driver store was cleared"
; install the WFP callout driver
ExecWait '"$INSTDIR\NPFInstall.exe" -iw' $0
; install the NDIS filter driver
${If} $dot11_support == "yes"
ExecWait '"$INSTDIR\NPFInstall.exe" -i2' $0
${Else}
ExecWait '"$INSTDIR\NPFInstall.exe" -i' $0
${EndIf}
StrCmp $0 "0" register_win7_success register_win7_fail
register_win7_fail:
DetailPrint "Failed to create the npf service for Vista, Win7, Win8 and Win10"
IfSilent register_win7_done register_win7_fail_messagebox
register_win7_fail_messagebox:
MessageBox MB_OK "Failed to create the npcap service for Vista, Win7, Win8 and Win10. Please try installing Npcap again, or use the official Npcap installer from https://github.com/nmap/npcap/releases"
Goto register_win7_done
register_win7_success:
DetailPrint "The npf service for Vista, Win7, Win8 and Win10 was successfully created"
register_win7_done:
FunctionEnd
Function un.registerServiceAPI_win7
ExecWait '"$INSTDIR\NPFInstall.exe" -u' $0
ExecWait '"$INSTDIR\NPFInstall.exe" -uw' $0
ExecWait '"$INSTDIR\NPFInstall.exe" -ul' $0
StrCmp $0 "0" unregister_win7_success unregister_win7_fail
unregister_win7_fail:
DetailPrint "Failed to delete the npf service for Vista, Win7, Win8 and Win10"
Goto unregister_win7_done
unregister_win7_success:
DetailPrint "The npf service for Vista, Win7, Win8 and Win10 was successfully deleted"
unregister_win7_done:
FunctionEnd
Function autoStartWinPcap
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Start" 1
nsExec::Exec "net start $driver_name"
FunctionEnd
;--------------------------------
; The stuff to install
Section "WinPcap" SecWinPcap
; stop the service, in case it's still registered, so files can be
; safely overwritten and the service can be deleted.
nsExec::Exec "net stop $driver_name"
; NB: We may need to introduce a check here to ensure that NPF
; has been stopped before we continue, otherwise we Sleep for a
; while and try the check again. This might help prevent any race
; conditions during a silent install (and potentially during the
; slower GUI installation.
; Create the system restore point
StrCpy $restore_point_success "no"
DetailPrint "Start setting system restore point: ${RESTORE_POINT_NAME_INSTALL}"
SysRestore::StartRestorePoint /NOUNLOAD "${RESTORE_POINT_NAME_INSTALL}"
Pop $0
${If} $0 != 0
DetailPrint "Error occured when starting setting system restore point, return value=|$0|"
${Else}
StrCpy $restore_point_success "yes"
${Endif}
; These x86 files are automatically redirected to the right place on x64
${If} $winpcap_mode == "yes"
SetOutPath $SYSDIR
${Else}
SetOutPath $SYSDIR\Npcap
${EndIf}
File pthreadVC.dll
File wpcap.dll
File win8_above\x86\NPcapHelper.exe
File win8_above\x86\WlanHelper.exe
; Check windows version
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
StrCpy $R1 $R0 2
${If} $R1 == "6."
${If} $R0 == "6.0"
StrCpy $os_ver 'vista'
${ElseIf} $R0 == "6.1"
StrCpy $os_ver 'win7'
${Else}
StrCpy $os_ver 'win8_above'
${EndIf}
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x86\Packet.dll
${Else}
File win8_above\x86\Packet.dll
${EndIf}
DetailPrint "Windows CurrentVersion: $R0 ($os_ver)"
Call is64bit
StrCmp $0 "0" install_win7_32bit install_win7_64bit
${Else} ; xp_files:
StrCpy $os_ver 'xp'
File nt5\x86\Packet.dll
DetailPrint "Windows CurrentVersion: $R0 ($os_ver)"
Call is64bit
StrCmp $0 "0" install_xp_32bit install_xp_64bit
${EndIf}
; Note, NSIS states: "You should always quote the path to make sure spaces
; in the path will not disrupt Windows to find the uninstaller."
; See: http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs
; This matches (most) Windows installations. Rather inconsistently,
; DisplayIcon doesn't usually have quotes (even on Microsoft installations) and
; HKLM Software\PackageName doesn't usually have quotes either.
install_xp_32bit:
SetOutPath $INSTDIR
File rpcapd.exe
File ..\LICENSE
WriteUninstaller "$INSTDIR\uninstall.exe"
DetailPrint "Installing NDIS5.0 x86 driver for XP"
SetOutPath $SYSDIR\drivers
File npf.sys ; x86 NT5/NT6.0 version
WriteRegStr HKLM "Software\Npcap" "" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayIcon" "$INSTDIR\uninstall.exe"
Goto npfdone
install_win7_32bit:
SetOutPath $INSTDIR
File rpcapd.exe
File ..\LICENSE
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x86\NPFInstall.exe
${Else}
File win8_above\x86\NPFInstall.exe
${EndIf}
${If} $os_ver == "vista"
${If} $winpcap_mode == "yes"
File vista_winpcap\x86\npf.sys
File vista_winpcap\x86\npf.inf
File vista_winpcap\x86\npf_wfp.inf
File vista_winpcap\x86\npf_wifi.inf
File vista_winpcap\x86\npf.cat
${Else}
File vista\x86\npcap.sys
File vista\x86\npcap.inf
File vista\x86\npcap_wfp.inf
File vista\x86\npcap_wifi.inf
File vista\x86\npcap.cat
${EndIf}
${ElseIf} $os_ver == "win7"
${If} $winpcap_mode == "yes"
File win7_winpcap\x86\npf.sys
File win7_winpcap\x86\npf.inf
File win7_winpcap\x86\npf_wfp.inf
File win7_winpcap\x86\npf_wifi.inf
File win7_winpcap\x86\npf.cat
${Else}
File win7\x86\npcap.sys
File win7\x86\npcap.inf
File win7\x86\npcap_wfp.inf
File win7\x86\npcap_wifi.inf
File win7\x86\npcap.cat
${EndIf}
${Else} ; $os_ver == "win8_above"
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x86\npf.sys
File win8_above_winpcap\x86\npf.inf
File win8_above_winpcap\x86\npf_wfp.inf
File win8_above_winpcap\x86\npf_wifi.inf
File win8_above_winpcap\x86\npf.cat
${Else}
File win8_above\x86\npcap.sys
File win8_above\x86\npcap.inf
File win8_above\x86\npcap_wfp.inf
File win8_above\x86\npcap_wifi.inf
File win8_above\x86\npcap.cat
${EndIf}
${EndIf}
WriteUninstaller "$INSTDIR\uninstall.exe"
DetailPrint "Installing NDIS6.x x86 driver for Vista, Win7, Win8 and Win10"
SetOutPath $SYSDIR\drivers
WriteRegStr HKLM "Software\Npcap" "" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayIcon" "$INSTDIR\uninstall.exe"
Goto npfdone
install_xp_64bit:
SetOutPath $INSTDIR
File rpcapd.exe
File ..\LICENSE
WriteUninstaller "$INSTDIR\uninstall.exe"
DetailPrint "Installing NDIS5.x x64 driver for XP"
SetOutPath $SYSDIR\drivers
; disable Wow64FsRedirection
System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
File x64\npf.sys ; x64 NT5/NT6.0 version
; The x86 versions of wpcap.dll and packet.dll are
; installed into the right place further above.
; install the 64-bit version of wpcap.dll into System32
${If} $winpcap_mode == "yes"
SetOutPath $SYSDIR
${Else}
SetOutPath $SYSDIR\Npcap
${EndIf}
File x64\wpcap.dll ; x64 NT5/NT6.0 version
; install the 64-bit version of packet.dll into System32
File nt5\x64\Packet.dll ; x64 XP/2003 version
WriteRegStr HKLM "Software\Npcap" "" "$INSTDIR"
; re-enable Wow64FsRedirection
System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayIcon" "$INSTDIR\uninstall.exe"
Goto npfdone
install_win7_64bit:
SetOutPath $INSTDIR
File rpcapd.exe
File ..\LICENSE
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x64\NPFInstall.exe
${Else}
File win8_above\x64\NPFInstall.exe
${EndIf}
${If} $os_ver == "vista"
${If} $winpcap_mode == "yes"
File vista_winpcap\x64\npf.sys
File vista_winpcap\x64\npf.inf
File vista_winpcap\x64\npf_wfp.inf
File vista_winpcap\x64\npf_wifi.inf
File vista_winpcap\x64\npf.cat
${Else}
File vista\x64\npcap.sys
File vista\x64\npcap.inf
File vista\x64\npcap_wfp.inf
File vista\x64\npcap_wifi.inf
File vista\x64\npcap.cat
${EndIf}
${ElseIf} $os_ver == "win7"
${If} $winpcap_mode == "yes"
File win7_winpcap\x64\npf.sys
File win7_winpcap\x64\npf.inf
File win7_winpcap\x64\npf_wfp.inf
File win7_winpcap\x64\npf_wifi.inf
File win7_winpcap\x64\npf.cat
${Else}
File win7\x64\npcap.sys
File win7\x64\npcap.inf
File win7\x64\npcap_wfp.inf
File win7\x64\npcap_wifi.inf
File win7\x64\npcap.cat
${EndIf}
${Else} ; $os_ver == "win8_above"
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x64\npf.sys
File win8_above_winpcap\x64\npf.inf
File win8_above_winpcap\x64\npf_wfp.inf
File win8_above_winpcap\x64\npf_wifi.inf
File win8_above_winpcap\x64\npf.cat
${Else}
File win8_above\x64\npcap.sys
File win8_above\x64\npcap.inf
File win8_above\x64\npcap_wfp.inf
File win8_above\x64\npcap_wifi.inf
File win8_above\x64\npcap.cat
${EndIf}
${EndIf}
WriteUninstaller "$INSTDIR\uninstall.exe"
DetailPrint "Installing NDIS6.x x64 driver for Vista, Win7, Win8 and Win10"
SetOutPath $SYSDIR\drivers
; disable Wow64FsRedirection
System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
; The x86 versions of wpcap.dll and packet.dll are
; installed into the right place further above.
; install the 64-bit version of wpcap.dll into System32
${If} $winpcap_mode == "yes"
SetOutPath $SYSDIR
${Else}
SetOutPath $SYSDIR\Npcap
${EndIf}
File win8_above\x64\NPcapHelper.exe
File win8_above\x64\WlanHelper.exe
File x64\wpcap.dll ; x64 NT5/NT6 version
; install the 64-bit version of packet.dll into System32
; install the NT6.0 above version (for Vista, Win7, Win8 and Win10)
${If} $winpcap_mode == "yes"
File win8_above_winpcap\x64\Packet.dll
${Else}
File win8_above\x64\Packet.dll
${EndIf}
WriteRegStr HKLM "Software\Npcap" "" "$INSTDIR"
; Packet.dll will read this option
${If} $admin_only == "yes"
WriteRegDWORD HKLM "Software\Npcap" "AdminOnly" 1 ; make "AdminOnly" = 1 only when "admin only" is chosen
${Else}
WriteRegDWORD HKLM "Software\Npcap" "AdminOnly" 0 ;
${EndIf}
; Wireshark will read this option
${If} $winpcap_mode == "yes"
WriteRegDWORD HKLM "Software\Npcap" "WinPcapCompatible" 1 ; make "WinPcapCompatible" = 1 only when "WinPcap API-compatible Mode" is chosen
${Else}
WriteRegDWORD HKLM "Software\Npcap" "WinPcapCompatible" 0 ;
${EndIf}
; re-enable Wow64FsRedirection
System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayIcon" "$INSTDIR\uninstall.exe"
npfdone:
; register the driver as a system service using Windows API calls
; this will work on Windows 2000 (that lacks sc.exe) and higher
StrCmp $os_ver 'vista' register_service_win7
StrCmp $os_ver 'win7' register_service_win7
StrCmp $os_ver 'win8_above' register_service_win7
;registerService_xp_vista:
Call registerServiceAPI_xp_vista
Goto registerdone
register_service_win7:
Call registerServiceAPI_win7
registerdone:
${If} $winpcap_mode == "no"
; Add "system32\Npcap" directory to PATH
DetailPrint "Adding DLL folder: $\"$SYSDIR\Npcap$\" to PATH environment variable"
; SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$SYSDIR\Npcap"
${EndIf}
; Create the default NPF startup setting of 1 (SERVICE_SYSTEM_START)
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Start" 1
; Npcap driver will read this option
${If} $admin_only == "yes"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "AdminOnly" 1 ; make "AdminOnly" = 1 only when "admin only" is chosen
${Else}
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "AdminOnly" 0
${Endif}
; Copy the "Loopback" option from software key to services key
ReadRegStr $0 HKLM "Software\Npcap" "Loopback"
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Loopback" $0
; Npcap driver will read this option
${If} $dlt_null == "yes"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "DltNull" 1 ; make "DltNull" = 1 only when "dlt null" is chosen
${Else}
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "DltNull" 0
${Endif}
${If} $dot11_support == "yes"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Dot11Support" 1 ; make "Dot11Support" = 1 only when "dot11 support" is chosen
${Else}
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "Dot11Support" 0
${Endif}
; Npcap driver will read this option
${If} $vlan_support == "yes"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "VlanSupport" 1 ; make "VlanSupport" = 1 only when "vlan support" is chosen
${Else}
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "VlanSupport" 0
${Endif}
; Wireshark will read this option
${If} $winpcap_mode == "yes"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "WinPcapCompatible" 1 ; make "WinPcapCompatible" = 1 only when "WinPcap API-compatible Mode" is chosen
${Else}
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\$driver_name" "WinPcapCompatible" 0 ;
${EndIf}
nsExec::Exec "net start $driver_name"
nsExec::Exec "net stop $driver_name"
nsExec::Exec "net start $driver_name"
; automatically start the service if performing a silent install, unless
; /NPFSTARTUP=NO was given.
IfSilent 0 skip_auto_start
StrCmp $npf_startup "NO" skip_auto_start
Call autoStartWinPcap
skip_auto_start:
; Write the rest of the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayName" "Npcap ${VERSION} for Nmap"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "Publisher" "Nmap Project"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "URLInfoAbout" "http://www.nmap.org"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "URLUpdateInfo" "http://www.nmap.org"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "VersionMajor" "0"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "VersionMinor" "1"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "InstalledBy" "Nmap"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NpcapInst" "NoRepair" 1
; delete our legacy winpcap-nmap keys if they still exist (e.g. official 4.0.2 force installed over our 4.0.2):
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\npcap-nmap"
; Close the system restore point
${If} $restore_point_success == "yes"
DetailPrint "Finish setting system restore point: ${RESTORE_POINT_NAME_INSTALL}"
SysRestore::FinishRestorePoint /NOUNLOAD
Pop $0