返回列表 发帖

[问题求助] Perl怎样查看可执行文件的十六进制编码?

比如,我有一个可执行文件:
C:\Windows\System32\clip.exe
怎样查看它的十六进制编码?就像用UE打开那样

cmd命令行下 "seehex C:\Windows\System32\clip.exe"
:: seehex.bat <file>
@perl -x -S %~s0 %*&goto:eof
#!perl
open EXE,"@ARGV" or die "$!";
binmode EXE;
while (<EXE>) {
    print &asc2hex($_);
}
sub asc2hex {
    ($s = shift) =~ s/./sprintf("%02lx", ord $&)/egs;
    return $s;
}COPY

TOP

#!/usr/bin/perl
use strict;
use warnings;
open(FH,"<",'C:\Windows\System32\clip.exe') or die;
my $a;
my $buffer;
while (read(FH,$buffer,16)) {
    $a=unpack("H*",$buffer);
$a=~s/../$& /g;
print $a;
}
close(FH);COPY

TOP

回复 3# sxw


多谢。用unpack和ord得到的结果有点差异,请问是为什么?
open EXE,'C:\Windows\System32\clip.exe';
binmode EXE;
while (<EXE>) {
    print &asc2hex($_);
}
sub asc2hex {
    ($s = shift) =~ s/./sprintf("%02lx ", ord $&)/egs;
    return $s;
}COPY

TOP

本帖最后由 sxw 于 2011-10-25 17:17 编辑

回复 4# Perl


    呵呵,不清楚,plp26的结果比3楼的多了1kb,下面的也可以吧
#!/usr/bin/perl
use strict;
use warnings;
open(FH,"<",'C:\Windows\System32\clip.exe') or die;
my @a;
my $buffer;
while (read(FH,$buffer,16)) {
    @a=unpack("H*",$buffer);#@a中只有一个元素
         print $a[0],"\n";
        }
close(FH);COPY

TOP

把2楼精简下:
:: seehex.bat <file>
@perl -x -S %~s0 %*&goto:eof
#!perl
open EXE,"@ARGV" or die $!;
binmode EXE;
while (<EXE>) {
   $_ =~ s/./sprintf("%02lx", ord $&)/egs;
   print;
}COPY
SOS --- >> lllsoslll@163.com

TOP

open EXE,'C:\Windows\System32\clip.exe' or die $!;
binmode EXE;
while (<EXE>) {
   $_ =~ s/./sprintf("%02lx", ord $&)/egs;
   print;
}COPY
SOS --- >> lllsoslll@163.com

TOP

返回列表