def add_true_guard_statements(obj,n_true_guard_statements_min_left=1,n_true_guard_statements_max_left=2, n_true_guard_statements_min_right=1,n_true_guard_statements_max_right=2): for i in xrange(len(obj)): n_guard_statements_left = randint(min(n_true_guard_statements_min_left,n_true_guard_statements_max_left), max(n_true_guard_statements_min_left,n_true_guard_statements_max_left)) n_guard_statements_right = randint(min(n_true_guard_statements_min_right,n_true_guard_statements_max_right), max(n_true_guard_statements_min_right,n_true_guard_statements_max_right)) is_if = ex.is_if(obj[i]) is_else_if = ex.is_else_if(obj[i]) is_while = ex.is_while(obj[i]) is_until = ex.is_until(obj[i]) if is_if or is_else_if or is_while or is_until: true_guard_statements_left = [Utils.generate_true_statement(n_min_value=100,n_max_value=300) for j in xrange(n_guard_statements_left)] true_guard_statements_right = [Utils.generate_true_statement(n_min_value=100,n_max_value=300) for j in xrange(n_guard_statements_right)] if is_if or is_else_if: obj[i] = add_true_guard_statements_if(obj[i],n_guard_statements_left, true_guard_statements_left, n_guard_statements_right, true_guard_statements_right) if is_while or is_until: obj[i] = add_true_guard_statements_while(obj[i],n_guard_statements_left, true_guard_statements_left, n_guard_statements_right, true_guard_statements_right) return obj
def block_if(deep_act, n_statements_min=10, n_statements_max=20, n_guard_statements_min=1, n_guard_statements_max=5, n_else_if_min=1, n_else_if_max=5, deep_max=5, case_values_min=-1000, case_values_max=1000): res = Utils.low_up_string("If ") declarations = "" n_guard_statements = randint( min(n_guard_statements_min, n_guard_statements_max), max(n_guard_statements_min, n_guard_statements_max)) log_statements = logical_statements( n_guard_statements) + Utils.low_up_string(" Then") + "\n" logic_variables = ExtractKeywords.extract_variables(log_statements) for i in logic_variables: declarations += Utils.generate_random_declarator( ) + assign_by_var_name(i) + "\n" res += log_statements res += block(deep_act + 1, n_statements_min, n_statements_max, n_guard_statements_min, n_guard_statements_max, n_else_if_min, n_else_if_max, deep_max, case_values_min, case_values_max) + "\n" else_type = randint(0, 1) # 0 -> Else if, 1 -> Else # if else_type == 0: n_else_if = randint(min(n_else_if_min, n_else_if_max), max(n_else_if_min, n_else_if_max)) for i in xrange(n_else_if): log_statements = logical_statements( randint(min(n_guard_statements_min, n_guard_statements_max), max(n_guard_statements_min, n_guard_statements_max))) logic_variables = ExtractKeywords.extract_variables(log_statements) for i in logic_variables: declarations += Utils.generate_random_declarator( ) + assign_by_var_name(i) + "\n" res += Utils.low_up_string( "ElseIf ") + log_statements + Utils.low_up_string( " Then\n") + block( deep_act + 1, n_statements_min, n_statements_max, n_guard_statements_min, n_guard_statements_max, n_else_if_min, n_else_if_max, deep_max, case_values_min, case_values_max) + "\n" res += Utils.low_up_string("Else ") + "\n" + block( deep_act + 1, n_statements_min, n_statements_max, n_guard_statements_min, n_guard_statements_max, n_else_if_min, n_else_if_max, deep_max, case_values_min, case_values_max) + "\n" res += Utils.low_up_string("EndIf") + "\n" return declarations + res
def hide_function_names(obj): identifiers = list(ex.extract_func_names_from_obj(obj)) replaces = Utils.mod_names_identifier(identifiers) obj = "\n".join(obj) for i in xrange(len(identifiers)): if identifiers[i]: obj = sub(r""+identifiers[i]+r"\s*\(",replaces[i]+"(",obj) return obj.split("\n")
def hide_strings_definition_shuffle(obj): for i in xrange(len(obj)): v = ex.extract_string_definition(obj[i]) if not v: continue else: v = list(v[0]) aux = v[0].strip().lower() if not '(' in aux and aux.find('if') != 0 and aux.find( 'elseif') != 0 and aux.find('func') != 0: indexes, shuffled = range(len(v[1])), "" shuffle(indexes) for index in indexes: shuffled += v[1][index] v[0] = v[0].strip() if " " in v[0]: var_name = v[0][v[0].rfind(" ") + 1:] else: var_name = v[0] var_aux_name = Utils.generate_identifier(50, 150) var_ind_name = Utils.generate_identifier(50, 150) var_cnt_name = Utils.generate_identifier(30, 75) obj[i] = v[ 0] + " = StringToASCIIArray(\"" + shuffled + "\")\n Local $" + var_aux_name + " = " + var_name + "\n Local $" + var_ind_name + "[" + str( len(indexes) ) + "] = " + str( indexes ) + "\n For $" + var_cnt_name + " = 0 To " + str( len(indexes) ) + "-1\n\t" + var_name + "[$" + var_ind_name + "[$" + var_cnt_name + "]] = $" + var_aux_name + "[$" + var_cnt_name + "]\nNext\n" + var_name + " = StringFromASCIIArray(" + var_name + ")\n" return obj
def replace_includes(obj,directories_files): for i in xrange(len(obj)): include = ex.extract_includes(obj[i]) if include: path_content = directories_files[include] if include in directories_files else None if path_content!=None: obj[i] = Utils.read_file(path_content) return obj
def replace_includes(obj, directories_files): for i in xrange(len(obj)): include = ex.extract_includes(obj[i]) if include: path_content = directories_files[ include] if include in directories_files else None if path_content != None: obj[i] = Utils.read_file(path_content) return obj
def hide_function_names(obj): identifiers = list(ex.extract_func_names_from_obj(obj)) replaces = Utils.mod_names_identifier(identifiers) obj = "\n".join(obj) for i in xrange(len(identifiers)): if identifiers[i]: obj = sub(r"" + identifiers[i] + r"\s*\(", replaces[i] + "(", obj) return obj.split("\n")
def hide_function_names(obj): identifiers = list(ex.extract_func_names_from_obj(obj)) replaces = Utils.mod_names_identifier(identifiers) for i in xrange(len(obj)): for j in xrange(len(identifiers)): obj[i] = obj[i].replace( identifiers[j], replaces[j]) if not not identifiers[j] else obj[i] return obj
def hide_variable_names(obj): identifiers = list(ex.extract_defined_variables_from_obj(obj)) # Extraer solo las que se definen en el script # replaces = Utils.mod_names_hash(identifiers) boundary = "\n"+Utils.generate_random_string(20,30)+"\n" obj = boundary.join(obj) for i in xrange(len(identifiers)): if identifiers[i]: obj = sub(r"\$"+identifiers[i][1:]+r"\b","$"+replaces[i]+" ",obj) return obj.split(boundary)
def hide_variable_names(obj): identifiers = list(ex.extract_defined_variables_from_obj( obj)) # Extraer solo las que se definen en el script # replaces = Utils.mod_names_hash(identifiers) for i in xrange(len(obj)): for j in xrange(len(identifiers)): obj[i] = obj[i].replace( identifiers[j], "$" + replaces[j]) if not not identifiers[j] else obj[i] return obj
def hide_numbers(obj,deep_max_min=3,deep_max_max=5,lower_bound=-10000,upper_bound=10000): deep_max = randint(min(deep_max_min,deep_max_max),max(deep_max_min,deep_max_max)) for i in xrange(len(obj)): #floats = ExtractKeywords.extract_float(obj[i]) integers = ExtractKeywords.extract_integer(obj[i]) #for j in xrange(len(floats)): obj[i] = obj[i].replace(floats[j],hide_number(float(floats[j]),0,deep_max,lower_bound,upper_bound)) for j in xrange(len(integers)): if int(integers[j])!=0: obj[i] = obj[i].replace(" "+integers[j]+"\n"," "+hide_number(int(integers[j]),0,deep_max,lower_bound,upper_bound)+"\n") return obj
def hide_strings_replace(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) if not "#include" in obj[i] and not "RegExp" in obj[i]: for j in xrange(len(v)): if len(v[j])>2 and len(obj[i])<Globals.max_size_len_autoit-(len(obj[i])+(1.0/2)*len(obj[i]))+4+len(Config.JUNK_SYMBOLS[0]): aux = Utils.add_random_char_between_string(v[j],Config.JUNK_SYMBOLS[0]) obj[i] = obj[i].replace('"'+v[j]+'"',Globals.string_replace_function+'("'+aux+'","'+Config.JUNK_SYMBOLS[0]+'")') obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_replace_function+"('"+aux+"','"+Config.JUNK_SYMBOLS[0]+"')") return obj
def hide_strings_split(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>2: obj[i] = obj[i].replace('"'+v[j]+'"',StringModifiers.split_string(v[j])) obj[i] = obj[i].replace("'"+v[j]+"'",StringModifiers.split_string(v[j])) return obj
def hide_strings_hexify(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>0: obj[i] = obj[i].replace('"'+v[j]+'"','BinaryToString("'+StringModifiers.hexify_string(v[j])+'") ') obj[i] = obj[i].replace("'"+v[j]+"'","BinaryToString('"+StringModifiers.hexify_string(v[j])+"') ") return obj
def hide_strings_flip_two(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>2: obj[i] = obj[i].replace('"'+v[j]+'"',Globals.string_flip_two_function+'("'+StringModifiers.flip_two_modifier(v[j])+'") ') obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_flip_two_function+"('"+StringModifiers.flip_two_modifier(v[j])+"') ") return obj
def hide_function_parameters(obj): identifiers = list(ex.extract_parameters_from_obj(obj)) replaces = Utils.mod_names_hash(identifiers) boundary = "\n"+Utils.generate_random_string(20,30)+"\n" obj = boundary.join(obj) for i in xrange(len(identifiers)): try: if identifiers[i]: obj = sub(r"\$"+identifiers[i][1:]+r"\b","$"+replaces[i]+" ",obj) except: continue return obj.split(boundary)
def hide_strings_reverse(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>2: obj[i] = obj[i].replace('"'+v[j]+'"',Globals.string_reverse_function+'("'+v[j][::-1]+'") ') obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_reverse_function+"('"+v[j][::-1]+"') ") # return obj
def hide_strings_rotate(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>2: params = StringModifiers.rotate_string(v[j]) obj[i] = obj[i].replace('"'+v[j]+'"',Globals.string_rotate_function+'("'+params[0]+'",'+str(params[1])+') ') obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_rotate_function+"('"+params[0]+"',"+str(params[1])+") ") return obj
def block_if(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000): res = Utils.low_up_string("If ") declarations = "" n_guard_statements = randint(min(n_guard_statements_min,n_guard_statements_max),max(n_guard_statements_min,n_guard_statements_max)) log_statements = logical_statements(n_guard_statements) + Utils.low_up_string(" Then")+"\n" logic_variables = ExtractKeywords.extract_variables(log_statements) for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n" res += log_statements res += block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n" else_type = randint(0,1) # 0 -> Else if, 1 -> Else # if else_type==0: n_else_if = randint(min(n_else_if_min,n_else_if_max),max(n_else_if_min,n_else_if_max)) for i in xrange(n_else_if): log_statements = logical_statements(randint(min(n_guard_statements_min,n_guard_statements_max),max(n_guard_statements_min,n_guard_statements_max))) logic_variables = ExtractKeywords.extract_variables(log_statements) for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n" res += Utils.low_up_string("ElseIf ")+log_statements+Utils.low_up_string(" Then\n")+block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n" res += Utils.low_up_string("Else ")+"\n"+block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n" res += Utils.low_up_string("EndIf")+"\n" return declarations+res
def hide_strings_definition_shuffle(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux)>0 and aux[0]!="#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j])>0: shuffled = StringModifiers.shuffle_string(v[j]) obj[i] = obj[i].replace('"'+v[j]+'"',Globals.string_shuffle_function+'("'+shuffled[0]+'","'+shuffled[1]+'") ') obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_shuffle_function+"('"+shuffled[0]+"','"+shuffled[1]+"') ") return obj
def ternary_operation(n_guard_statements_min=1,n_guard_statements_max=3): res = "" declarations = "" var = variable() n_guard_statements = randint(min(n_guard_statements_min,n_guard_statements_max), min(n_guard_statements_min,n_guard_statements_max)) log_statements = logical_statements(n_guard_statements) logic_variables = ExtractKeywords.extract_variables(log_statements) res += Utils.generate_random_declarator()+var+"\n" for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n" res += var+" = (" + log_statements + ") ? " + value() + " : " + value() return declarations+res+"\n"
def hide_strings_split(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j]) > 2: obj[i] = obj[i].replace('"' + v[j] + '"', StringModifiers.split_string(v[j])) obj[i] = obj[i].replace("'" + v[j] + "'", StringModifiers.split_string(v[j])) return obj
def hide_variable_names(obj): identifiers = list(ex.extract_defined_variables_from_obj( obj)) # Extraer solo las que se definen en el script # replaces = Utils.mod_names_hash(identifiers) boundary = "\n" + Utils.generate_random_string(20, 30) + "\n" obj = boundary.join(obj) for i in xrange(len(identifiers)): if identifiers[i]: obj = sub(r"\$" + identifiers[i][1:] + r"\b", "$" + replaces[i] + " ", obj) return obj.split(boundary)
def hide_strings_flip_two(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): v[j] = v[j][1:-1] if len(v[j]) > 2: obj[i] = obj[i].replace( '"' + v[j] + '"', Globals.string_flip_two_function + '("' + StringModifiers.flip_two_modifier(v[j]) + '") ') #obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_flip_two_function+'("'+StringModifiers.flip_two_modifier(v[j])+'") ') # return obj
def hide_function_parameters(obj): identifiers = list(ex.extract_parameters_from_obj(obj)) replaces = Utils.mod_names_hash(identifiers) boundary = "\n" + Utils.generate_random_string(20, 30) + "\n" obj = boundary.join(obj) for i in xrange(len(identifiers)): try: if identifiers[i]: obj = sub(r"\$" + identifiers[i][1:] + r"\b", "$" + replaces[i] + " ", obj) except: continue return obj.split(boundary)
def block_while(deep_act, n_statements_min=10, n_statements_max=20, n_guard_statements_min=1, n_guard_statements_max=5, n_else_if_min=1, n_else_if_max=5, deep_max=5, case_values_min=-1000, case_values_max=1000): n_guard_statements = randint( min(n_guard_statements_min, n_guard_statements_max), max(n_guard_statements_min, n_guard_statements_max)) log_statements, declarations = logical_statements(n_guard_statements), "" logic_variables = ExtractKeywords.extract_variables(log_statements) relational_operators = ExtractKeywords.extract_relational_operators( log_statements) const_values = ExtractKeywords.extract_integer(log_statements) for i in logic_variables: declarations += Utils.generate_random_declarator( ) + assign_by_var_name(i) + "\n" res = declarations + Utils.low_up_string("\nWhile ") + log_statements return res # Acabar #
def hide_strings_reverse(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j]) > 2: obj[i] = obj[i].replace( '"' + v[j] + '"', Globals.string_reverse_function + '("' + v[j][::-1] + '") ') obj[i] = obj[i].replace("'" + v[j] + "'", Globals.string_reverse_function + "('" + v[j][::-1] + "') ") # return obj
def hide_strings_hexify(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j]) > 0: obj[i] = obj[i].replace( '"' + v[j] + '"', 'BinaryToString("' + StringModifiers.hexify_string(v[j]) + '") ') obj[i] = obj[i].replace( "'" + v[j] + "'", "BinaryToString('" + StringModifiers.hexify_string(v[j]) + "') ") return obj
def ternary_operation(n_guard_statements_min=1, n_guard_statements_max=3): res = "" declarations = "" var = variable() n_guard_statements = randint( min(n_guard_statements_min, n_guard_statements_max), min(n_guard_statements_min, n_guard_statements_max)) log_statements = logical_statements(n_guard_statements) logic_variables = ExtractKeywords.extract_variables(log_statements) res += Utils.generate_random_declarator() + var + "\n" for i in logic_variables: declarations += Utils.generate_random_declarator( ) + assign_by_var_name(i) + "\n" res += var + " = (" + log_statements + ") ? " + value() + " : " + value() return declarations + res + "\n"
def hide_strings_definition_shuffle(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j]) > 0: shuffled = StringModifiers.shuffle_string(v[j]) obj[i] = obj[i].replace( '"' + v[j] + '"', Globals.string_shuffle_function + '("' + shuffled[0] + '","' + shuffled[1] + '") ') obj[i] = obj[i].replace( "'" + v[j] + "'", Globals.string_shuffle_function + "('" + shuffled[0] + "','" + shuffled[1] + "') ") return obj
def hide_strings_rotate(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): if len(v[j]) > 2: params = StringModifiers.rotate_string(v[j]) obj[i] = obj[i].replace( '"' + v[j] + '"', Globals.string_rotate_function + '("' + params[0] + '",' + str(params[1]) + ') ') obj[i] = obj[i].replace( "'" + v[j] + "'", Globals.string_rotate_function + "('" + params[0] + "'," + str(params[1]) + ") ") return obj
def hide_strings_replace(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) if not "#include" in obj[i] and not "RegExp" in obj[i]: for j in xrange(len(v)): v[j] = v[j][1:-1] if len(v[j].strip( )) > 0 and len(obj[i]) < Globals.max_size_len_autoit - ( len(obj[i]) + (1.0 / 2) * len(obj[i])) + 4 + len(Config.JUNK_SYMBOLS[0]): aux = Utils.add_random_char_between_string( v[j], Config.JUNK_SYMBOLS[0]) obj[i] = obj[i].replace( '"' + v[j] + '"', Globals.string_replace_function + "('" + aux + "','" + Config.JUNK_SYMBOLS[0] + "')") return obj
def hide_strings_split(obj): for i in xrange(len(obj)): v = ex.extract_string(obj[i]) aux = obj[i].strip() if len(aux) > 0 and aux[0] != "#" and not "RegExp" in aux: for j in xrange(len(v)): v[j] = v[j][ 1:-1] # !Comillas! -> puede bugear esto, probar a dejarlas if len(v[j]) > 2: obj[i] = obj[i].replace('"' + v[j] + '"', StringModifiers.split_string(v[j])) #obj[i] = obj[i].replace("'"+v[j]+"'",StringModifiers.split_string(v[j])) #print v[j] #print StringModifiers.split_string(v[j]) #raw_input() #obj[i] = obj[i].replace('"'+v[j]+'"',StringModifiers.split_string(v[j])) #obj[i] = obj[i].replace("'"+v[j]+"'",Globals.string_flip_two_function+'("'+StringModifiers.flip_two_modifier(v[j])+'") ') # return obj
def hide_numbers(obj, deep_max_min=3, deep_max_max=5, lower_bound=-10000, upper_bound=10000): deep_max = randint(min(deep_max_min, deep_max_max), max(deep_max_min, deep_max_max)) for i in xrange(len(obj)): #floats = ExtractKeywords.extract_float(obj[i]) integers = ExtractKeywords.extract_integer(obj[i]) #for j in xrange(len(floats)): obj[i] = obj[i].replace(floats[j],hide_number(float(floats[j]),0,deep_max,lower_bound,upper_bound)) for j in xrange(len(integers)): if int(integers[j]) != 0: obj[i] = obj[i].replace( " " + integers[j] + "\n", " " + hide_number(int(integers[j]), 0, deep_max, lower_bound, upper_bound) + "\n") return obj
def hide_definitions_with_assign(obj): for i in xrange(len(obj)): obj[i] = obj[i].strip() aux = obj[i].lower() res = "" if len(obj[i]) > 0 and obj[i][-1] != "_" and aux.find( "eval(") == -1 and aux.find("assign(") == -1: if obj[i][0] == "$": assign_expression = ex.extract_assign_expressions(obj[i]) if len(assign_expression) > 0: assign_expression = assign_expression[0] make = 0 if "'" in assign_expression[ 2] and '"' in assign_expression[2] else 1 if make and ',' not in assign_expression[ 2] and ';' not in assign_expression[ 2] and '#' not in assign_expression[2]: if assign_expression[1] == "=": #print assign_expression res += Utils.low_up_string( " Assign('") + assign_expression[0][ 1:] + "'," + assign_expression[2] + ")\n" obj[i] = res return obj
def hide_expressions_with_execute(obj): for i in xrange(len(obj)): obj[i] = obj[i].strip() aux = obj[i].lower() prob_execute = 0.75 res = "" if len(obj[i]) > 0 and obj[i][-1] != "_" and aux.find( "execute(") == -1 and aux.find("eval(") == -1 and aux.find( "assign(") == -1: local, dim, glbal = aux.find("local"), aux.find("dim"), aux.find( "global") if local == 0: res += Utils.low_up_string(" Local ") elif dim == 0: res += Utils.low_up_string(" Dim ") elif glbal == 0: res += Utils.low_up_string(" Global ") r = uniform(0, 1) if (local == 0 or dim == 0 or glbal == 0 or obj[i][0] == "$") and r <= prob_execute: assign_expression = ex.extract_assign_expressions(obj[i]) if len(assign_expression) > 0: assign_expression = assign_expression[0] make = 0 if "'" in assign_expression[ 2] and '"' in assign_expression[2] else 1 if make and "," not in assign_expression[ 2] and ',' not in assign_expression[ 2] and ';' not in assign_expression[ 2] and '#' not in assign_expression[ 2]: # Evitar definiciones multiples # if assign_expression[1] == "=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(" ) + quote + assign_expression[2] + quote + ") \n" obj[i] = res elif assign_expression[1] == "+=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(") + quote + assign_expression[ 0] + " + " + assign_expression[ 2] + quote + ")\n" obj[i] = res elif assign_expression[1] == "-=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(") + quote + assign_expression[ 0] + " - " + assign_expression[ 2] + quote + ")\n" obj[i] = res elif assign_expression[1] == "*=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(") + quote + assign_expression[ 0] + " * " + assign_expression[ 2] + quote + ")\n" obj[i] = res elif assign_expression[1] == "/=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(") + quote + assign_expression[ 0] + " / " + assign_expression[ 2] + quote + ")\n" obj[i] = res elif assign_expression[1] == "&=": quote = repr(assign_expression[2])[0] res += assign_expression[0] + Utils.low_up_string( " = Execute(") + quote + assign_expression[ 0] + " & " + assign_expression[ 2] + quote + ")\n" obj[i] = res return obj
def generate_graph(obj): obj = [obj[i] for i in xrange(len(obj)) if not not obj[i].strip()] flags = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ] # while_,do_while_,for_TO,for_IN,func_,if_,select_,switch_,with_ for line in obj: print line # Ajustar con Kernel.ExtractKeywords // Cuidado con el orden -> Do While antes de While y demás ..# if ex.is_do_while(line): flags[1] = 1 if ex.is_while(line): flags[0] = 1 if ex.is_for_to(line): flags[2] = 1 if ex.is_for_in(line): flags[3] = 1 if ex.is_func(line): flags[4] = 1 if ex.is_if(line): flags[5] = 1 if ex.is_select(line): flags[6] = 1 if ex.is_switch(line): flags[7] = 1 if ex.is_with(line): flags[8] = 1 if ex.is_end_while(line): flags[0] = 0 if ex.is_until(line): flags[1] = 0 if ex.is_next(line): if flags[2] == 1: flags[2] = 0 # Si es TO # else: flags[3] = 0 # Si es IN # if ex.is_end_func(line): flags[4] = 0 if ex.is_end_if(line): flags[5] = 0 if ex.is_end_select(line): flags[6] = 0 if ex.is_end_switch(line): flags[7] = 0 if ex.is_end_with(line): flags[8] = 0 raw_input() print flags
def generate_graph(obj): obj = [obj[i] for i in xrange(len(obj)) if not not obj[i].strip()] flags = [0,0,0,0,0,0,0,0,0] # while_,do_while_,for_TO,for_IN,func_,if_,select_,switch_,with_ for line in obj: print line # Ajustar con Kernel.ExtractKeywords // Cuidado con el orden -> Do While antes de While y demás ..# if ex.is_do_while(line): flags[1] = 1 if ex.is_while(line): flags[0] = 1 if ex.is_for_to(line): flags[2] = 1 if ex.is_for_in(line): flags[3] = 1 if ex.is_func(line): flags[4] = 1 if ex.is_if(line): flags[5] = 1 if ex.is_select(line): flags[6] = 1 if ex.is_switch(line): flags[7] = 1 if ex.is_with(line): flags[8] = 1 if ex.is_end_while(line): flags[0] = 0 if ex.is_until(line): flags[1] = 0 if ex.is_next(line): if flags[2]==1: flags[2] = 0 # Si es TO # else: flags[3] = 0 # Si es IN # if ex.is_end_func(line): flags[4] = 0 if ex.is_end_if(line): flags[5] = 0 if ex.is_end_select(line): flags[6] = 0 if ex.is_end_switch(line): flags[7] = 0 if ex.is_end_with(line): flags[8] = 0 raw_input() print flags