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

Function export_functions

plugins/dwarf/dwarf_export/src/lib.rs:409–534  ·  view source on GitHub ↗
(
    bv: &BinaryView,
    dwarf: &mut DwarfUnit,
    defined_types: &mut Vec<(Ref<Type>, UnitEntryId)>,
)

Source from the content-addressed store, hash-verified

407}
408
409fn export_functions(
410 bv: &BinaryView,
411 dwarf: &mut DwarfUnit,
412 defined_types: &mut Vec<(Ref<Type>, UnitEntryId)>,
413) {
414 let entry_point = bv.entry_point_function();
415
416 for function in &bv.functions() {
417 // Create function DIE as child of the compilation unit DIE
418 let root = dwarf.unit.root();
419 let function_die_uid = dwarf.unit.add(root, constants::DW_TAG_subprogram);
420 // let function_die = dwarf.unit.get_mut(function_die_uid);
421
422 // Set subprogram DIE attributes
423 dwarf.unit.get_mut(function_die_uid).set(
424 gimli::DW_AT_name,
425 AttributeValue::String(function.symbol().short_name().as_bytes().to_vec()),
426 );
427
428 // TODO : (DW_AT_main_subprogram VS DW_TAG_entry_point)
429 // TODO : This attribute seems maybe usually unused?
430 if let Some(entry_point_function) = &entry_point {
431 if entry_point_function.as_ref() == function.as_ref() {
432 dwarf
433 .unit
434 .get_mut(function_die_uid)
435 .set(gimli::DW_AT_main_subprogram, AttributeValue::Flag(true));
436 dwarf.unit.get_mut(function_die_uid).set(
437 gimli::DW_AT_low_pc,
438 AttributeValue::Address(Address::Constant(function.start())), // TODO: Relocations
439 );
440 }
441 }
442
443 let address_ranges = function.address_ranges();
444 if address_ranges.len() == 1 {
445 let address_range = address_ranges.get(0);
446 dwarf.unit.get_mut(function_die_uid).set(
447 gimli::DW_AT_low_pc,
448 AttributeValue::Address(Address::Constant(address_range.start)), // TODO: Relocations
449 );
450 dwarf.unit.get_mut(function_die_uid).set(
451 gimli::DW_AT_high_pc,
452 AttributeValue::Address(Address::Constant(address_range.end)),
453 );
454 } else {
455 let range_list = RangeList(
456 address_ranges
457 .into_iter()
458 .map(|range| Range::StartLength {
459 begin: Address::Constant(range.start), // TODO: Relocations?
460 length: range.end - range.start,
461 })
462 .collect(),
463 );
464 let range_list_id = dwarf.unit.ranges.add(range_list);
465 dwarf.unit.get_mut(function_die_uid).set(
466 gimli::DW_AT_ranges,

Callers 1

export_dwarfFunction · 0.85

Calls 15

StringClass · 0.85
export_typeFunction · 0.85
entry_point_functionMethod · 0.80
to_vecMethod · 0.80
as_bytesMethod · 0.80
mapMethod · 0.80
function_typeMethod · 0.80
externalMethod · 0.80
FlagClass · 0.50
ConstantClass · 0.50
functionsMethod · 0.45
rootMethod · 0.45

Tested by

no test coverage detected