typeparser module

binaryninja.typeparser.BasicTypeParserResult(...)

binaryninja.typeparser.CoreTypeParser([handle])

binaryninja.typeparser.ParsedType(name, ...)

binaryninja.typeparser.QualifiedNameTypeAndId(...)

binaryninja.typeparser.Settings([...])

Settings provides a way to define and access settings in a hierarchical fashion.

binaryninja.typeparser.TypeParser([handle])

binaryninja.typeparser.TypeParserError(...)

binaryninja.typeparser.TypeParserResult(...)

class BasicTypeParserResult(types: Dict[ForwardRef('types.QualifiedName'), ForwardRef('types.Type')], variables: Dict[ForwardRef('types.QualifiedName'), ForwardRef('types.Type')], functions: Dict[ForwardRef('types.QualifiedName'), ForwardRef('types.Type')])[source]

Bases: object

Parameters
Return type

None

functions: Dict[QualifiedName, Type]
types: Dict[QualifiedName, Type]
variables: Dict[QualifiedName, Type]
class CoreTypeParser(handle=None)[source]

Bases: binaryninja.typeparser.TypeParser

get_option_text(option: TypeParserOption, value: str) Optional[str][source]

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

Parameters
Returns

A string representing the option if the parser supports it, otherwise None

Return type

Optional[str]

parse_type_string(source: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None) Tuple[Optional[Tuple[Union[Iterable[Union[str, bytes]], str, QualifiedName], Type]], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to parse

  • platform (Platform) – Platform to assume the types are relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

Returns

A tuple of (result, errors) where result is a tuple of (type, name) or None of there was a fatal error.

Return type

Tuple[Optional[Tuple[Union[Iterable[Union[str, bytes]], str, QualifiedName], Type]], List[TypeParserError]]

parse_types_from_source(source: str, file_name: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None, options: Optional[List[str]] = None, include_dirs: Optional[List[str]] = None, auto_type_source: str = '') Tuple[Optional[TypeParserResult], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to parse

  • file_name (str) – Name of the file containing the source (optional: exists on disk)

  • platform (Platform) – Platform to assume the types are relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

  • options (Optional[List[str]]) – Optional string arguments to pass as options, e.g. command line arguments

  • include_dirs (Optional[List[str]]) – Optional list of directories to include in the header search path

  • auto_type_source (str) – Optional source of types if used for automatically generated types

Returns

A tuple of (result, errors) where the result is None if there was a fatal error

Return type

Tuple[Optional[TypeParserResult], List[TypeParserError]]

preprocess_source(source: str, file_name: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None, options: Optional[List[str]] = None, include_dirs: Optional[List[str]] = None) Tuple[Optional[str], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to process

  • file_name (str) – Name of the file containing the source (does not need to exist on disk)

  • platform (Platform) – Platform to assume the source is relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

  • options (Optional[List[str]]) – Optional string arguments to pass as options, e.g. command line arguments

  • include_dirs (Optional[List[str]]) – Optional list of directories to include in the header search path

Returns

A tuple of (preproccessed source, errors), where the preproccessed source is None if there was a fatal error.

Return type

Tuple[Optional[str], List[TypeParserError]]

class ParsedType(name: 'types.QualifiedNameType', type: 'types.Type', is_user: bool)[source]

Bases: object

Parameters
Return type

None

is_user: bool
name: Union[Iterable[Union[str, bytes]], str, QualifiedName]
type: Type
class QualifiedNameTypeAndId(name: 'types.QualifiedNameType', id: str, type: 'types.Type')[source]

Bases: object

Parameters
Return type

None

id: str
name: Union[Iterable[Union[str, bytes]], str, QualifiedName]
type: Type
class TypeParser(handle=None)[source]

Bases: object

get_option_text(option: TypeParserOption, value: str) Optional[str][source]

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

Parameters
Returns

A string representing the option if the parser supports it, otherwise None

Return type

Optional[str]

parse_type_string(source: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None) Tuple[Optional[Tuple[Union[Iterable[Union[str, bytes]], str, QualifiedName], Type]], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to parse

  • platform (Platform) – Platform to assume the types are relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

Returns

A tuple of (result, errors) where result is a tuple of (type, name) or None of there was a fatal error.

Return type

Tuple[Optional[Tuple[Union[Iterable[Union[str, bytes]], str, QualifiedName], Type]], List[TypeParserError]]

parse_types_from_source(source: str, file_name: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None, options: Optional[List[str]] = None, include_dirs: Optional[List[str]] = None, auto_type_source: str = '') Tuple[Optional[TypeParserResult], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to parse

  • file_name (str) – Name of the file containing the source (optional: exists on disk)

  • platform (Platform) – Platform to assume the types are relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

  • options (Optional[List[str]]) – Optional string arguments to pass as options, e.g. command line arguments

  • include_dirs (Optional[List[str]]) – Optional list of directories to include in the header search path

  • auto_type_source (str) – Optional source of types if used for automatically generated types

Returns

A tuple of (result, errors) where the result is None if there was a fatal error

Return type

Tuple[Optional[TypeParserResult], List[TypeParserError]]

preprocess_source(source: str, file_name: str, platform: Platform, existing_types: Optional[List[QualifiedNameTypeAndId]] = None, options: Optional[List[str]] = None, include_dirs: Optional[List[str]] = None) Tuple[Optional[str], List[TypeParserError]][source]

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

Parameters
  • source (str) – Source code to process

  • file_name (str) – Name of the file containing the source (does not need to exist on disk)

  • platform (Platform) – Platform to assume the source is relevant to

  • existing_types (Optional[List[QualifiedNameTypeAndId]]) – Optional map of all existing types to use for parsing context

  • options (Optional[List[str]]) – Optional string arguments to pass as options, e.g. command line arguments

  • include_dirs (Optional[List[str]]) – Optional list of directories to include in the header search path

Returns

A tuple of (preproccessed source, errors), where the preproccessed source is None if there was a fatal error.

Return type

Tuple[Optional[str], List[TypeParserError]]

register()[source]

Register a custom parser with the API

name = None
class TypeParserError(severity: TypeParserErrorSeverity, message: str, file_name: str, line: int, column: int)[source]

Bases: object

Parameters
Return type

None

column: int
file_name: str
line: int
message: str
severity: TypeParserErrorSeverity
class TypeParserResult(types: List[ParsedType], variables: List[ParsedType], functions: List[ParsedType])[source]

Bases: object

Parameters
Return type

None

functions: List[ParsedType]
types: List[ParsedType]
variables: List[ParsedType]
preprocess_source(source: str, filename: Optional[str] = None, include_dirs: Optional[List[str]] = None) Tuple[Optional[str], str][source]

preprocess_source run the C preprocessor on the given source or source filename.

Parameters
  • source (str) – source to pre-process

  • filename (str) – optional filename to pre-process

  • include_dirs (list(str)) – list of string directories to use as include directories.

Returns

returns a tuple of (preprocessed_source, error_string)

Return type

tuple(str,str)

Example
>>> source = "#define TEN 10\nint x[TEN];\n"
>>> preprocess_source(source)
('#line 1 "input"\n\n#line 2 "input"\n int x [ 10 ] ;\n', '')
>>>
to_bytes(field)[source]