mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-11 22:12:27 +00:00
Support extracting any partition from payload.bin
This commit is contained in:
@@ -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