FusionInventory-Agent

 view release on metacpan or  search on metacpan

t/lib/FusionInventory/Test/Utils.pm  view on Meta::CPAN

                    }

                    $current_key = $current_key->{$key_path};
                }
            } else {
                $root_offset = scalar @path;
            }
            next;
        }

        if ($line =~ /^ " ([^"]+) " = dword:(\d+)/x) {
            my ($key, $value) = ($1, $2);
            $current_key->{'/' . $key} = "0x$value";
            next;
        }

        if ($line =~ /^ " ([^"]+) " = hex:([a-f0-9,]+)/x) {
            my ($key, $value) = ($1, $2);
            $current_key->{'/' . $key} = _binary($2);
            $current_variable = '/' . $key if $line =~ /\\$/;
            next;
        }

        if ($line =~ /^ " ([^"]+) " = " ([^"]*) "/x) {
            my ($key, $value) = ($1, $2);
            $value =~ s{\\\\}{\\}g;
            $current_key->{'/' . $key} = $value;
            next;
        }

        # Default key value
        if ($line =~ /^ \@ = " ([^"]*) "/x) {
            my $value = $1;
            $value =~ s{\\\\}{\\}g;
            $current_key->{'/'} = $value;
            next;
        }

        if ($line =~ /^ \s \s ([a-f0-9,]+)/x) {
            # continuation line
            next unless $current_variable;
            $current_key->{$current_variable} .= _binary($1);
            $current_variable = undef if $line !~ /\\$/;
        }


    }
    close $handle;

    bless( $root_key, "Win32::TieRegistry" );

    return $root_key;
}

sub _binary {
    my ($string) = @_;
    return pack("C*", map { hex($_) } split (/,/, $string));
}

sub unsetProxyEnvVar {
    foreach my $key (qw(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY)) {
         delete($ENV{$key});
    }
}

sub run_executable {
    my ($executable, $args) = @_;

    my @args = $args ? split(/\s+/, $args) : ();
    run(
        [ $EXECUTABLE_NAME, 'bin/' . $executable, @args ],
        \my ($in, $out, $err)
    );
    return ($out, $err, $CHILD_ERROR >> 8);
}

sub openWin32Registry {

    my $Registry;
    my ($norecursion) = @_;
    Win32::TieRegistry->require();
    Win32::TieRegistry->import(
        Delimiter   => '/',
        TiedRef     => \$Registry
    );

    my $agentKey = 'FusionInventory-Agent-unittest';
    my $machKey = $Registry->{'LMachine'};
    my $settings  = $machKey->Open('SOFTWARE/' . $agentKey, { 'Delimiter' => '/' });
    if (! defined($settings)) {
        die "\nFailed to create HKEY_LOCAL_MACHINE/SOFTWARE/$agentKey key, be sure to run this win32 test with Administrator privileges"
            if $norecursion;
        $settings = $machKey->Open('SOFTWARE', { 'Delimiter' => '/' });
        $settings->{$agentKey} = {};
        $settings = openWin32Registry('no-recursion');
    }

    return $settings;
}



( run in 2.937 seconds using v1.01-cache-2.11-cpan-d7a12ab2c7f )