1#[repr(C)]
3pub struct AppMeta {
4 base: u64,
5 step: u64,
6 count: u64,
7 first: u64,
8}
9
10impl AppMeta {
11 #[inline]
15 pub fn locate() -> &'static Self {
16 extern "C" {
17 static apps: AppMeta;
18 }
19 unsafe { &apps }
22 }
23
24 #[inline]
26 pub fn iter(&'static self) -> AppIterator {
27 AppIterator { meta: self, i: 0 }
28 }
29}
30
31pub struct AppIterator {
33 meta: &'static AppMeta,
34 i: u64,
35}
36
37impl Iterator for AppIterator {
38 type Item = &'static [u8];
39
40 fn next(&mut self) -> Option<Self::Item> {
41 if self.i >= self.meta.count {
42 None
43 } else {
44 let i = self.i as usize;
45 self.i += 1;
46 unsafe {
51 let slice = core::slice::from_raw_parts(
52 &self.meta.first as *const _ as *const usize,
53 (self.meta.count + 1) as _,
54 );
55 let pos = slice[i];
56 let size = slice[i + 1] - pos;
57 let base = self.meta.base as usize + i * self.meta.step as usize;
58 if base != 0 {
59 core::ptr::copy_nonoverlapping::<u8>(pos as _, base as _, size);
62 core::slice::from_raw_parts_mut(base as *mut u8, 0x20_0000)[size..].fill(0);
64 Some(core::slice::from_raw_parts(base as _, size))
65 } else {
66 Some(core::slice::from_raw_parts(pos as _, size))
67 }
68 }
69 }
70 }
71}