[Perl] HexNow 0.1

Iniciado por BigBear, 9 Marzo 2013, 17:43 PM

0 Miembros y 1 Visitante están viendo este tema.

BigBear

Un simple script para convertir el codigo de un archivo en hexadecimal , muy util para un proyecto que tengo en mente.
El script es una traduccion a perl del famoso programa getbytes.py hecho por hecky neobits.

El codigo :

Código (perl) [Seleccionar]

#!usr/bin/perl
#HexNow 0.1
#Coded By Doddy H
#Script based in getbytes.py made by hecky neobits
#Thanks to hecky neobits & explorer(perlenespanol)

use Getopt::Long;
use File::Basename;
use Cwd;

chdir( getcwd() );

GetOptions(
    "hex=s"      => \$hex,
    "each=s"     => \$hexeach,
    "output=i"   => \$output,
    "savefile=s" => \$savefile
);

head();

if ($hex) {

    my $code_final;

    if ($hexeach) {

        my $st = unpack "H*", getcontent($hex);
        my $reco;

        for ( my $num = 0 ; $num <= length($st) - 1 ; $num += $hexeach ) {
            my $final = substr $st, $num, $hexeach;
            $reco .= $final . "\n";
        }

        $code_final = $reco;

    }
    else {
        $code_final = unpack "H*", getcontent($hex);
    }

    if ( $output eq "1" ) {

        print "\n\n[+] Encoding ....\n";

        print "\n[Start]\n\n";
        print $code_final;
        print "\n\n[End]\n";

    }

    if ($savefile) {
        savefile( $savefile, $code_final );
        print "\n[+] Result generated in : $savefile\n";
    }
    else {
        my $div = basename($hex);
        if ( $div =~ /(.*)\.(.*)/ ) {
            my $listo = $1 . "_hex.txt";
            savefile( $listo, $code_final );
            print "\n[+] Result generated in : $listo\n";
        }
    }

    copyright();

}

sub head {
    print qq(

             _____
      ,----/,--.   `.
     /    '. `-'     \         Program Name : HexNow
     | ____ \      '`|_        Version : 0.1
     \'.--._/` _     \ '.       Author : Doddy H
          /'-|/ \|`\|-`  \       Script based in getbytes.py made by hecky neobits 
         /   /       \   |     Thanks to hecky neobits
         |  ;    '`  |  .'
         '. |;;      ;  /
          \ \ ;     / ,'        Examples :
           ;--,   .,--,
        __||=|=|./|=|=||___   perl hexnow.pl -hex imagen.jpg
          `'-'-'  `-'-'`      perl hexnow.pl -hex imagen.jpg -each 5
      ______________________  perl hexnow.pl -hex imagen.jpg -output 1
          /'/ /  \  \ \          perl hexnow.pl -hex imagen.jpg -savefile test.txt
         / '.';  ; \ ' \
        '-/   | ; | ; \-'
          \_| |   | |_/        The End ?
            `-'\_/`-'

);
}

sub copyright {
    print "\n(C) Doddy Hackman 2013\n";
    exit(1);
}

sub getcontent {

    open( FILE, $_[0] );
    binmode(FILE);
    my @lines = <FILE>;
    close FILE;

    $code = join "", @lines;
    return $code;

}

sub savefile {

    if ( -f $_[0] ) {
        unlink( $_[0] );
    }

    open( SAVE, ">>" . $_[0] );
    print SAVE $_[1];
    close SAVE;
}

#The End ?