datarender module¶
|
DataRenderer objects tell the Linear View how to render specific types. |
|
- class DataRenderer(context=None)[source]¶
Bases:
object
DataRenderer objects tell the Linear View how to render specific types.
The perform_is_valid_for_data method returns a boolean to indicate if your derived class is able to render the type, given the addr and context. The context is a list of Type objects which represents the chain of nested objects that is being displayed.
The perform_get_lines_for_data method returns a list of DisassemblyTextLine objects each one representing a single line of Linear View output. The prefix variable is a list of InstructionTextToken’s which have already been generated by other DataRenderer’s.
After defining the DataRenderer subclass you must then register it with the core. This is done by calling either register_type_specific or register_generic. A “generic” type renderer is able to be overridden by a “type specific” renderer. For instance there is a generic struct render which renders any struct that hasn’t been explicitly overridden by a “type specific” renderer.
In the below example we create a data renderer that overrides the default display for struct BAR:
class BarDataRenderer(DataRenderer): def __init__(self): DataRenderer.__init__(self) def perform_is_valid_for_data(self, ctxt, view, addr, type, context): return DataRenderer.is_type_of_struct_name(type, "BAR", context) def perform_get_lines_for_data(self, ctxt, view, addr, type, prefix, width, context, language): prefix.append(InstructionTextToken(InstructionTextTokenType.TextToken, "I'm in ur BAR")) return [DisassemblyTextLine(prefix, addr)] def __del__(self): pass BarDataRenderer().register_type_specific()
Note that the formatting is sub-optimal to work around an issue with Sphinx and reStructured text