Changeset 7 for src


Ignore:
Timestamp:
05/14/05 19:44:00 (19 years ago)
Author:
tim
Message:

Fixed a bug in output.

Improved typing output.

Added type filter command line argument.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/reglookup.c

    r6 r7  
    4343#include <stdio.h>
    4444#include <stdlib.h>
     45#include <stdbool.h>
    4546#include <errno.h>
    4647#include <assert.h>
     
    386387
    387388static int nt_val_list_iterator(REGF *regf,  REG_KEY *key_tree, int bf,
    388                                 char *path, int terminal,
    389                                 const char* filter_prefix);
     389                                char *path, int terminal);
    390390static int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf,
    391                            const char *path, const char* filter_prefix);
     391                           const char *path);
    392392static REG_KEY *nt_find_key_by_name(REG_KEY *tree, char *key);
    393393static int print_key(const char *path, char *name, char *class_name, int root,
     
    397397                     int last);
    398398
    399 static
    400 int print_sec(SEC_DESC *sec_desc);
     399static int print_sec(SEC_DESC *sec_desc);
     400
     401
     402/* Globals */
     403
     404char* prefix_filter = "";
     405char* type_filter = "";
     406bool type_filter_enabled = false;
     407
    401408
    402409unsigned int str_is_prefix(const char* p, const char* s)
     
    462469static
    463470int nt_val_list_iterator(REGF *regf,  REG_KEY *key_tree, int bf, char *path,
    464                          int terminal, const char* filter_prefix)
     471                         int terminal)
    465472{
    466473  int i;
    467474  VAL_LIST* val_list = key_tree->values;
    468475
    469   if (str_is_prefix(filter_prefix, path))
    470   { 
    471     for (i=0; i<val_list->val_count; i++)
    472     {
    473       /*XXX: print_key() is doing nothing right now, can probably be removed. */
    474       if (!print_key(path, key_tree->name,
    475                      key_tree->class_name,
    476                      (key_tree->type == REG_ROOT_KEY),
    477                      (key_tree->sub_keys == NULL),
    478                      (key_tree->values?(key_tree->values->val_count):0),
    479                      "\n") ||
    480           !print_val(path, val_list->vals[i]->name,val_list->vals[i]->data_type,
    481                      val_list->vals[i]->data_len, val_list->vals[i]->data_blk,
    482                      terminal,
    483                      (i == 0),
    484                      (i == val_list->val_count)))
    485       { return 0; }
    486     }
     476  for (i=0; i<val_list->val_count; i++)
     477  {
     478    /*XXX: print_key() is doing nothing right now, can probably be removed. */
     479    if (!print_key(path, key_tree->name,
     480                   key_tree->class_name,
     481                   (key_tree->type == REG_ROOT_KEY),
     482                   (key_tree->sub_keys == NULL),
     483                   (key_tree->values?(key_tree->values->val_count):0),
     484                   "\n") ||
     485        !print_val(path, val_list->vals[i]->name,val_list->vals[i]->data_type,
     486                   val_list->vals[i]->data_len, val_list->vals[i]->data_blk,
     487                   terminal,
     488                   (i == 0),
     489                   (i == val_list->val_count)))
     490    { return 0; }
    487491  }
    488492
     
    492496static
    493497int nt_key_list_iterator(REGF *regf, KEY_LIST *key_list, int bf,
    494                          const char *path, const char* filter_prefix)
     498                         const char *path)
    495499{
    496500  int i;
     
    501505  for (i=0; i < key_list->key_count; i++)
    502506  {
    503     if (!nt_key_iterator(regf, key_list->keys[i], bf, path, filter_prefix))
     507    if (!nt_key_iterator(regf, key_list->keys[i], bf, path))
    504508      return 0;
    505509  }
     
    509513static
    510514int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf,
    511                     const char *path, const char* filter_prefix)
     515                    const char *path)
    512516{
    513517  int path_len = strlen(path);
     
    517521    return -1;
    518522
     523  new_path = (char *)malloc(path_len + 1 + strlen(key_tree->name) + 1);
     524  if (!new_path)
     525    return 0; /* Errors? */
     526  new_path[0] = '\0';
     527  strcat(new_path, path);
     528  strcat(new_path, key_tree->name);
     529  strcat(new_path, "/");
     530
    519531  /* List the key first, then the values, then the sub-keys */
    520   /*printf("filter_prefix: %s, path: %s\n", filter_prefix, path);*/
    521   if (str_is_prefix(filter_prefix, path))
     532  /*printf("prefix_filter: %s, path: %s\n", prefix_filter, path);*/
     533  if (str_is_prefix(prefix_filter, new_path))
    522534  {
     535    if (!type_filter_enabled || (strcmp(type_filter, "KEY") == 0))
     536      printf("%s%s:KEY\n", path, key_tree->name);
     537
    523538    /*XXX: print_key() is doing nothing right now, can probably be removed. */
    524539    if (!print_key(path, key_tree->name,
     
    538553  }
    539554
    540   new_path = (char *)malloc(path_len + 1 + strlen(key_tree->name) + 1);
    541   if (!new_path)
    542     return 0; /* Errors? */
    543   new_path[0] = '\0';
    544   strcat(new_path, path);
    545   strcat(new_path, key_tree->name);
    546   strcat(new_path, "\\");
    547 
    548555  /*
    549556   * Now, iterate through the values in the val_list
     
    551558  if (key_tree->values &&
    552559      !nt_val_list_iterator(regf, key_tree, bf, new_path,
    553                             (key_tree->values!=NULL), filter_prefix))
     560                            (key_tree->values!=NULL)))
    554561  {
    555562    free(new_path);
     
    562569  if (key_tree->sub_keys &&
    563570      !nt_key_list_iterator(regf, key_tree->sub_keys, bf,
    564                             new_path, filter_prefix))
     571                            new_path))
    565572  {
    566573    free(new_path);
     
    615622   */
    616623  c1 = lname;
    617   c2 = strchr(c1, '\\');
     624  c2 = strchr(c1, '/');
    618625  if (c2)
    619626  { /* Split here ... */
     
    756763
    757764  c1 = lname;
    758   c2 = strchr(c1, '\\');
     765  c2 = strchr(c1, '/');
    759766  if (c2) { /* Split here ... */
    760767    *c2 = 0;
     
    864871
    865872const VAL_STR reg_type_names[] = {
    866    { REG_TYPE_REGSZ,    "REG_SZ" },
    867    { REG_TYPE_EXPANDSZ, "REG_EXPAND_SZ" },
    868    { REG_TYPE_BIN,      "REG_BIN" },
    869    { REG_TYPE_DWORD,    "REG_DWORD" },
    870    { REG_TYPE_MULTISZ,  "REG_MULTI_SZ" },
     873   { REG_TYPE_REGSZ,    "SZ" },
     874   { REG_TYPE_EXPANDSZ, "EXPAND_SZ" },
     875   { REG_TYPE_BIN,      "BIN" },
     876   { REG_TYPE_DWORD,    "DWORD" },
     877   { REG_TYPE_MULTISZ,  "MULTI_SZ" },
     878   /*   { REG_TYPE_KEY,      "KEY" },*/
    871879   { 0, NULL },
    872880};
     
    933941    if (verbose)
    934942      fprintf(stderr, "Len: %d\n", len);
    935 
     943   
    936944    ascii_max = sizeof(char)*len;
    937945    ascii = malloc(ascii_max+4);
    938946    if(ascii == NULL)
    939947      return NULL;
    940 
     948   
    941949    /* FIXME. This has to be fixed. It has to be UNICODE */
    942950    uni_to_ascii(datap, ascii, len, ascii_max);
     
    19461954{
    19471955  if (full_print)
    1948     fprintf(stdout, "%s%s\\%s", path, name, newline);
     1956    fprintf(stdout, "%s%s/%s", path, name, newline);
    19491957
    19501958  return 1;
     
    20902098{
    20912099  unsigned char* data_asc;
    2092  
     2100  char* new_path;
     2101  const char* str_type = val_to_str(val_type,reg_type_names);
     2102
    20932103  if(!val_name)
    2094     val_name = "<No Name>";
    2095 
    2096   fprintf(stdout, "%s", path);
    2097   data_asc = data_to_ascii((unsigned char *)data_blk, data_len, val_type);
    2098   fprintf(stdout, "%s:%s=%s\n", val_name, val_to_str(val_type, reg_type_names),
    2099           data_asc);
    2100  
    2101   free(data_asc);
     2104    val_name = "";
     2105  if(!str_type)
     2106    str_type = "";
     2107  if(!path)
     2108    path = "";
     2109
     2110  new_path = (char *)malloc(strlen(path)+ strlen(val_name) + 1);
     2111  if (!new_path)
     2112    return 0; /* Errors? */
     2113  new_path[0] = '\0';
     2114  strcat(new_path, path);
     2115  strcat(new_path, val_name);
     2116
     2117  if (str_is_prefix(prefix_filter, new_path))
     2118  {
     2119    if (!type_filter_enabled || (strcmp(type_filter, str_type) == 0))
     2120    {
     2121      if(!val_name)
     2122        val_name = "<No Name>";
     2123     
     2124      data_asc = data_to_ascii((unsigned char *)data_blk, data_len, val_type);
     2125      fprintf(stdout, "%s:%s=%s\n", new_path, str_type, data_asc);
     2126     
     2127      free(data_asc);
     2128    }
     2129  }
     2130
     2131  free(new_path);
    21022132  return 1;
    21032133}
     
    21062136void usage(void)
    21072137{
    2108   fprintf(stderr, "Usage: readreg [-f<filterprefix>] [-v] [-p] [-k] [-s]"
    2109           "<registryfile>\n");
    2110   fprintf(stderr, "Version: 0.1\n\n");
    2111   fprintf(stderr, "\n\t-v\t sets verbose mode");
     2138  fprintf(stderr, "Usage: readreg [-f<PREFIX_FILTER>] [-t<TYPE_FILTER>] "
     2139                  "[-v] [-p] [-k] [-s] <REGISTRY_FILE>\n");
     2140  fprintf(stderr, "Version: 0.1\n");
     2141  fprintf(stderr, "\n\t-v\t sets verbose mode.");
    21122142  fprintf(stderr, "\n\t-f\t a simple prefix filter.");
    2113   fprintf(stderr, "\n\t-s\t prints security descriptors");
     2143  fprintf(stderr, "\n\t-t\t restrict results to a specific type.");
     2144  fprintf(stderr, "\n\t-s\t prints security descriptors.");
    21142145  fprintf(stderr, "\n");
    21152146}
     
    21232154  int opt;
    21242155  int regf_opt = 1;
    2125   char* filter_prefix = "";
    21262156
    21272157  if (argc < 2)
     
    21352165   */
    21362166
    2137   while ((opt = getopt(argc, argv, "svkf:o:c:")) != EOF)
     2167  while ((opt = getopt(argc, argv, "svkf:t:o:c:")) != EOF)
    21382168  {
    21392169    switch (opt)
     
    21412171    case 'f':
    21422172      /*full_print = 1;*/
    2143       filter_prefix = strdup(optarg);
     2173      prefix_filter = strdup(optarg);
     2174      regf_opt++;
     2175      break;
     2176
     2177    case 't':
     2178      /* XXX: this should be converted to the integer form of types up front,
     2179       *      and then used to filter with a simple comparison later.
     2180       */
     2181      type_filter = strdup(optarg);
     2182      type_filter_enabled = true;
    21442183      regf_opt++;
    21452184      break;
     
    22052244   * to iterate over it.
    22062245   */
    2207   nt_key_iterator(regf, regf->root, 0, "", filter_prefix);
     2246  nt_key_iterator(regf, regf->root, 0, "");
    22082247
    22092248  return 0;
Note: See TracChangeset for help on using the changeset viewer.