mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 14:55:20 +00:00
Support extracting any partition from payload.bin
This commit is contained in:
@@ -13,3 +13,4 @@ cxx-gen = { workspace = true }
|
||||
cxx = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
cfg-if = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![feature(format_args_nl)]
|
||||
#![feature(io_error_more)]
|
||||
|
||||
pub use libc;
|
||||
|
||||
|
||||
@@ -157,32 +157,14 @@ macro_rules! debug {
|
||||
}
|
||||
|
||||
pub trait ResultExt {
|
||||
fn ok_or_log(&self);
|
||||
fn ok_or_msg(&self, args: Arguments);
|
||||
fn log_on_error(&self) -> &Self;
|
||||
fn msg_on_error(&self, args: Arguments) -> &Self;
|
||||
fn log(self) -> Self;
|
||||
}
|
||||
|
||||
impl<R, E: Display> ResultExt for Result<R, E> {
|
||||
fn ok_or_log(&self) {
|
||||
if let Err(e) = self {
|
||||
error!("{}", e);
|
||||
impl<T, E: Display> ResultExt for Result<T, E> {
|
||||
fn log(self) -> Self {
|
||||
if let Err(e) = &self {
|
||||
error!("{:#}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn ok_or_msg(&self, args: Arguments) {
|
||||
if let Err(e) = self {
|
||||
error!("{}: {}", args, e);
|
||||
}
|
||||
}
|
||||
|
||||
fn log_on_error(&self) -> &Self {
|
||||
self.ok_or_log();
|
||||
self
|
||||
}
|
||||
|
||||
fn msg_on_error(&self, args: Arguments) -> &Self {
|
||||
self.ok_or_msg(args);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::cmp::min;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::Arguments;
|
||||
use std::fmt::{Arguments, Debug};
|
||||
use std::str::Utf8Error;
|
||||
use std::{fmt, slice};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
pub fn copy_str(dest: &mut [u8], src: &[u8]) -> usize {
|
||||
let len = min(src.len(), dest.len() - 1);
|
||||
dest[..len].copy_from_slice(&src[..len]);
|
||||
@@ -78,6 +81,24 @@ macro_rules! raw_cstr {
|
||||
}};
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum StrErr {
|
||||
#[error(transparent)]
|
||||
Invalid(#[from] Utf8Error),
|
||||
#[error("argument is null")]
|
||||
NullPointer,
|
||||
}
|
||||
|
||||
pub fn ptr_to_str_result<'a, T>(ptr: *const T) -> Result<&'a str, StrErr> {
|
||||
if ptr.is_null() {
|
||||
Err(StrErr::NullPointer)
|
||||
} else {
|
||||
unsafe { CStr::from_ptr(ptr.cast()) }
|
||||
.to_str()
|
||||
.map_err(|e| StrErr::from(e))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ptr_to_str<'a, T>(ptr: *const T) -> &'a str {
|
||||
if ptr.is_null() {
|
||||
"(null)"
|
||||
|
||||
Reference in New Issue
Block a user