- Timestamp:
- 05/14/05 19:44:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/reglookup.c
r6 r7 43 43 #include <stdio.h> 44 44 #include <stdlib.h> 45 #include <stdbool.h> 45 46 #include <errno.h> 46 47 #include <assert.h> … … 386 387 387 388 static 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); 390 390 static int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf, 391 const char *path , const char* filter_prefix);391 const char *path); 392 392 static REG_KEY *nt_find_key_by_name(REG_KEY *tree, char *key); 393 393 static int print_key(const char *path, char *name, char *class_name, int root, … … 397 397 int last); 398 398 399 static 400 int print_sec(SEC_DESC *sec_desc); 399 static int print_sec(SEC_DESC *sec_desc); 400 401 402 /* Globals */ 403 404 char* prefix_filter = ""; 405 char* type_filter = ""; 406 bool type_filter_enabled = false; 407 401 408 402 409 unsigned int str_is_prefix(const char* p, const char* s) … … 462 469 static 463 470 int nt_val_list_iterator(REGF *regf, REG_KEY *key_tree, int bf, char *path, 464 int terminal , const char* filter_prefix)471 int terminal) 465 472 { 466 473 int i; 467 474 VAL_LIST* val_list = key_tree->values; 468 475 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; } 487 491 } 488 492 … … 492 496 static 493 497 int nt_key_list_iterator(REGF *regf, KEY_LIST *key_list, int bf, 494 const char *path , const char* filter_prefix)498 const char *path) 495 499 { 496 500 int i; … … 501 505 for (i=0; i < key_list->key_count; i++) 502 506 { 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)) 504 508 return 0; 505 509 } … … 509 513 static 510 514 int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf, 511 const char *path , const char* filter_prefix)515 const char *path) 512 516 { 513 517 int path_len = strlen(path); … … 517 521 return -1; 518 522 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 519 531 /* 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)) 522 534 { 535 if (!type_filter_enabled || (strcmp(type_filter, "KEY") == 0)) 536 printf("%s%s:KEY\n", path, key_tree->name); 537 523 538 /*XXX: print_key() is doing nothing right now, can probably be removed. */ 524 539 if (!print_key(path, key_tree->name, … … 538 553 } 539 554 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 548 555 /* 549 556 * Now, iterate through the values in the val_list … … 551 558 if (key_tree->values && 552 559 !nt_val_list_iterator(regf, key_tree, bf, new_path, 553 (key_tree->values!=NULL) , filter_prefix))560 (key_tree->values!=NULL))) 554 561 { 555 562 free(new_path); … … 562 569 if (key_tree->sub_keys && 563 570 !nt_key_list_iterator(regf, key_tree->sub_keys, bf, 564 new_path , filter_prefix))571 new_path)) 565 572 { 566 573 free(new_path); … … 615 622 */ 616 623 c1 = lname; 617 c2 = strchr(c1, ' \\');624 c2 = strchr(c1, '/'); 618 625 if (c2) 619 626 { /* Split here ... */ … … 756 763 757 764 c1 = lname; 758 c2 = strchr(c1, ' \\');765 c2 = strchr(c1, '/'); 759 766 if (c2) { /* Split here ... */ 760 767 *c2 = 0; … … 864 871 865 872 const 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" },*/ 871 879 { 0, NULL }, 872 880 }; … … 933 941 if (verbose) 934 942 fprintf(stderr, "Len: %d\n", len); 935 943 936 944 ascii_max = sizeof(char)*len; 937 945 ascii = malloc(ascii_max+4); 938 946 if(ascii == NULL) 939 947 return NULL; 940 948 941 949 /* FIXME. This has to be fixed. It has to be UNICODE */ 942 950 uni_to_ascii(datap, ascii, len, ascii_max); … … 1946 1954 { 1947 1955 if (full_print) 1948 fprintf(stdout, "%s%s \\%s", path, name, newline);1956 fprintf(stdout, "%s%s/%s", path, name, newline); 1949 1957 1950 1958 return 1; … … 2090 2098 { 2091 2099 unsigned char* data_asc; 2092 2100 char* new_path; 2101 const char* str_type = val_to_str(val_type,reg_type_names); 2102 2093 2103 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); 2102 2132 return 1; 2103 2133 } … … 2106 2136 void usage(void) 2107 2137 { 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."); 2112 2142 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."); 2114 2145 fprintf(stderr, "\n"); 2115 2146 } … … 2123 2154 int opt; 2124 2155 int regf_opt = 1; 2125 char* filter_prefix = "";2126 2156 2127 2157 if (argc < 2) … … 2135 2165 */ 2136 2166 2137 while ((opt = getopt(argc, argv, "svkf: o:c:")) != EOF)2167 while ((opt = getopt(argc, argv, "svkf:t:o:c:")) != EOF) 2138 2168 { 2139 2169 switch (opt) … … 2141 2171 case 'f': 2142 2172 /*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; 2144 2183 regf_opt++; 2145 2184 break; … … 2205 2244 * to iterate over it. 2206 2245 */ 2207 nt_key_iterator(regf, regf->root, 0, "" , filter_prefix);2246 nt_key_iterator(regf, regf->root, 0, ""); 2208 2247 2209 2248 return 0;
Note: See TracChangeset
for help on using the changeset viewer.