#!/usr/bin/perl#author : morphad#date : 2013-12-26use warnings;use strict;use IO::file;use Fcntl;sub hexdump{ my $data = shift; my $offset = shift; my @darray = unpack("C*",$data); my $IDx = $offset - $offset % 16; if ($IDx != $offset) { printf "%08X | ",$IDx; while ($IDx < $offset) { printf " " if (($IDx % 2) == 0); printf "--"; $IDx++; } } $IDx = $offset; foreach my $byte (@darray) { if (($IDx % 16) == 0) { printf "\n" if ($IDx != 0); printf "%08X | ",$IDx; } printf " " if (($IDx % 2) == 0); printf "%02X",$byte; $IDx++; } printf "\n\n";}sub usage{ print "usage : hexdump.pl file offset len\n"; print "hexdump content of file,len bytes at offset\n"; exit 2;}my $file = shift;my $offset = shift;my $len = shift;unless ($file && $offset && $len){ usage;}my $fh = IO::file->new();$fh->binmode(":raw");unless ($fh->open($file,"<")) { dIE "cannot open $file";}my $buf;my $readn;$fh->seek($offset,SEEK_SET);$readn = $fh->read($buf,$len) || dIE "cannot read buf";dIE "read err" if ($readn != $len);print "=====hex dump [$file]\n";hexdump $buf,$offset;$fh->close();1;总结
以上是内存溢出为你收集整理的perl hexdump全部内容,希望文章能够帮你解决perl hexdump所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)