windows: install gzip, 7zip

disable c++ modules in settings.gradle.kts
add copyright.kts
master
cfig 1 week ago
parent 44881fe090
commit c55f584f2e
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -87,7 +87,7 @@ jobs:
run: python -c "import sys; print(sys.version)"
- name: choco
run: choco install openssl dtc-msys2 zip vim
run: choco install openssl dtc-msys2 zip vim gzip 7zip
- name: Unit Test
run: ./gradlew.bat check && ./gradlew.bat clean || true

@ -12,7 +12,7 @@ Make sure you have [JDK11+](https://www.oracle.com/java/technologies/downloads/#
* Mac: `brew install lz4 xz dtc`
* Windows: Install openssl and device-tree compiler with [chocolate](https://chocolatey.org/install)
`choco install openssl dtc-msys2 zip vim`
`choco install openssl dtc-msys2 zip vim gzip 7zip`
## Getting Started
Put your boot.img to current directory, then start gradle 'unpack' task:

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2021 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2021 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2018-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2021 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -345,16 +345,18 @@ data class BootV2(
this.secondBootloader?.let { theSecondBootloader ->
if (theSecondBootloader.size > 0) {
it.addRule()
it.addRow("second bootloader", theSecondBootloader.file)
prints.add(Pair("second bootloader", theSecondBootloader.file.toString()))
val tmp = theSecondBootloader.file?.let { file -> shortenPath(file) } ?: "NONE"
it.addRow("second bootloader", tmp)
prints.add(Pair("second bootloader", tmp))
}
}
//dtbo
this.recoveryDtbo?.let { theDtbo ->
if (theDtbo.size > 0) {
it.addRule()
it.addRow("recovery dtbo", theDtbo.file)
prints.add(Pair("recovery dtbo", theDtbo.file.toString()))
val tmp = theDtbo.file.toString()
it.addRow("recovery dtbo", tmp)
prints.add(Pair("recovery dtbo", tmp))
}
}
//dtb
@ -362,8 +364,9 @@ data class BootV2(
if (theDtb.size > 0) {
val dtbCount = this.dtb!!.dtbList.size
it.addRule()
it.addRow("dtb", theDtb.file?.let { fullPath -> shortenPath(fullPath) })
prints.add(Pair("dtb", shortenPath(theDtb.file.toString())))
val tmp = shortenPath(shortenPath(theDtb.file!!))
it.addRow("dtb", tmp)
prints.add(Pair("dtb", tmp))
if (File(theDtb.file + ".0.${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts [$dtbCount]", shortenPath(theDtb.file!!) + ".*.${dtsSuffix}")
prints.add(Pair("\\-- decompiled dts [$dtbCount]", shortenPath(theDtb.file!!) + ".*.${dtsSuffix}"))

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2021-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -214,57 +214,21 @@ data class BootV3(
return this
}
fun sign(fileName: String): BootV3 {
var bSigningNeeded = false
if (File(Avb.getJsonFileName(info.role)).exists()) {
bSigningNeeded = true
Signer.signAVB(
Helper.joinPath(Helper.prop("intermediateDir")!!, info.role),
this.info.imageSize,
String.format(Helper.prop("avbtool")!!, "v1.2")
)
fun sign(outputFile: String): BootV3 {
val bSigningNeeded = File(Avb.getJsonFileName(info.role)).exists()
val origOutFile = Helper.joinPath(Helper.prop("intermediateDir")!!, info.role)
val clearOutFile = Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".clear")
val signedOutFile = Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".signed")
if (bSigningNeeded) {
Signer.signAVB(origOutFile, this.info.imageSize, String.format(Helper.prop("avbtool")!!, "v1.2"))
File(signedOutFile).copyTo(File(outputFile), true)
log.info("Signed image saved as $outputFile")
} else {
bSigningNeeded = false
log.warn("no AVB info found, assume it's clear image")
File(clearOutFile).copyTo(File(outputFile), true)
log.info("Unsigned image saved as $outputFile")
}
if (fileName != info.role) {
if (bSigningNeeded) {
log.info("x1")
Helper.setProp("out.file", "$fileName.signed")
//@formatter:off
File(Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".signed"))
.copyTo(File(Helper.prop("out.file")!!), true)
//@formatter:on
log.info("Signed image saved as " + Helper.prop("out.file"))
} else {
log.info("x2")
Helper.setProp("out.file", fileName)
//@formatter:off
File(Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".clear"))
.copyTo(File(Helper.prop("out.file")!!), true)
//@formatter:on
log.info("Unsigned image saved as " + Helper.prop("out.file"))
}
} else {
if (bSigningNeeded) {
log.info("x3")
Helper.setProp("out.file", info.role + ".signed")
//@formatter:off
File(Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".signed"))
.copyTo(File(info.role + ".signed"), true)
//@formatter:on
log.info("Signed image saved as ${info.role}.signed")
} else {
log.info("x4")
Helper.setProp("out.file", info.role + ".clear")
//@formatter:off
File(Helper.joinPath(Helper.prop("intermediateDir")!!, info.role + ".clear"))
.copyTo(File(info.role + ".clear"), true)
//@formatter:on
log.info("Unsigned image saved as ${info.role}.clear")
}
}
Helper.setProp("out.file", outputFile)
return this
}
@ -392,14 +356,22 @@ data class BootV3(
val tab = AsciiTable().let {
it.addRule()
it.addRow("image info", shortenPath(Helper.joinPath(workDir!!, info.role.removeSuffix(".img") + ".json")))
prints.add(Pair("image info", shortenPath(Helper.joinPath(workDir, info.role.removeSuffix(".img") + ".json"))))
prints.add(
Pair(
"image info",
shortenPath(Helper.joinPath(workDir, info.role.removeSuffix(".img") + ".json"))
)
)
it.addRule()
if (this.kernel.size > 0) {
it.addRow("kernel", shortenPath(this.kernel.file))
prints.add(Pair("kernel", shortenPath(this.kernel.file)))
File(Helper.joinPath(workDir, Helper.prop("kernelVersionStem")!!)).let { kernelVersionFile ->
if (kernelVersionFile.exists()) {
it.addRow("\\-- version " + kernelVersionFile.readLines().toString(), shortenPath( kernelVersionFile.path))
it.addRow(
"\\-- version " + kernelVersionFile.readLines().toString(),
shortenPath(kernelVersionFile.path)
)
prints.add(
Pair(
"\\-- version " + kernelVersionFile.readLines().toString(),

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,3 +1,17 @@
// Copyright 2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package init
class BootReason {

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2022-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2022-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2022-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -96,7 +96,6 @@ class BootImgParser : IPackable {
fun packInternal(workspace: String, outFileName: String) {
log.info("packInternal($workspace, $outFileName)")
Helper.setProp("workDir", workspace)
val targetFile = outFileName
val iniRole = Common.loadProperties(File(workspace, "workspace.ini").canonicalPath).getProperty("role")
val cfgFile = File(workspace, iniRole.removeSuffix(".img") + ".json").canonicalPath
log.info("Loading config from $cfgFile")
@ -137,61 +136,7 @@ class BootImgParser : IPackable {
is BootV3 -> {
worker
.pack()
.sign(targetFile)
.updateVbmeta()
.printPackSummary(worker.info.role)
}
else -> {
log.error("unsupported boot image format")
exitProcess(2)
}
}
}
fun packInternalLegacy(targetFile: String, workspace: String, fileName: String) {
log.info("packInternal(targetFile: $targetFile, fileName: $fileName, workspace: $workspace)")
Helper.setProp("workDir", workspace)
val cfgFile = Helper.joinPath(outDir, targetFile.removeSuffix(".img") + ".json")
log.info("Loading config from $cfgFile")
if (!File(cfgFile).exists()) {
val tab = AsciiTable().let {
it.addRule()
it.addRow("'$cfgFile' doesn't exist, did you forget to 'unpack' ?")
it.addRule()
it
}
log.info("\n{}", tab.render())
return
}
val worker =
try {
ObjectMapper().readValue(File(cfgFile), BootV2::class.java)
} catch (e: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) {
try {
ObjectMapper().readValue(File(cfgFile), BootV3::class.java)
} catch (e: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) {
null
}
}
if (worker == null) {
log.error("no worker available")
exitProcess(2)
}
when (worker) {
is BootV2 -> {
worker
.pack()
.sign()
.updateVbmeta()
.printPackSummary()
}
is BootV3 -> {
worker
.pack()
.sign(fileName)
.sign(outFileName)
.updateVbmeta()
.printPackSummary(worker.info.role)
}
@ -231,7 +176,7 @@ class BootImgParser : IPackable {
}
override fun `@verify`(fileName: String) {
File(Helper.prop("workDir")!!).let {
File(outDir).let {
if (!it.exists()) {
it.mkdirs()
}

@ -1,3 +1,17 @@
// Copyright 2023-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package packable
import cfig.bootimg.Common

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2022-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2022 yuyezhong@gmail.com
// Copyright 2022-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2019-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2020-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,3 +1,17 @@
// Copyright 2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.fdt
import avb.AVBInfo

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,3 +1,17 @@
// Copyright 2023-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.misc
import cc.cfig.io.Struct

@ -1,3 +1,17 @@
// Copyright 2023-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.sparse
import cfig.helper.Helper

@ -1,3 +1,17 @@
// Copyright 2023-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.sparse
import avb.AVBInfo

@ -1,3 +1,17 @@
// Copyright 2023-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.sparse
import avb.AVBInfo

@ -1,3 +1,17 @@
// Copyright 2023-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rom.sparse
import avb.AVBInfo
@ -139,7 +153,7 @@ data class SparseImage(var info: SparseInfo = SparseInfo()) {
companion object {
private val SPARSE_MAGIC: UInt = 0x3aff26edu
private val log = LoggerFactory.getLogger(SparseImage::class.java)
private val workDir = Helper.prop("workDir")!!
private val workDir get() = Helper.prop("workDir")!!
private val simg2imgBin = "simg2img"
private val img2simgBin = "img2simg"
@ -188,8 +202,8 @@ data class SparseImage(var info: SparseInfo = SparseInfo()) {
log.warn("unsuported image type: ${ret.info.innerFsType}")
}
}
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File("${workDir}/${ret.info.json}"), ret)
File("${workDir}mount").mkdir()
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File(workDir, ret.info.json), ret)
File(workDir, "mount").mkdir()
extractVBMeta(ret.info.pulp)
generateFileContexts()
@ -216,8 +230,9 @@ data class SparseImage(var info: SparseInfo = SparseInfo()) {
private fun extractExt4(fileName: String) {
if (EnvironmentVerifier().has7z) {
val stem = File(fileName).nameWithoutExtension
val outStr = "7z x $fileName -y -o${workDir}$stem".check_output()
File("${workDir}/$stem.log").writeText(outStr)
val outFilePath = Helper.joinPath(workDir, stem)
val outStr = "7z x $fileName -y -o$outFilePath".check_output()
File(workDir, "$stem.log").writeText(outStr)
} else {
log.warn("Please install 7z for ext4 extraction")
}

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2023-2025 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ class SparseImgParser : IPackable {
override fun unpack(fileName: String) {
log.info("unpack(fileName: $fileName)")
unpackInternal(fileName, Helper.prop("workDir")!!)
unpackInternal(fileName, outDir)
}
fun unpackInternal(fileName: String, unpackDir: String) {
@ -59,7 +59,7 @@ class SparseImgParser : IPackable {
override fun pack(fileName: String) {
//TODO("not implemented: refer to https://github.com/cfig/Android_boot_image_editor/issues/133")
packInternal(Helper.prop("workDir")!!, fileName)
packInternal(outDir, fileName)
}
fun packInternal(workspace: String, outFileName: String) {
@ -121,7 +121,6 @@ class SparseImgParser : IPackable {
companion object {
private val workDir = Helper.prop("workDir")
private var outerFsType = "raw"
private var innerFsType = "raw"
}

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2021-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2021-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,3 +1,17 @@
// Copyright 2021-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE")
package cfig.helper

@ -1,3 +1,17 @@
// Copyright 2022-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cfig.helper
import java.io.ByteArrayInputStream

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2021-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -1,3 +1,17 @@
// Copyright 2021-2023 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE")
package cfig.helper

@ -1,3 +1,17 @@
// Copyright 2021-2022 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cfig.helper
import org.apache.commons.exec.CommandLine

@ -1,4 +1,4 @@
// Copyright 2021 yuyezhong@gmail.com
// Copyright 2021-2024 yuyezhong@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

@ -9,9 +9,9 @@ include("aosp:apksigner")
include("aosp:boot_signer")
include("aosp:bouncycastle:bcpkix")
include("aosp:bouncycastle:bcprov")
include("aosp:libavb1.1")
include("aosp:libavb1.2")
include("avbImpl")
//include("aosp:libavb1.1")
//include("aosp:libavb1.2")
//include("avbImpl")
include("helper")
include("lazybox")

@ -1 +1 @@
Subproject commit 012bda615f1c02f16064c30b828f2307f08a6730
Subproject commit b534ff8f20a167682526c248cdf1ddc25dfb3f99

@ -0,0 +1,166 @@
import java.io.File
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
if (args.isEmpty()) {
println("Usage: kotlin copyright_updater.kts <directory_or_file_path>")
return
}
val path = args[0]
val file = File(path)
if (!file.exists()) {
println("Error: Path '$path' does not exist")
return
}
if (file.isFile()) {
updateCopyrightForFile(file)
} else if (file.isDirectory()) {
updateCopyrightForDirectory(file)
}
}
fun updateCopyrightForDirectory(directory: File) {
println("Processing directory: ${directory.absolutePath}")
directory.walkTopDown()
.filter { it.isFile() && isSourceFile(it) }
.forEach { file ->
println("Processing file: ${file.relativeTo(directory)}")
updateCopyrightForFile(file)
}
}
fun updateCopyrightForFile(file: File) {
try {
val (firstCommitYear, lastCommitYear) = getCommitYears(file)
if (firstCommitYear == null || lastCommitYear == null) {
println(" Warning: Could not determine git history for ${file.name}")
return
}
val content = file.readText()
val updatedContent = updateCopyright(content, firstCommitYear, lastCommitYear)
if (content != updatedContent) {
file.writeText(updatedContent)
println(" Updated copyright: $firstCommitYear-$lastCommitYear")
} else {
println(" No changes needed")
}
} catch (e: Exception) {
println(" Error processing ${file.name}: ${e.message}")
}
}
fun isSourceFile(file: File): Boolean {
val sourceExtensions = setOf("kt", "java", "scala", "groovy", "js", "ts", "cpp", "c", "h", "hpp")
return sourceExtensions.contains(file.extension.lowercase())
}
fun getCommitYears(file: File): Pair<Int?, Int?> {
return try {
// Get first commit year
val firstCommitProcess = ProcessBuilder(
"git", "log", "--reverse", "--format=%ci", "--", file.absolutePath
).directory(file.parentFile).start()
val firstCommitOutput = firstCommitProcess.inputStream.bufferedReader().use { it.readText() }
firstCommitProcess.waitFor(10, TimeUnit.SECONDS)
// Get last commit year
val lastCommitProcess = ProcessBuilder(
"git", "log", "-1", "--format=%ci", "--", file.absolutePath
).directory(file.parentFile).start()
val lastCommitOutput = lastCommitProcess.inputStream.bufferedReader().use { it.readText() }
lastCommitProcess.waitFor(10, TimeUnit.SECONDS)
val firstYear = extractYearFromGitDate(firstCommitOutput.lines().firstOrNull() ?: "")
val lastYear = extractYearFromGitDate(lastCommitOutput.lines().firstOrNull() ?: "")
Pair(firstYear, lastYear)
} catch (e: Exception) {
println(" Git command failed: ${e.message}")
Pair(null, null)
}
}
fun extractYearFromGitDate(dateString: String): Int? {
return try {
if (dateString.isBlank()) return null
// Git date format: "2022-03-15 10:30:45 +0000"
val year = dateString.substring(0, 4).toInt()
year
} catch (e: Exception) {
null
}
}
fun updateCopyright(content: String, firstYear: Int, lastYear: Int): String {
val lines = content.lines().toMutableList()
val copyrightLineIndex = findCopyrightLine(lines)
return if (copyrightLineIndex != -1) {
// Update existing copyright
val updatedCopyrightLine = updateExistingCopyright(lines[copyrightLineIndex], firstYear, lastYear)
lines[copyrightLineIndex] = updatedCopyrightLine
lines.joinToString("\n")
} else {
// Add new copyright header
val copyrightHeader = createCopyrightHeader(firstYear, lastYear)
(copyrightHeader + lines).joinToString("\n")
}
}
fun findCopyrightLine(lines: List<String>): Int {
return lines.indexOfFirst { line ->
line.contains("Copyright", ignoreCase = true) &&
line.contains("yuyezhong@gmail.com", ignoreCase = true)
}
}
fun updateExistingCopyright(copyrightLine: String, firstYear: Int, lastYear: Int): String {
val yearRange = if (firstYear == lastYear) {
firstYear.toString()
} else {
"$firstYear-$lastYear"
}
// Replace the year pattern in the existing copyright line
return copyrightLine.replaceFirst(
Regex("""\b\d{4}(-\d{4})?\b"""),
yearRange
)
}
fun createCopyrightHeader(firstYear: Int, lastYear: Int): List<String> {
val yearRange = if (firstYear == lastYear) {
firstYear.toString()
} else {
"$firstYear-$lastYear"
}
return listOf(
"// Copyright $yearRange yuyezhong@gmail.com",
"//",
"// Licensed under the Apache License, Version 2.0 (the \"License\");",
"// you may not use this file except in compliance with the License.",
"// You may obtain a copy of the License at",
"//",
"// http://www.apache.org/licenses/LICENSE-2.0",
"//",
"// Unless required by applicable law or agreed to in writing, software",
"// distributed under the License is distributed on an \"AS IS\" BASIS,",
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"// See the License for the specific language governing permissions and",
"// limitations under the License.",
""
)
}
main(args)
Loading…
Cancel
Save