虾米getLocation的PHP和JavaScript实现

getLocation这个函数可以说是整个XiamiThief的核心, 之前在Flash中反编译出的AS代码太难看了, 所以专门重写了能看的版本.

PHP

function getLocation($str){  
        try{
                $a1=(int)$str{0};
                $a2=substr($str, 1);
                $a3=floor(strlen($a2) / $a1);
                $a4=strlen($a2) % $a1;
                $a5=array();
                $a6=0;
                $a7='';
                $a8='';
                for(;$a6 < $a4; ++$a6){
                        $a5[$a6]=substr($a2, ($a3 + 1) * $a6, ($a3 + 1));
                }
                for(;$a6 < $a1; ++$a6){
                        $a5[$a6]=substr($a2, $a3 * ($a6 - $a4) + ($a3 + 1) * $a4, $a3);
                }
                for($i=0, $a5_0_length=strlen($a5[0]); $i < $a5_0_length; ++$i){
                        for($j=0, $a5_length=count($a5); $j < $a5_length; ++$j){
                                $a7.=$a5[$j]{$i};
                        }
                }
                $a7=urldecode($a7);
                for($i=0, $a7_length=strlen($a7); $i < $a7_length; ++$i){
                        $a8.=$a7{$i}==='^'?'0':$a7{$i};
                }
                return $a8;
        } catch(Exception $e){
                return false;
        }
}

JavaScript

function getLocation(str) {  
    try {
        var a1 = parseInt(str.charAt(0)),
            a2 = str.substring(1),
            a3 = Math.floor(a2.length / a1),
            a4 = a2.length % a1,
            a5 = [],
            a6 = 0,
            a7 = '',
            a8 = '';
        for (; a6 < a4; ++a6) {
            a5[a6] = a2.substr((a3 + 1) * a6, (a3 + 1));
        }
        for (; a6 < a1; ++a6) {
            a5[a6] = a2.substr(a3 * (a6 - a4) + (a3 + 1) * a4, a3);
        }
        for (var i = 0,a5_0_length = a5[0].length; i < a5_0_length; ++i) {
            for (var j = 0,a5_length = a5.length; j < a5_length; ++j) {
                a7 += a5[j].charAt(i);
            }
        }
        a7 = decodeURIComponent(a7);
        for (var i = 0,a7_length = a7.length; i < a7_length; ++i) {
            a8 += a7.charAt(i) === '^' ? '0': a7.charAt(i);
        }
        return a8;
    } catch(e) {
        return false;
    }
}