示例#1
0
def switch_model(tablevel):

    if tablevel is None:
        tablevel = tab_level_1

    param_name = randomvalue.string_value()
    param_value = randomvalue.int_value(switch_num_min, switch_num_max)
    param_name_selfid = randomvalue.string_value_num(3)
    switch_string = f"{tablevel}id {param_name_selfid} = self;\n{tablevel}int {param_name} = [{param_name_selfid} intValue];\n"
    # switch_string = f"{tablevel}int {param_name} = {param_value};\n"

    #switch的分支数
    random_num = randomvalue.int_value(switch_num_min, switch_num_max)
    randstring1 = randomvalue.string_value()
    if random_num == switch_num_min:
        inline_string1 = inline_model_tablevel(tab_level_3)
        switch_string = f'{switch_string}{tablevel}switch ({param_name}) {{\n{tablevel}{tab_level_1}case 2:{{\n{inline_string1}{tablevel}{tab_level_2}}}break;\n{tablevel}{tab_level_1}default:{{\n{tablevel}{tab_level_2}NSLog(@\"do not catch anything\");\n{tablevel}{tab_level_2}}}break;\n\t}}\n'
    else:
        for num in range(switch_num_min, random_num + 1):
            if num == switch_num_min:
                inline_string1 = inline_model_tablevel(tab_level_3)
                switch_string = f'{switch_string}{tablevel}switch ({param_name}) {{\n{tablevel}{tab_level_1}case 2:{{\n{inline_string1}{tablevel}{tab_level_2}}}break;\n'
            elif num == random_num:
                switch_string = f'{switch_string}\n{tablevel}{tab_level_1}default:\n{tablevel}{tab_level_2}{{NSLog(@\"do not catch anything\");\n{tablevel}{tab_level_2}}}break;\n\t}}\n'
            else:
                inline_string1 = inline_model_tablevel(tab_level_3)
                num_str = str(num)
                switch_string = f'\n{switch_string}\n{tablevel}{tab_level_1}case {num_str}:{{\n{inline_string1}{tablevel}{tab_level_2}}}break;'
    return f'\n{switch_string}\n'
示例#2
0
def inline_model_tablevel(tablevel):
    if tablevel is None:
        tablevel = tab_level_1
    param_name = randomvalue.string_value()
    param_value = randomvalue.string_value()
    result_string = f'{tablevel}NSString *{param_name} = @\"{param_value}\";\n{tablevel}NSLog(@\"%@\", {param_name});\n'
    return result_string
示例#3
0
def constom_func_call_model(funcjsonstring, tablevel):
    funcdic = eval(funcjsonstring)
    if funcdic["funcname"] == "":
        print("函数名为空")
        return
    obj_name = randomvalue.string_value()
    class_type = funcdic["class_name"]

    func_string = ""
    func_string = f'{tab_level_1}{class_type} *{obj_name} = [{class_type} new];\n'

    params_name = []
    for i in range(0, len(funcdic["params"])):
        params_name.append(randomvalue.string_value_num(2))

    param_init_string = ""
    for i in range(len(funcdic["params"])):
        param_init_string = f'{param_init_string}{tab_level_1}{funcdic["params"][i]} {params_name[i]} = {randomvalue.type_random_value(funcdic["params"][i])};\n'

    call_string = ""
    if len(params_name) == 0:
        call_string = f'{tab_level_1}[{obj_name} {funcdic["funcname"]}];\n'
    else:
        if len(funcdic["descrip"]) == 1:
            call_string = f'{tab_level_1}[{obj_name} {funcdic["funcname"]}:{params_name[0]}];\n'
        else:
            call_string = f'{tab_level_1}[{obj_name} {funcdic["funcname"]}:{params_name[0]} '
            for i in range(1, len(funcdic["descrip"])):
                call_string = f'{call_string}{funcdic["descrip"][i]}:{params_name[i]} '
            call_string = f'{call_string}];\n'

    return f'\n{func_string}{param_init_string}{call_string}\n'
示例#4
0
def create_h_m(outpath, name):

    super_class = "NSObject"
    if name is None:
        index = randomvalue.int_value(0, len(file_type_pool) - 1)
        world = randomvalue.string_value()
        name = f'{world}{file_name_pool[index]}'
        super_class = f'{file_type_pool[index]}'

    newfile_h = open(f'{outpath}/{name}.h', 'w')
    h_string = f'#import <UIKit/UIKit.h>\nNS_ASSUME_NONNULL_BEGIN\n\n@interface {name} : {super_class}\n\n@end\n\nNS_ASSUME_NONNULL_END'
    newfile_h.write(h_string)
    newfile_h.close()

    newfile_m = open(f'{outpath}/{name}.m', 'w')
    m_string = f'#import \"{name}.h\"\n#import <objc/message.h>\n@implementation {name}\n\n@end'
    newfile_m.write(m_string)
    newfile_m.close()
    print(f'生成类:{name}')

    path_dir = {
        "m_path": f'{outpath}/{name}.m',
        "h_path": f'{outpath}/{name}.h',
        "class_name": f'{name}'
    }

    return path_dir
示例#5
0
def system_func_call_model(funcjsonstring, tablevel):

    funcdic = eval(funcjsonstring)
    if funcdic["funcname"] == "":
        print("函数名为空")
        return
    class_name = randomvalue.string_value()
    class_string = randomvalue.string_value()

    func_string = ""
    func_string = f'{tab_level_1}Class {class_name} = NSClassFromString(@\"{class_string}\");\n'

    msg_send_param = ""
    param_string = ""
    param_descri_string = ""
    imp_string = ""
    sel_name = randomvalue.string_value()
    imp_name = randomvalue.string_value()
    if len(funcdic["params"]):
        for i in range(len(funcdic["params"])):
            param_name = randomvalue.string_value()
            param_string = f'{param_string}{tab_level_1}id {param_name};\n'
            msg_send_param = f'{msg_send_param},{param_name}'
            imp_string = f'{imp_string},id'
            if i != 0:
                param_descri_string = f'{param_descri_string}:{funcdic["descrip"][i-1]}'
        if param_descri_string == "":
            param_descri_string = ":"
        sel_string = f'{tab_level_1}SEL {sel_name} = @selector({funcdic["funcname"]}{param_descri_string}:);\n'
        func_string = f'{func_string}{param_string}{sel_string}'
    else:
        sel_string = f'{tab_level_1}SEL {sel_name} = @selector({funcdic["funcname"]});\n'
        func_string = f'{func_string}{sel_string}'

    # objc_msgSend 的写法
    # func_string = f'{func_string}{tab_level_1}objc_msgSend({class_name},{sel_name}{msg_send_param});'
    # func_string = str(func_string).replace("::",":")
    # performSelector 的写法
    # func_string = f'{func_string}{tab_level_1}[{class_name} performSelector:{sel_name} withObject:{msg_send_param}];'
    # func_string = str(func_string).replace("::",":").replace(":,",":")
    # imp 的写法
    imp_init_string = f'IMP {imp_name} = [{class_name} methodForSelector:{sel_name}];'
    func_string = f'{func_string}{tab_level_1}{imp_init_string}\n{tab_level_1}((id(*)(id, SEL{imp_string})){imp_name})({class_name},{sel_name}{msg_send_param});'
    func_string = str(func_string).replace("::", ":")
    return f'\n{func_string}\n'