1
1
use std:: {
2
- mem:: MaybeUninit , ptr:: copy_nonoverlapping, slice:: from_raw_parts_mut,
2
+ mem:: MaybeUninit , ops :: Range , ptr:: copy_nonoverlapping, slice:: from_raw_parts_mut,
3
3
str:: from_utf8_unchecked_mut,
4
4
} ;
5
5
@@ -21,6 +21,18 @@ pub struct GuestMaps {
21
21
pageflags_node : * mut IntervalTreeNode ,
22
22
}
23
23
24
+ /// Information about the image loaded by QEMU.
25
+ pub struct ImageInfo {
26
+ pub code : Range < GuestAddr > ,
27
+ pub data : Range < GuestAddr > ,
28
+ pub stack : Range < GuestAddr > ,
29
+ pub vdso : GuestAddr ,
30
+ pub entry : GuestAddr ,
31
+ pub brk : GuestAddr ,
32
+ pub alignment : GuestAddr ,
33
+ pub exec_stack : bool ,
34
+ }
35
+
24
36
// Consider a private new only for Emulator
25
37
impl GuestMaps {
26
38
#[ must_use]
@@ -129,6 +141,33 @@ impl Qemu {
129
141
GuestMaps :: new ( )
130
142
}
131
143
144
+ #[ must_use]
145
+ pub fn image_info ( & self ) -> ImageInfo {
146
+ // # Safety
147
+ // Safe because QEMU has been correctly initialized since it takes self as parameter.
148
+ let image_info = unsafe { * libafl_qemu_sys:: libafl_get_image_info ( ) } ;
149
+
150
+ let code_start = image_info. start_code ;
151
+ let code_end = image_info. end_code ;
152
+
153
+ let data_start = image_info. start_data ;
154
+ let data_end = image_info. end_data ;
155
+
156
+ let stack_start = image_info. stack_limit ;
157
+ let stack_end = image_info. start_stack ;
158
+
159
+ ImageInfo {
160
+ code : code_start..code_end,
161
+ data : data_start..data_end,
162
+ stack : stack_start..stack_end,
163
+ vdso : image_info. vdso ,
164
+ entry : image_info. entry ,
165
+ brk : image_info. brk ,
166
+ alignment : image_info. alignment ,
167
+ exec_stack : image_info. exec_stack ,
168
+ }
169
+ }
170
+
132
171
#[ must_use]
133
172
pub fn g2h < T > ( & self , addr : GuestAddr ) -> * mut T {
134
173
unsafe { ( addr as usize + guest_base) as * mut T }
0 commit comments