def viewapk(apk_path): infoFile = os.path.splitext(apk_path)[0] + '_apkinfo.txt' retcode, msg = star.runcmd2( [PathManager.get_aapt_path(), 'dump', 'badging', apk_path]) if retcode == 0: package = star.find("package: name='(.*?)'", msg) versionCode = star.find("versionCode='(.*?)'", msg) versionName = star.find("versionName='(.*?)'", msg) appName = star.find("application-label:'(.*?)'", msg) activity = star.find("launchable-activity: name='(.*?)'", msg) print(package) print(versionCode) print(versionName) print(appName) print(activity) # APK类型探测 app_type, is_game_app = detectApk(apk_path) if is_game_app: info = '软件名称: {0}\n软件包名: {1}\n软件版本: {2} ( {3} )\n启动Activity: {4}\n该apk为游戏类型app,使用的游戏引擎为: {5}\n'.format( appName, package, versionName, versionCode, activity, ''.join(app_type)) else: info = '软件名称: {0}\n软件包名: {1}\n软件版本: {2} ( {3} )\n启动Activity: {4}\n'.format( appName, package, versionName, versionCode, activity) star.log(info, infoFile) # 打开日志文件 if os.path.exists(infoFile): star.run_cmd_asyn(['notepad', infoFile]) return retcode, msg
def axml2txt(f): ret = 0 msg = None ext = os.path.splitext(f)[1].lower() txtFile = None if ext == '.apk': print('axml2txt .apk') zfile = zipfile.ZipFile(f, 'r', compression=zipfile.ZIP_DEFLATED) for p in zfile.namelist(): if p == "AndroidManifest.xml": axmlFile = os.path.join(Utils.getparent(f), 'AndroidManifest.xml') file(axmlFile, 'wb').write(zfile.read(p)) txtFile = axmlFile + '.txt' star.runcmd2([ PathManager.get_axmlprinter_path(), axmlFile, '>', txtFile ]) break os.remove(axmlFile) else: txtFile = f + '.txt' ret, msg = star.runcmd2( [PathManager.get_axmlprinter_path(), f, '>', txtFile]) print('axml2txt .xml') if os.path.exists(txtFile): star.run_cmd_asyn(['notepad', txtFile]) print('axml2txt ok') return ret, msg
def dex2jar(f): # 如果操作的是apk,则将apk中全部的dex转换为jar文件输出到在apk同级目录下 if f.endswith('.apk'): output_jar_prefix = os.path.splitext(f)[0] + '_' temp_dex_dir = PathManager.get_temp_dir_path() ZipManager.unzip_dexFile_to_dest(f, temp_dex_dir) filenames = os.listdir(temp_dex_dir) for dex_name in filenames: if dex_name.endswith('.dex'): dex_file_path = os.path.join(temp_dex_dir, dex_name) jar_file = output_jar_prefix + os.path.splitext( dex_name)[0] + '.jar' retcode, msg = star.runcmd2([ PathManager.get_dex2jar_path(), dex_file_path, '-f', '-o', jar_file ]) if retcode == 0: star.run_cmd_asyn([PathManager.get_jdgui_path(), jar_file]) print('dex2jar ok') shutil.rmtree(temp_dex_dir) return retcode, msg elif f.endswith('.dex'): jarFile = os.path.splitext(f)[0] + '.jar' retcode, msg = star.runcmd2( [PathManager.get_dex2jar_path(), f, '-f', '-o', jarFile]) if retcode == 0: star.run_cmd_asyn([PathManager.get_jdgui_path(), jarFile]) print('dex2jar ok') return retcode, msg else: print(u'选择文件不合法,文件格式需要是apk或者dex格式') os.system("pause") return 0, None
def viewsign(f): infoFile = os.path.splitext(f)[0] + '_signinfo.txt' check_v2sign_tool_path = PathManager.get_checkV2_sign_tool_path() code, info = star.runcmd2(['java', '-jar', check_v2sign_tool_path, f]) if code == 0: msg_dic = json.loads(info) if msg_dic['isV1OK']: # 如果使用了v1签名,不管是否使用了v2签名检测v1签名 code, info = star.runcmd2([Constant.KEYTOOL_FILENAME, '-printcert', '-jarfile', f]) if msg_dic['isV2'] and not msg_dic['isV1OK']: # 未使用v1签名,仅仅使用了v2签名 info += u"该apk仅仅使用了v2签名,未使用v1签名,具体信息如上所示" if code == 0: star.log(info, infoFile) if os.path.exists(infoFile): star.run_cmd_asyn(['notepad', infoFile]) return code, info
def viewphone(f): adb = ADBManager() if len(adb.get_devices()) == 0: print(u"该功能需要连接手机或者模拟器,请确保手机或者模拟器已经启动") return 0, None ret, model = adb.shell('getprop ro.product.model') ret, name = adb.shell('getprop ro.product.name') ret, release = adb.shell('getprop ro.build.version.release') ret, sdk = adb.shell('getprop ro.build.version.sdk') ret, cpu = adb.shell('getprop ro.product.cpu.abi') ret, cpu2 = adb.shell('getprop ro.product.cpu.abi2') ret, serialno = adb.shell('getprop ro.serialno') ret, imei = adb.shell('getprop gsm.sim.imei') ret, androidid = adb.shell('getprop net.hostname') ret, description = adb.shell('getprop ro.build.description') ret, mac = adb.shell('cat /sys/class/net/wlan0/address') ret, size = adb.shell('wm size') if ret == 0: size = star.find('size: (.*?)\s', size) infoFile = os.path.splitext(f)[0] + '_phone.txt' star.log('手机类型:' + model, infoFile) star.loga('手机名称:' + name, infoFile) star.loga('系统版本:' + release, infoFile) star.loga('API版本:' + sdk, infoFile) star.loga('CPU:' + cpu, infoFile) star.loga('CPU2:' + cpu2, infoFile) star.loga('MAC:' + mac, infoFile) star.loga('序列号:' + serialno, infoFile) star.loga('IMEI:' + imei, infoFile) star.loga('AndroidId:' + androidid, infoFile) star.loga('描述信息:' + description, infoFile) if size is not None: # 获取分辨率如果失败size将会是None对象,此时不能使用+连接 star.loga('分辨率:' + size, infoFile) if os.path.exists(infoFile): star.run_cmd_asyn(['notepad', infoFile]) return 1, None
def on_command(params): ret = 0 # 默认返回成功 msg = None paramCount = len(params) isMultiFiles = False if params is None or paramCount < 3: print(params[0]) print(params[1]) return -1, u'参数不对,需要传至少 3 个参数' CMD_STR = params[1] filesSelected = params[2] if paramCount > 3: isMultiFiles = True if sys.platform == 'win32': pass # win下命令行参数为gbk编码,转换为UNICODE # filesSelected = filesSelected.decode('gbk', 'ignore') print(str(paramCount) + ' ' + CMD_STR + ' ' + filesSelected) if CMD_STR == 'dex2jar': ret, msg = dex2jar(filesSelected) elif CMD_STR == 'axml2txt': ret, msg = axml2txt(filesSelected) elif CMD_STR == 'viewapk': ret, msg = viewapk(filesSelected) elif CMD_STR == 'viewsign': ret, msg = viewsign(filesSelected) elif CMD_STR == 'sign': ret, msg = sign(filesSelected) elif CMD_STR == 'sign_v1_v2': ret, msg = sign_v1_v2(filesSelected) elif CMD_STR == 'installd': ret, msg = installd(filesSelected) elif CMD_STR == 'installr': ret, msg = installr(filesSelected) elif CMD_STR == 'uninstall': ret, msg = uninstall(filesSelected) elif CMD_STR == 'viewwrapper': ret, msg = viewwrapper(filesSelected) elif CMD_STR == 'phone': ret, msg = viewphone(filesSelected) if ret == 0: os.system('pause') elif CMD_STR == 'photo': ret, msg = photo(filesSelected) elif CMD_STR == 'icon': ret, msg = extracticon(filesSelected) os.system('pause') elif CMD_STR == 'zipalign': ret, msg = zipalign(filesSelected) os.system('pause') elif CMD_STR == 'baksmali': ret, msg = baksmali(filesSelected) elif CMD_STR == 'smali': ret, msg = smali(filesSelected) elif CMD_STR == 'plug_get_neprotect_ver': ret, msg = plug_get_neprotect_ver(filesSelected) os.system('pause') elif CMD_STR == 'md2html': ret, msg = md2html(filesSelected) elif CMD_STR == 'md2pdf': ret, msg = md2pdf(filesSelected) elif CMD_STR == 'plug3': ret, msg = plug(filesSelected) elif CMD_STR == 'about': print(u'\n\n右键工具v3.0 by bising(https://github.com/bigsinger)\n\n') os.system('pause') # star.runcmd2([PathManager.get_about_path()]) elif CMD_STR == 'notepad': ret, msg = star.run_cmd_asyn(['notepad', filesSelected]) elif CMD_STR == 'hex': print('open with hex tool') tool = PathManager.get_hextool_path() ret, msg = star.run_cmd_asyn([tool, filesSelected]) elif CMD_STR == 'lua': print('open with Lua Editor') tool = PathManager.get_luaeditor_path() ret, msg = star.run_cmd_asyn([tool, filesSelected]) elif CMD_STR == 'luyten': print('open with luyten') tool = PathManager.get_luyten_path() ret, msg = star.run_cmd_asyn([tool, filesSelected]) if ret != 0: # 说明此时执行命令出错,暂停下让用户能够看到cmd窗口的出错信息 os.system('pause') elif CMD_STR == 'jdgui': print('open with jdgui') tool = PathManager.get_jdgui_path() ret, msg = star.run_cmd_asyn([tool, filesSelected]) elif CMD_STR == 'md5': ret, msg = md5(filesSelected) os.system('pause') else: return -1, u'\n\n未实现命令:' + CMD_STR + u'请检查您输入的命令是否正确\n\n' return ret, msg