Created
August 12, 2014 21:08
-
-
Save themainframe/65402ae2c06bdbf00fa4 to your computer and use it in GitHub Desktop.
DVR file_list reader v1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/../vendor/autoload.php'; | |
// Build a schema that defines the structure of the binary file | |
$schema = new Binary\Schema; | |
$schema | |
// 96 bytes of bullshit at the head of the file | |
// Probably does have some meaning, but right now be silly and skip it with a Padding field | |
->addField( | |
(new \Binary\Field\Padding()) | |
->setSize(new \Binary\Field\Property\Property(96)) | |
) | |
// Add a compound field which will be a repeating block of several fields | |
// These will contain the name and alarm flag | |
->addField( | |
(new \Binary\Field\Compound()) | |
// For now, we'll read 5 records from the file | |
// Need to figure out how to read the header to work out how many there will be total... | |
->setName('records') | |
->setCount(new \Binary\Field\Property\Property(5)) | |
// Skip 8 bytes of random fluff | |
->addField( | |
(new \Binary\Field\Padding()) | |
->setSize(new \Binary\Field\Property\Property(8)) | |
) | |
// Read the filename - stupidly assume it will always be 80b long, may not be true... | |
->addField( | |
(new \Binary\Field\Text()) | |
->setName('filename') | |
->setSize(new \Binary\Field\Property\Property(80)) | |
) | |
// Skip 24 bytes of random fluff (mostly 0x00 bytes...) | |
->addField( | |
(new \Binary\Field\Padding()) | |
->setSize(new \Binary\Field\Property\Property(24)) | |
) | |
// Read the alarm status of this record | |
->addField( | |
(new \Binary\Field\UnsignedInteger()) | |
->setName('is_alarm') | |
->setSize(new \Binary\Field\Property\Property(1)) | |
) | |
// Skip 23 bytes of random fluff, upto the end of this record | |
->addField( | |
(new \Binary\Field\Padding()) | |
->setSize(new \Binary\Field\Property\Property(23)) | |
) | |
) | |
; | |
// Open the DVR data file | |
$stream = new Binary\Stream\FileStream( | |
fopen('file_list.damo.8-11-2014.bin', 'r') | |
); | |
// Read the file | |
$result = $schema->readStream($stream); | |
// Show it | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment