-
Notifications
You must be signed in to change notification settings - Fork 202
PHP
markbook2 edited this page Feb 3, 2017
·
9 revisions
The Kaitai Struct: runtime for PHP can be used in two different ways:
-
As part of Kaitai Struct
-
Independently as Composer's library
The both approaches are described below in order.
@TODO
# Create composer.json
cat <<'OUT' > composer.json
{
"minimum-stability": "dev",
"require": {
"kaitai-io/kaitai_struct_php_runtime": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:kaitai-io/kaitai_struct_php_runtime.git"
}
]
}
OUT
# Install the library
composer install --prefer-source --no-dev
# Usage example
cat <<'OUT' > bash-ep.php
<?php
require __DIR__ . '/vendor/autoload.php';
$binStream = new \Kaitai\Struct\Stream(fopen('/usr/bin/bash', 'rb'));
$binStream->seek(5);
$endianness = $binStream->readS1();
$binStream->seek(24);
if ($endianness === 1) {
// Read on little-endian machine
$entryPoint = $binStream->readU8le();
} else {
// Read on bin-endian machine
$entryPoint = $binStream->readU8be();
}
echo "Entry point 0x" . dechex($entryPoint) . " (as int: $entryPoint)";
OUT
# Shows "Entry point 0x41b6e0 (as int: 4306656)"
php bash-ep.php