-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c3897be
Showing
6 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/libs | ||
/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 LibXZR | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# vbmeta-disable-verification | ||
|
||
Patch Android vbmeta image and disable verification flags inside. | ||
|
||
## Usage | ||
|
||
Get prebuilts from [releases](https://github.com/libxzr/vbmeta-disable-verification/releases). | ||
|
||
``` | ||
$ ./vbmeta-disable-verification vbmeta.img | ||
Successfully disabled verification on the provided vbmeta image. | ||
``` | ||
|
||
Give it a vbmeta image and then verification will be disabled on it. | ||
|
||
This should be equal to `fastboot --disable-verity --disable-verification flash vbmeta vbmeta.img`. The only difference is that it directly patch the image file. Fastboot doesn't provide the ability to generate an image with verification disabled, but sometimes I need it :) . | ||
|
||
## Building | ||
|
||
It's easy to build it with [Android NDK](https://developer.android.com/ndk). | ||
|
||
``` | ||
$ export PATH="/path/to/your/ndk:${PATH}" | ||
$ git clone https://github.com/libxzr/vbmeta-disable-verification | ||
...... | ||
$ cd vbmeta-disable-verification | ||
$ ndk-build | ||
...... | ||
$ tree libs | ||
libs | ||
├── arm64-v8a | ||
│ └── vbmeta-disable-verification | ||
├── armeabi-v7a | ||
│ └── vbmeta-disable-verification | ||
├── x86 | ||
│ └── vbmeta-disable-verification | ||
└── x86_64 | ||
└── vbmeta-disable-verification | ||
``` | ||
|
||
## References | ||
|
||
- [libavb](https://android.googlesource.com/platform/external/avb/+/refs/tags/android-13.0.0_r15/libavb/avb_vbmeta_image.h) | ||
- [fastboot](https://android.googlesource.com/platform/system/core/+/refs/tags/android-13.0.0_r15/fastboot/fastboot.cpp) | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := vbmeta-disable-verification | ||
LOCAL_SRC_FILES := main.c | ||
LOCAL_LDFLAGS := -static | ||
include $(BUILD_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APP_ABI := all | ||
APP_PLATFORM := android-33 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
/* Magic for the vbmeta image header. */ | ||
#define AVB_MAGIC "AVB0" | ||
#define AVB_MAGIC_LEN 4 | ||
|
||
/* Information about the verification flags */ | ||
#define FLAGS_OFFSET 123 | ||
#define FLAG_DISABLE_VERITY 0x01 | ||
#define FLAG_DISABLE_VERIFICATION 0x02 | ||
|
||
static void help() | ||
{ | ||
printf("vbmeta-disable-verify by LibXZR <i@xzr.moe>\n"); | ||
printf("Usage:\n vbmeta-disable-verify <vbmeta-image>\n"); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int fd; | ||
char magic[AVB_MAGIC_LEN] = {0}; | ||
char buf; | ||
|
||
argc--; | ||
argv++; | ||
|
||
if (argc != 1) { | ||
help(); | ||
return 0; | ||
} | ||
|
||
fd = open(*argv, O_RDWR); | ||
if (fd < 0) { | ||
printf("Error: Unable to access the provided vbmeta image.\n"); | ||
return 1; | ||
} | ||
|
||
read(fd, magic, AVB_MAGIC_LEN); | ||
if (strncmp(magic, AVB_MAGIC, AVB_MAGIC_LEN)) { | ||
printf("Error: The provided image is not a valid vbmeta image.\n"); | ||
goto error_cleanup; | ||
} | ||
|
||
if (lseek(fd, FLAGS_OFFSET, SEEK_SET) != FLAGS_OFFSET) | ||
goto error_patching; | ||
if (read(fd, &buf, 1) != 1) | ||
goto error_patching; | ||
buf |= FLAG_DISABLE_VERITY | FLAG_DISABLE_VERIFICATION; | ||
if (lseek(fd, FLAGS_OFFSET, SEEK_SET) != FLAGS_OFFSET) | ||
goto error_patching; | ||
if (write(fd, &buf, 1) != 1) | ||
goto error_patching; | ||
|
||
printf("Successfully disabled verification on the provided vbmeta image.\n"); | ||
close(fd); | ||
return 0; | ||
|
||
error_patching: | ||
printf("Error: Failed when patching the vbmeta image\n"); | ||
error_cleanup: | ||
close(fd); | ||
return 1; | ||
} |