x64.nsh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. ; ${If} ${IsNativeAMD64}
  27. ; File "amd64\myapp.exe"
  28. ; ${ElseIf} ${IsNativeIA32}
  29. ; ${OrIf} ${IsWow64}
  30. ; File "x86\myapp.exe"
  31. ; ${Else}
  32. ; Abort "Unsupported CPU architecture!"
  33. ; ${EndIf}
  34. ;
  35. ; DisableX64FSRedirection disables file system redirection.
  36. ; EnableX64FSRedirection enables file system redirection.
  37. ;
  38. ; SetOutPath $SYSDIR
  39. ; ${DisableX64FSRedirection}
  40. ; File something.bin # extracts to C:\Windows\System32
  41. ; ${EnableX64FSRedirection}
  42. ; File something.bin # extracts to C:\Windows\SysWOW64
  43. ;
  44. !ifndef ___X64__NSH___
  45. !define ___X64__NSH___
  46. !include LogicLib.nsh
  47. !define IsWow64 `"" IsWow64 ""`
  48. !macro _IsWow64 _a _b _t _f
  49. !insertmacro _LOGICLIB_TEMP
  50. System::Call kernel32::GetCurrentProcess()p.s
  51. System::Call kernel32::IsWow64Process2(ps,*i0s,*i) ; [Win10.1511+] 0 if not WOW64
  52. Push |
  53. System::Call kernel32::IsWow64Process(p-1,*i0s) ; [WinXP+] FALSE for a 32-bit application on ARM64!
  54. System::Int64Op
  55. Pop $_LOGICLIB_TEMP
  56. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  57. !macroend
  58. !define RunningX64 `"" RunningX64 ""`
  59. !macro _RunningX64 _a _b _t _f
  60. !if ${NSIS_PTR_SIZE} > 4
  61. !insertmacro LogicLib_JumpToBranch `${_t}` `${_f}`
  62. !else
  63. !insertmacro _IsWow64 `${_a}` `${_b}` `${_t}` `${_f}`
  64. !endif
  65. !macroend
  66. !define GetNativeMachineArchitecture "!insertmacro GetNativeMachineArchitecture "
  67. !macro GetNativeMachineArchitecture outvar
  68. !define GetNativeMachineArchitecture_lbl lbl_GNMA_${__COUNTER__}
  69. System::Call kernel32::GetCurrentProcess()p.s
  70. System::Call kernel32::IsWow64Process2(ps,*i,*i0s)
  71. Pop ${outvar}
  72. IntCmp ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_done ${GetNativeMachineArchitecture_lbl}_done
  73. !if "${NSIS_PTR_SIZE}" <= 4
  74. !if "${NSIS_CHAR_SIZE}" <= 1
  75. System::Call 'USER32::CharNextW(w"")p.s'
  76. Pop ${outvar}
  77. IntPtrCmpU ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_oldnt ${GetNativeMachineArchitecture_lbl}_oldnt
  78. StrCpy ${outvar} 332 ; Always IMAGE_FILE_MACHINE_I386 on Win9x
  79. Goto ${GetNativeMachineArchitecture_lbl}_done
  80. ${GetNativeMachineArchitecture_lbl}_oldnt:
  81. !endif
  82. !endif
  83. System::Call '*0x7FFE002E(&i2.s)'
  84. Pop ${outvar}
  85. ${GetNativeMachineArchitecture_lbl}_done:
  86. !undef GetNativeMachineArchitecture_lbl
  87. !macroend
  88. !macro _IsNativeMachineArchitecture _ignore _arc _t _f
  89. !insertmacro _LOGICLIB_TEMP
  90. ${GetNativeMachineArchitecture} $_LOGICLIB_TEMP
  91. !insertmacro _= $_LOGICLIB_TEMP ${_arc} `${_t}` `${_f}`
  92. !macroend
  93. !define IsNativeMachineArchitecture `"" IsNativeMachineArchitecture `
  94. !define IsNativeIA32 '${IsNativeMachineArchitecture} 332' ; Intel x86
  95. !define IsNativeAMD64 '${IsNativeMachineArchitecture} 34404' ; x86-64/x64
  96. !define IsNativeARM64 '${IsNativeMachineArchitecture} 43620'
  97. !define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
  98. !macro DisableX64FSRedirection
  99. System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
  100. !macroend
  101. !define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
  102. !macro EnableX64FSRedirection
  103. System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
  104. !macroend
  105. !endif # !___X64__NSH___