(
section_id: SectionId,
view: &'a BinaryView,
endian: Endian,
dwo_file: bool,
)
| 90 | } |
| 91 | |
| 92 | pub fn create_section_reader<'a, Endian: 'a + Endianity>( |
| 93 | section_id: SectionId, |
| 94 | view: &'a BinaryView, |
| 95 | endian: Endian, |
| 96 | dwo_file: bool, |
| 97 | ) -> Result<EndianRcSlice<Endian>, Error> { |
| 98 | let section_name = if dwo_file && section_id.dwo_name().is_some() { |
| 99 | section_id.dwo_name().unwrap() |
| 100 | } else { |
| 101 | section_id.name() |
| 102 | }; |
| 103 | |
| 104 | if let Some(section) = view.section_by_name(section_name) { |
| 105 | // TODO : This is kinda broke....should add rust wrappers for some of this |
| 106 | if let Some(symbol) = view |
| 107 | .symbols() |
| 108 | .iter() |
| 109 | .find(|symbol| symbol.full_name().as_str() == "__elf_section_headers") |
| 110 | { |
| 111 | if let Some(data_var) = view |
| 112 | .data_variables() |
| 113 | .iter() |
| 114 | .find(|var| var.address == symbol.address()) |
| 115 | { |
| 116 | // TODO : This should eventually be wrapped by some DataView sorta thingy thing, like how python does it |
| 117 | let data_type = &data_var.ty.contents; |
| 118 | let data = view.read_vec(data_var.address, data_type.width() as usize); |
| 119 | let element_type = data_type.element_type().unwrap().contents; |
| 120 | |
| 121 | if let Some(current_section_header) = data |
| 122 | .chunks(element_type.width() as usize) |
| 123 | .find(|section_header| { |
| 124 | if view.address_size() == 4 { |
| 125 | endian.read_u32(§ion_header[16..20]) as u64 == section.start() |
| 126 | } else { |
| 127 | endian.read_u64(§ion_header[24..32]) == section.start() |
| 128 | } |
| 129 | }) |
| 130 | { |
| 131 | let section_flags = if view.address_size() == 4 { |
| 132 | endian.read_u32(¤t_section_header[8..12]) as u64 |
| 133 | } else { |
| 134 | endian.read_u64(¤t_section_header[8..16]) |
| 135 | }; |
| 136 | // If the section has the compressed bit set |
| 137 | if (section_flags & 2048) != 0 { |
| 138 | // Get section, trim header, decompress, return |
| 139 | let compressed_header_size = view.address_size() * 3; |
| 140 | |
| 141 | let offset = section.start() + compressed_header_size as u64; |
| 142 | let len = section.len() - compressed_header_size; |
| 143 | |
| 144 | let ch_type_vec = view.read_vec(section.start(), 4); |
| 145 | let ch_type = endian.read_u32(&ch_type_vec); |
| 146 | |
| 147 | if let Ok(buffer) = view.read_buffer(offset, len) { |
| 148 | match ch_type { |
| 149 | 1 => { |
no test coverage detected