elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Perl] HexNow 0.1
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Perl] HexNow 0.1  (Leído 1,351 veces)
BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
[Perl] HexNow 0.1
« en: 9 Marzo 2013, 17:43 pm »

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
  1. #!usr/bin/perl
  2. #HexNow 0.1
  3. #Coded By Doddy H
  4. #Script based in getbytes.py made by hecky neobits
  5. #Thanks to hecky neobits & explorer(perlenespanol)
  6.  
  7. use Getopt::Long;
  8. use File::Basename;
  9. use Cwd;
  10.  
  11. chdir( getcwd() );
  12.  
  13. GetOptions(
  14.    "hex=s"      => \$hex,
  15.    "each=s"     => \$hexeach,
  16.    "output=i"   => \$output,
  17.    "savefile=s" => \$savefile
  18. );
  19.  
  20. head();
  21.  
  22. if ($hex) {
  23.  
  24.    my $code_final;
  25.  
  26.    if ($hexeach) {
  27.  
  28.        my $st = unpack "H*", getcontent($hex);
  29.        my $reco;
  30.  
  31.        for ( my $num = 0 ; $num <= length($st) - 1 ; $num += $hexeach ) {
  32.            my $final = substr $st, $num, $hexeach;
  33.            $reco .= $final . "\n";
  34.        }
  35.  
  36.        $code_final = $reco;
  37.  
  38.    }
  39.    else {
  40.        $code_final = unpack "H*", getcontent($hex);
  41.    }
  42.  
  43.    if ( $output eq "1" ) {
  44.  
  45.        print "\n\n[+] Encoding ....\n";
  46.  
  47.        print "\n[Start]\n\n";
  48.        print $code_final;
  49.        print "\n\n[End]\n";
  50.  
  51.    }
  52.  
  53.    if ($savefile) {
  54.        savefile( $savefile, $code_final );
  55.        print "\n[+] Result generated in : $savefile\n";
  56.    }
  57.    else {
  58.        my $div = basename($hex);
  59.        if ( $div =~ /(.*)\.(.*)/ ) {
  60.            my $listo = $1 . "_hex.txt";
  61.            savefile( $listo, $code_final );
  62.            print "\n[+] Result generated in : $listo\n";
  63.        }
  64.    }
  65.  
  66.    copyright();
  67.  
  68. }
  69.  
  70. sub head {
  71.    print qq(
  72.  
  73.             _____
  74.      ,----/,--.   `.
  75.     /    '. `-'     \         Program Name : HexNow
  76.     | ____ \      '`|_        Version : 0.1
  77.     \'.--._/` _     \ '.       Author : Doddy H
  78.          /'-|/ \|`\|-`  \       Script based in getbytes.py made by hecky neobits  
  79.         /   /       \   |     Thanks to hecky neobits
  80.         |  ;    '`  |  .'
  81.         '. |;;      ;  /
  82.          \ \ ;     / ,'        Examples :
  83.           ;--,   .,--,
  84.        __||=|=|./|=|=||___   perl hexnow.pl -hex imagen.jpg
  85.          `'-'-'  `-'-'`      perl hexnow.pl -hex imagen.jpg -each 5
  86.      ______________________  perl hexnow.pl -hex imagen.jpg -output 1
  87.          /'/ /  \ \ \         perl hexnow.pl -hex imagen.jpg -savefile test.txt
  88.         / '.';  ; \ ' \
  89.        '-/   | ; | ; \-'
  90.          \_| |   | |_/        The End ?
  91.            `-'\_/`-'
  92.  
  93. );
  94. }
  95.  
  96. sub copyright {
  97.    print "\n(C) Doddy Hackman 2013\n";
  98.    exit(1);
  99. }
  100.  
  101. sub getcontent {
  102.  
  103.    open( FILE, $_[0] );
  104.    binmode(FILE);
  105.    my @lines = <FILE>;
  106.    close FILE;
  107.  
  108.    $code = join "", @lines;
  109.    return $code;
  110.  
  111. }
  112.  
  113. sub savefile {
  114.  
  115.    if ( -f $_[0] ) {
  116.        unlink( $_[0] );
  117.    }
  118.  
  119.    open( SAVE, ">>" . $_[0] );
  120.    print SAVE $_[1];
  121.    close SAVE;
  122. }
  123.  
  124. #The End ?
  125.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
perl
Scripting
nobo 0 3,205 Último mensaje 22 Febrero 2005, 07:49 am
por nobo
Perl
Scripting
zhynar_X 2 2,235 Último mensaje 12 Enero 2008, 04:36 am
por GroK
-=PERL=-
Scripting
D4RIO 1 5,725 Último mensaje 25 Febrero 2008, 17:27 pm
por D4RIO
MSN Perl y PHP
Scripting
isseu 0 2,681 Último mensaje 30 Diciembre 2008, 14:36 pm
por isseu
Libros de Perl online [PERL]
Scripting
madpitbull_99 0 3,843 Último mensaje 18 Mayo 2011, 21:49 pm
por madpitbull_99
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines