2022-12-13 03:33:16 +00:00
|
|
|
#![feature(format_args_nl)]
|
2023-06-09 13:43:26 +00:00
|
|
|
#![feature(btree_drain_filter)]
|
2022-12-13 03:33:16 +00:00
|
|
|
|
2022-07-01 11:53:41 +00:00
|
|
|
pub use base;
|
2023-06-22 09:23:27 +00:00
|
|
|
use cpio::cpio_commands;
|
|
|
|
use patch::{hexpatch, patch_encryption, patch_verity};
|
|
|
|
use payload::extract_boot_from_payload;
|
2023-08-08 07:57:58 +00:00
|
|
|
use sign::{get_sha, sha1_hash, sha256_hash, sign_boot_image, verify_boot_image, SHA};
|
2023-05-05 01:49:33 +00:00
|
|
|
|
2023-06-09 13:43:26 +00:00
|
|
|
mod cpio;
|
2023-06-21 01:17:26 +00:00
|
|
|
mod patch;
|
2023-05-05 01:49:33 +00:00
|
|
|
mod payload;
|
2023-06-20 21:29:09 +00:00
|
|
|
// Suppress warnings in generated code
|
|
|
|
#[allow(warnings)]
|
2023-06-20 16:22:48 +00:00
|
|
|
mod proto;
|
2023-06-09 13:43:26 +00:00
|
|
|
mod ramdisk;
|
2023-07-18 01:57:50 +00:00
|
|
|
mod sign;
|
2022-12-13 03:33:16 +00:00
|
|
|
|
2023-05-20 08:28:10 +00:00
|
|
|
#[cxx::bridge]
|
2023-05-05 01:49:33 +00:00
|
|
|
pub mod ffi {
|
2023-05-26 06:45:38 +00:00
|
|
|
unsafe extern "C++" {
|
2023-05-19 22:16:54 +00:00
|
|
|
include!("compress.hpp");
|
2023-05-26 06:45:38 +00:00
|
|
|
fn decompress(buf: &[u8], fd: i32) -> bool;
|
2023-07-18 01:57:50 +00:00
|
|
|
|
|
|
|
include!("bootimg.hpp");
|
|
|
|
#[rust_name = "BootImage"]
|
|
|
|
type boot_img;
|
|
|
|
#[rust_name = "payload"]
|
|
|
|
fn get_payload(self: &BootImage) -> &[u8];
|
|
|
|
#[rust_name = "tail"]
|
|
|
|
fn get_tail(self: &BootImage) -> &[u8];
|
2022-12-13 03:33:16 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 09:23:27 +00:00
|
|
|
extern "Rust" {
|
2023-06-30 22:50:52 +00:00
|
|
|
type SHA;
|
|
|
|
fn get_sha(use_sha1: bool) -> Box<SHA>;
|
|
|
|
fn update(self: &mut SHA, data: &[u8]);
|
|
|
|
fn finalize_into(self: &mut SHA, out: &mut [u8]);
|
|
|
|
fn output_size(self: &SHA) -> usize;
|
|
|
|
fn sha1_hash(data: &[u8], out: &mut [u8]);
|
|
|
|
fn sha256_hash(data: &[u8], out: &mut [u8]);
|
|
|
|
|
2023-06-22 09:23:27 +00:00
|
|
|
fn hexpatch(file: &[u8], from: &[u8], to: &[u8]) -> bool;
|
|
|
|
fn patch_encryption(buf: &mut [u8]) -> usize;
|
|
|
|
fn patch_verity(buf: &mut [u8]) -> usize;
|
|
|
|
}
|
|
|
|
|
2023-05-20 08:28:10 +00:00
|
|
|
#[namespace = "rust"]
|
2022-12-13 03:33:16 +00:00
|
|
|
extern "Rust" {
|
|
|
|
unsafe fn extract_boot_from_payload(
|
2023-05-26 06:45:38 +00:00
|
|
|
partition: *const c_char,
|
2022-12-13 03:33:16 +00:00
|
|
|
in_path: *const c_char,
|
|
|
|
out_path: *const c_char,
|
|
|
|
) -> bool;
|
2023-06-09 13:43:26 +00:00
|
|
|
|
|
|
|
unsafe fn cpio_commands(argc: i32, argv: *const *const c_char) -> bool;
|
2023-07-18 01:57:50 +00:00
|
|
|
unsafe fn verify_boot_image(img: &BootImage, cert: *const c_char) -> bool;
|
|
|
|
unsafe fn sign_boot_image(
|
|
|
|
payload: &[u8],
|
|
|
|
name: *const c_char,
|
|
|
|
cert: *const c_char,
|
|
|
|
key: *const c_char,
|
|
|
|
) -> Vec<u8>;
|
2022-12-13 03:33:16 +00:00
|
|
|
}
|
|
|
|
}
|