示例#1
0
def executeSnippet(code, description):
    #Get UI context, try currently selected otherwise default to the first one if the snippet widget is selected.
    ctx = UIContext.activeContext()
    dummycontext = {
        'binaryView': None,
        'address': None,
        'function': None,
        'token': None,
        'lowLevelILFunction': None,
        'mediumLevelILFunction': None
    }
    if not ctx:
        ctx = UIContext.allContexts()[0]
    if not ctx:
        #There is no tab open at all but we still want other snippest to run that don't rely on context.
        context = namedtuple("context",
                             dummycontext.keys())(*dummycontext.values())

    else:
        handler = ctx.contentActionHandler()
        if handler:
            context = handler.actionContext()
        else:
            context = namedtuple("context",
                                 dummycontext.keys())(*dummycontext.values())

    snippetGlobals = setupGlobals(context)

    SnippetTask(code, snippetGlobals, context, snippetName=description).start()
示例#2
0
    def current_function(self, message_box=False) -> Optional[Function]:
        all_contexts = UIContext.allContexts()
        if not all_contexts:
            if message_box:
                show_message_box(
                    "UI contexts not found",
                    "No UI context is available. Please open a binary first.",
                    MessageBoxButtonSet.OKButtonSet,
                    MessageBoxIcon.ErrorIcon,
                )
            return
        ctx = all_contexts[0]
        handler = ctx.contentActionHandler()
        if handler is None:
            if message_box:
                show_message_box(
                    "Action handler not found",
                    "No action handler is available. Please open a binary first.",
                    MessageBoxButtonSet.OKButtonSet,
                    MessageBoxIcon.ErrorIcon,
                )
            return
        actionContext = handler.actionContext()
        func = actionContext.function
        if func is None:
            if message_box:
                show_message_box(
                    "No function is in selection",
                    "Please navigate to a function in the disassembly view.",
                    MessageBoxButtonSet.OKButtonSet,
                    MessageBoxIcon.ErrorIcon,
                )
            return None

        return func
示例#3
0
    def init(self):
        self.raw = self.data
        self.binary = self.raw.read(0, len(self.raw))
        macho_list = self.get_macho_names(self.data, len(self.raw))

        print(f"Found {len(macho_list)} apps")
        [print(f" - {macho}") for macho in macho_list]

        offset = self.get_header_offset()
        sep_fw_header = self.get_fw_header(offset)
        offset += 0xC8

        choice = interaction.get_choice_input("sep-firmware modules",
                                              "choices", macho_list)
        if choice is not None:
            print(f"extracting {macho_list[choice]}")
            if choice == 0:
                app = self.extract_sepos_kernel(sep_fw_header)
            elif choice == 1:
                app = self.extract_sepos_root(sep_fw_header)
            else:
                name = macho_list[choice]
                app = self.process_apps(sep_fw_header, offset, name, choice)

            mainthread.execute_on_main_thread_and_wait(
                lambda: UIContext.allContexts()[0].openFilename(app))
        else:
            return False
        return True
示例#4
0
    def active_context(self):
        all_contexts = UIContext.allContexts()
        if not all_contexts:
            return None

        ctx = all_contexts[0]
        handler = ctx.contentActionHandler()
        if handler is None:
            return None

        actionContext = handler.actionContext()
        func = actionContext.function
        if func is None:
            return None

        return binsync.data.Function(func.start,
                                     0,
                                     header=FunctionHeader(
                                         func.name, func.start))
示例#5
0
def open_file_tab(filename: str):
    # TODO: Save libc analysis? (Renaming symbols might cause some issues...)
    execute_on_main_thread_and_wait(
        lambda: UIContext.allContexts()[0].openFilename(filename)
    )