我有一个带有尾随数据的gzip存档。如果我用gzip -d
它解包,它会告诉我:“解压缩好,忽略了尾随垃圾”(同样gzip -t
,可以用作检测是否有此类数据的方法)。
现在,我想了解这个垃圾,但奇怪的是,我找不到任何方法来提取它。gzip -l --verbose
告诉我档案的“压缩”大小是文件的大小(即带有尾随数据),这是错误的,没有帮助。file
也无济于事,那我该怎么办?
现在想出了如何获取尾随数据。
我创建了Perl脚本,该脚本使用尾随数据创建了一个文件,该脚本很大程度上基于https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=604617#10:
#!/usr/bin/perl
use strict;
use warnings;
use IO::Uncompress::Gunzip qw(:all);
use IO::File;
unshift(@ARGV, '-') unless -t STDIN;
my $input_file_name = shift;
my $output_file_name = shift;
if (! defined $input_file_name) {
die <<END;
Usage:
$0 ( GZIP_FILE | - ) [OUTPUT_FILE]
... | $0 [OUTPUT_FILE]
Extracts the trailing data of a gzip archive.
Outputs to stdout if no OUTPUT_FILE is given.
- as input file file causes it to read from stdin.
Examples:
$0 archive.tgz trailing.bin
cat archive.tgz | $0
END
}
my $in = new IO::File "<$input_file_name" or die "Couldn't open gzip file.\n";
gunzip $in => "/dev/null",
TrailingData => my $trailing;
undef $in;
if (! defined $output_file_name) {
print $trailing;
} else {
open(my $fh, ">", $output_file_name) or die "Couldn't open output file.\n";
print $fh $trailing;
close $fh;
print "Output file written.\n";
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句