This represents my first effort with Perl/TK. The basic idea behind this was to create a GUI app that would quickly convert hex values to char and vice versa without having to rely on eyeing an ASCII table each time I want to perform a conversion. For example, this app will take the following HEX values
50 65 72 6C 20 4D 6F 6E 6B 73 21
and output...well, you'll just have to see. ;)
This application can also be used in some cases to create or convert Snort IDS bytecode, which could prove useful when working with signatures.
#!c:/perl/bin/perl -w use Tk; use Tk::DialogBox; use strict; sub convert_hex; sub convert_char; my $main = new MainWindow(-title => 'Hex2Char - Char2Hex'); my (@splithex, @splitchar); my ($val, $value); my $leftframe = $main->Frame(); $leftframe->pack(-side => 'left'); my $rightframe = $main->Frame(); $rightframe->pack(-side => 'right'); $leftframe->Label(-text => "Hex")->pack(); my $hexval = $leftframe->Entry(-width => '30')->pack(); my $buttonleft = $leftframe->Button(-text => '>>', -command => sub{convert_hex;})->pack(); $rightframe->Label(-text => "Char")->pack(); my $charval = $rightframe->Entry(-width => '30')->pack();; my $buttonright = $rightframe->Button(-text => '<<', -command => sub{convert_char;})->pack(); my $exit = $main->Button(-text => 'Exit', -command => sub{exit;}); $exit->pack(-side => 'bottom'); MainLoop; sub convert_hex { my @charconv = (); my $hexvals = $hexval->get; @splithex = split(' ', $hexvals); foreach $value (@splithex) { $val = pack "H*", $value; push @charconv, "$val"; } my @switch = reverse @charconv; $charval->delete(0, 'end'); map {$charval->insert(0,$_)} @switch; } sub convert_char { my @hexconv = (); my $charvals = $charval->get; @splitchar = split(//, $charvals); foreach $value (@splitchar) { $val = unpack "H*", $value; push @hexconv, "$val "; } my @switch = reverse @hexconv; $hexval->delete(0, 'end'); map {$hexval->insert(0,uc $_)} @switch; }
As always, comments and suggestions for improvement welcome.

cheers, -semio


In reply to Perl/TK hex2char - char2hex convertor by semio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.