MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / init

Method init

python/examples/mappedview.py:98–148  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

96 return load_settings
97
98 def init(self):
99 # The BinaryView init method is invoked as part of the BinaryView creation process. This method is called under several different conditions:
100 # 1) When opening a file/bndb and no load options are provided.
101 # 2) When opening a file/bndb and load options are provided. e.g. 'Open with Options' in the UI, or load
102 # 3) When parsing a file to create an ephemeral BinaryView (self.parse_only == True) for the purpose of extracting header information.
103 # Note: The get_load_settings_for_data classmethod is optional. If provided, it's used to generate load options for the BinaryViewType.
104 # If not provided, then the default load options are automatically generated by the core, extracting information automatically from a parsed BinaryView.
105 # Notice the call to get_default_load_settings_for_data above in get_load_settings_for_data. This will force parsing a file to create an ephemeral BinaryView.
106 # It is also used as a convenience method to pre-populate a Settings object with relevant, generic loader settings that are tagged as 'readOnly'. It is the responsibility,
107 # of the BinaryViewType to communicate and enforce which settings are mutable.
108 if self.parse_only is True:
109 # Perform light-weight parsing to extract required information for load settings generation.
110 # A light-weight parsed view does not get finalized.
111 print("Mapped (Python): init(): perform light-weight parsing")
112 else:
113 # Perform normal BinaryView initialization
114 print("Mapped (Python): init(): perform normal BinaryView initialization")
115
116 # Finish BinaryView initialization using the load settings, if they exist
117 try:
118 load_settings = self.get_load_settings(self.name)
119 if load_settings is None:
120 if self.parse_only is True:
121 self.arch = Architecture['x86'] # type: ignore
122 self.platform = Architecture['x86'].standalone_platform # type: ignore
123 assert self.parent_view is not None
124 self.add_auto_segment(0, len(self.parent_view), 0, len(self.parent_view), SegmentFlag.SegmentReadable)
125 return True
126 else:
127 # Note: If there are no load settings and this is not a parse_only view, it's possible to call get_load_settings_for_data directly.
128 # This allows us to generate default load options for the BinaryView. This step is not required but can be useful.
129 load_settings = self.__class__.get_load_settings_for_data(self.parent_view)
130
131 platform = load_settings.get_string("loader.platform", self)
132 self.platform = Platform[platform]
133 self.arch = self.platform.arch # type: ignore
134 self.load_address = load_settings.get_integer("loader.imageBase", self)
135 self.add_auto_segment(
136 self.load_address, len(self.parent_view), 0, len(self.parent_view),
137 SegmentFlag.SegmentReadable | SegmentFlag.SegmentExecutable
138 )
139 if load_settings.contains("loader.entryPointOffset"):
140 self.entry_point_offset = load_settings.get_integer("loader.entryPointOffset", self)
141 self.add_entry_point(self.load_address + self.entry_point_offset)
142
143 # Note: This MappedView (Python) BinaryView implementation is incomplete. It ignores platform, section, and segment settings.
144 # It's preferred that values saved in the settings system be imageBase agnostic.
145 return True
146 except:
147 log_error(traceback.format_exc())
148 return False
149
150 def perform_get_entry_point(self):
151 if hasattr(self, 'entry_point_offset'):

Callers

nothing calls this directly

Calls 8

log_errorFunction · 0.90
get_load_settingsMethod · 0.80
add_auto_segmentMethod · 0.80
get_stringMethod · 0.45
get_integerMethod · 0.45
containsMethod · 0.45
add_entry_pointMethod · 0.45

Tested by

no test coverage detected