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, as a rehex.BitOffset object. |
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 (or bits). |
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 = rehex.BitOffset(0, 0), length = rehex.BitOffset(0, 0), text = "First comment", }, { offset = rehex.BitOffset(10, 0), length = rehex.BitOffset(8, 0), 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, as a rehex.BitOffset object.
- 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, as a rehex.BitOffset object.
- 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.
- real_offset
- 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(rehex.BitOffset(0, 0), rehex.BitOffset(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 as a rehex.BitOffset object.
- length Length as a rehex.BitOffset object.
- 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 (or bits).
Example data types include:
"u16le" - unsigned 16-bit (little endian) "f32be" - 32-bit float (big endian) "code:i386" - Machine code (X86)
Parameters:
- offset Data offset as a rehex.BitOffset object.
- length Data length as a rehex.BitOffset object.
- 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.
- desc
- 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.
- virt_offset