コード例 #1
0
def modify_control_flow_1_post_func(program, arg):
    if isinstance(program, Statements):
        if shouldi(arg=arg):
            vardec, name = genVarNotIn(arg["ident_present"])
            old = program.statements_list
            varlist = []
            if len(old) != 0 and not is_break_inside(program):
                li = []
                we, wgt = generate_expr_for_compare(name)
                we = Expr([we.exprs[2]])
                for index in range(len(old)):
                    e, gt = generate_expr_for_compare(name)
                    if isinstance(old[index], VarDeclaration):
                        varlist.append(old[index])
                        continue
                    cb = Statements([old[index]])
                    li.append((cb, e, gt))
                (cb, e, gt) = li[0]
                ini = gt
                (cb1, e1, gt1) = li[0]
                for i in range(len(li) - 1):
                    (cb, e, gt) = li[i]
                    (cb1, e1, gt1) = li[i + 1]
                    cb.append(gt1)
                cb1.append(wgt)
                sw = If(list(zip(*li)[1]), list(zip(*li)[0]))
                #sw = Switch(Expr([Ident(name)]), list(zip(*li)[0]))
                wh = While(Expr([we, "!=", Ident(name)]), Statements([sw]))
                # print (wh)
                program.replaceall(varlist + [vardec, ini, wh])
    return [], arg
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
def modify_data_flow_1_post_func(program, arg):
    if isinstance(program, Assignment):
        if shouldi(arg=arg):      
            s, pos = get_upper_statement_and_pos(program)
            s2, pos2 = get_upper_expression_statement_and_pos(program)
            if pos2 is None and s is not None:
                if not is_functioncall_inside(program):# and position_in_exprstatement(program) == 0: # TODO check position_in_exprstatement is working
                    vardeclist, name = genVarNotIn(arg["ident_present"])
                    s.insert(pos, Assignment(Expr([Ident(name)]), "=", program.expr))
                    s.insert(0, vardeclist)
                    program.expr = Ident(name)
                    program.expr.parent = program
    return [], arg
コード例 #5
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 = 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