cfig / Android_boot_image_editor

Parsing and re-packing Android boot.img/vbmeta.img/payload.bin, supporting Android 15
Apache License 2.0
995 stars 227 forks source link

unknown issue #119

Closed 99degree closed 1 year ago

99degree commented 1 year ago

remote: Enumerating objects: 82, done. remote: Counting objects: 100% (75/75), done. remote: Compressing objects: 100% (8/8), done. remote: Total 22 (delta 10), reused 22 (delta 10), pack-reused 0 Unpacking objects: 100% (22/22), 3.34 KiB | 59.00 KiB/s, done. From https://github.com/cfig/Android_boot_image_editor 95ee9b6..d0dfebd master -> origin/master Updating 95ee9b6..d0dfebd Fast-forward .github/workflows/main.yml | 2 +- README.md | 17 ++--------------- bbootimg/build.gradle.kts | 2 +- bbootimg/src/main/kotlin/utils/SparseImgParser.kt | 10 ++-------- build.gradle.kts | 30 ------------------------------ helper/src/main/kotlin/cfig/helper/ZipHelper.kt | 3 +++ settings.gradle.kts | 8 -------- 7 files changed, 9 insertions(+), 63 deletions(-) root@LAPTOP:~/source/Android_boot_image_editor# adb pull /dev/block/by-name/boot /dev/block/by-name/boot: 1 file pulled, 0 skipped. 34.6 MB/s (134217728 bytes in 3.697s) root@LAPTOP:~/source/Android_boot_image_editor# mv boot boot.img root@LAPTOP boot.zip :~/source/Android_boot_image_editor# ./gradlew unpack Starting a Gradle Daemon (subsequent builds will be faster)

Task :bbootimg:compileKotlin w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/avb/desc/HashDescriptor.kt:88:43 Parameter 'parent' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt:246:17 Variable 'ai' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/init/BootReason.kt:8:66 Parameter 'subReason' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/init/BootReason.kt:8:86 Parameter 'detail' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/ota/Payload.kt:123:41 Parameter 'sig_data' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/ota/Payload.kt:123:63 Parameter 'pubkey' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/ota/Payload.kt:123:79 Parameter 'sigHash' is never used w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/ota/PayloadGenerator.kt:172:30 Unchecked cast: Pair<String, String?> to Pair<String, String> w: file:///root/source/Android_boot_image_editor/bbootimg/src/main/kotlin/packable/PayloadBinParser.kt:47:15 Parameter 'fileName' is never used

Task :unpack 01:50:23.531 [main] WARN cfig.packable.PackableLauncher - [boot.img] will be handled by [BootImgParser] 01:50:23.792 [main] WARN cfig.packable.PackableLauncher - 'unpack' sequence initialized 01:50:23.807 [main] INFO cfig.packable.IPackable - deleting build/unzip_boot/ ... 01:50:23.907 [main] INFO Helper - deleting uiderrors 01:50:23.928 [main] INFO cfig.packable.BootImgParser - header version 2 01:50:24.213 [main] WARN cfig.bootimg.v2.BootHeaderV2 - BootImgHeader constructor 01:50:24.298 [main] INFO cfig.Avb - python aosp/avb/avbtool.v1.2.py verify_image --image boot.img 01:50:24.454 [main] ERROR cfig.Avb - boot.img failed integrity check by "python aosp/avb/avbtool.v1.2.py verify_image --image boot.img" /usr/bin/env: ‘python’: No such file or directory 01:50:24.896 [main] WARN KernelExtractor - can not parse kernel info 01:50:24.958 [main] INFO ZipHelper - decompress(gz) done: build/unzip_boot/ramdisk.img.gz -> build/unzip_boot/ramdisk.img 01:50:24.962 [main] INFO cfig.bootimg.cpio.AndroidCpio - Cleaning /root/source/Android_boot_image_editor/build/unzip_boot/root ... 01:50:25.053 [main] INFO cfig.bootimg.cpio.AndroidCpio - cpio trailer found, mode=000001ed 01:50:25.056 [main] INFO cfig.bootimg.Common - ramdisk extracted : build/unzip_boot/ramdisk.img -> build/unzip_boot/root 01:50:25.065 [main] INFO cfig.utils.DTC - parsing DTB: build/unzip_boot/dtb 01:50:25.193 [main] INFO cfig.utils.DTC - [dtc, -q, -I, dtb, -O, dts, build/unzip_boot/dtb, -o, build/unzip_boot/dtb.dts] 01:50:25.497 [main] INFO cfig.utils.DTC - [dtc, -q, -I, dts, -O, yaml, build/unzip_boot/dtb.dts, -o, build/unzip_boot/dtb.dts.yaml] 01:50:25.504 [main] INFO avb.AVBInfo - parseFrom(FILE:boot.img) ... Exception in thread "main" 01:50:25.620 [main] INFO avb.AVBInfo - FILE:boot.img: Glance(footer=Footer(versionMajor=1, versionMinor=0, originalImageSize=48115712, vbMetaOffset=48115712, vbMetaSize=704), vbMetaOffset=48115712).footer java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:113) at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108) at cfig.packable.PackableLauncherKt.main(PackableLauncher.kt:108) Caused by: java.lang.IllegalArgumentException: stream doesn't look like valid VBMeta Header at avb.blob.Header.(Header.kt:47) at avb.blob.Header.(Header.kt:71) at avb.AVBInfo$Companion.parseFrom(AVBInfo.kt:113) at cfig.bootimg.v2.BootV2.extractVBMeta(BootV2.kt:231) at cfig.packable.BootImgParser.unpack(BootImgParser.kt:47) ... 8 more

Task :unpack FAILED

FAILURE: Build failed with an exception.

BUILD FAILED in 3m 34s 10 actionable tasks: 8 executed, 2 up-to-date

99degree commented 1 year ago

boot.zip

cfig commented 1 year ago

Some checking fails when trying to parse AVB info from image:

17:33:50.693 [main] INFO  cfig.Avb - python aosp/avb/avbtool.v1.2.py verify_image --image boot.img
aosp/avb/avbtool.v1.2.py: Given image does not look like a vbmeta image.

You can quickly bypass the error by simply comment out the following line:

diff --git a/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt b/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt
index ca49556..46a0ddb 100644
--- a/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt
+++ b/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt
@@ -228,7 +228,7 @@ data class BootV2(

     fun extractVBMeta(): BootV2 {
         if (this.info.verify.startsWith("VB2.0")) {
-            AVBInfo.parseFrom(Dumpling(info.output)).dumpDefault(info.output)
+            //AVBInfo.parseFrom(Dumpling(info.output)).dumpDefault(info.output)
             if (File("vbmeta.img").exists()) {
                 log.warn("Found vbmeta.img, parsing ...")
                 VBMetaParser().unpack("vbmeta.img")

I will check the details a little later

99degree commented 1 year ago

nice let me try this out.

just some background info. the boot.img is directly adb pull /dev/block/by-name/boot the resulting boot.img is not original los but highly possibly concat by modified los boot.img (by this editor) w/ some sparse remaining from previous(? many times before) flashed data such that it might get mis-interpeted.

hope this might help understood this situation better. so there might be a chance to chop the boot.img from the big bin.img itself before process.

cfig commented 1 year ago

It seems the "vbmeta metadata" part of the "boot.img" is broken. If I did some tricks in the the ending area of the image, by erasing the last 1024bytes, which has "AVB footer", the tool can parse the boot.img, without any "vbmeta metada".

mv boot.img boot.img.orig
dd if=boot.img.orig of=boot.img bs=1024 count=131071
./gradlew unpack

So it would help if you have the original correct boot.img to do parsing.

99degree commented 1 year ago

nice. let me close this issue.