[Kong API].internal.image_interface

Data mapping templates and image_interface class


class : image_interface

image_interface.link:

These mapping templates provide an method for extracting and modifying data blocks from executable images. They are non-copying for memory based streams - the mapped data points directly to the original. For file based streams a memory block (copy_block) is allocated and tagged so image_interface.commit() can write them back to disk. The size of the base datatype is inferred from typeof(A) (if not explicity set) and is combined with "n" to calculate the raw block length in bytes.

  • Note: image_interface.commit() blindly copies each block back to disk without checking for overlapping regions etc.
  • Proxy structures are handled as a special case and are initialized properly by link, link_b, and copy.

Type Name Description
Constructors:
(io_stream) this Supported Streams: memory_stream?, file_stream?
Data:
io_stream file
bool endian Passed to proxy objects to initialize their state.
int type Ditto.
copy_block[uintptr_t] memory Data allocated with file based streams.
Methods:
string (size_t offset) read_stringz Read at offset until 0x0 is reached.
string () read_stringz Read from current file position until 0x0.
T (T, U...)(ref T t, U u) link Creates a reference point to memory. t = void* or void[] to fill with the reference. u[0] = how many items to map. u[1] = file offset. (Optional).
T (T, U...)(ref T t, U u) link_b Same as above but size parameter is in bytes not units.
void (T, U...)(ref T t, U u) copy Reads a block of memory into given buffer. Handles proxy objects as a special case. t = pre allocated buffer. u = same as link();
void () commit Record all copy_blocks from this.memory back to file.
aligned_block (size_t size, size_t alignment) aligned_extend Extend file so that theres room for size bytes starting on aligned boundry.
Static Methods:
uintptr_t (uintptr_t a, uintptr_t b) align_to Align A to B boundry.
  • Writing proxy objects is not supported yet - will be implemented soon. The objects state can be examined manually to obtain the size and memory address. see image_reflect.

Related:

ELF, PE, image_reflect (proxy structs)