# -*- coding: utf-8 -*- import os import subprocess from stat import * #start_dir = '/media/ARC_1/Android64/buildroot-2013.11/output/target' start_dir = '/media/ARC_1/Android64/mclinux371/target' #start_dir = '/home/dark/mlinux/work/toolchain/buildroot-2011.05/output/target' file_list = [] for root, dirs, files in os.walk(start_dir): for f in files: file_list.append(os.path.join(root, f)) exefile_list = [] #exefile_list.append('/media/ARC_1/Android64/buildroot-2013.11/output/host/usr/lib/gcc/mipsel-buildroot-linux-uclibc/4.8.2/libgcc.a') exefile_list.append('/media/ARC_1/Android64/mclinux371/linux-3.7.1/vmlinux') for f in file_list: try: mode = os.lstat(f)[ST_MODE] if not S_ISREG(mode) : continue if S_IXUSR & mode : exefile_list.append(f) except OSError: None # print exefile_list disassembled_file = [] log_file = "/media/ARC_1/Android64/check/log.txt" out_log = open(log_file,"w") for f in exefile_list : objdump_str = "/media/ARC_1/Android64/buildroot-2013.11/output/host/usr/bin/mipsel-linux-objdump" disassemble_opt = "--disassemble" source_file = f output_file = "/media/ARC_1/Android64/check/disassemble" + f[f.rfind('/'):] + ".txt" call_arg = objdump_str + " " + disassemble_opt + " " + source_file + " > " + output_file; process = subprocess.Popen([call_arg], shell=True) rc = process.wait() if rc != 0 : print "skipped : " , f else : disassembled_file.append(output_file) out_log.write(f + "\n") # print disassembled_file l = " " l1 = " " load_list = ["lw", "lb", "lbu", "ldc1", "lwc1", "lh", "lhu"] jump_list = ["b", "bal", "bc1f", "bc1fl", "bc1t", "bc1tl", "beq", "beqz", "beql", "bgez", "bgezal", "bgezall", \ "bgezl", "bgez", "bgtz", "bgtzl", "blez", "blezl", "bltz" ,"bltzal", "bltzall", "bne", "bnez", "bnel", \ "bnezl", "j", "jal", "jr", "jalr"] ls_list = ["lw", "lb", "lbu", "ldc1", "lwc1", "lh", "lhu","sw","sb","sbu","sdc1","swc1","sh","shu"] for f in disassembled_file: print "check file: ", f out_log.write(f + "\n") dump = open(f) l = " " line_n = 0 while len(l): l1 = l l = dump.readline() line_n = line_n + 1 t1 = l1.split() if len(t1) < 4: if (len(t1) == 2) and (t1[1] == "<.MIPS.stubs>:"): break continue if not (t1[2] in jump_list): continue t = l.split() if len(t) < 4: continue # if t1[2] in ls_list: if (t[2] != "nop"): out_str = str(line_n) + ":\n" + l1 + l + "\n"; out_log.write(out_str); dump.close() out_log.close() print "success..."