Esempio n. 1
0
function decodeLength($fd, $length, &$json, $level = 0)
{
    $pad = str_pad("", $level * 4, " ");
    $rest = 0;
    while ($rest + 5 < $length) {
        $type = readByte($fd);
        $nlen = readByte($fd);
        $dlen = readInt($fd, 4);
        $name = readString($fd, $nlen);
        $rest += 6 + $nlen + $dlen;
        if ($type == 1 || $type == 5) {
            $subj = array();
            decodeLength($fd, $dlen, $subj, $level + 1);
            if ($name == "") {
                $json[] = $subj;
            } else {
                $json[$name] = $subj;
            }
            //echo "$pad$type $nlen $dlen $name\n";
            continue;
        }
        if ($type == 2) {
            $number = readNumber($fd, $dlen);
            if ($name == "") {
                $json[] = $number;
            } else {
                $json[$name] = $number;
            }
            //echo "$pad$type $nlen $dlen $name => " . gmp_strval($number) . "\n";
            continue;
        }
        if ($type == 3) {
            $data = readString($fd, $dlen);
            if ($name == "") {
                $json[] = $data;
            } else {
                $json[$name] = $data;
            }
            //echo "$pad$type $nlen $dlen $name => $data\n";
            continue;
        }
        $data = readString($fd, $dlen);
        $dump = "";
        for ($inx = 0; $inx < strlen($data); $inx++) {
            $dump .= ord($data[$inx]) . " ";
        }
        echo "=========================={$type} {$nlen} {$dlen} {$name} {$dump}\n";
        exit(0);
    }
}
Esempio n. 2
0
function trackToFlash($id)
{
    if (file_exists("tracks/" . $id . ".track")) {
        $file = fopen("tracks/" . $id . ".track", "r");
        $startLine = false;
        $final = "";
        $lineid = 0;
        while (ftell($file) < filesize("tracks/" . $id . ".track")) {
            $skipIt = false;
            $length = readShort($file);
            if ($length == 0) {
                if (readByte($file) == 9) {
                    //End Array/Object
                    $skipIt = true;
                    if ($startLine == true) {
                        $startLine = false;
                    }
                } else {
                    skip($file, -1);
                    //Invalid item of length 0
                    $skipIt = true;
                }
            }
            if ($skipIt == false) {
                $name = readString($file, $length);
                $type = readByte($file);
                if ($type == 0) {
                    //Double
                    if ($startLine == true) {
                        $append = "s";
                    } else {
                        $append = "l";
                    }
                    if ($name != 'level') {
                        $val = readDouble($file);
                        if ((string) $val == 'NAN') {
                            $val = 'undefined';
                        }
                        $final .= $append . $lineid . "_" . $name . "=" . $val . "&";
                    } else {
                        skip($file, 8);
                    }
                }
                if ($type == 1) {
                    //Boolean (Show)
                    skip($file, 1);
                }
                if ($type == 2) {
                    //String
                    $strlength = readShort($file);
                    skip($file, $strlength);
                }
                //Type 3 & 6 Do Nothing
                if ($type == 8) {
                    //Array
                    if ($name == "startLine") {
                        $startLine = true;
                    } else {
                        $lineid = (int) $name;
                    }
                    skip($file, 4);
                }
            }
        }
        fclose($file);
        $final = substr($final, 0, strlen($final) - 1);
        return $final;
    }
}
Esempio n. 3
0
 if ($length == 0) {
     if (readByte($file) == 9) {
         //End Array/Object
         if ($startLine == true) {
             $startLine = false;
         }
         $skipIt = true;
     } else {
         skip($file, -1);
         //Invalid item of length 0
         $skipIt = true;
     }
 }
 if ($skipIt == false) {
     $name = readString($file, $length);
     $type = readByte($file);
     if ($type == 0) {
         //Double
         $value = readDouble($file);
         if ($startLine == true) {
             if ($name == "0") {
                 $startLinex[$track] = $value;
             }
             if ($name == "1") {
                 $startLiney[$track] = $value;
             }
         } else {
             if ($name == "0" || $name == "2") {
                 if ($value < $lowx) {
                     $lowx = $value;
                 }