GitLab's annual major release is around the corner. Along with a lot of new and exciting features, there will be a few breaking changes. Learn more here.

  • Hans-Christoph Steiner's avatar
    mark apps/builds with ga_trackingId set with Tracking Anti-Feature · 32826c83
    Hans-Christoph Steiner authored
    Google Firebase Analytics is configured using an XML file, and it seems to
    require that an value with the key `ga_trackingId` is included:
    https://developers.google.com/android/reference/com/google/android/gms/analytics/Tracker
    
    That means that any app that is setting `ga_trackingId` is most likely
    configuring Google Firebase Analytics.  If not, then that file/key should
    be removed entirely. It can easily be moved to a flavor also.
    
    This was detected by running this script across the whole archive:
    https://gitlab.com/trackingthetrackers/scripts/-/blob/master/find-ga_trackingId.py
    ```python
    import os
    import sys
    import zipfile
    from androguard.core.bytecodes.axml import AXMLPrinter
    try:
        import defusedxml.ElementTree as XMLElementTree
    except ImportError:
        import xml.etree.ElementTree as XMLElementTree  # nosec this is a fallback only
    
    if len(sys.argv) > 1:
        search_dirs = sys.argv[1:]
    else:
        search_dirs = ['.']
    print('search_dirs', search_dirs)
    
    for d in search_dirs:
        for root, dirs, files in os.walk(d):
            for f in files:
                path = os.path.join(root, f)
                try:
                    with zipfile.ZipFile(path) as apk:
                        for info in apk.infolist():
                            if info.file_size < 10:
                                continue
                            name = info.filename
                            if name.startswith('res/') and name.endswith('.xml'):
                                with apk.open(name) as binary_xml:
                                    axml = AXMLPrinter(binary_xml.read())
                                    resources = XMLElementTree.fromstring(axml.get_xml())
                                    for item in resources:
                                        if 'ga_trackingId' == (item.get('name')):
                                            print(path, name, item.get('name'))
                except (zipfile.BadZipFile, AssertionError, TypeError, ValueError) as e:
                    #print(path, e)
                    pass
    ```
    
    Then applied using this script:
    
    ```python
    import os
    import yaml
    from fdroidserver import metadata
    
    apps = dict()
    with open('ga_trackingId-finds.txt') as fp:
        for line in fp:
            apk, xml, _ = line.split()
            apk = apk.split('/')[1]
            appid = apk[:apk.rindex('_')]
            versionCode = int(apk[:-4][apk.rindex('_') + 1:])
            if appid not in apps:
                apps[appid] = []
            apps[appid].append(versionCode)
    
    for appid, versionCodes in apps.items():
        metadatapath = 'metadata/%s.yml' % appid
        with open(metadatapath) as fp:
            app = yaml.load(fp)
        print(appid, app.get('Repo', '///').split('/')[3], sep='\t')
        for build in app['Builds']:
            if build.get('gradle') is True or build.get('gradle') == 'true':
                build['gradle'] = ['yes']
            if build['versionCode'] in versionCodes:
                build['antifeatures'] = ['Tracking']
        metadata.write_metadata(metadatapath, metadata.App(app))
        os.system("sed -i 's,^      - true,      - yes,' " + metadatapath)
    ```
    
    !7898
    32826c83
com.rehanced.lunary.yml 3.93 KB