diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-04-22 12:00:38 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-05-08 15:27:58 -0400 |
| commit | 99c7a280ae771073b6a36e958426d6f2c7d29462 (patch) | |
| tree | 02c2f8164c657f5bc24a88a99acdc7fac29e5d93 | |
| parent | 2693da23c708d454d3fbed93326ed319dc2d082a (diff) | |
Pass debug file along with original file to debug info parsers
| -rw-r--r-- | binaryninjaapi.h | 7 | ||||
| -rw-r--r-- | binaryninjacore.h | 9 | ||||
| -rw-r--r-- | debuginfo.cpp | 16 | ||||
| -rw-r--r-- | python/debuginfo.py | 2 | ||||
| -rw-r--r-- | rust/src/debuginfo.rs | 9 | ||||
| -rw-r--r-- | rust/src/types.rs | 16 |
6 files changed, 35 insertions, 24 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index de79371d..1da9bf3a 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -14736,7 +14736,7 @@ namespace BinaryNinja { static std::vector<Ref<DebugInfoParser>> GetListForView(const Ref<BinaryView> data); std::string GetName() const; - Ref<DebugInfo> Parse(Ref<BinaryView> view, Ref<DebugInfo> existingDebugInfo = nullptr, std::function<bool(size_t, size_t)> progress = {}) const; + Ref<DebugInfo> Parse(Ref<BinaryView> view, Ref<BinaryView> debugView, Ref<DebugInfo> existingDebugInfo = nullptr, std::function<bool(size_t, size_t)> progress = {}) const; bool IsValidForView(const Ref<BinaryView> view) const; }; @@ -14747,7 +14747,7 @@ namespace BinaryNinja { class CustomDebugInfoParser : public DebugInfoParser { static bool IsValidCallback(void* ctxt, BNBinaryView* view); - static bool ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view, bool (*progress)(void*, size_t, size_t), void* progressCtxt); + static bool ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view, BNBinaryView* debugFile, bool (*progress)(void*, size_t, size_t), void* progressCtxt); BNDebugInfoParser* Register(const std::string& name); public: @@ -14755,7 +14755,8 @@ namespace BinaryNinja { virtual ~CustomDebugInfoParser() {} virtual bool IsValid(Ref<BinaryView>) = 0; - virtual bool ParseInfo(Ref<DebugInfo>, Ref<BinaryView>, std::function<bool(size_t, size_t)>) = 0; + virtual bool ParseInfo( + Ref<DebugInfo>, Ref<BinaryView>, Ref<BinaryView>, std::function<bool(size_t, size_t)>) = 0; }; /*! Class for storing secrets (e.g. tokens) in a system-specific manner diff --git a/binaryninjacore.h b/binaryninjacore.h index 3f9f0f29..5d716374 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -6430,16 +6430,17 @@ extern "C" BINARYNINJACOREAPI char* BNRustSimplifyStrToStr(const char* const); BINARYNINJACOREAPI BNDebugInfoParser* BNRegisterDebugInfoParser(const char* name, - bool (*isValid)(void*, BNBinaryView*), bool (*parseInfo)(void*, BNDebugInfo*, BNBinaryView*, bool(*)(void*, size_t, size_t), void*), void* context); + bool (*isValid)(void*, BNBinaryView*), + bool (*parseInfo)(void*, BNDebugInfo*, BNBinaryView*, BNBinaryView*, bool (*)(void*, size_t, size_t), void*), + void* context); BINARYNINJACOREAPI void BNUnregisterDebugInfoParser(const char* rawName); BINARYNINJACOREAPI BNDebugInfoParser* BNGetDebugInfoParserByName(const char* name); BINARYNINJACOREAPI BNDebugInfoParser** BNGetDebugInfoParsers(size_t* count); BINARYNINJACOREAPI BNDebugInfoParser** BNGetDebugInfoParsersForView(BNBinaryView* view, size_t* count); BINARYNINJACOREAPI char* BNGetDebugInfoParserName(BNDebugInfoParser* parser); BINARYNINJACOREAPI bool BNIsDebugInfoParserValidForView(BNDebugInfoParser* parser, BNBinaryView* view); - BINARYNINJACOREAPI BNDebugInfo* BNParseDebugInfo( - BNDebugInfoParser* parser, BNBinaryView* view, BNDebugInfo* existingDebugInfo, - bool (*progress)(void*, size_t, size_t), void* progressCtxt); + BINARYNINJACOREAPI BNDebugInfo* BNParseDebugInfo(BNDebugInfoParser* parser, BNBinaryView* view, BNBinaryView* debugFile, + BNDebugInfo* existingDebugInfo, bool (*progress)(void*, size_t, size_t), void* progressCtxt); BINARYNINJACOREAPI BNDebugInfoParser* BNNewDebugInfoParserReference(BNDebugInfoParser* parser); BINARYNINJACOREAPI void BNFreeDebugInfoParserReference(BNDebugInfoParser* parser); BINARYNINJACOREAPI void BNFreeDebugInfoParserList(BNDebugInfoParser** parsers, size_t count); diff --git a/debuginfo.cpp b/debuginfo.cpp index c2079824..5f4e1af0 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -355,7 +355,8 @@ string DebugInfoParser::GetName() const } -Ref<DebugInfo> DebugInfoParser::Parse(Ref<BinaryView> view, Ref<DebugInfo> existingDebugInfo, std::function<bool(size_t, size_t)> progress) const +Ref<DebugInfo> DebugInfoParser::Parse(Ref<BinaryView> view, Ref<BinaryView> debugFile, Ref<DebugInfo> existingDebugInfo, + std::function<bool(size_t, size_t)> progress) const { ProgressContext ctxt; if (progress) @@ -366,14 +367,15 @@ Ref<DebugInfo> DebugInfoParser::Parse(Ref<BinaryView> view, Ref<DebugInfo> exist BNDebugInfo* info = nullptr; if (existingDebugInfo) { - info = BNParseDebugInfo(m_object, view->GetObject(), existingDebugInfo->GetObject(), ProgressCallback, &ctxt); + info = BNParseDebugInfo(m_object, view->GetObject(), debugFile->GetObject(), existingDebugInfo->GetObject(), + ProgressCallback, &ctxt); if (!info) return nullptr; info = BNNewDebugInfoReference(info); } else { - info = BNParseDebugInfo(m_object, view->GetObject(), nullptr, ProgressCallback, &ctxt); + info = BNParseDebugInfo(m_object, view->GetObject(), debugFile->GetObject(), nullptr, ProgressCallback, &ctxt); if (!info) return nullptr; } @@ -399,12 +401,12 @@ bool CustomDebugInfoParser::IsValidCallback(void* ctxt, BNBinaryView* view) } -bool CustomDebugInfoParser::ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view, bool (*progress)(void*, size_t, size_t), void* progressCtxt) +bool CustomDebugInfoParser::ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view, + BNBinaryView* debugFile, bool (*progress)(void*, size_t, size_t), void* progressCtxt) { CustomDebugInfoParser* parser = (CustomDebugInfoParser*)ctxt; - return parser->ParseInfo(new DebugInfo(debugInfo), new BinaryView(view), [=](size_t cur, size_t max) { - return progress(progressCtxt, cur, max); - }); + return parser->ParseInfo(new DebugInfo(debugInfo), new BinaryView(view), new BinaryView(debugFile), + [=](size_t cur, size_t max) { return progress(progressCtxt, cur, max); }); } diff --git a/python/debuginfo.py b/python/debuginfo.py index a8307cae..6e179ab8 100644 --- a/python/debuginfo.py +++ b/python/debuginfo.py @@ -131,7 +131,7 @@ class _DebugInfoParserMetaClass(type): ctypes.POINTER(core.BNBinaryView ))(lambda ctxt, view: cls._is_valid(view, is_valid)) parse_info_cb = ctypes.CFUNCTYPE( - ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNDebugInfo), ctypes.POINTER(core.BNBinaryView), + ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNDebugInfo), ctypes.POINTER(core.BNDebugInfo), ctypes.POINTER(core.BNBinaryView), ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_size_t), ctypes.c_void_p, )(lambda ctxt, debug_info, view, progress, progress_ctxt: cls._parse_info(debug_info, view, lambda cur, max: progress(progress_ctxt, cur, max), parse_info)) diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index 0fd1930e..40c1fd39 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -40,7 +40,7 @@ //! true //! } //! -//! fn parse_info(&self, _debug_info: &mut DebugInfo, _view: &BinaryView, _progress: Box<dyn Fn(usize, usize) -> bool>) { +//! fn parse_info(&self, _debug_info: &mut DebugInfo, _view: &BinaryView, _debug_file: &BinaryView, _progress: Box<dyn Fn(usize, usize) -> bool>) { //! println!("Parsing info"); //! } //! } @@ -145,6 +145,7 @@ impl DebugInfoParser { pub fn parse_debug_info( &self, view: &BinaryView, + debug_file: &BinaryView, existing_debug_info: Option<&DebugInfo>, progress: Option<Box<dyn Fn(usize, usize) -> Result<(), ()>>>, ) -> Option<Ref<DebugInfo>> { @@ -154,6 +155,7 @@ impl DebugInfoParser { BNParseDebugInfo( self.handle, view.handle, + debug_file.handle, debug_info.handle, Some(Self::cb_progress), &mut progress_raw as *mut _ as *mut c_void, @@ -163,6 +165,7 @@ impl DebugInfoParser { BNParseDebugInfo( self.handle, view.handle, + debug_file.handle, ptr::null_mut(), Some(Self::cb_progress), &mut progress_raw as *mut _ as *mut c_void, @@ -197,6 +200,7 @@ impl DebugInfoParser { ctxt: *mut c_void, debug_info: *mut BNDebugInfo, view: *mut BNBinaryView, + debug_file: *mut BNBinaryView, progress: Option<unsafe extern "C" fn(*mut c_void, usize, usize) -> bool>, progress_ctxt: *mut c_void, ) -> bool @@ -206,11 +210,13 @@ impl DebugInfoParser { ffi_wrap!("CustomDebugInfoParser::parse_info", unsafe { let cmd = &*(ctxt as *const C); let view = BinaryView::from_raw(view); + let debug_file = BinaryView::from_raw(debug_file); let mut debug_info = DebugInfo::from_raw(debug_info); cmd.parse_info( &mut debug_info, &view, + &debug_file, Box::new(move |cur: usize, max: usize| match progress { Some(func) => { if func(progress_ctxt, cur, max) { @@ -839,6 +845,7 @@ pub trait CustomDebugInfoParser: 'static + Sync { &self, debug_info: &mut DebugInfo, view: &BinaryView, + debug_file: &BinaryView, progress: Box<dyn Fn(usize, usize) -> Result<(), ()>>, ) -> bool; } diff --git a/rust/src/types.rs b/rust/src/types.rs index beca2aea..23a28631 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1917,14 +1917,14 @@ impl InheritedStructureMember { } } - pub(crate) unsafe fn from_raw(handle: BNInheritedStructureMember) -> Self { - Self { - base: RefCountable::inc_ref(&NamedTypeReference::from_raw(handle.base)), - base_offset: handle.baseOffset, - member: StructureMember::from_raw(handle.member), - member_index: handle.memberIndex, - } - } + // pub(crate) unsafe fn from_raw(handle: BNInheritedStructureMember) -> Self { + // Self { + // base: RefCountable::inc_ref(&NamedTypeReference::from_raw(handle.base)), + // base_offset: handle.baseOffset, + // member: StructureMember::from_raw(handle.member), + // member_index: handle.memberIndex, + // } + // } } #[derive(Debug, Clone)] |
