All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gabrielittner.github.diff.Apk.kt Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
package com.gabrielittner.github.diff

import com.gabrielittner.github.diff.manifest.AndroidManifestParser
import com.gabrielittner.github.diff.manifest.AndroidXmlTranslator
import com.jakewharton.dex.DexParser
import okio.ByteString
import java.util.SortedSet
import java.util.TreeSet

data class Apk(
    val name: String,
    val commit: String,
    val bytes: ByteString,
    val url: String?,
    val manifest: String,
    val permissions: SortedSet,
    val features: SortedSet,
    val methods: SortedSet,
    val fields: SortedSet
) {
    val fileSize: Int get() = bytes.size
    val methodCount: Int get() = methods.size
    val fieldCount: Int get() = fields.size

    companion object {
        fun from(name: String, commit: String, bytes: ByteString, url: String? = null): Apk {
            val manifest = AndroidXmlTranslator.parse(bytes.toByteArray().inputStream())

            val manifestParser = AndroidManifestParser(manifest)
            val permissions = TreeSet(manifestParser.parsePermissions())
            val features = TreeSet(manifestParser.parseFeatures())

            val dexParser = DexParser.fromBytes(bytes.toByteArray())
            val methods = TreeSet(dexParser.listMethods().map { it.toString() })
            val fields = TreeSet(dexParser.listFields().map { it.toString() })

            return Apk(name, commit, bytes, url, manifest, permissions, features, methods, fields)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy