Changeset 37
- Timestamp:
- 07/30/05 23:25:40 (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile
r36 r37 12 12 $(CC) $(CFLAGS) $(OPTS) -o $@ reglookup.o $(LIBS) 13 13 14 reglookup.o: 14 reglookup.o: reglookup.c 15 15 $(CC) $(CFLAGS) $(OPTS) -c -o $@ reglookup.c 16 16 -
trunk/src/reglookup.c
r36 r37 28 28 #include "../include/void_stack.h" 29 29 30 30 /* XXX: this needs to be rewritten to malloc each resulting string, instead of 31 * altering them in place 32 */ 31 33 void_stack* path2Stack(const char* s) 32 34 { 33 35 void_stack* ret_val = void_stack_new(1024); 34 char* cur = strdup(s);35 36 char* next = NULL; 36 37 char* cur; 38 if (s == NULL) 39 return ret_val; 40 else 41 cur = strdup(s); 42 37 43 while((next = strrchr(cur, '/')) != NULL) 38 44 { … … 51 57 { 52 58 const REGF_NK_REC* cur; 53 u nsigned intbuf_left = 127;54 u nsigned intbuf_len = buf_left+1;55 u nsigned intname_len = 0;56 u nsigned intgrow_amt;59 uint32 buf_left = 127; 60 uint32 buf_len = buf_left+1; 61 uint32 name_len = 0; 62 uint32 grow_amt; 57 63 char* buf; 58 64 char* new_buf; … … 81 87 if(name_len+1 > buf_left) 82 88 { 83 grow_amt = (u nsigned int)(buf_len/2);89 grow_amt = (uint32)(buf_len/2); 84 90 buf_len += name_len+1+grow_amt-buf_left; 85 91 if((new_buf = realloc(buf, buf_len)) == NULL) … … 112 118 void printValueList(REGF_NK_REC* nk, char* prefix) 113 119 { 114 u nsigned inti;120 uint32 i; 115 121 116 122 for(i=0; i < nk->num_values; i++) 117 123 printValue(&nk->values[i], prefix); 118 124 } 125 119 126 120 127 /* XXX: this function is god-awful. Needs to be re-designed. */ … … 179 186 char* cur_str = NULL; 180 187 bool found_cur = true; 181 u nsigned inti;182 u nsigned shortpath_depth;188 uint32 i; 189 uint16 path_depth; 183 190 if(path_stack == NULL) 184 191 return -1; … … 210 217 211 218 if(!found_cur) 212 return 0;219 return 1; 213 220 } 214 221 … … 242 249 243 250 251 static void usage(void) 252 { 253 fprintf(stderr, "Usage: readreg [-f <PREFIX_FILTER>] [-t <TYPE_FILTER>] " 254 "[-v] [-s] <REGISTRY_FILE>\n"); 255 /* XXX: replace version string with Subversion property? */ 256 fprintf(stderr, "Version: 0.2\n"); 257 fprintf(stderr, "\n\t-v\t sets verbose mode."); 258 fprintf(stderr, "\n\t-f\t a simple prefix filter."); 259 fprintf(stderr, "\n\t-t\t restrict results to a specific type."); 260 fprintf(stderr, "\n\t-s\t prints security descriptors."); 261 fprintf(stderr, "\n"); 262 } 263 264 /* Globals, influenced by command line parameters */ 265 bool print_verbose = false; 266 bool print_security = false; 267 bool prefix_filter_enabled = false; 268 bool type_filter_enabled = false; 269 char* prefix_filter = NULL; 270 char* type_filter = NULL; 271 char* registry_file = NULL; 272 273 244 274 int main(int argc, char** argv) 245 275 { … … 249 279 REGF_NK_REC* root; 250 280 int retr_path_ret; 251 char* path = "/ControlSet002/Services/Eventlog/"; 252 281 uint32 argi; 282 283 /* Process command line arguments */ 253 284 if(argc < 2) 254 285 { 255 286 printf("ERROR: Requires 1 argument.\n"); 256 return 1; 257 } 258 259 f = regfio_open( argv[1] ); 287 usage(); 288 exit(1); 289 } 290 291 for(argi = 1; argi < argc; argi++) 292 { 293 if (strcmp("-f", argv[argi]) == 0) 294 { 295 if(++argi > argc) 296 { 297 fprintf(stderr, "ERROR: '-f' option requires parameter.\n"); 298 usage(); 299 exit(1); 300 } 301 if((prefix_filter = strdup(argv[argi])) == NULL) 302 { 303 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 304 exit(2); 305 } 306 prefix_filter_enabled = true; 307 } 308 else if (strcmp("-t", argv[argi]) == 0) 309 { 310 if(++argi > argc) 311 { 312 fprintf(stderr, "ERROR: '-t' option requires parameter.\n"); 313 usage(); 314 exit(1); 315 } 316 if((prefix_filter = strdup(argv[argi])) == NULL) 317 { 318 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 319 exit(2); 320 } 321 type_filter_enabled = true; 322 } 323 else if (strcmp("-s", argv[argi]) == 0) 324 print_security = true; 325 else if (strcmp("-v", argv[argi]) == 0) 326 print_verbose = true; 327 else if (argv[argi][0] == '-') 328 { 329 fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]); 330 usage(); 331 exit(1); 332 } 333 else 334 { 335 if((registry_file = strdup(argv[argi])) == NULL) 336 { 337 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 338 exit(2); 339 } 340 } 341 } 342 343 f = regfio_open(registry_file); 344 if(f == NULL) 345 { 346 fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file); 347 exit(1); 348 } 260 349 root = regfio_rootkey(f); 261 262 350 nk_stack = void_stack_new(1024); 351 263 352 if(void_stack_push(nk_stack, root)) 264 353 { 265 path_stack = path2Stack(p ath);354 path_stack = path2Stack(prefix_filter); 266 355 if(void_stack_size(path_stack) < 1) 267 356 printKeyTree(f, nk_stack, ""); 268 357 else 269 358 { 270 retr_path_ret = retrievePath(f, nk_stack, 271 path_stack); 359 retr_path_ret = retrievePath(f, nk_stack, path_stack); 272 360 if(retr_path_ret == 1) 273 printf("WARNING: specified path not found.\n");361 fprintf(stderr, "WARNING: specified path not found.\n"); 274 362 else if(retr_path_ret != 0) 275 printf("ERROR\n"); 276 } 363 fprintf(stderr, "ERROR:\n"); 364 } 365 } 366 else 367 { 368 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 369 exit(2); 277 370 } 278 371 void_stack_destroy(nk_stack);
Note: See TracChangeset
for help on using the changeset viewer.