Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use std::option::Option;
4 : use std::marker::PhantomData;
5 : use crate::{common::FromFFI, generic, common::into_optional};
6 :
7 : pub mod compilation_unit;
8 : pub mod function;
9 : pub mod variable;
10 : pub mod types;
11 :
12 : #[doc(inline)]
13 : pub use compilation_unit::CompilationUnit;
14 :
15 : #[doc(inline)]
16 : pub use types::Type;
17 :
18 : #[doc(inline)]
19 : pub use variable::Variable;
20 :
21 : #[doc(inline)]
22 : pub use function::Function;
23 :
24 : /// This structure exposes the main API to create DWARF information
25 : pub struct Editor<'a> {
26 : ptr: cxx::UniquePtr<ffi::DWARF_Editor>,
27 : _owner: PhantomData<&'a ()>,
28 : }
29 :
30 : impl FromFFI<ffi::DWARF_Editor> for Editor<'_> {
31 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::DWARF_Editor>) -> Self {
32 0 : Self {
33 0 : ptr,
34 0 : _owner: PhantomData,
35 0 : }
36 0 : }
37 : }
38 :
39 : impl<'a> Editor<'a> {
40 : /// Instantiate an editor for the given binary object
41 0 : pub fn from_binary(bin: &'a mut dyn generic::Binary) -> Option<Editor<'a>> {
42 0 : into_optional(ffi::DWARF_Editor::from_binary(bin.as_pin_mut_generic()))
43 0 : }
44 :
45 : /// Create a new compilation unit
46 0 : pub fn create_compile_unit(&mut self) -> Option<CompilationUnit> {
47 0 : into_optional(self.ptr.pin_mut().create_compilation_unit())
48 0 : }
49 :
50 : /// Write the DWARF file to the specified output
51 0 : pub fn write(&mut self, output: &str) {
52 0 : self.ptr.pin_mut().write(output)
53 0 : }
54 : }
55 :
|