def analyze(app_path, data = []): app, d, dx = AnalyzeAPK(app_path) #app = APK(os.path.join(folder, app_path)) app_perms = set(app.get_permissions()) for perm in ALL_PERMISSIONS: if perm in app_perms: data.append(True) else: data.append(False) extcount = dict() for f in app.get_files(): ext = os.path.splitext(f)[1] if ext in extcount: extcount[ext] += 1 else: extcount[ext] = 1 for ext in FILE_EXTENSIONS: if ext in extcount: data.append(extcount[ext]) else: data.append(0) for call in API_CALLS: data.append(len(dx.tainted_packages.search_methods(".", call, "."))) return data + [len(app.get_file("classes.dex")), len(app.get_package()), len(app.get_files()), len(app.get_activities()), len(app.get_services()), len(app.get_providers()), len(dx.tainted_packages.search_crypto_packages()), len(dx.tainted_packages.search_telephony_packages()), len(dx.tainted_packages.search_net_packages()), is_dyn_code(dx), is_native_code(dx), is_reflection_code(dx), len(d.get_classes()), len(d.get_methods()), len(d.get_fields())]
content += " TRUE : " content += self.str2format(self.state2str(start_state)) + "; \n" content += " esac; " #content = content.replace("/", "__") # for the specification of Nusmv, "/",";" is forbidden in use of name define return content if __name__ == "__main__": #inputAPK = "/home/guochenkai/download/SW/androguard/androguard/csdTesting/testing/testNotificationIcon.apk"; inputAPK = "/home/guochenkai/droidWorkspace/Servicesink/bin/Servicesink.apk" try: #apk,d,inputDex = AnalyzeAPK(inputAPK) parseResullt = AnalyzeAPK(inputAPK) print "parse success!!\n" except: print "[error-1]: Could not be parsed!" #with open (AndroConf.result_path, mode='a') as f: #f.write("[app] " + inputContent +"\n") #f.write("--[error-1] Androguard parse error!\n") #return model = AndroModel(parseResullt) ret = model.get_register_methods() print ret #if model.get_states():
else: #print "Main_If_Servicewithsink is None!" pass return csdBlock, ret_total_collect if __name__ == '__main__': method_trace = [] inputContent = "/home/guochenkai/droidWorkspace/Servicesink/bin/Servicesink.apk" inputAPK = inputContent try: apk,vm,inputDex = AnalyzeAPK(inputAPK) #vmx = analysis.VMAnalysis(self.d) except: print "[error-1]: Could not be parsed!" method1_list = vm.get_method("onCreate") for method1 in method1_list: if method1.get_class_name().find("Servicewithsink")!= -1: method_trace.append(method1) #for j in method_trace: #j.show() csd = CsdAnalysis(vm, apk) csd_block = CsdBlockAnalysis (csd)
def process_apk(self, file_name): print('%s processing %s ' % (self.name, file_name)) apk, dex, dx = AnalyzeAPK(file_name) print apk.get_package()