chiark / gitweb /
Merge branch 'master' into 'master'
authorHans-Christoph Steiner <hans@guardianproject.info>
Thu, 26 Apr 2018 14:36:07 +0000 (14:36 +0000)
committerHans-Christoph Steiner <hans@guardianproject.info>
Thu, 26 Apr 2018 14:36:07 +0000 (14:36 +0000)
fix bad parsing of maxSdkVersion as a @string resource

See merge request fdroid/fdroidserver!494

.gitignore
fdroidserver/update.py
tests/metadata/souch.smsbypass.txt [new file with mode: 0644]
tests/repo/index-v1.json
tests/repo/index.xml
tests/repo/souch.smsbypass_9.apk [new file with mode: 0644]
tests/stats/known_apks.txt
tests/update.TestCase

index b92ef773a22ee062032c6d7e0d779aa9441379b3..be36e3745195869663793741a3b0f77dcb27dfe6 100644 (file)
@@ -36,9 +36,12 @@ makebuildserver.config.py
 /tests/archive/categories.txt
 /tests/archive/icons*
 /tests/archive/index.jar
+/tests/archive/index_unsigned.jar
 /tests/archive/index.xml
 /tests/archive/index-v1.jar
+/tests/archive/index-v1.json
 /tests/repo/index.jar
+/tests/repo/index_unsigned.jar
 /tests/repo/index-v1.jar
 /tests/repo/info.guardianproject.urzip/
 /tests/repo/info.guardianproject.checkey/en-US/phoneScreenshots/checkey-phone.png
index 830a2252653dfb5cb7c7743d4d70351327d9f8f7..ebd29a2c508ce8e0a2ba1c7ac78ef630dd8d9ce9 100644 (file)
@@ -1181,6 +1181,46 @@ def scan_apk_aapt(apk, apkfile):
     apk['icons_src'] = _get_apk_icons_src(apkfile, icon_name)
 
 
+def _ensure_final_value(packageName, arsc, value):
+    """Ensure incoming value is always the value, not the resid
+
+    androguard will sometimes return the Android "resId" aka
+    Resource ID instead of the actual value.  This checks whether
+    the value is actually a resId, then performs the Android
+    Resource lookup as needed.
+
+    """
+    if value:
+        returnValue = value
+        if value[0] == '@':
+            try:  # can be a literal value or a resId
+                res_id = int(value.replace("@", "0x"), 16)
+                res_id = arsc.get_id(packageName, res_id)[1]
+                returnValue = arsc.get_string(packageName, res_id)[1]
+            except ValueError:
+                pass
+        return returnValue
+
+
+def _sanitize_sdk_version(value):
+    """Sanitize the raw values from androguard to handle bad values
+
+    minSdkVersion/targetSdkVersion/maxSdkVersion must be integers,
+    but that doesn't stop devs from doing strange things like
+    setting them using Android XML strings.
+
+    https://gitlab.com/souch/SMSbypass/blob/v0.9/app/src/main/AndroidManifest.xml#L29
+    https://gitlab.com/souch/SMSbypass/blob/v0.9/app/src/main/res/values/strings.xml#L27
+    """
+    try:
+        sdk_version = int(value)
+        if sdk_version > 0:
+            return str(sdk_version)  # heinous, but this is still str in the codebase
+    except (TypeError, ValueError):
+        pass
+    return None
+
+
 def scan_apk_androguard(apk, apkfile):
     try:
         from androguard.core.bytecodes.apk import APK
@@ -1210,23 +1250,20 @@ def scan_apk_androguard(apk, apkfile):
     apk['versionCode'] = int(apkobject.get_androidversion_code())
     apk['name'] = apkobject.get_app_name()
 
-    versionName = apkobject.get_androidversion_name()
-    if versionName:
-        apk['versionName'] = versionName
-        if versionName[0] == '@':
-            try:  # can be a literal value or a resId
-                res_id = int(versionName.replace("@", "0x"), 16)
-                res_id = arsc.get_id(apk['packageName'], res_id)[1]
-                apk['versionName'] = arsc.get_string(apk['packageName'], res_id)[1]
-            except ValueError:
-                pass
+    apk['versionName'] = _ensure_final_value(apk['packageName'], arsc,
+                                             apkobject.get_androidversion_name())
+
+    minSdkVersion = _sanitize_sdk_version(apkobject.get_min_sdk_version())
+    if minSdkVersion is not None:
+        apk['minSdkVersion'] = minSdkVersion
+
+    targetSdkVersion = _sanitize_sdk_version(apkobject.get_target_sdk_version())
+    if targetSdkVersion is not None:
+        apk['targetSdkVersion'] = targetSdkVersion
 
-    if apkobject.get_max_sdk_version() is not None:
-        apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
-    if apkobject.get_min_sdk_version() is not None:
-        apk['minSdkVersion'] = apkobject.get_min_sdk_version()
-    if apkobject.get_target_sdk_version() is not None:
-        apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
+    maxSdkVersion = _sanitize_sdk_version(apkobject.get_max_sdk_version())
+    if maxSdkVersion is not None:
+        apk['maxSdkVersion'] = maxSdkVersion
 
     icon_id_str = apkobject.get_element("application", "icon")
     if icon_id_str:
diff --git a/tests/metadata/souch.smsbypass.txt b/tests/metadata/souch.smsbypass.txt
new file mode 100644 (file)
index 0000000..6b16e05
--- /dev/null
@@ -0,0 +1,52 @@
+Categories:Phone & SMS
+License:GPL-3.0
+Web Site:https://gitlab.com/souch/SMSbypass
+Source Code:https://gitlab.com/souch/SMSbypass/tree/HEAD
+Issue Tracker:https://gitlab.com/souch/SMSbypass/issues
+Donate:http://rodolphe.souchaud.free.fr/donate
+FlattrID:cad90e036b975ed129a3ce80a0750466
+
+Auto Name:Battery level
+Summary:Filter SMS and show them in a fake app
+Description:
+In order to keep away curious eyes, SMS-bypass filters incoming SMS messages
+before they reach your inbox. Based on bughunter2.smsfilter.
+
+Features:
+
+* Discrete fake app "Battery level": Long tap on Battery percentage will show SMS.
+* Filter incoming SMS specified address: redirect the SMS to SMS-bypass messages list; remove SMS arrival sound or vibration; show a discreet notification icon (battery level); vibrate if checked in settings
+* Add contact from contact list
+* Export messages to a text file
+.
+
+Repo Type:git
+Repo:https://gitlab.com/souch/SMSbypass.git
+
+Build:0.8,5
+    commit=v0.8
+    subdir=app
+    gradle=yes
+    prebuild=sed -i -e '/minSdkVersion/amaxSdkVersion 19\n' build.gradle
+
+Build:0.8b,6
+    disable=don't build, just use as template for AUM, correct VC is 8
+    commit=2bd6164ff6391906af2af2b484de69a4ff926a01
+    subdir=app
+    gradle=yes
+
+Build:0.8.1,8
+    disable=mistagged
+    commit=v0.8.1
+    subdir=app
+    gradle=yes
+
+Build:0.9,9
+    commit=v0.9
+    subdir=app
+    gradle=yes
+
+Auto Update Mode:Version v%v
+Update Check Mode:Tags
+Current Version:0.9
+Current Version Code:9
index cda10cf2377ce265718c12b1ed472d7fbc3e4e3a..912f610c6a674ed7e4c63aaaca7dcdbeaa94c823 100644 (file)
     ]
   },
   "apps": [
+    {
+      "categories": [
+        "Phone & SMS"
+      ],
+      "suggestedVersionName": "0.9",
+      "suggestedVersionCode": "9",
+      "description": "<p>In order to keep away curious eyes, SMS-bypass filters incoming SMS messages before they reach your inbox. Based on bughunter2.smsfilter.</p><p>Features:</p><ul><li> Discrete fake app \"Battery level\": Long tap on Battery percentage will show SMS.</li><li> Filter incoming SMS specified address: redirect the SMS to SMS-bypass messages list; remove SMS arrival sound or vibration; show a discreet notification icon (battery level); vibrate if checked in settings</li><li> Add contact from contact list</li><li> Export messages to a text file</li></ul>",
+      "donate": "http://rodolphe.souchaud.free.fr/donate",
+      "flattrID": "cad90e036b975ed129a3ce80a0750466",
+      "issueTracker": "https://gitlab.com/souch/SMSbypass/issues",
+      "license": "GPL-3.0",
+      "name": "Battery level",
+      "sourceCode": "https://gitlab.com/souch/SMSbypass/tree/HEAD",
+      "summary": "Filter SMS and show them in a fake app",
+      "webSite": "https://gitlab.com/souch/SMSbypass",
+      "added": 1524700800000,
+      "icon": "souch.smsbypass.9.png",
+      "packageName": "souch.smsbypass",
+      "lastUpdated": 1524700800000
+    },
     {
       "categories": [
         "tests"
         "versionCode": 1619,
         "versionName": "0.1"
       }
+    ],
+    "souch.smsbypass": [
+      {
+        "added": 1524700800000,
+        "apkName": "souch.smsbypass_9.apk",
+        "hash": "80b0ae68a1189baa3ee6717092e3dbf1a4210165f7f7e5f2f9616bd63a2ec01d",
+        "hashType": "sha256",
+        "minSdkVersion": "8",
+        "packageName": "souch.smsbypass",
+        "sig": "e50c99753cd45e2736d52cb49be07581",
+        "signer": "d3aec784b1fd71549fc22c999789122e3639895db6bd585da5835fbe3db6985c",
+        "size": 81295,
+        "targetSdkVersion": "18",
+        "uses-permission": [
+          [
+            "android.permission.RECEIVE_SMS",
+            null
+          ],
+          [
+            "android.permission.SEND_SMS",
+            null
+          ],
+          [
+            "android.permission.READ_CONTACTS",
+            null
+          ],
+          [
+            "android.permission.WRITE_EXTERNAL_STORAGE",
+            null
+          ],
+          [
+            "android.permission.VIBRATE",
+            null
+          ],
+          [
+            "android.permission.READ_EXTERNAL_STORAGE",
+            null
+          ]
+        ],
+        "versionCode": 9,
+        "versionName": "0.9"
+      }
     ]
   }
-}
+}
\ No newline at end of file
index ef6988deaa9797a7e300ada566aba60817885f41..9b6ef50a170e0de1c6f9c07d189ab59881423c83 100644 (file)
@@ -8,6 +8,37 @@
        <install packageName="org.adaway"/>
        <uninstall packageName="com.android.vending"/>
        <uninstall packageName="com.facebook.orca"/>
+       <application id="souch.smsbypass">
+               <id>souch.smsbypass</id>
+               <added>2018-04-26</added>
+               <lastupdated>2018-04-26</lastupdated>
+               <name>Battery level</name>
+               <summary>Filter SMS and show them in a fake app</summary>
+               <icon>souch.smsbypass.9.png</icon>
+               <desc>&lt;p&gt;In order to keep away curious eyes, SMS-bypass filters incoming SMS messages before they reach your inbox. Based on bughunter2.smsfilter.&lt;/p&gt;&lt;p&gt;Features:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Discrete fake app &quot;Battery level&quot;: Long tap on Battery percentage will show SMS.&lt;/li&gt;&lt;li&gt; Filter incoming SMS specified address: redirect the SMS to SMS-bypass messages list; remove SMS arrival sound or vibration; show a discreet notification icon (battery level); vibrate if checked in settings&lt;/li&gt;&lt;li&gt; Add contact from contact list&lt;/li&gt;&lt;li&gt; Export messages to a text file&lt;/li&gt;&lt;/ul&gt;</desc>
+               <license>GPL-3.0</license>
+               <categories>Phone &amp; SMS</categories>
+               <category>Phone &amp; SMS</category>
+               <web>https://gitlab.com/souch/SMSbypass</web>
+               <source>https://gitlab.com/souch/SMSbypass/tree/HEAD</source>
+               <tracker>https://gitlab.com/souch/SMSbypass/issues</tracker>
+               <donate>http://rodolphe.souchaud.free.fr/donate</donate>
+               <flattr>cad90e036b975ed129a3ce80a0750466</flattr>
+               <marketversion>0.9</marketversion>
+               <marketvercode>9</marketvercode>
+               <package>
+                       <version>0.9</version>
+                       <versioncode>9</versioncode>
+                       <apkname>souch.smsbypass_9.apk</apkname>
+                       <hash type="sha256">80b0ae68a1189baa3ee6717092e3dbf1a4210165f7f7e5f2f9616bd63a2ec01d</hash>
+                       <size>81295</size>
+                       <sdkver>8</sdkver>
+                       <targetSdkVersion>18</targetSdkVersion>
+                       <added>2018-04-26</added>
+                       <sig>e50c99753cd45e2736d52cb49be07581</sig>
+                       <permissions>READ_CONTACTS,READ_EXTERNAL_STORAGE,RECEIVE_SMS,SEND_SMS,VIBRATE,WRITE_EXTERNAL_STORAGE</permissions>
+               </package>
+       </application>
        <application id="duplicate.permisssions">
                <id>duplicate.permisssions</id>
                <added>2017-12-22</added>
diff --git a/tests/repo/souch.smsbypass_9.apk b/tests/repo/souch.smsbypass_9.apk
new file mode 100644 (file)
index 0000000..ce96f29
Binary files /dev/null and b/tests/repo/souch.smsbypass_9.apk differ
index ef90c79742b3080a095ff6e3633dfe76d334f25e..392c68ffb079136ee613ac5b57844abea2dde7de 100644 (file)
@@ -10,4 +10,5 @@ obb.main.twoversions_1101615.apk obb.main.twoversions 2016-01-01
 obb.main.twoversions_1101617.apk obb.main.twoversions 2016-06-20
 obb.mainpatch.current_1619.apk obb.mainpatch.current 2016-04-23
 obb.mainpatch.current_1619_another-release-key.apk obb.mainpatch.current 2017-06-01
+souch.smsbypass_9.apk souch.smsbypass 2018-04-26
 urzip-; Рахма́нинов, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢尔盖·.apk info.guardianproject.urzip 2016-06-23
index eb59c3d0848d25994f18e48b2306789a510c567b..f4e02e47a15b8461524583d3212f06760ff34217 100755 (executable)
@@ -253,7 +253,7 @@ class UpdateTest(unittest.TestCase):
         apps = fdroidserver.metadata.read_metadata(xref=True)
         knownapks = fdroidserver.common.KnownApks()
         apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
-        self.assertEqual(len(apks), 13)
+        self.assertEqual(len(apks), 14)
         apk = apks[0]
         self.assertEqual(apk['packageName'], 'com.politedroid')
         self.assertEqual(apk['versionCode'], 3)
@@ -298,7 +298,12 @@ class UpdateTest(unittest.TestCase):
         if os.path.basename(os.getcwd()) != 'tests':
             raise Exception('This test must be run in the "tests/" subdir')
 
+        apk_info = fdroidserver.update.scan_apk('repo/souch.smsbypass_9.apk')
+        self.assertIsNone(apk_info.get('maxSdkVersion'))
+        self.assertEqual(apk_info.get('versionName'), '0.9')
+
         apk_info = fdroidserver.update.scan_apk('repo/duplicate.permisssions_9999999.apk')
+        self.assertIsNone(apk_info.get('versionName'))
         self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_launcher.png',
                                                  '-1': 'res/drawable/ic_launcher.png'})
 
@@ -324,14 +329,17 @@ class UpdateTest(unittest.TestCase):
         self.assertEqual(apk_info['targetSdkVersion'], '8')
 
         apk_info = fdroidserver.update.scan_apk('org.bitbucket.tickytacky.mirrormirror_4.apk')
+        self.assertEqual(apk_info.get('versionName'), '1.0.3')
         self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable-mdpi/mirror.png',
                                                  '-1': 'res/drawable-mdpi/mirror.png'})
 
         apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk')
+        self.assertEqual(apk_info.get('versionName'), '1.3')
         self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_coffee_on.xml',
                                                  '-1': 'res/drawable/ic_coffee_on.xml'})
 
         apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk')
+        self.assertEqual(apk_info.get('versionName'), '1.5')
         self.assertEqual(apk_info['icons_src'], {'120': 'res/drawable-ldpi-v4/icon.png',
                                                  '160': 'res/drawable-mdpi-v4/icon.png',
                                                  '240': 'res/drawable-hdpi-v4/icon.png',
@@ -339,6 +347,7 @@ class UpdateTest(unittest.TestCase):
                                                  '-1': 'res/drawable-mdpi-v4/icon.png'})
 
         apk_info = fdroidserver.update.scan_apk('SpeedoMeterApp.main_1.apk')
+        self.assertEqual(apk_info.get('versionName'), '1.0')
         self.assertEqual(apk_info['icons_src'], {})
 
     def test_scan_apk_no_sig(self):
@@ -549,7 +558,7 @@ class UpdateTest(unittest.TestCase):
         knownapks = fdroidserver.common.KnownApks()
         apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
         fdroidserver.update.translate_per_build_anti_features(apps, apks)
-        self.assertEqual(len(apks), 13)
+        self.assertEqual(len(apks), 14)
         foundtest = False
         for apk in apks:
             if apk['packageName'] == 'com.politedroid' and apk['versionCode'] == 3: