Changeset 166 for trunk


Ignore:
Timestamp:
12/15/09 22:18:05 (14 years ago)
Author:
tim
Message:

fixed a bug in big data parsing
broke up some of REGFI_FILE initialization
started added more regfi API documentation

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r165 r166  
    519519/*                         Main iterator API                                  */
    520520/******************************************************************************/
     521
     522/* regfi_open: Attempts to open a registry hive and allocate related data
     523 *             structures.
     524 *
     525 * Arguments:
     526 *   filename -- A string containing the relative or absolute path of the
     527 *               registry hive to be opened.
     528 *
     529 * Returns:
     530 *   A reference to a newly allocated REGFI_FILE structure, if successful.
     531 *   NULL on error.
     532 */
    521533REGFI_FILE*           regfi_open(const char* filename);
    522 int                   regfi_close(REGFI_FILE* r);
     534
     535
     536/* regfi_alloc: Parses file headers of an already open registry hive file and
     537 *              allocates related structures for further parsing.
     538 *
     539 * Arguments:
     540 *   fd       -- A file descriptor of an already open file.  Must be seekable.
     541 *
     542 * Returns:
     543 *   A reference to a newly allocated REGFI_FILE structure, if successful.
     544 *   NULL on error.
     545 */
     546REGFI_FILE*           regfi_alloc(int fd);
     547
     548
     549/* regfi_close: Closes and frees an open registry hive.
     550 *
     551 * Arguments:
     552 *   file     -- The registry structure to close.
     553 *
     554 * Returns:
     555 *   0 on success, -1 on failure with errno set. 
     556 *   errno codes are similar to those of close(2).
     557 */
     558int                   regfi_close(REGFI_FILE* file);
     559
     560
     561/* regfi_free: Frees a hive's data structures without closing the underlying
     562 *             file.
     563 *
     564 * Arguments:
     565 *   file     -- The registry structure to free.
     566 */
     567void                  regfi_free(REGFI_FILE* file);
     568
    523569
    524570/* regfi_get_messages: Get errors, warnings, and/or verbose information
     
    533579char*                 regfi_get_messages(REGFI_FILE* file);
    534580
     581
     582/* regfi_set_message_mask: Set the verbosity level of errors and warnings
     583 *                         generated by the library
     584 *                         (as accessible via regfi_get_messages).
     585 *
     586 * Arguments:
     587 *   file     -- the structure for the registry file
     588 *   mask     -- an integer representing the types of messages desired.
     589 *               Acceptable values are created through bitwise ORs of
     590 *               REGFI_MSG_* values.  For instance, if only errors and
     591 *               informational messages were desired (but not warnings),
     592 *               then one would specify: REGFI_MSG_ERROR|REGFI_MSG_INFO
     593 *               New REGFI_FILE structures are created with:
     594 *                REGFI_MSG_ERROR|REGFI_MSG_WARN
     595 *               Note that error and warning messages will continue to
     596 *               accumulate in memory if they are not fetched using
     597 *               regfi_get_messages and then freed by the caller.
     598 *               To disable error messages entirely, supply 0, which
     599 *               will prevent message accumulation. 
     600 *
     601 * This may be called at any time and will take effect immediately.
     602 */
    535603void                  regfi_set_message_mask(REGFI_FILE* file, uint16 mask);
    536604
     
    549617 *                      REGFI_ENCODING_UTF8
    550618 *
    551  *                      XXX: This encoding only applies to specific data
    552  *                           strings currently, but should apply to key
    553  *                           names and value names in the future.
    554  *
    555619 * Returns:
    556620 *   A newly allocated REGFI_ITERATOR. Must be free()d with regfi_iterator_free.
     
    558622REGFI_ITERATOR*       regfi_iterator_new(REGFI_FILE* file,
    559623                                         REGFI_ENCODING output_encoding);
     624
     625
     626/* regfi_iterator_free: Frees a registry file iterator previously created by
     627 *                      regfi_iterator_new.
     628 *
     629 * This does not affect the underlying registry file's allocation status.
     630 *
     631 * Arguments:
     632 *   file            -- the iterator to be freed
     633 */
    560634void                  regfi_iterator_free(REGFI_ITERATOR* i);
     635
     636
     637/* regfi_iterator_down: Traverse deeper into the registry tree at the
     638 *                      current subkey.
     639 *
     640 * Arguments:
     641 *   i            -- the iterator
     642 *
     643 * Returns:
     644 *   true on success, false on failure.  Note that subkey and value indexes
     645 *   are preserved.  That is, if a regfi_iterator_up call occurs later
     646 *   (reversing the effect of this call) then the subkey and value referenced
     647 *   prior to the regfi_iterator_down call will still be referenced.  This
     648 *   makes depth-first iteration particularly easy.
     649 */
    561650bool                  regfi_iterator_down(REGFI_ITERATOR* i);
     651
     652
     653/* regfi_iterator_up: Traverse up to the current key's parent key.
     654 *
     655 * Arguments:
     656 *   i            -- the iterator
     657 *
     658 * Returns:
     659 *   true on success, false on failure.  Any subkey or value state
     660 *   associated with the current key is lost.
     661 */
    562662bool                  regfi_iterator_up(REGFI_ITERATOR* i);
     663
     664
     665/* regfi_iterator_to_root: Traverse up to the root key of the hive.
     666 *
     667 * Arguments:
     668 *   i            -- the iterator
     669 *
     670 * Returns:
     671 *   true on success, false on failure.
     672 */
    563673bool                  regfi_iterator_to_root(REGFI_ITERATOR* i);
    564674
     675
     676/* regfi_iterator_walk_path: Traverse down multiple levels in the registry hive.
     677 *
     678 * Arguments:
     679 *   i            -- the iterator
     680 *   path         -- a list of key names representing the path.  This list must
     681 *                   contain NUL terminated strings.  The list itself is
     682 *                   terminated with a NULL pointer.  All path elements must be
     683 *                   keys; value names are not accepted (even as the last
     684 *                   element).
     685 *
     686 * XXX: This currently only accepts ASCII key names.  Need to look into
     687 *      accepting other encodings.
     688 *
     689 * Returns:
     690 *   true on success, false on failure.  If any element of path is not found,
     691 *   false will be returned and the iterator will remain in its original
     692 *   position.
     693 */
    565694bool                  regfi_iterator_walk_path(REGFI_ITERATOR* i,
    566695                                               const char** path);
     696
     697
     698/* regfi_iterator_cur_key: Returns the currently referenced key.
     699 *
     700 * Arguments:
     701 *   i            -- the iterator
     702 *
     703 * Returns:
     704 *   A read-only key structure for the current key, or NULL on failure.
     705 */
    567706const REGFI_NK_REC*   regfi_iterator_cur_key(REGFI_ITERATOR* i);
     707
     708
     709/* regfi_iterator_cur_sk: Returns the SK (security) record referenced by the
     710 *                        current key.
     711 *
     712 * Arguments:
     713 *   i            -- the iterator
     714 *
     715 * Returns:
     716 *   A read-only SK structure, or NULL on failure.
     717 */
    568718const REGFI_SK_REC*   regfi_iterator_cur_sk(REGFI_ITERATOR* i);
    569719
     720
     721/* regfi_iterator_first_subkey: Sets the internal subkey index to the first
     722 *                              subkey referenced by the current key.
     723 *
     724 * Arguments:
     725 *   i            -- the iterator
     726 *
     727 * Returns:
     728 *   A read-only key structure for the newly referenced first subkey,
     729 *   or NULL on failure.  Failure may be due to a lack of any subkeys or other
     730 *   errors.
     731 */
    570732REGFI_NK_REC*         regfi_iterator_first_subkey(REGFI_ITERATOR* i);
     733
     734
     735/* regfi_iterator_cur_subkey: Returns the currently indexed subkey.
     736 *
     737 * Arguments:
     738 *   i            -- the iterator
     739 *
     740 * Returns:
     741 *   A newly allocated key structure for the currently referenced subkey,
     742 *   or NULL on failure.  Newly allocated keys must be freed with
     743 *   regfi_free_key.
     744 */
    571745REGFI_NK_REC*         regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
    572746REGFI_NK_REC*         regfi_iterator_next_subkey(REGFI_ITERATOR* i);
  • trunk/lib/regfi.c

    r165 r166  
    12711271
    12721272
    1273 /*******************************************************************
    1274  * Open the registry file and then read in the REGF block to get the
    1275  * first hbin offset.
    1276  *******************************************************************/
     1273/******************************************************************************
     1274 ******************************************************************************/
    12771275REGFI_FILE* regfi_open(const char* filename)
     1276{
     1277  REGFI_FILE* ret_val;
     1278  int fd;
     1279
     1280  /* open an existing file */
     1281  if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1)
     1282  {
     1283    /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/
     1284    return NULL;
     1285  }
     1286
     1287  ret_val = regfi_alloc(fd);
     1288
     1289  if(ret_val == NULL)
     1290    close(fd);
     1291
     1292  return ret_val;
     1293}
     1294
     1295
     1296/******************************************************************************
     1297 ******************************************************************************/
     1298REGFI_FILE* regfi_alloc(int fd)
    12781299{
    12791300  struct stat sbuf;
     
    12811302  REGFI_HBIN* hbin = NULL;
    12821303  uint32 hbin_off, file_length, cache_secret;
    1283   int fd;
    12841304  bool rla;
    12851305
    1286   /* open an existing file */
    1287   if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1)
    1288   {
    1289     /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/
    1290     return NULL;
    1291   }
    1292  
    12931306  /* Determine file length.  Must be at least big enough
    12941307   * for the header and one hbin.
     
    13001313    return NULL;
    13011314
    1302   /* read in an existing file */
     1315  /* Read file header */
    13031316  if ((rb = regfi_parse_regf(fd, true)) == NULL)
    13041317  {
    1305     /* fprintf(stderr, "regfi_open: Failed to read initial REGF block\n"); */
    1306     close(fd);
     1318    /* fprintf(stderr, "regfi_alloc: Failed to read initial REGF block\n"); */
    13071319    return NULL;
    13081320  }
     
    13121324  if(rb->hbins == NULL)
    13131325  {
    1314     /* fprintf(stderr, "regfi_open: Failed to create HBIN list.\n"); */
    1315     close(fd);
     1326    /* fprintf(stderr, "regfi_alloc: Failed to create HBIN list.\n"); */
    13161327    talloc_free(rb);
    13171328    return NULL;
     
    13501361/******************************************************************************
    13511362 ******************************************************************************/
    1352 int regfi_close(REGFI_FILE *file)
     1363int regfi_close(REGFI_FILE* file)
    13531364{
    13541365  int fd;
     
    13611372  file->fd = -1;
    13621373
    1363   range_list_free(file->hbins);
    1364 
    1365   if(file->sk_cache != NULL)
    1366     lru_cache_destroy(file->sk_cache);
     1374  regfi_free(file);
     1375
     1376  return close(fd);
     1377}
     1378
     1379
     1380/******************************************************************************
     1381 ******************************************************************************/
     1382void regfi_free(REGFI_FILE *file)
     1383{
     1384  if(file->last_message != NULL)
     1385    free(last_message);
    13671386
    13681387  talloc_free(file);
    1369   return close(fd);
    13701388}
    13711389
     
    20772095
    20782096
    2079 /*******************************************************************
     2097/******************************************************************************
    20802098 * Convert from UTF-16LE to specified character set.
    20812099 * On error, returns a negative errno code.
    2082  *******************************************************************/
     2100 *****************************************************************************/
    20832101int32 regfi_conv_charset(const char* input_charset, const char* output_charset,
    20842102                         uint8* input, char* output,
     
    29012919                                       uint16 num_chunks, bool strict)
    29022920{
    2903   uint32 cell_length, chunk_offset, data_left;
     2921  uint32 cell_length, chunk_offset;
    29042922  range_list* ret_val;
    29052923  uint16 i;
     
    29112929    goto fail;
    29122930 
    2913   for(i=0; (i<num_chunks) && (data_left>0); i++)
     2931  for(i=0; i<num_chunks; i++)
    29142932  {
    29152933    chunk_offset = offsets[i]+REGFI_REGF_SIZE;
Note: See TracChangeset for help on using the changeset viewer.