Example #1
1
 function convert_uudecode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     if (strlen($string) < 8) {
         user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
         return false;
     }
     $decoded = '';
     foreach (explode("\n", $string) as $line) {
         $c = count($bytes = unpack('c*', substr(trim($line), 1)));
         while ($c % 4) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 4) as $b) {
             $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
             $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
             $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
             $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
             $b0 <<= 2;
             $b0 |= $b1 >> 4 & 0x3;
             $b1 <<= 4;
             $b1 |= $b2 >> 2 & 0xf;
             $b2 <<= 6;
             $b2 |= $b3 & 0x3f;
             $decoded .= pack('c*', $b0, $b1, $b2);
         }
     }
     return rtrim($decoded, "");
 }
Example #2
1
 /**
  * Parse binary data
  *
  * @param string $binaryData The binary data
  */
 public function parseBinary($binaryData)
 {
     if (!is_null($binaryData) && Util::binaryLength($binaryData) >= TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE) {
         $reply = unpack('C1status/C1flags/n1server_msgLenght/n1dataLenght', $binaryData);
         $this->status = $reply['status'];
         $this->flags = $reply['flags'];
         $this->msgLenght = $reply['server_msgLenght'];
         $this->dataLenght = $reply['dataLenght'];
         $checkLen = TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE + $this->msgLenght + $this->dataLenght;
         if (Util::binaryLength($binaryData) == $checkLen) {
             $unpackMask = 'a' . TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE . 'header';
             if ($this->msgLenght > 0) {
                 $unpackMask .= '/a' . $this->msgLenght . 'msg';
             }
             if ($this->dataLenght > 0) {
                 $unpackMask .= '/a' . $this->dataLenght . 'data';
             }
             $unpack = unpack($unpackMask, $binaryData);
             if ($this->msgLenght > 0) {
                 $this->msg = $unpack['msg'];
             }
             if ($this->dataLenght > 0) {
                 $this->data = $unpack['data'];
             }
         }
     }
 }
Example #3
0
function webid_claim()
{
    $r = array('uri' => array());
    if (isset($_SERVER['SSL_CLIENT_CERT'])) {
        $pem = $_SERVER['SSL_CLIENT_CERT'];
        if ($pem) {
            $x509 = openssl_x509_read($pem);
            $pubKey = openssl_pkey_get_public($x509);
            $keyData = openssl_pkey_get_details($pubKey);
            if (isset($keyData['rsa'])) {
                if (isset($keyData['rsa']['n'])) {
                    $r['m'] = strtolower(array_pop(unpack("H*", $keyData['rsa']['n'])));
                }
                if (isset($keyData['rsa']['e'])) {
                    $r['e'] = hexdec(array_shift(unpack("H*", $keyData['rsa']['e'])));
                }
            }
            $d = openssl_x509_parse($x509);
            if (isset($d['extensions']) && isset($d['extensions']['subjectAltName'])) {
                foreach (explode(', ', $d['extensions']['subjectAltName']) as $elt) {
                    if (substr($elt, 0, 4) == 'URI:') {
                        $r['uri'][] = substr($elt, 4);
                    }
                }
            }
        }
    }
    return $r;
}
Example #4
0
 function convert_uuencode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     $u = 0;
     $encoded = '';
     while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) {
         $u += 45;
         $encoded .= pack('c', $c + 0x20);
         while ($c % 3) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 3) as $b) {
             $b0 = ($b[0] & 0xfc) >> 2;
             $b1 = (($b[0] & 0x3) << 4) + (($b[1] & 0xf0) >> 4);
             $b2 = (($b[1] & 0xf) << 2) + (($b[2] & 0xc0) >> 6);
             $b3 = $b[2] & 0x3f;
             $b0 = $b0 ? $b0 + 0x20 : 0x60;
             $b1 = $b1 ? $b1 + 0x20 : 0x60;
             $b2 = $b2 ? $b2 + 0x20 : 0x60;
             $b3 = $b3 ? $b3 + 0x20 : 0x60;
             $encoded .= pack('c*', $b0, $b1, $b2, $b3);
         }
         $encoded .= "\n";
     }
     // Add termination characters
     $encoded .= "`\n";
     return $encoded;
 }
 /**
  * Creates an UUID from a binary representation
  *
  * @param string $uuid
  * @param int    $version
  * @return UUID
  */
 public static function fromBinary($uuid, $version = \null)
 {
     if (\strlen($uuid) !== 16) {
         throw new \InvalidArgumentException("Must have exactly 16 bytes");
     }
     return new UUID(\unpack("N", \substr($uuid, 0, 4))[1], \unpack("N", \substr($uuid, 4, 4))[1], \unpack("N", \substr($uuid, 8, 4))[1], \unpack("N", \substr($uuid, 12, 4))[1], $version);
 }
Example #6
0
 function Net_DNS_RR_SRV(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference/nweight/nport", $data);
             $offset += 6;
             list($target, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->weight = $a['weight'];
             $this->port = $a['port'];
             $this->target = $target;
         }
     } else {
         ereg("([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)[ \t]*\$", $data, $regs);
         $this->preference = $regs[1];
         $this->weight = $regs[2];
         $this->port = $regs[3];
         $this->target = ereg_replace('(.*)\\.$', '\\1', $regs[4]);
     }
 }
Example #7
0
 public function signature_split($orgfile, $input)
 {
     $info = unpack('n', fread($input, 2));
     $blocksize = $info[1];
     $this->info['transferid'] = mt_rand();
     $count = 0;
     $needed = array();
     $cache = $this->getCache();
     $prefix = $this->getPrefix();
     while (!feof($orgfile)) {
         $new_md5 = fread($input, 16);
         if (feof($input)) {
             break;
         }
         $data = fread($orgfile, $blocksize);
         $org_md5 = md5($data, true);
         if ($org_md5 == $new_md5) {
             $cache->set($prefix . $count, $data);
         } else {
             $needed[] = $count;
         }
         $count++;
     }
     return array('transferid' => $this->info['transferid'], 'needed' => $needed, 'count' => $count);
 }
Example #8
0
 /**
  * Faz a leitura do arquivos e popula as variaveis.
  * @param $fileName nome do arquivo
  */
 function load($fileName)
 {
     $f = fopen($fileName, "rb");
     $header['magic'] = fread($f, 2);
     $header['version'] = unpack("Cmajor/Cminor", fread($f, 2));
     $this->version = (double) ($header['version']['major'] . "." . $header['version']['minor']);
     $header['count'] = freadb($f, 2, 'S');
     $header['unknown'] = freadb($f, 2, 'S');
     if ($header['magic'] !== self::MAGIC) {
         throw new UnexpectedValueException("Invalid magic header, found ({$header['magic']}) expected ({self->MAGIC})");
     }
     //Faz a leitura dos sprites.
     for ($i = 0; $i < $header['count']; ++$i) {
         $width = freadb($f, 2, 'S');
         $height = freadb($f, 2, 'S');
         $size = freadb($f, 2, 'S');
         $data = fread($f, $size);
         $this->list[] = new Sprite($width, $height, $data);
     }
     //Faz a leitura da paleta de cores
     for ($i = 0; $i < 256; ++$i) {
         $this->palette[$i] = unpack('Cred/Cgreen/Cblue/Calpha', fread($f, 4));
     }
     //Define a paleta para da Sprite lido
     for ($i = 0; $i < $header['count']; ++$i) {
         $this->list[$i]->setPalette($this->palette);
     }
     fclose($f);
 }
Example #9
0
 static function lookupByToken($token)
 {
     //Expecting well formatted token see getAuthToken routine for details.
     $matches = array();
     if (!preg_match(static::$token_regex, $token, $matches)) {
         return null;
     }
     //Unpack the user and ticket ids
     $matches += unpack('Vuid/Vtid', Base32::decode(strtolower(substr($matches['hash'], 0, 13))));
     $user = null;
     switch ($matches['type']) {
         case 'c':
             //Collaborator c
             if (($user = Collaborator::lookup($matches['uid'])) && $user->getTicketId() != $matches['tid']) {
                 $user = null;
             }
             break;
         case 'o':
             //Ticket owner
             if ($ticket = Ticket::lookup($matches['tid'])) {
                 if (($user = $ticket->getOwner()) && $user->getId() != $matches['uid']) {
                     $user = null;
                 }
             }
             break;
     }
     if (!$user || !$user instanceof TicketUser || strcasecmp($user->getAuthToken($matches['algo']), $token)) {
         return false;
     }
     return $user;
 }
Example #10
0
function sendsock($in)
{
    global $config;
    $service_port = $config['sockport'];
    $address = $config['sockhost'];
    if (!function_exists("socket_create")) {
        error_log(date("y-m-d H:i:s") . " 未启用socket模块\n", 3, "error.log");
        return null;
    }
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) {
        error_log(date("y-m-d H:i:s") . "socket_create() failed, reason: " . socket_strerror(socket_last_error()) . "\n", 3, "error.log");
        return null;
    }
    $result = socket_connect($socket, $address, $service_port);
    if ($result === false) {
        error_log(date("y-m-d H:i:s") . "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n", 3, "error.log");
        return null;
    }
    socket_write($socket, $in, strlen($in));
    $result = socket_read($socket, 8192);
    $arr = unpack("C*", $result);
    socket_close($socket);
    return $arr;
}
Example #11
0
 /**
  * 
  */
 public function handleRequest($fh)
 {
     while (!feof($fh)) {
         // Makes the handler compatable with command line testing and playdar resolver pipeline usage
         if (!($content = fread($fh, 4))) {
             break;
         }
         // get the length of the payload from the first 4 bytes:
         $len = current(unpack('N', $content));
         // bail on empty request.
         if ($len == 0) {
             continue;
         }
         // read $len bytes for the actual payload and assume it's a JSON object.
         $request = json_decode(fread($fh, $len));
         // Malformed request
         if (!isset($request->artist, $request->album)) {
             continue;
         }
         // Let's resolve this bitch
         $results = $this->resolve($request);
         // No results, bail
         if (!$results) {
             continue;
         }
         // Build response and send
         $response = (object) array('_msgtype' => 'results', 'qid' => $request->qid, 'results' => $results);
         $this->sendResponse($response);
     }
 }
Example #12
0
 /**
  * @param string $bin Raw binary data from imagegif or file_get_contents
  *
  * @return GifByteStream
  */
 public function load($bin)
 {
     $bytes = unpack('H*', $bin);
     // Unpack as hex
     $bytes = $bytes[1];
     return new GifByteStream($bytes);
 }
Example #13
0
function phpfiwa_check($engine_properties)
{
    $dir = $engine_properties['dir'];
    $files = scandir($dir);
    $feeds = array();
    for ($i = 2; $i < count($files); $i++) {
        $filename_parts = explode(".", $files[$i]);
        $feedid = (int) $filename_parts[0];
        if ($feedid > 0 && !in_array($feedid, $feeds)) {
            $feeds[] = $feedid;
        }
    }
    $error_count = 0;
    $n = 0;
    foreach ($feeds as $id) {
        $error = false;
        $errormsg = "";
        // 1) Analyse meta file
        $feedname = "{$id}.meta";
        // CHECK 1: META FILE EXISTS
        if (!file_exists($dir . $feedname)) {
            print "[Meta file does not exist: {$id}]\n";
            $error = true;
        } else {
            $meta = new stdClass();
            $metafile = fopen($dir . $feedname, 'rb');
            fseek($metafile, 4);
            $tmp = unpack("I", fread($metafile, 4));
            $meta->start_time = $tmp[1];
            $tmp = unpack("I", fread($metafile, 4));
            $meta->nlayers = $tmp[1];
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
            }
            $meta->interval = array();
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
                $meta->interval[$i] = $tmp[1];
            }
            fclose($metafile);
            if ($meta->nlayers < 1 || $meta->nlayers > 4) {
                $errormsg .= "[nlayers out of range: " . $meta->nlayers . "]";
                $error = true;
            }
            if ($meta->start_time > 0 && filesize($dir . $id . "_0.dat") == 0) {
                $errormsg .= "[Start time set but datafile is empty]";
                $error = true;
            }
            if ($error) {
                print "Feed {$id} " . $errormsg . " [" . date("d:m:Y G:i", filemtime($dir . $feedname)) . "]\n";
            }
        }
        if ($error) {
            $error_count++;
        }
        $n++;
    }
    print "Error count: " . $error_count . "\n";
    print "Number of feeds: {$n}\n";
}
Example #14
0
 public function readShort()
 {
     $data = substr($this->contents, $this->offset, 2);
     $this->offset += 2;
     $unpack = unpack('v', $data);
     return $unpack[1];
 }
 /**
  * @param Buffer $ip
  * @return string
  * @throws \Exception
  */
 private function parseIpBuffer(Buffer $ip)
 {
     $end = $ip->slice(12, 4);
     return implode(".", array_map(function ($int) {
         return unpack("C", $int)[1];
     }, str_split($end->getBinary(), 1)));
 }
Example #16
0
 /**
  * 字符串转16进制
  * @param  [type] $str [description]
  * @return [type]      [description]
  */
 public static function str2hex($str)
 {
     //需要先转GBK编码
     $str = iconv('utf-8', 'gbk//IGNORE', $str);
     $unpack = unpack('H*', $str);
     return $unpack[1];
 }
Example #17
0
/**
 * auto detect image mimetype
 *
 * @author  Won-Kyu Park <*****@*****.**>
 * @since   2013/12/26
 * @license GPLv2
 */
function detect_image($filename)
{
    $fp = @fopen($filename, 'rb');
    if (!is_resource($fp)) {
        return false;
    }
    $dat = fread($fp, 4);
    $tmp = unpack('a4', $dat);
    if ($tmp[1] == 'GIF8') {
        fclose($fp);
        return 'gif';
    }
    $tmp = unpack('C1h/a3a', $dat);
    if ($tmp['h'] == 0x89 && $tmp['a'] == 'PNG') {
        fclose($fp);
        return 'png';
    }
    $tmp = unpack('n1', $dat);
    if ($tmp[1] == 0xffd8) {
        fclose($fp);
        return 'jpeg';
    }
    fclose($fp);
    return false;
}
Example #18
0
function dnpt($ext_ip, $ext_prefix, $int_prefix)
{
    $debug = false;
    // This is not a complete solution!!!!!!!!!!!!!!!!!!!!!!!!!!
    $ext_prefix = str_replace(":", "", $ext_prefix);
    $int_prefix = str_replace(":", "", $int_prefix);
    // hehe
    $sauce = hexdec(split(":", $ext_ip)[4]);
    $ext_c = icmpChecksum(hex2bin($ext_prefix));
    $int_c = icmpChecksum(hex2bin($int_prefix));
    if ($debug) {
        print_r(unpack('n', $int_c));
    }
    $diff = unpack('n', $ext_c)[1] - unpack('n', $int_c)[1];
    if ($diff < 0) {
        $diff = 0xffff + $diff;
    }
    $diff = $sauce - $diff;
    if ($debug) {
        print bin2hex($ext_c);
        print "\n";
        print bin2hex($int_c);
        print "\n";
        print dechex($diff);
        print "\n";
    }
    $out = split(":", $ext_ip);
    $out[4] = dechex($diff);
    $out = join($out, ":");
    return $out;
}
 /**
  * {@inheritdoc}
  */
 public function encodeCharacter($immune, $c)
 {
     //detect encoding, special-handling for chr(172) and chr(128) to chr(159)
     //which fail to be detected by mb_detect_encoding()
     $initialEncoding = $this->detectEncoding($c);
     // Normalize encoding to UTF-32
     $_4ByteUnencodedOutput = $this->normalizeEncoding($c);
     // Start with nothing; format it to match the encoding of the string passed
     //as an argument.
     $encodedOutput = mb_convert_encoding("", $initialEncoding);
     // Grab the 4 byte character.
     $_4ByteCharacter = $this->forceToSingleCharacter($_4ByteUnencodedOutput);
     // Get the ordinal value of the character.
     list(, $ordinalValue) = unpack("N", $_4ByteCharacter);
     // check for immune characters
     if ($this->containsCharacter($_4ByteCharacter, $immune)) {
         return $encodedOutput . chr($ordinalValue);
     }
     // Check for alphanumeric characters
     $hex = $this->getHexForNonAlphanumeric($_4ByteCharacter);
     if ($hex === null) {
         return $encodedOutput . chr($ordinalValue);
     }
     return $encodedOutput . "\\" . $c;
 }
Example #20
0
 protected function _parse()
 {
     $font = $this->getFont();
     $offset = $font->pos();
     $indexToLocFormat = $font->getData("head", "indexToLocFormat");
     $numGlyphs = $font->getData("maxp", "numGlyphs");
     $font->seek($offset);
     $data = array();
     // 2 bytes
     if ($indexToLocFormat == 0) {
         $d = $font->read(($numGlyphs + 1) * 2);
         $loc = unpack("n*", $d);
         for ($i = 0; $i <= $numGlyphs; $i++) {
             $data[] = $loc[$i + 1] * 2;
         }
     } else {
         if ($indexToLocFormat == 1) {
             $d = $font->read(($numGlyphs + 1) * 4);
             $loc = unpack("N*", $d);
             for ($i = 0; $i <= $numGlyphs; $i++) {
                 $data[] = $loc[$i + 1];
             }
         }
     }
     $this->data = $data;
 }
 public function decode()
 {
     $this->x = \unpack("N", $this->get(4))[1];
     $this->y = \unpack("N", $this->get(4))[1];
     $this->z = \unpack("N", $this->get(4))[1];
     $this->namedtag = $this->get(\true);
 }
Example #22
0
function convertip_tiny($ip, $ipdatafile)
{
    static $fp = NULL, $offset = array(), $index = NULL;
    $ipdot = explode('.', $ip);
    $ip = pack('N', ip2long($ip));
    $ipdot[0] = (int) $ipdot[0];
    $ipdot[1] = (int) $ipdot[1];
    if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
        $offset = @unpack('Nlen', @fread($fp, 4));
        $index = @fread($fp, $offset['len'] - 4);
    } elseif ($fp == FALSE) {
        return '- IP数据库文件不可用';
    }
    $length = $offset['len'] - 1028;
    $start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
    for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
        if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
            $index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "");
            $index_length = @unpack('Clen', $index[$start + 7]);
            break;
        }
    }
    @fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
    if ($index_length['len']) {
        return '- ' . @fread($fp, $index_length['len']);
    } else {
        return '- 未知';
    }
}
 public function getDocuments($name)
 {
     if (!file_exists($this->_getFilePathName($name))) {
         return array();
     }
     $fp = fopen($this->_getFilePathName($name), 'r');
     $filesize = filesize($this->_getFilePathName($name));
     if ($filesize % MULTIINDEX_DOCUMENTBYTESIZE != 0) {
         throw new Exception('Filesize not correct index is corrupt!');
     }
     $ret = array();
     $count = 0;
     for ($i = 0; $i < $filesize / MULTIINDEX_DOCUMENTBYTESIZE; $i++) {
         $bindata1 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
         $bindata2 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
         $bindata3 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
         $data1 = unpack('i', $bindata1);
         $data2 = unpack('i', $bindata2);
         $data3 = unpack('i', $bindata3);
         $ret[] = array($data1[1], $data2[1], $data3[1]);
         $count++;
         if ($count == MULTIINDEX_DOCUMENTRETURN) {
             break;
         }
     }
     fclose($fp);
     return $ret;
 }
 public function calculateCode($secret, $timeSlice = null)
 {
     // If we haven't been fed a timeSlice, then get one.
     // It looks a bit unclean doing it like this, but it allows us to write testable code
     $timeSlice = $timeSlice ? $timeSlice : $this->getTimeSlice();
     // Packs the timeslice as a "unsigned long" (always 32 bit, big endian byte order)
     $timeSlice = pack("N", $timeSlice);
     // Then pad it with the null terminator
     $timeSlice = str_pad($timeSlice, 8, chr(0), STR_PAD_LEFT);
     // Hash it with SHA1. The spec does offer the idea of other algorithms, but notes that the authenticator is currently
     // ignoring it...
     $hash = hash_hmac("SHA1", $timeSlice, Base32::decode($secret), true);
     // Last 4 bits are an offset apparently
     $offset = ord(substr($hash, -1)) & 0xf;
     // Grab the last 4 bytes
     $result = substr($hash, $offset, 4);
     // Unpack it again
     $value = unpack('N', $result)[1];
     // Only 32 bits
     $value = $value & 0x7fffffff;
     // Modulo down to the right number of digits
     $modulo = pow(10, $this->codeLength);
     // Finally, pad out the string with 0s
     return str_pad($value % $modulo, $this->codeLength, '0', STR_PAD_LEFT);
 }
Example #25
0
function Qiniu_PutFile($upToken, $key, $localFile, $putExtra)
{
    global $QINIU_UP_HOST;
    if ($putExtra === null) {
        $putExtra = new Qiniu_PutExtra();
    }
    if (!empty($putExtra->MimeType)) {
        $localFile .= ';type=' . $putExtra->MimeType;
    }
    $fields = array('token' => $upToken, 'file' => '@' . $localFile);
    if ($key === null) {
        $fname = '?';
    } else {
        $fname = $key;
        $fields['key'] = $key;
    }
    if ($putExtra->CheckCrc) {
        if ($putExtra->CheckCrc === 1) {
            $hash = hash_file('crc32b', $localFile);
            $array = unpack('N', pack('H*', $hash));
            $putExtra->Crc32 = $array[1];
        }
        $fields['crc32'] = sprintf('%u', $putExtra->Crc32);
    }
    $client = new Qiniu_HttpClient();
    return Qiniu_Client_CallWithForm($client, $QINIU_UP_HOST, $fields, 'multipart/form-data');
}
Example #26
0
 function &gzdecode($data)
 {
     $headerlen = 10;
     $flags = ord(substr($data, 3, 1));
     if ($flags & 4) {
         $extralen = unpack('v', substr($data, 10, 2));
         $headerlen += 2 + $extralen[1];
     }
     if ($flags & 8) {
         // Filename
         $headerlen = strpos($data, chr(0), $headerlen) + 1;
     }
     if ($flags & 16) {
         // Comment
         $headerlen = strpos($data, chr(0), $headerlen) + 1;
     }
     if ($flags & 2) {
         // CRC at end of file
         $headerlen += 2;
     }
     if (false === ($unpacked = gzinflate(substr($data, $headerlen)))) {
         return $data;
     }
     return $unpacked;
 }
Example #27
0
 private function getFloat(&$string)
 {
     $data = substr($string, 0, 4);
     $string = substr($string, 4);
     $array = unpack("fvalue", $data);
     return $array['value'];
 }
Example #28
0
 function OpenTable()
 {
     $this->unicode_table = array();
     if (!$this->iconv_enabled && $this->config['TargetLang'] == 'BIG5') {
         $this->config['TargetLang'] = 'GBK';
         $this->convertbig5 = TRUE;
     }
     if ($this->config['SourceLang'] == 'GBK' || $this->config['TargetLang'] == 'GBK') {
         $this->table = CODETABLE_DIR . $this->config['GBtoUnicode_table'];
     } elseif ($this->config['SourceLang'] == 'BIG5' || $this->config['TargetLang'] == 'BIG5') {
         $this->table = CODETABLE_DIR . $this->config['BIG5toUnicode_table'];
     }
     $fp = fopen($this->table, 'rb');
     $tabletmp = fread($fp, filesize($this->table));
     for ($i = 0; $i < strlen($tabletmp); $i += 4) {
         $tmp = unpack('nkey/nvalue', substr($tabletmp, $i, 4));
         if ($this->config['TargetLang'] == 'UTF-8') {
             $this->unicode_table[$tmp['key']] = '0x' . dechex($tmp['value']);
         } elseif ($this->config['SourceLang'] == 'UTF-8') {
             $this->unicode_table[$tmp['value']] = '0x' . dechex($tmp['key']);
         } elseif ($this->config['TargetLang'] == 'UNICODE') {
             $this->unicode_table[$tmp['key']] = dechex($tmp['value']);
         }
     }
 }
Example #29
0
 /**
  * code for parsing the wmf is originally from: http://www.fpdf.de/downloads/addons/55/
  * as an addon for FPDF, written by Martin HALL-MAY
  */
 private function setImageDimension()
 {
     $headerSize = $this->getHeaderSize();
     fseek($this->_stream, $headerSize);
     while (!feof($this->_stream)) {
         $recordInfo = unpack('Lsize/Sfunc', fread($this->_stream, 6));
         // size of record given in WORDs (= 2 bytes)
         $size = $recordInfo['size'];
         // func is number of GDI function
         $func = $recordInfo['func'];
         // parameters are read as one block and processed
         // as necessary by the case statement below.
         // the data are stored in little-endian format and are unpacked using:
         // s - signed 16-bit int
         // S - unsigned 16-bit int (or WORD)
         // L - unsigned 32-bit int (or DWORD)
         // NB. parameters to GDI functions are stored in reverse order
         // however structures are not reversed,
         // e.g. POINT { int x, int y } where x=3000 (0x0BB8) and y=-1200 (0xFB50)
         // is stored as B8 0B 50 FB
         if ($size > 3) {
             $params = fread($this->_stream, 2 * ($size - 3));
         }
         switch ($func) {
             case 0x20c:
                 // SetWindowExt
                 $sizes = array_reverse(unpack('s2', $params));
                 $this->setImageWidth(PHPRtfLite_Unit::getPointsInTwips($sizes[0]));
                 $this->setImageHeight(PHPRtfLite_Unit::getPointsInTwips($sizes[1]));
                 return;
             case 0x0:
                 return;
         }
     }
 }
Example #30
0
 function Net_DNS_RR_A(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             /*
              *  We don't have inet_ntoa in PHP?
              */
             $aparts = unpack('C4b', $this->rdata);
             $addr = $aparts['b1'] . '.' . $aparts['b2'] . '.' . $aparts['b3'] . '.' . $aparts['b4'];
             $this->address = $addr;
         }
     } else {
         if (strlen($data) && ereg("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)[ \t]*\$", $data, $regs)) {
             if ($regs[1] >= 0 && $regs[1] <= 255 && ($regs[2] >= 0 && $regs[2] <= 255) && ($regs[3] >= 0 && $regs[3] <= 255) && ($regs[4] >= 0 && $regs[4] <= 255)) {
                 $this->address = $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4];
             }
         }
     }
 }