mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-04-28 12:03:09 -07:00
Switch over to use Wire
Assisted-by: Gemini
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import com.google.protobuf.gradle.id
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
kotlin("plugin.parcelize")
|
||||
alias(libs.plugins.moshix)
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.protobuf)
|
||||
alias(libs.plugins.wire)
|
||||
}
|
||||
|
||||
setupCoreLib()
|
||||
@@ -14,19 +12,8 @@ ksp {
|
||||
arg("room.generateKotlin", "true")
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = libs.protobuf.protoc.get().toString()
|
||||
}
|
||||
generateProtoTasks {
|
||||
ofNonTest().forEach { task ->
|
||||
task.builtins {
|
||||
id("java") {
|
||||
option("lite")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
wire {
|
||||
kotlin {}
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -59,7 +46,7 @@ dependencies {
|
||||
implementation(libs.bcpkix)
|
||||
implementation(libs.commons.compress)
|
||||
implementation(libs.xz)
|
||||
implementation(libs.protobuf.javalite)
|
||||
implementation(libs.wire.runtime)
|
||||
|
||||
api(libs.libsu.core)
|
||||
api(libs.libsu.service)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.topjohnwu.magisk.core.tasks
|
||||
|
||||
import chromeos_update_engine.UpdateMetadata.DeltaArchiveManifest
|
||||
import chromeos_update_engine.UpdateMetadata.InstallOperation
|
||||
import chromeos_update_engine.UpdateMetadata.PartitionUpdate
|
||||
import chromeos_update_engine.DeltaArchiveManifest
|
||||
import chromeos_update_engine.InstallOperation
|
||||
import chromeos_update_engine.PartitionUpdate
|
||||
import com.topjohnwu.magisk.core.utils.DataSourceChannel
|
||||
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
|
||||
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream
|
||||
@@ -25,18 +25,19 @@ class Payload(private val channel: DataSourceChannel) {
|
||||
@Throws(IOException::class)
|
||||
fun extract(outputFile: File, console: (String) -> Unit, logger: (String) -> Unit) {
|
||||
val partition = findPartition()
|
||||
console("- Found partition ${partition.partitionName}")
|
||||
console("- Found partition ${partition.partition_name}")
|
||||
|
||||
val actualHash = extractPartition(outputFile, partition, console)
|
||||
|
||||
if (!partition.newPartitionInfo.hasHash()) {
|
||||
val newPartitionInfo = partition.new_partition_info
|
||||
if (newPartitionInfo?.hash == null) {
|
||||
logger("Hash verification skipped")
|
||||
return
|
||||
}
|
||||
|
||||
fun toHex(bytes: ByteArray) = bytes.joinToString("") { "%02x".format(it) }
|
||||
|
||||
val expectedHash = partition.newPartitionInfo.hash.toByteArray()
|
||||
val expectedHash = newPartitionInfo.hash.toByteArray()
|
||||
if (!expectedHash.contentEquals(actualHash)) {
|
||||
throw IOException(
|
||||
"Hash mismatch, expected ${toHex(expectedHash)}, but got ${toHex(actualHash)}"
|
||||
@@ -87,7 +88,7 @@ class Payload(private val channel: DataSourceChannel) {
|
||||
val manifestBuffer = ByteBuffer.allocate(manifestLen)
|
||||
channel.read(manifestBuffer)
|
||||
manifestBuffer.flip()
|
||||
val manifest = DeltaArchiveManifest.parseFrom(manifestBuffer.array())
|
||||
val manifest = DeltaArchiveManifest.ADAPTER.decode(manifestBuffer.array())
|
||||
|
||||
// Skip manifest signature
|
||||
channel.position(channel.position() + manifestSigLen)
|
||||
@@ -99,8 +100,8 @@ class Payload(private val channel: DataSourceChannel) {
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun findPartition(): PartitionUpdate {
|
||||
return manifest.partitionsList.find { it.partitionName == "init_boot" }
|
||||
?: manifest.partitionsList.find { it.partitionName == "boot" }
|
||||
return manifest.partitions.find { it.partition_name == "init_boot" }
|
||||
?: manifest.partitions.find { it.partition_name == "boot" }
|
||||
?: throw IOException("boot partition not found in payload")
|
||||
}
|
||||
|
||||
@@ -117,11 +118,11 @@ class Payload(private val channel: DataSourceChannel) {
|
||||
StandardOpenOption.READ,
|
||||
StandardOpenOption.TRUNCATE_EXISTING
|
||||
).use { outChannel ->
|
||||
val size = partition.newPartitionInfo.size
|
||||
val size = partition.new_partition_info?.size ?: 0L
|
||||
outChannel.write(ByteBuffer.allocate(1), size - 1)
|
||||
|
||||
val count = partition.operationsCount
|
||||
partition.operationsList.forEachIndexed { index, operation ->
|
||||
val count = partition.operations.size
|
||||
partition.operations.forEachIndexed { index, operation ->
|
||||
if (index % 5 == 0 || index == count - 1) {
|
||||
console("- Downloading ${index + 1}/$count")
|
||||
}
|
||||
@@ -137,17 +138,17 @@ class Payload(private val channel: DataSourceChannel) {
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun processOperation(outChannel: FileChannel, operation: InstallOperation) {
|
||||
val dataType = operation.getType()
|
||||
val dataType = operation.type
|
||||
if (dataType == InstallOperation.Type.ZERO) {
|
||||
return
|
||||
}
|
||||
|
||||
val dataBuffer = ByteBuffer.allocate(operation.getDataLength().toInt())
|
||||
channel.read(dataBuffer, dataBase + operation.getDataOffset())
|
||||
val dataBuffer = ByteBuffer.allocate(operation.data_length?.toInt() ?: 0)
|
||||
channel.read(dataBuffer, dataBase + (operation.data_offset ?: 0L))
|
||||
dataBuffer.flip()
|
||||
|
||||
val dstExtent = operation.getDstExtents(0)
|
||||
val outOffset = dstExtent.getStartBlock() * manifest.getBlockSize()
|
||||
val dstExtent = operation.dst_extents[0]
|
||||
val outOffset = (dstExtent.start_block ?: 0L) * (manifest.block_size ?: 4096)
|
||||
|
||||
when (dataType) {
|
||||
InstallOperation.Type.REPLACE -> {
|
||||
|
||||
@@ -25,7 +25,6 @@ kapt.use.k2=true
|
||||
|
||||
# Android
|
||||
android.injected.testOnly=false
|
||||
android.newDsl=false
|
||||
|
||||
# Magisk
|
||||
magisk.stubVersion=40
|
||||
|
||||
@@ -14,7 +14,7 @@ compose-ui = "1.10.6"
|
||||
compose-m3 = "1.4.0"
|
||||
navigation3 = "1.1.0-rc01"
|
||||
navigationevent = "1.0.2"
|
||||
protobuf = "4.31.1"
|
||||
wire = "6.2.0"
|
||||
|
||||
[libraries]
|
||||
bcpkix = { module = "org.bouncycastle:bcpkix-jdk18on", version = "1.83" }
|
||||
@@ -27,8 +27,6 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||
okhttp-dnsoverhttps = { module = "com.squareup.okhttp3:okhttp-dnsoverhttps", version.ref = "okhttp" }
|
||||
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
|
||||
timber = { module = "com.jakewharton.timber:timber", version = "5.0.1" }
|
||||
protobuf-javalite = { module = "com.google.protobuf:protobuf-javalite", version.ref = "protobuf" }
|
||||
protobuf-protoc = { module = "com.google.protobuf:protoc", version.ref = "protobuf" }
|
||||
xz = { module = "org.tukaani:xz", version = "1.10" }
|
||||
|
||||
# AndroidX
|
||||
@@ -57,6 +55,7 @@ test-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version =
|
||||
|
||||
# topjohnwu
|
||||
indeterminate-checkbox = { module = "com.github.topjohnwu:indeterminate-checkbox", version = "1.0.7" }
|
||||
wire-runtime = { module = "com.squareup.wire:wire-runtime", version.ref = "wire" }
|
||||
libsu-core = { module = "com.github.topjohnwu.libsu:core", version.ref = "libsu" }
|
||||
libsu-service = { module = "com.github.topjohnwu.libsu:service", version.ref = "libsu" }
|
||||
libsu-nio = { module = "com.github.topjohnwu.libsu:nio", version.ref = "libsu" }
|
||||
@@ -94,4 +93,4 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "
|
||||
lsparanoid = { id = "org.lsposed.lsparanoid", version = "0.6.0" }
|
||||
moshix = { id = "dev.zacsweers.moshix", version = "0.35.0" }
|
||||
navigation-safeargs = { id = "androidx.navigation.safeargs.kotlin", version.ref = "navigation" }
|
||||
protobuf = { id = "com.google.protobuf", version = "0.9.6" }
|
||||
wire = { id = "com.squareup.wire", version.ref = "wire" }
|
||||
|
||||
Reference in New Issue
Block a user