import os import os.path def get_smali_method_count(smaliFile, allMethods): if not os.path.exists(smaliFile): return 0 f = open(smaliFile, 'r', encoding='UTF-8') lines = f.readlines() f.close() classLine = lines[0] classLine.strip() if not classLine.startswith('.class'): print(f + ' not startswith .class') return 0 className = parse_class(classLine) count = 0 for line in lines: line = line.strip() method = None if line.startswith('.method'): method = parse_method_default(className, line) elif line.startswith('invoke-'): method = parse_method_invoke(line) if method is None: continue if method not in allMethods: count = count + 1 allMethods.append(method) else: pass return count def parse_class(line): if not line.startswith('.class'): print('line parse error. not startswith .class : '+line) return None blocks = line.split() return blocks[len(blocks)-1] def parse_method_default(className, line): if not line.startswith('.method'): print('the line parse error in parse_method_default:'+line) return None blocks = line.split() return className + '->' + blocks[len(blocks)-1] def parse_method_invoke(line): if not line.startswith('invoke-'): print('the line parse error in parse_method_invoke:'+line) blocks = line.split() return blocks[len(blocks)-1]