Module: PatchELF::Helper
- Defined in:
- lib/patchelf/helper.rb
Overview
Helper methods for internal usage.
Constant Summary collapse
- COLOR_CODE =
Color codes for pretty print.
{ esc_m: "\e[0m", info: "\e[38;5;82m", # light green warn: "\e[38;5;230m", # light yellow error: "\e[38;5;196m" # heavy red }.freeze
Class Method Summary collapse
-
.aligndown(val, align = page_size) ⇒ Integer
Aligned result.
-
.alignup(val, align = page_size) ⇒ Integer
Aligned result.
-
.color_enabled? ⇒ Boolean
For #colorize to decide if need add color codes.
-
.colorize(str, type) ⇒ String
For wrapping string with color codes for prettier inspect.
-
.page_size(e_machine = nil) ⇒ Object
The size of one page.
Class Method Details
.aligndown(val, align = page_size) ⇒ Integer
Returns Aligned result.
65 66 67 |
# File 'lib/patchelf/helper.rb', line 65 def aligndown(val, align = page_size) val - (val & (align - 1)) end |
.alignup(val, align = page_size) ⇒ Integer
Returns Aligned result.
80 81 82 |
# File 'lib/patchelf/helper.rb', line 80 def alignup(val, align = page_size) (val & (align - 1)).zero? ? val : (aligndown(val, align) + align) end |
.color_enabled? ⇒ Boolean
For #colorize to decide if need add color codes.
50 51 52 |
# File 'lib/patchelf/helper.rb', line 50 def color_enabled? $stderr.tty? end |
.colorize(str, type) ⇒ String
For wrapping string with color codes for prettier inspect.
40 41 42 43 44 45 46 |
# File 'lib/patchelf/helper.rb', line 40 def colorize(str, type) return str unless color_enabled? cc = COLOR_CODE color = cc.key?(type) ? cc[type] : '' "#{color}#{str.sub(COLOR_CODE[:esc_m], color)}#{cc[:esc_m]}" end |
.page_size(e_machine = nil) ⇒ Object
The size of one page.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/patchelf/helper.rb', line 17 def page_size(e_machine = nil) # Different architectures have different minimum section alignments. case e_machine when ELFTools::Constants::EM_SPARC, ELFTools::Constants::EM_MIPS, ELFTools::Constants::EM_PPC, ELFTools::Constants::EM_PPC64, ELFTools::Constants::EM_AARCH64, ELFTools::Constants::EM_TILEGX, ELFTools::Constants::EM_LOONGARCH 0x10000 else 0x1000 end end |