Changeset 118

Show
Ignore:
Timestamp:
12/16/06 23:43:37 (2 years ago)
Author:
kindlund
Message:

Completed draft version of code; everything appears to work… still need to rigorously test it and cleanup debug logic, along with documentation and unit testing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry.pm

    r116 r118  
    132132use Filesys::CygwinPaths qw(:all); 
    133133 
     134# Use Binary Search Library. 
     135use Search::Binary; 
     136 
    134137####################################################################### 
    135138# Module Initialization                                               # 
     
    251254use Filesys::CygwinPaths qw(:all); 
    252255 
     256# Make sure Search::Binary loads 
     257BEGIN { 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."); } 
     259require_ok('Search::Binary'); 
     260can_ok('Search::Binary', 'binary_search'); 
     261use Search::Binary; 
     262 
    253263# Make sure HoneyClient::Agent::Integrity::Registry::Parser loads 
    254264BEGIN { use_ok('HoneyClient::Agent::Integrity::Registry::Parser') 
     
    347357    # is the file parser, and the hash value is the entry counter. 
    348358    _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 => [ ], 
    349368); 
    350369 
     
    617636        Carp::croak("Error: Unable to unlink temporary file '" . $tmpfile ."'."); 
    618637    } 
     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 
     650sub _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'}); 
    619669} 
    620670 
     
    747797            $after_total_linenums += $after_parser->getCurrentLineCount(); 
    748798 
     799$self->{'_group_index_linenums'} = $before_linenums; 
     800my $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. 
     803if ($found_index > 0) { 
     804    $found_index--; 
     805} 
     806 
     807print("FOUND INDEX: " . Dumper($found_index) . "\n"); 
     808print("FOUND B_LINENO: " . Dumper(@{$before_linenums}[$found_index]) . "\n"); 
     809print("FOUND TYPE: " . Dumper(@{$diff_types}[$found_index]) . "\n"); 
     810$diff_type = @{$diff_types}[$found_index]; 
     811 
    749812print("Before Current Linenums: ", Dumper($before_total_linenums) . "\n"); 
    750813print("After Current Linenums: ", Dumper($after_total_linenums) . "\n"); 
     
    880943                # Else, if the after group doesn't exist, or if the before group exists and the 
    881944                # before group name is alphabetically earlier than the after group name... 
    882                 # but verify that our $diff_type signifies a deletion (otherwise, the groups 
     945                # but verify that our $diff_type signifies a deletion or change (otherwise, the groups 
    883946                # may not be sorted alphabetically). 
    884947            } elsif (!defined($after_group) || defined($before_group) && 
    885                      (($diff_type eq 'd') && 
     948                     ((($diff_type eq 'd') || ($diff_type eq 'c')) && 
    886949                      ($self->_cmpGroup($before_group, $after_group) < 0))) { 
    887950 
     
    9641027                $changeState--; 
    9651028            } 
    966 # TODO: delete. 
    967 #$Data::Dumper::Terse = 1; 
    968 #$Data::Dumper::Indent = 1; 
    969 #print "Current Change: " . Dumper($currentChange) . "\n"; 
    9701029        } 
    9711030 
    9721031    } 
    973  
    974     # TODO: delete. 
    975     #return $changes; 
    9761032} 
    9771033 
  • honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Makefile

    r116 r118  
    22 
    33Parser: 
     4    chmod 644 Makefile 
     5    chmod 644 Parser.yp 
    46    yapp -m HoneyClient::Agent::Integrity::Registry::Parser Parser.yp 
    57 
  • honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.pm

    r117 r118  
    687687# Search::Binary::binary_search() function, in order to allow 
    688688# the binary_search to properly read in group index data from 
    689 # the default array reference. 
     689# the default parser reference. 
    690690# 
    691691# For more information about how this function operates, please 
  • honeyclient/branches/bug/42/lib/HoneyClient/Agent/Integrity/Registry/Parser.yp

    r117 r118  
    532532# Search::Binary::binary_search() function, in order to allow 
    533533# the binary_search to properly read in group index data from 
    534 # the default array reference. 
     534# the default parser reference. 
    535535# 
    536536# For more information about how this function operates, please