MCPcopy Create free account
hub / github.com/PLSysSec/wave / parse

Method parse

src/types/platform/linux.rs:80–128  ·  view source on GitHub ↗
(host_buf: &Vec<u8>, in_idx: usize)

Source from the content-addressed store, hash-verified

78impl Dirent {
79 #[requires(in_idx < host_buf.len())]
80 pub fn parse(host_buf: &Vec<u8>, in_idx: usize) -> RuntimeResult<Dirent> {
81 // Inode number
82 let d_ino = u64::from_le_bytes([
83 host_buf[in_idx + 0],
84 host_buf[in_idx + 1],
85 host_buf[in_idx + 2],
86 host_buf[in_idx + 3],
87 host_buf[in_idx + 4],
88 host_buf[in_idx + 5],
89 host_buf[in_idx + 6],
90 host_buf[in_idx + 7],
91 ]);
92
93 // Offset to next linux_dirent
94 let d_offset = u64::from_le_bytes([
95 host_buf[in_idx + 8],
96 host_buf[in_idx + 9],
97 host_buf[in_idx + 10],
98 host_buf[in_idx + 11],
99 host_buf[in_idx + 12],
100 host_buf[in_idx + 13],
101 host_buf[in_idx + 14],
102 host_buf[in_idx + 15],
103 ]);
104
105 // File type
106 let d_type = u8::from_le_bytes([host_buf[in_idx + 18]]);
107
108 // Length of this linux_dirent
109 let d_reclen = u16::from_le_bytes([host_buf[in_idx + 16], host_buf[in_idx + 17]]);
110
111 // If we would overflow - don't :)
112 if d_reclen < 19 || (in_idx + d_reclen as usize) > host_buf.len() {
113 return Err(RuntimeError::Eoverflow);
114 }
115
116 let out_namlen = first_null(&host_buf, in_idx, 19, d_reclen as usize);
117 // let out_namlen = 3;
118
119 let dirent = Dirent {
120 ino: d_ino,
121 reclen: d_reclen,
122 name_start: 19,
123 out_namlen,
124 typ: d_type,
125 };
126
127 Ok(dirent)
128 }
129}

Callers

nothing calls this directly

Calls 2

first_nullFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected