lib/macho/macho_file.rb
# Inserts a load command at the given offset.
# @param offset [Integer] the offset to insert at
# @param lc [LoadCommands::LoadCommand] the load command to insert
# @param options [Hash]
# @option options [Boolean] :repopulate (true) whether or not to repopulate
#  the instance fields
# @raise [OffsetInsertionError] if the offset is not in the load command region
# @raise [HeaderPadError] if the new command exceeds the header pad buffer
# @note Calling this method with an arbitrary offset in the load command
#  region **will leave the object in an inconsistent state**.
Inserts a load command at the given offset.
Inserts a load command at the given offset .
def insert_command(offset, lc, options = {})
      context = LoadCommands::LoadCommand::SerializationContext.context_for(self)
      cmd_raw = lc.serialize(context)
      fileoff = offset + cmd_raw.bytesize
      raise OffsetInsertionError, offset if offset < header.class.bytesize || fileoff > low_fileoff
      new_sizeofcmds = sizeofcmds + cmd_raw.bytesize
      raise HeaderPadError, @filename if header.class.bytesize + new_sizeofcmds > low_fileoff
      update_ncmds(ncmds + 1)
      update_sizeofcmds(new_sizeofcmds)
      @raw_data.insert(offset, cmd_raw)
      @raw_data.slice!(header.class.bytesize + new_sizeofcmds, cmd_raw.bytesize)
      populate_fields if options.fetch(:repopulate, true)
    end
def insert_command ( offset , lc , options = { } ) context = LoadCommands :: LoadCommand :: SerializationContext . context_for ( self ) cmd_raw = lc . serialize ( context ) fileoff = offset + cmd_raw . bytesize raise OffsetInsertionError , offset if offset < header . class . bytesize || fileoff > low_fileoff new_sizeofcmds = sizeofcmds + cmd_raw . bytesize raise HeaderPadError , @filename if header . class . bytesize + new_sizeofcmds > low_fileoff update_ncmds ( ncmds + 1 ) update_sizeofcmds ( new_sizeofcmds ) @raw_data . insert ( offset , cmd_raw ) @raw_data . slice! ( header . class . bytesize + new_sizeofcmds , cmd_raw . bytesize ) populate_fields if options . fetch ( :repopulate , true ) end
Inserts a load command at the given offset.
Inserts a load command at the given offset .
# update Mach-O header fields to account for inserted load command
[OffsetInsertionError] if the offset is not in the load command region
[ OffsetInsertionError ] if the offset is not in the load command region
[HeaderPadError] if the new command exceeds the header pad buffer
[ HeaderPadError ] if the new command exceeds the header pad buffer
offset
the offset to insert at
the offset to insert at
lc
the load command to insert
the load command to insert
options
:repopulate (true) whether or not to repopulate the instance fields
: repopulate ( true ) whether or not to repopulate the instance fields
<not_specific>
None
note
Calling this method with an arbitrary offset in the load command region **will leave the object in an inconsistent state**.
Calling this method with an arbitrary offset in the load command region ** will leave the object in an inconsistent state ** .