diff options
| author | Peter LaFosse <peter@vector35.com> | 2023-07-17 13:43:16 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2023-07-17 14:42:18 -0400 |
| commit | f9a68f76f871449924b4fe32e6ade3d02a98249c (patch) | |
| tree | 5a6140a80390d0618d77cb759d72896ae97dddb1 | |
| parent | 1a9be2ee9d1ac8d3506f9d2adbe0f25cf6d2f84d (diff) | |
Add CheckForStringAnnotationType API
| -rw-r--r-- | binaryninjaapi.h | 19 | ||||
| -rw-r--r-- | binaryninjacore.h | 11 | ||||
| -rw-r--r-- | binaryview.cpp | 22 |
3 files changed, 41 insertions, 11 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 2170e82f..4ea0ff50 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4882,6 +4882,24 @@ namespace BinaryNinja { std::vector<Ref<Component>> GetFunctionParentComponents(Ref<Function> function) const; std::vector<Ref<Component>> GetDataVariableParentComponents(DataVariable var) const; + /*! Heuristically determine if a string exists at the given address. This API checks for the following settings: + "analysis.unicode.utf8" - default true enables UTF-8 string detection + "analysis.unicode.utf16" - default true enables UTF-16 string detection + "analysis.unicode.utf32" - default true enables UTF-32 string detection + "analysis.unicode.blocks" - selects the Unicode blocks to use for detection + + \param addr Address to check + \param value String value to populate + \param allowShortStrings Whether to allow short strings < 4 characters + \param allowLargeStrings If false strings must be less than "rendering.strings.maxAnnotationLength" (default 32) + If true strings must be less than "analysis.limits.maxStringLength" (default 16384) + \param childWidth Width of the characters + \return The type of string annotation found + + */ + std::optional<BNStringType> CheckForStringAnnotationType(uint64_t addr, std::string& value, + bool allowShortStrings, bool allowLargeStrings, size_t childWidth); + /*! Check whether the given architecture supports assembling instructions \param arch Architecture to check @@ -5006,7 +5024,6 @@ namespace BinaryNinja { AnalysisInfo GetAnalysisInfo(); BNAnalysisProgress GetAnalysisProgress(); Ref<BackgroundTask> GetBackgroundAnalysisTask(); - size_t GetFullStringSize(uint64_t addr, BNStringType type); /*! Returns the virtual address of the Function that occurs after the virtual address `addr` diff --git a/binaryninjacore.h b/binaryninjacore.h index d2b51224..db9f9473 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -377,9 +377,11 @@ extern "C" FunctionReturnTokenContext = 3, InstructionAddressTokenContext = 4, ILInstructionIndexTokenContext = 5, - ConstDataTokenContext = 6, - ConstStringDataTokenContext = 7, - StringReferenceTokenContext = 8 + ConstDataTokenContext = 6, // For Const Data arrays + ConstStringDataTokenContext = 7, // For ConstData strings + StringReferenceTokenContext = 8, // For References to strings + StringDataVariableTokenContext = 9, // For String DataVariables + StringDisplayTokenContex = 10 // For displaying strings which aren't associated with an address } BNInstructionTextTokenContext; typedef enum BNLinearDisassemblyLineType @@ -4237,7 +4239,6 @@ extern "C" BINARYNINJACOREAPI void BNFreeAnalysisInfo(BNAnalysisInfo* info); BINARYNINJACOREAPI BNAnalysisProgress BNGetAnalysisProgress(BNBinaryView* view); BINARYNINJACOREAPI BNBackgroundTask* BNGetBackgroundAnalysisTask(BNBinaryView* view); - BINARYNINJACOREAPI size_t BNGetFullStringSize(BNBinaryView* view, uint64_t addr, BNStringType type); BINARYNINJACOREAPI uint64_t BNGetNextFunctionStartAfterAddress(BNBinaryView* view, uint64_t addr); BINARYNINJACOREAPI uint64_t BNGetNextBasicBlockStartAfterAddress(BNBinaryView* view, uint64_t addr); @@ -5604,6 +5605,8 @@ extern "C" BINARYNINJACOREAPI BNComponent** BNGetFunctionParentComponents(BNBinaryView* view, BNFunction *func, size_t* count); BINARYNINJACOREAPI BNComponent** BNGetDataVariableParentComponents(BNBinaryView* view, uint64_t dataVariable, size_t* count); + BINARYNINJACOREAPI bool BNCheckForStringAnnotationType(BNBinaryView* view, uint64_t addr, char** value, BNStringType* strType, + bool allowShortStrings, bool allowLargeStrings, size_t childWidth); BINARYNINJACOREAPI BNBinaryView* BNLoadFilename(const char* const filename, const bool updateAnalysis, bool (*progress)(size_t, size_t), const BNMetadata* const options); diff --git a/binaryview.cpp b/binaryview.cpp index 343dc322..2be28283 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -3185,6 +3185,22 @@ std::vector<Ref<Component>> BinaryView::GetDataVariableParentComponents(DataVari } +std::optional<BNStringType> BinaryView::CheckForStringAnnotationType(uint64_t addr, string& value, bool allowShortStrings, bool allowLargeStrings, size_t childWidth) +{ + char* str = nullptr; + BNStringType type; + bool result = BNCheckForStringAnnotationType(m_object, addr, &str, &type, + allowShortStrings, allowLargeStrings, childWidth); + if (result) + { + value = string(str); + BNFreeString(str); + return type; + } + return std::nullopt; +} + + bool BinaryView::CanAssemble(Architecture* arch) { return BNCanAssemble(m_object, arch->GetObject()); @@ -3303,12 +3319,6 @@ Ref<BackgroundTask> BinaryView::GetBackgroundAnalysisTask() } -size_t BinaryView::GetFullStringSize(uint64_t addr, BNStringType type) -{ - return BNGetFullStringSize(m_object, addr, type); -} - - uint64_t BinaryView::GetNextFunctionStartAfterAddress(uint64_t addr) { return BNGetNextFunctionStartAfterAddress(m_object, addr); |
