) + "] = " + 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)
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)
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
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)
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)
## 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