Ejemplo n.º 1
0
    def _inject_script_implement(cls, oc_bridge_name, oc_api_map, indent):
        SSN = ' \\' + SN
        lua = 'if cc.exports then' + SSN
        lua += ST(indent + 1) + 'cc.exports.g_OCFuncNameMap = {}' + SSN
        lua += ST(indent) + 'else' + SSN
        lua += ST(indent + 1) + 'g_OCFuncNameMap = {}' + SSN
        lua += ST(indent) + 'end' + SSN
        lua += ST(
            indent
        ) + 'g_OCFuncNameMap.UniteInterface = ' + '\\"' + oc_bridge_name + '\\"' + SSN
        for oc in oc_api_map:
            lua += ST(
                indent) + 'g_OCFuncNameMap.' + oc + ' = ' + '\\"' + oc_api_map[
                    oc] + '\\"' + SSN
        lua = lua[:-3]  # 去除最后的追加符号

        var_script = JWords.hump(6, 9)
        s = ''
        s += ST(
            indent) + 'const char* ' + var_script + ' = "' + lua + '";' + SN
        s += ST(indent) + 'CCEngine::eval(' + var_script + ');' + SN
        s += '#if defined(DEBUG)' + SN
        s += ST(indent) + 'CCEngine::eval("print = release_print");' + SN
        s += '#else' + SN
        s += ST(indent) + 'CCEngine::eval("print = function(...) end");' + SN
        s += ST(indent
                ) + 'CCEngine::eval("release_print = function(...) end");' + SN
        s += '#endif' + SN
        return s
Ejemplo n.º 2
0
 def rand_child_path(self, ext=None, left=3, right=15):
     if ext is None:
         ext = random.choice(self._ext_list)
     while (True):
         f = os.path.join(self._dir_path, JWords.hump(left, right)) + ext
         if not os.path.exists(f):  # 避免覆盖
             return f
Ejemplo n.º 3
0
 def _sign_sounds(self):
     sound_list = []
     JFileUtils.find_files(self._dst_dir, sound_list, ['.mp3'])
     if len(sound_list) < 1:
         return
     author = JWords.hump(5, 10)
     print('... sign sounds, author:', author)
     JSoundsSigner.sign_sounds(sound_list, author)
Ejemplo n.º 4
0
 def rand_dir_path_by_depth(parent, depth, left=3, right=15):
     dir_path = parent
     for i in range(depth):
         while (True):
             f = os.path.join(dir_path, JWords.hump(left, right))
             if not os.path.exists(f):  # 避免覆盖
                 dir_path = f
                 break
     if (not os.path.exists(dir_path)):
         JFileUtils.mkdir(dir_path)
     return dir_path
Ejemplo n.º 5
0
 def cheat_disk_output(cls, ref, indent=1):
     weight = random.randint(cls._disk_o_size[0], cls._disk_o_size[1])
     config = {}
     for i in range(weight):
         n = None
         while (True):
             n = JWords.hump(32, 64)
             if (n not in config):
                 break
         config[n] = random.randint(1, 20000)
     ref.add_function(cls._disk_o_func,
                      cls._cheat_disk_output_implement(config, indent))
Ejemplo n.º 6
0
 def cheat_net_io(cls, ref, indent=1):
     weight = random.randint(cls._net_io_size[0], cls._net_io_size[1])
     node = None
     func = None
     for i in range(weight, 0, -1):
         if (i != 1):
             func = JWords.hump(8, 16)
         else:
             func = cls._net_io_func
         # tim = round(random.random() * (10 * i) + 0.3, 2)
         tim = max(round(random.random() * 10, 2), 1)
         req = JThirdPartyNetApi.randReq()
         ref.add_function(
             func, cls._cheat_net_io_implement(node, req, tim, indent))
         node = func
Ejemplo n.º 7
0
 def _inject_assets_implement(cls, packages, res_map, indent):
     var_urlstr = JWords.hump(6, 9)
     var_bundle = JWords.hump(6, 9)
     s = ''
     s += ST(indent) + 'NSString* ' + var_urlstr + ' = nil;' + SN
     s += ST(
         indent
     ) + 'NSBundle* ' + var_bundle + ' = [NSBundle mainBundle];' + SN
     # 注入重命名映射
     if (res_map is not None):
         dir_name_map = {
             'music': JWords.hump(6, 9),
             'bgm': JWords.hump(6, 9),
             'sound': JWords.hump(6, 9),
             'juqing': JWords.hump(6, 9),
         }
         file_suffixs = {'.mp3': JWords.hump(6, 9)}
         for d_name in dir_name_map:
             s += ST(indent) + 'const char* ' + dir_name_map[
                 d_name] + ' = "' + d_name + '";' + SN
         for suffix in file_suffixs:
             s += ST(indent) + 'const char* ' + file_suffixs[
                 suffix] + ' = "' + suffix + '";' + SN
         for old_name in res_map:
             res_name = cls._crypt_assets_path(old_name[4:], dir_name_map,
                                               file_suffixs)  # 去除 'res/'
             new_name = res_map[old_name]
             s += ST(
                 indent
             ) + 'CCEngine::resMapping(' + res_name + ', "' + new_name + '");' + SN
     # 注入 assets bin
     if (packages is not None):
         for pi in packages:
             s += ST(
                 indent
             ) + var_urlstr + ' = [' + var_bundle + ' pathForResource:@"' + pi.pack_bin_path + '" ofType:nil];' + SN
             s += ST(indent) + 'if (' + var_urlstr + ') {' + SN
             s += ST(indent + 1) + 'CCEngine::resPackage(' + var_urlstr  + ', ' + \
                  str(pi.pack_bin_sign) + ', ' + str(pi.pack_bin_version) + ');' + SN
             s += ST(indent) + '}' + SN
     return s
Ejemplo n.º 8
0
    def _cheat_net_io_implement(cls, node, request, time, indent):
        s = ''
        s += ST(
            indent
        ) + 'dispatch_time_t t = dispatch_time(DISPATCH_TIME_NOW,' + str(
            time) + '*NSEC_PER_SEC);' + SN
        s += ST(
            indent
        ) + 'dispatch_after(t, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {' + SN

        var_args = JWords.hump(6, 9)
        s += ST(indent + 1) + 'NSDictionary *' + var_args + ' = nil;' + SN
        args_var = request['args']
        if (args_var is not None):
            s += ST(
                indent + 1
            ) + var_args + ' = [NSDictionary dictionaryWithObjectsAndKeys:' + SN
            for k in args_var:
                v = args_var[k]
                s += ST(indent +
                        2) + '@"' + str(v) + '", ' + '@"' + k + '", ' + SN
            s += ST(indent + 1) + 'nil];' + SN

        s += ST(indent +
                1) + ('__http_GET' if
                      ('UBGET' == request['method']) else '__httpPOST')
        s += '(@"' + request[
            'url'] + '", ' + var_args + ', ^(NSData* data, NSURLResponse *resp) {' + SN
        if node is None:
            s += ST(indent + 2) + 'NSLog(@"check net done");' + SN
        else:
            s += ST(indent + 2) + node + '();' + SN
        s += ST(indent + 1) + '});' + SN

        s += ST(indent) + '});' + SN
        return s
Ejemplo n.º 9
0
 def randValue(cls, t):
     # OC对象类型
     if t.startswith('NS'):
         if ('NSString*' == t):
             r = random.random()
             if (r < 0.03):
                 return 'nil'
             elif (r < 0.8):
                 s = '@"' + JWords.hump(OC_LSTR[0], OC_LSTR[1], False) + '"'
                 return s
             else:
                 s = '@"' + JWords.hump(OC_LSTR[0], OC_LSTR[1], False) + '"'
                 if (random.random() < 0.5):
                     d = str(random.random() * OC_LNUM[1] * 2 - OC_LNUM[0])
                     return '[NSString stringWithFormat:@"%@_(%f)",' + s + ',' + d + ']'
                 else:
                     d = str(random.randint(OC_LNUM[0], OC_LNUM[1]))
                     return '[NSString stringWithFormat:@"%@_(%d)",' + s + ',' + d + ']'
         if t.endswith('Dictionary*'):
             if (random.random() < 0.5):
                 return 'nil'
             else:
                 s = '[' + t[:-1] + ' dictionaryWithObjectsAndKeys:'
                 if (random.random() < 0.8):
                     for i in range(random.randint(OC_LSET[0], OC_LSET[1])):
                         s += '@(' + str(i) + '),'
                         s += '@"' + JWords.rand_lowers(1, 10) + '",'
                 else:
                     for i in range(random.randint(OC_LSET[0], OC_LSET[1])):
                         s += '@(' + str(i) + '),'
                         s += '@(' + str(i) + '),'
                 s += 'nil]'
                 return s
         if t.endswith('Array*'):
             if (random.random() < 0.5):
                 return 'nil'
             else:
                 s = '[' + t[:-1] + ' arrayWithObjects:'
                 if (random.random() < 0.8):
                     for i in range(random.randint(OC_LSET[0], OC_LSET[1])):
                         s += '@"' + JWords.rand_lowers(1, 10) + '",'
                 else:
                     for i in range(random.randint(OC_LSET[0], OC_LSET[1])):
                         s += '@(' + str(i) + '),'
                 s += 'nil]'
                 return s
     # 布尔值
     if ('BOOL' == t):
         return random.choice(OC_BOOL)
     # 字符数组
     if ('const char*' == t):
         if (random.random() < 0.03):
             return 'NULL'
         else:
             return '"' + JWords.hump(OC_LSTR[0], OC_LSTR[1], False) + '"'
     # 数值类型数据
     if (cls.isFloat(t)):
         f = random.random() * OC_LNUM[1] * 2 - OC_LNUM[0]
         return str(round(f, random.randint(1, 4)))
     else:
         return str(random.randint(OC_LNUM[0], OC_LNUM[1]))
Ejemplo n.º 10
0
 def cla(cls, ctx=None, prifix='', suffix=''):
     while True:
         n = prifix + JWords.hump(4, 10, True) + suffix
         if ((ctx is None) or (n not in ctx)) and (not cls.isKW(n)):
             return n
Ejemplo n.º 11
0
 def var(cls, ctx=None):
     while True:
         n = JWords.hump(4, 10, False)
         if ((ctx is None) or (n not in ctx)) and (not cls.isKW(n)):
             return n
Ejemplo n.º 12
0
 def rand_path(dir, ext='', left=3, right=9):
     while (True):
         f = os.path.join(dir, JWords.hump(left, right)) + ext
         if not os.path.exists(f):  # 避免覆盖
             return f