I wrote these scripts a while ago and am only just coming back to them. They used to operate as a
pair but I'm trying to use Binhex on its own.
the problem is that Binhex will not properly
put back together the hex file. Hexbin will (although
but if I use it on a .wav file, the file has a lot
of static in it. If I use Binhex to recompile it,
Windows media player will not open the file. Anyone
know what I'm doing wrong? (Also, I'm going to look
into this myself, but if anyone knows how to split
the txt files into bytes, please tell me).
Thanks, here's the code:
Binhex:
#!/usr/bin/perl
use warnings;
use strict;
my $hexbin = shift;
my $filename = shift;
my $savefile = shift;
open (INPUT,"$filename") || die "Couldn't open file: $!";
open (OUTPUT,">$savefile") || die "Unable to save: $!";
if ($hexbin eq "-h"||"-H") {
binhex();
}
elsif ($hexbin eq "-b"||"-B") {
hexbin();
}
close INPUT;
close OUTPUT;
exit 0;
sub binhex {
binmode INPUT;
while (<INPUT>) {
print OUTPUT unpack ('H*', $_), "\n";
}
}
sub hexbin {
while (<INPUT>) {
print OUTPUT pack ('H*', $_), "\n";
}
}
Hexbin:
#!/usr/bin/perl
use warnings;
use strict;
my $filename = shift;
my $savefile = shift;
open (HEX,"$filename") || die "Couldn't open file: $!";
open (SAVEFILE,">$savefile") || die "Unable to save: $!";
while (<HEX>) {
print SAVEFILE pack ('H*', $_), "\n";
}
close HEX;
close SAVEFILE;
*********************************************
print "Just another iconoclastic Perl hacker";
In reply to Hex editor
by Trag
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.