TypeParser

Detailed Description

Classes

struct  BinaryNinja::ParsedType
 
struct  BinaryNinja::TypeParserResult
 
struct  BinaryNinja::TypeParserError
 
class  BinaryNinja::TypeParser
 
class  BinaryNinja::CoreTypeParser
 

Class Documentation

◆ BinaryNinja::ParsedType

struct BinaryNinja::ParsedType

Public Member Functions

 ParsedType ()=default
 
 ParsedType (const std::string &name, const Ref< Type > &type, bool isUser)
 
 ParsedType (const QualifiedName &name, const Ref< Type > &type, bool isUser)
 
bool operator< (const ParsedType &other) const
 

Public Attributes

QualifiedName name
 
Ref< Typetype
 
bool isUser
 

Constructor & Destructor Documentation

◆ ParsedType() [1/3]

BinaryNinja::ParsedType::ParsedType ( )
default

◆ ParsedType() [2/3]

BinaryNinja::ParsedType::ParsedType ( const std::string &  name,
const Ref< Type > &  type,
bool  isUser 
)
inline

◆ ParsedType() [3/3]

BinaryNinja::ParsedType::ParsedType ( const QualifiedName name,
const Ref< Type > &  type,
bool  isUser 
)
inline

Member Function Documentation

◆ operator<()

bool BinaryNinja::ParsedType::operator< ( const ParsedType other) const
inline

Member Data Documentation

◆ name

QualifiedName BinaryNinja::ParsedType::name

◆ type

Ref<Type> BinaryNinja::ParsedType::type

◆ isUser

bool BinaryNinja::ParsedType::isUser

◆ BinaryNinja::TypeParserResult

struct BinaryNinja::TypeParserResult
Class Members
vector< ParsedType > types
vector< ParsedType > variables
vector< ParsedType > functions

◆ BinaryNinja::TypeParserError

struct BinaryNinja::TypeParserError

Public Member Functions

 TypeParserError ()=default
 
 TypeParserError (BNTypeParserErrorSeverity severity, const std::string &message)
 

Public Attributes

BNTypeParserErrorSeverity severity
 
std::string message
 
std::string fileName
 
uint64_t line
 
uint64_t column
 

Constructor & Destructor Documentation

◆ TypeParserError() [1/2]

BinaryNinja::TypeParserError::TypeParserError ( )
default

◆ TypeParserError() [2/2]

BinaryNinja::TypeParserError::TypeParserError ( BNTypeParserErrorSeverity  severity,
const std::string &  message 
)
inline

Member Data Documentation

◆ severity

BNTypeParserErrorSeverity BinaryNinja::TypeParserError::severity

◆ message

std::string BinaryNinja::TypeParserError::message

◆ fileName

std::string BinaryNinja::TypeParserError::fileName

◆ line

uint64_t BinaryNinja::TypeParserError::line

◆ column

uint64_t BinaryNinja::TypeParserError::column

◆ BinaryNinja::TypeParser

class BinaryNinja::TypeParser

Public Member Functions

virtual bool GetOptionText (BNTypeParserOption option, std::string value, std::string &result) const
 
virtual bool PreprocessSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, std::string &output, std::vector< TypeParserError > &errors)=0
 Preprocess a block of source, returning the source that would be parsed. More...
 
virtual bool ParseTypesFromSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, const std::string &autoTypeSource, TypeParserResult &result, std::vector< TypeParserError > &errors)=0
 Parse an entire block of source into types, variables, and functions. More...
 
bool ParseTypesFromSourceFile (const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, const std::string &autoTypeSource, TypeParserResult &result, std::vector< TypeParserError > &errors)
 Parse an entire source file into types, variables, and functions. More...
 
virtual bool ParseTypeString (const std::string &source, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, QualifiedNameAndType &result, std::vector< TypeParserError > &errors)=0
 Parse a single type and name from a string containing their definition. More...
 
- Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
 StaticCoreRefCountObject ()
 
virtual ~StaticCoreRefCountObject ()
 
BNTypeParserGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Static Public Member Functions

static void Register (TypeParser *parser)
 
static std::vector< Ref< TypeParser > > GetList ()
 
static Ref< TypeParserGetByName (const std::string &name)
 
static Ref< TypeParserGetDefault ()
 
static std::vector< std::string > ParseOptionsText (const std::string &optionsText)
 Parse a space-separated string of options into a list. More...
 
static std::string FormatParseErrors (const std::vector< TypeParserError > &errors)
 Format a list of parser errors into a big string. More...
 
- Static Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
static BNTypeParserGetObject (StaticCoreRefCountObject *obj)
 

Protected Member Functions

 TypeParser (const std::string &name)
 
 TypeParser (BNTypeParser *parser)
 

Static Protected Member Functions

static bool GetOptionTextCallback (void *ctxt, BNTypeParserOption option, const char *value, char **result)
 
static bool PreprocessSourceCallback (void *ctxt, const char *source, const char *fileName, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, const char *const *options, size_t optionCount, const char *const *includeDirs, size_t includeDirCount, char **output, BNTypeParserError **errors, size_t *errorCount)
 
static bool ParseTypesFromSourceCallback (void *ctxt, const char *source, const char *fileName, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, const char *const *options, size_t optionCount, const char *const *includeDirs, size_t includeDirCount, const char *autoTypeSource, BNTypeParserResult *result, BNTypeParserError **errors, size_t *errorCount)
 
static bool ParseTypeStringCallback (void *ctxt, const char *source, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, BNQualifiedNameAndType *result, BNTypeParserError **errors, size_t *errorCount)
 
static void FreeStringCallback (void *ctxt, char *result)
 
static void FreeResultCallback (void *ctxt, BNTypeParserResult *result)
 
static void FreeErrorListCallback (void *ctxt, BNTypeParserError *errors, size_t errorCount)
 

Additional Inherited Members

- Public Attributes inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
std::atomic< int > m_refs
 
BNTypeParserm_object
 

Constructor & Destructor Documentation

◆ TypeParser() [1/2]

BinaryNinja::TypeParser::TypeParser ( const std::string &  name)
explicitprotected

◆ TypeParser() [2/2]

TypeParser::TypeParser ( BNTypeParser parser)
protected

Member Function Documentation

◆ GetOptionTextCallback()

bool TypeParser::GetOptionTextCallback ( void *  ctxt,
BNTypeParserOption  option,
const char *  value,
char **  result 
)
staticprotected

◆ PreprocessSourceCallback()

bool TypeParser::PreprocessSourceCallback ( void *  ctxt,
const char *  source,
const char *  fileName,
BNPlatform platform,
const BNQualifiedNameTypeAndId existingTypes,
size_t  existingTypeCount,
const char *const *  options,
size_t  optionCount,
const char *const *  includeDirs,
size_t  includeDirCount,
char **  output,
BNTypeParserError **  errors,
size_t *  errorCount 
)
staticprotected

◆ ParseTypesFromSourceCallback()

bool TypeParser::ParseTypesFromSourceCallback ( void *  ctxt,
const char *  source,
const char *  fileName,
BNPlatform platform,
const BNQualifiedNameTypeAndId existingTypes,
size_t  existingTypeCount,
const char *const *  options,
size_t  optionCount,
const char *const *  includeDirs,
size_t  includeDirCount,
const char *  autoTypeSource,
BNTypeParserResult result,
BNTypeParserError **  errors,
size_t *  errorCount 
)
staticprotected

◆ ParseTypeStringCallback()

bool TypeParser::ParseTypeStringCallback ( void *  ctxt,
const char *  source,
BNPlatform platform,
const BNQualifiedNameTypeAndId existingTypes,
size_t  existingTypeCount,
BNQualifiedNameAndType result,
BNTypeParserError **  errors,
size_t *  errorCount 
)
staticprotected

◆ FreeStringCallback()

void TypeParser::FreeStringCallback ( void *  ctxt,
char *  result 
)
staticprotected

◆ FreeResultCallback()

void TypeParser::FreeResultCallback ( void *  ctxt,
BNTypeParserResult result 
)
staticprotected

◆ FreeErrorListCallback()

void TypeParser::FreeErrorListCallback ( void *  ctxt,
BNTypeParserError errors,
size_t  errorCount 
)
staticprotected

◆ Register()

void TypeParser::Register ( TypeParser parser)
static

◆ GetList()

vector< Ref< TypeParser > > TypeParser::GetList ( )
static

◆ GetByName()

Ref< TypeParser > TypeParser::GetByName ( const std::string &  name)
static

◆ GetDefault()

Ref< TypeParser > TypeParser::GetDefault ( )
static

◆ ParseOptionsText()

std::vector< std::string > TypeParser::ParseOptionsText ( const std::string &  optionsText)
static

Parse a space-separated string of options into a list.

Parameters
optionsTextSpace-separated options text
Returns
List of options

◆ FormatParseErrors()

std::string TypeParser::FormatParseErrors ( const std::vector< TypeParserError > &  errors)
static

Format a list of parser errors into a big string.

Parameters
errorsList of errors
Returns
String of formatted errors

◆ GetOptionText()

bool TypeParser::GetOptionText ( BNTypeParserOption  option,
std::string  value,
std::string &  result 
) const
virtual

Get the string representation of an option for passing to ParseTypes*

Parameters
optionOption type
valueOption value
resultString representing the option
Returns
True if the parser supports the option

Reimplemented in BinaryNinja::CoreTypeParser.

◆ PreprocessSource()

virtual bool BinaryNinja::TypeParser::PreprocessSource ( const std::string &  source,
const std::string &  fileName,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
const std::vector< std::string > &  options,
const std::vector< std::string > &  includeDirs,
std::string &  output,
std::vector< TypeParserError > &  errors 
)
pure virtual

Preprocess a block of source, returning the source that would be parsed.

Parameters
sourceSource code to process
fileNameName of the file containing the source (does not need to exist on disk)
platformPlatform to assume the source is relevant to
existingTypesMap of all existing types to use for parsing context
optionsString arguments to pass as options, e.g. command line arguments
includeDirsList of directories to include in the header search path
outputReference to a string into which the preprocessed source will be written
errorsReference to a list into which any parse errors will be written
Returns
True if preprocessing was successful

Implemented in BinaryNinja::CoreTypeParser.

◆ ParseTypesFromSource()

virtual bool BinaryNinja::TypeParser::ParseTypesFromSource ( const std::string &  source,
const std::string &  fileName,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
const std::vector< std::string > &  options,
const std::vector< std::string > &  includeDirs,
const std::string &  autoTypeSource,
TypeParserResult result,
std::vector< TypeParserError > &  errors 
)
pure virtual

Parse an entire block of source into types, variables, and functions.

Parameters
sourceSource code to parse
fileNameName of the file containing the source (optional: exists on disk)
platformPlatform to assume the types are relevant to
existingTypesMap of all existing types to use for parsing context
optionsString arguments to pass as options, e.g. command line arguments
includeDirsList of directories to include in the header search path
autoTypeSourceOptional source of types if used for automatically generated types
resultReference to structure into which the results will be written
errorsReference to a list into which any parse errors will be written
Returns
True if parsing was successful

Implemented in BinaryNinja::CoreTypeParser.

◆ ParseTypesFromSourceFile()

bool TypeParser::ParseTypesFromSourceFile ( const std::string &  fileName,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
const std::vector< std::string > &  options,
const std::vector< std::string > &  includeDirs,
const std::string &  autoTypeSource,
TypeParserResult result,
std::vector< TypeParserError > &  errors 
)

Parse an entire source file into types, variables, and functions.

Parameters
fileNameName of the file on disk containing the source
platformPlatform to assume the types are relevant to
existingTypesMap of all existing types to use for parsing context
optionsString arguments to pass as options, e.g. command line arguments
includeDirsList of directories to include in the header search path
autoTypeSourceOptional source of types if used for automatically generated types
resultReference to structure into which the results will be written
errorsReference to a list into which any parse errors will be written
Returns
True if parsing was successful

◆ ParseTypeString()

virtual bool BinaryNinja::TypeParser::ParseTypeString ( const std::string &  source,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
QualifiedNameAndType result,
std::vector< TypeParserError > &  errors 
)
pure virtual

Parse a single type and name from a string containing their definition.

Parameters
sourceSource code to parse
platformPlatform to assume the types are relevant to
existingTypesMap of all existing types to use for parsing context
resultReference into which the resulting type and name will be written
errorsReference to a list into which any parse errors will be written
Returns
True if parsing was successful

Implemented in BinaryNinja::CoreTypeParser.

◆ BinaryNinja::CoreTypeParser

class BinaryNinja::CoreTypeParser

Public Member Functions

 CoreTypeParser (BNTypeParser *parser)
 
virtual ~CoreTypeParser ()
 
virtual bool GetOptionText (BNTypeParserOption option, std::string value, std::string &result) const override
 
virtual bool PreprocessSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, std::string &output, std::vector< TypeParserError > &errors) override
 Preprocess a block of source, returning the source that would be parsed. More...
 
virtual bool ParseTypesFromSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, const std::string &autoTypeSource, TypeParserResult &result, std::vector< TypeParserError > &errors) override
 Parse an entire block of source into types, variables, and functions. More...
 
virtual bool ParseTypeString (const std::string &source, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, QualifiedNameAndType &result, std::vector< TypeParserError > &errors) override
 Parse a single type and name from a string containing their definition. More...
 
- Public Member Functions inherited from BinaryNinja::TypeParser
virtual bool GetOptionText (BNTypeParserOption option, std::string value, std::string &result) const
 
virtual bool PreprocessSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, std::string &output, std::vector< TypeParserError > &errors)=0
 Preprocess a block of source, returning the source that would be parsed. More...
 
virtual bool ParseTypesFromSource (const std::string &source, const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, const std::string &autoTypeSource, TypeParserResult &result, std::vector< TypeParserError > &errors)=0
 Parse an entire block of source into types, variables, and functions. More...
 
bool ParseTypesFromSourceFile (const std::string &fileName, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, const std::vector< std::string > &options, const std::vector< std::string > &includeDirs, const std::string &autoTypeSource, TypeParserResult &result, std::vector< TypeParserError > &errors)
 Parse an entire source file into types, variables, and functions. More...
 
virtual bool ParseTypeString (const std::string &source, Ref< Platform > platform, const std::map< QualifiedName, TypeAndId > &existingTypes, QualifiedNameAndType &result, std::vector< TypeParserError > &errors)=0
 Parse a single type and name from a string containing their definition. More...
 
- Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
 StaticCoreRefCountObject ()
 
virtual ~StaticCoreRefCountObject ()
 
BNTypeParserGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Additional Inherited Members

- Static Public Member Functions inherited from BinaryNinja::TypeParser
static void Register (TypeParser *parser)
 
static std::vector< Ref< TypeParser > > GetList ()
 
static Ref< TypeParserGetByName (const std::string &name)
 
static Ref< TypeParserGetDefault ()
 
static std::vector< std::string > ParseOptionsText (const std::string &optionsText)
 Parse a space-separated string of options into a list. More...
 
static std::string FormatParseErrors (const std::vector< TypeParserError > &errors)
 Format a list of parser errors into a big string. More...
 
- Static Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
static BNTypeParserGetObject (StaticCoreRefCountObject *obj)
 
- Public Attributes inherited from BinaryNinja::StaticCoreRefCountObject< BNTypeParser >
std::atomic< int > m_refs
 
BNTypeParserm_object
 
- Protected Member Functions inherited from BinaryNinja::TypeParser
 TypeParser (const std::string &name)
 
 TypeParser (BNTypeParser *parser)
 
- Static Protected Member Functions inherited from BinaryNinja::TypeParser
static bool GetOptionTextCallback (void *ctxt, BNTypeParserOption option, const char *value, char **result)
 
static bool PreprocessSourceCallback (void *ctxt, const char *source, const char *fileName, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, const char *const *options, size_t optionCount, const char *const *includeDirs, size_t includeDirCount, char **output, BNTypeParserError **errors, size_t *errorCount)
 
static bool ParseTypesFromSourceCallback (void *ctxt, const char *source, const char *fileName, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, const char *const *options, size_t optionCount, const char *const *includeDirs, size_t includeDirCount, const char *autoTypeSource, BNTypeParserResult *result, BNTypeParserError **errors, size_t *errorCount)
 
static bool ParseTypeStringCallback (void *ctxt, const char *source, BNPlatform *platform, const BNQualifiedNameTypeAndId *existingTypes, size_t existingTypeCount, BNQualifiedNameAndType *result, BNTypeParserError **errors, size_t *errorCount)
 
static void FreeStringCallback (void *ctxt, char *result)
 
static void FreeResultCallback (void *ctxt, BNTypeParserResult *result)
 
static void FreeErrorListCallback (void *ctxt, BNTypeParserError *errors, size_t errorCount)
 

Constructor & Destructor Documentation

◆ CoreTypeParser()

CoreTypeParser::CoreTypeParser ( BNTypeParser parser)

◆ ~CoreTypeParser()

virtual BinaryNinja::CoreTypeParser::~CoreTypeParser ( )
inlinevirtual

Member Function Documentation

◆ GetOptionText()

bool CoreTypeParser::GetOptionText ( BNTypeParserOption  option,
std::string  value,
std::string &  result 
) const
overridevirtual

Get the string representation of an option for passing to ParseTypes*

Parameters
optionOption type
valueOption value
resultString representing the option
Returns
True if the parser supports the option

Reimplemented from BinaryNinja::TypeParser.

◆ PreprocessSource()

bool CoreTypeParser::PreprocessSource ( const std::string &  source,
const std::string &  fileName,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
const std::vector< std::string > &  options,
const std::vector< std::string > &  includeDirs,
std::string &  output,
std::vector< TypeParserError > &  errors 
)
overridevirtual

Preprocess a block of source, returning the source that would be parsed.

Parameters
sourceSource code to process
fileNameName of the file containing the source (does not need to exist on disk)
platformPlatform to assume the source is relevant to
existingTypesMap of all existing types to use for parsing context
optionsString arguments to pass as options, e.g. command line arguments
includeDirsList of directories to include in the header search path
outputReference to a string into which the preprocessed source will be written
errorsReference to a list into which any parse errors will be written
Returns
True if preprocessing was successful

Implements BinaryNinja::TypeParser.

◆ ParseTypesFromSource()

bool CoreTypeParser::ParseTypesFromSource ( const std::string &  source,
const std::string &  fileName,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
const std::vector< std::string > &  options,
const std::vector< std::string > &  includeDirs,
const std::string &  autoTypeSource,
TypeParserResult result,
std::vector< TypeParserError > &  errors 
)
overridevirtual

Parse an entire block of source into types, variables, and functions.

Parameters
sourceSource code to parse
fileNameName of the file containing the source (optional: exists on disk)
platformPlatform to assume the types are relevant to
existingTypesMap of all existing types to use for parsing context
optionsString arguments to pass as options, e.g. command line arguments
includeDirsList of directories to include in the header search path
autoTypeSourceOptional source of types if used for automatically generated types
resultReference to structure into which the results will be written
errorsReference to a list into which any parse errors will be written
Returns
True if parsing was successful

Implements BinaryNinja::TypeParser.

◆ ParseTypeString()

bool CoreTypeParser::ParseTypeString ( const std::string &  source,
Ref< Platform platform,
const std::map< QualifiedName, TypeAndId > &  existingTypes,
QualifiedNameAndType result,
std::vector< TypeParserError > &  errors 
)
overridevirtual

Parse a single type and name from a string containing their definition.

Parameters
sourceSource code to parse
platformPlatform to assume the types are relevant to
existingTypesMap of all existing types to use for parsing context
resultReference into which the resulting type and name will be written
errorsReference to a list into which any parse errors will be written
Returns
True if parsing was successful

Implements BinaryNinja::TypeParser.