com.gabrielittner.github.diff.Apk.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of github-diff Show documentation
Show all versions of github-diff Show documentation
Diff apks and post results to Github
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)
}
}
}