def append_defunct_class_now(base_dir, curr_dirr, incremental): """Append a random generated class file to the class tree""" class_path = curr_dirr.replace(base_dir, '') # Remove the root reference if class_path.startswith('/'): class_path = class_path[1:] defunct_class = u.get_defunct_class() random_class_name = u.get_random(True, 16) + str(incremental) if class_path != '': class_path = class_path + '/' defunct_class = defunct_class.replace( '*ClassName*', class_path + random_class_name) # Random class name defunct_class = defunct_class.replace('*String1*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*String2*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*MethodName*', u.get_random(True, 16)) # Random method defunct_class = defunct_class.replace('*SourceName*', u.get_random(True, 16)) # Random source u.write_text_file(curr_dirr + '/' + random_class_name + '.smali', defunct_class) # Write the class file
def append_defunct_class_now(base_dir, curr_dir, incremental): """Append a random generated class file to the class tree""" if base_dir == curr_dir: class_path = '' else: class_path = curr_dir.replace(base_dir, '') # Remove the root reference class_path = os.path.relpath(curr_dir, base_dir) defunct_class = u.get_defunct_class() random_class_name = u.get_random(True, 16) + str(incremental) defunct_class = defunct_class.replace( '*ClassName*', os.path.join(class_path, random_class_name)) # Random class name defunct_class = defunct_class.replace('*String1*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*String2*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*MethodName*', u.get_random(True, 16)) # Random method defunct_class = defunct_class.replace('*SourceName*', u.get_random(True, 16)) # Random source u.write_text_file(os.path.join(curr_dir, random_class_name + '.smali'), defunct_class) # Write the class file
def move_string_class(class_name): decrypt_class = u.get_string_class() # Load the decrypt class from file decrypt_class = decrypt_class.replace('StringManagerOb', class_name) # Random key u.write_text_file(u.base_dir() + '/smali/android/content/res/' + class_name + '.smali', decrypt_class) # Write the class file
def move_asset_class(class_name): asset_class = u.get_asset_class() # Load the decrypt class from file asset_class = asset_class.replace('AssetManagerOb', class_name) # Random key u.write_text_file( os.path.join(u.base_dir(), 'smali', 'android', 'content', 'res', class_name + '.smali'), asset_class) # Write the class file
def test_write_text_file(): base_path = 'C:/test/' util.write_text_file(base_path + 'a.txt', 'aaa\nbbb\nccc') util.write_text_file(base_path + 'a-kana.txt', 'abcあいう') util.write_text_file(base_path + 'a-kana-utf8.txt', 'abcあいう', encoding='utf-8') util.write_text_file(base_path + 'a-kana-sjis.txt', 'abcあいう', encoding='shift-jis') return ''
def append_defunct_class_now(base_dir, curr_dirr, incremental): """Append a random generated class file to the class tree""" class_path = curr_dirr.replace(base_dir, '') # Remove the root reference if class_path.startswith('/'): class_path = class_path[1:] defunct_class = u.get_defunct_class() random_class_name = u.get_random(True, 16) + str(incremental) if class_path != '': class_path = class_path + '/' defunct_class = defunct_class.replace('*ClassName*', class_path + random_class_name) # Random class name defunct_class = defunct_class.replace('*String1*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*String2*', u.get_random(True, 16)) # Random string defunct_class = defunct_class.replace('*MethodName*', u.get_random(True, 16)) # Random method defunct_class = defunct_class.replace('*SourceName*', u.get_random(True, 16)) # Random source u.write_text_file(curr_dirr + '/' + random_class_name + '.smali', defunct_class) # Write the class file
def move_asset_class(class_name): asset_class = u.get_asset_class() # Load the decrypt class from file asset_class = asset_class.replace('AssetManagerOb', class_name) # Random key u.write_text_file(u.base_dir()+'/smali/android/content/res/' + class_name + '.smali', asset_class) # Write the class file
def main(): init() subdir = "motifs" motif_fullpath = html_path + "/motifs" util._mkdir(motif_fullpath) main_html_file = open(html_path + "/motifs.html", "w") anti_motif_list = [] for size in motif_sizes: motifs = verify_file(size) motifs_t = motifs_templates(motifs) motif_hist = normalize_motifs(motifs) motif_hist_t = normalize_motifs(motifs_t) print "Generating all graphs of size %d ..." % size, all_graphs = generate_all_graphs(motif_hist, size) print "[DONE]" results = {} for h in all_graphs: G = chemconvert.hash2graph(h) template = G.template() count = int(motifs.get(h, 0)) likelihoods = [0, 0] for i in range(2, size+1): likelihoods.append(get_likelihood(G, motif_hist, i)) delta_l = likelihoods[-2] - likelihoods[-1] if (not results.has_key(template)): results[template] = [] results[template].append((delta_l, likelihoods, count, h)) main_html_file.write("<p>") size_html_file = util.embed_link(main_html_file, html_path, subdir + "/motifs%s" % size, "Motifs of size %s" % size) main_html_file.write("</p>") for (template, graph_list) in results.iteritems(): size_html_file.write("<p>") template_svg = chemconvert.hash2svg(template, 200, 200, node_color=black, bond_color=grey) template_svg.embed_in_html(size_html_file, motif_fullpath, template) count_t = len(graph_list) if (count_t > 0): template_html_file = util.embed_link(size_html_file, motif_fullpath, template, "View all %d instances" % count_t) for (delta_l, likelihoods, count, h) in sorted(graph_list): if (likelihoods[-1] <= log_zero and likelihoods[-2] <= log_zero): continue elif (likelihoods[-1] <= log_zero): bond_color = red anti_motif_list.append(h) else: #bond_color = (0, 255 * math.exp(-delta_l), 255 * (1 - math.exp(-delta_l))) bond_color = green motif_svg = chemconvert.hash2svg(h, 150, 150, black, bond_color) motif_svg.set_attribute("height", 200) if (True): # add #motif_svg.add(svg.Text((35, 25), h, 12, green)) l_string = ",".join(["%.1f" % l for l in likelihoods[2:]]) motif_svg.add(svg.Text((10, 160), "ΔL = %.1f" % delta_l, font_size=12)) motif_svg.add(svg.Text((10, 175), l_string, font_size=12)) if (count > 0): #motif_svg.add(svg.Text((35, 75), "diff = %.1f" % (l1-l0), 12, black)) motif_svg.add(svg.Text((10, 190), "count = %d" % count, font_size=12)) motif_svg.embed_in_html(template_html_file, motif_fullpath, h) else: template_html_file.write("<p>") motif_svg.embed_in_html(template_html_file, motif_fullpath, h) template_html_file.write("<a href=\"" + h + ".svg\">" + h + "</a>") template_html_file.write(", count = %d" % count) for i in range(2, size+1): template_html_file.write(", L(%d) = %.1f" % (i, likelihoods[i])) template_html_file.write("</p>") template_html_file.close() else: size_html_file.write("No instances") size_html_file.write("</p>") size_html_file.close() main_html_file.close() util.write_text_file(anti_motif_list, "../results/stat/anti_motifs.txt") return
def main(): init() subdir = "motifs" motif_fullpath = html_path + "/motifs" util._mkdir(motif_fullpath) main_html_file = open(html_path + "/motifs.html", "w") anti_motif_list = [] for size in motif_sizes: motifs = verify_file(size) motifs_t = motifs_templates(motifs) motif_hist = normalize_motifs(motifs) motif_hist_t = normalize_motifs(motifs_t) print "Generating all graphs of size %d ..." % size, all_graphs = generate_all_graphs(motif_hist, size) print "[DONE]" results = {} for h in all_graphs: G = chemconvert.hash2graph(h) template = G.template() count = int(motifs.get(h, 0)) likelihoods = [0, 0] for i in range(2, size + 1): likelihoods.append(get_likelihood(G, motif_hist, i)) delta_l = likelihoods[-2] - likelihoods[-1] if (not results.has_key(template)): results[template] = [] results[template].append((delta_l, likelihoods, count, h)) main_html_file.write("<p>") size_html_file = util.embed_link(main_html_file, html_path, subdir + "/motifs%s" % size, "Motifs of size %s" % size) main_html_file.write("</p>") for (template, graph_list) in results.iteritems(): size_html_file.write("<p>") template_svg = chemconvert.hash2svg(template, 200, 200, node_color=black, bond_color=grey) template_svg.embed_in_html(size_html_file, motif_fullpath, template) count_t = len(graph_list) if (count_t > 0): template_html_file = util.embed_link( size_html_file, motif_fullpath, template, "View all %d instances" % count_t) for (delta_l, likelihoods, count, h) in sorted(graph_list): if (likelihoods[-1] <= log_zero and likelihoods[-2] <= log_zero): continue elif (likelihoods[-1] <= log_zero): bond_color = red anti_motif_list.append(h) else: #bond_color = (0, 255 * math.exp(-delta_l), 255 * (1 - math.exp(-delta_l))) bond_color = green motif_svg = chemconvert.hash2svg(h, 150, 150, black, bond_color) motif_svg.set_attribute("height", 200) if (True): # add #motif_svg.add(svg.Text((35, 25), h, 12, green)) l_string = ",".join( ["%.1f" % l for l in likelihoods[2:]]) motif_svg.add( svg.Text((10, 160), "ΔL = %.1f" % delta_l, font_size=12)) motif_svg.add( svg.Text((10, 175), l_string, font_size=12)) if (count > 0): #motif_svg.add(svg.Text((35, 75), "diff = %.1f" % (l1-l0), 12, black)) motif_svg.add( svg.Text((10, 190), "count = %d" % count, font_size=12)) motif_svg.embed_in_html(template_html_file, motif_fullpath, h) else: template_html_file.write("<p>") motif_svg.embed_in_html(template_html_file, motif_fullpath, h) template_html_file.write("<a href=\"" + h + ".svg\">" + h + "</a>") template_html_file.write(", count = %d" % count) for i in range(2, size + 1): template_html_file.write(", L(%d) = %.1f" % (i, likelihoods[i])) template_html_file.write("</p>") template_html_file.close() else: size_html_file.write("No instances") size_html_file.write("</p>") size_html_file.close() main_html_file.close() util.write_text_file(anti_motif_list, "../results/stat/anti_motifs.txt") return