test_apk.c (5851B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_apk.c 22 * @brief testcase for the apk plugin 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include "test_lib.h" 27 28 29 /** 30 * Shorthand for a UTF-8 text item. 31 */ 32 #define TXT(type, s) { type, EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ 33 s, strlen (s) + 1, 0 } 34 35 36 /** 37 * Main function for the apk testcase. 38 * 39 * @param argc number of arguments (ignored) 40 * @param argv arguments (ignored) 41 * @return 0 on success 42 */ 43 int 44 main (int argc, char *argv[]) 45 { 46 struct SolutionData apk_sol[] = { 47 TXT (EXTRACTOR_METATYPE_MIMETYPE, 48 "application/vnd.android.package-archive"), 49 /* everything down to the target architectures comes out of the 50 binary AndroidManifest.xml */ 51 TXT (EXTRACTOR_METATYPE_PACKAGE_NAME, "org.gnu.libextractor.apktest"), 52 TXT (EXTRACTOR_METATYPE_PACKAGE_VERSION, "1719"), 53 TXT (EXTRACTOR_METATYPE_SOFTWARE_VERSION, "1.19.0"), 54 /* android:compileSdkVersion="33" */ 55 TXT (EXTRACTOR_METATYPE_TOOLCHAIN, "Android API 33 (Android 13)"), 56 TXT (EXTRACTOR_METATYPE_MINIMUM_OS_VERSION, 57 "Android API 21 (Android 5.0)"), 58 TXT (EXTRACTOR_METATYPE_TARGET_OS, "Android API 33 (Android 13)"), 59 TXT (EXTRACTOR_METATYPE_PERMISSION, "android.permission.INTERNET"), 60 TXT (EXTRACTOR_METATYPE_PERMISSION, 61 "android.permission.ACCESS_FINE_LOCATION"), 62 TXT (EXTRACTOR_METATYPE_PERMISSION, "android.permission.READ_SMS"), 63 TXT (EXTRACTOR_METATYPE_PERMISSION, "android.permission.CAMERA"), 64 TXT (EXTRACTOR_METATYPE_PERMISSION, 65 "android.permission.RECEIVE_BOOT_COMPLETED"), 66 /* android:label is a literal string here; android:icon is a 67 resource reference and must not be reported */ 68 TXT (EXTRACTOR_METATYPE_TITLE, "libextractor APK test"), 69 TXT (EXTRACTOR_METATYPE_ATTRIBUTES, "debuggable"), 70 TXT (EXTRACTOR_METATYPE_ATTRIBUTES, "allowBackup: false"), 71 TXT (EXTRACTOR_METATYPE_ATTRIBUTES, "usesCleartextTraffic: true"), 72 TXT (EXTRACTOR_METATYPE_ATTRIBUTES, "networkSecurityConfig: present"), 73 /* read off the member names in the central directory */ 74 TXT (EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, "arm64-v8a"), 75 TXT (EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, "armeabi-v7a"), 76 TXT (EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, "x86_64"), 77 TXT (EXTRACTOR_METATYPE_COMMENT, "3 dex files"), 78 TXT (EXTRACTOR_METATYPE_ENTRY_COUNT, "12"), 79 TXT (EXTRACTOR_METATYPE_SIGNER, "JAR signing (v1), alias ANDROIDD"), 80 /* the certificate authority comes first in the PKCS#7 block, so 81 this also proves the SignerInfo is resolved rather than the first 82 certificate taken */ 83 TXT (EXTRACTOR_METATYPE_SIGNER, 84 "CN=libextractor test signer, O=GNU libextractor," 85 " OU=Testing, C=CH"), 86 /* from the APK Signing Block spliced in before the central 87 directory */ 88 TXT (EXTRACTOR_METATYPE_SIGNER, "APK Signature Scheme v2"), 89 TXT (EXTRACTOR_METATYPE_SIGNER, "APK Signature Scheme v3"), 90 { 0, 0, NULL, NULL, 0, -1 } 91 }; 92 struct SolutionData jar_sol[] = { 93 TXT (EXTRACTOR_METATYPE_MIMETYPE, "application/java-archive"), 94 TXT (EXTRACTOR_METATYPE_TOOLCHAIN, "17.0.9+9 (Eclipse Adoptium)"), 95 TXT (EXTRACTOR_METATYPE_TOOLCHAIN, "17"), 96 TXT (EXTRACTOR_METATYPE_TOOLCHAIN, "17.0.9+9"), 97 TXT (EXTRACTOR_METATYPE_ENTRY_POINT, "org.gnu.libextractor.TestMain"), 98 TXT (EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY, 99 "lib/support.jar lib/codec.jar"), 100 /* this header is 98 bytes long in the manifest and therefore 101 folded across two lines; getting it back in one piece proves the 102 continuation lines are unfolded */ 103 TXT (EXTRACTOR_METATYPE_TITLE, 104 "GNU libextractor JAR test archive with a very long title" 105 " that has to be folded"), 106 TXT (EXTRACTOR_METATYPE_SOFTWARE_VERSION, "1.19.0"), 107 TXT (EXTRACTOR_METATYPE_VENDOR, "GNU libextractor project"), 108 TXT (EXTRACTOR_METATYPE_SUBJECT, 109 "libextractor plugin test specification"), 110 TXT (EXTRACTOR_METATYPE_FORMAT_VERSION, "1.19"), 111 TXT (EXTRACTOR_METATYPE_ORGANIZATION, "GNU"), 112 TXT (EXTRACTOR_METATYPE_APPLICATION_ID, "org.gnu.libextractor.test"), 113 TXT (EXTRACTOR_METATYPE_PRODUCT_NAME, "libextractor test bundle"), 114 TXT (EXTRACTOR_METATYPE_PACKAGE_VERSION, "1.19.0.qualifier"), 115 TXT (EXTRACTOR_METATYPE_VENDOR, "GNU libextractor project"), 116 TXT (EXTRACTOR_METATYPE_DESCRIPTION, 117 "test bundle produced by gen_apk_testdata.sh"), 118 TXT (EXTRACTOR_METATYPE_MINIMUM_OS_VERSION, "JavaSE-17"), 119 TXT (EXTRACTOR_METATYPE_ENTRY_COUNT, "4"), 120 TXT (EXTRACTOR_METATYPE_SIGNER, "JAR signing (v1), alias CERT"), 121 TXT (EXTRACTOR_METATYPE_SIGNER, 122 "CN=libextractor test signer, O=GNU libextractor," 123 " OU=Testing, C=CH"), 124 { 0, 0, NULL, NULL, 0, -1 } 125 }; 126 struct ProblemSet ps[] = { 127 { "testdata/apk_test.apk", apk_sol }, 128 { "testdata/apk_test.jar", jar_sol }, 129 { NULL, NULL } 130 }; 131 132 return ET_main ("apk", ps); 133 } 134 135 136 /* end of test_apk.c */