Verified Commit 32826c83 authored by Hans-Christoph Steiner's avatar Hans-Christoph Steiner
Browse files

mark apps/builds with ga_trackingId set with Tracking Anti-Feature

Google Firebase Analytics is configured using an XML file, and it seems to
require that an value with the key `ga_trackingId` is included:

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:
import os
import sys
import zipfile
from androguard.core.bytecodes.axml import AXMLPrinter
    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:]
    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)
                with zipfile.ZipFile(path) as apk:
                    for info in apk.infolist():
                        if info.file_size < 10:
                        name = info.filename
                        if name.startswith('res/') and name.endswith('.xml'):
                            with as binary_xml:
                                axml = AXMLPrinter(
                                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)

Then applied using this script:

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] = []

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)

parent 30260b35
Pipeline #288917104 passed with stages
in 38 minutes and 41 seconds