Changeset 178 for trunk/include/regfi.h


Ignore:
Timestamp:
03/13/10 12:56:36 (14 years ago)
Author:
tim
Message:

reworked I/O to use callback functions

fixed a bug in mtime validation and consolidated time formatting code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r172 r178  
    9393
    9494#define REGFI_NUM_ENCODINGS    3
    95 
    96 /* Windows is lame */
    97 #ifdef O_BINARY
    98 #define REGFI_OPEN_FLAGS O_RDONLY|O_BINARY
    99 #else
    100 #define REGFI_OPEN_FLAGS O_RDONLY
    101 #endif
    10295
    10396/* Registry data types */
     
    162155 /* Minimum time is Jan 1, 1990 00:00:00 */
    163156#define REGFI_MTIME_MIN_HIGH       0x01B41E6D
    164 #define REGFI_MTIME_MIN_LOW        0x26F98000
     157
    165158 /* Maximum time is Jan 1, 2290 00:00:00
    166159  * (We hope no one is using Windows by then...)
    167160  */
    168161#define REGFI_MTIME_MAX_HIGH       0x03047543
    169 #define REGFI_MTIME_MAX_LOW        0xC80A4000
    170162
    171163
     
    649641
    650642
     643typedef struct _regfi_raw_file
     644{
     645  off_t    (* seek)(); /* (REGFI_RAW_FILE* self, off_t offset, int whence) */
     646  ssize_t  (* read)(); /* (REGFI_RAW_FILE* self, void* buf, size_t count) */
     647
     648  uint64_t cur_off;
     649  uint64_t size;
     650  void*    state;
     651} REGFI_RAW_FILE;
     652
    651653
    652654/** Registry hive file data structure
     
    665667 * @ingroup regfiBase
    666668 */
    667 typedef struct
     669typedef struct _regfi_file
    668670{
    669671  /* Run-time information */
    670672  /************************/
    671   /* file descriptor */
    672   int fd;
     673  /* Functions for accessing the file */
     674  REGFI_RAW_FILE* cb;
    673675
    674676  /* For sanity checking (not part of the registry header) */
     
    798800/******************************************************************************/
    799801
    800 /** Attempts to open a registry hive and allocate related data structures.
    801  *
    802  * @param filename A string containing the relative or absolute path of the
    803  *               registry hive to be opened.
    804  *
    805  * @return A reference to a newly allocated REGFI_FILE structure,
    806  *         if successful;  NULL on error.
    807  *
    808  * @ingroup regfiBase
    809  */
    810 REGFI_FILE*           regfi_open(const char* filename);
    811 
    812 
    813802/** Parses file headers of an already open registry hive file and
    814803 *  allocates related structures for further parsing.
     
    824813
    825814
    826 /** Closes and frees an open registry hive.
    827  *
    828  * @param file The registry structure to close.
    829  *
    830  * @return 0 on success, -1 on failure with errno set. 
    831  *         errno codes are similar to those of close(2).
     815/** Parses file headers returned by supplied callback functions.
     816 *
     817 * This interface is useful if you have a registry hive in memory
     818 * or have some other reason to emulate a real file.
     819 *
     820 * @param file_cb A structure defining the callback functions needed to access the file.
     821 *
     822 * @return A reference to a newly allocated REGFI_FILE structure, if successful;
     823 *         NULL on error.
    832824 *
    833825 * @ingroup regfiBase
    834826 */
    835 int                   regfi_close(REGFI_FILE* file);
     827REGFI_FILE*           regfi_alloc_cb(REGFI_RAW_FILE* file_cb);
    836828
    837829
     
    12981290/******************************************************************************/
    12991291
    1300 REGFI_FILE*           regfi_parse_regf(int fd, bool strict);
     1292REGFI_FILE*           regfi_parse_regf(REGFI_RAW_FILE* file_cb, bool strict);
    13011293REGFI_HBIN*           regfi_parse_hbin(REGFI_FILE* file, uint32_t offset,
    13021294                                       bool strict);
     
    13671359 * @ingroup regfiParseLayer
    13681360 */
    1369 bool                  regfi_parse_cell(int fd, uint32_t offset,
     1361bool                  regfi_parse_cell(REGFI_RAW_FILE* file_cb, uint32_t offset,
    13701362                                       uint8_t* hdr, uint32_t hdr_len,
    13711363                                       uint32_t* cell_length, bool* unalloc);
     
    14101402                                    REGFI_ENCODING output_encoding);
    14111403void                  regfi_subkeylist_free(REGFI_SUBKEY_LIST* list);
    1412 uint32_t              regfi_read(int fd, uint8_t* buf, uint32_t* length);
     1404
     1405off_t                 regfi_raw_seek(REGFI_RAW_FILE* self,
     1406                                     off_t offset, int whence);
     1407ssize_t               regfi_raw_read(REGFI_RAW_FILE* self,
     1408                                     void* buf, size_t count);
     1409off_t                 regfi_seek(REGFI_RAW_FILE* file_cb,
     1410                                 off_t offset, int whence);
     1411uint32_t              regfi_read(REGFI_RAW_FILE* file_cb,
     1412                                 uint8_t* buf, uint32_t* length);
    14131413
    14141414const char*           regfi_type_val2str(unsigned int val);
Note: See TracChangeset for help on using the changeset viewer.