mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-11 22:12:27 +00:00
Move hexpatch to Rust
This commit is contained in:
@@ -9,6 +9,8 @@ use std::{fmt, io, slice, str};
|
||||
use libc::c_char;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::ffi;
|
||||
|
||||
pub fn copy_str<T: AsRef<[u8]>>(dest: &mut [u8], src: T) -> usize {
|
||||
let src = src.as_ref();
|
||||
let len = min(src.len(), dest.len() - 1);
|
||||
@@ -346,3 +348,13 @@ impl<T> LibcReturn for *mut T {
|
||||
self.is_null()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MutBytesExt {
|
||||
fn patch(&mut self, from: &[u8], to: &[u8]) -> Vec<usize>;
|
||||
}
|
||||
|
||||
impl<T: AsMut<[u8]>> MutBytesExt for T {
|
||||
fn patch(&mut self, from: &[u8], to: &[u8]) -> Vec<usize> {
|
||||
ffi::mut_u8_patch(self.as_mut(), from, to)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user