1

我只想从原始分区映像 (EXT4) 的可用空间中提取垃圾数据。所以我有了这个想法,将可用空间归零,然后将结果用作掩码。

我有包含数据和可用空间的原始分区映像(14GB)以及相同的原始分区映像,可用空间为零。

我想在 Perl 中对这两个文件进行以下操作,对于它们的每个字节,为了获得处理后的原始分区图像,将只包含来自空闲空间的垃圾数据。

RPM  - raw partition image
RPMz - raw partition image with free space zeroed
RPMp - raw partition image processed, will contain only junk data from free space

对于每个字节:RPM & !RPMz => RPMp

有人可以用 Perl 脚本或起点帮助我吗?

4

1 回答 1

1

这是我为反转字节而写的,以获得!RPMz。但它很慢,而且有 100MB 的块我内存不足。我需要一些帮助。

use strict;
use warnings;
use bignum;

my $buffer = "";

my $path1="F:/data-lost-workspace/partition-for-zerofree/mmcblk0p12.raw";
my $path2="F:/data-lost-workspace/partition-for-zerofree/mmcblk0p12_invert.raw";

open(FILE_IN, "<$path1");
binmode(FILE_IN); 

my $offset=0;
my $remaining = -s $path1;
my $length=1024*1024*100;
my $index=1;

unlink $path2;

while($remaining>0)
{
my $line=read(FILE_IN, $buffer, $length);  
print $index." ".$line."\r\n";
$index++;
$remaining=$remaining-$length;

my $buffer_invert=();

my @c = split('', $buffer);

for(my $i=0;$i<$length;$i++)
{
    if(ord($c[$i])==0x0)
    {
        $c[$i]=chr(0xFF);
    }
    else
    {
        $c[$i]=chr(0x00);
    }
}

$buffer_invert=join('', @c);

open(FILE_OUT, ">>$path2");
binmode(FILE_OUT); 
print FILE_OUT $buffer_invert;
close(FILE_OUT);
}
close(FILE_IN);
于 2014-11-10T07:13:55.897 回答