Index: src/reglookup.c
===================================================================
--- src/reglookup.c	(revision 6)
+++ src/reglookup.c	(revision 7)
@@ -43,4 +43,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <assert.h>
@@ -386,8 +387,7 @@
 
 static int nt_val_list_iterator(REGF *regf,  REG_KEY *key_tree, int bf, 
-                                char *path, int terminal, 
-                                const char* filter_prefix);
+                                char *path, int terminal);
 static int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf,
-			   const char *path, const char* filter_prefix);
+			   const char *path);
 static REG_KEY *nt_find_key_by_name(REG_KEY *tree, char *key);
 static int print_key(const char *path, char *name, char *class_name, int root,
@@ -397,6 +397,13 @@
                      int last);
 
-static
-int print_sec(SEC_DESC *sec_desc);
+static int print_sec(SEC_DESC *sec_desc);
+
+
+/* Globals */
+
+char* prefix_filter = "";
+char* type_filter = "";
+bool type_filter_enabled = false;
+
 
 unsigned int str_is_prefix(const char* p, const char* s)
@@ -462,27 +469,24 @@
 static
 int nt_val_list_iterator(REGF *regf,  REG_KEY *key_tree, int bf, char *path,
-			 int terminal, const char* filter_prefix)
+			 int terminal)
 {
   int i;
   VAL_LIST* val_list = key_tree->values;
 
-  if (str_is_prefix(filter_prefix, path))
-  {  
-    for (i=0; i<val_list->val_count; i++) 
-    {
-      /*XXX: print_key() is doing nothing right now, can probably be removed. */
-      if (!print_key(path, key_tree->name,
-		     key_tree->class_name,
-		     (key_tree->type == REG_ROOT_KEY),
-		     (key_tree->sub_keys == NULL),
-		     (key_tree->values?(key_tree->values->val_count):0),
-		     "\n") ||
-	  !print_val(path, val_list->vals[i]->name,val_list->vals[i]->data_type,
-		     val_list->vals[i]->data_len, val_list->vals[i]->data_blk,
-		     terminal,
-		     (i == 0),
-		     (i == val_list->val_count)))
-      { return 0; }
-    }
+  for (i=0; i<val_list->val_count; i++) 
+  {
+    /*XXX: print_key() is doing nothing right now, can probably be removed. */
+    if (!print_key(path, key_tree->name,
+		   key_tree->class_name,
+		   (key_tree->type == REG_ROOT_KEY),
+		   (key_tree->sub_keys == NULL),
+		   (key_tree->values?(key_tree->values->val_count):0),
+		   "\n") ||
+	!print_val(path, val_list->vals[i]->name,val_list->vals[i]->data_type,
+		   val_list->vals[i]->data_len, val_list->vals[i]->data_blk,
+		   terminal,
+		   (i == 0),
+		   (i == val_list->val_count)))
+    { return 0; }
   }
 
@@ -492,5 +496,5 @@
 static
 int nt_key_list_iterator(REGF *regf, KEY_LIST *key_list, int bf, 
-			 const char *path, const char* filter_prefix)
+			 const char *path)
 {
   int i;
@@ -501,5 +505,5 @@
   for (i=0; i < key_list->key_count; i++) 
   {
-    if (!nt_key_iterator(regf, key_list->keys[i], bf, path, filter_prefix)) 
+    if (!nt_key_iterator(regf, key_list->keys[i], bf, path)) 
       return 0;
   }
@@ -509,5 +513,5 @@
 static
 int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf, 
-		    const char *path, const char* filter_prefix)
+		    const char *path)
 {
   int path_len = strlen(path);
@@ -517,8 +521,19 @@
     return -1;
 
+  new_path = (char *)malloc(path_len + 1 + strlen(key_tree->name) + 1);
+  if (!new_path) 
+    return 0; /* Errors? */
+  new_path[0] = '\0';
+  strcat(new_path, path);
+  strcat(new_path, key_tree->name);
+  strcat(new_path, "/");
+
   /* List the key first, then the values, then the sub-keys */
-  /*printf("filter_prefix: %s, path: %s\n", filter_prefix, path);*/
-  if (str_is_prefix(filter_prefix, path))
+  /*printf("prefix_filter: %s, path: %s\n", prefix_filter, path);*/
+  if (str_is_prefix(prefix_filter, new_path))
   {
+    if (!type_filter_enabled || (strcmp(type_filter, "KEY") == 0))
+      printf("%s%s:KEY\n", path, key_tree->name);
+
     /*XXX: print_key() is doing nothing right now, can probably be removed. */
     if (!print_key(path, key_tree->name,
@@ -538,12 +553,4 @@
   }
 
-  new_path = (char *)malloc(path_len + 1 + strlen(key_tree->name) + 1);
-  if (!new_path) 
-    return 0; /* Errors? */
-  new_path[0] = '\0';
-  strcat(new_path, path);
-  strcat(new_path, key_tree->name);
-  strcat(new_path, "\\");
-
   /*
    * Now, iterate through the values in the val_list 
@@ -551,5 +558,5 @@
   if (key_tree->values &&
       !nt_val_list_iterator(regf, key_tree, bf, new_path, 
-			    (key_tree->values!=NULL), filter_prefix))
+			    (key_tree->values!=NULL)))
   {
     free(new_path);
@@ -562,5 +569,5 @@
   if (key_tree->sub_keys && 
       !nt_key_list_iterator(regf, key_tree->sub_keys, bf, 
-                            new_path, filter_prefix)) 
+                            new_path)) 
   {
     free(new_path);
@@ -615,5 +622,5 @@
    */
   c1 = lname;
-  c2 = strchr(c1, '\\');
+  c2 = strchr(c1, '/');
   if (c2) 
   { /* Split here ... */
@@ -756,5 +763,5 @@
 
   c1 = lname;
-  c2 = strchr(c1, '\\');
+  c2 = strchr(c1, '/');
   if (c2) { /* Split here ... */
     *c2 = 0;
@@ -864,9 +871,10 @@
 
 const VAL_STR reg_type_names[] = {
-   { REG_TYPE_REGSZ,    "REG_SZ" },
-   { REG_TYPE_EXPANDSZ, "REG_EXPAND_SZ" },
-   { REG_TYPE_BIN,      "REG_BIN" },
-   { REG_TYPE_DWORD,    "REG_DWORD" },
-   { REG_TYPE_MULTISZ,  "REG_MULTI_SZ" },
+   { REG_TYPE_REGSZ,    "SZ" },
+   { REG_TYPE_EXPANDSZ, "EXPAND_SZ" },
+   { REG_TYPE_BIN,      "BIN" },
+   { REG_TYPE_DWORD,    "DWORD" },
+   { REG_TYPE_MULTISZ,  "MULTI_SZ" },
+   /*   { REG_TYPE_KEY,      "KEY" },*/
    { 0, NULL },
 };
@@ -933,10 +941,10 @@
     if (verbose)
       fprintf(stderr, "Len: %d\n", len);
-
+    
     ascii_max = sizeof(char)*len;
     ascii = malloc(ascii_max+4);
     if(ascii == NULL)
       return NULL;
-
+    
     /* FIXME. This has to be fixed. It has to be UNICODE */ 
     uni_to_ascii(datap, ascii, len, ascii_max);
@@ -1946,5 +1954,5 @@
 {
   if (full_print)
-    fprintf(stdout, "%s%s\\%s", path, name, newline);
+    fprintf(stdout, "%s%s/%s", path, name, newline);
 
   return 1;
@@ -2090,14 +2098,36 @@
 {
   unsigned char* data_asc;
-  
+  char* new_path;
+  const char* str_type = val_to_str(val_type,reg_type_names);
+
   if(!val_name)
-    val_name = "<No Name>";
-
-  fprintf(stdout, "%s", path);
-  data_asc = data_to_ascii((unsigned char *)data_blk, data_len, val_type);
-  fprintf(stdout, "%s:%s=%s\n", val_name, val_to_str(val_type, reg_type_names),
-	  data_asc);
-  
-  free(data_asc);
+    val_name = "";
+  if(!str_type)
+    str_type = "";
+  if(!path)
+    path = "";
+
+  new_path = (char *)malloc(strlen(path)+ strlen(val_name) + 1);
+  if (!new_path)
+    return 0; /* Errors? */
+  new_path[0] = '\0';
+  strcat(new_path, path);
+  strcat(new_path, val_name);
+
+  if (str_is_prefix(prefix_filter, new_path))
+  {
+    if (!type_filter_enabled || (strcmp(type_filter, str_type) == 0))
+    {
+      if(!val_name)
+	val_name = "<No Name>";
+      
+      data_asc = data_to_ascii((unsigned char *)data_blk, data_len, val_type);
+      fprintf(stdout, "%s:%s=%s\n", new_path, str_type, data_asc);
+      
+      free(data_asc);
+    }
+  }
+
+  free(new_path);
   return 1;
 }
@@ -2106,10 +2136,11 @@
 void usage(void)
 {
-  fprintf(stderr, "Usage: readreg [-f<filterprefix>] [-v] [-p] [-k] [-s]"
-	  "<registryfile>\n");
-  fprintf(stderr, "Version: 0.1\n\n");
-  fprintf(stderr, "\n\t-v\t sets verbose mode");
+  fprintf(stderr, "Usage: readreg [-f<PREFIX_FILTER>] [-t<TYPE_FILTER>] "
+                  "[-v] [-p] [-k] [-s] <REGISTRY_FILE>\n");
+  fprintf(stderr, "Version: 0.1\n");
+  fprintf(stderr, "\n\t-v\t sets verbose mode.");
   fprintf(stderr, "\n\t-f\t a simple prefix filter.");
-  fprintf(stderr, "\n\t-s\t prints security descriptors");
+  fprintf(stderr, "\n\t-t\t restrict results to a specific type.");
+  fprintf(stderr, "\n\t-s\t prints security descriptors.");
   fprintf(stderr, "\n");
 }
@@ -2123,5 +2154,4 @@
   int opt; 
   int regf_opt = 1;
-  char* filter_prefix = "";
 
   if (argc < 2)
@@ -2135,5 +2165,5 @@
    */
 
-  while ((opt = getopt(argc, argv, "svkf:o:c:")) != EOF)
+  while ((opt = getopt(argc, argv, "svkf:t:o:c:")) != EOF)
   {
     switch (opt)
@@ -2141,5 +2171,14 @@
     case 'f':
       /*full_print = 1;*/
-      filter_prefix = strdup(optarg);
+      prefix_filter = strdup(optarg);
+      regf_opt++;
+      break;
+
+    case 't':
+      /* XXX: this should be converted to the integer form of types up front,
+       *      and then used to filter with a simple comparison later.
+       */
+      type_filter = strdup(optarg);
+      type_filter_enabled = true;
       regf_opt++;
       break;
@@ -2205,5 +2244,5 @@
    * to iterate over it.
    */
-  nt_key_iterator(regf, regf->root, 0, "", filter_prefix);
+  nt_key_iterator(regf, regf->root, 0, "");
 
   return 0;
