MCPcopy Index your code
hub / github.com/encounter/objdiff / from_section

Method from_section

objdiff-core/src/obj/split_meta.rs:35–84  ·  view source on GitHub ↗
(section: object::Section, e: E, is_64: bool)

Source from the content-addressed store, hash-verified

33
34impl SplitMeta {
35 pub fn from_section<E>(section: object::Section, e: E, is_64: bool) -> Result<Self>
36 where E: Endian {
37 let mut result = SplitMeta::default();
38 let data = section.uncompressed_data().map_err(object_error)?;
39 let mut iter = NoteIterator::new(data.as_ref(), section.align(), e, is_64)?;
40 while let Some(note) = iter.next(e)? {
41 if note.name != ELF_NOTE_SPLIT {
42 continue;
43 }
44 match note.n_type {
45 NT_SPLIT_GENERATOR => {
46 let string =
47 String::from_utf8(note.desc.to_vec()).map_err(anyhow::Error::new)?;
48 result.generator = Some(string);
49 }
50 NT_SPLIT_MODULE_NAME => {
51 let string =
52 String::from_utf8(note.desc.to_vec()).map_err(anyhow::Error::new)?;
53 result.module_name = Some(string);
54 }
55 NT_SPLIT_MODULE_ID => {
56 result.module_id = Some(e.read_u32_bytes(
57 note.desc.try_into().map_err(|_| anyhow!("Invalid module ID size"))?,
58 ));
59 }
60 NT_SPLIT_VIRTUAL_ADDRESSES => {
61 let vec = if is_64 {
62 let mut vec = vec![0u64; note.desc.len() / 8];
63 for (i, v) in vec.iter_mut().enumerate() {
64 *v =
65 e.read_u64_bytes(note.desc[i * 8..(i + 1) * 8].try_into().unwrap());
66 }
67 vec
68 } else {
69 let mut vec = vec![0u64; note.desc.len() / 4];
70 for (i, v) in vec.iter_mut().enumerate() {
71 *v = e.read_u32_bytes(note.desc[i * 4..(i + 1) * 4].try_into().unwrap())
72 as u64;
73 }
74 vec
75 };
76 result.virtual_addresses = Some(vec);
77 }
78 _ => {
79 // Ignore unknown sections
80 }
81 }
82 }
83 Ok(result)
84 }
85
86 #[cfg(feature = "std")]
87 pub fn to_writer<E, W>(&self, writer: &mut W, e: E, is_64: bool) -> std::io::Result<()>

Callers

nothing calls this directly

Calls 2

nextMethod · 0.80
iter_mutMethod · 0.80

Tested by

no test coverage detected