Changeset 54


Ignore:
Timestamp:
09/04/05 21:19:05 (19 years ago)
Author:
tim
Message:

Added some verbose output

code cleanup and minor bug fixes

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfio.h

    r53 r54  
    5757#define REG_BINARY                     3
    5858#define REG_DWORD                      4
    59 #define REG_DWORD_LE                   4        /* DWORD, little endian */
    60 #define REG_DWORD_BE                   5        /* DWORD, big endian */
     59#define REG_DWORD_LE                   4  /* DWORD, little endian */
     60#define REG_DWORD_BE                   5  /* DWORD, big endian */
    6161#define REG_LINK                       6
    6262#define REG_MULTI_SZ                   7
     
    9595#define NK_TYPE_ROOTKEY         0x002c
    9696
    97 #define HBIN_STORE_REF(x, y)    { x->hbin = y; y->ref_count++ };
    98 #define HBIN_REMOVE_REF(x, y)   { x->hbin = NULL; y->ref_count-- /* if the count == 0; we can clean up */ };
     97#define HBIN_STORE_REF(x, y) { x->hbin = y; y->ref_count++ };
     98/* if the count == 0; we can clean up */
     99#define HBIN_REMOVE_REF(x, y){ x->hbin = NULL; y->ref_count-- };
    99100
    100101
     
    107108  uint32 free_off;       /* offset to free space within the hbin record */
    108109  uint32 free_size;      /* amount of data left in the block */
    109   int    ref_count;      /* how many active records are pointing to this block (not used currently) */
     110  int    ref_count;      /* how many active records are pointing to this
     111                          * block (not used currently)
     112                          */
    110113       
    111114  uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
    112115  uint32 first_hbin_off; /* offset from first hbin block */
    113   uint32 block_size;     /* block size of this blockually a multiple of 4096Kb) */
    114   prs_struct ps;               /* data */
     116  uint32 block_size;     /* block size of this block is
     117                          * usually a multiple of 4096Kb
     118                          */
     119  prs_struct ps;         /* data */
    115120  bool dirty;            /* has this hbin block been modified? */
    116121} REGF_HBIN;
    117122
    118123/* ??? List -- list of key offsets and hashed names for consistency */
    119 
    120124typedef struct {
    121125  uint32 nk_off;
     
    124128
    125129typedef struct {
    126   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing this nk record */
    127   uint32 hbin_off;      /* offset from beginning of this hbin block */
    128   uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
     130  REGF_HBIN *hbin;       /* pointer to HBIN record (in memory) containing
     131                          * this nk record
     132                          */
     133  uint32 hbin_off;       /* offset from beginning of this hbin block */
     134  uint32 rec_size;       /* ((start_offset - end_offset) & 0xfffffff8) */
    129135 
    130136  uint8 header[REC_HDR_SIZE];
     
    136142
    137143typedef struct {
    138   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing this nk record */
     144  REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     145                         * this nk record
     146                         */
    139147  uint32 hbin_off;      /* offset from beginning of this hbin block */
    140148  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    141   uint32 rec_off;               /* offset stored in the value list */
     149  uint32 rec_off;       /* offset stored in the value list */
    142150 
    143151  uint8  header[REC_HDR_SIZE];
     
    156164typedef struct _regf_sk_rec {
    157165  struct _regf_sk_rec *next, *prev;
    158   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing this nk record */
     166  REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     167                         * this nk record
     168                         */
    159169  uint32 hbin_off;      /* offset from beginning of this hbin block */
    160170  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    161171 
    162   uint32 sk_off;                /* offset parsed from NK record used as a key
    163                                    to lookup reference to this SK record */
     172  uint32 sk_off;        /* offset parsed from NK record used as a key
     173                         * to lookup reference to this SK record
     174                         */
    164175 
    165176  uint8  header[REC_HDR_SIZE];
     
    174185
    175186typedef struct {
    176   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing this nk record */
     187  REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     188                         * this nk record
     189                         */
    177190  uint32 hbin_off;      /* offset from beginning of this hbin block */
    178191  uint32 subkey_index;  /* index to next subkey record to return */
     
    180193 
    181194  /* header information */
    182  
    183195  uint8  header[REC_HDR_SIZE];
    184196  uint16 key_type;
     
    190202 
    191203  /* max lengths */
    192  
    193   uint32 max_bytes_subkeyname;          /* max subkey name * 2 */
    194   uint32 max_bytes_subkeyclassname;     /* max subkey classname length (as if) */
    195   uint32 max_bytes_valuename;           /* max valuename * 2 */
    196   uint32 max_bytes_value;                       /* max value data size */
     204  uint32 max_bytes_subkeyname;      /* max subkey name * 2 */
     205  uint32 max_bytes_subkeyclassname; /* max subkey classname length (as if) */
     206  uint32 max_bytes_valuename;       /* max valuename * 2 */
     207  uint32 max_bytes_value;           /* max value data size */
    197208 
    198209  /* unknowns */
    199  
    200   uint32 unk_index;                     /* nigel says run time index ? */
     210  uint32 unk_index;                 /* nigel says run time index ? */
    201211 
    202212  /* children */
    203  
    204213  uint32 num_subkeys;
    205214  uint32 subkeys_off;   /* hash records that point to NK records */     
    206215  uint32 num_values;
    207216  uint32 values_off;    /* value lists which point to VK records */
    208   uint32 sk_off;                /* offset to SK record */
     217  uint32 sk_off;        /* offset to SK record */
    209218 
    210219  /* link in the other records here */
    211  
    212220  REGF_LF_REC subkeys;
    213221  REGF_VK_REC *values;
     
    220228typedef struct {
    221229  /* run time information */
    222  
    223   int fd;                               /* file descriptor */
    224   int open_flags;                       /* flags passed to the open() call */
    225   void *mem_ctx;                /* memory context for run-time file access information */
    226   REGF_HBIN *block_list;                /* list of open hbin blocks */
     230  int fd;         /* file descriptor */
     231  int open_flags; /* flags passed to the open() call */
     232  void *mem_ctx;  /* memory context for run-time file access information */
     233  REGF_HBIN *block_list; /* list of open hbin blocks */
    227234 
    228235  /* file format information */
    229236 
    230237  uint8  header[REGF_HDR_SIZE]; /* "regf" */
    231   uint32 data_offset;           /* offset to record in the first (or any?) hbin block */
     238  uint32 data_offset;           /* offset to record in the first (or any?)
     239                                 * hbin block
     240                                 */
    232241  uint32 last_block;            /* offset to last hbin block in file */
    233242  uint32 checksum;              /* XOR of bytes 0x0000 - 0x01FB */
    234243  NTTIME mtime;
    235244 
    236   REGF_SK_REC *sec_desc_list;   /* list of security descriptors referenced by NK records */
     245  REGF_SK_REC *sec_desc_list;   /* list of security descriptors referenced
     246                                 * by NK records
     247                                 */
    237248 
    238249  /* unknowns used to simply writing */
    239  
    240250  uint32 unknown1;
    241251  uint32 unknown2;
     
    247257
    248258
     259/******************************************************************************/
    249260/* Function Declarations */
    250  
     261
    251262const char*   regfio_type_val2str(unsigned int val);
    252263int           regfio_type_str2val(const char* str);
  • trunk/src/reglookup.c

    r53 r54  
    184184
    185185  /* XXX: this MULTI_SZ parser is pretty inefficient.  Should be
    186    *      redone with fewer malloc and better string concatenation.
     186   *      redone with fewer malloc calls and better string concatenation.
    187187   */
    188188  case REG_MULTI_SZ:
     
    317317  if (buf == NULL)
    318318    return NULL;
    319   buf[0] = '/';
    320   buf[1] = '\0';
     319  buf[0] = '\0';
    321320
    322321  iter = void_stack_iterator_new(nk_stack);
     
    472471
    473472
    474 /* XXX: this function is god-awful.  Needs to be re-designed. */
     473/* XXX: this function is awful.  Needs to be re-designed. */
    475474void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix)
    476475{
     
    479478  char* path = NULL;
    480479  char* val_path = NULL;
    481 
    482480  int key_type = regfio_type_str2val("KEY");
    483481 
     
    486484    cur->subkey_index = 0;
    487485    path = stack2Path(nk_stack);
    488    
     486
     487    if(print_verbose)
     488    {
     489      if(prefix[0] == '\0')
     490        fprintf(stderr, "VERBOSE: Printing key tree under path: /\n");
     491      else
     492        fprintf(stderr, "VERBOSE: Printing key tree under path: %s\n",
     493                prefix);
     494    }
    489495
    490496    val_path = (char*)malloc(strlen(prefix)+strlen(path)+1);
    491497    sprintf(val_path, "%s%s", prefix, path);
     498    if(val_path[0] == '\0')
     499    {
     500      val_path[0] = '/';
     501      val_path[1] = '\0';
     502    }
     503
    492504    if(!type_filter_enabled || (key_type == type_filter))
    493505      printKey(cur, val_path);
    494 
    495506    if(!type_filter_enabled || (key_type != type_filter))
    496507      printValueList(cur, val_path);
     
    527538    }
    528539  }
     540  if(print_verbose)
     541    fprintf(stderr, "VERBOSE: Finished printing key tree.\n");
    529542}
    530543
     
    559572  cur = (REGF_NK_REC*)void_stack_cur(nk_stack);
    560573
     574  if(print_verbose)
     575    fprintf(stderr, "VERBOSE: Beginning retrieval of specified path: %s\n",
     576            path_filter);
     577
    561578  while(void_stack_size(path_stack) > 1)
    562579  {
     
    575592      }
    576593    }
     594    if(print_verbose && !found_cur)
     595      fprintf(stderr, "VERBOSE: Could not find KEY '%s' in specified path.\n",
     596              cur_str);
     597
    577598    free(cur_str);
    578 
    579599    if(!found_cur)
    580600      return 1;
     
    583603  /* Last round, search value and key records */
    584604  cur_str = (char*)void_stack_pop(path_stack);
     605
     606  if(print_verbose)
     607    fprintf(stderr, "VERBOSE: Searching values for last component"
     608                    " of specified path.\n");
    585609
    586610  for(i=0; (i < cur->num_values); i++)
     
    594618      if(path != NULL)
    595619        free(path);
     620
     621      if(print_verbose)
     622        fprintf(stderr, "VERBOSE: Found final path element as value.\n");
     623
    596624      return 0;
    597625    }
    598626  }
     627
     628  if(print_verbose)
     629    fprintf(stderr, "VERBOSE: Searching keys for last component"
     630                    " of specified path.\n");
    599631
    600632  while((sub = regfio_fetch_subkey(f, cur)) != NULL)
     
    611643      strcat(prefix, "/");
    612644      strcat(prefix, sub->keyname);
     645
     646      if(print_verbose)
     647        fprintf(stderr, "VERBOSE: Found final path element as key.\n");
     648
    613649      printKeyTree(f, sub_nk_stack, prefix);
     650
    614651      return 0;
    615652    }
    616653  }
     654
     655  if(print_verbose)
     656    fprintf(stderr, "VERBOSE: Could not find last element of path.\n");
    617657
    618658  return 1;
Note: See TracChangeset for help on using the changeset viewer.