給iOS工程插入無(wú)用的函數(shù)

很多App打多個(gè)渠道包,代碼變動(dòng)很小,和可能被拒絕,所以在打渠道包之前可以在工程中得文件中插入無(wú)用的代碼,會(huì)提高通過(guò)率,打包完成后可以git checkout插入的無(wú)用函數(shù)。

function tree(&$arr_file, $directory, $dir_name='')
{
    $mydir = dir($directory);
    while($file = $mydir->read())
    {
        if((is_dir("$directory/$file")) AND ($file != ".") AND ($file != ".."))
        {
            tree($arr_file, "$directory/$file", "$dir_name/$file");
        }
        else if(($file != ".") AND ($file != ".."))
        {
            $arr_file[] = "$dir_name/$file";
        }
    }
    $mydir->close();
}
//開始運(yùn)行

function randomkeys($length)
{
    $pattern = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ";
    $key = '';
    for($i=0;$i<$length;$i++)
    {
        $key .= $pattern{mt_rand(0,35)};    //生成php隨機(jī)數(shù)
    }
    return $key;
}

// else if ($ext == 'swift') {
//$content = preg_replace('#(\s*)(func[\s\S]*?->)#', "$1\n//swiftcomment$rand_content\n$2", $content);
//}

function createOCRandFunc($name) {

    $num = mt_rand(0,100);
    $num2 = mt_rand(0,50);
    $str = randomkeys(mt_rand(10,70));
    $func1 = "- (NSString *)$name:(NSString *) pwd {
    if (pwd.length<=0) {
        return @\"\";
    }
    NSString * result = @\"$str\";
    int start = 0;
    do{
        int t = 0;
        for (int i = start; t!= $num; i+=8) {
            result = [NSString stringWithFormat:@\"%@%@\",result,[pwd substringWithRange:NSMakeRange(i%pwd.length, 1)]];
            t++;
        }
        t = 0;
        for (int j = start+4; t!=$num2; j+=8) {
            result = [NSString stringWithFormat:@\"%@%@\",result,[pwd substringWithRange:NSMakeRange(j%pwd.length, 1)]];
            t++;
        }
        start++;
    }while(result.length!= pwd.length*$num);
    return result;
}\n";

    $func2 = "-(int)$name:(int)aa other:(int) bb
     { 
        int a = $num;
        int b = $num2;
        for(int i=0;i<b;i++) {
            a+=b*i;
        }
        return a+b;
     }\n";
    $func3 = "-(int)$name:(int)aa other:(int) bb
     { 
        int a = $num;
        int b = $num2;
        if(a>b) {
            return a+b;
        }else {
            return a-b;
        }
     }\n";
    $funcs = [$func1,$func2,$func3];
    return $funcs[mt_rand(0,2)];
}
function createSwiftRandFunc($name) {

    $func = "func $name(array: [Int]) -> (min: Int, max: Int) {
    var currentMin = array[0]
    var currentMax = array[0]
    for value in array[1..<array.count] {
        if value < currentMin {
            currentMin = value
        } else if value > currentMax {
            currentMax = value
        }
    }
    return (currentMin, currentMax)
    }\n
    ";
    return $func;
}

function hx_encrypt()
{
    $arr_file = array();
    $root = "/Users/mac/Desktop/project";
    tree($arr_file, $root);
    foreach ($arr_file as $file) {
        $file = $root . $file;
        $content = file_get_contents($file);
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if ($ext == 'm') {
            $cnts = mt_rand(3,6);
            $funcs = "";
            for ($i = 0;$i < $cnts;$i++) {
                $funcs .= createOCRandFunc(uniqid('hs'));
            }
            $content = preg_replace('#(@implementation[\s\S]*?)(@end)#',"$1\n$funcs$2",$content);
        }else if($ext == 'swift') {
            $funcs = "";
            $cnts = mt_rand(3,6);
            for ($i = 0;$i < $cnts;$i++) {
                $funcs .= createSwiftRandFunc(uniqid('hs'));
            }
            $content = preg_replace('#([\s\S]*?)(}\s*$)#',"$1\n$funcs$2",$content);
        }
        echo "<pre>";
        echo ($content);
        echo "<pre>";
        file_put_contents($file,$content);
    }
}
hx_encrypt();
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,292評(píng)論 25 708
  • 一、電腦本地初始化一個(gè)倉(cāng)庫(kù) 1. git init: 初始化一個(gè)電腦上本地倉(cāng)庫(kù) 終端進(jìn)入項(xiàng)目目錄,輸入: 該命令將...
    dragon_li閱讀 3,000評(píng)論 1 4
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,924評(píng)論 18 139
  • OpenGLES命令需要渲染上下文和繪制表面。渲染上下文存儲(chǔ)相關(guān)的OpenGLES 狀態(tài)。繪制表面時(shí)用于繪制圖元的...
    cain_huang閱讀 3,689評(píng)論 0 2