x64.nsh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ; ---------------------
  2. ; x64.nsh
  3. ; ---------------------
  4. ;
  5. ; A few simple macros to handle installations on x64 machines.
  6. ;
  7. ; RunningX64 checks if the installer is running on a 64-bit OS.
  8. ; IsWow64 checks if the installer is a 32-bit application running on a 64-bit OS.
  9. ;
  10. ; ${If} ${RunningX64}
  11. ; MessageBox MB_OK "Running on 64-bit Windows"
  12. ; ${EndIf}
  13. ;
  14. ; IsNative* checks the OS native CPU architecture.
  15. ;
  16. ; ${If} ${IsNativeAMD64}
  17. ; ; Install AMD64 64-bit driver/library
  18. ; ${ElseIf} ${IsNativeARM64}
  19. ; ; Install ARM64 64-bit driver/library
  20. ; ${ElseIf} ${IsNativeIA32}
  21. ; ; Install i386 32-bit driver/library
  22. ; ${Else}
  23. ; Abort "Unsupported CPU architecture!"
  24. ; ${EndIf}
  25. ;
  26. ; DisableX64FSRedirection disables file system redirection.
  27. ; EnableX64FSRedirection enables file system redirection.
  28. ;
  29. ; SetOutPath $SYSDIR
  30. ; ${DisableX64FSRedirection}
  31. ; File something.bin # extracts to C:\Windows\System32
  32. ; ${EnableX64FSRedirection}
  33. ; File something.bin # extracts to C:\Windows\SysWOW64
  34. ;
  35. !ifndef ___X64__NSH___
  36. !define ___X64__NSH___
  37. !include LogicLib.nsh
  38. !define IsWow64 `"" IsWow64 ""`
  39. !macro _IsWow64 _a _b _t _f
  40. !insertmacro _LOGICLIB_TEMP
  41. System::Call kernel32::GetCurrentProcess()p.s
  42. System::Call kernel32::IsWow64Process2(ps,*i0s,*i) ; [Win10.1511+] 0 if not WOW64
  43. Push |
  44. System::Call kernel32::IsWow64Process(p-1,*i0s) ; [WinXP+] FALSE for a 32-bit application on ARM64!
  45. System::Int64Op
  46. Pop $_LOGICLIB_TEMP
  47. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  48. !macroend
  49. !define RunningX64 `"" RunningX64 ""`
  50. !macro _RunningX64 _a _b _t _f
  51. !if ${NSIS_PTR_SIZE} > 4
  52. !insertmacro LogicLib_JumpToBranch `${_t}` `${_f}`
  53. !else
  54. !insertmacro _IsWow64 `${_a}` `${_b}` `${_t}` `${_f}`
  55. !endif
  56. !macroend
  57. !define GetNativeMachineArchitecture "!insertmacro GetNativeMachineArchitecture "
  58. !macro GetNativeMachineArchitecture outvar
  59. !define GetNativeMachineArchitecture_lbl lbl_GNMA_${__COUNTER__}
  60. System::Call kernel32::GetCurrentProcess()p.s
  61. System::Call kernel32::IsWow64Process2(ps,*i,*i0s)
  62. Pop ${outvar}
  63. IntCmp ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_done ${GetNativeMachineArchitecture_lbl}_done
  64. !if "${NSIS_PTR_SIZE}" <= 4
  65. !if "${NSIS_CHAR_SIZE}" <= 1
  66. System::Call 'USER32::CharNextW(w"")p.s'
  67. Pop ${outvar}
  68. IntPtrCmpU ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_oldnt ${GetNativeMachineArchitecture_lbl}_oldnt
  69. StrCpy ${outvar} 332 ; Always IMAGE_FILE_MACHINE_I386 on Win9x
  70. Goto ${GetNativeMachineArchitecture_lbl}_done
  71. ${GetNativeMachineArchitecture_lbl}_oldnt:
  72. !endif
  73. !endif
  74. System::Call '*0x7FFE002E(&i2.s)'
  75. Pop ${outvar}
  76. ${GetNativeMachineArchitecture_lbl}_done:
  77. !undef GetNativeMachineArchitecture_lbl
  78. !macroend
  79. !macro _IsNativeMachineArchitecture _ignore _arc _t _f
  80. !insertmacro _LOGICLIB_TEMP
  81. ${GetNativeMachineArchitecture} $_LOGICLIB_TEMP
  82. !insertmacro _= $_LOGICLIB_TEMP ${_arc} `${_t}` `${_f}`
  83. !macroend
  84. !define IsNativeMachineArchitecture `"" IsNativeMachineArchitecture `
  85. !define IsNativeIA32 '${IsNativeMachineArchitecture} 332' ; Intel x86
  86. !define IsNativeAMD64 '${IsNativeMachineArchitecture} 34404' ; x86-64/x64
  87. !define IsNativeARM64 '${IsNativeMachineArchitecture} 43620'
  88. !define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
  89. !macro DisableX64FSRedirection
  90. System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
  91. !macroend
  92. !define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
  93. !macro EnableX64FSRedirection
  94. System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
  95. !macroend
  96. !endif # !___X64__NSH___