Eikonal Blog

2010.03.23

kmtune.pl

Filed under: unix, VA (Vulnerability Assessment) — Tags: , — sandokan65 @ 14:30

kmtune.pl – a Perl script wrapping kmtune: http://forums2.itrc.hp.com/service/forums/getattachment.do?attachmentId=4902&ext=.txt. Author: H.Merijn Brand. (Source: http://forums13.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1269354030577+28353475&threadId=939626).

Local copy:

#!/pro/bin/perl -w

use strict;
use integer;

if (@ARGV) {
    local $" = '/i || m/';
    eval "sub pat { local \$_ = shift; m/@ARGV/i }";
    }
else {
    eval "sub pat { 1 }"
    }

my (%tune, %parm, $PARM, $parm, %ref);

open my $list, "kmtune -l |";
while () {
    s/\s+$//;
    my ($p, $v) = split m/:\s+/, $_, 2 or next;
    $v =~ s/\b0X([\dA-Fa-f]+)\b/0x\L$1/g;
    $p eq "Parameter" and $parm = $v, next;

    $tune{$parm}{$p} = $v;

    $p eq "Value" or next;
    if ($v =~ m/^-?(0x[\da-f]+|\d+)$/) {
	$parm{uc $parm} = 0 + $v =~ m/^-?0x/ ? hex $v : $v;
	}
    else {
	#printf STDERR "%-20s: '%s'\n", $p, $v;
	$ref{$parm} = $v;
	}
    }
close $list;

while (keys %ref) {
    foreach my $p (keys %ref) {
	my $up = uc $p;
	my $v  = $tune{$p}{Value};
	#my @r = (m/\b([A-Za-z]\w*)\b/g);
	my $x = 0;
	eval q(
	    $v =~ s/\b([A-Za-z]\w*)\b/exists$parm{uc $1}?$parm{uc $1}:do{$x++,$1}/ge;
	    );
	$x and next;
	eval "\$v = $v";
	$parm{$up} = $v;
	delete $ref{$p};
	}
    }

$= = 64;
foreach $parm (sort keys %tune) {
    $tune{$parm}{Default} eq $tune{$parm}{Value} and $tune{$parm}{Default} = "";
    $PARM = uc $parm;
    pat ("$parm $parm{$PARM} $tune{$parm}{Value} $tune{$parm}{Default}\n") and
	write;
    }

format STDOUT_TOP =
Parameter            Value hex    Value dec   Function                    Default
-------------------- ------------ ----------- --------------------------- --------------------
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<>>>>>>>>>> @>>>>>>>>>> ^<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<
$parm,sprintf("0x%010x",$parm{$PARM}),$parm{$PARM},$tune{$parm}{Value},$tune{$parm}{Default}
~~                                            ^<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<
					      $tune{$parm}{Value},        $tune{$parm}{Default}
.

1 Comment »


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: