Python源码示例:idaapi.Form()

示例1
def __init__(self):
        """Create the starting configuration form."""
        # dialog content
        dialog_content = """%s
                            Please insert the path to configuration directory that holds the *.json files
                            to match against the current binary.

                            <#Select a *.json configs directory for %s exported libraries       #Configs Directory    :{_config_path}>
                            <#Enable this option for binaries compiled for Windows              #Is Windows binary    :{_is_windows}>{_check_group}>
                          """ % (LIBRARY_NAME, LIBRARY_NAME)
        # argument parsing
        args = {
                '_config_path': idaapi.Form.DirInput(swidth=65),
                '_check_group': idaapi.Form.ChkGroupControl(("_is_windows",)),
               }
        idaapi.Form.__init__(self, dialog_content, args) 
示例2
def __init__(self, prepared_entries):
        """Construct the UI Form view, according to the external matching entries.

        Args:
            prepared_entries (list): list of UI rows, including the length for the different columns
        """
        # Using tuples causes this to crash...
        columns = [['Line', 4], ['Source Function Name', 25], ['Binary Address', 14], ['Binary Function Name', 25], ['Matching Rule \\ Information', 35]]
        idaapi.Choose.__init__(self, "%s Matched Externals (LibC)" % (libraryName()), columns, idaapi.Choose.CH_MULTI)
        self.deflt = 0
        self.icon = -1
        self.selcount = 0
        self.modal = False
        self.items = []
        self._entries  = prepared_entries
        # build the table
        for idx, entry in enumerate(prepared_entries):
            self.items.append(["%04d" % (idx + 1), entry[0], ("0x%08X" % (entry[1])) if entry[1] is not None else 'N/A', entry[2], entry[3]])

    # Overridden base function 
示例3
def __init__(self, expr):
        "@expr: Expr instance"

        # Init
        self.languages = list(Translator.available_languages())
        self.expr = expr

        # Initial translation
        text = Translator.to_language(self.languages[0]).from_expr(self.expr)

        # Create the Form
        idaapi.Form.__init__(self, r"""STARTITEM 0
Python Expression
{FormChangeCb}
<Language:{cbLanguage}>
<Translation:{result}>
""", {
            'result': idaapi.Form.MultiLineTextControl(text=text,
                                                       flags=translatorForm.flags),
            'cbLanguage': idaapi.Form.DropdownListControl(
                    items=self.languages,
                    readonly=True,
                    selval=0),
            'FormChangeCb': idaapi.Form.FormChangeCb(self.OnFormChange),
        }) 
示例4
def __init__(self, ioctl, driver):
        idaapi.Form.__init__(
                        self,
                        """Send IOCTL
                        {form_change}
                        <#Input Buffer#~I~nput Buffer:{in_buf}>
                        <#Input Buffer Size#~I~nput Buffer Size:{in_size}>
                        <#Output Buffer#~O~utput Buffer:{out_buf}>
                        <#Output Buffer Size#~O~utput Buffer Size:{out_size}>
                        <#Send IOCTL#~S~end IOCTL:{sendIOCTL}>
                        """, {
                            "form_change": idaapi.Form.FormChangeCb(self.form_change),
                            "in_buf": idaapi.Form.MultiLineTextControl(),
                            "out_buf": idaapi.Form.MultiLineTextControl(),
                            "in_size": idaapi.Form.NumericInput(),
                            "out_size": idaapi.Form.NumericInput(),
                            "sendIOCTL": idaapi.Form.ButtonInput(self.send_ioctl)
                        }
        )
        self.driver = driver
        global ioctl_tracker
        for inst in ioctl_tracker.ioctl_locs:
            value = get_operand_value(inst)
            function = ioctl_decoder.get_function(value)
            if function == int(ioctl[1],16):
                self.ioctl = value
        self.Compile()
        self.in_size.value = 0x20
        self.out_size.value = 0x20
        self.in_buf.value = "\\x41" * 0x20
        self.Execute() 
示例5
def __init__(self, text):
        """Create a basic message box.

        Args:
            text (str): Text to be shown by the message box
        """
        # dialog content
        dialog_content = """%s
                            %s
                          """ % (LIBRARY_NAME, text)
        idaapi.Form.__init__(self, dialog_content, {}) 
示例6
def __init__(self, prepared_entries, suggested_names, rename_fn):
        """Construct the UI Form view, according to the matching entries.

        Args:
            prepared_entries (list): list of UI rows, including the length for the different columns
            suggested_names (dict): suggested names for the renaming: bin ea => name
            rename_fn (func): function handler for renaming the exported functions
        """
        # Using tuples causes this to crash...
        columns = [['Line', 4], ['File Name', 20], ['Source Function Name', 25], ['Binary Address', 14], ['Binary Function Name', 25], ['Matching Rule \\ Information', 35]]
        idaapi.Choose.__init__(self, "%s Matching Results" % (libraryName()), columns, idaapi.Choose.CH_MULTI)
        self.deflt = 0
        self.icon = -1
        self.selcount = 0
        self.modal = False
        self.items = []
        self._entries  = prepared_entries
        self._names    = suggested_names
        self._selected = []
        # build the table
        for idx, entry in enumerate(prepared_entries):
            self.items.append(["%04d" % (idx + 1), entry[0], entry[1], ("0x%08X" % (entry[2])) if entry[2] is not None else 'N/A', entry[3], entry[4]])
        # register additional command handlers
        self._import_selected = self.AddCommand(GUI_CMD_IMPORT_SELECTED)
        self._import_matched  = self.AddCommand(GUI_CMD_IMPORT_MATCHED)
        self._rename_handler  = rename_fn

    # Overridden base function 
示例7
def __init__( self, title, chooser ):

        self.chooser = chooser
        template_instance = PLUGIN_CHOOSER_FORM_TEMPLATE % title
        Form.__init__(self, template_instance, {
            'Chooser' : Form.EmbeddedChooserControl(chooser)
        })


# ------------------------------------------------------------------------------ 
示例8
def prompt_for_segment():
    ''' :returns: a Segment instance, or raises BadInputError '''
    class MyForm(idaapi.Form):
        def __init__(self):
            idaapi.Form.__init__(self, """STARTITEM 0
add segment by buffer

<##buffer path:{path}>
<##segment name:{name}>
<##segment start address:{addr}>
""",
                                 {
                                     'path': idaapi.Form.FileInput(open=True),
                                     'name': idaapi.Form.StringInput(),
                                     'addr': idaapi.Form.NumericInput(tp=Form.FT_ADDR),
                                 })

        def OnFormChange(self, fid):
            return 1

    f = MyForm()
    f.Compile()
    f.path.value = ""
    f.name.value = ""
    f.addr.value = 0x0
    ok = f.Execute()
    if ok != 1:
        raise BadInputError('user cancelled')

    path = f.path.value
    if path == "" or path is None:
        raise BadInputError('bad path provided')

    if not os.path.exists(path):
        raise BadInputError('file doesn\'t exist')

    name = f.name.value
    if name == "" or name is None:
        raise BadInputError('bad name provided')

    addr = f.addr.value
    f.Free()
    return Segment(path, name, addr) 
示例9
def kernelcache_find_virtual_method_overrides(classname=None, method=None):
    import idc
    import idaapi
    import ida_kernelcache as kc

    # Define the form to ask for the arguments.
    class MyForm(idaapi.Form):
        def __init__(self):
            swidth = 40
            idaapi.Form.__init__(self, r"""STARTITEM 0
Find virtual method overrides

<#The class#Class :{classname}>
<#The virtual method#Method:{method}>""", {
                'classname': idaapi.Form.StringInput(tp=idaapi.Form.FT_IDENT, swidth=swidth),
                'method':    idaapi.Form.StringInput(tp=idaapi.Form.FT_IDENT, swidth=swidth),
            })
        def OnFormChange(self, fid):
            return 1

    kc.collect_class_info()

    if any(arg is None for arg in (classname, method)):
        f = MyForm()
        f.Compile()
        f.classname.value = classname or ''
        f.method.value    = method    or ''
        ok = f.Execute()
        if ok != 1:
            print 'Cancelled'
            return False
        classname = f.classname.value
        method    = f.method.value
        f.Free()

    if classname not in kc.class_info:
        print 'Not a valid class: {}'.format(classname)
        return False

    print 'Subclasses of {} that override {}:'.format(classname, method)
    baseinfo = kc.class_info[classname]
    found = False
    for classinfo in baseinfo.descendants():
        for _, override, _ in kc.vtable.class_vtable_overrides(classinfo, superinfo=baseinfo,
                methods=True):
            name = idc.NameEx(idc.BADADDR, override)
            demangled = idc.Demangle(name, idc.GetLongPrm(idc.INF_SHORT_DN))
            name = demangled if demangled else name
            if method in name:
                print '{:#x}  {}'.format(override, classinfo.classname)
                found = True
    if not found:
        print 'No subclass of {} overrides {}'.format(classname, method)
    return found