def duplicate_function_func_post(program, arg):
    if program.__class__ == Function:
        if shouldi(arg=arg):
            if program.ident is not None:
                newfunc = deepcopy(program)
                statement, pos = get_upper_statement_and_pos(program)
                statement.insert(
                    solidityobf_random.randint(
                        0,
                        len(statement.statements_list) - 1), newfunc)
                sl = newfunc.statements.statements_list
                if len(sl) > 0:
                    for i in range(max(1, len(sl) / 3)):
                        del sl[solidityobf_random.randint(0, len(sl) - 1)]
                i = 0
                newname = program.ident.name
                n = newname
                while newname in arg["ident_present"]:
                    i = i + 1
                    newname = program.ident.name + format(i)
                    n += " " + newname
                print red(n)
                arg["ident_present"].append(newname)
                newfunc.replace_ident(Ident(newname))
    return [], arg
def add_if_statement_2_func_post(program, arg):
    if program.__class__ == Statements:
        if shouldi(arg=arg):  #and not is_function_inside(program):
            o = program.statements_list
            if len(o) > 0:
                ifrom = solidityobf_random.randint(0, len(o) - 1)
                ito = solidityobf_random.randint(ifrom, len(o))
                s1 = deepcopy(o[ifrom:ito])
                s2 = deepcopy(o[ifrom:ito])
                for i in range(len(s2), 0, -1):
                    if solidityobf_random.randint(0, 4) == 0:
                        del s2[i - 1]
                flipcoin = solidityobf_random.randint(0, 1)
                if not flipcoin:
                    s1, s2 = s2, s1
                if not flipcoin:
                    ie = If([genPredicate(program, flipcoin)],
                            [Statements([EmptyStatement()]),
                             Statements(s2)])
                else:
                    ie = If([genPredicate(program, flipcoin)],
                            [Statements(s1),
                             Statements([EmptyStatement()])])
                program.replaceall(o[:ifrom])
                program.append(ie)
                program.append_list(o[ito:])
    return [], arg
def change_str_func(program, arg):
    if isinstance(program, String):
        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 program != program.parent.name):
                if shouldi(arg=arg):
                    depth = solidityobf_random.randint(
                        0,
                        len(list_upper_statements) - 1)
                    s = list_upper_statements[depth][0]
                    maxi = list_upper_statements[depth][1]
                    mylist = []
                    after_escape = False
                    i = 0
                    oi = 0
                    l = program.value
                    sel = range(len(l))
                    solidityobf_random.shuffle(sel)
                    sel2 = sel[:3]
                    sel2.sort()
                    for index in sel2 + [None]:
                        i = 0
                        if index:
                            while ord(l[index - i]) >= 128:

                                print index - i
                                i += 1
                                if index - i == oi:
                                    break
                            if not (i % 2):
                                index -= 1
                        vardeclist, name = genVarNotIn(
                            arg["ident_present"],
                            Expr([String(repr(l[oi:index].encode("utf-8")))]))
                        pos = solidityobf_random.randint(0, maxi)
                        maxi = maxi + 1
                        s.insert(pos, vardeclist)
                        mylist.append(name)
                        oi = index
#
                    varlist = map(lambda x: Ident(x), mylist)
                    [
                        varlist.insert(i * 2 - 1, "+")
                        for i in range(1, len(varlist))
                    ]
                    expr = Expr([
                        Functioncall(Expr([Ident("eval")]),
                                     Listarguments([Expr(varlist)]))
                    ])
                    if program.parent.__class__ in [
                            Expr, VarDeclaration, PropertyName
                    ]:
                        program.parent.replace_item(program, expr)
    return [], arg
def add_dummy_var_func_post(program, arg):
    if program.__class__ == Statements:
        if shouldi(arg=arg):
            dummyvar, name = genVarNotIn(arg["ident_present"])
            dummyvar.dummy = True
            program.insert(
                solidityobf_random.randint(0, len(program.statements_list)),
                dummyvar)
    return [], arg
def add_if_statement_func_post(program, arg):
    if program.__class__ == Statements:
        if shouldi(arg=arg):
            ie = If([genPredicate(program, True)], [
                Statements([EmptyStatement()]),
                Statements([EmptyStatement()])
            ])
            #      print GREEN,"gen " , ie.__class__ , "%x"% id(ie),BLACK
            program.insert(
                solidityobf_random.randint(0, len(program.statements_list)),
                ie)
    return [], arg
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
示例#7
0
 def gennewname2(i):
     return "a%d" % solidityobf_random.randint(0, (i + 1) * 20)
示例#8
0
def generate_expr_for_compare(name):
    r = solidityobf_random.randint(0, 100000)
    e = Expr([Ident(name), "==", Number(r)])
    gt = Assignment(Expr([Ident(name)]), "=", Expr([Number(r)]))
    return e, gt