Refactor dtb in rust

This commit is contained in:
LoveSy
2023-09-19 00:12:49 -07:00
committed by John Wu
parent 8e1a91509c
commit 8d7c7c3dfb
14 changed files with 403 additions and 626 deletions
+10 -4
View File
@@ -3,11 +3,14 @@
pub use base;
use cpio::cpio_commands;
use patch::{hexpatch, patch_encryption, patch_verity};
use dtb::dtb_commands;
use patch::hexpatch;
use payload::extract_boot_from_payload;
use sign::{get_sha, sha1_hash, sha256_hash, sign_boot_image, verify_boot_image, SHA};
use std::env;
mod cpio;
mod dtb;
mod patch;
mod payload;
// Suppress warnings in generated code
@@ -41,8 +44,6 @@ pub mod ffi {
fn sha256_hash(data: &[u8], out: &mut [u8]);
fn hexpatch(file: &[u8], from: &[u8], to: &[u8]) -> bool;
fn patch_encryption(buf: &mut [u8]) -> usize;
fn patch_verity(buf: &mut [u8]) -> usize;
}
#[namespace = "rust"]
@@ -52,7 +53,6 @@ pub mod ffi {
in_path: *const c_char,
out_path: *const c_char,
) -> bool;
unsafe fn cpio_commands(argc: i32, argv: *const *const c_char) -> bool;
unsafe fn verify_boot_image(img: &BootImage, cert: *const c_char) -> bool;
unsafe fn sign_boot_image(
@@ -61,5 +61,11 @@ pub mod ffi {
cert: *const c_char,
key: *const c_char,
) -> Vec<u8>;
unsafe fn dtb_commands(argc: i32, argv: *const *const c_char) -> bool;
}
}
#[inline(always)]
pub(crate) fn check_env(env: &str) -> bool {
env::var(env).map_or(false, |var| var == "true")
}