Changeset 118
- Timestamp:
- 12/16/06 23:43:37 (2 years ago)
- Files:
-
- honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry.pm (modified) (7 diffs)
- honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Makefile (modified) (1 diff)
- honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.pm (modified) (1 diff)
- honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.yp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry.pm
r116 r118 132 132 use Filesys::CygwinPaths qw(:all); 133 133 134 # Use Binary Search Library. 135 use Search::Binary; 136 134 137 ####################################################################### 135 138 # Module Initialization # … … 251 254 use Filesys::CygwinPaths qw(:all); 252 255 256 # Make sure Search::Binary loads 257 BEGIN { use_ok('Search::Binary') 258 or diag("Can't load Search::Binary package. Check to make sure the package library is correctly listed within the path."); } 259 require_ok('Search::Binary'); 260 can_ok('Search::Binary', 'binary_search'); 261 use Search::Binary; 262 253 263 # Make sure HoneyClient::Agent::Integrity::Registry::Parser loads 254 264 BEGIN { use_ok('HoneyClient::Agent::Integrity::Registry::Parser') … … 347 357 # is the file parser, and the hash value is the entry counter. 348 358 _currentEntryIndex => { }, 359 360 # A helper variable, used to keep track of the last search index, 361 # used by the _search() function. 362 _last_search_index => undef, 363 364 # A helper variable, used to set the array of known line numbers, 365 # where each array entry is a line number, which separates a different 366 # group block. 367 _group_index_linenums => [ ], 349 368 ); 350 369 … … 617 636 Carp::croak("Error: Unable to unlink temporary file '" . $tmpfile ."'."); 618 637 } 638 } 639 640 # Helper function, designed to be called from within the 641 # Search::Binary::binary_search() function, in order to allow 642 # the binary_search to properly read in group line number data from 643 # the default array reference. 644 # 645 # For more information about how this function operates, please 646 # see the Search::Binary POD documentation. 647 # 648 # Inputs: arrayref, value_to_compare, current_array_index 649 # Outputs: comparison, last_valid_array_index 650 sub _search { 651 # Extract arguments. 652 my ($self, $value_to_compare, $current_array_index) = @_; 653 654 # Increment the search index, if the current one is undef. 655 if (defined($current_array_index)) { 656 $self->{'_last_search_index'} = $current_array_index; 657 } else { 658 $self->{'_last_search_index'}++; 659 } 660 661 # Perform a comparison, if the array entry is defined. 662 if (defined(@{$self->{'_group_index_linenums'}}[$self->{'_last_search_index'}])) { 663 return($value_to_compare <=> @{$self->{'_group_index_linenums'}}[$self->{'_last_search_index'}], 664 $self->{'_last_search_index'}); 665 } 666 667 # Array entry not found, return undef with this position. 668 return (undef, $self->{'_last_search_index'}); 619 669 } 620 670 … … 747 797 $after_total_linenums += $after_parser->getCurrentLineCount(); 748 798 799 $self->{'_group_index_linenums'} = $before_linenums; 800 my $found_index = binary_search(0, scalar(@{$before_linenums}) - 1, $before_total_linenums, \&_search, $self); 801 802 # Find the group before corresponding the matched line number. 803 if ($found_index > 0) { 804 $found_index--; 805 } 806 807 print("FOUND INDEX: " . Dumper($found_index) . "\n"); 808 print("FOUND B_LINENO: " . Dumper(@{$before_linenums}[$found_index]) . "\n"); 809 print("FOUND TYPE: " . Dumper(@{$diff_types}[$found_index]) . "\n"); 810 $diff_type = @{$diff_types}[$found_index]; 811 749 812 print("Before Current Linenums: ", Dumper($before_total_linenums) . "\n"); 750 813 print("After Current Linenums: ", Dumper($after_total_linenums) . "\n"); … … 880 943 # Else, if the after group doesn't exist, or if the before group exists and the 881 944 # before group name is alphabetically earlier than the after group name... 882 # but verify that our $diff_type signifies a deletion (otherwise, the groups945 # but verify that our $diff_type signifies a deletion or change (otherwise, the groups 883 946 # may not be sorted alphabetically). 884 947 } elsif (!defined($after_group) || defined($before_group) && 885 (( $diff_type eq 'd') &&948 ((($diff_type eq 'd') || ($diff_type eq 'c')) && 886 949 ($self->_cmpGroup($before_group, $after_group) < 0))) { 887 950 … … 964 1027 $changeState--; 965 1028 } 966 # TODO: delete.967 #$Data::Dumper::Terse = 1;968 #$Data::Dumper::Indent = 1;969 #print "Current Change: " . Dumper($currentChange) . "\n";970 1029 } 971 1030 972 1031 } 973 974 # TODO: delete.975 #return $changes;976 1032 } 977 1033 honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Makefile
r116 r118 2 2 3 3 Parser: 4 chmod 644 Makefile 5 chmod 644 Parser.yp 4 6 yapp -m HoneyClient::Agent::Integrity::Registry::Parser Parser.yp 5 7 honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.pm
r117 r118 687 687 # Search::Binary::binary_search() function, in order to allow 688 688 # the binary_search to properly read in group index data from 689 # the default arrayreference.689 # the default parser reference. 690 690 # 691 691 # For more information about how this function operates, please honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.yp
r117 r118 532 532 # Search::Binary::binary_search() function, in order to allow 533 533 # the binary_search to properly read in group index data from 534 # the default arrayreference.534 # the default parser reference. 535 535 # 536 536 # For more information about how this function operates, please
