jeudi 26 février 2015

Perl | extract data from binary file


I have a binary file. I want extract all data from $marker+$step to $marker (or EOF).


Data example:


23 40 92 34 32 09 84 39 02 89 30 fe 90 38 01 02 03 f1 f2 00 00 00 22 33 44 56 77 22 aa bb cc dd ee ff 00 11 ff dd cc cc cc 22 80 ee 01 02 03 f1 f2 00 00 00 22 33 44 56 23 40 92 34 32 dd cc cc 22 33 44 22 33 44 01 02 03 f1 f2 00 00 00 22 33 44 56 77 22 FF FF FF 52 FF FF 52 00 00 00 00 00 00 00


It contains three blocks, what i need


1)



00 00 00 22 33 44 56 77 22 aa bb cc dd ee ff 00 11 ff dd cc cc cc 22 80 ee


2)



00 00 00 22 33 44 56 23 40 92 34 32 dd cc cc 22 33 44 22 33 44


3)



00 00 00 22 33 44 56 77 22 FF FF FF 52 FF FF 52 00 00 00 00 00 00 00


I never worked with binary files with perl.



$filename = $ARGV[0];
$marker = \x01\x02\x03\xf1\xf2;
$step = 3;
$count = 0;

open $file
while <$file> {
seek $marker;
go to forward +$step bytes;
$count++
print EXTFILE_.$count.'.dat' $_
# until do not seek new $marker or EOF
}
close file


As a result, I have to get 3 .dat files.


Help me please realize this pseudocode. Write simple example please.





Aucun commentaire:

Enregistrer un commentaire