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
Beispiel #2
0
def simple_block(n_statements_min=10,n_statements_max=20): 
    n_statements = randint(min(n_statements_min,n_statements_max),max(n_statements_min,n_statements_max))
    variables    = [variable() for i in xrange(n_statements)]
    values       = [value() for i in xrange(n_statements)]
    res = ""
    for i in xrange(n_statements): res += assign(variables[i],values[i])+"\n"
    #res += enum(1,3,5,10) + "\n"
    #elif rnd==2: res += ternary_operation(1,3)
    for i in xrange(n_statements/2):
	""" -3 -> ternary
	    -2 -> enum
	    -1 -> arithmetic assign
	    0  -> f arity 0
	    1  -> f arity 1
	    2  -> f arity 2
	"""
	arity = randint(-1,2)
	if arity==-1:   
	    r,rp  = randint(0,len(variables)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+variables[rp]+"\n"
	elif arity==0:  res  += Utils.low_up_string(choice(Config.FUNCTIONS_ZERO_ARITY)) + "()\n"
	elif arity==1:  
	    r,rf,rp  = randint(0,len(variables)-1),randint(0,len(Config.FUNCTIONS_ONE_ARITY)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+Utils.low_up_string(Config.FUNCTIONS_ONE_ARITY[rf])+"("+variables[rp]+")\n"
	elif arity==2:
	    r,rf,rp,rt = randint(0,len(variables)-1),randint(0,len(Config.FUNCTIONS_TWO_ARITY)-1),randint(0,len(variables)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+Utils.low_up_string(Config.FUNCTIONS_TWO_ARITY[rf])+"("+variables[rp]+","+variables[rt]+")\n"
    return res
Beispiel #3
0
def block_with(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):
    v           = variable()
    declaration = Utils.generate_random_declarator()+v+' = ObjCreate("shell.application") \n'
    res 	= Utils.low_up_string(" With ") + v + "\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)+Utils.low_up_string("\n EndWith\n")
    return declaration+res
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_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)
Beispiel #6
0
def block_func(arity_min=1,arity_max=4,identifiers_length_min=5,identifiers_length_max=10,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):
    id_func,arity = Utils.generate_identifier(identifiers_length_min,identifiers_length_max),randint(min(arity_min,arity_max),max(arity_min,arity_max))
    Config.TDS_FUNCTIONS[id_func]=arity # ¿Sobra?
    res = Utils.low_up_string("Func ")+id_func+"("
    for i in xrange(arity):
	if i<arity-1:  res += variable()+","
	else:          res += variable()
    res += ")\n\n\n"+block(0,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)+Utils.low_up_string("\n EndFunc\n")
    Globals.arity_new_functions.append(arity)
    return res
Beispiel #7
0
def enum(n_enumeration_min=1,n_enumeration_max=3,length_min=5,length_max=10):
    rnd_enum = randint(n_enumeration_min,n_enumeration_max)
    r        = Utils.low_up_string("Local Enum ")
    rnd_step = randint(0,1)
    if rnd_step==1:       r   += Utils.low_up_string("Step ")+enum_stepval()+" "
    for i in xrange(rnd_enum):
	var = variable(length_min,length_max)
	val = value()
	r  += var_definition(var,val)
	if i != rnd_enum-1: r += ", "
	else:               r += " "
    return r
Beispiel #8
0
def block_switch(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): 
    v = variable()
    declaration = Utils.generate_random_declarator()+assign_by_var_name(v)+"\n"
    n_cases = randint(min(n_else_if_min,n_else_if_max),max(n_else_if_min,n_else_if_max))
    res = Utils.low_up_string("Switch ")+v+"\n" 
    for i in xrange(n_cases):
	a,b = integer(min(case_values_min,case_values_max),max(case_values_min,case_values_max)),integer(min(case_values_min,case_values_max),max(case_values_min,case_values_max))
	a,b = min(a,b),max(a,b)
	res += Utils.low_up_string("Case ")+a+Utils.low_up_string(" To ")+b+"\n"+block(deep_act,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)
	res += "\nCase Else\n"+block(deep_act,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)
    res += Utils.low_up_string("\nEndSwitch\n")
    return declaration+res
Beispiel #9
0
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 add_true_guard_statements_while(line,n_guard_statements_left,true_guard_statements_left,
			         n_guard_statements_right,true_guard_statements_right):
				     				     
    line = line.strip()
    if line[-1]!="_":
	splitted = split("\s",line)
	line = splitted[0] + " "
	if n_guard_statements_left>0:
	    line += Utils.low_up_string(" And ").join(true_guard_statements_left) + Utils.low_up_string(" And ")
	line += " ".join(splitted[1:])
	if n_guard_statements_right>0:
	    line += Utils.low_up_string(" And ") + Utils.low_up_string(" And ").join(true_guard_statements_right)
    return line
def add_hardcoded_funcs(obj,add_calls=False,functions=Globals.defined_new_functions,arity=Globals.arity_new_functions,n_funcs_min=3,n_funcs_max=5):
    n_funcs = randint(min(n_funcs_min,n_funcs_max),max(n_funcs_min,n_funcs_max))
    shuffle(hp.HARDCODED_PROGRAMS)
    funcs   = hp.HARDCODED_PROGRAMS[:n_funcs]
    for i in xrange(n_funcs):
	function_code   = funcs[i]()
	obj.insert(0,function_code+"\n\n")
	if add_calls:
	    arity           = Globals.arity_new_functions[-1]
	    identifier      = Globals.defined_new_functions[-1]
	    params          = ",".join([g.value() for i in xrange(arity)])
	    obj.insert(0,Utils.low_up_string(Utils.generate_random_declarator()) + \
		       g.variable() + " = " + identifier + "("+params+")\n\n")
    return obj
Beispiel #12
0
def block_for(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): 
    a,b = integer(),integer()
    a,b = min(a,b),max(a,b)
    v   = variable()
    declaration = Utils.generate_random_declarator()+assign_by_var_name(v)+"\n\n"
    res = Utils.low_up_string("For ")+assign_full(v,a)+Utils.low_up_string(" To ")+b
    rnd_step = randint(0,1)
    if rnd_step==1:    
	res += Utils.low_up_string(" Step ")+str(randint(1,10))+" \n"
    else:              res += "\n"
    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)+Utils.low_up_string("\n Next\n")
    return declaration+res
Beispiel #13
0
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))
    vars_one = []
    vars_two = []
    vals_one = []
    vals_two = []
    rel_ops  = []
    declarations = []
    for i in xrange(n_guard_statements):
	vars_one.append(variable())
	vars_two.append(variable())
	vals_one.append(integer(100,1000))
	vals_two.append(integer(100,1000))
	rel_ops.append(choice([">","<",">=","<=","="]))
	declarations.append(Utils.generate_random_declarator() + vars_one[i] + " = " + vals_one[i])
	declarations.append(Utils.generate_random_declarator() + vars_two[i] + " = " + vals_two[i])
    
    res      = Utils.low_up_string(" While ")
   
    for i in xrange(n_guard_statements):
	res += vars_one[i] + " " + rel_ops[i] + " "+ vars_two[i]
	if i<n_guard_statements-1: res += Utils.low_up_string(" Or ")
    
    res += "\n"
    
    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"
			    
    
    for i in xrange(n_guard_statements):
	if rel_ops[i]==">":
	    if vals_one[i]>vals_two[i]: 
		res += choice([vars_one[i] + " -= 1\n", vars_two[i] + " += 1\n"])
	elif rel_ops[i]=="<":
	    if vals_one[i]<vals_two[i]:  res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n"])
	elif rel_ops[i]==">=":
	    if vals_one[i]>=vals_two[i]: 
		res += choice([vars_one[i] + " -= 1\n", vars_two[i] + " += 1\n"])
	elif rel_ops[i]=="<=":
	     if vals_one[i]<=vals_two[i]: res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n"])
	elif rel_ops[i]=="=":
	    if vals_one[i]==vals_two[i]: res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n" , 
							vars_one[i] + " -= 1\n",vars_two[i] + " += 1\n"])
			
    res += Utils.low_up_string("\nWEnd\n")
    return "\n".join(declarations)+"\n"+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 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_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 add_true_guard_statements_if(line,n_guard_statements_left,true_guard_statements_left,
			         n_guard_statements_right,true_guard_statements_right):
    line = line.strip()
    if line[-1]!="_": 
	aux    = line.title()
	splitted_aux = split("\s",aux)
	splitted     = split("\s",line)
	index_then = splitted_aux.index("Then")
		    
	line = splitted[0] + " " 
		    
	if n_guard_statements_left>0:
	    line += Utils.low_up_string(" And ").join(true_guard_statements_left) + Utils.low_up_string(" And ")
			
	line += " ".join(splitted[1:index_then])
		    
	if n_guard_statements_right>0:
	    line += Utils.low_up_string(" And ") + Utils.low_up_string(" And ").join(true_guard_statements_right)
			
	line += " " + " ".join(splitted[index_then:])
    return line
def add_regions(obj,n_regions_min=5,n_regions_max=10,id_length_min=5,id_length_max=10):
    n_regions       = randint(n_regions_min,n_regions_max)
    pos_regions     = [randint(0,len(obj)-1) for i in xrange(n_regions)]
    pos_end_regions = [randint(pos_regions[i]+1,len(obj)-1) for i in xrange(n_regions) if pos_regions[i]+1<len(obj)-1]
    while len(pos_end_regions)<n_regions: pos_end_regions.append(randint(0,len(obj)-1))
    for i in xrange(n_regions):
	id_length = randint(id_length_min,id_length_max)
	if pos_regions[i]>0 and pos_end_regions[i]>0:
	    ant_line_init_region = obj[pos_regions[i]-1].strip()
	    ant_line_end_region  = obj[pos_end_regions[i]-1].strip()
	    if len(ant_line_init_region)>0 and len(ant_line_end_region)>0 and ant_line_init_region[-1]!='_' and ant_line_end_region[-1]!='_':
		obj.insert(pos_regions[i],"#region "+Utils.generate_random_key(id_length)+"\n")
		obj.insert(pos_end_regions[i],"#endregion\n\n")
    return obj
Beispiel #19
0
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 add_random_directives(obj,n_directives_min=5,n_directives_max=20,n_includes_min=10,n_includes_max=20,func_name=Utils.generate_random_string(ext="")):
    pragma,include,start,tray,once = randint(0,1),randint(0,1),randint(0,1),randint(0,1),randint(0,1)
    if start:   obj = add_autoit_on_start_directive(obj,func_name)
    if tray:    obj = add_no_tray_icon_directive(obj)
    if include: obj = add_include_directives(obj,n_includes_min,n_includes_max)
    if once:    obj = add_include_once_directive(obj)
    if pragma:  obj = add_pragma_directives(obj,n_directives_min,n_directives_max)
    return obj
## Requiere el código estructurado ##
def remove_comments_by_semicolon(obj): 
    for i in xrange(len(obj)):
	obj[i] = obj[i][obj[i].rfind(";")+1:]
    return obj

def remove_comments_by_hash(obj):
    res = []
    for i in xrange(len(obj)): 
	aux = obj[i].strip()
	if len(aux)>0 and aux[0]!="#" and not "include" in aux: res.append(obj[i])
    return res
    
def remove_region_directive(obj):
    for i in xrange(len(obj)):
	aux = obj[i].lower().strip()
	if aux.find("#region")==0 or aux.find("#endregion")==0: obj[i] = "\n"
    return obj
	
def remove_comments_by_comment_tag(code): return sub(r"#comments-start.*#comments-end[^\n]*","",code,flags=DOTALL)
def remove_comments_by_c_tag(code): return sub(r"#cs.*#ce[^\n]*","",code,flags=DOTALL)
def remove_comments_by_tag(code): return remove_comments_by_c_tag(remove_comments_by_comment_tag(code))

########################################

if __name__ == "__main__":
    a = Utils.extract_code("runpe_danyfirex.au3")
    a = Utils.get_string_from_code(a)
    a = remove_comments(a)
    print a
Beispiel #22
0
    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


if __name__ == "__main__":
    obj = Utils.remove_comments(Utils.extract_code("test.au3"))
    print generate_graph(obj)
	try:
	    if identifiers[i]: obj = sub(r"\$"+identifiers[i][1:]+r"\b","$"+replaces[i]+"  ",obj)
	except: continue
    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)
    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_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")

if __name__ == "__main__":
    obj = Utils.extract_code("test.au3")
    obj = hide_variable_names(obj)
    obj = hide_function_names(obj)
    Utils.write_code(Utils.get_string_from_obj(obj),"testmod.au3")
    #print generate_graph(obj)
    
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__import__("sys").path.append('./System')
from string import ascii_letters, digits, punctuation, whitespace, ascii_uppercase, ascii_lowercase
from Kernel import Utils
from random import shuffle
import base64

####################### DIRECTIVES #######################
PRAGMA_DIRECTIVES = ["Out","ExecLevel","UPX","AutoItExecuteAllowed","Console","Compression",\
       "Compatibility","x64","inputboxres","Comments","CompanyName","FileDescription",\
       "FileVersion","InternalName","LegalCopyright","LegalTrademarks","OriginalFilename",\
       "ProductName","ProductVersion"]

PRAGMA_VALID_VALUES = [Utils.generate_random_string(ext="exe"),\
         ["none","asInvoker","highestAvailable"],["true","false"],\
         ["true","false"],["true","false"],['1','3','5','7','9'],["vista","win7","win8","win81","win10"],\
         ["true","false"],["true","false"],Utils.generate_random_string(15,30,""),\
         Utils.generate_random_string(10,15,""),Utils.generate_random_string(15,50,""),\
         Utils.generate_random_string(5,10,""),Utils.generate_random_string(20,30,""),\
         Utils.generate_random_string(50,75,""),Utils.generate_random_string(50,75,""),\
         Utils.generate_random_string(15,30,""),Utils.generate_random_string(10,20,""),\
         Utils.generate_random_string(10,20,"")]

##########################################################

####################### AUTOIT DEFINITIONS #######################

INCLUDES = [
    'AVIConstants.au3', 'Array.au3', 'BorderConstants.au3',
def hex_to_string(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sHex)
Beispiel #26
0
def string_dump(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(2)
    return """Func """ + identifier + """($sString, $iLength)
Beispiel #27
0
def is_prime(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """ + identifier + """($iNum) ; Alexander Alvonellos
Beispiel #28
0
def log_change_base(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(2)
    return """Func """ + identifier + """($Number, $Base)
Beispiel #29
0
def flip_two_string(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.string_flip_two_function = identifier
    return """Func """ + identifier + """($sText)
Beispiel #30
0
def replace_string(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.string_replace_function = identifier
    return """Func """ + identifier + """($sText,$symbol)
Beispiel #31
0
def random_autoit(length_min=10, length_max=15):
    identifier = Utils.generate_identifier(length_min, length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(2)
    return """Func """ + identifier + """($nNum1 = 0, $nNum2 = 0, $iFlag = 0)
Beispiel #32
0
def hide_variable_names(obj):
    identifiers = list(ex.extract_variables_from_obj(obj))
    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
Beispiel #33
0
def logical_operation(): return choice([Utils.low_up_string("And"),Utils.low_up_string("Or")])

def logical_statement(spaces_min=1,spaces_max=5): return variable()+" "+relational_operation()+" "+value() # Facilita las cosas un formato estándar #
def y_day_to_date(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(2)
    return """Func """+identifier+"""($yday, $year)
def get_separator(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sString)
Beispiel #36
0
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
Beispiel #37
0
                    ) + "] = " + 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 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)):
                v[j] = v[j][1:-1]
                if '"' not in v[j] and "'" not in v[j] and len(v[j]) > 0:
                    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


if __name__ == "__main__":
    obj = Utils.extract_code("test.au3")
    obj = hide_strings_definition(obj)
    Utils.write_code(Utils.get_string_from_obj(obj), "testmod.au3")
    #print generate_graph(obj)
def days_in_month(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(2)
    return """Func """+identifier+"""($iMonth,$iYear)
def base_128_decode(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sStr)
def is_maximized(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($hWnd)
Beispiel #41
0
def logical_operation():
    return choice([Utils.low_up_string("And"), Utils.low_up_string("Or")])
def ternary(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(3)
    return """Func """+identifier+"""($iValue, $vTrue, $vFalse)
def random_autoit(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(3)
    return """Func """+identifier+"""($nNum1 = 0, $nNum2 = 0, $iFlag = 0)
def get_cpu_name(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(0)
    return """Func """+identifier+"""()
def add_autoit_on_start_directive(obj,func_name=Utils.generate_random_string(ext="")): 
    obj.insert(0,d.on_autoit_start_register(func_name))
    return obj
def format_bytes_size(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($iBytes)
Beispiel #47
0
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 reg_exists(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sKey)
Beispiel #49
0
def assign(var,val):
    rnd = randint(0,1)
    if rnd==0: return Utils.generate_random_declarator()+var+" = "+val+"\n"
    else:      return Utils.generate_random_declarator()+var+" = 0\n"+Utils.low_up_string("Assign")+"('"+var+"','"+val.replace('"',"").replace("'","")+"')\n"
def get_bit_entropy(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sStr, $fCase = True)
def name_count(length_min=10,length_max=15):
    identifier = Utils.generate_identifier(length_min,length_max)
    Globals.defined_new_functions.append(identifier)
    Globals.arity_new_functions.append(1)
    return """Func """+identifier+"""($sData)
Beispiel #52
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__import__("sys").path.append('../')
from Kernel import Utils
from Kernel import ExtractKeywords as ex
from GenerateCode import Grammar as g


def hide_code_with_string(obj):
    code = Utils.get_string_from_obj(obj)
    code = Utils.standar_quotes(code)
    obj = Utils.get_obj_from_code(code)
    s_var = g.variable()
    res = "Local " + s_var + ' = "' + obj[0] + '" & _ \n'
    for i in xrange(1, len(obj) - 1):
        res += '"' + obj[i] + '" & _ \n'
    res += '"' + obj[len(obj) - 1] + '"\n'
    res += "Local " + g.variable() + " = Execute(" + s_var + ")\n"
    return res


if __name__ == "__main__":
    obj = Utils.extract_code("test_m3.au3")
    #obj = hide_variable_names(obj)
    #obj = hide_function_names(obj)
    print hide_code_with_string(obj)
    #Utils.write_code(Utils.get_string_from_obj(obj),"test_m3_mod.au3")
    #print generate_graph(obj)