Skip to content

Commit

Permalink
linux: use android-sdk-libsparse-utils instead of local code copy
Browse files Browse the repository at this point in the history
  • Loading branch information
cfig committed Apr 6, 2023
1 parent 95ee9b6 commit d0dfebd
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
java-version: 17

- name: apt
run: sudo apt install device-tree-compiler p7zip-full
run: sudo apt install device-tree-compiler p7zip-full android-sdk-libsparse-utils

# Runs a single command using the runners shell
- name: Unit Test
Expand Down
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A tool for reverse engineering Android ROM images.
## Requirements
Make sure you have [JDK11+](https://www.oracle.com/java/technologies/downloads/#java17) and [Python3](https://www.python.org/downloads/).

* Linux / WSL: `sudo apt install git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full`
* Linux / WSL: `sudo apt install git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils`

* Mac: `brew install lz4 xz dtc`

Expand Down Expand Up @@ -60,23 +60,11 @@ Well done you did it! The last step is to star this repo :smile
| recovery | recovery.img, recovery-two-step.img | all | |
| vbmeta | vbmeta.img, vbmeta_system.img etc. | all | |
| dtbo | dtbo.img | linux & mac | |
| sparse images | system.img, vendor.img, product.img etc.| linux & mac | need **hacking mode**\* |
| sparse images | system.img, vendor.img, product.img etc.| linux | |
| OTA payload | payload.bin | all | Windows git-bash |

Please note that the boot.img MUST follows AOSP verified boot flow, either [Boot image signature](https://source.android.com/security/verifiedboot/verified-boot#signature_format) in VBoot 1.0 or [AVB HASH footer](https://android.googlesource.com/platform/external/avb/+/master/README.md#The-VBMeta-struct) (a.k.a. AVB) in VBoot 2.0.

**hacking mode**\*:

Open build.gradle.kts, Line #8, change
```
val bHackingMode = false
```
to
```
val bHackingMode = true
```
This will enable c++ modules, which is necessary for working with sparse images.

## compatible devices

| Device Model | Manufacturer | Compatible | Android Version | Note |
Expand Down Expand Up @@ -199,7 +187,6 @@ cp <your_dtb> build/unzip_boot/dtb
<details>
<summary>working with system.img</summary>

First enable **hacking mode** by setting `bHackingMode = true` in file `build.gradle.kts`, then
```bash
cp <your_system_image> system.img
./gradlew unpack
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation("org.bouncycastle:bcprov-jdk15on:1.70")
implementation("de.vandermeer:asciitable:0.3.2")
implementation("com.github.freva:ascii-table:1.8.0")
implementation("com.google.protobuf:protobuf-java:3.21.1")
implementation("com.google.protobuf:protobuf-java:3.21.7")
implementation(project(":helper"))

testImplementation("org.jetbrains.kotlin:kotlin-test")
Expand Down
10 changes: 2 additions & 8 deletions bbootimg/src/main/kotlin/utils/SparseImgParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ class SparseImgParser : IPackable {
override val loopNo: Int
get() = 0
private val log = LoggerFactory.getLogger(SparseImgParser::class.java)
private val simg2imgBin: String
private val img2simgBin: String

init {
val osSuffix = if (EnvironmentVerifier().isMacOS) "macos" else "linux"
simg2imgBin = "./aosp/libsparse/simg2img/build/install/main/release/$osSuffix/simg2img"
img2simgBin = "./aosp/libsparse/img2simg/build/install/main/release/$osSuffix/img2simg"
}
private val simg2imgBin = "simg2img"
private val img2simgBin = "img2simg"

override fun capabilities(): List<String> {
return listOf(
Expand Down
30 changes: 0 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.apache.commons.exec.DefaultExecutor
import org.apache.commons.exec.PumpStreamHandler

val GROUP_ANDROID = "android"
val bHackingMode = false
if (parseGradleVersion(gradle.gradleVersion) < 6) {
logger.error("ERROR: Gradle Version MUST >= 6.0, current is {}", gradle.gradleVersion)
throw RuntimeException("ERROR: Gradle Version")
Expand Down Expand Up @@ -82,35 +81,6 @@ tasks {
args("clear")
}
clearTask.dependsOn("bbootimg:jar")

//sparse image dependencies
if (bHackingMode) {
logger.info("Hacking mode!")
//C++ mkbootfs
if (System.getProperty("os.name").contains("Mac")) {
//mac
unpackTask.dependsOn("aosp:libsparse:simg2img:installReleaseMacos")
packTask.dependsOn("aosp:libsparse:img2simg:installReleaseMacos")
// common
packTask.dependsOn("aosp:mkbootfs.10:mkbootfsExecutable")
packTask.dependsOn("aosp:mkbootfs.11:mkbootfsExecutable")
unpackTask.dependsOn("aosp:mkbootfs.10:mkbootfsExecutable")
unpackTask.dependsOn("aosp:mkbootfs.11:mkbootfsExecutable")
} else if (System.getProperty("os.name").contains("Linux")) {
//linux
unpackTask.dependsOn("aosp:libsparse:simg2img:installReleaseLinux")
packTask.dependsOn("aosp:libsparse:img2simg:installReleaseLinux")
// common
packTask.dependsOn("aosp:mkbootfs.10:mkbootfsExecutable")
packTask.dependsOn("aosp:mkbootfs.11:mkbootfsExecutable")
unpackTask.dependsOn("aosp:mkbootfs.10:mkbootfsExecutable")
unpackTask.dependsOn("aosp:mkbootfs.11:mkbootfsExecutable")
} else {
logger.info("Disable C++ modules on Window$")
}
} else {
logger.info("Release mode")
}
}

fun parseGradleVersion(version: String): Int {
Expand Down
3 changes: 3 additions & 0 deletions helper/src/main/kotlin/cfig/helper/ZipHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ class ZipHelper {
val baosE = ByteArrayOutputStream()
DefaultExecutor().let { exec ->
exec.streamHandler = PumpStreamHandler(fos, baosE, inputStream)
// -l: compress using Legacy format (Linux kernel compression)
// -12: --best
// --favor-decSpeed: compressed files decompress faster, but are less compressed
val cmd = CommandLine.parse("${getLz4Prog()} -l -12")
if ("${getLz4Prog()} --version".check_output().contains("r\\d+,".toRegex())) {
log.warn("lz4 version obsolete, needs update")
Expand Down
8 changes: 0 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
rootProject.name = "boot"
include("bbootimg")
include("aosp:boot_signer")
include("aosp:mkbootfs.10")
include("aosp:mkbootfs.11")
include("aosp:libsparse:base")
include("aosp:libsparse:sparse")
include("aosp:libsparse:img2simg")
include("aosp:libsparse:simg2img")
include("aosp:libsparse:simg2simg")
include("aosp:libsparse:append2simg")
include("aosp:libavb1.1")
include("aosp:libavb1.2")
include("avbImpl")
Expand Down

0 comments on commit d0dfebd

Please sign in to comment.