def setup_stack(view: BinaryView, function: LowLevelILFunction) -> None: emulator = view.session_data['emulator'] memory_view = view.session_data['emulator.memory.view'] map_start = 0x1000 map_len = 0x10000 while True: while memory_view.get_segment_at(map_start) is not None: map_start += 0x1000 if any(s.start > map_start and s.start < map_start + map_len for s in memory_view.segments): map_start += 0x1000 continue emulator.map_memory( map_start, map_len, SegmentFlag.SegmentReadable | SegmentFlag.SegmentWritable) break sp = map_start + map_len - view.address_size emulator.write_register(view.arch.stack_pointer, sp) PluginCommand.register_for_low_level_il_function( 'Emulator\\Setup stack', 'Setup Emulator Stack', setup_stack, lambda v, f: v.session_data.get('emulator') is not None)
hooks.remove_hook(emulator, instruction) def remove_function_hook( view: BinaryView, function: LowLevelILFunction ) -> None: emulator = view.session_data.get("emulator") if emulator is None: return hooks.remove_function_hook(emulator, function) PluginCommand.register_for_low_level_il_function( "Emulator\\Load", "Load Emulator", load_emulator ) PluginCommand.register_for_low_level_il_instruction( "Emulator\\Add Hook", "Add an emulator hook for this LLIL instruction", add_hook, ) PluginCommand.register_for_low_level_il_function( "Emulator\\Add Function Hook", "Add an emulator hook for this LLIL function", add_function_hook, ) PluginCommand.register_for_low_level_il_instruction(