module Metasm::ExeFormat::IntToHash
Public Instance Methods
bits_from_hash(val, hash)
click to toggle source
converts an array of flag constants to its numeric value using the hash {1 => 'toto', 2 => 'tata'}: ['toto', 'tata'] => 3, 'toto' => 2, 42 => 42
# File metasm/exe_format/main.rb, line 231 def bits_from_hash(val, hash) val.kind_of?(Array) ? val.inject(0) { |val_, bitname| val_ | int_from_hash(bitname, hash) } : int_from_hash(val, hash) end
bits_to_hash(val, hash)
click to toggle source
converts a numeric value to the corresponding array of constant flag names using the hash {1 => 'toto', 2 => 'tata'}: 5 => ['toto', 4]
# File metasm/exe_format/main.rb, line 243 def bits_to_hash(val, hash) (val.kind_of?(Integer) ? (hash.find_all { |k, v| val & k == k and val &= ~k }.map { |k, v| v } << val) : val.kind_of?(Array) ? val.map { |e| int_to_hash(e, hash) } : [int_to_hash(val, hash)]) - [0] end
int_from_hash(val, hash)
click to toggle source
converts a constant name to its numeric value using the hash {1 => 'toto', 2 => 'tata'}: 'toto' => 1, 42 => 42, 'tutu' => raise
# File metasm/exe_format/main.rb, line 225 def int_from_hash(val, hash) val.kind_of?(Integer) ? hash.index(val) || val : hash.index(val) or raise "unknown constant #{val.inspect}" end
int_to_hash(val, hash)
click to toggle source
converts a numeric value to the corresponding constant name using the hash {1 => 'toto', 2 => 'tata'}: 1 => 'toto', 42 => 42, 'tata' => 'tata', 'tutu' => raise
# File metasm/exe_format/main.rb, line 237 def int_to_hash(val, hash) val.kind_of?(Integer) ? hash.fetch(val, val) : (hash.index(val) ? val : raise("unknown constant #{val.inspect}")) end