summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2024-10-02 12:55:43 +0800
committerXusheng <xusheng@vector35.com>2024-10-03 13:20:18 +0800
commit84172132ffed56cb1ff97b33d729a3daeb637736 (patch)
tree947d206c466e8cc1eea6e3e61a7ebf3525d8b1da
parente9c53f3c9a8cb2f28ea8047c1b9b12f0ea31968f (diff)
Make sure the undefined data variable does not get recreated by auto-analysis. Fix https://github.com/Vector35/binaryninja-api/issues/5817
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp4
-rw-r--r--python/binaryview.py6
-rw-r--r--rust/src/binaryview.rs4
5 files changed, 12 insertions, 8 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 898a1711..bec3474f 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -5080,8 +5080,10 @@ namespace BinaryNinja {
/*! Undefine a DataVariable at a given address
\param addr virtual address of the DataVariable
+ \param blacklist whether to add the address to the data variable black list so that the auto analysis would
+ not recreate the variable on re-analysis
*/
- void UndefineDataVariable(uint64_t addr);
+ void UndefineDataVariable(uint64_t addr, bool blacklist = true);
/*! Undefine a user DataVariable at a given address
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 892a9bb5..94625309 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -4863,7 +4863,7 @@ extern "C"
BINARYNINJACOREAPI void BNDefineDataVariable(BNBinaryView* view, uint64_t addr, BNTypeWithConfidence* type);
BINARYNINJACOREAPI void BNDefineUserDataVariable(BNBinaryView* view, uint64_t addr, BNTypeWithConfidence* type);
- BINARYNINJACOREAPI void BNUndefineDataVariable(BNBinaryView* view, uint64_t addr);
+ BINARYNINJACOREAPI void BNUndefineDataVariable(BNBinaryView* view, uint64_t addr, bool blacklist);
BINARYNINJACOREAPI void BNUndefineUserDataVariable(BNBinaryView* view, uint64_t addr);
BINARYNINJACOREAPI BNDataVariable* BNGetDataVariables(BNBinaryView* view, size_t* count);
BINARYNINJACOREAPI void BNFreeDataVariable(BNDataVariable* var);
diff --git a/binaryview.cpp b/binaryview.cpp
index 9c1373c1..0570e635 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -2058,9 +2058,9 @@ void BinaryView::DefineUserDataVariable(uint64_t addr, const Confidence<Ref<Type
}
-void BinaryView::UndefineDataVariable(uint64_t addr)
+void BinaryView::UndefineDataVariable(uint64_t addr, bool blacklist)
{
- BNUndefineDataVariable(m_object, addr);
+ BNUndefineDataVariable(m_object, addr, blacklist);
}
diff --git a/python/binaryview.py b/python/binaryview.py
index 9fa471dd..3321a21a 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -4719,18 +4719,20 @@ class BinaryView:
return self.get_data_var_at(addr)
- def undefine_data_var(self, addr: int) -> None:
+ def undefine_data_var(self, addr: int, blacklist: bool = True) -> None:
"""
``undefine_data_var`` removes the non-user data variable at the virtual address ``addr``.
:param int addr: virtual address to define the data variable to be removed
+ :param bool blacklist: whether to add the address to the data variable black list so that the auto analysis
+ would not recreat the variable on re-analysis
:rtype: None
:Example:
>>> bv.undefine_data_var(bv.entry_point)
>>>
"""
- core.BNUndefineDataVariable(self.handle, addr)
+ core.BNUndefineDataVariable(self.handle, addr, blacklist)
def undefine_user_data_var(self, addr: int) -> None:
"""
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs
index ed35bc76..6c8020c6 100644
--- a/rust/src/binaryview.rs
+++ b/rust/src/binaryview.rs
@@ -585,9 +585,9 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn undefine_auto_data_var(&self, addr: u64) {
+ fn undefine_auto_data_var(&self, addr: u64, blacklist: Option<bool>) {
unsafe {
- BNUndefineDataVariable(self.as_ref().handle, addr);
+ BNUndefineDataVariable(self.as_ref().handle, addr, blacklist.unwrap_or(true));
}
}