Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
def outlining(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply outlining transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"ident_present": ret, "encountered": [], "numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=outlining_post_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
Exemple #6
0
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
Exemple #7
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
Exemple #8
0
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 = jshadobf_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(jshadobf_random.gauss(
                            0,
                            len(l) / 3))) + 1
                        i = min(len(l), i)
                        vardeclist, name = genVarNotIn(arg["ident_present"],
                                                       Expr([List(l[oi:i])]))
                        pos = jshadobf_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
Exemple #9
0
def add_dummy_exprs(parse_tree,verbose=0,numbermax=NUMBERMAX):
    """This function takes in arpument parse_tree as a parse tree, and will add some dummy exprs,
    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_exprs transformation" ,"with", numbermax
    p = deepcopy(parse_tree)
  #~ ret = get_all_ident_assigned(parse_tree)
    arg={"ident_ass":[],"dummyvars":[],"numbermax":numbermax}
    arg["size"]=count_object(p,[Statements])
    walker(p,add_dummy_exprs_func,postfunction=add_dummy_exprs_func_post,arg=arg)
    return p
def modify_data_flow_2_func(program,arg):
    if isinstance(program,Number):
        if shouldi(arg=arg):
            s,pos = get_upper_statement_and_pos(program)
            if s != None:
                whereto = jshadobf_random.randint(0,pos)
                newp = deepcopy(program)
                vardeclist,name=genVarNotIn(arg["ident_present"],newp)
                program.parent.replace_item(program, Ident(name))
                s.insert(whereto,vardeclist)
    if isinstance(program,List):
        if shouldi(arg=arg):
            s,pos = get_upper_statement_and_pos(program)
            if s != None  and not is_functioncall_inside(program):
                whereto = jshadobf_random.randint(0,pos)
                if count_object(program,[Ident] ):
                    whereto = pos
                newp = deepcopy(program)
                vardeclist,name=genVarNotIn(arg["ident_present"],newp)
                program.parent.replace_item(program, Ident(name))
                s.insert(whereto,vardeclist)
    return [] , arg