Development [DEV] Hashtree Patcher

Search This thread

capntrips

Senior Member
Aug 29, 2020
212
401
OnePlus 6T
Google Pixel 6
Hashtree Patcher is an Android command-line tool that patches vendor_dlkm.img and vbmeta.img for booting without disabling verity.

For background on the issue, see here, but the bottom line is when installing a custom kernel on Magisk 24303+, verity enabled devices have to patch vendor_dlkm and vbmeta.

Hashtree Patcher has now been integrated with AK3, so there should no longer be any need to run this tool manually.

To use this tool, take the vbmeta from your ROM and the vendor_dlkm from your kernel and perform the following steps:

Code:
adb push httools /data/local/tmp
adb push fec /data/local/tmp
adb push vendor_dlkm.img /data/local/tmp
adb push vbmeta.img /data/local/tmp
adb shell
cd /data/local/tmp
chmod +x httools
chmod +x fec
./httools patch vendor_dlkm.img vbmeta.img
exit
adb pull /data/local/tmp/vendor_dlkm.img vendor_dlkm-patched.img
adb pull /data/local/tmp/vbmeta.img vbmeta-patched.img

Then flash your kernel using the method of your choice followed immediately by flashing the patched vbmeta and vendor_dlkm images acquired above:

Code:
fastboot flash vbmeta vbmeta-patched.img
fastboot reboot fastboot
fastboot flash vendor_dlkm vendor_dlkm-patched.img

Notes

You can acquire the fec binary here.

Latest Update

2022-06-09 v2.0.0
 
Last edited:

swieder711

Senior Member
Thanks for moving this work to a new thread. I am starting over to make sure I have all the right files.

Trying to install Kiri 2.4-stable with Magisk Canary (currently 24313).

Grabbed vbmeta.img from Raven May sources.
Grabbed vendor_dlkm.img from Kiri 2.4-stable kernel
Renamed fec-arm64 to fec
Put everything on my phone.
Fixed permissions with Chmod
Ran hashtreepatcher-alpha2

raven:/data/local/tmp # ./hashtreepatcher vendor_dlkm.img vbmeta.img
- Patching complete
Hashtree descriptor:
Image Size: 44224512 bytes
Tree Offset: 44224512
Tree Size: 352256 bytes
Data Block Size: 4096 bytes
Hash Block Size: 4096 bytes
FEC num roots: 2
FEC offset: 44576768
FEC size: 360448 bytes
Hash Algorithm: sha256
Partition Name: vendor_dlkm
Salt: dcfdb868e3aef90f102187d66b9cd2c71589a8b0f0035387940a2ca364d8cd05
Root Digest: 6dd4ee4ec76f02c778d56c5d43a08cdb8fb20f8db3b0ee3d04bf1728c6627b06
Flags: 0

Flashed Kiri kernel via FKM. (verified AK3 helper module installed in Magisk)
Reboot to Fastboot


fastboot flash vbmeta vbmeta-patched.img
fastboot reboot fastboot
fastboot flash vendor_dlkm vendor_dlkm-patched.img

Reboot

SUCCESS!!!!
 
Last edited:

capntrips

Senior Member
Aug 29, 2020
212
401
OnePlus 6T
Google Pixel 6
I have been using a Pixel 5a as my daily driver, since I had been doing frequent flashes and wipes while working on the verity stuff with Magisk 24303+, so I can't comment on the Pixel 6, currently, but none of my apps detect root on the latest canary on the 5a. Since I'm happy with this solution, I'm planning to move back to a Pixel 6 this weekend. I am only using the safetynet-fix module.
 
  • Like
Reactions: swieder711

Freak07

Recognized Developer / Recognized Contributor
Jan 2, 2011
5,586
18,583
Well that fun was short lived. My work apps (Outlook, Teams, etc) are now detecting that my phone is rooted.

Im back on the stock kernel with Magisk Canary and root is not detected.

Odd that the works apps dont detect Root on my other Android device that is running Magisk stable.
Did you use the 2.4.0 kernel.zip from the "official" release post or from the other post I pointed you to?
 

swieder711

Senior Member
Yes. I'm pretty sure it will work with the other zip.
Trying it now and will report back.

EDIT: YEAH! Using the fixed 2.4 kernel is working. The apps are no longer detecting root when running Magisk Canary and your kernel @Freak07 Oh Happy Days.
 
Last edited:

bobbarker2

Senior Member
Aug 30, 2013
1,574
570
Google Pixel 6 Pro
Google Pixel 6
Code:
adb push hashtreepatcher /data/local/tmp
adb push fec /data/local/tmp
adb push vendor_dlkm.img /data/local/tmp
adb push vbmeta.img /data/local/tmp
adb shell
cd /data/local/tmp
chmod +x hashtreepatcher
chmod +x fec
./hashtreepatcher vendor_dlkm.img vbmeta.img
exit
adb pull /data/local/tmp/vendor_dlkm.img vendor_dlkm-patched.img
adb pull /data/local/tmp/vbmeta.img vbmeta-patched.img


Latest Update

2022-05-25 v1.0.0-alpha02
Huge thank you for this. I've only one time been able to use a custom kernel on Stock+Magisk, always had Device Corrupt/Bootloops. Now using Hashtreepatcher, I was able to successfully flash Kiri kernel. Can confirm its working with current Magisk Canary v24315. Bank apps/GPay still work, didn't even need to reset data on Play Services, Play Store etc.

Just wanted to add that for v1.0.0-alpha02 of hashtreepatcher the line:

./hashtreepatcher vendor_dlkm.img vbmeta.img

should be:

./hashtreepatcher patch vendor_dlkm.img vbmeta.img

Code:
1|oriole:/data/local/tmp $ ./hashtreepatcher vendor_dlkm.img vbmeta.img
./hashtreepatcher <avb|disable-flags|patch>
1|oriole:/data/local/tmp $ ./hashtreepatcher patch vendor_dlkm.img vbmeta.img
- Patching complete
    Hashtree descriptor:
    Image Size:            44224512 bytes
    Tree Offset:           44224512
    Tree Size:             352256 bytes
    Data Block Size:       4096 bytes
    Hash Block Size:       4096 bytes
    FEC num roots:         2
    FEC offset:            44576768
    FEC size:              360448 bytes
    Hash Algorithm:        sha256
    Partition Name:        vendor_dlkm
    Salt:                  51193cce3e801498112759c99b294f47c816f97e383bf193c2397c465ac5f3b
    Root Digest:           84091e9b829aa6fadeb80599e4d78bcbcef0353ce72nn432f5c05f7125n05cf6
    Flags:                 0
 
  • Like
Reactions: capntrips

capntrips

Senior Member
Aug 29, 2020
212
401
OnePlus 6T
Google Pixel 6
Just wanted to add that for v1.0.0-alpha02 of hashtreepatcher the line:

./hashtreepatcher vendor_dlkm.img vbmeta.img

should be:

./hashtreepatcher patch vendor_dlkm.img vbmeta.img
I'm working on getting it added to AK3, so the API will slightly change in 2.0, as I needed to add methods to check if patching is even necessary. I don't anticipate it changing from the current state of the feature branch, but I didn't want to document it here until it was stable. Thanks for noting it, in case anyone else comes along in the interim.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Just wanted to add that for v1.0.0-alpha02 of hashtreepatcher the line:

    ./hashtreepatcher vendor_dlkm.img vbmeta.img

    should be:

    ./hashtreepatcher patch vendor_dlkm.img vbmeta.img
    I'm working on getting it added to AK3, so the API will slightly change in 2.0, as I needed to add methods to check if patching is even necessary. I don't anticipate it changing from the current state of the feature branch, but I didn't want to document it here until it was stable. Thanks for noting it, in case anyone else comes along in the interim.
    1
    Code:
    adb push hashtreepatcher /data/local/tmp
    adb push fec /data/local/tmp
    adb push vendor_dlkm.img /data/local/tmp
    adb push vbmeta.img /data/local/tmp
    adb shell
    cd /data/local/tmp
    chmod +x hashtreepatcher
    chmod +x fec
    ./hashtreepatcher vendor_dlkm.img vbmeta.img
    exit
    adb pull /data/local/tmp/vendor_dlkm.img vendor_dlkm-patched.img
    adb pull /data/local/tmp/vbmeta.img vbmeta-patched.img


    Latest Update

    2022-05-25 v1.0.0-alpha02
    Huge thank you for this. I've only one time been able to use a custom kernel on Stock+Magisk, always had Device Corrupt/Bootloops. Now using Hashtreepatcher, I was able to successfully flash Kiri kernel. Can confirm its working with current Magisk Canary v24315. Bank apps/GPay still work, didn't even need to reset data on Play Services, Play Store etc.

    Just wanted to add that for v1.0.0-alpha02 of hashtreepatcher the line:

    ./hashtreepatcher vendor_dlkm.img vbmeta.img

    should be:

    ./hashtreepatcher patch vendor_dlkm.img vbmeta.img

    Code:
    1|oriole:/data/local/tmp $ ./hashtreepatcher vendor_dlkm.img vbmeta.img
    ./hashtreepatcher <avb|disable-flags|patch>
    1|oriole:/data/local/tmp $ ./hashtreepatcher patch vendor_dlkm.img vbmeta.img
    - Patching complete
        Hashtree descriptor:
        Image Size:            44224512 bytes
        Tree Offset:           44224512
        Tree Size:             352256 bytes
        Data Block Size:       4096 bytes
        Hash Block Size:       4096 bytes
        FEC num roots:         2
        FEC offset:            44576768
        FEC size:              360448 bytes
        Hash Algorithm:        sha256
        Partition Name:        vendor_dlkm
        Salt:                  51193cce3e801498112759c99b294f47c816f97e383bf193c2397c465ac5f3b
        Root Digest:           84091e9b829aa6fadeb80599e4d78bcbcef0353ce72nn432f5c05f7125n05cf6
        Flags:                 0
    1
    This officially landed in AK3, so I pushed a final v2.0.0. I updated the instructions in the OP, but there should now be little need to run it manually.
    1
    Thank you for this!
  • 9
    Hashtree Patcher is an Android command-line tool that patches vendor_dlkm.img and vbmeta.img for booting without disabling verity.

    For background on the issue, see here, but the bottom line is when installing a custom kernel on Magisk 24303+, verity enabled devices have to patch vendor_dlkm and vbmeta.

    Hashtree Patcher has now been integrated with AK3, so there should no longer be any need to run this tool manually.

    To use this tool, take the vbmeta from your ROM and the vendor_dlkm from your kernel and perform the following steps:

    Code:
    adb push httools /data/local/tmp
    adb push fec /data/local/tmp
    adb push vendor_dlkm.img /data/local/tmp
    adb push vbmeta.img /data/local/tmp
    adb shell
    cd /data/local/tmp
    chmod +x httools
    chmod +x fec
    ./httools patch vendor_dlkm.img vbmeta.img
    exit
    adb pull /data/local/tmp/vendor_dlkm.img vendor_dlkm-patched.img
    adb pull /data/local/tmp/vbmeta.img vbmeta-patched.img

    Then flash your kernel using the method of your choice followed immediately by flashing the patched vbmeta and vendor_dlkm images acquired above:

    Code:
    fastboot flash vbmeta vbmeta-patched.img
    fastboot reboot fastboot
    fastboot flash vendor_dlkm vendor_dlkm-patched.img

    Notes

    You can acquire the fec binary here.

    Latest Update

    2022-06-09 v2.0.0
    5
    Thanks for moving this work to a new thread. I am starting over to make sure I have all the right files.

    Trying to install Kiri 2.4-stable with Magisk Canary (currently 24313).

    Grabbed vbmeta.img from Raven May sources.
    Grabbed vendor_dlkm.img from Kiri 2.4-stable kernel
    Renamed fec-arm64 to fec
    Put everything on my phone.
    Fixed permissions with Chmod
    Ran hashtreepatcher-alpha2

    raven:/data/local/tmp # ./hashtreepatcher vendor_dlkm.img vbmeta.img
    - Patching complete
    Hashtree descriptor:
    Image Size: 44224512 bytes
    Tree Offset: 44224512
    Tree Size: 352256 bytes
    Data Block Size: 4096 bytes
    Hash Block Size: 4096 bytes
    FEC num roots: 2
    FEC offset: 44576768
    FEC size: 360448 bytes
    Hash Algorithm: sha256
    Partition Name: vendor_dlkm
    Salt: dcfdb868e3aef90f102187d66b9cd2c71589a8b0f0035387940a2ca364d8cd05
    Root Digest: 6dd4ee4ec76f02c778d56c5d43a08cdb8fb20f8db3b0ee3d04bf1728c6627b06
    Flags: 0

    Flashed Kiri kernel via FKM. (verified AK3 helper module installed in Magisk)
    Reboot to Fastboot


    fastboot flash vbmeta vbmeta-patched.img
    fastboot reboot fastboot
    fastboot flash vendor_dlkm vendor_dlkm-patched.img

    Reboot

    SUCCESS!!!!
    4
    Yes. I'm pretty sure it will work with the other zip.
    Trying it now and will report back.

    EDIT: YEAH! Using the fixed 2.4 kernel is working. The apps are no longer detecting root when running Magisk Canary and your kernel @Freak07 Oh Happy Days.
    2
    I used the official 2.4

    Do you think my setup might work better with the other version?
    Yes. I'm pretty sure it will work with the other zip.
    2
    Just wanted to add that for v1.0.0-alpha02 of hashtreepatcher the line:

    ./hashtreepatcher vendor_dlkm.img vbmeta.img

    should be:

    ./hashtreepatcher patch vendor_dlkm.img vbmeta.img
    I'm working on getting it added to AK3, so the API will slightly change in 2.0, as I needed to add methods to check if patching is even necessary. I don't anticipate it changing from the current state of the feature branch, but I didn't want to document it here until it was stable. Thanks for noting it, in case anyone else comes along in the interim.