Skip to content

Commit 6397c23

Browse files
committed
merging main
2 parents 6c78209 + 68ac3ce commit 6397c23

File tree

8 files changed

+267
-193
lines changed

8 files changed

+267
-193
lines changed

binaryninjaapi.h

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5858,11 +5858,12 @@ namespace BinaryNinja {
58585858
\param[in] text Text containing the type definition
58595859
\param[out] result Reference into which the resulting type and name will be written
58605860
\param[out] errors Reference to a list into which any parse errors will be written
5861-
\param typesAllowRedefinition
5861+
\param[in] typesAllowRedefinition List of types whose names are allowed to be overwritten (legacy cruft?)
5862+
\param[in] importDependencies If Type Library / Type Archive types should be imported during parsing
58625863
\return Whether parsing was successful
58635864
*/
58645865
bool ParseTypeString(const std::string& text, QualifiedNameAndType& result, std::string& errors,
5865-
const std::set<QualifiedName>& typesAllowRedefinition = {});
5866+
const std::set<QualifiedName>& typesAllowRedefinition = {}, bool importDependencies = true);
58665867

58675868
/*! Parse an entire block of source into types, variables, and functions
58685869

@@ -5871,14 +5872,25 @@ namespace BinaryNinja {
58715872
\param[out] variables Reference to a list of QualifiedNames and Types the parsed variables will be writen to
58725873
\param[out] functions Reference to a list of QualifiedNames and Types the parsed functions will be writen to
58735874
\param[out] errors Reference to a list into which any parse errors will be written
5874-
\param typesAllowRedefinition
5875+
\param[in] typesAllowRedefinition List of types whose names are allowed to be overwritten (legacy cruft?)
5876+
\param[in] importDependencies If Type Library / Type Archive types should be imported during parsing
58755877
\return Whether parsing was successful
58765878
*/
58775879
bool ParseTypeString(const std::string& text, std::map<QualifiedName, Ref<Type>>& types,
58785880
std::map<QualifiedName, Ref<Type>>& variables, std::map<QualifiedName, Ref<Type>>& functions,
5879-
std::string& errors, const std::set<QualifiedName>& typesAllowRedefinition = {});
5881+
std::string& errors, const std::set<QualifiedName>& typesAllowRedefinition = {}, bool importDependencies = true);
5882+
5883+
/*! Parse an entire block of source into a structure containing types, variables, and functions
5884+
5885+
\param[in] text Source code to parse
5886+
\param[out] result Reference to a TypeParserResult structure into which types, variables, and functions will be written
5887+
\param[out] errors Reference to a list into which any parse errors will be written
5888+
\param[in] typesAllowRedefinition List of types whose names are allowed to be overwritten (legacy cruft?)
5889+
\param[in] importDependencies If Type Library / Type Archive types should be imported during parsing
5890+
\return Whether parsing was successful
5891+
*/
58805892
bool ParseTypesFromSource(const std::string& text, const std::vector<std::string>& options, const std::vector<std::string>& includeDirs, TypeParserResult& result,
5881-
std::string& errors, const std::set<QualifiedName>& typesAllowRedefinition = {});
5893+
std::string& errors, const std::set<QualifiedName>& typesAllowRedefinition = {}, bool importDependencies = true);
58825894

58835895
/*! Type Container for all types (user and auto) in the BinaryView. Any auto types
58845896
modified through the Type Container will be converted into user types.
@@ -14572,22 +14584,22 @@ namespace BinaryNinja {
1457214584
static bool GetOptionTextCallback(void* ctxt, BNTypeParserOption option, const char* value, char** result);
1457314585
static bool PreprocessSourceCallback(void* ctxt,
1457414586
const char* source, const char* fileName, BNPlatform* platform,
14575-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
14587+
BNTypeContainer* existingTypes,
1457614588
const char* const* options, size_t optionCount,
1457714589
const char* const* includeDirs, size_t includeDirCount,
1457814590
char** output, BNTypeParserError** errors, size_t* errorCount
1457914591
);
1458014592
static bool ParseTypesFromSourceCallback(void* ctxt,
1458114593
const char* source, const char* fileName, BNPlatform* platform,
14582-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
14594+
BNTypeContainer* existingTypes,
1458314595
const char* const* options, size_t optionCount,
1458414596
const char* const* includeDirs, size_t includeDirCount,
1458514597
const char* autoTypeSource, BNTypeParserResult* result,
1458614598
BNTypeParserError** errors, size_t* errorCount
1458714599
);
1458814600
static bool ParseTypeStringCallback(void* ctxt,
1458914601
const char* source, BNPlatform* platform,
14590-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
14602+
BNTypeContainer* existingTypes,
1459114603
BNQualifiedNameAndType* result,
1459214604
BNTypeParserError** errors, size_t* errorCount
1459314605
);
@@ -14629,7 +14641,7 @@ namespace BinaryNinja {
1462914641
\param source Source code to process
1463014642
\param fileName Name of the file containing the source (does not need to exist on disk)
1463114643
\param platform Platform to assume the source is relevant to
14632-
\param existingTypes Map of all existing types to use for parsing context
14644+
\param existingTypes Container of all existing types to use for parsing context
1463314645
\param options String arguments to pass as options, e.g. command line arguments
1463414646
\param includeDirs List of directories to include in the header search path
1463514647
\param output Reference to a string into which the preprocessed source will be written
@@ -14640,7 +14652,7 @@ namespace BinaryNinja {
1464014652
const std::string& source,
1464114653
const std::string& fileName,
1464214654
Ref<Platform> platform,
14643-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14655+
std::optional<TypeContainer> existingTypes,
1464414656
const std::vector<std::string>& options,
1464514657
const std::vector<std::string>& includeDirs,
1464614658
std::string& output,
@@ -14652,7 +14664,7 @@ namespace BinaryNinja {
1465214664
\param source Source code to parse
1465314665
\param fileName Name of the file containing the source (optional: exists on disk)
1465414666
\param platform Platform to assume the types are relevant to
14655-
\param existingTypes Map of all existing types to use for parsing context
14667+
\param existingTypes Container of all existing types to use for parsing context
1465614668
\param options String arguments to pass as options, e.g. command line arguments
1465714669
\param includeDirs List of directories to include in the header search path
1465814670
\param autoTypeSource Optional source of types if used for automatically generated types
@@ -14664,7 +14676,7 @@ namespace BinaryNinja {
1466414676
const std::string& source,
1466514677
const std::string& fileName,
1466614678
Ref<Platform> platform,
14667-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14679+
std::optional<TypeContainer> existingTypes,
1466814680
const std::vector<std::string>& options,
1466914681
const std::vector<std::string>& includeDirs,
1467014682
const std::string& autoTypeSource,
@@ -14676,7 +14688,7 @@ namespace BinaryNinja {
1467614688
Parse an entire source file into types, variables, and functions
1467714689
\param fileName Name of the file on disk containing the source
1467814690
\param platform Platform to assume the types are relevant to
14679-
\param existingTypes Map of all existing types to use for parsing context
14691+
\param existingTypes Container of all existing types to use for parsing context
1468014692
\param options String arguments to pass as options, e.g. command line arguments
1468114693
\param includeDirs List of directories to include in the header search path
1468214694
\param autoTypeSource Optional source of types if used for automatically generated types
@@ -14687,7 +14699,7 @@ namespace BinaryNinja {
1468714699
bool ParseTypesFromSourceFile(
1468814700
const std::string& fileName,
1468914701
Ref<Platform> platform,
14690-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14702+
std::optional<TypeContainer> existingTypes,
1469114703
const std::vector<std::string>& options,
1469214704
const std::vector<std::string>& includeDirs,
1469314705
const std::string& autoTypeSource,
@@ -14699,15 +14711,15 @@ namespace BinaryNinja {
1469914711
Parse a single type and name from a string containing their definition.
1470014712
\param source Source code to parse
1470114713
\param platform Platform to assume the types are relevant to
14702-
\param existingTypes Map of all existing types to use for parsing context
14714+
\param existingTypes Container of all existing types to use for parsing context
1470314715
\param result Reference into which the resulting type and name will be written
1470414716
\param errors Reference to a list into which any parse errors will be written
1470514717
\return True if parsing was successful
1470614718
*/
1470714719
virtual bool ParseTypeString(
1470814720
const std::string& source,
1470914721
Ref<Platform> platform,
14710-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14722+
std::optional<TypeContainer> existingTypes,
1471114723
QualifiedNameAndType& result,
1471214724
std::vector<TypeParserError>& errors
1471314725
) = 0;
@@ -14728,7 +14740,7 @@ namespace BinaryNinja {
1472814740
const std::string& source,
1472914741
const std::string& fileName,
1473014742
Ref<Platform> platform,
14731-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14743+
std::optional<TypeContainer> existingTypes,
1473214744
const std::vector<std::string>& options,
1473314745
const std::vector<std::string>& includeDirs,
1473414746
std::string& output,
@@ -14739,7 +14751,7 @@ namespace BinaryNinja {
1473914751
const std::string& source,
1474014752
const std::string& fileName,
1474114753
Ref<Platform> platform,
14742-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14754+
std::optional<TypeContainer> existingTypes,
1474314755
const std::vector<std::string>& options,
1474414756
const std::vector<std::string>& includeDirs,
1474514757
const std::string& autoTypeSource,
@@ -14750,7 +14762,7 @@ namespace BinaryNinja {
1475014762
virtual bool ParseTypeString(
1475114763
const std::string& source,
1475214764
Ref<Platform> platform,
14753-
const std::map<QualifiedName, TypeAndId>& existingTypes,
14765+
std::optional<TypeContainer> existingTypes,
1475414766
QualifiedNameAndType& result,
1475514767
std::vector<TypeParserError>& errors
1475614768
) override;
@@ -17287,10 +17299,21 @@ namespace BinaryNinja {
1728717299
with knowledge of the types in the Type Container.
1728817300

1728917301
\param source Source code to parse
17302+
\param importDependencies If Type Library / Type Archive types should be imported during parsing
1729017303
\param result Reference into which the resulting type and name will be written
1729117304
\param errors Reference to a list into which any parse errors will be written
1729217305
\return True if parsing was successful
1729317306
*/
17307+
bool ParseTypeString(
17308+
const std::string& source,
17309+
bool importDependencies,
17310+
QualifiedNameAndType& result,
17311+
std::vector<TypeParserError>& errors
17312+
);
17313+
17314+
/*!
17315+
\deprecated Use `ParseTypeString` with the extra `importDependencies` param
17316+
*/
1729417317
bool ParseTypeString(
1729517318
const std::string& source,
1729617319
QualifiedNameAndType& result,
@@ -17305,10 +17328,25 @@ namespace BinaryNinja {
1730517328
\param options Optional string arguments to pass as options, e.g. command line arguments
1730617329
\param includeDirs Optional list of directories to include in the header search path
1730717330
\param autoTypeSource Optional source of types if used for automatically generated types
17331+
\param importDependencies If Type Library / Type Archive types should be imported during parsing
1730817332
\param result Reference to structure into which the results will be written
1730917333
\param errors Reference to a list into which any parse errors will be written
1731017334
\return True if successful
1731117335
*/
17336+
bool ParseTypesFromSource(
17337+
const std::string& text,
17338+
const std::string& fileName,
17339+
const std::vector<std::string>& options,
17340+
const std::vector<std::string>& includeDirs,
17341+
const std::string& autoTypeSource,
17342+
bool importDependencies,
17343+
TypeParserResult& result,
17344+
std::vector<TypeParserError>& errors
17345+
);
17346+
17347+
/*!
17348+
\deprecated Use `ParseTypesFromSource` with the extra `importDependencies` param
17349+
*/
1731217350
bool ParseTypesFromSource(
1731317351
const std::string& text,
1731417352
const std::string& fileName,

binaryninjacore.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 57
40+
#define BN_CURRENT_CORE_ABI_VERSION 58
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 57
47+
#define BN_MINIMUM_CORE_ABI_VERSION 58
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -932,7 +932,10 @@ extern "C"
932932
SrcInstructionUsesPointerAuth = 0x10,
933933

934934
// Prevents alias analysis from being performed on the instruction
935-
ILPreventAliasAnalysis = 0x20
935+
ILPreventAliasAnalysis = 0x20,
936+
937+
// Set on and instruction that has been re-written to clarify ControlFlowGuard constructs
938+
ILIsCFGProtected = 0x40
936939
} BNILInstructionAttribute;
937940

938941
typedef enum BNIntrinsicClass
@@ -2723,22 +2726,22 @@ extern "C"
27232726
bool (*getOptionText)(void* ctxt, BNTypeParserOption option, const char* value, char** result);
27242727
bool (*preprocessSource)(void* ctxt,
27252728
const char* source, const char* fileName, BNPlatform* platform,
2726-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
2729+
BNTypeContainer* existingTypes,
27272730
const char* const* options, size_t optionCount,
27282731
const char* const* includeDirs, size_t includeDirCount,
27292732
char** output, BNTypeParserError** errors, size_t* errorCount
27302733
);
27312734
bool (*parseTypesFromSource)(void* ctxt,
27322735
const char* source, const char* fileName, BNPlatform* platform,
2733-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
2736+
BNTypeContainer* existingTypes,
27342737
const char* const* options, size_t optionCount,
27352738
const char* const* includeDirs, size_t includeDirCount,
27362739
const char* autoTypeSource, BNTypeParserResult* result,
27372740
BNTypeParserError** errors, size_t* errorCount
27382741
);
27392742
bool (*parseTypeString)(void* ctxt,
27402743
const char* source, BNPlatform* platform,
2741-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
2744+
BNTypeContainer* existingTypes,
27422745
BNQualifiedNameAndType* result,
27432746
BNTypeParserError** errors, size_t* errorCount
27442747
);
@@ -3140,6 +3143,7 @@ extern "C"
31403143
TypeArchiveTypeContainerType,
31413144
DebugInfoTypeContainerType,
31423145
PlatformTypeContainerType,
3146+
OtherTypeContainerType
31433147
} BNTypeContainerType;
31443148

31453149
typedef enum BNSyncStatus
@@ -4661,10 +4665,10 @@ extern "C"
46614665
BINARYNINJACOREAPI bool BNGetDataVariableAtAddress(BNBinaryView* view, uint64_t addr, BNDataVariable* var);
46624666

46634667
BINARYNINJACOREAPI bool BNParseTypeString(BNBinaryView* view, const char* text, BNQualifiedNameAndType* result,
4664-
char** errors, BNQualifiedNameList* typesAllowRedefinition);
4668+
char** errors, BNQualifiedNameList* typesAllowRedefinition, bool importDepencencies);
46654669
BINARYNINJACOREAPI bool BNParseTypesString(BNBinaryView* view, const char* text, const char* const* options, size_t optionCount,
46664670
const char* const* includeDirs, size_t includeDirCount, BNTypeParserResult* result, char** errors,
4667-
BNQualifiedNameList* typesAllowRedefinition);
4671+
BNQualifiedNameList* typesAllowRedefinition, bool importDepencencies);
46684672
BINARYNINJACOREAPI void BNFreeQualifiedNameAndType(BNQualifiedNameAndType* obj);
46694673
BINARYNINJACOREAPI void BNFreeQualifiedNameAndTypeArray(BNQualifiedNameAndType* obj, size_t count);
46704674
BINARYNINJACOREAPI void BNFreeQualifiedNameTypeAndId(BNQualifiedNameTypeAndId* obj);
@@ -4745,14 +4749,14 @@ extern "C"
47454749
BINARYNINJACOREAPI bool BNTypeContainerGetTypeNames(BNTypeContainer* container, BNQualifiedName** typeNames, size_t* count);
47464750
BINARYNINJACOREAPI bool BNTypeContainerGetTypeNamesAndIds(BNTypeContainer* container, char*** typeIds, BNQualifiedName** typeNames, size_t* count);
47474751
BINARYNINJACOREAPI bool BNTypeContainerParseTypeString(BNTypeContainer* container,
4748-
const char* source, BNQualifiedNameAndType* result,
4752+
const char* source, bool importDepencencies, BNQualifiedNameAndType* result,
47494753
BNTypeParserError** errors, size_t* errorCount
47504754
);
47514755
BINARYNINJACOREAPI bool BNTypeContainerParseTypesFromSource(BNTypeContainer* container,
47524756
const char* source, const char* fileName,
47534757
const char* const* options, size_t optionCount,
47544758
const char* const* includeDirs, size_t includeDirCount,
4755-
const char* autoTypeSource, BNTypeParserResult* result,
4759+
const char* autoTypeSource, bool importDepencencies, BNTypeParserResult* result,
47564760
BNTypeParserError** errors, size_t* errorCount
47574761
);
47584762

@@ -5987,22 +5991,22 @@ extern "C"
59875991
const char* value, char** result);
59885992
BINARYNINJACOREAPI bool BNTypeParserPreprocessSource(BNTypeParser* parser,
59895993
const char* source, const char* fileName, BNPlatform* platform,
5990-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
5994+
BNTypeContainer* existingTypes,
59915995
const char* const* options, size_t optionCount,
59925996
const char* const* includeDirs, size_t includeDirCount,
59935997
char** output, BNTypeParserError** errors, size_t* errorCount
59945998
);
59955999
BINARYNINJACOREAPI bool BNTypeParserParseTypesFromSource(BNTypeParser* parser,
59966000
const char* source, const char* fileName, BNPlatform* platform,
5997-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
6001+
BNTypeContainer* existingTypes,
59986002
const char* const* options, size_t optionCount,
59996003
const char* const* includeDirs, size_t includeDirCount,
60006004
const char* autoTypeSource, BNTypeParserResult* result,
60016005
BNTypeParserError** errors, size_t* errorCount
60026006
);
60036007
BINARYNINJACOREAPI bool BNTypeParserParseTypeString(BNTypeParser* parser,
60046008
const char* source, BNPlatform* platform,
6005-
const BNQualifiedNameTypeAndId* existingTypes, size_t existingTypeCount,
6009+
BNTypeContainer* existingTypes,
60066010
BNQualifiedNameAndType* result,
60076011
BNTypeParserError** errors, size_t* errorCount
60086012
);

binaryview.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ bool BinaryView::ParsePossibleValueSet(
37173717

37183718

37193719
bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& result, string& errors,
3720-
const std::set<QualifiedName>& typesAllowRedefinition)
3720+
const std::set<QualifiedName>& typesAllowRedefinition, bool importDependencies)
37213721
{
37223722
BNQualifiedNameAndType nt;
37233723
char* errorStr;
@@ -3732,7 +3732,7 @@ bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& resul
37323732
i++;
37333733
}
37343734

3735-
if (!BNParseTypeString(m_object, text.c_str(), &nt, &errorStr, &typesList))
3735+
if (!BNParseTypeString(m_object, text.c_str(), &nt, &errorStr, &typesList, importDependencies))
37363736
{
37373737
errors = errorStr;
37383738
BNFreeString(errorStr);
@@ -3751,7 +3751,7 @@ bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& resul
37513751

37523752
bool BinaryView::ParseTypeString(const string& source, map<QualifiedName, Ref<Type>>& types,
37533753
map<QualifiedName, Ref<Type>>& variables, map<QualifiedName, Ref<Type>>& functions, string& errors,
3754-
const std::set<QualifiedName>& typesAllowRedefinition)
3754+
const std::set<QualifiedName>& typesAllowRedefinition, bool importDependencies)
37553755
{
37563756
BNTypeParserResult result;
37573757
char* errorStr = nullptr;
@@ -3774,7 +3774,7 @@ bool BinaryView::ParseTypeString(const string& source, map<QualifiedName, Ref<Ty
37743774
vector<const char*> includeDirs;
37753775

37763776
bool ok = BNParseTypesString(m_object, source.c_str(), options.data(), options.size(),
3777-
includeDirs.data(), includeDirs.size(), &result, &errorStr, &typesList);
3777+
includeDirs.data(), includeDirs.size(), &result, &errorStr, &typesList, importDependencies);
37783778
if (errorStr)
37793779
{
37803780
errors = errorStr;
@@ -3805,7 +3805,7 @@ bool BinaryView::ParseTypeString(const string& source, map<QualifiedName, Ref<Ty
38053805

38063806

38073807
bool BinaryView::ParseTypesFromSource(const string& source, const vector<string>& options, const vector<string>& includeDirs,
3808-
TypeParserResult& result, string& errors, const std::set<QualifiedName>& typesAllowRedefinition)
3808+
TypeParserResult& result, string& errors, const std::set<QualifiedName>& typesAllowRedefinition, bool importDependencies)
38093809
{
38103810
BNQualifiedNameList typesList;
38113811
typesList.count = typesAllowRedefinition.size();
@@ -3829,7 +3829,7 @@ bool BinaryView::ParseTypesFromSource(const string& source, const vector<string>
38293829
char* errorStr = nullptr;
38303830

38313831
bool ok = BNParseTypesString(m_object, source.c_str(), coreOptions.data(), coreOptions.size(),
3832-
coreIncludeDirs.data(), coreIncludeDirs.size(), &apiResult, &errorStr, &typesList);
3832+
coreIncludeDirs.data(), coreIncludeDirs.size(), &apiResult, &errorStr, &typesList, importDependencies);
38333833
if (errorStr)
38343834
{
38353835
errors = errorStr;

0 commit comments

Comments
 (0)