Class rehex.Document

An open "Document" (file) in the editor.

Methods

rehex.Document:buffer_length () Get the length of the file, in bytes.
rehex.Document:clear_virt_mapping_r (real_offset, length) Clear virtual address mapping by file offset.
rehex.Document:clear_virt_mapping_v (virt_offset, length) Clear virtual address mapping by virtual address.
rehex.Document:get_comments () Get all comments in the document.
rehex.Document:get_cursor_position () Get the current cursor position in the file, in bytes.
rehex.Document:get_filename () Get the filename of the document.
rehex.Document:get_title () Get the title of the document.
rehex.Document:read_data (offset, max_length) Read data from the document.
rehex.Document:real_to_virt_offset (real_offset) Convert a file offset to a virtual address.
rehex.Document:set_comment (offset, length, comment) Set a comment in the document.
rehex.Document:set_data_type (offset, length, type) Set the data type of a range of bytes.
rehex.Document:set_virt_mapping (real_offset, virt_offset, length) Set up a virtual address mapping in the document.
rehex.Document:transact_begin (desc) Start an undo/redo transaction.
rehex.Document:transact_commit () Commit a transaction started with transact_begin()
rehex.Document:transact_rollback () Rollback (cancel) a transaction started with transact_begin()
rehex.Document:virt_to_real_offset (virt_offset) Convert a virtual address to a file offset.


Methods

rehex.Document:buffer_length ()
Get the length of the file, in bytes.
rehex.Document:clear_virt_mapping_r (real_offset, length)
Clear virtual address mapping by file offset.

This method can be used to clear partial of whole segments. Any byte ranges which are not part of a virtual segment will be ignored.

Parameters:

  • real_offset Offset to segment to clear in file.
  • length Length to clear in bytes.
rehex.Document:clear_virt_mapping_v (virt_offset, length)
Clear virtual address mapping by virtual address.

This method can be used to clear partial of whole segments. Any byte ranges which are not part of a virtual segment will be ignored.

Parameters:

  • virt_offset Address of segment to clear.
  • length Length to clear in bytes.
rehex.Document:get_comments ()
Get all comments in the document.

{ { offset = 0, length = 0, text = "First comment", }, { offset = 10, length = 8, text = "Second comment", }, }

Returns:

    A table containing each comment as a table.
rehex.Document:get_cursor_position ()
Get the current cursor position in the file, in bytes.
rehex.Document:get_filename ()
Get the filename of the document.
rehex.Document:get_title ()
Get the title of the document.
rehex.Document:read_data (offset, max_length)
Read data from the document.

Parameters:

  • offset File offset to read from, in bytes.
  • max_length Maximum number of bytes to read.

Returns:

    The binary data as a string.
rehex.Document:real_to_virt_offset (real_offset)
Convert a file offset to a virtual address.

Parameters:

  • real_offset - File offset.

Returns:

    Virtual address of file offset, negative if offset isn't part of a virtual segment.
rehex.Document:set_comment (offset, length, comment)
Set a comment in the document.

Example usage:

-- Set a comment at the start of the file. doc:set_comment(0, 0, rehex.Comment.new("Hello world"))

The length parameter sets how many bytes are encompassed by the comment - if it is zero, the comment will just be inserted at that point in the data, if nonzero, it will visibly nest the data in itself (if the "Nest comments" option is enabled).

Existing comments with the same offset and length will be replaced.

Parameters:

  • offset File offset in bytes.
  • length Length in bytes.
  • comment rehex.REHex_Document_Comment object.

Returns:

    true on success, false on failure
rehex.Document:set_data_type (offset, length, type)
Set the data type of a range of bytes.

Example data types include:

"u16le" - unsigned 16-bit (little endian) "f32be" - 32-bit float (big endian) "code:i386" - Machine code (X86)

Parameters:

  • offset File offset in bytes
  • length Length in bytes
  • type Data type as a string

Returns:

    true on success, false on failure
rehex.Document:set_virt_mapping (real_offset, virt_offset, length)
Set up a virtual address mapping in the document.

Parameters:

  • real_offset Offset to start of segment in file.
  • virt_offset Virtual address of segment.
  • length Length of segment in bytes.

Returns:

    true on success, false on conflict.
rehex.Document:transact_begin (desc)
Start an undo/redo transaction.

This method allows batching multiple operations (modifying data, inserting comments, etc) into a single operation in the undo/redo system.

Every call to this method *MUST* be matched with a call to either the transact_commit() or transact_rollback() method.

Parameters:

  • desc - Description of operation.
rehex.Document:transact_commit ()
Commit a transaction started with transact_begin()
rehex.Document:transact_rollback ()
Rollback (cancel) a transaction started with transact_begin()
rehex.Document:virt_to_real_offset (virt_offset)
Convert a virtual address to a file offset.

Parameters:

  • virt_offset - Virtual address.

Returns:

    File offset of virtual address, negative if address isn't part of a virtual segment.
generated by LDoc 1.4.6 Last updated 2024-02-14 23:56:27