Changeset 166
- Timestamp:
- 12/15/09 22:18:05 (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r165 r166 519 519 /* Main iterator API */ 520 520 /******************************************************************************/ 521 522 /* regfi_open: Attempts to open a registry hive and allocate related data 523 * structures. 524 * 525 * Arguments: 526 * filename -- A string containing the relative or absolute path of the 527 * registry hive to be opened. 528 * 529 * Returns: 530 * A reference to a newly allocated REGFI_FILE structure, if successful. 531 * NULL on error. 532 */ 521 533 REGFI_FILE* regfi_open(const char* filename); 522 int regfi_close(REGFI_FILE* r); 534 535 536 /* regfi_alloc: Parses file headers of an already open registry hive file and 537 * allocates related structures for further parsing. 538 * 539 * Arguments: 540 * fd -- A file descriptor of an already open file. Must be seekable. 541 * 542 * Returns: 543 * A reference to a newly allocated REGFI_FILE structure, if successful. 544 * NULL on error. 545 */ 546 REGFI_FILE* regfi_alloc(int fd); 547 548 549 /* regfi_close: Closes and frees an open registry hive. 550 * 551 * Arguments: 552 * file -- The registry structure to close. 553 * 554 * Returns: 555 * 0 on success, -1 on failure with errno set. 556 * errno codes are similar to those of close(2). 557 */ 558 int regfi_close(REGFI_FILE* file); 559 560 561 /* regfi_free: Frees a hive's data structures without closing the underlying 562 * file. 563 * 564 * Arguments: 565 * file -- The registry structure to free. 566 */ 567 void regfi_free(REGFI_FILE* file); 568 523 569 524 570 /* regfi_get_messages: Get errors, warnings, and/or verbose information … … 533 579 char* regfi_get_messages(REGFI_FILE* file); 534 580 581 582 /* regfi_set_message_mask: Set the verbosity level of errors and warnings 583 * generated by the library 584 * (as accessible via regfi_get_messages). 585 * 586 * Arguments: 587 * file -- the structure for the registry file 588 * mask -- an integer representing the types of messages desired. 589 * Acceptable values are created through bitwise ORs of 590 * REGFI_MSG_* values. For instance, if only errors and 591 * informational messages were desired (but not warnings), 592 * then one would specify: REGFI_MSG_ERROR|REGFI_MSG_INFO 593 * New REGFI_FILE structures are created with: 594 * REGFI_MSG_ERROR|REGFI_MSG_WARN 595 * Note that error and warning messages will continue to 596 * accumulate in memory if they are not fetched using 597 * regfi_get_messages and then freed by the caller. 598 * To disable error messages entirely, supply 0, which 599 * will prevent message accumulation. 600 * 601 * This may be called at any time and will take effect immediately. 602 */ 535 603 void regfi_set_message_mask(REGFI_FILE* file, uint16 mask); 536 604 … … 549 617 * REGFI_ENCODING_UTF8 550 618 * 551 * XXX: This encoding only applies to specific data552 * strings currently, but should apply to key553 * names and value names in the future.554 *555 619 * Returns: 556 620 * A newly allocated REGFI_ITERATOR. Must be free()d with regfi_iterator_free. … … 558 622 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, 559 623 REGFI_ENCODING output_encoding); 624 625 626 /* regfi_iterator_free: Frees a registry file iterator previously created by 627 * regfi_iterator_new. 628 * 629 * This does not affect the underlying registry file's allocation status. 630 * 631 * Arguments: 632 * file -- the iterator to be freed 633 */ 560 634 void regfi_iterator_free(REGFI_ITERATOR* i); 635 636 637 /* regfi_iterator_down: Traverse deeper into the registry tree at the 638 * current subkey. 639 * 640 * Arguments: 641 * i -- the iterator 642 * 643 * Returns: 644 * true on success, false on failure. Note that subkey and value indexes 645 * are preserved. That is, if a regfi_iterator_up call occurs later 646 * (reversing the effect of this call) then the subkey and value referenced 647 * prior to the regfi_iterator_down call will still be referenced. This 648 * makes depth-first iteration particularly easy. 649 */ 561 650 bool regfi_iterator_down(REGFI_ITERATOR* i); 651 652 653 /* regfi_iterator_up: Traverse up to the current key's parent key. 654 * 655 * Arguments: 656 * i -- the iterator 657 * 658 * Returns: 659 * true on success, false on failure. Any subkey or value state 660 * associated with the current key is lost. 661 */ 562 662 bool regfi_iterator_up(REGFI_ITERATOR* i); 663 664 665 /* regfi_iterator_to_root: Traverse up to the root key of the hive. 666 * 667 * Arguments: 668 * i -- the iterator 669 * 670 * Returns: 671 * true on success, false on failure. 672 */ 563 673 bool regfi_iterator_to_root(REGFI_ITERATOR* i); 564 674 675 676 /* regfi_iterator_walk_path: Traverse down multiple levels in the registry hive. 677 * 678 * Arguments: 679 * i -- the iterator 680 * path -- a list of key names representing the path. This list must 681 * contain NUL terminated strings. The list itself is 682 * terminated with a NULL pointer. All path elements must be 683 * keys; value names are not accepted (even as the last 684 * element). 685 * 686 * XXX: This currently only accepts ASCII key names. Need to look into 687 * accepting other encodings. 688 * 689 * Returns: 690 * true on success, false on failure. If any element of path is not found, 691 * false will be returned and the iterator will remain in its original 692 * position. 693 */ 565 694 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, 566 695 const char** path); 696 697 698 /* regfi_iterator_cur_key: Returns the currently referenced key. 699 * 700 * Arguments: 701 * i -- the iterator 702 * 703 * Returns: 704 * A read-only key structure for the current key, or NULL on failure. 705 */ 567 706 const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 707 708 709 /* regfi_iterator_cur_sk: Returns the SK (security) record referenced by the 710 * current key. 711 * 712 * Arguments: 713 * i -- the iterator 714 * 715 * Returns: 716 * A read-only SK structure, or NULL on failure. 717 */ 568 718 const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i); 569 719 720 721 /* regfi_iterator_first_subkey: Sets the internal subkey index to the first 722 * subkey referenced by the current key. 723 * 724 * Arguments: 725 * i -- the iterator 726 * 727 * Returns: 728 * A read-only key structure for the newly referenced first subkey, 729 * or NULL on failure. Failure may be due to a lack of any subkeys or other 730 * errors. 731 */ 570 732 REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); 733 734 735 /* regfi_iterator_cur_subkey: Returns the currently indexed subkey. 736 * 737 * Arguments: 738 * i -- the iterator 739 * 740 * Returns: 741 * A newly allocated key structure for the currently referenced subkey, 742 * or NULL on failure. Newly allocated keys must be freed with 743 * regfi_free_key. 744 */ 571 745 REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); 572 746 REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); -
trunk/lib/regfi.c
r165 r166 1271 1271 1272 1272 1273 /******************************************************************* 1274 * Open the registry file and then read in the REGF block to get the 1275 * first hbin offset. 1276 *******************************************************************/ 1273 /****************************************************************************** 1274 ******************************************************************************/ 1277 1275 REGFI_FILE* regfi_open(const char* filename) 1276 { 1277 REGFI_FILE* ret_val; 1278 int fd; 1279 1280 /* open an existing file */ 1281 if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1) 1282 { 1283 /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/ 1284 return NULL; 1285 } 1286 1287 ret_val = regfi_alloc(fd); 1288 1289 if(ret_val == NULL) 1290 close(fd); 1291 1292 return ret_val; 1293 } 1294 1295 1296 /****************************************************************************** 1297 ******************************************************************************/ 1298 REGFI_FILE* regfi_alloc(int fd) 1278 1299 { 1279 1300 struct stat sbuf; … … 1281 1302 REGFI_HBIN* hbin = NULL; 1282 1303 uint32 hbin_off, file_length, cache_secret; 1283 int fd;1284 1304 bool rla; 1285 1305 1286 /* open an existing file */1287 if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1)1288 {1289 /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/1290 return NULL;1291 }1292 1293 1306 /* Determine file length. Must be at least big enough 1294 1307 * for the header and one hbin. … … 1300 1313 return NULL; 1301 1314 1302 /* read in an existing file*/1315 /* Read file header */ 1303 1316 if ((rb = regfi_parse_regf(fd, true)) == NULL) 1304 1317 { 1305 /* fprintf(stderr, "regfi_open: Failed to read initial REGF block\n"); */ 1306 close(fd); 1318 /* fprintf(stderr, "regfi_alloc: Failed to read initial REGF block\n"); */ 1307 1319 return NULL; 1308 1320 } … … 1312 1324 if(rb->hbins == NULL) 1313 1325 { 1314 /* fprintf(stderr, "regfi_open: Failed to create HBIN list.\n"); */ 1315 close(fd); 1326 /* fprintf(stderr, "regfi_alloc: Failed to create HBIN list.\n"); */ 1316 1327 talloc_free(rb); 1317 1328 return NULL; … … 1350 1361 /****************************************************************************** 1351 1362 ******************************************************************************/ 1352 int regfi_close(REGFI_FILE *file)1363 int regfi_close(REGFI_FILE* file) 1353 1364 { 1354 1365 int fd; … … 1361 1372 file->fd = -1; 1362 1373 1363 range_list_free(file->hbins); 1364 1365 if(file->sk_cache != NULL) 1366 lru_cache_destroy(file->sk_cache); 1374 regfi_free(file); 1375 1376 return close(fd); 1377 } 1378 1379 1380 /****************************************************************************** 1381 ******************************************************************************/ 1382 void regfi_free(REGFI_FILE *file) 1383 { 1384 if(file->last_message != NULL) 1385 free(last_message); 1367 1386 1368 1387 talloc_free(file); 1369 return close(fd);1370 1388 } 1371 1389 … … 2077 2095 2078 2096 2079 /******************************************************************* 2097 /****************************************************************************** 2080 2098 * Convert from UTF-16LE to specified character set. 2081 2099 * On error, returns a negative errno code. 2082 ******************************************************************* /2100 *****************************************************************************/ 2083 2101 int32 regfi_conv_charset(const char* input_charset, const char* output_charset, 2084 2102 uint8* input, char* output, … … 2901 2919 uint16 num_chunks, bool strict) 2902 2920 { 2903 uint32 cell_length, chunk_offset , data_left;2921 uint32 cell_length, chunk_offset; 2904 2922 range_list* ret_val; 2905 2923 uint16 i; … … 2911 2929 goto fail; 2912 2930 2913 for(i=0; (i<num_chunks) && (data_left>0); i++)2931 for(i=0; i<num_chunks; i++) 2914 2932 { 2915 2933 chunk_offset = offsets[i]+REGFI_REGF_SIZE;
Note: See TracChangeset
for help on using the changeset viewer.