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