def add_if_statement(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply add_if_statement transformation", "with", numbermax
    p = deepcopy(program_tree)
    arg = {"numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=add_if_statement_func_post, arg=arg)
    return p
def change_str(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply change_str transformation", "with", numbermax
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"numbermax": numbermax, "ident_present": ret}
    arg["size"] = count_object(p, [String])
    walker(p, postfunction=change_str_func, arg=arg)
    return p
def duplicate_function(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply duplicate_function transformation", "with", numbermax
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"ident_present": ret, "numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=duplicate_function_func_post, arg=arg)
    return p
def modify_data_flow_1(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply modify_data_flow_1 transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"ident_present":ret, "numbermax":numbermax}
    arg["size"] = count_object(p, [Assignment])
    walker(p, postfunction=modify_data_flow_1_post_func, arg=arg)
    return p
def evalification(program_tree, verbose=False, numbermax=NUMBERMAX):
    if verbose:
        print "apply evalification transformation"
    p = deepcopy(program_tree)
    arg = {"numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])

    #~ ret =get_all_ident(program_tree)
    walker(p, evalification_func, arg=arg)
    return p
Example #6
0
def rename_variables(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply rename_variables transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    if "eval" in ret:
        return program_tree
    arg = {"idents": ret, "switcher": [], "numbermax": numbermax}
    arg["size"] = count_object(p, [Ident])
    walker(p, rename_variables_func, rename_variables_post_func, arg=arg)
    return p
def add_dummy_variables(parse_tree, verbose=0, numbermax=NUMBERMAX):
    """This function takes in arpument parse_tree as a parse tree, and will add some dummy variables,
    it will return a new parse tree, with these dummy variables
    the verbose argument allows to increase verbosity"""
    if verbose > 1:
        print "apply add_dummy_var transformation"
    p = deepcopy(parse_tree)
    ret = get_all_ident(parse_tree)
    arg = {"ident_present": ret, "numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=add_dummy_var_func_post, arg=arg)
    return p
def change_list_func_post(program, arg):
    if isinstance(program, List):
        if len(program.value) > 1:    
            list_upper_statements = get_all_upper_statements_and_pos(program)
            if list_upper_statements != [] and (not isinstance(program.parent, PropertyName)) and not is_functioncall_inside(program): # and program != program.parent.name):
                if shouldi(arg=arg):
                    ident_inside = count_object(program, [Ident])
                    if ident_inside:
                        depth = 0
                    else:
                        depth = solidityobf_random.randrange(0, len(list_upper_statements))
                    s = list_upper_statements[depth][0] 
                    maxi = list_upper_statements[depth][1]
                    mini = 0
                    mylist = []
                    if ident_inside:
                        mini = maxi
                    after_escape = False
                    i = 0
                    oi = 0
                    l = program.value
                    while len(l) != i:
                        i = oi + int(abs(solidityobf_random.gauss(0, len(l) / 3))) + 1
                        i = min(len(l), i)
                        vardeclist, name = genVarNotIn(arg["ident_present"], Expr([List(l[oi:i])]))
                        pos = solidityobf_random.randint(mini, maxi)
                        maxi = maxi + 1
                        s.insert(pos, vardeclist)
                        mylist.append(name)
                        oi = i 
                    varlist = map(lambda x: Ident(x), mylist)
                    if len(varlist) > 1:
                        callexprsuffix = CallExpressionSuffix(
                                    sum([[Property(Ident("concat")),  Listarguments([Expr([varlist[i]])])]
                                         for i in range(2, len(varlist))], []))
                        expr = Expr([Functioncall(MemberExpr(Expr([varlist[0]]), [Property(Ident("concat"))]), Listarguments([varlist[1]]), callexprsuffix)])
                    else:
                        expr = Expr(varlist)
                    program.parent.replace_item(program, expr)
    return [], arg