コード例 #1
0
## 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
コード例 #2
0
def remove_comments_by_hash(obj):
    res = []
    for i in xrange(len(obj)): 
	aux = obj[i].strip().lower()
	if len(aux)>0:
	    if aux[0]=="#":
		if aux.find("#comments-start")==0 or aux.find("#comments-end")==0 or aux.find("#include")==0 or \
		   aux.find("#notrayicon")==0 or aux.find("#onautoitstartregister")==0 or aux.find("#pragma")==0 or \
		   aux.find("#requireadmin")==0 or aux.find("#cs")==0 or aux.find("#ce")==0:
		   res.append(obj[i]) 
	    else: 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
コード例 #3
0
	param_names = [g.value() for j in xrange(arity[i])]
	random_pos  = choice([0,-1])
	obj.insert(random_pos,functions[i]+"("+",".join(param_names)+")\n\n")
    return obj

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

def add_hardcoded_string_modifiers(obj,hardcoded_function):
    obj.insert(0,hardcoded_function()+"\n\n")
    return obj

if __name__ == "__main__":
    obj = Utils.extract_code("test.au3")
    obj = add_comments(obj)
    obj = add_variables(obj)
    Utils.write_code(Utils.get_string_from_code(obj),"test_mod.au3")