languagerepresentation module¶
|
|
|
|
|
|
|
|
- class CoreLanguageRepresentationFunctionType(handle: LP_BNLanguageRepresentationFunctionType)[source]¶
Bases:
LanguageRepresentationFunctionType
- Parameters:
handle (LP_BNLanguageRepresentationFunctionType) –
- create(arch: Architecture, owner: Function, hlil: HighLevelILFunction) LanguageRepresentationFunction [source]¶
This method must be overridden. This creates the
class LanguageRepresentationFunction
object for the given architecture, owner function, and High Level IL function.- Parameters:
arch (Architecture) –
owner (Function) –
hlil (HighLevelILFunction) –
- Return type:
- function_type_tokens(func: Function, settings: DisassemblySettings | None) List[DisassemblyTextLine] [source]¶
Returns a list of lines representing a function prototype in this language. If no lines are returned, the default C-style prototype will be used.
- Parameters:
func (Function) –
settings (DisassemblySettings | None) –
- Return type:
- is_valid(view: BinaryView) bool [source]¶
Returns whether the language is valid for the given binary view.
- Parameters:
view (BinaryView) –
- Return type:
- property type_parser: TypeParser | None¶
Returns the type parser for parsing types in this language. If
None
is returned, the default type parser will be used.
- property type_printer: TypePrinter | None¶
Returns the type printer for displaying types in this language. If
None
is returned, the default type printer will be used.
- class HighLevelILTokenEmitter(handle: LP_BNHighLevelILTokenEmitter)[source]¶
Bases:
object
class HighLevelILTokenEmitter
contains methods for emitting text tokens for High Level IL instructions. Methods are provided for typical patterns found in various high level languages.This class cannot be instantiated directly. An instance of the class will be provided when the methods in
class LanguageRepresentationFunction
are called.- Parameters:
handle (LP_BNHighLevelILTokenEmitter) –
- class ExprContext(emitter: HighLevelILTokenEmitter, hlil_expr: HighLevelILInstruction)[source]¶
Bases:
object
class ExprContext
is a context manager that associates the tokens inside the context with the given High Level IL expression.- Parameters:
emitter (HighLevelILTokenEmitter) –
hlil_expr (HighLevelILInstruction) –
- class ZeroConfidenceContext(emitter: HighLevelILTokenEmitter, enabled: bool)[source]¶
Bases:
object
class ZeroConfidenceContext
is a context manager that optionally forces tokens to be of zero confidence inside the context.- Parameters:
emitter (HighLevelILTokenEmitter) –
enabled (bool) –
- append(tokens: InstructionTextToken | List[InstructionTextToken])[source]¶
Appends a token or list of tokens to the output.
- Parameters:
tokens (InstructionTextToken | List[InstructionTextToken]) –
- append_array_index_token(instr: HighLevelILInstruction, value: int, size: int, address: int = 0)[source]¶
Appends tokens for accessing an array by index.
- Parameters:
instr (HighLevelILInstruction) –
value (int) –
size (int) –
address (int) –
- append_constant_text_token(instr: HighLevelILInstruction, value: int, size: int, settings: DisassemblySettings | None, precedence: OperatorPrecedence)[source]¶
Appends tokens for a constant value.
- Parameters:
instr (HighLevelILInstruction) –
value (int) –
size (int) –
settings (DisassemblySettings | None) –
precedence (OperatorPrecedence) –
- append_float_size_token(size: int, token_type: InstructionTextTokenType)[source]¶
Appends a floating point size token for the given size in the High Level IL syntax.
- Parameters:
size (int) –
token_type (InstructionTextTokenType) –
- append_integer_text_token(instr: HighLevelILInstruction, value: int, size: int)[source]¶
Appends tokens for a constant intenger value.
- Parameters:
instr (HighLevelILInstruction) –
value (int) –
size (int) –
- append_pointer_text_token(instr: HighLevelILInstruction, value: int, settings: DisassemblySettings | None, symbol_display: SymbolDisplayType, precedence: OperatorPrecedence, allow_short_string: bool = False) SymbolDisplayResult [source]¶
Appends tokens for displaying a constant pointer value.
- Parameters:
instr (HighLevelILInstruction) –
value (int) –
settings (DisassemblySettings | None) –
symbol_display (SymbolDisplayType) –
precedence (OperatorPrecedence) –
allow_short_string (bool) –
- Return type:
- append_size_token(size: int, token_type: InstructionTextTokenType)[source]¶
Appends a size token for the given size in the High Level IL syntax.
- Parameters:
size (int) –
token_type (InstructionTextTokenType) –
- append_var_text_token(var: CoreVariable, instr: HighLevelILInstruction, size: int)[source]¶
Appends tokens for access to a variable.
- Parameters:
var (CoreVariable) –
instr (HighLevelILInstruction) –
size (int) –
- begin_scope(scope_type: ScopeType)[source]¶
Begins a new scope. Insertion of newlines and braces will be handled using the current settings.
- Parameters:
scope_type (ScopeType) –
- end_scope(scope_type: ScopeType)[source]¶
Ends the current scope.
- Parameters:
scope_type (ScopeType) –
- expr(hlil_expr: HighLevelILInstruction) ExprContext [source]¶
Returns a context manager that associates the tokens inside the context with the given High Level IL expression.
- Parameters:
hlil_expr (HighLevelILInstruction) –
- Return type:
- finalize_scope()[source]¶
Finalizes the previous scope, indicating that there are no more associated scopes.
- force_zero_confidence(enabled: bool = True) ZeroConfidenceContext [source]¶
Returns a context manager that forces tokens inside of it to be of zero confidence. If
False
is passed to this method, the context has no effect, allowing the caller to conditionally apply this behavior.- Parameters:
enabled (bool) –
- Return type:
- static names_for_outer_structure_members(view: BinaryView, struct_type: Type, var: HighLevelILInstruction) List[str] [source]¶
Gets the list of names for the outer structure members when accessing a structure member. This list can be passed for the
typeNames
parameter of theclass InstructionTextToken
constructor.- Parameters:
view (BinaryView) –
struct_type (Type) –
var (HighLevelILInstruction) –
- Return type:
- scope_continuation(force_same_line: bool)[source]¶
Continues the previous scope with a new associated scope. This is most commonly used for
else
statements.- Parameters:
force_same_line (bool) –
- scope_separator()[source]¶
Indicates that visual separation of scopes is desirable at the current position. By default, this will insert a blank line, but this can be configured by the user.
- property brace_requirement: BraceRequirement¶
The requirement for insertion of braces around scopes in the output.
- property braces_around_switch_cases¶
Whether cases within switch statements should always have braces around them.
- property current_tokens: List[InstructionTextToken]¶
The list of tokens on the current line (read-only).
- property default_braces_on_same_line¶
Whether braces should default to being on the same line as the statement that begins the scope. If the user has explicitly set a preference, this setting will be ignored and the user’s preference will be used instead.
- property lines: List[DisassemblyTextLine]¶
The list of lines in the output (read-only).
- property simple_scope_allowed¶
Whether omitting braces around single-line scopes is allowed.
- class LanguageRepresentationFunction(arch: Architecture | None = None, owner: Function | None = None, hlil: HighLevelILFunction | None = None, handle=None)[source]¶
Bases:
object
class LanguageRepresentationFunction
represents a single function in a registered high level language.- Parameters:
arch (Architecture | None) –
owner (Function | None) –
hlil (HighLevelILFunction | None) –
- get_block_lines(block: HighLevelILBasicBlock, settings: DisassemblySettings | None = None) List[DisassemblyTextLine] [source]¶
Generates lines for a single High Level IL basic block.
- Parameters:
block (HighLevelILBasicBlock) –
settings (DisassemblySettings | None) –
- Return type:
- get_expr_text(instr: HighLevelILInstruction, settings: DisassemblySettings | None, precedence: OperatorPrecedence = OperatorPrecedence.TopLevelOperatorPrecedence, statement: bool = False) List[DisassemblyTextLine] [source]¶
Gets the lines of tokens for a given High Level IL instruction.
- Parameters:
instr (HighLevelILInstruction) –
settings (DisassemblySettings | None) –
precedence (OperatorPrecedence) –
statement (bool) –
- Return type:
- get_linear_lines(instr: HighLevelILInstruction, settings: DisassemblySettings | None = None) List[DisassemblyTextLine] [source]¶
Generates lines for the given High Level IL instruction in the style of the linear view. To get the lines for the entire function, pass the
root
property of aclass HighLevelILFunction
.- Parameters:
instr (HighLevelILInstruction) –
settings (DisassemblySettings | None) –
- Return type:
- perform_begin_lines(instr: HighLevelILInstruction, tokens: HighLevelILTokenEmitter)[source]¶
This method can be overridden to emit tokens at the start of a function.
- Parameters:
instr (HighLevelILInstruction) –
tokens (HighLevelILTokenEmitter) –
- perform_end_lines(instr: HighLevelILInstruction, tokens: HighLevelILTokenEmitter)[source]¶
This method can be overridden to emit tokens at the end of a function.
- Parameters:
instr (HighLevelILInstruction) –
tokens (HighLevelILTokenEmitter) –
- perform_get_expr_text(instr: HighLevelILInstruction, tokens: HighLevelILTokenEmitter, settings: DisassemblySettings | None, precedence: OperatorPrecedence = OperatorPrecedence.TopLevelOperatorPrecedence, statement: bool = False)[source]¶
This method must be overridden by all language representation plugins.
This method is called to emit the tokens for a given High Level IL instruction.
- Parameters:
instr (HighLevelILInstruction) –
tokens (HighLevelILTokenEmitter) –
settings (DisassemblySettings | None) –
precedence (OperatorPrecedence) –
statement (bool) –
- perform_init_token_emitter(emitter: HighLevelILTokenEmitter)[source]¶
Override this method to initialize the options for the token emitter before it is used.
- Parameters:
emitter (HighLevelILTokenEmitter) –
- annotation_end_string = '}'¶
- annotation_start_string = '{'¶
- property arch: Architecture¶
- comment_end_string = ''¶
- comment_start_string = '// '¶
- property high_level_il: HighLevelILFunction¶
- property hlil: HighLevelILFunction¶
- class LanguageRepresentationFunctionType(handle=None)[source]¶
Bases:
object
class LanguageRepresentationFunctionType
represents a custom language representation function type. This class provides methods to createclass LanguageRepresentationFunction
instances for functions, as well as manage the printing and parsing of types.- create(arch: Architecture, owner: Function, hlil: HighLevelILFunction) LanguageRepresentationFunction [source]¶
This method must be overridden. This creates the
class LanguageRepresentationFunction
object for the given architecture, owner function, and High Level IL function.- Parameters:
arch (Architecture) –
owner (Function) –
hlil (HighLevelILFunction) –
- Return type:
- function_type_tokens(func: Function, settings: DisassemblySettings | None) List[DisassemblyTextLine] [source]¶
Returns a list of lines representing a function prototype in this language. If no lines are returned, the default C-style prototype will be used.
- Parameters:
func (Function) –
settings (DisassemblySettings | None) –
- Return type:
- is_valid(view: BinaryView) bool [source]¶
Returns whether the language is valid for the given binary view.
- Parameters:
view (BinaryView) –
- Return type:
- language_name = None¶
- property type_parser: TypeParser | None¶
Returns the type parser for parsing types in this language. If
None
is returned, the default type parser will be used.
- property type_printer: TypePrinter | None¶
Returns the type printer for displaying types in this language. If
None
is returned, the default type printer will be used.