1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#![cfg_attr(not(feature = "module-names"), no_std)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![deny(warnings)]
#![allow(clippy::needless_doctest_main)]
#![allow(clippy::missing_safety_doc)]
#[cfg(not(feature = "module-names"))]
extern crate alloc;
extern crate num;
#[allow(unused_imports)]
#[macro_use]
extern crate num_derive;
use core::{
convert::TryFrom,
ffi::{c_char, c_void, CStr},
};
#[cfg(not(feature = "module-names"))]
use alloc::string::String;
pub mod stalker;
pub mod interceptor;
pub mod instruction_writer;
mod module;
pub use module::*;
mod module_map;
pub use module_map::*;
mod error;
pub use error::Error;
mod cpu_context;
pub use cpu_context::*;
mod memory_range;
pub use memory_range::*;
mod range_details;
pub use range_details::*;
mod debug_symbol;
pub use debug_symbol::*;
#[cfg(all(feature = "backtrace", not(target_os = "windows")))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "backtrace")))]
mod backtracer;
#[cfg(all(feature = "backtrace", not(target_os = "windows")))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "backtrace")))]
pub use backtracer::*;
#[doc(hidden)]
pub type Result<T> = core::result::Result<T, error::Error>;
pub struct Gum;
impl Gum {
pub unsafe fn obtain() -> Gum {
frida_gum_sys::gum_init_embedded();
Gum {}
}
}
impl Drop for Gum {
fn drop(&mut self) {
unsafe { frida_gum_sys::gum_deinit_embedded() };
}
}
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
#[repr(transparent)]
pub struct NativePointer(pub *mut c_void);
impl NativePointer {
pub fn is_null(&self) -> bool {
self.0.is_null()
}
}
impl From<&NativePointer> for *mut c_void {
fn from(other: &NativePointer) -> Self {
other.0
}
}
impl From<NativePointer> for *mut c_void {
fn from(other: NativePointer) -> Self {
other.0
}
}
impl TryFrom<NativePointer> for String {
type Error = Error;
fn try_from(ptr: NativePointer) -> Result<Self> {
if ptr.is_null() {
Err(Error::MemoryAccessError)
} else {
unsafe {
Ok(
Self::from_utf8_lossy(CStr::from_ptr(ptr.0 as *const c_char).to_bytes())
.into_owned(),
)
}
}
}
}
impl AsRef<NativePointer> for NativePointer {
fn as_ref(&self) -> &NativePointer {
self
}
}