Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/ronin/support/core_ext/integer.rb,
lib/ronin/support/binary/core_ext/integer.rb,
lib/ronin/support/encoding/c/core_ext/integer.rb,
lib/ronin/support/encoding/js/core_ext/integer.rb,
lib/ronin/support/encoding/hex/core_ext/integer.rb,
lib/ronin/support/encoding/uri/core_ext/integer.rb,
lib/ronin/support/encoding/xml/core_ext/integer.rb,
lib/ronin/support/encoding/html/core_ext/integer.rb,
lib/ronin/support/encoding/http/core_ext/integer.rb,
lib/ronin/support/encoding/shell/core_ext/integer.rb,
lib/ronin/support/binary/bit_flip/core_ext/integer.rb,
lib/ronin/support/encoding/base36/core_ext/integer.rb,
lib/ronin/support/encoding/base62/core_ext/integer.rb,
lib/ronin/support/encoding/powershell/core_ext/integer.rb
Overview
Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
ronin-support is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
ronin-support is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with ronin-support. If not, see https://www.gnu.org/licenses/.
Instance Method Summary collapse
-
#base36_encode ⇒ String
[Base36] encodes the Integer.
-
#base62_encode ⇒ String
[Base62] encodes the Integer.
-
#bit_flips(bits) ⇒ Array<Integer>
(also: #flip_bits)
Returns every bit flip in the integer.
-
#c_encode ⇒ String
Formats the Integer as a C escaped String.
-
#c_escape ⇒ String
(also: #c_char)
Escapes the Integer as a C character.
-
#each_bit_flip(bits) {|int| ... } ⇒ Enumerator
Enumerates over every bit flip in the integer.
-
#hex_encode ⇒ String
(also: #to_hex)
Converts the integer into hex format.
-
#hex_escape ⇒ String
(also: #hex_char)
Converts the integer into an escaped hex character.
-
#hex_int ⇒ String
Encodes the number as a
0xXX
hex integer. -
#html_encode(**kwargs) ⇒ String
Encodes the Integer as a HTML String.
-
#html_escape(**kwargs) ⇒ String
Escapes the Integer as an HTML String.
-
#http_encode(**kwargs) ⇒ String
Encodes the byte as an escaped HTTP decimal character.
-
#http_escape(**kwargs) ⇒ String
HTTP escapes the Integer.
-
#js_encode ⇒ String
Encodes the Integer as a JavaScript character.
-
#js_escape ⇒ String
Escapes the Integer as a JavaScript character.
-
#pack(argument, **kwargs) ⇒ String
Packs the Integer into a String.
-
#powershell_encode ⇒ String
(also: #psh_encode)
Encodes the Integer as a PowerShell character.
-
#powershell_escape ⇒ String
(also: #psh_escape)
Escapes the Integer as a PowerShell character.
-
#shell_encode ⇒ String
(also: #sh_encode, #bash_encode)
Encodes the Integer as a shell character.
-
#shell_escape ⇒ String
(also: #sh_escape, #bash_escape)
Escapes the Integer as a shell character.
-
#to_int16 ⇒ Integer
(also: #to_i16)
Converts the integer into an 16-bit signed integer.
-
#to_int32 ⇒ Integer
(also: #to_i32)
Converts the integer into an 32-bit signed integer.
-
#to_int64 ⇒ Integer
(also: #to_i64)
Converts the integer into an 64-bit signed integer.
-
#to_int8 ⇒ Integer
(also: #to_i8)
Converts the integer into an 8-bit signed integer.
-
#to_uint16 ⇒ Integer
(also: #to_u16)
Converts the integer into an 16-bit unsigned integer.
-
#to_uint32 ⇒ Integer
(also: #to_u32)
Converts the integer into an 32-bit unsigned integer.
-
#to_uint64 ⇒ Integer
(also: #to_u64)
Converts the integer into an 64-bit unsigned integer.
-
#to_uint8 ⇒ Integer
(also: #to_u8)
Converts the integer into an 8-bit unsigned integer.
-
#uri_encode(**kwargs) ⇒ String
URI encodes the byte.
-
#uri_escape(**kwargs) ⇒ String
URI escapes the byte.
-
#uri_form_encode(**kwargs) ⇒ String
URI Form encodes the Integer.
-
#uri_form_escape(**kwargs) ⇒ String
URI Form escapes the Integer.
-
#xml_encode(**kwargs) ⇒ String
Encodes the Integer as a XML String.
-
#xml_escape(**kwargs) ⇒ String
Escapes the Integer as an XML String.
Instance Method Details
#base36_encode ⇒ String
Base36 encodes the Integer.
39 40 41 |
# File 'lib/ronin/support/encoding/base36/core_ext/integer.rb', line 39 def base36_encode Ronin::Support::Encoding::Base36.encode_int(self) end |
#base62_encode ⇒ String
Base62 encodes the Integer.
39 40 41 |
# File 'lib/ronin/support/encoding/base62/core_ext/integer.rb', line 39 def base62_encode Ronin::Support::Encoding::Base62.encode_int(self) end |
#bit_flips(bits) ⇒ Array<Integer> Also known as: flip_bits
Returns every bit flip in the integer.
73 74 75 |
# File 'lib/ronin/support/binary/bit_flip/core_ext/integer.rb', line 73 def bit_flips(bits) Ronin::Support::Binary::BitFlip::Integer.bit_flips(self,bits) end |
#c_encode ⇒ String
Formats the Integer as a C escaped String.
78 79 80 |
# File 'lib/ronin/support/encoding/c/core_ext/integer.rb', line 78 def c_encode Ronin::Support::Encoding::C.encode_byte(self) end |
#c_escape ⇒ String Also known as: c_char
Escapes the Integer as a C character.
52 53 54 |
# File 'lib/ronin/support/encoding/c/core_ext/integer.rb', line 52 def c_escape Ronin::Support::Encoding::C.escape_byte(self) end |
#each_bit_flip(bits) {|int| ... } ⇒ Enumerator
Enumerates over every bit flip in the integer.
49 50 51 |
# File 'lib/ronin/support/binary/bit_flip/core_ext/integer.rb', line 49 def each_bit_flip(bits,&block) Ronin::Support::Binary::BitFlip::Integer.each_bit_flip(self,bits,&block) end |
#hex_encode ⇒ String Also known as: to_hex
Converts the integer into hex format.
37 38 39 |
# File 'lib/ronin/support/encoding/hex/core_ext/integer.rb', line 37 def hex_encode Ronin::Support::Encoding::Hex.encode_byte(self) end |
#hex_escape ⇒ String Also known as: hex_char
Converts the integer into an escaped hex character.
60 61 62 |
# File 'lib/ronin/support/encoding/hex/core_ext/integer.rb', line 60 def hex_escape Ronin::Support::Encoding::Hex.escape_byte(self) end |
#hex_int ⇒ String
Encodes the number as a 0xXX
hex integer.
78 79 80 |
# File 'lib/ronin/support/encoding/hex/core_ext/integer.rb', line 78 def hex_int "0x%.2x" % self end |
#html_encode(**kwargs) ⇒ String
Encodes the Integer as a HTML String.
102 103 104 |
# File 'lib/ronin/support/encoding/html/core_ext/integer.rb', line 102 def html_encode(**kwargs) Ronin::Support::Encoding::HTML.encode_byte(self,**kwargs) end |
#html_escape(**kwargs) ⇒ String
Escapes the Integer as an HTML String.
53 54 55 |
# File 'lib/ronin/support/encoding/html/core_ext/integer.rb', line 53 def html_escape(**kwargs) Ronin::Support::Encoding::HTML.escape_byte(self,**kwargs) end |
#http_encode(**kwargs) ⇒ String
Encodes the byte as an escaped HTTP decimal character.
54 55 56 |
# File 'lib/ronin/support/encoding/http/core_ext/integer.rb', line 54 def http_encode(**kwargs) Ronin::Support::Encoding::HTTP.encode_byte(self,**kwargs) end |
#http_escape(**kwargs) ⇒ String
HTTP escapes the Integer.
91 92 93 |
# File 'lib/ronin/support/encoding/http/core_ext/integer.rb', line 91 def http_escape(**kwargs) Ronin::Support::Encoding::HTTP.escape_byte(self,**kwargs) end |
#js_encode ⇒ String
Encodes the Integer as a JavaScript character.
63 64 65 |
# File 'lib/ronin/support/encoding/js/core_ext/integer.rb', line 63 def js_encode Ronin::Support::Encoding::JS.encode_byte(self) end |
#js_escape ⇒ String
Escapes the Integer as a JavaScript character.
43 44 45 |
# File 'lib/ronin/support/encoding/js/core_ext/integer.rb', line 43 def js_escape Ronin::Support::Encoding::JS.escape_byte(self) end |
#pack(argument, **kwargs) ⇒ String
Packs the Integer into a String.
The desired architecture of the binary format.
The Operating System name to lookup.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 80 def pack(argument, **kwargs) case argument when String [self].pack(argument) when Symbol types = Ronin::Support::Binary::CTypes.platform(**kwargs) type = types[argument] type.pack(self) else raise(ArgumentError,"invalid pack argument: #{argument}") end end |
#powershell_encode ⇒ String Also known as: psh_encode
Encodes the Integer as a PowerShell character.
48 49 50 |
# File 'lib/ronin/support/encoding/powershell/core_ext/integer.rb', line 48 def powershell_encode Ronin::Support::Encoding::PowerShell.encode_byte(self) end |
#powershell_escape ⇒ String Also known as: psh_escape
Escapes the Integer as a PowerShell character.
81 82 83 |
# File 'lib/ronin/support/encoding/powershell/core_ext/integer.rb', line 81 def powershell_escape Ronin::Support::Encoding::PowerShell.escape_byte(self) end |
#shell_encode ⇒ String Also known as: sh_encode, bash_encode
Encodes the Integer as a shell character.
48 49 50 |
# File 'lib/ronin/support/encoding/shell/core_ext/integer.rb', line 48 def shell_encode Ronin::Support::Encoding::Shell.encode_byte(self) end |
#shell_escape ⇒ String Also known as: sh_escape, bash_escape
Escapes the Integer as a shell character.
82 83 84 |
# File 'lib/ronin/support/encoding/shell/core_ext/integer.rb', line 82 def shell_escape Ronin::Support::Encoding::Shell.escape_byte(self) end |
#to_int16 ⇒ Integer Also known as: to_i16
Converts the integer into an 16-bit signed integer.
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 190 def to_int16 int = self & 0xffff if int[15] == 1 # interpret the new signed bit int -= 0x10000 end return int end |
#to_int32 ⇒ Integer Also known as: to_i32
Converts the integer into an 32-bit signed integer.
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 213 def to_int32 int = self & 0xffffffff if int[31] == 1 # interpret the new signed bit int -= 0x100000000 end return int end |
#to_int64 ⇒ Integer Also known as: to_i64
Converts the integer into an 64-bit signed integer.
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 236 def to_int64 int = self & 0xffffffffffffffff if int[63] == 1 # interpret the new signed bit int -= 0x10000000000000000 end return int end |
#to_int8 ⇒ Integer Also known as: to_i8
Converts the integer into an 8-bit signed integer.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 167 def to_int8 int = self & 0xff if int[7] == 1 # interpret the new signed bit int -= 0x100 end return int end |
#to_uint16 ⇒ Integer Also known as: to_u16
Converts the integer into an 16-bit unsigned integer.
119 120 121 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 119 def to_uint16 self & 0xffff end |
#to_uint32 ⇒ Integer Also known as: to_u32
Converts the integer into an 32-bit unsigned integer.
135 136 137 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 135 def to_uint32 self & 0xffffffff end |
#to_uint64 ⇒ Integer Also known as: to_u64
Converts the integer into an 64-bit unsigned integer.
151 152 153 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 151 def to_uint64 self & 0xffffffffffffffff end |
#to_uint8 ⇒ Integer Also known as: to_u8
Converts the integer into an 8-bit unsigned integer.
103 104 105 |
# File 'lib/ronin/support/binary/core_ext/integer.rb', line 103 def to_uint8 self & 0xff end |
#uri_encode(**kwargs) ⇒ String
URI encodes the byte.
48 49 50 |
# File 'lib/ronin/support/encoding/uri/core_ext/integer.rb', line 48 def uri_encode(**kwargs) Ronin::Support::Encoding::URI.encode_byte(self,**kwargs) end |
#uri_escape(**kwargs) ⇒ String
URI escapes the byte.
79 80 81 |
# File 'lib/ronin/support/encoding/uri/core_ext/integer.rb', line 79 def uri_escape(**kwargs) Ronin::Support::Encoding::URI.escape_byte(self,**kwargs) end |
#uri_form_encode(**kwargs) ⇒ String
URI Form encodes the Integer.
145 146 147 |
# File 'lib/ronin/support/encoding/uri/core_ext/integer.rb', line 145 def uri_form_encode(**kwargs) Ronin::Support::Encoding::URI::Form.encode_byte(self,**kwargs) end |
#uri_form_escape(**kwargs) ⇒ String
URI Form escapes the Integer.
112 113 114 |
# File 'lib/ronin/support/encoding/uri/core_ext/integer.rb', line 112 def uri_form_escape(**kwargs) Ronin::Support::Encoding::URI::Form.escape_byte(self,**kwargs) end |