<?php
/*
    EZgetPHP ver1.1.2
    作者:まおう
    http://ezweb.s35.xrea.com/
    詳しくはHPを読んでください。
*/

// _/_/_/_/_/_/  設定  _/_/_/_/_/_/

// データのあるディレクトリ
define('DF''./file/');

// EZweb以外からのアクセス制限(0:しない 1:DL領域のみ 2:すべて)
define('OE''0');

// XHTML OBJECTダウンロード領域(0:使わない 1:使う)
define('XD''0');

// ファイルリストモード(0:使わない 1:使う)
define('FL''0');

// カシオ/日立アイコン(png)相互変換機能(0:使わない 1:使う)
define('CI''1');

// CRCのキャッシュ機能(0:使わない 1:使う)
define('CS''1');

// _/_/_/_/_/_/  変更の必要がない設定  _/_/_/_/_/_/

/* <対応しているファイル>
L1 すべてCRC付加ダウンロード
L2 XHTML対応機種のみダウンロード可能
L3 XHTML対応機種の場合OBJECTダウンロードを使用
*/
define('EX',
  
'bmp,jpg,gif,png,wnn,pdl,sli,scl,ck4,ck3,ck2,clk|'.
  
'amc,3g2,3gp,kmf,swf,tar,aad,pbx,hvs,m3f,mqf,ys1,di1|'.
  
'mmf,pmd,qcp,kjx,vcf,vcs,k3d'
);

// EZweb機種確認
define('EZ'preg_match("/\.(ezweb|ido|brew)\.ne\.jp$/i"gethostbyaddr($_SERVER['REMOTE_ADDR'])));
//define('EZ', preg_match("/\.(ezweb|ido|brew)\.ne\.jp$/i", $_SERVER['REMOTE_HOST']));

// _/_/_/_/_/_/  以下から処理開始  _/_/_/_/_/_/

if(OE == && !EZTemp::err('EZweb以外は禁止');

// ファイル情報表示
if($_GET['f']){
  new 
Info();

// CRC付加ダウンロード領域
}elseif(!empty($_GET['name']) && isset($_GET['count']) && isset($_GET['offset'])){
  new 
Download();

//XHTML OBJECTダウンロード領域
}elseif(XD && !empty($_GET['name'])
  && 
preg_match("/^[A-z\d\/\-]+$/"$_GET['m'])
  && 
preg_match("/^\d+$/"$_GET['s'])){
  new 
Download(1);

// ファイルリスト
}elseif(FL){
  
Tool::FileList();

// エラー
}else{
  
Temp::err('ファイル名を指定してください');
}


// _/_/_/_/_/_/  クラス  _/_/_/_/_/_/

// テンプレート
class Temp {

  
// ヘッダー
  
function Head($title 'ダウンロード') {
    
header('Content-type: text/html;charset=Shift_JIS');
    echo 
'<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
<title>'
.$title.'</title>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="vnd.up.markable" content="false" />
<do type="accept"><noop /></do>
</head><body>'
;
  }

  
// フッター
  
function Foot() {
    die(
'</body></html>');
  }

  
// エラーメッセージ
  
function err($mes){
    
header('Content-type: text/plain;charset=Shift_JIS');
    die(
$mes);
  }

}

// 情報表示
class Info extends Temp {
  var 
$info = array();

  function 
Info() {

    if(
preg_match("/\.([A-z\d]+)$/"$_GET['f'], $ext)){
      
$ext strtolower($ext[1]);
    }else 
$this->err('拡張子がありません');
    if(!
preg_match("/".$ext."/"EX)) $this->err('対応したファイルではありません');
    
$this->info['path'] = DF.$_GET['f'];
    
$size = @filesize($this->info['path']) or $this->err('ファイルが見つかりません');
    
$title rawurldecode($_GET['t'] ? $_GET['t'] : basename($_GET['f']));

    list(,
$XH$XH2) = explode("|"EX);

    
// XHTML対応チェック
    
if(preg_match("/^KDDI\-/"$_SERVER['HTTP_USER_AGENT'])
      && 
$_SERVER['HTTP_X_UP_DEVCAP_MULTIMEDIA']{6}
      && 
preg_match("/".$ext."/"$XH.$XH2)){
      
$this->info['xhdl'] = 1;

    }else{
// 非対応
      
if(EZ && !preg_match("/".$ext."/"$XH)){

        
// CRC付加チェック用データ取得
        
$fp fopen($this->info['path'], 'rb');
        
$this->data fread($fp$size);
        
fclose($fp);

        
// カシオアイコン相互変換チェック
        
if(CI && $ext == 'png' && Download::pngcrc()) $size strlen($this->data);

        
// CRC付加チェック
        
if(Download::crc()) $size += 2;

        
// キャッシュ
        
if(CS){
          
setcookie('crc',
            
$_GET['f'].'/'.bin2hex($this->info['crc']),
            
time()+86400);
        }

      }else 
$this->info['xhdl'] = 0;
    }

    
// 解析用データ取得
    
if(!$this->data){
      
$fp fopen($this->info['path'], 'rb');
      
$this->data fread($fp512);
      if(
preg_match("/".$ext."/"'3g2,3gp,amc') && $moov strpos($this->data'moov')){
        
rewind($fp);
        
$this->data fread($fphexdec(bin2hex(substr($this->data$moov-44)))+$moov);
      }elseif(
$ext == 'swf'){
        
rewind($fp);
        
$this->data fread($fp307200);
      }
      
fclose($fp);
    }else 
$this->data substr($this->data0512);

    
// 情報取得
    
if(preg_match("/^\d/"$ext)) $ext 'x'.$ext;
    
$this->info['oth'] = '';
    
FileInfo::$ext();

    
// 解析用データ破棄
    
unset($this->data);

    
// 情報強制指定
    
if(preg_match("/^[A-z\d]+$/"$_GET['d'])) $this->info['dis'] = $_GET['d'];
    if(
$this->info['xhdl'] && preg_match("/^[A-z\d\/\-]+$/"$_GET['m'])) $this->info['mine'] = $_GET['m'];
    if(
$_GET['k']) $this->info['kind'] = htmlspecialchars(rawurldecode($_GET['k']));

    
// ヘッダー
    
$this->Head();

    
// 情報の表示
    
echo '
<div mode="nowrap">名前:'
.htmlspecialchars($title).'<br>
種類:'
.$this->info['kind'].'<br>'.$this->info['oth'].'
容量:'
.Tool::mosize($size).'<br>
更新:'
.date('y/m/d'filemtime($this->info['path'])).'<br>
</div>'
;

    if(
EZ){
      
// 半角スペース( )と半角プラス(+)対策?
      
$file rawurlencode(rawurldecode($_GET['f']));

      
// OBJECT DL
      
if($this->info['xhdl']){
        if(
XD$url '?name='.$file.'&m='.rawurlencode($this->info['mine']).'&s='.$size.'&';
        else 
$url DF.$file;

        if(
$_SERVER['HTTP_X_UP_DEVCAP_NONATTACHMENT'])
          echo 
'添付データを再生するに設定してください<br>';

        echo 
'
<object data="'
.$url.'" type="'.$this->info['mine'].'" copyright="no" standby="ダウンロード">
<param name="disposition" value="'
.$this->info['dis'].'" valuetype="data" />
<param name="size" value="'
.$size.'" valuetype="data" />
<param name="title" value="'
.rawurlencode($title).'" valuetype="data" />
<param name="ac" value="" valuetype="data" />
</object>'
;

      }elseif(
$this->info['xhdl'] === 0){
        echo 
'非対応ファイル';

      }else{ 
// EZGET
        // スクリプトまでのURL
        
$url 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
        
//$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        //$url =  = '';    // 直接入力
        
echo '<wml:anchor label="DL"><wml:spawn href="device:data/dnld?url='.$url.'&name='.$file.'&size='.$size.'&disposition='.$this->info['dis'].'&title='.rawurlencode($title).'" />ダウンロード</wml:anchor>';

      }

    }elseif(!
OE){

      
// FLASHの表示
      
if($ext == 'swf'){
        
$wh getimagesize($this->info['path']);
        echo 
'
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
    width="'
.$wh[0].'" height="'.$wh[1].'">
    <param name="movie" value="'
.$this->info['path'].'" />
    <param name="quality" value="high" />
    <embed src="'
.$this->info['path'].'" quality="high" width="'.$wh[0].'" height="'.$wh[1].'"
         name="'
.htmlspecialchars($title).'" type="application/x-shockwave-flash"
         pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object><hr>
'
;
      }
      echo 
'<a href="'.$this->info['path'].'">ダウンロード</a>';

    }else{
      echo 
'EZweb以外はダウンロードできません';

    }

    
// フッター
    
$this->Foot();
  }

}


// ツール
class Tool {

  
// ファイルリスト
  
function FileList() {
    
Temp::Head('ファイルリスト');
    if(
$dir = @dir(DF.$_GET['d'])){
      while((
$name $dir->read()) !== false){
        if(!
preg_match("/^[\.]+$/"$name)){
          if(
is_dir(DF.$name)) $d[] = $name.'/';
          elseif(
preg_match("/".substr($name, -3)."/i"EX))
            
$f[] = $name;
        }
      }
      
$dir->close();
      
$len count($d);
      
$i 0;
      while(
$i $len){
        echo 
'<a href="?d='.$_GET['d'].rawurlencode($d[$i]).'">./'.$d[$i].'</a><br>';
        
$i++;
      }
      if(
$len) echo '<hr>';
      
$len count($f);
      
$i 0;
      while(
$i $len){
        echo 
'<a href="?f='.$_GET['d'].rawurlencode($f[$i]).'">'.$f[$i].'</a><br>';
        
$i++;
      }
    }else echo 
DF.'が存在しません';
    
Temp::Foot();
  }

  
// 最適サイズ表示
  
function mosize($size) {
    
$tan = array('byte','KB','MB','GB');
    
$si floor($size/1024);
    
$i 0;
    while(
$si != 0){
      if(
$i++ > 2) break;
      
$si floor($si/1024);
    }
    return 
round($size/pow(1024$i), $i).$tan[$i];
  }

}

// 拡張子別情報取得
class FileInfo {

  
// BMP画像
  
function bmp() {
    
$this->info['kind'] = 'BMP画像';
    
$wh getimagesize($this->info['path']);
    
$this->info['oth'] = '横縦:'.$wh[0].'*'.$wh[1].'<br>';
    
$this->info['dis'] = 'devabm';
  }

  
// JPEG画像
  
function jpg() {
    
$this->info['kind'] = 'JPEG画像';
    
$wh getimagesize($this->info['path']);
    
$this->info['oth'] = '横縦:'.$wh[0].'*'.$wh[1].'<br>';
    
$this->info['dis'] = 'devjaww';
  }

  
// GIF画像
  
function gif() {
    if(
preg_match("/NETSCAPE/i"$this->data)){
      
$this->info['dis'] = "devga2z";
      
$this->info['kind'] = "GIFアニメ";
    }else{
      
$this->info['dis'] = "devgi0z";
      
$this->info['kind'] = 'GIF画像';
    }
    
$wh getimagesize($this->info['path']);
    
$this->info['oth'] = '横縦:'.$wh[0].'*'.$wh[1].'<br>';
  }

  
// PNG画像
  
function png() {
    
$wh getimagesize($this->info['path']);
    
$this->info['oth'] = '横縦:'.$wh[0].'*'.$wh[1].'<br>';
    if((
$wh[0] == 162 && $wh[1] == 248) || ($wh[0] == 519 && $wh[1] == 371)){
      
preg_match("/tEXtDescription\\x00\-ICN([A-z\d]+)\-a02/i"$this->data$ki);
      
$this->info['dis'] = 'devicna';
      if(
$ki[1] == 'W31H'$ki[1] = 'PENCK';
      elseif(!
$ki[1]) $ki[1] = 'カシオ/日立';
      
$this->info['kind'] = $ki[1].'アイコン';
    }elseif(
preg_match("/tEXtDescription\\x00KDFRAMAU/i"$this->data)){
      
$this->info['dis'] = 'devfr0i';
      
$this->info['kind'] = 'フレーム';
    }elseif(
preg_match("/tEXtDescription\\x00KDSTMPAU/i"$this->data)){
      
$this->info['dis'] = 'devst0j';
      
$this->info['kind'] = 'スタンプ';
    }else{
      
$this->info['dis'] = 'dev8aww';
      
$this->info['kind'] = 'PNG画像';
    }
  }

  
// 旧EZムービー,着うた
  
function amc() {
    
$this->info['dis'] = 'devdl1q';
    
$this->info['mine'] = 'application/x-mpeg';
    if(
strlen($this->data) === 512) return $this->info['kind'] = '?AMC';
    if(
$vide strpos($this->data'vide')){
      
$stsd strpos($this->data'stsd'$vide)+45;
      
$video '横縦:'.ord($this->data{$stsd}).'*'.ord($this->data{$stsd+2}).'<br>';
    }
    if(
$soun strpos($this->data'soun')){
      if(
strpos($this->data'Qcelp'$soun)) $sound 'QCP';
      else 
$sound 'MP3';
    }else{
      
$this->info['dis'] = 'devdk1n';
    }
    if(!
$video){
      if(
$sound == 'MP3'){
        
$this->info['kind'] = '着うた';
        
$this->info['dis'] = 'devdl1m';
      }else{
        
$this->info['kind'] = 'ボイス';
        if(
preg_match("/^KDDI\-SN23/i"$_SERVER['HTTP_USER_AGENT'])) $this->info['dis'] = 'devdl2bq';
        else 
$this->info['dis'] = 'devdl1bq';
      }
    }else{
      if(
$sound == 'MP3'$this->info['kind'] = '着ムービー';
      else 
$this->info['kind'] = 'ムービー';
    }
    if(
$sound$sound '音声:'.$sound.'<br>';
    
$this->info['oth'] = $video.$sound;
  }

  
// EZムービー,着うた
  
function x3g2($key 1) {
    
$this->info['dis'] = 'devmpzz';
    if(
$vide strpos($this->data'vide')){
      if(
$key$this->info['mine'] = 'video/3gpp2';
      else 
$this->info['mine'] = 'video/3gpp';
      
$stsd strpos($this->data'stsd'$vide)+45;
      
$video '横縦:'.ord($this->data{$stsd}).'*'.ord($this->data{$stsd+2}).'<br>';
    }else{
      if(
$key$this->info['mine'] = 'audio/3gpp2';
      else 
$this->info['mine'] = 'audio/3gpp';
    }
    if(
$soun strpos($this->data'soun')){
      if(
strpos($this->data'damrappl'$soun)) $sound 'AMR';
      elseif(
strpos($this->data'Qcelp'$soun)) $sound 'QCP';
      else 
$sound 'AAC';
    }else{
      
$this->info['dis'] = 'devdk1n';
    }
    if(!
$video){
      if(
$sound == 'AAC'$this->info['kind'] = '着うた';
      else 
$this->info['kind'] = 'ボイス';
    }else{
      if(
$sound == 'AAC'$this->info['kind'] = '着ムービー';
      else 
$this->info['kind'] = 'ムービー';
    }
    if(
strlen($this->data) === 512) return $this->info['kind'] = '?3GPP';
    if(
$sound$sound '音声:'.$sound.'<br>';
    
$this->info['oth'] = $video.$sound;
  }

  
// EZムービー,着うた
  
function x3gp() {
    
FileInfo::x3g2(0);// 3g2,3gp共通処理
  
}

  
// 着うたフル
  
function kmf() {
    
$this->info['dis']  = 'devcufz';
    
$this->info['mine'] = 'application/x-kddi-ezmusic';
    
$this->info['kind'] = '着うたフル';
  }
  
  
// EZアプリ(Java)
  
function kjx() {
    
$this->info['mine'] = 'application/x-kjx';
    
$this->info['kind'] = 'EZアプリ';
    if(
preg_match("/MicroEdition\-Profile:\sKDDIP\-(\d\.\d)/i"$this->data$api)){
      switch(
$api[1]){
        case 
'1.0':
          
$this->info['kind'] .= '(Phase1)';
          
$this->info['dis'] = 'devkdjx';
          break;
        case 
'2.0':
          
$this->info['kind'] .= '(Phase2)';
          
$this->info['dis'] = 'devkdj2';
          break;
        case 
'2.5':
          
$this->info['kind'] .= '(Phase2.5)';
          
$this->info['dis'] = 'devkdj2';
          break;
        case 
'3.0':
          
$this->info['kind'] .= '(Phase3)';
          
$this->info['dis'] = 'devkdj3';
          break;
        default:
          
$this->info['dis'] = 'devkdjx';
      }
    }else 
$this->info['dis'] = 'devkdjx';
  }

  
// ボイス
  
function qcp() {
    
$this->info['dis'] = 'dev13anq';
    
$this->info['mine'] = 'audio/vnd.qcelp';
    
$this->info['kind'] = 'ボイス(Qcelp)';
  }

  
// 着メロ(SMAF)
  
function mmf() {
    
$this->info['mine'] = 'application/x-smaf';
    
$this->info['kind'] = '着メロ(SMAF)';
    
$cnk 8;
    
$i 0;
    while(
$cnkn != 'MTR'){
      if(
$i++ > 4){ $i 0; break; }
      
$cnk += hexdec(bin2hex(substr($this->data$cnk+44))) + 8;
      
$cnkn substr($this->data$cnk3);
    }
    if(
$i){
      switch(
ord($this->data{$cnk+3})){
        case 
0:
          
$wo 4;
          
$this->info['dis'] = 'dev4anm';
          break;
        case 
1:
          
$wo 16;
          
$this->info['dis'] = 'devmfan';
          break;
        case 
5:
          
$wo 40;
          
$this->info['dis'] = 'devm39z';
          break;
        case 
6:
          
$wo 64;
          
$this->info['dis'] = 'devm53z';
          break;
        default:
          
$wo '?';
          
$this->info['dis'] = 'devmfan';
      }
      
$this->info['oth'] = '和音:'.$wo.'和音<br>';
    }else 
$this->info['dis'] = 'devmfan';
  }

  
// フォトミキサー
  
function m3f() {
    
FileInfo::mmf();
    
$this->info['oth'] = '';
    
$this->info['kind'] = "フォトミキサー";
  }

  
// フォトミキサー
  
function mqf() {
    
FileInfo::mmf();
    
$this->info['oth'] = '';
    
$this->info['kind'] = 'フォトミキサー';
  }

  
// 着メロ(C-MIDI)
  
function pmd() {
    
$this->info['mine'] = 'application/x-pmd';
    
$this->info['kind'] = '着メロ(C-MIDI)';
    if(
preg_match("/\\x76\\x65\\x72\\x73\\x00\\x040([1-2])00/"$this->data$ki)){
      switch(
$ki[1]){
        case 
1:
          
$this->info['dis'] = 'dev3anp';
          
$this->info['oth'] = '和音:3和音<br>';
          break;
        case 
2:
          
$this->info['dis'] = 'devcman';
          
$this->info['oth'] = '和音:16和音<br>';
          break;
      }
    }else 
$this->info['dis'] = 'devcman';
  }

  
// FLASH
  
function swf() {
    
$this->info['mine'] = 'application/x-shockwave-flash';
    
$wh getimagesize($this->info['path']);
    
$this->info['oth'] = '横縦:'.$wh[0].'*'.$wh[1].'<br>';
    if(
preg_match("/FSCommand:launch\\x00M\\x00/i"$this->data)
    && 
preg_match("/FSCommand:launch\\x00df\\x00/i"$this->data)){
      
// カシオ,日立アイコン
      
if(preg_match("/FSCommand:launch\\x00photo\\x00/i"$this->data)){
        
$this->info['dis'] = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 54)).'fl7k';
        if(
$wh[0] == 240 && $wh[1] == 400){
          if(!
preg_match("/FSCommand:launch\\x00enjoytool\\x00/i"$this->data))
            
$this->info['kind'] = 'W41H/W41CA';
          else 
$this->info['kind'] = 'W21CA/W31CA';
        }elseif(
$wh[0] == 240 && $wh[1] == 320){
          if(
preg_match("/FSCommand:launch\\x00fmradio\\x00/i"$this->data))
            
$this->info['kind'] = 'W32H';
          if(
preg_match("/FSCommand:launch\\x00eznavigation\\x00/i"$this->data))
            
$this->info['kind'] = 'A5512CA/G\'zOne';
          if(
preg_match("/FSCommand:launch\\x00memorycard\\x00/i"$this->data))
            
$this->info['kind'] = 'W22H/PENCK';
          else 
$this->info['kind'] = 'カシオ/日立';
        }else 
$this->info['kind'] = 'カシオ/日立';
        
$this->info['kind'] .= 'アイコン';
      
// 鳥取三洋アイコン
      
}elseif(preg_match("/FSCommand:launch\\x00camera\\x00/i"$this->data)
        && 
$wh[0] == 240 && $wh[1] == 270){
        
$this->info['dis'] = 'stfl01';
        if(
preg_match("/FSCommand:launch\\x00fmradio\\x00/i"$this->data))
          
$this->info['kind'] = 'A5518SA';
        elseif(
preg_match("/FSCommand:launch\\x00ptm\\x00/i"$this->data))
          
$this->info['kind'] = 'Sweets pure/A55(18/20)SA';
        else 
$this->info['kind'] = '鳥取三洋';
        
$this->info['kind'] .= 'アイコン';
      
// その他
      
}else{
        
$this->info['kind'] = 'FLASH';
        
$this->info['dis'] = 'devfl7z';
      }
    
// 東芝
    
}elseif(preg_match("/FSCommand:launch\\x00(\d\d?|\\x96\\x07)\\x00/i"$this->data)
      && 
$wh[0] == 240 && $wh[1] == 270){
      
$this->info['kind'] = '東芝アイコン';
      
$this->info['dis'] = 'tsmenu1';
    
// その他
    
}else{
      
$this->info['kind'] = 'FLASH';
      
$this->info['dis'] = 'devfl7z';
    }

  }

  
// カシオ(日立?)3Dアニメ
  
function k3d() {
    
$this->info['dis'] = 'devk32z';
    
$this->info['mine'] = 'application/x-k3d';
    
$this->info['kind'] = '3Dアニメ';
  }

  
// カシオ,日立ダウンロード辞書
  
function aad() {
    
$this->info['mine'] = 'application/x-atokdic';
    if(
$null strpos($this->data"\x00\x00\x00\x00\x01\x00\x00\x00")){
      
$this->info['oth'] = '登録:'.
        (
ord($this->data{$null+8})
        + (
ord($this->data{$null+9}) << 8)
        + (
ord($this->data{$null+10}) << 16)
        + (
ord($this->data{$null+11}) << 24)).
        
'語<br>';
    }
    if(
preg_match("/^KDDI\-HI/"$_SERVER['HTTP_USER_AGENT'])){
      
$this->info['dis'] = 'hiaada0';
      
$this->info['kind'] = 'ATOK辞書(日立)';
    }else{
      
$this->info['dis'] = 'caaada0';
      
$this->info['kind'] = 'ATOK辞書(カシオ)';
    }
  }

  
// ソニーエリクソン辞書
  
function pbx() {
    
$this->info['dis'] = 'SNPB01a';
    
$this->info['mine'] = 'application/x-pobox';
    
$this->info['kind'] = 'ソニエリ辞書';
  }

  
// 三洋辞書
  
function wnn() {
    if(
preg_match("/SANYO\-Wnn00(\d)/"$this->data$no)){
      
$ki = array('','3015|5302|1302','1303|5503|5505|1305','W21SA','W22SA|W31SA|W32SA');
      
$this->info['kind'] = $ki[$no[1]];
      if(!
$this->info['kind']) $this->info['kind'] = '三洋['.$no[1].']';
    }
    if(
$no[1] == '1'$this->info['dis'] = 'sydic01';
    else 
$this->info['dis'] = 'sydic02';
    if(!
$this->info['kind']) $this->info['kind'] = '三洋';
    
$this->info['kind'] .= '辞書';
  }

  
// 三洋ピクトアイコン
  
function pdl() {
    
$this->info['dis'] = 'sypct01';
    if(
preg_match("/PCTHSANYO\-PCT00(\d)/"$this->data$no)){
      
$ki = array('','W21SA','W22SA','W31SA','W32SA','W33SA','W41SA');
      
$this->info['kind'] = $ki[$no[1]];
      if(!
$this->info['kind']) $this->info['kind'] = '三洋['.$no[1].']';
    }
    if(!
$this->info['kind']) $this->info['kind'] = '三洋';
    
$this->info['kind'] .= 'ピクト';
  }

  
// 三洋アイコン
  
function sli() {
    
$this->info['dis'] = 'sylcm01';
    
$this->info['kind'] = '三洋アイコン';
    
$this->data strstr($this->data'DLID臼NG');
    
$w hexdec(bin2hex(substr($this->data204)));
    
$h hexdec(bin2hex(substr($this->data244)));
    if(
$w == 320 && $h == 86$this->info['kind'] .= 1;
    elseif(
$w == 480 && $h == 172$this->info['kind'] .= 5;
    elseif(
$w == 480 && $h == 258$this->info['kind'] .= 9;
    else 
$this->info['kind'] .= '?';
  }

  
// 三洋時計
  
function scl() {
    
$this->info['dis'] = 'syclk01';
    
$this->info['kind'] = '三洋時計';
  }

  
// 東芝時計4
  
function ck4() {
    
$this->info['dis'] = 'tsdclk4';
    
$this->info['kind'] = 'W21T|5509|5506時計';
  }

  
// 東芝時計3
  
function ck3() {
    
$this->info['dis'] = 'tsdclk3';
    
$this->info['kind'] = '5304|1304|5501|5504時計';
  }

  
// 東芝時計2
  
function ck2() {
    
$this->info['dis'] = 'tsdclk2';
    
$this->info['kind'] = 'A5301T時計';
  }

  
// 東芝時計
  
function clk() {
    
$this->info['dis'] = 'tsdclk';
    
$this->info['kind'] = 'A3013T時計';
  }
  
  
// 東芝辞書
  
function di1() {
    
$this->info['dis']  = 'tsrupo';
    
$this->info['mine'] = 'application/x-tsb-rupo';
    
$this->info['kind'] = '東芝辞書';
  }

  
// 東芝予測辞書
  
function ys1() {
    
$this->info['dis']  = 'tsrupoy';
    
$this->info['mine'] = 'application/x-tsb-rupo';
    
$this->info['kind'] = '東芝辞書(予測)';
  }

  
// HV-Script
  
function hvs() {
    
$this->info['dis'] = 'devm58z';
    
$this->info['mine'] = 'application/vnd.yamaha.hv-script';
    
$this->info['kind'] = 'ボイス(HV-Script)';
  }

  
// EZチャンネル
  
function tar() {
    
$this->info['dis'] = 'devsmzw';
    
$this->info['mine'] = 'application/x-tar';
    
$this->info['kind'] = 'EZチャンネル';
  }

  
// メモリダイヤル
  
function vcf() {
    
$this->info['dis'] = 'devvcf';
    
$this->info['mine'] = 'text/x-vcard';
    
$this->info['kind'] = 'メモリダイヤル';
  }

  
// スケジュール
  
function vcs() {
    
$this->info['dis'] = 'devvcs';
    
$this->info['mine'] = 'text/x-vcalendar';
    
$this->info['kind'] = 'スケジュール';
  }

}

// ダウンロード
class Download {
  var 
$data;

  function 
Download($t 0) {
    if(!
EZTemp::err('不正ダウンロード禁止');

    
is_file(DF.$_GET['name']) or Temp::err('ファイルが見つかりません');

    if(
$t){//XHTML OBJECTダウンロード用ファイル領域
      
$update date('D, j M Y G:i:s'filemtime(DF.$_GET['name'])).' GMT';
      if(
preg_match("/^bytes=(\d+)\-(\d+)$/"$_SERVER['HTTP_RANGE'], $length)){
        
$offset $length[1];
        
$count = (($length[2]+1) >= $_GET['s']) ? $length[2] : ($_GET['s']-1);
        
$length $count $offset 1;
        
header('HTTP/1.1 206 Partial Content');
        
header('Last-Modified: '.$update);
        
header('Accept-Ranges: bytes');
        
header('Content-length: '.$length);
        
header('Content-Range: bytes '.$offset.'-'.$count.'/'.$_GET['s']);
        
header('Content-type: '.$_GET['m']);
        
$fp fopen(DF.$_GET['name'], 'rb');
        
fseek($fp$offset);
        echo 
fread($fp$length);
        
fclose($fp);
      }else{
        
header('Last-Modified: '.$update);
        
header('Accept-Ranges: bytes');
        
header('Content-length: '.$_GET['s']);
        
header('Connection: close');
        
header('Content-type: '.$_GET['m']);
        
readfile(DF.$_GET['name']);
      }

    }else{
//CRC付加
      
if($_GET['offset'] >= && $_GET['count'] > 0){
        
$fp fopen(DF.$_GET['name'], 'rb');
        
$this->data fread($fpfilesize(DF.$_GET['name']));
        
fclose($fp);

        
// カシオアイコン相互変換
        
if(CI && preg_match("/\.png$/i"$_GET['name'])) $this->pngcrc();

        
// キャッシュ,CRC付加
        
if(CS){
          list(
$file$crc) = explode("/"$_COOKIE['crc'], 2);
          if(
$file == $_GET['name']){
            if(@
strlen($crc) == 4$this->data .= pack('H*'$crc);
          }else 
$this->crc();
        }else 
$this->crc();

        
header('Content-type: application/x-up-download');
        
header('Content-length: '.$_GET['count']);
        die(
substr($this->data$_GET['offset'], $_GET['count']));

      }elseif(
$_GET['offset'] == && $_GET['count'] == 0){
        
header('Content-type: application/x-up-download');
        
header('Content-length: 0');
        die(
"\n");

      }elseif(
$_GET['offset'] == -&& $_GET['count'] == -1){
        
Temp::err('ダウンロード成功しました');

      }elseif(
$_GET['offset'] == -&& $_GET['count'] == -2){
        
Temp::err('ダウンロード失敗しました');

      }else 
Temp::err('原因不明のエラー');
    }
  }


  
// CRC付加
  
function crc() {
    
$table = array(
      
0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
      
0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
      
0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,
      
0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
      
0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,
      
0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
      
0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,
      
0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
      
0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,
      
0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
      
0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,
      
0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
      
0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,
      
0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
      
0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,
      
0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
      
0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,
      
0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
      
0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,
      
0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
      
0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,
      
0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
      
0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,
      
0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
      
0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,
      
0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
      
0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,
      
0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
      
0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,
      
0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
      
0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,
      
0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0
    
);
    if(!
$size strlen($this->data)) return 0;
    
$crc 0xFFFF;
/*    for($i = 0;$i < $size;$i++){
      $crc = $table[(($crc & 0xFF00) >> 8) ^ ord($this->data{$i})] ^ (($crc << 8) & 0xFFFF);
    }*/
/*    $i = 0;
    while($i < $size){
      $crc = $table[(($crc & 0xFF00) >> 8) ^ ord($this->data{$i})] ^ (($crc << 8) & 0xFFFF);
      $i++;
    }*/
    
$i 0;
    do{
      
$crc $table[(($crc 0xFF00) >> 8) ^ ord($this->data{$i})] ^ (($crc << 8) & 0xFFFF);
    }while(++
$i $size);

    if(
$crc &= 0xFFFF){
      
$this->data .= ($this->info['crc'] = chr(($crc 0xFF00) >> 8).chr($crc 0x00FF));
      return 
1;
    }else return 
0;
  }

  
// カシオ/日立アイコン(png)相互変換
  
function pngcrc() {
    
// 幅取得
    
$w hexdec(bin2hex(substr($this->data164)));
    
$h hexdec(bin2hex(substr($this->data204)));

    
// 機種名
    
if($w == 162 && $h == 248){
      
$des = array(
        
'HI32' => 'W21H',
        
'CA23' => 'A5401CA',
        
'CA22' => 'A5302CA',
        
'CA21' => 'A3012CA',
      );

    }elseif(
$w == 519 && $h == 371){
      
$des = array(
        
'HI34' => 'W31H',// PENCK
        
'HI33' => 'W22H',
        
'CA27' => 'A5512CA',
        
'CA26' => 'A5407CA',
        
'CA25' => 'A5406CA',
        
'CA24' => 'A5403CA',
      );

    }else return 
0;


    
// 対応機種チェック,チャンク開始位置、終了位置
    
if(preg_match("/^(KDDI|UP\.Browser\/[^\-]+)\-((HI|CA)\d{2})/i"$_SERVER['HTTP_USER_AGENT'], $ki)
      && (
$ki $des[$ki[2]])){
      
$chk "tEXtDescription\x00-ICN";
      if(
preg_match("/tEXtDescription\\x00\-ICN([A-z\d]+)\-a02/i"$this->data$ki2)){
        if(
$ki == $ki2[1]) return 0;
        
$sch strpos($this->data$chk.$ki2[1].'-a02') - 4;
        
$ech hexdec(bin2hex(substr($this->data$sch4))) + 12;
      }else{
        
$sch 33;
        
$ech 0;
      }

    }else return 
0;

    
$chk .= $ki.'-a02';

    
// CRCテーブル
    
$table = array(
      
0,1996959894,-301047508,-1727442502,124634137,1886057615,-379345611,-1637575261,
      
249268274,2044508324,-522852066,-1747789432,162941995,2125561021,-407360249,-1866523247,
      
498536548,1789927666,-205950648,-2067906082,450548861,1843258603,-187386543,-2083289657,
      
325883990,1684777152,-43845254,-1973040660,335633487,1661365465,-99664541,-1928851979,
      
997073096,1281953886,-715111964,-1570279054,1006888145,1258607687,-770865667,-1526024853,
      
901097722,1119000684,-608450090,-1396901568,853044451,1172266101,-589951537,-1412350631,
      
651767980,1373503546,-925412992,-1076862698,565507253,1454621731,-809855591,-1195530993,
      
671266974,1594198024,-972236366,-1324619484,795835527,1483230225,-1050600021,-1234817731,
      
1994146192,31158534,-1731059524,-271249366,1907459465,112637215,-1614814043,-390540237,
      
2013776290,251722036,-1777751922,-519137256,2137656763,141376813,-1855689577,-429695999,
      
1802195444,476864866,-2056965928,-228458418,1812370925,453092731,-2113342271,-183516073,
      
1706088902,314042704,-1950435094,-54949764,1658658271,366619977,-1932296973,-69972891,
      
1303535960,984961486,-1547960204,-725929758,1256170817,1037604311,-1529756563,-740887301,
      
1131014506,879679996,-1385723834,-631195440,1141124467,855842277,-1442165665,-586318647,
      
1342533948,654459306,-1106571248,-921952122,1466479909,544179635,-1184443383,-832445281,
      
1591671054,702138776,-1328506846,-942167884,1504918807,783551873,-1212326853,-1061524307,
      -
306674912,-1698712650,62317068,1957810842,-355121351,-1647151185,81470997,1943803523,
      -
480048366,-1805370492,225274430,2053790376,-468791541,-1828061283,167816743,2097651377,
      -
267414716,-2029476910,503444072,1762050814,-144550051,-2140837941,426522225,1852507879,
      -
19653770,-1982649376,282753626,1742555852,-105259153,-1900089351,397917763,1622183637,
      -
690576408,-1580100738,953729732,1340076626,-776247311,-1497606297,1068828381,1219638859,
      -
670225446,-1358292148,906185462,1090812512,-547295293,-1469587627,829329135,1181335161,
      -
882789492,-1134132454,628085408,1382605366,-871598187,-1156888829,570562233,1426400815,
      -
977650754,-1296233688,733239954,1555261956,-1026031705,-1244606671,752459403,1541320221,
      -
1687895376,-328994266,1969922972,40735498,-1677130071,-351390145,1913087877,83908371,
      -
1782625662,-491226604,2075208622,213261112,-1831694693,-438977011,2094854071,198958881,
      -
2032938284,-237706686,1759359992,534414190,-2118248755,-155638181,1873836001,414664567,
      -
2012718362,-15766928,1711684554,285281116,-1889165569,-127750551,1634467795,376229701,
      -
1609899400,-686959890,1308918612,956543938,-1486412191,-799009033,1231636301,1047427035,
      -
1362007478,-640263460,1088359270,936918000,-1447252397,-558129467,1202900863,817233897,
      -
1111625188,-893730166,1404277552,615818150,-1160759803,-841546093,1423857449,601450431,
      -
1285129682,-1000256840,1567103746,711928724,-1274298825,-1022587231,1510334235,755167117
    
);

    
// チャンクデータサイズ
    
$len strlen($chk) - 4;
    
$chk pack("c*",
      (
$len >> 24) & 0xFF,
      (
$len >> 16) & 0xFF,
      (
$len >> 8) & 0xFF,
      
$len 0xFF
    
).$chk;

    
// チャンクCRC計算
    
if(!$size strlen($chk)) return 0;
    
$crc 0xFFFFFFFF;
/*    for($i = 4; $i < $size; $i++){
      $crc = $table[($crc ^ ord($chk{$i})) & 0xFF] ^ ($crc >> 8) & 0xFFFFFF;
    }*/
/*    $i = 4;
    while($i < $size){
      $crc = $table[($crc ^ ord($chk{$i})) & 0xFF] ^ ($crc >> 8) & 0xFFFFFF;
      $i++;
    }*/
    
$i 4;
    do{
      
$crc $table[($crc ord($chk{$i})) & 0xFF] ^ ($crc >> 8) & 0xFFFFFF;
    }while(++
$i $size);
    
$crc ^= 0xFFFFFFFF;
    
$chk .= chr(($crc >> 24) & 0xFF).chr(($crc >> 16) & 0xFF).chr(($crc >> 8) & 0xFF).chr($crc 0xFF);

    
// チャンク挿入
    
$this->data substr_replace($this->data$chk$sch$ech);
    if(!
preg_match("/IEND\\xAE\\x42\\x60\\x82$/"$this->data)){
      
$this->data substr($this->data0,
        
strpos($this->data'IEND'strlen($this->data)-10))."IEND\xAE\x42\x60\x82";
    }
    return 
1;
  }

}

?>