MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / create_section_reader

Function create_section_reader

plugins/dwarf/shared/src/lib.rs:92–192  ·  view source on GitHub ↗
(
    section_id: SectionId,
    view: &'a BinaryView,
    endian: Endian,
    dwo_file: bool,
)

Source from the content-addressed store, hash-verified

90}
91
92pub 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(&section_header[16..20]) as u64 == section.start()
126 } else {
127 endian.read_u64(&section_header[24..32]) == section.start()
128 }
129 })
130 {
131 let section_flags = if view.address_size() == 4 {
132 endian.read_u32(&current_section_header[8..12]) as u64
133 } else {
134 endian.read_u64(&current_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 => {

Callers 3

dump_dwarfFunction · 0.85
parse_range_data_offsetsFunction · 0.85
parse_dwarfFunction · 0.85

Calls 15

section_by_nameMethod · 0.80
findMethod · 0.80
as_strMethod · 0.80
read_vecMethod · 0.80
read_bufferMethod · 0.80
nameMethod · 0.45
iterMethod · 0.45
symbolsMethod · 0.45
full_nameMethod · 0.45
data_variablesMethod · 0.45
addressMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected