Class: FFI::Pointer
- Inherits:
-
Object
- Object
- FFI::Pointer
- Defined in:
- lib/facter/resolvers/windows/ffi/ffi.rb
Instance Method Summary collapse
- #read_wide_string_with_length(char_length) ⇒ Object
- #read_wide_string_without_length(replace_invalid_chars: false) ⇒ Object
- #read_win32_bool ⇒ Object
Instance Method Details
#read_wide_string_with_length(char_length) ⇒ Object
30 31 32 33 34 |
# File 'lib/facter/resolvers/windows/ffi/ffi.rb', line 30 def read_wide_string_with_length(char_length) # char_length is number of wide chars (typically excluding NULLs), *not* bytes str = get_bytes(0, char_length * 2).force_encoding(Encoding::UTF_16LE) str.encode(Encoding::UTF_8, str.encoding) end |
#read_wide_string_without_length(replace_invalid_chars: false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/facter/resolvers/windows/ffi/ffi.rb', line 36 def read_wide_string_without_length(replace_invalid_chars: false) wide_character = get_bytes(0, 2) wide_character.force_encoding(Encoding::UTF_16LE) i = 2 str = [] while wide_character != END_OF_WCHAR_STRING str << wide_character wide_character = get_bytes(i, 2) wide_character.force_encoding(Encoding::UTF_16LE) i += 2 end if replace_invalid_chars str.join.force_encoding(Encoding::UTF_16LE).encode(Encoding::UTF_8, Encoding::UTF_16LE, invalid: :replace) else str.join.force_encoding(Encoding::UTF_16LE).encode(Encoding::UTF_8) end end |
#read_win32_bool ⇒ Object
56 57 58 59 60 |
# File 'lib/facter/resolvers/windows/ffi/ffi.rb', line 56 def read_win32_bool # BOOL is always a 32-bit integer in Win32 # some Win32 APIs return 1 for true, while others are non-0 read_int32 != WIN32FALSE end |