; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Metasploit Framework"
!define PRODUCT_VERSION "3.2"
!define PRODUCT_PUBLISHER "Metasploit LLC"
!define PRODUCT_WEB_SITE "http://metasploit.com/framework/"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"


VIProductVersion "3.2.0.0"
VIAddVersionKey /LANG=1033 "ProductName" "Metasploit Framework"
VIAddVersionKey /LANG=1033 "Comments" "This is the official installer for Metasploit 3"
VIAddVersionKey /LANG=1033 "CompanyName" "Metasploit LLC"
VIAddVersionKey /LANG=1033 "LegalTrademarks" "Metasploit is a registered trademark of Metasploit LLC"
VIAddVersionKey /LANG=1033 "LegalCopyright" " Copyright (C) 2003-2008 Metasploit LLC"
VIAddVersionKey /LANG=1033 "FileDescription" "Metasploit 3 Windows Installer"
VIAddVersionKey /LANG=1033 "FileVersion" "3.2.0.0"

SetCompressor /SOLID lzma

Function ReconfigGTK
    Exec '"$INSTDIR\GTK\bin\reconfig.bat"'
FunctionEnd

Function LaunchMetasploit
    Exec '"$INSTDIR\bin\rubyw.exe" "$INSTDIR\bin\launcher.rb" framework msfgui'
FunctionEnd

Function SetEnv
    Push $4
  
;    FileOpen $4 "$INSTDIR\loader.cmd" w
;    FileWrite $4 "@echo off$\r$\n"
;    FileWrite $4 "Set INSTDIR=$INSTDIR$\r$\n"
;    FileWrite $4 "Set PATH=%INSTDIR%\bin;%INSTDIR%\tools;%PATH%$\r$\n"
;    FileWrite $4 "Set PATH=%INSTDIR%\GTK\bin;%INSTDIR%\GTK\lib;%PATH%$\r$\n"
;    FileWrite $4 'cd "$INSTDIR"$\r$\n'
;    FileWrite $4 "cmd /c start %1 %2 %3 %4 %5 %6$\r$\n"
;    FileClose $4 
    
    Pop $4
FunctionEnd

Function CreateReconfigGTK
    Push $4

    FileOpen $4 "$INSTDIR\GTK\bin\reconfig.bat" w
    FileWrite $4 "@echo off$\r$\n"
    FileWrite $4 "Set INSTDIR=$INSTDIR$\r$\n"
    FileWrite $4 "set PATH=%INSTDIR%\GTK\bin;%INSTDIR%\GTK\lib;%PATH%$\r$\n"
    FileWrite $4 '"$INSTDIR\GTK\bin\gdk-pixbuf-query-loaders.exe" > "$INSTDIR\GTK\etc\gtk-2.0\gdk-pixbuf.loaders"$\r$\n'
    FileWrite $4 '"$INSTDIR\GTK\bin\gtk-query-immodules-2.0.exe" > "$INSTDIR\GTK\etc\gtk-2.0\gtk.immodules"$\r$\n'
    FileWrite $4 '"$INSTDIR\GTK\bin\pango-querymodules.exe" > "$INSTDIR\GTK\etc\pango\pango.modules"$\r$\n'
    FileClose $4 	

    Pop $4
FunctionEnd


; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Launch the Metasploit Framework"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchMetasploit"

; Welcome page
!insertmacro MUI_PAGE_WELCOME

; License page
!insertmacro MUI_PAGE_LICENSE "metasploit_license.txt"

; Directory page
!insertmacro MUI_PAGE_DIRECTORY

; Start menu page
var ICONS_GROUP
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Metasploit 3"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP

; Instfiles page
!insertmacro MUI_PAGE_INSTFILES

; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "framework-3.2.exe"
InstallDir "$PROGRAMFILES\Metasploit\Framework3"
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SecCore
        SetOutPath $INSTDIR
	Call SetEnv
       File /r "C:\Dev\Framework3\*.*"
SectionEnd

Section "GTK" SecGTK
	Call CreateReconfigGTK
	Call ReconfigGTK
SectionEnd

Section "Nmap" SecNmap
	MessageBox MB_YESNO \
		"Would you like to install the Nmap Security Scanner v4.76? Nmap is a free and open source \
		utility for network exploration and security auditing. The Metasploit \
		Framework is able to work with Nmap to provide exploit automation features. \
		Nmap is copyright (C) 1996-2008 Insecure.Com LLC. Nmap is a registered \
		trademark of Insecure.Com LLC. Nmap is included in this installer with \
		the permission of the Nmap Project. Nmap is provided under the GNU Public License, \
		not the BSD license which covers most of the Metasploit Framework" /SD IDYES IDNO endNmap

	ExecWait '"$INSTDIR\tools\nmap-4.76-setup.exe"' 
	endNmap:
	Delete "$INSTDIR\tools\nmap-4.76-setup.exe"
SectionEnd

Section "Registry" SecReg
	Exec 'regedt32 /S "$INSTDIR\tools\nmap_performance.reg"' 
	Delete "$INSTDIR\tools\nmap_performance.reg" 
SectionEnd 


Section -AdditionalIcons
  SetShellVarContext all
  ;WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Metasploit 3 GUI.lnk" "$INSTDIR\bin\rubyw.exe" '"$INSTDIR\bin\launcher.rb" framework msfgui' "$INSTDIR\metasploit.ico" 0  
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Metasploit 3 Web.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" framework msfweb -s' "$INSTDIR\metasploit.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Online Update.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" base updater.rb' "$INSTDIR\metasploit.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\CMD Shell.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" base shell.rb'
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\NASM Shell.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" framework tools\nasm_shell.rb'
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\RUBY Shell.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" framework tools\msf_irb_shell.rb' "$INSTDIR\ruby.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"

  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP\Development"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Development\Metasploit 3 GUI (Normal).lnk" "$INSTDIR\bin\rubyw.exe" '"$INSTDIR\bin\launcher.rb" framework-dev msfgui' "$INSTDIR\metasploit.ico" 0  
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Development\Metasploit 3 GUI (Debug).lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" framework-dev msfgui -D' "$INSTDIR\metasploit.ico" 0  
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Development\Metasploit 3 Web.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" framework-dev msfweb -s' "$INSTDIR\metasploit.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Development\Online Update.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" base-dev updater.rb' "$INSTDIR\metasploit.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Development\CMD Shell.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\launcher.rb" base-dev shell.rb'

  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP\Documentation"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Documentation\User Guide.lnk" "$INSTDIR\users_guide.pdf" "" "$INSTDIR\pdf.ico" 0
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Documentation\Developer Guide.lnk" "$INSTDIR\developers_guide.pdf" "" "$INSTDIR\pdf.ico" 0
  ;CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Documentation\Metasploit Online.lnk" "$INSTDIR\${PRODUCT_NAME}.url"

  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP\Tools"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Tools\Putty.lnk" "$INSTDIR\tools\putty.exe"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Tools\VNCViewer.lnk" "$INSTDIR\tools\vncviewer.exe"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Tools\WinVI.lnk" "$INSTDIR\tools\winvi32.exe"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Tools\CleanupTool.lnk" "$INSTDIR\bin\ruby.exe" '"$INSTDIR\bin\cleaner.rb"' "$INSTDIR\ruby.ico" 0


SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "${PRODUCT_STARTMENU_REGVAL}" "$ICONS_GROUP"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Function un.onUninstSuccess
  ;HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  SetShellVarContext all
  ReadRegStr $ICONS_GROUP ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "${PRODUCT_STARTMENU_REGVAL}"

  
  RMDir /r "$INSTDIR"
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"

  MessageBox MB_OK \
	"The per-user files stored in the %LOCALAPPDATA%/%APPDATA% directory (msf3 and .msf3) will not be \
	automatically removed by this installer. If you want to remove all traces of the \
	Metasploit Framework, you will need to delete these by hand."
 
  RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
  SetAutoClose true
SectionEnd
