美文网首页
给iOS工程插入无用的函数

给iOS工程插入无用的函数

作者: 鸿雁长飞光不度 | 来源:发表于2018-01-08 01:24 被阅读0次

很多App打多个渠道包,代码变动很小,和可能被拒绝,所以在打渠道包之前可以在工程中得文件中插入无用的代码,会提高通过率,打包完成后可以git checkout插入的无用函数。

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();
}
//开始运行

function randomkeys($length)
{
    $pattern = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ";
    $key = '';
    for($i=0;$i<$length;$i++)
    {
        $key .= $pattern{mt_rand(0,35)};    //生成php随机数
    }
    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();

相关文章

网友评论

      本文标题:给iOS工程插入无用的函数

      本文链接:https://www.haomeiwen.com/subject/nwjuextx.html