diff options
| author | Peter LaFosse <peter@vector35.com> | 2023-02-08 08:56:03 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2023-02-08 11:52:37 -0500 |
| commit | 0b752f36c9d3b6bcb51a05fdcf5b38633d38bdbd (patch) | |
| tree | 74551bbf2d65f3d21a159ee006df7da45e93e398 | |
| parent | c2f7f8acadb4aec2c4df646528692fc9bfe1abd1 (diff) | |
Add boolean for Function.user_type to indicate if a user type has been set
| -rw-r--r-- | binaryninjaapi.h | 2 | ||||
| -rw-r--r-- | binaryninjacore.h | 1 | ||||
| -rw-r--r-- | function.cpp | 6 | ||||
| -rw-r--r-- | python/function.py | 5 | ||||
| -rw-r--r-- | suite/api_test.py | 2 |
5 files changed, 16 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 7ad86999..c08e2c1a 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -8754,6 +8754,8 @@ namespace BinaryNinja { void SetRegisterStackAdjustments(const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust); void SetClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered); + bool HasUserType() const; + void ApplyImportedTypes(Symbol* sym, Ref<Type> type = nullptr); void ApplyAutoDiscoveredType(Type* type); diff --git a/binaryninjacore.h b/binaryninjacore.h index 52614f41..6486f657 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -3763,6 +3763,7 @@ extern "C" BINARYNINJACOREAPI BNBoolWithConfidence BNCanFunctionReturn(BNFunction* func); BINARYNINJACOREAPI void BNSetFunctionAutoType(BNFunction* func, BNType* type); BINARYNINJACOREAPI void BNSetFunctionUserType(BNFunction* func, BNType* type); + BINARYNINJACOREAPI bool BNFunctionHasUserType(BNFunction* func); BINARYNINJACOREAPI char* BNGetFunctionComment(BNFunction* func); BINARYNINJACOREAPI char* BNGetCommentForAddress(BNFunction* func, uint64_t addr); diff --git a/function.cpp b/function.cpp index 37192ba0..04318393 100644 --- a/function.cpp +++ b/function.cpp @@ -1051,6 +1051,12 @@ void Function::SetUserType(Type* type) } +bool Function::HasUserType() const +{ + return BNFunctionHasUserType(m_object); +} + + void Function::SetReturnType(const Confidence<Ref<Type>>& type) { BNTypeWithConfidence tc; diff --git a/python/function.py b/python/function.py index 73b08b48..80dd3968 100644 --- a/python/function.py +++ b/python/function.py @@ -2512,6 +2512,11 @@ class Function: (value, _) = self.view.parse_type_string(value) core.BNSetFunctionUserType(self.handle, value.handle) + @property + def user_type(self) -> bool: + """True if the function has a user-defined type""" + return core.BNFunctionHasUserType(self.handle) + def set_auto_return_type(self, value: StringOrType) -> None: type_conf = core.BNTypeWithConfidence() if value is None: diff --git a/suite/api_test.py b/suite/api_test.py index 39c58491..9e5431ac 100644 --- a/suite/api_test.py +++ b/suite/api_test.py @@ -2115,7 +2115,9 @@ class TestWithFunction(TestWithBinaryView): assert ft.return_value == Type.int(4) ftm = ft.mutable_copy() ftm.return_value = Type.int(4, False) + assert not ft.user_type self.func.function_type = ftm + assert ft.user_type self.func.view.update_analysis_and_wait() assert self.func.function_type.return_value == Type.int(4, False), f"{self.func.function_type.return_value} != {Type.int(4, False)}" func_str = "int32_t main(int32_t argc, char** argv, char** envp)" |
