Represents a Load Command string. A rough analogue to the lc_str struct used internally by OS X. This class allows ruby-macho to pretend that strings stored in LCs are immediately available without explicit operations on the raw Mach-O data.
@param lc [LoadCommand] the load command @param lc_str [Fixnum, String] the offset to the beginning of the
string, or the string itself if not being initialized with a view.
@raise [MachO::LCStrMalformedError] if the string is malformed @todo devise a solution such that the `lc_str` parameter is not
interpreted differently depending on `lc.view`. The current behavior is a hack to allow viewless load command creation.
@api private
# File lib/macho/load_commands.rb, line 277 def initialize(lc, lc_str) view = lc.view if view lc_str_abs = view.offset + lc_str lc_end = view.offset + lc.cmdsize - 1 raw_string = view.raw_data.slice(lc_str_abs..lc_end) @string, null_byte, _padding = raw_string.partition("\x00") raise LCStrMalformedError, lc if null_byte.empty? @string_offset = lc_str else @string = lc_str @string_offset = 0 end end
@return [Fixnum] the offset to the beginning of the string in the
load command
# File lib/macho/load_commands.rb, line 300 def to_i @string_offset end
@return [String] a string representation of the LCStr
# File lib/macho/load_commands.rb, line 294 def to_s @string end