Rizin
unix-like reverse engineering framework and cli tools
|
#include <mspack.h>
Public Attributes | |
struct mspack_file *(* | open )(struct mspack_system *self, const char *filename, int mode) |
void(* | close )(struct mspack_file *file) |
int(* | read )(struct mspack_file *file, void *buffer, int bytes) |
int(* | write )(struct mspack_file *file, void *buffer, int bytes) |
int(* | seek )(struct mspack_file *file, off_t offset, int mode) |
off_t(* | tell )(struct mspack_file *file) |
void(* | message )(struct mspack_file *file, const char *format,...) |
void *(* | alloc )(struct mspack_system *self, size_t bytes) |
void(* | free )(void *ptr) |
void(* | copy )(void *src, void *dest, size_t bytes) |
void * | null_ptr |
A structure which abstracts file I/O and memory management.
The library always uses the mspack_system structure for interaction with the file system and to allocate, free and copy all memory. It also uses it to send literal messages to the library user.
When the library is compiled normally, passing NULL to a compressor or decompressor constructor will result in a default mspack_system being used, where all methods are implemented with the standard C library. However, all constructors support being given a custom created mspack_system structure, with the library user's own methods. This allows for more abstract interaction, such as reading and writing files directly to memory, or from a network socket or pipe.
Implementors of an mspack_system structure should read all documentation entries for every structure member, and write methods which conform to those standards.
void *(* mspack_system::alloc)(struct mspack_system *self, size_t bytes) |
Allocates memory.
self | a self-referential pointer to the mspack_system structure whose alloc() method is being called. |
bytes | the number of bytes to allocate |
Definition at line 421 of file mspack.h.
Referenced by cabd_extract(), cabd_find(), cabd_merge(), cabd_open(), cabd_read_headers(), cabd_read_string(), cabd_search(), chmd_extract(), chmd_read_headers(), chmd_real_open(), find_sys_file(), kwajd_extract(), kwajd_open(), kwajd_read_headers(), lzh_init(), lzss_decompress(), lzxd_init(), mspack_create_cab_decompressor(), mspack_create_chm_decompressor(), mspack_create_kwaj_decompressor(), mspack_create_oab_decompressor(), mspack_create_szdd_decompressor(), mspack_valid_system(), mszipd_init(), noned_init(), oabd_decompress(), oabd_decompress_incremental(), qtmd_init(), read_chunk(), read_sys_file(), and szddd_open().
void(* mspack_system::close)(struct mspack_file *file) |
Closes a previously opened file. If any memory was allocated for this particular file handle, it should be freed at this time.
file | the file to close |
Definition at line 321 of file mspack.h.
Referenced by cabd_close(), cabd_extract(), cabd_open(), cabd_search(), cabd_sys_read_block(), chmd_close(), chmd_extract(), chmd_fast_find(), chmd_real_open(), kwajd_extract(), kwajd_open(), mspack_destroy_cab_decompressor(), mspack_destroy_chm_decompressor(), mspack_valid_system(), oabd_decompress(), oabd_decompress_incremental(), szddd_extract(), and szddd_open().
Copies from one region of memory to another.
The regions of memory are guaranteed not to overlap, are usually less than 256 bytes, and may not be aligned. Please note that the source parameter comes before the destination parameter, unlike the standard C function memcpy().
src | the region of memory to copy from |
dest | the region of memory to copy to |
bytes | the size of the memory region, in bytes |
Definition at line 444 of file mspack.h.
Referenced by cabd_read_string(), cabd_sys_read(), chmd_read_headers(), lzxd_decompress(), and mspack_valid_system().
void(* mspack_system::free)(void *ptr) |
Frees memory.
ptr | the memory to be freed. NULL is accepted and ignored. |
Definition at line 430 of file mspack.h.
Referenced by cabd_close(), cabd_merge(), cabd_read_headers(), cabd_search(), chmd_close(), chmd_init_decomp(), chmd_read_headers(), kwajd_extract(), kwajd_open(), lzh_free(), lzss_decompress(), lzxd_free(), lzxd_init(), mspack_destroy_cab_decompressor(), mspack_destroy_chm_decompressor(), mspack_destroy_kwaj_decompressor(), mspack_destroy_oab_decompressor(), mspack_destroy_szdd_decompressor(), mspack_valid_system(), mszipd_free(), mszipd_init(), noned_free(), noned_init(), oabd_decompress(), oabd_decompress_incremental(), qtmd_free(), qtmd_init(), read_chunk(), read_reset_table(), read_spaninfo(), read_sys_file(), and szddd_open().
void(* mspack_system::message)(struct mspack_file *file, const char *format,...) |
Used to send messages from the library to the user.
Occasionally, the library generates warnings or other messages in plain english to inform the human user. These are informational only and can be ignored if not wanted.
file | may be a file handle returned from open() if this message pertains to a specific open file, or NULL if not related to a specific file. |
format | a printf() style format string. It does NOT include a trailing newline. |
Definition at line 407 of file mspack.h.
Referenced by cabd_can_merge_folders(), cabd_extract(), cabd_find(), cabd_merge(), cabd_read_headers(), cabd_search(), cabd_sys_read_block(), chmd_read_headers(), chmd_real_open(), lzxd_decompress(), mspack_valid_system(), and read_off64().
void * mspack_system::null_ptr |
A null pointer to mark the end of mspack_system. It must equal NULL.
Should the mspack_system structure extend in the future, this NULL will be seen, rather than have an invalid method pointer called.
Definition at line 454 of file mspack.h.
Referenced by mspack_valid_system().
struct mspack_file *(* mspack_system::open)(struct mspack_system *self, const char *filename, int mode) |
Opens a file for reading, writing, appending or updating.
self | a self-referential pointer to the mspack_system structure whose open() method is being called. If this pointer is required by close(), read(), write(), seek() or tell(), it should be stored in the result structure at this time. |
filename | the file to be opened. It is passed directly from the library caller without being modified, so it is up to the caller what this parameter actually represents. |
mode | one of MSPACK_SYS_OPEN_READ (open an existing file for reading), MSPACK_SYS_OPEN_WRITE (open a new file for writing), MSPACK_SYS_OPEN_UPDATE (open an existing file for reading/writing from the start of the file) or MSPACK_SYS_OPEN_APPEND (open an existing file for reading/writing from the end of the file) |
Definition at line 683 of file mspack.h.
Referenced by cabd_extract(), cabd_open(), cabd_search(), cabd_sys_read_block(), chmd_extract(), chmd_fast_find(), chmd_real_open(), kwajd_extract(), kwajd_open(), mspack_valid_system(), oabd_decompress(), oabd_decompress_incremental(), szddd_extract(), and szddd_open().
Reads a given number of bytes from an open file.
file | the file to read from |
buffer | the location where the read bytes should be stored |
bytes | the number of bytes to read from the file. |
Definition at line 336 of file mspack.h.
Referenced by cabd_extract(), cabd_find(), cabd_read_headers(), cabd_read_string(), cabd_sys_read_block(), chmd_extract(), chmd_read_headers(), copy_fh(), kwajd_extract(), kwajd_read_headers(), lzh_read_input(), lzxd_set_reference_data(), mspack_valid_system(), oabd_decompress(), oabd_decompress_incremental(), read_chunk(), read_sys_file(), and szddd_read_headers().
Seeks to a specific file offset within an open file.
Sometimes the library needs to know the length of a file. It does this by seeking to the end of the file with seek(file, 0, MSPACK_SYS_SEEK_END), then calling tell(). Implementations may want to make a special case for this.
Due to the potentially varying 32/64 bit datatype off_t on some architectures, the MSPACK_SYS_SELFTEST macro MUST be used before using the library. If not, the error caused by the library passing an inappropriate stackframe to seek() is subtle and hard to trace.
file | the file to be seeked |
offset | an offset to seek, measured in bytes |
mode | one of MSPACK_SYS_SEEK_START (the offset should be measured from the start of the file), MSPACK_SYS_SEEK_CUR (the offset should be measured from the current file offset) or MSPACK_SYS_SEEK_END (the offset should be measured from the end of the file) |
Definition at line 380 of file mspack.h.
Referenced by cabd_extract(), cabd_find(), cabd_read_headers(), cabd_read_string(), cabd_sys_read_block(), chmd_extract(), chmd_read_headers(), kwajd_extract(), kwajd_read_headers(), mspack_sys_filelen(), mspack_valid_system(), read_chunk(), read_sys_file(), and szddd_extract().
off_t(* mspack_system::tell)(struct mspack_file *file) |
Returns the current file position (in bytes) of the given file.
file | the file whose file position is wanted |
Definition at line 391 of file mspack.h.
Referenced by cabd_read_string(), chmd_extract(), chmd_read_headers(), mspack_sys_filelen(), and mspack_valid_system().
Writes a given number of bytes to an open file.
file | the file to write to |
buffer | the location where the written bytes should be read from |
bytes | the number of bytes to write to the file. |
Definition at line 353 of file mspack.h.
Referenced by chmd_extract(), copy_fh(), kwajd_extract(), lzxd_decompress(), mspack_valid_system(), oabd_decompress(), oabd_decompress_incremental(), and qtmd_decompress().