এমনকি ইনপুটস্ট্রিম ব্যবহার করেও কীভাবে এপিএল ফাইলের একটি নির্ভরযোগ্য ও বৈধ মেনিফেস্ট সামগ্রী পাবেন?


9

পটভূমি

আমি APK ফাইলগুলি (বিভক্ত এপিএল ফাইলগুলি সহ) সম্পর্কিত তথ্য পেতে চেয়েছিলাম, এমনকি যদি তারা সংকুচিত জিপ ফাইলের মধ্যে থাকে (সেগুলি ডি-সংক্ষেপণ না করে)। আমার ক্ষেত্রে এটিতে প্যাকেজের নাম, সংস্করণ-কোড, সংস্করণ-নাম, অ্যাপ্লিকেশন-লেবেল, অ্যাপ্লিকেশন-আইকন, এবং এটি বিভক্ত যদি APK ফাইল হয় বা না হয় তার মতো বিভিন্ন বিষয় অন্তর্ভুক্ত রয়েছে।

মনে রাখবেন যে আমি এটি একটি অ্যান্ড্রয়েড অ্যাপের ভিতরেই করতে চাইছি, পিসি ব্যবহার না করে, তাই কিছু সরঞ্জাম ব্যবহার করা সম্ভব নাও হতে পারে।

সমস্যাটি

এর অর্থ আমি getPackageArchiveInfo ফাংশনটি ব্যবহার করতে পারি না , কারণ এই ফাংশনটির জন্য APK ফাইলের জন্য একটি পথ প্রয়োজন এবং এটি কেবল বিভক্ত-এপিপি ফাইলগুলিতে কাজ করে।

সংক্ষেপে, এটি করার জন্য কোনও ফ্রেমওয়ার্কের ফাংশন নেই, তাই ইনপুটস্ট্রিমটিকে কোনও ফাংশনে পার্স করার জন্য ইনপুট স্ট্রিমটি ব্যবহার করে জিনপ ফাইলটিতে গিয়ে কীভাবে এটি করা যায় তার একটি উপায় আমাকে খুঁজে বের করতে হবে।

অ্যান্ড্রয়েডের বাইরের সহ অনলাইনে বিভিন্ন সমাধান রয়েছে, তবে আমি স্থিতিশীল এবং এটি সব ক্ষেত্রেই কাজ করে এমন একটি সম্পর্কে আমার জানা নেই। অনেকগুলি অ্যান্ড্রয়েডের জন্য এমনকি উদাহরণস্বরূপ ( এখানে উদাহরণস্বরূপ ) ভাল হতে পারে তবে পার্সিংয়ে ব্যর্থ হতে পারে এবং উরি / ইনপুট স্ট্রিমের পরিবর্তে ফাইলের প্রয়োজন হতে পারে।

আমি যা খুঁজে পেয়েছি এবং চেষ্টা করেছি

আমি পেয়েছি এই Stackoverflow, কিন্তু দুঃখিতভাবে আমার পরীক্ষা অনুযায়ী, এটা সবসময় বিষয়বস্তু উত্পন্ন, কিন্তু কিছু বিরল ক্ষেত্রে এটি একটি বৈধ XML বিষয়বস্তু নয়।

এখনও অবধি, আমি এই অ্যাপ্লিকেশনগুলির প্যাকেজের নাম এবং তাদের সংস্করণ কোডগুলি খুঁজে পেয়েছি যা পার্সার পার্স করতে ব্যর্থ হয়েছে, আউটপুট এক্সএমএল সামগ্রীটি অবৈধ:

  1. com.farproc.wifi.analyzer 139
  2. com.teslacoilsw.launcherclientproxy 2
  3. com.hotornot.app 3072
  4. অ্যান্ড্রয়েড 29 (এটি "অ্যান্ড্রয়েড সিস্টেম" সিস্টেম অ্যাপ্লিকেশন নিজেই)
  5. com.google.android.videos 41300042
  6. com.facebook.katana 201518851
  7. com.keramidas.TitaniumBackupPro 10
  8. com.google.android.apps.tachyon 2985033
  9. com.google.android.apps.photos 3594753

একটি এক্সএমএল ভিউয়ার এবং এক্সএমএল যাচাইকারী ব্যবহার করে , এই অ্যাপ্লিকেশনগুলির সাথে সমস্যাগুলি এখানে রয়েছে:

  • # 1, # 2 জন্য, আমি একটি খুব অদ্ভুত বিষয়বস্তু পেয়েছি, দিয়ে শুরু <mnfs
  • # 3 এর জন্য এটি "&" এর পছন্দ করে না <activity theme="resourceID 0x7f13000b" label="Features & Tests" ...
  • # 4 এর জন্য, এটি শেষে "ম্যানিফেস্ট" এর শেষ ট্যাগটি মিস করেছে।
  • # 5 এর জন্য, এটি কমপক্ষে "অভিপ্রায়-ফিল্টার", "রিসিভার" এবং "ম্যানিফেস্ট" একাধিক প্রান্তের ট্যাগগুলি হারিয়েছে। হয়তো আরো.
  • # 6 এর জন্য, এটি কোনও কারণে "অ্যাপ্লিকেশন" ট্যাগে দুবার "অনুমতিব্যাকআপ" বৈশিষ্ট্যটি পেয়েছে।
  • # 7, এটি স্পষ্ট ট্যাগে অ্যাট্রিবিউট ছাড়া একটি মান করেছেন: <manifest versionCode="resourceID 0xa" ="1.3.2"
  • # 8-র জন্য, কিছু "ইউজ-ফিচার" ট্যাগ পাওয়ার পরে এটি প্রচুর সামগ্রী মিস করেছে এবং "ম্যানিফেস্ট" এর জন্য একটি শেষ ট্যাগ নেই।
  • # 9 এর জন্য, কিছু "ব্যবহারের অনুমতি" ট্যাগ পাওয়ার পরে এটি প্রচুর সামগ্রী মিস করেছে এবং "ম্যানিফেস্ট" এর জন্য একটি শেষ ট্যাগ নেই

আশ্চর্যজনকভাবে, আমি বিভক্ত এপিএল ফাইলগুলির সাথে কোনও সমস্যা পাইনি। কেবলমাত্র প্রধান APK ফাইলগুলি।

এখানে কোড (এছাড়াও উপলব্ধ এখানে ):

মেইনঅ্যাক্টিভিটি। কেটি

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        thread {
            val problematicApkFiles = HashMap<ApplicationInfo, HashSet<String>>()
            val installedApplications = packageManager.getInstalledPackages(0)
            val startTime = System.currentTimeMillis()
            for ((index, packageInfo) in installedApplications.withIndex()) {
                val applicationInfo = packageInfo.applicationInfo
                val packageName = packageInfo.packageName
//                Log.d("AppLog", "$index/${installedApplications.size} parsing app $packageName ${packageInfo.versionCode}...")
                val mainApkFilePath = applicationInfo.publicSourceDir
                val parsedManifestOfMainApkFile =
                        try {
                            val parsedManifest = ManifestParser.parse(mainApkFilePath)
                            if (parsedManifest?.isSplitApk != false)
                                Log.e("AppLog", "$packageName - parsed normal APK, but failed to identify it as such")
                            parsedManifest?.manifestAttributes
                        } catch (e: Exception) {
                            Log.e("AppLog", e.toString())
                            null
                        }
                if (parsedManifestOfMainApkFile == null) {
                    problematicApkFiles.getOrPut(applicationInfo, { HashSet() }).add(mainApkFilePath)
                    Log.e("AppLog", "$packageName - failed to parse main APK file $mainApkFilePath")
                }
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    applicationInfo.splitPublicSourceDirs?.forEach {
                        val parsedManifestOfSplitApkFile =
                                try {
                                    val parsedManifest = ManifestParser.parse(it)
                                    if (parsedManifest?.isSplitApk != true)
                                        Log.e("AppLog", "$packageName - parsed split APK, but failed to identify it as such")
                                    parsedManifest?.manifestAttributes
                                } catch (e: Exception) {
                                    Log.e("AppLog", e.toString())
                                    null
                                }
                        if (parsedManifestOfSplitApkFile == null) {
                            Log.e("AppLog", "$packageName - failed to parse main APK file $it")
                            problematicApkFiles.getOrPut(applicationInfo, { HashSet() }).add(it)
                        }
                    }
            }
            val endTime = System.currentTimeMillis()
            Log.d("AppLog", "done parsing. number of files we failed to parse:${problematicApkFiles.size} time taken:${endTime - startTime} ms")
            if (problematicApkFiles.isNotEmpty()) {
                Log.d("AppLog", "list of files that we failed to get their manifest:")
                for (entry in problematicApkFiles) {
                    Log.d("AppLog", "packageName:${entry.key.packageName} , files:${entry.value}")
                }
            }
        }
    }
}

ManifestParser.kt

class ManifestParser{
    var isSplitApk: Boolean? = null
    var manifestAttributes: HashMap<String, String>? = null

    companion object {
        fun parse(file: File) = parse(java.io.FileInputStream(file))
        fun parse(filePath: String) = parse(File(filePath))
        fun parse(inputStream: InputStream): ManifestParser? {
            val result = ManifestParser()
            val manifestXmlString = ApkManifestFetcher.getManifestXmlFromInputStream(inputStream)
                    ?: return null
            val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
            val builder: DocumentBuilder = factory.newDocumentBuilder()
            val document: Document? = builder.parse(manifestXmlString.byteInputStream())
            if (document != null) {
                document.documentElement.normalize()
                val manifestNode: Node? = document.getElementsByTagName("manifest")?.item(0)
                if (manifestNode != null) {
                    val manifestAttributes = HashMap<String, String>()
                    for (i in 0 until manifestNode.attributes.length) {
                        val node = manifestNode.attributes.item(i)
                        manifestAttributes[node.nodeName] = node.nodeValue
                    }
                    result.manifestAttributes = manifestAttributes
                }
            }
            result.manifestAttributes?.let {
                result.isSplitApk = (it["android:isFeatureSplit"]?.toBoolean()
                        ?: false) || (it.containsKey("split"))
            }
            return result
        }

    }
}

ApkManifestFetcher.kt

object ApkManifestFetcher {
    fun getManifestXmlFromFile(apkFile: File) = getManifestXmlFromInputStream(FileInputStream(apkFile))
    fun getManifestXmlFromFilePath(apkFilePath: String) = getManifestXmlFromInputStream(FileInputStream(File(apkFilePath)))
    fun getManifestXmlFromInputStream(ApkInputStream: InputStream): String? {
        ZipInputStream(ApkInputStream).use { zipInputStream: ZipInputStream ->
            while (true) {
                val entry = zipInputStream.nextEntry ?: break
                if (entry.name == "AndroidManifest.xml") {
//                    zip.getInputStream(entry).use { input ->
                    return decompressXML(zipInputStream.readBytes())
//                    }
                }
            }
        }
        return null
    }

    /**
     * Binary XML doc ending Tag
     */
    private var endDocTag = 0x00100101

    /**
     * Binary XML start Tag
     */
    private var startTag = 0x00100102

    /**
     * Binary XML end Tag
     */
    private var endTag = 0x00100103


    /**
     * Reference var for spacing
     * Used in prtIndent()
     */
    private var spaces = "                                             "

    /**
     * Parse the 'compressed' binary form of Android XML docs
     * such as for AndroidManifest.xml in .apk files
     * Source: http://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689
     *
     * @param xml Encoded XML content to decompress
     */
    private fun decompressXML(xml: ByteArray): String {

        val resultXml = StringBuilder()

        // Compressed XML file/bytes starts with 24x bytes of data,
        // 9 32 bit words in little endian order (LSB first):
        //   0th word is 03 00 08 00
        //   3rd word SEEMS TO BE:  Offset at then of StringTable
        //   4th word is: Number of strings in string table
        // WARNING: Sometime I indiscriminently display or refer to word in
        //   little endian storage format, or in integer format (ie MSB first).
        val numbStrings = lew(xml, 4 * 4)

        // StringIndexTable starts at offset 24x, an array of 32 bit LE offsets
        // of the length/string data in the StringTable.
        val sitOff = 0x24  // Offset of start of StringIndexTable

        // StringTable, each string is represented with a 16 bit little endian
        // character count, followed by that number of 16 bit (LE) (Unicode) chars.
        val stOff = sitOff + numbStrings * 4  // StringTable follows StrIndexTable

        // XMLTags, The XML tag tree starts after some unknown content after the
        // StringTable.  There is some unknown data after the StringTable, scan
        // forward from this point to the flag for the start of an XML start tag.
        var xmlTagOff = lew(xml, 3 * 4)  // Start from the offset in the 3rd word.
        // Scan forward until we find the bytes: 0x02011000(x00100102 in normal int)
        run {
            var ii = xmlTagOff
            while (ii < xml.size - 4) {
                if (lew(xml, ii) == startTag) {
                    xmlTagOff = ii
                    break
                }
                ii += 4
            }
        } // end of hack, scanning for start of first start tag

        // XML tags and attributes:
        // Every XML start and end tag consists of 6 32 bit words:
        //   0th word: 02011000 for startTag and 03011000 for endTag
        //   1st word: a flag?, like 38000000
        //   2nd word: Line of where this tag appeared in the original source file
        //   3rd word: FFFFFFFF ??
        //   4th word: StringIndex of NameSpace name, or FFFFFFFF for default NS
        //   5th word: StringIndex of Element Name
        //   (Note: 01011000 in 0th word means end of XML document, endDocTag)

        // Start tags (not end tags) contain 3 more words:
        //   6th word: 14001400 meaning??
        //   7th word: Number of Attributes that follow this tag(follow word 8th)
        //   8th word: 00000000 meaning??

        // Attributes consist of 5 words:
        //   0th word: StringIndex of Attribute Name's Namespace, or FFFFFFFF
        //   1st word: StringIndex of Attribute Name
        //   2nd word: StringIndex of Attribute Value, or FFFFFFF if ResourceId used
        //   3rd word: Flags?
        //   4th word: str ind of attr value again, or ResourceId of value

        // TMP, dump string table to tr for debugging
        //tr.addSelect("strings", null);
        //for (int ii=0; ii<numbStrings; ii++) {
        //  // Length of string starts at StringTable plus offset in StrIndTable
        //  String str = compXmlString(xml, sitOff, stOff, ii);
        //  tr.add(String.valueOf(ii), str);
        //}
        //tr.parent();

        // Step through the XML tree element tags and attributes
        var off = xmlTagOff
        var indent = 0
//        var startTagLineNo = -2
        while (off < xml.size) {
            val tag0 = lew(xml, off)
            //int tag1 = LEW(xml, off+1*4);
//            val lineNo = lew(xml, off + 2 * 4)
            //int tag3 = LEW(xml, off+3*4);
//            val nameNsSi = lew(xml, off + 4 * 4)
            val nameSi = lew(xml, off + 5 * 4)

            if (tag0 == startTag) { // XML START TAG
//                val tag6 = lew(xml, off + 6 * 4)  // Expected to be 14001400
                val numbAttrs = lew(xml, off + 7 * 4)  // Number of Attributes to follow
                //int tag8 = LEW(xml, off+8*4);  // Expected to be 00000000
                off += 9 * 4  // Skip over 6+3 words of startTag data
                val name = compXmlString(xml, sitOff, stOff, nameSi)
                //tr.addSelect(name, null);
//                startTagLineNo = lineNo

                // Look for the Attributes
                val sb = StringBuffer()
                for (ii in 0 until numbAttrs) {
//                    val attrNameNsSi = lew(xml, off)  // AttrName Namespace Str Ind, or FFFFFFFF
                    val attrNameSi = lew(xml, off + 1 * 4)  // AttrName String Index
                    val attrValueSi = lew(xml, off + 2 * 4) // AttrValue Str Ind, or FFFFFFFF
//                    val attrFlags = lew(xml, off + 3 * 4)
                    val attrResId = lew(xml, off + 4 * 4)  // AttrValue ResourceId or dup AttrValue StrInd
                    off += 5 * 4  // Skip over the 5 words of an attribute

                    val attrName = compXmlString(xml, sitOff, stOff, attrNameSi)
                    val attrValue = if (attrValueSi != -1)
                        compXmlString(xml, sitOff, stOff, attrValueSi)
                    else
                        "resourceID 0x" + Integer.toHexString(attrResId)
                    sb.append(" $attrName=\"$attrValue\"")
                    //tr.add(attrName, attrValue);
                }
                resultXml.append(prtIndent(indent, "<$name$sb>"))
                indent++

            } else if (tag0 == endTag) { // XML END TAG
                indent--
                off += 6 * 4  // Skip over 6 words of endTag data
                val name = compXmlString(xml, sitOff, stOff, nameSi)
                resultXml.append(prtIndent(indent, "</$name>")) //  (line $startTagLineNo-$lineNo)
                //tr.parent();  // Step back up the NobTree

            } else if (tag0 == endDocTag) {  // END OF XML DOC TAG
                break

            } else {
//                println("  Unrecognized tag code '" + Integer.toHexString(tag0)
//                        + "' at offset " + off
//                )
                break
            }
        } // end of while loop scanning tags and attributes of XML tree
//        println("    end at offset $off")

        return resultXml.toString()
    } // end of decompressXML


    /**
     * Tool Method for decompressXML();
     * Compute binary XML to its string format
     * Source: Source: http://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689
     *
     * @param xml Binary-formatted XML
     * @param sitOff
     * @param stOff
     * @param strInd
     * @return String-formatted XML
     */
    private fun compXmlString(xml: ByteArray, @Suppress("SameParameterValue") sitOff: Int, stOff: Int, strInd: Int): String? {
        if (strInd < 0) return null
        val strOff = stOff + lew(xml, sitOff + strInd * 4)
        return compXmlStringAt(xml, strOff)
    }


    /**
     * Tool Method for decompressXML();
     * Apply indentation
     *
     * @param indent Indentation level
     * @param str String to indent
     * @return Indented string
     */
    private fun prtIndent(indent: Int, str: String): String {

        return spaces.substring(0, min(indent * 2, spaces.length)) + str
    }


    /**
     * Tool method for decompressXML()
     * Return the string stored in StringTable format at
     * offset strOff.  This offset points to the 16 bit string length, which
     * is followed by that number of 16 bit (Unicode) chars.
     *
     * @param arr StringTable array
     * @param strOff Offset to get string from
     * @return String from StringTable at offset strOff
     */
    private fun compXmlStringAt(arr: ByteArray, strOff: Int): String {
        val strLen = (arr[strOff + 1] shl (8 and 0xff00)) or (arr[strOff].toInt() and 0xff)
        val chars = ByteArray(strLen)
        for (ii in 0 until strLen) {
            chars[ii] = arr[strOff + 2 + ii * 2]
        }
        return String(chars)  // Hack, just use 8 byte chars
    } // end of compXmlStringAt


    /**
     * Return value of a Little Endian 32 bit word from the byte array
     * at offset off.
     *
     * @param arr Byte array with 32 bit word
     * @param off Offset to get word from
     * @return Value of Little Endian 32 bit word specified
     */
    private fun lew(arr: ByteArray, off: Int): Int {
        return (arr[off + 3] shl 24 and -0x1000000 or ((arr[off + 2] shl 16) and 0xff0000)
                or (arr[off + 1] shl 8 and 0xff00) or (arr[off].toInt() and 0xFF))
    } // end of LEW

    private infix fun Byte.shl(i: Int): Int = (this.toInt() shl i)
//    private infix fun Int.shl(i: Int): Int = (this shl i)
}

প্রশ্নসমুহ

  1. আমি কীভাবে কিছু APK ম্যানিফেস্ট ফাইলের জন্য একটি অবৈধ এক্সএমএল সামগ্রী পেতে পারি (সুতরাং তাদের জন্য এক্সএমএল পার্সিং ব্যর্থ হওয়া)?
  2. আমি কীভাবে এটি সর্বদা কাজ করতে পারি?
  3. বৈধ এক্সএমএলে ম্যানিফেস্ট ফাইলটি পার্স করার আরও ভাল কোনও উপায় আছে কি? সম্ভবত এর চেয়ে ভাল বিকল্প, এটি জিপড ফাইলগুলি সহ সমস্ত ধরণের APK ফাইলগুলি সংক্ষেপণ ছাড়াই কাজ করতে পারে?

আমি মনে করি যে উদ্ভাসিত কিছুগুলি DexGuard দ্বারা আবদ্ধ করা হয়েছে ( এখানে দেখুন ) যেখানে ম্যানিফেস্ট ফাইলের অস্পষ্টতার কথা বলা হয়েছে। এটি আপনার তালিকার # 1 এর ক্ষেত্রে বলে মনে হচ্ছে, com.farproc.wifi.analyzer। এর ম্যানিফেস্ট ফাইলটি "<মেনিফেস্ট" এর পরিবর্তে "<mnfs" দিয়ে শুরু হয় এবং তাই আমার ফোনে আরও 20 বা তাই অ্যাপ্লিকেশনগুলি করে।
চেটিক্যাম্প

@ ক্যান্টেম্প স্ট্যাম্প, ফ্রেমওয়ার্ক নিজেই এটি ঠিকঠাক পড়তে পারে। এগুলি সমস্ত ডিপিএল ফাইল যা আমার ডিভাইসে সূক্ষ্মভাবে ইনস্টল করা আছে। আপনার বর্ণনা করা কিছুটির কাছে এই সঠিক সমস্যাটি ছিল না এবং তাদের মধ্যে একটি অত্যন্ত পুরানো।
অ্যান্ড্রয়েড বিকাশকারী

এবং তবুও, ডেক্সগার্ড দাবি করেছে যে ম্যানিফেস্ট ফাইলটি অপ্রকাশিত করতে সক্ষম হবে। আমি জানি না তারা কীভাবে এটি করে এবং তবুও ফ্রেমওয়ার্কটি ম্যানিফেস্টটি পড়তে পারে তবে এটি আইএমওতে দেখার বিষয় to অন্যান্য সমস্যা হিসাবে, আপনি কি প্রয়োজন কেবল এক্সট্রোল করতে এক্সএমএলপুলপারসার ব্যবহার করে দেখেছেন? হতে পারে আপনি ইতিমধ্যে এটি চেষ্টা করেছেন এবং আমি যথেষ্ট মনোযোগ দিয়ে পড়িনি।
চেটিক্যাম্প

আমি ইতিমধ্যে খুঁজে পাওয়া সমস্ত সমস্যার উল্লেখ করেছি এবং বেশিরভাগ ক্ষেত্রে এটি "এমএনএফএস" নয়। এটি কেবল প্রথম 2 টি ক্ষেত্রে। এছাড়াও, যদি আপনি কিছু অনলাইন সরঞ্জামের মাধ্যমে সেগুলি বিশ্লেষণ করার চেষ্টা করেন তবে এটি এখনও দুর্দান্ত কাজ করবে।
অ্যান্ড্রয়েড বিকাশকারী

এপিপি-পার্সার দিয়ে কী কাজ করে না ? আমি এটি একটি এমুলেটরটিতে চালাতে সক্ষম হয়েছি এবং এটি ঠিক আছে। এটির জন্য কি কোনও ইনপুট স্ট্রিম গ্রহণ করতে হবে?
চেটিক্যাম্প

উত্তর:


0

সম্ভবত আপনি ইতিমধ্যে চিহ্নিত সমস্ত বিশেষ কেসগুলি হ্যান্ডেল করতে হবে।

উপমা এবং হেক্সাডেসিমাল উল্লেখগুলি এটিকে বিভ্রান্ত করতে পারে; এগুলি সমাধান করা দরকার।

উদাহরণস্বরূপ, ফল-ব্যাক থেকে manifestথেকে mnfsঅন্তত একটি সমস্যা সমাধানের হবে:

fun getRootNode(document: Document): Node? {
    var node: Node? = document.getElementsByTagName("manifest")?.item(0)
    if (node == null) {
        node = document.getElementsByTagName("mnfs")?.item(0)
    }
    return node
}

"বৈশিষ্ট্য ও পরীক্ষা" এর TextUtils.htmlEncode()জন্য &amp;বা অন্য কোনও পার্সার কনফিগারেশন প্রয়োজন।

একক AndroidManifest.xmlফাইলগুলিকে পার্স করা এটিকে পরীক্ষা করা আরও সহজ করে তুলবে, কারণ একে অপরের প্যাকেজের সাথে আরও অপ্রত্যাশিত ইনপুট থাকতে পারে - যতক্ষণ না এটি ম্যানিফেস্ট পার্সারের কাছে না আসে যতক্ষণ না ওএস ব্যবহার করে ( উত্স কোড সাহায্য করতে পারে)। যেমনটি দেখতে পাচ্ছে এটি পড়ার জন্য এটি কুকিজ সেট করতে পারে। প্যাকেজ নামের এই তালিকাটি নিন এবং সেগুলির প্রত্যেকের জন্য একটি পরীক্ষা কেস সেট আপ করুন, তারপরে বিষয়গুলি বরং পৃথক করা হয়েছে। তবে মূল সমস্যাটি হ'ল এই কুকিগুলি সম্ভবত তৃতীয় পক্ষের অ্যাপ্লিকেশনগুলিতে উপলব্ধ নয়।


এটি কেবল তাই নয়, তবে আমি যেমন লিখেছি এক্সএমএল নিজেই অবৈধ। বিষয়টি এমনকি এক্সএমএলকে বিশ্লেষণ করার আগে। অর্থ: কিছু ট্যাগের অস্তিত্ব নেই এবং কিছুতে শেষ-ট্যাগ নেই। দয়া করে, আপনি যদি এই সমস্যাটি সমাধানের কোনও উপায় খুঁজে পেয়েছেন তবে কীভাবে আমাকে বলুন।
অ্যান্ড্রয়েড বিকাশকারী

0

দেখে মনে হচ্ছে ApkManLiveFetcher পাঠ্য (ট্যাগগুলির মধ্যে) এবং নামের স্থান ঘোষণার মতো এবং অন্যান্য কিছু জিনিস যেমন সমস্ত ক্ষেত্রে পরিচালনা করে না। নীচে অ্যাপম্যানিফেস্টফ্যাচারের একটি পুনর্নির্মাণ দেওয়া হয়েছে যা নেটফ্লিক্স এপিপি ব্যতীত আমার ফোনে সমস্ত 300+ APK হ্যান্ডেল করে যা কিছু ফাঁকা বৈশিষ্ট্য নিয়ে আসে।

আমি আর বিশ্বাস করি না যে ফাইলগুলি <mnfsযেগুলির সাথে শুরু হয় সেগুলি ইউটিএফ -16 এর পরিবর্তে ইউটিএফ -8 ব্যবহার করে এনকোড থাকে যা অ্যাপটি ধরে নেয় (16 বিট বনাম 8 বিট)। পুনরায় কাজ করা অ্যাপটি ইউটিএফ -8 এনকোডিং পরিচালনা করে এবং এই ফাইলগুলিকে পার্স করতে পারে।

উপরে উল্লিখিত হিসাবে, নামের জায়গাগুলি মূল বর্গ বা এই পুনর্নির্মাণের দ্বারা সঠিকভাবে পরিচালনা করা হয় না যদিও পুনরায় কাজটি সেগুলি ছাড়তে পারে। কোডে মন্তব্যগুলি এটি একটু বর্ণনা করে।

এটি বলেছিল, নীচের কোডটি নির্দিষ্ট অ্যাপ্লিকেশনের জন্য যথেষ্ট ভাল হতে পারে। আরও ভাল, যদিও দীর্ঘতর, ক্রমক্রমে অবশ্যই apktool থেকে কোড ব্যবহার করা হবে যা মনে হয় যে সমস্ত APKs পরিচালনা করতে সক্ষম হবে।

ApkManifestFetcher

object ApkManifestFetcher {
    fun getManifestXmlFromFile(apkFile: File) =
            getManifestXmlFromInputStream(FileInputStream(apkFile))

    fun getManifestXmlFromFilePath(apkFilePath: String) =
            getManifestXmlFromInputStream(FileInputStream(File(apkFilePath)))

    fun getManifestXmlFromInputStream(ApkInputStream: InputStream): String? {
        ZipInputStream(ApkInputStream).use { zipInputStream: ZipInputStream ->
            while (true) {
                val entry = zipInputStream.nextEntry ?: break
                if (entry.name == "AndroidManifest.xml") {
                    return decompressXML(zipInputStream.readBytes())
                }
            }
        }
        return null
    }

    /**
     * Binary XML name space starts
     */
    private const val startNameSpace = 0x00100100

    /**
     * Binary XML name space ends
     */
    private const val endNameSpace = 0x00100101

    /**
     * Binary XML start Tag
     */
    private const val startTag = 0x00100102

    /**
     * Binary XML end Tag
     */
    private const val endTag = 0x00100103

    /**
     * Binary XML text Tag
     */
    private const val textTag = 0x00100104

    /*
     * Flag for UTF-8 encoded file. Default is UTF-16.
     */
    private const val FLAG_UTF_8 = 0x00000100

    /**
     * Reference var for spacing
     * Used in prtIndent()
     */
    private const val spaces = "                                             "

    // Flag if the manifest is in UTF-8 but we don't really handle it.
    private var mIsUTF8 = false

    /**
     * Parse the 'compressed' binary form of Android XML docs
     * such as for AndroidManifest.xml in .apk files
     * Source: http://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689
     *
     * @param xml Encoded XML content to decompress
     */
    private fun decompressXML(xml: ByteArray): String {
        val resultXml = StringBuilder()
        /*
        Compressed XML file/bytes starts with 24x bytes of data
            9 32 bit words in little endian order (LSB first):
                0th word is 03 00 (Magic number) 08 00 (header size words 0-1)
                1st word is the size of the compressed XML. This should equal size of xml array.
                2nd word is 01 00 (Magic number) 1c 00 (header size words 2-8)
                3rd word is offset of byte after string table
                4th word is number of strings in string table
                5th word is style count
                6th word are flags
                7th word string table offset
                8th word is styles offset
                [string index table (little endian offset into string table)]
                [string table (two byte length followed by text for each entry UTF-16, nul)]
        */

        mIsUTF8 = (lew(xml, 24) and FLAG_UTF_8) != 0

        val numbStrings = lew(xml, 4 * 4)

        // StringIndexTable starts at offset 24x, an array of 32 bit LE offsets
        // of the length/string data in the StringTable.
        val sitOff = 0x24  // Offset of start of StringIndexTable

        // StringTable, each string is represented with a 16 bit little endian
        // character count, followed by that number of 16 bit (LE) (Unicode) chars.
        val stOff = sitOff + numbStrings * 4  // StringTable follows StrIndexTable

        // XMLTags, The XML tag tree starts after some unknown content after the
        // StringTable.  There is some unknown data after the StringTable, scan
        // forward from this point to the flag for the start of an XML start tag.
        var xmlTagOff = lew(xml, 3 * 4)  // Start from the offset in the 3rd word.
        // Scan forward until we find the bytes: 0x02011000(x00100102 in normal int)
        run {
            var ii = xmlTagOff
            while (ii < xml.size - 4) {
                if (lew(xml, ii) == startTag) {
                    xmlTagOff = ii
                    break
                }
                ii += 4
            }
        }

        /*
        XML tags and attributes:

        Every XML start and end tag consists of 6 32 bit words:
            0th word: 02011000 for startTag and 03011000 for endTag
            1st word: a flag?, like 38000000
            2nd word: Line of where this tag appeared in the original source file
            3rd word: 0xFFFFFFFF ??
            4th word: StringIndex of NameSpace name, or 0xFFFFFF for default NS
            5th word: StringIndex of Element Name
            (Note: 01011000 in 0th word means end of XML document, endDocTag)

        Start tags (not end tags) contain 3 more words:
            6th word: 14001400 meaning??
            7th word: Number of Attributes that follow this tag(follow word 8th)
            8th word: 00000000 meaning??

        Attributes consist of 5 words:
            0th word: StringIndex of Attribute Name's Namespace, or 0xFFFFFF
            1st word: StringIndex of Attribute Name
            2nd word: StringIndex of Attribute Value, or 0xFFFFFFF if ResourceId used
            3rd word: Flags?
            4th word: str ind of attr value again, or ResourceId of value

        Text blocks consist of 7 words
            0th word: The text tag (0x00100104)
            1st word: Size of the block (28 bytes)
            2nd word: Line number
            3rd word: 0xFFFFFFFF
            4th word: Index into the string table
            5th word: Unknown
            6th word: Unknown

        startNameSpace blocks consist of 6 words
            0th word: The startNameSpace tag (0x00100100)
            1st word: Size of the block (24 bytes)
            2nd word: Line number
            3rd word: 0xFFFFFFFF
            4th word: Index into the string table for the prefix
            5th word: Index into the string table for the URI

        endNameSpace blocks consist of 6 words
            0th word: The endNameSpace tag (0x00100101)
            1st word: Size of the block (24 bytes)
            2nd word: Line number
            3rd word: 0xFFFFFFFF
            4th word: Index into the string table for the prefix
            5th word: Index into the string table for the URI
        */

        // Step through the XML tree element tags and attributes
        var off = xmlTagOff
        var indent = 0
        while (off < xml.size) {
            val tag0 = lew(xml, off)
            val nameSi = lew(xml, off + 5 * 4)

            when (tag0) {
                startTag -> {
                    val numbAttrs = lew(xml, off + 7 * 4)  // Number of Attributes to follow
                    off += 9 * 4  // Skip over 6+3 words of startTag data
                    val name = compXmlString(xml, sitOff, stOff, nameSi)

                    // Look for the Attributes
                    val sb = StringBuffer()
                    for (ii in 0 until numbAttrs) {
                        val attrNameSi = lew(xml, off + 1 * 4)  // AttrName String Index
                        val attrValueSi = lew(xml, off + 2 * 4) // AttrValue Str Ind, or 0xFFFFFF
                        val attrResId = lew(xml, off + 4 * 4)  // AttrValue ResourceId or dup AttrValue StrInd
                        off += 5 * 4  // Skip over the 5 words of an attribute

                        val attrName = compXmlString(xml, sitOff, stOff, attrNameSi)
                        val attrValue = if (attrValueSi != -1)
                            compXmlString(xml, sitOff, stOff, attrValueSi)
                        else
                            "resourceID 0x" + Integer.toHexString(attrResId)
                        sb.append(" $attrName=\"$attrValue\"")
                    }
                    resultXml.append(prtIndent(indent, "<$name$sb>"))
                    indent++
                }
                endTag -> {
                    indent--
                    off += 6 * 4  // Skip over 6 words of endTag data
                    val name = compXmlString(xml, sitOff, stOff, nameSi)
                    resultXml.append(prtIndent(indent, "</$name>")
                    )

                }
                textTag -> {  // Text that is hanging out between start and end tags
                    val text = compXmlString(xml, sitOff, stOff, lew(xml, off + 16))
                    resultXml.append(text)
                    off += lew(xml, off + 4)
                }
                startNameSpace -> {
                    //Todo startNameSpace and endNameSpace are effectively skipped, but they are not handled.
                    off += lew(xml, off + 4)
                }
                endNameSpace -> {
                    off += lew(xml, off + 4)
                }
                else -> {
                    Log.d(
                            "Applog", "  Unrecognized tag code '" + Integer.toHexString(tag0)
                            + "' at offset " + off
                    )
                }
            }
        }
        return resultXml.toString()
    }

    /**
     * Tool Method for decompressXML();
     * Compute binary XML to its string format
     * Source: Source: http://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689
     *
     * @param xml Binary-formatted XML
     * @param sitOff
     * @param stOff
     * @param strInd
     * @return String-formatted XML
     */
    private fun compXmlString(
            xml: ByteArray, @Suppress("SameParameterValue") sitOff: Int,
            stOff: Int,
            strInd: Int
    ): String? {
        if (strInd < 0) return null
        val strOff = stOff + lew(xml, sitOff + strInd * 4)
        return compXmlStringAt(xml, strOff)
    }

    /**
     * Tool Method for decompressXML();
     * Apply indentation
     *
     * @param indent Indentation level
     * @param str String to indent
     * @return Indented string
     */
    private fun prtIndent(indent: Int, str: String): String {
        return spaces.substring(0, min(indent * 2, spaces.length)) + str
    }

    /**
     * Tool method for decompressXML()
     * Return the string stored in StringTable format at
     * offset strOff.  This offset points to the 16 bit string length, which
     * is followed by that number of 16 bit (Unicode) chars.
     *
     * @param arr StringTable array
     * @param strOff Offset to get string from
     * @return String from StringTable at offset strOff
     */
    private fun compXmlStringAt(arr: ByteArray, strOff: Int): String {
        var start = strOff
        var charSetUsed: Charset = Charsets.UTF_16LE

        val byteLength = if (mIsUTF8) {
            charSetUsed = Charsets.UTF_8
            start += 2
            arr[strOff + 1].toInt() and 0xFF
        } else { // UTF-16LE
            start += 2
            ((arr[strOff + 1].toInt() and 0xFF shl 8) or (arr[strOff].toInt() and 0xFF)) * 2
        }
        return String(arr, start, byteLength, charSetUsed)
    }

    /**
     * Return value of a Little Endian 32 bit word from the byte array
     * at offset off.
     *
     * @param arr Byte array with 32 bit word
     * @param off Offset to get word from
     * @return Value of Little Endian 32 bit word specified
     */
    private fun lew(arr: ByteArray, off: Int): Int {
        return (arr[off + 3] shl 24 and -0x1000000 or ((arr[off + 2] shl 16) and 0xff0000)
                or (arr[off + 1] shl 8 and 0xff00) or (arr[off].toInt() and 0xFF))
    }

    private infix fun Byte.shl(i: Int): Int = (this.toInt() shl i)
}

সুতরাং এটি এখনও নির্ভরযোগ্য নয়। আপনি সম্ভবত jadx চেষ্টা করেছেন? আমি আশ্চর্য হয়েছি যে এটি যদি এন্ড্রয়েড অ্যাপ্লিকেশনটিতেও APK ফাইল ভালভাবে পরিচালনা করতে পারে।
অ্যান্ড্রয়েড বিকাশকারী

@ Androiddeveloper আমি জ্যাডএক্সের দিকে তাকাইনি। আমি অ্যাপটোলকে অনুধাবন করেছি এবং মনে করি এটি একটি ভাল উত্স (এবং উন্মুক্ত)) এটি অ্যান্ড্রয়েড এ হোস্ট করতে কিছু কাজ লাগবে তবে সম্ভবত প্রকাশ্য অংশটি করণীয় হবে। এখানে যা পোস্ট করা হয় তা অবশ্যই উত্পাদন যোগ্য নয় কারণ ম্যানিফেস্ট ফাইলগুলির অনেকগুলি দিক এটি সম্বোধন করে না।
চেটিক্যাম্প

@ অ্যান্ড্রয়েড ডেভেলপার আমি বিশ্বাস করি যে "<এমএনএফএস" দিয়ে শুরু হওয়া উদ্ভাবনগুলি ইউটিএফ -16 এর পরিবর্তে ইউটিএফ -8 এনকোডেড রয়েছে এবং অ্যাপটি ইউটিএফ -16 ধরেছে। এ কারণেই এটি "mnfs" - "m (a) n (i) f (e) s (t)" এ, i, e, t বাদ দেওয়া হয়েছে যেহেতু 16-বিট ধরে নেওয়া হয়।
চেটিক্যাম্প

জ্যাডেক্স ওপেন সোর্সযুক্ত, এবং জাভাতেও। নিশ্চিত না যে এটি ইনপুটস্ট্রিমকে সমর্থন করে কিনা (যেমন আমি জিজ্ঞাসা করেছি)। আপনি যদি কোনও ভাল সমাধান খুঁজে পান তবে দয়া করে আমাকে জানান। আমি ইতিমধ্যে বিভিন্ন সমাধান চেষ্টা করেছি এবং কোনও নির্ভরযোগ্য খুঁজে পাইনি। আমি বড় বড় সরঞ্জামগুলি ব্যবহার করার বিষয়েও ভীত, কারণ সম্ভবত তারা অনেক বেশি মেমরি নিতে পারে যা কিছু ডিভাইসে ক্রাশ হতে পারে (জ্যাডেক্স এর প্রায়শই জিজ্ঞাসিত প্রশ্নাগুলিতে OOM সম্পর্কে আলোচনা করে: github.com/skylot/jadx/wiki/Troubleshooting-Q&A ) । তাই আমি এমন একটি ন্যূনতম সমাধান / লাইব্রেরি পছন্দ করি যা অ্যান্ড্রয়েডের পক্ষে সবচেয়ে ভাল কাজ করে।
অ্যান্ড্রয়েড বিকাশকারী 13
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.