Class: Mixlibrary::Core::Utilities::WindowsArchitectureHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlibrary/core/utilities/windows_architecture_helper.rb

Class Method Summary collapse

Class Method Details

.architectureObject

returns the architecture based on if the machine is 64 bit



27
28
29
30
31
32
33
# File 'lib/mixlibrary/core/utilities/windows_architecture_helper.rb', line 27

def self.architecture
  if(is_machine_64bit?)
    return :x86_64
  else
    return :i386
  end
end

.disable_wow64_file_redirectionObject

Disables syswow redirection



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mixlibrary/core/utilities/windows_architecture_helper.rb', line 48

def self.disable_wow64_file_redirection()
  original_redirection_state = ['0'].pack('P')

  win32_wow_64_disable_wow_64_fs_redirection =
    ::Win32::API.new('Wow64DisableWow64FsRedirection', 'P', 'L', 'kernel32')

  succeeded = win32_wow_64_disable_wow_64_fs_redirection.call(original_redirection_state)

  if succeeded == 0
    raise  "Failed to disable Wow64 file redirection"
  end

  return original_redirection_state
end

.is_machine_64bit?Boolean

Attempts to determine if this machine is 64 bit or not in a variety of ways - using generic ruby and/or Windows specific environment variabes

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mixlibrary/core/utilities/windows_architecture_helper.rb', line 10

def self.is_machine_64bit?
  if(RubyInfo.architecture==:x86_64)
    return true
  end

  if(ENV.has_key?('ProgramFiles(x86)'))
    return true;
  end

  if(ENV.has_key?('PROCESSOR_ARCHITEW6432'))
    return true;
  end        
  
  return false;
end

.restore_wow64_file_redirection(original_redirection_state) ⇒ Object

Restore syswow redirection



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mixlibrary/core/utilities/windows_architecture_helper.rb', line 64

def self.restore_wow64_file_redirection(original_redirection_state )

  win32_wow_64_revert_wow_64_fs_redirection =
    ::Win32::API.new('Wow64RevertWow64FsRedirection', 'P', 'L', 'kernel32')

  succeeded = win32_wow_64_revert_wow_64_fs_redirection.call(original_redirection_state)

  if succeeded == 0
    raise  "Failed to revert Wow64 file redirection"
  end
end

.wow64_architecture_override_required?(desired_architecture) ⇒ Boolean

Determines if the syswow redirection needs to be disabled based on the desired architecture.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
# File 'lib/mixlibrary/core/utilities/windows_architecture_helper.rb', line 36

def self.wow64_architecture_override_required?(desired_architecture)
  #only use case we need to disable redirection is if
  #running as 32 bit
  #want 64 bit
  #On 64bit machine
  RubyInfo.architecture==:i386 &&
    desired_architecture == :x86_64  &&
    is_machine_64bit?
  
end