#!/usr/bin/perl # @(#) Usage : hexdump.pl infile # @(#) Example : hexdump.pl tmp.txt # @(#) Copyright (C) 1998, Web Sailor Production, All Rights Reserved. # @(#) 06Aug98 - khngai, Initial creation. # @(#) # @(#) This program hexdump an ascii file or a binary file. open(FPTR,$ARGV[0]) || die("\07Error opening file $ARGV[0]"); binmode(FPTR); $num = 0; while(eof(FPTR) != 1) { $num_byte_read = read(FPTR,$buf,16); if (($num & 0xFF) == 0) { printf("\n /0 /1 /2 /3 /4 /5 /6 /7 /8 /9/ A /B /C /D /E /F 0123456789ABCDEF\n"); } printf("%04X :",$num); $lhs = ""; $rhs = ""; foreach $i ($buf =~ m/./gs) { # This loop is to process each character at a time. $lhs .= sprintf(" %02X",ord($i)); if ($i =~ m/[ -~]/) { $rhs .= $i; } else { $rhs .= "."; } $num++; } printf("%-50s %s\n",$lhs,$rhs); } close(FPTR);