Debian Codegraph @

Include/x64.nsh

raw
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
45 !ifndef ___X64__NSH___
46 !define ___X64__NSH___
47
48 !include LogicLib.nsh
49
50
51 !define IsWow64 `"" IsWow64 ""`
52 !macro _IsWow64 _a _b _t _f
53 !insertmacro _LOGICLIB_TEMP
54 System::Call kernel32::GetCurrentProcess()p.s
55 System::Call kernel32::IsWow64Process2(ps,*i0s,*i) ; [Win10.1511+] 0 if not WOW64
56 Push |
57 System::Call kernel32::IsWow64Process(p-1,*i0s) ; [WinXP+] FALSE for a 32-bit application on ARM64!
58 System::Int64Op
59 Pop $_LOGICLIB_TEMP
60 !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
61 !macroend
62
63
64 !define RunningX64 `"" RunningX64 ""`
65 !macro _RunningX64 _a _b _t _f
66 !if ${NSIS_PTR_SIZE} > 4
67 !insertmacro LogicLib_JumpToBranch `${_t}` `${_f}`
68 !else
69 !insertmacro _IsWow64 `${_a}` `${_b}` `${_t}` `${_f}`
70 !endif
71 !macroend
72
73
74 !define GetNativeMachineArchitecture "!insertmacro GetNativeMachineArchitecture "
75 !macro GetNativeMachineArchitecture outvar
76 !define GetNativeMachineArchitecture_lbl lbl_GNMA_${__COUNTER__}
77 System::Call kernel32::GetCurrentProcess()p.s
78 System::Call kernel32::IsWow64Process2(ps,*i,*i0s)
79 Pop ${outvar}
80 IntCmp ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_done ${GetNativeMachineArchitecture_lbl}_done
81 !if "${NSIS_PTR_SIZE}" <= 4
82 !if "${NSIS_CHAR_SIZE}" <= 1
83 System::Call 'USER32::CharNextW(w"")p.s'
84 Pop ${outvar}
85 IntPtrCmpU ${outvar} 0 "" ${GetNativeMachineArchitecture_lbl}_oldnt ${GetNativeMachineArchitecture_lbl}_oldnt
86 StrCpy ${outvar} 332 ; Always IMAGE_FILE_MACHINE_I386 on Win9x
87 Goto ${GetNativeMachineArchitecture_lbl}_done
88 ${GetNativeMachineArchitecture_lbl}_oldnt:
89 !endif
90 !endif
91 System::Call '*0x7FFE002E(&i2.s)'
92 Pop ${outvar}
93 ${GetNativeMachineArchitecture_lbl}_done:
94 !undef GetNativeMachineArchitecture_lbl
95 !macroend
96
97 !macro _IsNativeMachineArchitecture _ignore _arc _t _f
98 !insertmacro _LOGICLIB_TEMP
99 ${GetNativeMachineArchitecture} $_LOGICLIB_TEMP
100 !insertmacro _= $_LOGICLIB_TEMP ${_arc} `${_t}` `${_f}`
101 !macroend
102
103 !define IsNativeMachineArchitecture `"" IsNativeMachineArchitecture `
104 !define IsNativeIA32 '${IsNativeMachineArchitecture} 332' ; Intel x86
105 !define IsNativeAMD64 '${IsNativeMachineArchitecture} 34404' ; x86-64/x64
106 !define IsNativeARM64 '${IsNativeMachineArchitecture} 43620'
107
108
109 !define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
110 !macro DisableX64FSRedirection
111 System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
112 !macroend
113
114 !define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
115 !macro EnableX64FSRedirection
116 System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
117 !macroend
118
119
120 !endif # !___X64__NSH___