Exemple #1
0
    def __call__(self):
        local_type = []
        for t in self.local_type:
            if t is not None:
                local_type.append((
                    t[0],
                    Event.encode_bytes(t[1]),
                    Event.encode_bytes(t[2]),
                    Event.encode_bytes(t[3]),
                ))
            else:
                local_type.append(None)

        def alloc_oridinal(target_ordinal):
            # Get_ordinal_qty() will return (current max ordinal + 1)
            missing_ord = (target_ordinal - ida_typeinf.get_ordinal_qty(None) +
                           1)
            if missing_ord > 0:
                ida_typeinf.alloc_type_ordinals(None, missing_ord)

        for t in local_type:
            if t is not None:
                alloc_oridinal(t[0])

                # Can't change some local types if we don't delete them first
                ida_typeinf.del_numbered_type(None, t[0])

                cur_tinfo = ida_typeinf.tinfo_t()
                cur_tinfo.deserialize(None, t[1], t[2])
                cur_tinfo.set_numbered_type(None, t[0], 0, t[3])
                ida_typeinf.import_type(None, -1, t[-1])

        ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #2
0
    def __call__(self):
        new_ranges = {r[0]: r for r in self.sreg_ranges}
        old_ranges = {r[0]: r for r in SgrChanged.get_sreg_ranges(self.rg)}

        start_eas = sorted(
            set(list(new_ranges.keys()) + list(old_ranges.keys())))
        for start_ea in start_eas:
            new_range = new_ranges.get(start_ea, None)
            old_range = old_ranges.get(start_ea, None)

            if new_range and not old_range:
                _, __, val, tag = new_range
                ida_segregs.split_sreg_range(start_ea, self.rg, val, tag, True)

            if not new_range and old_range:
                ida_segregs.del_sreg_range(start_ea, self.rg)

            if new_range and old_range:
                _, __, new_val, new_tag = new_range
                _, __, old_val, old_tag = old_range
                if new_val != old_val or new_tag != old_tag:
                    ida_segregs.split_sreg_range(start_ea, self.rg, new_val,
                                                 new_tag, True)

        ida_kernwin.request_refresh(ida_kernwin.IWID_SEGREGS)
Exemple #3
0
 def __call__(self):
     flags = ida_name.SN_LOCAL if self.local_name else 0
     ida_name.set_name(
         self.ea, Event.encode(self.new_name), flags | ida_name.SN_NOWARN
     )
     ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)
     HexRaysEvent.refresh_pseudocode_view(self.ea)
Exemple #4
0
    def __call__(self):
        local_type = []
        for t in self.local_type:
            if t is not None:
                local_type.append((
                    t[0],
                    Event.encode_bytes(t[1]),
                    Event.encode_bytes(t[2]),
                    Event.encode_bytes(t[3]),
                ))
            else:
                local_type.append(None)

        def alloc_oridinal(target_ordinal):
            # get_ordinal_qty() will return (current max ordinal + 1)
            missing_ord = target_ordinal - ida_typeinf.get_ordinal_qty(
                None) + 1
            if missing_ord > 0:
                ida_typeinf.alloc_type_ordinals(None, missing_ord)

        for t in local_type:
            if t is not None:
                logger.debug("Processing: %s", str(t))
                alloc_oridinal(t[0])

                # Can't change some local types if not delete them first
                # Example: struct aaa{int a;}'
                ida_typeinf.del_numbered_type(None, t[0])

                cur_tinfo = ida_typeinf.tinfo_t()
                cur_tinfo.deserialize(None, t[1], t[2])
                logger.debug("set_numbered_type ret: %d",
                             cur_tinfo.set_numbered_type(None, t[0], 0, t[3]))

        ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #5
0
    def __call__(self):
        from .core import Core

        dll = Core.get_ida_dll()

        get_idati = dll.get_idati
        get_idati.argtypes = []
        get_idati.restype = ctypes.c_void_p

        set_numbered_type = dll.set_numbered_type
        set_numbered_type.argtypes = [
            ctypes.c_void_p,
            ctypes.c_uint32,
            ctypes.c_int,
            ctypes.c_char_p,
            ctypes.c_char_p,
            ctypes.c_char_p,
            ctypes.c_char_p,
            ctypes.c_char_p,
            ctypes.c_int,
        ]
        set_numbered_type.restype = ctypes.c_int

        py_ti = ida_typeinf.get_idati()
        ordinal_qty = ida_typeinf.get_ordinal_qty(py_ti) - 1
        last_ordinal = self.local_types[-1][0]
        if ordinal_qty < last_ordinal:
            ida_typeinf.alloc_type_ordinals(py_ti, last_ordinal - ordinal_qty)
        else:
            for py_ordinal in range(last_ordinal + 1, ordinal_qty + 1):
                ida_typeinf.del_numbered_type(py_ti, py_ordinal)

        local_types = self.local_types
        for py_ord, name, type, fields, cmt, fieldcmts, sclass in local_types:
            if type:
                ti = get_idati()
                ordinal = ctypes.c_uint32(py_ord)
                ntf_flags = ctypes.c_int(ida_typeinf.NTF_REPLACE)
                name = ctypes.c_char_p(name)
                type = ctypes.c_char_p(type)
                fields = ctypes.c_char_p(fields)
                cmt = ctypes.c_char_p(cmt)
                fieldcmts = ctypes.c_char_p(fieldcmts)
                sclass = ctypes.c_int(sclass)
                set_numbered_type(
                    ti,
                    ordinal,
                    ntf_flags,
                    name,
                    type,
                    fields,
                    cmt,
                    fieldcmts,
                    sclass,
                )
            else:
                ida_typeinf.del_numbered_type(py_ti, py_ord)

        ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #6
0
def force_update():
    """Forcefuly requests IDA kernel to update all widgets and views. Useful
  for when delayed actions modify the program and/or plugin state without
  IDA's awareness"""
    iwid_all = 0xFFFFFFFF
    ida_kernwin.request_refresh(iwid_all)
    ida_kernwin.refresh_idaview_anyway()
    log("utils").info("Requested forceful gui update")
Exemple #7
0
 def __call__(self):
     for t_old, t_new in self.local_types:
         if t_new:
             name, parsed_list, type_fields = t_new
             t_new = LocalType(name=name,
                               parsedList=parsed_list,
                               TypeFields=type_fields.encode())
             InsertType(t_new, fReplace=True)
     ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #8
0
    def __call__(self):
        flags = ida_name.SN_LOCAL if self.local_name else 0

        try:
            ida_name.set_name(self.ea, (self.new_name),
                              flags | ida_name.SN_NOWARN)
        except:
            raise Exception(
                repr((self.ea, (self.new_name), flags | ida_name.SN_NOWARN)))
        ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)
        HexRaysEvent.refresh_pseudocode_view(self.ea)
Exemple #9
0
 def implement(self):
     if self._is_public:
         if idc.get_name(self._linear_address) != self._new_name:
             idc.set_name(
                 self._linear_address, self._new_name, ida_name.SN_PUBLIC
                 if self._is_public else ida_name.SN_LOCAL)
     else:
         if idc.get_name(self._linear_address,
                         ida_name.GN_LOCAL) != self._new_name:
             idc.set_name(
                 self._linear_address, self._new_name, ida_name.SN_PUBLIC
                 if self._is_public else ida_name.SN_LOCAL)
     ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)
Exemple #10
0
def apply_update(indices):
    """
    Calls the `apply` function on every update that needs to be applied, then removes said update.
    Because the removal happens after every apply, a fix is need to be done on the index to remove.

    :param indices: (list(int)) Indices in the item list of the updates that need to be applied
    """
    try:
        g_item_list_mutex.lock()

        removed_rows = 0
        # since every time you apply an update you discard it
        # AND you have to keep the update order you need to
        # track the offset for all indices after the one you just removed
        for i in sorted(indices):
            effective_index = i - removed_rows
            update_item = g_item_list_model.item(effective_index)
            update = update_item.data()

            successfully_executed = False
            should_remove_row = True
            try:
                hooks.g_hook_enabled = False
                should_remove_row = update.apply()
                successfully_executed = True
            except:
                if CONFIGURATION['debug']:
                    traceback.print_exc()
                pass
            finally:
                hooks.g_hooks_enabled = True

            if not successfully_executed:
                print 'ERROR - Update - Could not update: "%s"' % update_item.text()
            elif should_remove_row:
                g_item_list_model.removeRow(effective_index)
                g_identifiers_to_updates.pop(update.get_identifier())
                removed_rows += 1

        ida_kernwin.request_refresh(ida_kernwin.IWID_IDAMEMOS)
    except:
        traceback.print_exc()

    finally:
        g_item_list_mutex.unlock()
Exemple #11
0
    def __call__(self):
        ti = ida_typeinf.get_idati()

        ordinal_qty = ida_typeinf.get_ordinal_qty(ti)
        last_ordinal = self.local_types[-1][0]
        if ordinal_qty < last_ordinal:
            ida_typeinf.alloc_type_ordinals(ti, last_ordinal - ordinal_qty)
        else:
            for ordinal in range(last_ordinal + 1, ordinal_qty + 1):
                ida_typeinf.del_numbered_type(ti, ordinal)

        for ordinal, name, ret in self.local_types:
            name = Event.encode_bytes(name)
            type, fields, fieldcmts = ret
            type = Event.encode_bytes(type)
            fields = Event.encode_bytes(fields)
            fieldcmts = Event.encode_bytes(fieldcmts)

            type_info = ida_typeinf.tinfo_t()
            type_info.deserialize(ti, type, fields, fieldcmts)
            type_info.set_numbered_type(ti, ordinal, 0, name)

        ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #12
0
    def __call__(self):
        local_type = []
        for t in self.local_type:
            if t is not None:
                local_type.append((
                    Event.encode_bytes(t[0]),
                    Event.encode_bytes(t[1]),
                    Event.encode_bytes(t[2]),
                ))
            else:
                local_type.append(None)

        missing_ord = len(local_type) - ida_typeinf.get_ordinal_qty(None) + 1
        if missing_ord > 0:
            ida_typeinf.alloc_type_ordinals(None, missing_ord)

        for i, t in enumerate(local_type):
            if t is not None:
                cur_tinfo = ida_typeinf.tinfo_t()
                cur_tinfo.deserialize(None, t[0], t[1])
                cur_tinfo.set_numbered_type(None, i + 1, 0, t[2])
            else:
                ida_typeinf.del_numbered_type(None, i + 1)
        ida_kernwin.request_refresh(ida_kernwin.IWID_LOCTYPS)
Exemple #13
0
 def refresh(self):
     ida_kernwin.refresh_navband(True)
     ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)
     ida_kernwin.request_refresh(ida_kernwin.IWID_FUNCS)
Exemple #14
0
def set_ida_func_name(func_addr, new_name):
    idaapi.set_name(func_addr, new_name, idaapi.SN_FORCE)
    ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)
    ida_kernwin.request_refresh(ida_kernwin.IWID_STRUCTS)
    ida_kernwin.request_refresh(ida_kernwin.IWID_STKVIEW)
Exemple #15
0
 def force_update():
     """Forcefuly requests IDA kernel to update all widgets and views. Useful
 for when delayed actions modify the program and/or plugin state without
 IDA's awareness"""
     iwid_all = 0xFFFFFFFF
     ida_kernwin.request_refresh(iwid_all)
Exemple #16
0
 def _on_renamed(self, ea, new_name, local_name):
     logger.debug('Inside renamed event from server')
     flags = ida_name.SN_LOCAL if local_name else 0
     ida_name.set_name(ea, Unicoder.encode(new_name),
                       flags | ida_name.SN_NOWARN)
     ida_kernwin.request_refresh(ida_kernwin.IWID_DISASMS)