mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Use quick-protobuf
This commit is contained in:
parent
9929b25339
commit
51e985ae7f
180
native/src/Cargo.lock
generated
180
native/src/Cargo.lock
generated
@ -2,15 +2,6 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.3.2"
|
||||
@ -198,12 +189,6 @@ dependencies = [
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.1"
|
||||
@ -225,21 +210,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
|
||||
dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
@ -252,25 +222,6 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.11"
|
||||
@ -333,8 +284,8 @@ dependencies = [
|
||||
"clap",
|
||||
"cxx",
|
||||
"cxx-gen",
|
||||
"protobuf",
|
||||
"protobuf-codegen",
|
||||
"pb-rs",
|
||||
"quick-protobuf",
|
||||
"size",
|
||||
]
|
||||
|
||||
@ -364,6 +315,22 @@ version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.3.3"
|
||||
@ -390,6 +357,15 @@ version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "pb-rs"
|
||||
version = "0.10.0"
|
||||
source = "git+https://github.com/tafia/quick-protobuf.git?rev=2f37d5a65504de7d716b5b28fd82219501a901a9#2f37d5a65504de7d716b5b28fd82219501a901a9"
|
||||
dependencies = [
|
||||
"log",
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.60"
|
||||
@ -400,54 +376,11 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
|
||||
name = "quick-protobuf"
|
||||
version = "0.8.1"
|
||||
source = "git+https://github.com/tafia/quick-protobuf.git?rev=2f37d5a65504de7d716b5b28fd82219501a901a9#2f37d5a65504de7d716b5b28fd82219501a901a9"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"protobuf-support",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf-codegen"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"once_cell",
|
||||
"protobuf",
|
||||
"protobuf-parse",
|
||||
"regex",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf-parse"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"log",
|
||||
"protobuf",
|
||||
"protobuf-support",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf-support"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -459,32 +392,6 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.19"
|
||||
@ -533,20 +440,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"redox_syscall",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.2.0"
|
||||
@ -594,17 +487,6 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
|
||||
dependencies = [
|
||||
"either",
|
||||
"libc",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -12,11 +12,11 @@ anyhow = "1.0"
|
||||
num-traits = "0.2"
|
||||
num-derive = "0.3"
|
||||
thiserror = "1.0"
|
||||
protobuf = "3.2.0"
|
||||
protobuf-codegen = "3.2.0"
|
||||
byteorder = "1"
|
||||
size = "0.4"
|
||||
clap = "4.3"
|
||||
pb-rs = { git = "https://github.com/tafia/quick-protobuf.git", rev = "2f37d5a65504de7d716b5b28fd82219501a901a9", default-features = false }
|
||||
quick-protobuf = { git = "https://github.com/tafia/quick-protobuf.git", rev = "2f37d5a65504de7d716b5b28fd82219501a901a9" }
|
||||
|
||||
[profile.dev]
|
||||
opt-level = "z"
|
||||
|
3
native/src/boot/.gitignore
vendored
3
native/src/boot/.gitignore
vendored
@ -1 +1,2 @@
|
||||
update_metadata.rs
|
||||
proto/update_metadata.rs
|
||||
proto/mod.rs
|
||||
|
@ -8,14 +8,14 @@ crate-type = ["staticlib"]
|
||||
path = "lib.rs"
|
||||
|
||||
[build-dependencies]
|
||||
protobuf-codegen = { workspace = true }
|
||||
cxx-gen = { workspace = true }
|
||||
pb-rs = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
base = { path = "../base" }
|
||||
cxx = { path = "../external/cxx-rs" }
|
||||
protobuf = { workspace = true }
|
||||
byteorder = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
clap = { workspace = true, features = ["derive"] }
|
||||
size = { workspace = true }
|
||||
quick-protobuf = { workspace = true }
|
||||
|
@ -1,19 +1,26 @@
|
||||
use protobuf_codegen::Customize;
|
||||
|
||||
use crate::gen::gen_cxx_binding;
|
||||
use pb_rs::{types::FileDescriptor, ConfigBuilder};
|
||||
|
||||
#[path = "../include/gen.rs"]
|
||||
mod gen;
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=update_metadata.proto");
|
||||
protobuf_codegen::Codegen::new()
|
||||
.pure()
|
||||
.include(".")
|
||||
.input("update_metadata.proto")
|
||||
.customize(Customize::default().gen_mod_rs(false))
|
||||
.out_dir(".")
|
||||
.run_from_script();
|
||||
println!("cargo:rerun-if-changed=proto/update_metadata.proto");
|
||||
|
||||
gen_cxx_binding("boot-rs");
|
||||
|
||||
let cb = ConfigBuilder::new(
|
||||
&["proto/update_metadata.proto"],
|
||||
None,
|
||||
Some(&"proto"),
|
||||
&["."],
|
||||
)
|
||||
.unwrap();
|
||||
FileDescriptor::run(
|
||||
&cb.single_module(true)
|
||||
.dont_use_cow(true)
|
||||
.generate_getters(true)
|
||||
.build(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ pub use ramdisk::*;
|
||||
|
||||
mod cpio;
|
||||
mod payload;
|
||||
mod proto;
|
||||
mod ramdisk;
|
||||
mod update_metadata;
|
||||
|
||||
#[cxx::bridge]
|
||||
pub mod ffi {
|
||||
|
@ -4,15 +4,15 @@ use std::os::fd::{AsRawFd, FromRawFd};
|
||||
|
||||
use anyhow::{anyhow, Context};
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use protobuf::{EnumFull, Message};
|
||||
use quick_protobuf::{BytesReader, MessageRead};
|
||||
|
||||
use base::libc::c_char;
|
||||
use base::{ReadSeekExt, StrErr, Utf8CStr};
|
||||
use base::{ResultExt, WriteExt};
|
||||
|
||||
use crate::ffi;
|
||||
use crate::update_metadata::install_operation::Type;
|
||||
use crate::update_metadata::DeltaArchiveManifest;
|
||||
use crate::proto::update_metadata::mod_InstallOperation::Type;
|
||||
use crate::proto::update_metadata::DeltaArchiveManifest;
|
||||
|
||||
macro_rules! bad_payload {
|
||||
($msg:literal) => {
|
||||
@ -64,42 +64,43 @@ fn do_extract_boot_from_payload(
|
||||
let manifest = {
|
||||
let manifest = &mut buf[..manifest_len];
|
||||
reader.read_exact(manifest)?;
|
||||
DeltaArchiveManifest::parse_from_bytes(manifest)?
|
||||
let mut br = BytesReader::from_bytes(manifest);
|
||||
DeltaArchiveManifest::from_reader(&mut br, manifest)?
|
||||
};
|
||||
if !manifest.has_minor_version() || manifest.minor_version() != 0 {
|
||||
if manifest.get_minor_version() != 0 {
|
||||
return Err(bad_payload!(
|
||||
"delta payloads are not supported, please use a full payload file"
|
||||
));
|
||||
}
|
||||
|
||||
let block_size = manifest.block_size() as u64;
|
||||
let block_size = manifest.get_block_size() as u64;
|
||||
|
||||
let partition = match partition_name {
|
||||
None => {
|
||||
let boot = manifest
|
||||
.partitions
|
||||
.iter()
|
||||
.find(|p| p.partition_name() == "init_boot");
|
||||
.find(|p| p.partition_name == "init_boot");
|
||||
let boot = match boot {
|
||||
Some(boot) => Some(boot),
|
||||
None => manifest
|
||||
.partitions
|
||||
.iter()
|
||||
.find(|p| p.partition_name() == "boot"),
|
||||
.find(|p| p.partition_name == "boot"),
|
||||
};
|
||||
boot.ok_or(anyhow!("boot partition not found"))?
|
||||
}
|
||||
Some(name) => manifest
|
||||
.partitions
|
||||
.iter()
|
||||
.find(|p| p.partition_name() == name)
|
||||
.find(|p| p.partition_name.as_str() == &*name)
|
||||
.ok_or(anyhow!("partition '{name}' not found"))?,
|
||||
};
|
||||
|
||||
let out_str: String;
|
||||
let out_path = match out_path {
|
||||
None => {
|
||||
out_str = format!("{}.img", partition.partition_name());
|
||||
out_str = format!("{}.img", partition.partition_name);
|
||||
out_str.as_str()
|
||||
}
|
||||
Some(s) => s,
|
||||
@ -126,11 +127,7 @@ fn do_extract_boot_from_payload(
|
||||
.data_offset
|
||||
.ok_or(bad_payload!("data offset not found"))?;
|
||||
|
||||
let data_type = operation
|
||||
.type_
|
||||
.ok_or(bad_payload!("operation type not found"))?
|
||||
.enum_value()
|
||||
.map_err(|_| bad_payload!("operation type not valid"))?;
|
||||
let data_type = operation.type_pb;
|
||||
|
||||
buf.resize(data_len, 0u8);
|
||||
let data = &mut buf[..data_len];
|
||||
@ -171,12 +168,7 @@ fn do_extract_boot_from_payload(
|
||||
return Err(bad_payload!("decompression failed"));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(bad_payload!(
|
||||
"unsupported operation type: {}",
|
||||
data_type.descriptor().name()
|
||||
));
|
||||
}
|
||||
_ => return Err(bad_payload!("unsupported operation type")),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user