@@ -28,45 +28,54 @@ pub mod mmap;
28
28
pub mod munmap;
29
29
pub mod posix_memalign;
30
30
pub mod pvalloc;
31
+ pub mod rawmemchr;
31
32
pub mod read;
32
33
pub mod realloc;
33
34
pub mod reallocarray;
34
35
pub mod stpcpy;
36
+ pub mod stpncpy;
35
37
pub mod strcasecmp;
36
38
pub mod strcasestr;
37
39
pub mod strcat;
38
40
pub mod strchr;
41
+ pub mod strchrnul;
39
42
pub mod strcmp;
40
43
pub mod strcpy;
41
44
pub mod strdup;
42
45
pub mod strlen;
43
46
pub mod strncasecmp;
47
+ pub mod strncat;
44
48
pub mod strncmp;
45
49
pub mod strncpy;
46
50
pub mod strndup;
47
51
pub mod strnlen;
48
52
pub mod strrchr;
49
53
pub mod strstr;
50
54
pub mod valloc;
55
+ pub mod wcschr;
51
56
pub mod wcscmp;
52
57
pub mod wcscpy;
53
58
pub mod wcslen;
59
+ pub mod wcsncmp;
60
+ pub mod wcsnlen;
61
+ pub mod wcsrchr;
62
+ pub mod wmemchr;
54
63
pub mod write;
55
64
56
65
#[ cfg( feature = "libc" ) ]
57
66
pub mod fgets;
58
67
59
- use alloc:: vec:: Vec ;
68
+ use alloc:: vec:: { IntoIter , Vec } ;
60
69
use core:: ffi:: { CStr , c_char, c_int, c_void} ;
61
70
62
- use crate :: { GuestAddr , hooks, size_t, wchar_t} ;
71
+ use crate :: { GuestAddr , hooks, size_t, symbols :: Symbols , wchar_t} ;
63
72
64
73
unsafe extern "C" {
65
74
pub fn asprintf ( strp : * mut * mut c_char , fmt : * const c_char , ...) -> c_int ;
66
75
pub fn vasprintf ( strp : * mut * mut c_char , fmt : * const c_char , va : * const c_void ) -> c_int ;
67
76
}
68
77
69
- #[ derive( Clone ) ]
78
+ #[ derive( Debug , Clone ) ]
70
79
pub struct PatchedHook {
71
80
pub name : & ' static CStr ,
72
81
pub destination : GuestAddr ,
@@ -79,8 +88,27 @@ impl PatchedHook {
79
88
Self { name, destination }
80
89
}
81
90
82
- pub fn all ( ) -> Vec < Self > {
83
- [
91
+ pub fn lookup < S : Symbols > ( & self ) -> Result < GuestAddr , S :: Error > {
92
+ S :: lookup ( self . name . as_ptr ( ) as * const c_char )
93
+ }
94
+ }
95
+
96
+ pub struct PatchedHooks {
97
+ hooks : Vec < PatchedHook > ,
98
+ }
99
+
100
+ impl IntoIterator for PatchedHooks {
101
+ type Item = PatchedHook ;
102
+ type IntoIter = IntoIter < Self :: Item > ;
103
+
104
+ fn into_iter ( self ) -> Self :: IntoIter {
105
+ self . hooks . into_iter ( )
106
+ }
107
+ }
108
+
109
+ impl Default for PatchedHooks {
110
+ fn default ( ) -> Self {
111
+ Self { hooks : [
84
112
PatchedHook :: new :: < unsafe extern "C" fn ( size_t , size_t ) -> * mut c_void > (
85
113
c"aligned_alloc" ,
86
114
hooks:: aligned_alloc:: aligned_alloc,
@@ -124,10 +152,17 @@ impl PatchedHook {
124
152
c"memrchr" ,
125
153
hooks:: memrchr:: memrchr,
126
154
) ,
155
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const c_void , c_int ) -> * mut c_void > (
156
+ c"rawmemchr" ,
157
+ hooks:: rawmemchr:: rawmemchr,
158
+ ) ,
127
159
PatchedHook :: new :: < unsafe extern "C" fn ( * mut c_char , * const c_char ) -> * mut c_char > (
128
160
c"stpcpy" ,
129
161
hooks:: stpcpy:: stpcpy,
130
162
) ,
163
+ PatchedHook :: new :: <
164
+ unsafe extern "C" fn ( * mut c_char , * const c_char , size_t ) -> * mut c_char ,
165
+ > ( c"stpncpy" , hooks:: stpncpy:: stpncpy) ,
131
166
PatchedHook :: new :: < unsafe extern "C" fn ( * const c_char , * const c_char ) -> c_int > (
132
167
c"strcasecmp" ,
133
168
hooks:: strcasecmp:: strcasecmp,
@@ -144,6 +179,10 @@ impl PatchedHook {
144
179
c"strchr" ,
145
180
hooks:: strchr:: strchr,
146
181
) ,
182
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const c_char , c_int ) -> * mut c_char > (
183
+ c"strchrnul" ,
184
+ hooks:: strchrnul:: strchrnul,
185
+ ) ,
147
186
PatchedHook :: new :: < unsafe extern "C" fn ( * const c_char , * const c_char ) -> c_int > (
148
187
c"strcmp" ,
149
188
hooks:: strcmp:: strcmp,
@@ -164,6 +203,9 @@ impl PatchedHook {
164
203
c"strncasecmp" ,
165
204
hooks:: strncasecmp:: strncasecmp,
166
205
) ,
206
+ PatchedHook :: new :: <
207
+ unsafe extern "C" fn ( * mut c_char , * const c_char , size_t ) -> * mut c_char ,
208
+ > ( c"strncat" , hooks:: strncat:: strncat) ,
167
209
PatchedHook :: new :: < unsafe extern "C" fn ( * const c_char , * const c_char , size_t ) -> c_int > (
168
210
c"strncmp" ,
169
211
hooks:: strncmp:: strncmp,
@@ -190,6 +232,10 @@ impl PatchedHook {
190
232
PatchedHook :: new :: <
191
233
unsafe extern "C" fn ( * mut * mut c_char , * const c_char , * const c_void ) -> c_int ,
192
234
> ( c"vasprintf" , hooks:: vasprintf) ,
235
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , c_int ) -> * mut wchar_t > (
236
+ c"wcschr" ,
237
+ hooks:: wcschr:: wcschr,
238
+ ) ,
193
239
PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , * const wchar_t ) -> c_int > (
194
240
c"wcscmp" ,
195
241
hooks:: wcscmp:: wcscmp,
@@ -202,7 +248,24 @@ impl PatchedHook {
202
248
c"wcslen" ,
203
249
hooks:: wcslen:: wcslen,
204
250
) ,
251
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , * const wchar_t , size_t ) -> c_int > (
252
+ c"wcsncmp" ,
253
+ hooks:: wcsncmp:: wcsncmp,
254
+ ) ,
255
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , size_t ) -> size_t > (
256
+ c"wcsnlen" ,
257
+ hooks:: wcsnlen:: wcsnlen,
258
+ ) ,
259
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , c_int ) -> * mut wchar_t > (
260
+ c"wcsrchr" ,
261
+ hooks:: wcsrchr:: wcsrchr,
262
+ ) ,
263
+ PatchedHook :: new :: < unsafe extern "C" fn ( * const wchar_t , wchar_t , size_t ) -> * mut wchar_t > (
264
+ c"wmemchr" ,
265
+ hooks:: wmemchr:: wmemchr,
266
+ ) ,
267
+
205
268
]
206
- . to_vec ( )
269
+ . to_vec ( ) }
207
270
}
208
271
}
0 commit comments