实现代码如下:

# 找出packagename和activity
import os
import re
class packagename_activity:
    def get_packagename(self, path):
        aapt = []
        os.system(f'aapt dump badging {path}> ../xc_logs/AaptLog.txt')
        with open('../xc_logs/AaptLog.txt', 'rb') as f:
            p1 = "package: name='(.+?)'"
            results1 = re.finditer(pattern=p1, string=f.readline().decode('utf-8'))
            for r in results1:
                packagename = r.group(1)
                aapt.append(packagename)
            p2 = "launchable-activity: name='(.+?)'"
            st = str(f.readlines())
            results2 = re.findall(p2, st)
            activity = results2[0]
            aapt.append(activity)
        return aapt
if __name__ == '__main__':
    a=packagename_activity()
    b=a.get_packagename('../xc_apk/wangyiyunyinyue.apk')
    print(b)
posted on 2020-01-07 20:04  badbadboy  阅读(460)  评论(0编辑  收藏  举报