Beispiel #1
0
    def save(self):
        """
            Function which allow to save the change made to the local variable
            inside the idb. This is necessary because by default the change
            made to a lvar using the IDA interface only change the object in
            memory and not its content.
            
            This function is called by default by the setters of this object
            if the ``_persistent`` property is at True (the default). It
            should not be necessary to call this directly.

            .. todo:: this should probably set the flags to ? flags are not
                directly accessible through the the lvar object from IDAPython
                rigth now...
        """
        # object needed for containing the information to save about the lvar
        lsi = lvar_saved_info_t()
        # set everything which need to be save
        lsi.ll = self._lvar
        lsi.name = self.name
        lsi.type = self._lvar.tif
        lsi.size = self.size
        lsi.cmt = self.comment
        # create the object which is used for saving in the idb
        lvuv = lvar_uservec_t()
        # get the info from the previously modify lvar
        restore_user_lvar_settings(lvuv, self._hxcfunc.ea)
        if not lvuv.lvvec.add_unique(lsi):  # adding this var to save
            # this is actually not an error but simply means the lvar
            #   was already at the same state
            return
        # saving in the idb
        save_user_lvar_settings(self._hxcfunc.ea, lvuv)
Beispiel #2
0
    def __call__(self):
        if len(self.lvar_settings) == 0:
            return

        lvinf = ida_hexrays.lvar_uservec_t()
        lvinf.lvvec = ida_hexrays.lvar_saved_infos_t()
        if "lvvec" in self.lvar_settings:
            for lv in self.lvar_settings["lvvec"]:
                lvinf.lvvec.push_back(
                    UserLvarSettingsEvent._get_lvar_saved_info(lv))
        lvinf.sizes = ida_pro.intvec_t()
        if "sizes" in self.lvar_settings:
            for i in self.lvar_settings["sizes"]:
                lvinf.sizes.push_back(i)
        lvinf.lmaps = ida_hexrays.lvar_mapping_t()
        if "lmaps" in self.lvar_settings:
            for key, val in self.lvar_settings["lmaps"]:
                key = UserLvarSettingsEvent._get_lvar_locator(key)
                val = UserLvarSettingsEvent._get_lvar_locator(val)
                ida_hexrays.lvar_mapping_insert(lvinf.lmaps, key, val)
        if "stkoff_delta" in self.lvar_settings:
            lvinf.stkoff_delta = self.lvar_settings["stkoff_delta"]
        if "ulv_flags" in self.lvar_settings:
            lvinf.ulv_flags = self.lvar_settings["ulv_flags"]
        ida_hexrays.save_user_lvar_settings(self.ea, lvinf)
        HexRaysEvent.refresh_pseudocode_view(self.ea)
 def __call__(self):
     lvinf = ida_hexrays.lvar_uservec_t()
     lvinf.lvvec = ida_hexrays.lvar_saved_infos_t()
     for lv in self.lvar_settings['lvvec']:
         lvinf.lvvec.push_back(
             UserLvarSettingsEvent._get_lvar_saved_info(lv))
     lvinf.sizes = ida_pro.intvec_t()
     for i in self.lvar_settings['sizes']:
         lvinf.sizes.push_back(i)
     lvinf.lmaps = ida_hexrays.lvar_mapping_t()
     for key, val in self.lvar_settings['lmaps']:
         key = UserLvarSettingsEvent._get_lvar_locator(key)
         val = UserLvarSettingsEvent._get_lvar_locator(val)
         ida_hexrays.lvar_mapping_insert(lvinf.lmaps, key, val)
     lvinf.stkoff_delta = self.lvar_settings['stkoff_delta']
     lvinf.ulv_flags = self.lvar_settings['ulv_flags']
     ida_hexrays.save_user_lvar_settings(self.ea, lvinf)
     HexRaysEvent.refresh_pseudocode_view()
 def _get_user_lvar_settings(ea):
     dct = {}
     lvinf = ida_hexrays.lvar_uservec_t()
     if ida_hexrays.restore_user_lvar_settings(lvinf, ea):
         dct['lvvec'] = []
         for lv in lvinf.lvvec:
             dct['lvvec'].append(HexRaysHooks._get_lvar_saved_info(lv))
         dct['sizes'] = list(lvinf.sizes)
         dct['lmaps'] = []
         it = ida_hexrays.lvar_mapping_begin(lvinf.lmaps)
         while it != ida_hexrays.lvar_mapping_end(lvinf.lmaps):
             key = ida_hexrays.lvar_mapping_first(it)
             key = HexRaysHooks._get_lvar_locator(key)
             val = ida_hexrays.lvar_mapping_second(it)
             val = HexRaysHooks._get_lvar_locator(val)
             dct['lmaps'].append((key, val))
             it = ida_hexrays.lvar_mapping_next(it)
         dct['stkoff_delta'] = lvinf.stkoff_delta
         dct['ulv_flags'] = lvinf.ulv_flags
     return dct
Beispiel #5
0
def _get_user_lvar_settings(ea):
    dct = {}
    lvinf = ida_hexrays.lvar_uservec_t()
    if ida_hexrays.restore_user_lvar_settings(lvinf, ea):
        dct["lvvec"] = []
        for lv in lvinf.lvvec:
            dct["lvvec"].append(_get_lvar_saved_info(lv))
        if hasattr(lvinf, "sizes"):
            dct["sizes"] = list(lvinf.sizes)
        dct["lmaps"] = []
        it = ida_hexrays.lvar_mapping_begin(lvinf.lmaps)
        while it != ida_hexrays.lvar_mapping_end(lvinf.lmaps):
            key = ida_hexrays.lvar_mapping_first(it)
            key = _get_lvar_locator(key)
            val = ida_hexrays.lvar_mapping_second(it)
            val = _get_lvar_locator(val)
            dct["lmaps"].append((key, val))
            it = ida_hexrays.lvar_mapping_next(it)
        dct["stkoff_delta"] = lvinf.stkoff_delta
        dct["ulv_flags"] = lvinf.ulv_flags
    return dct
Beispiel #6
0
def run():

    cfunc = ida_hexrays.decompile(ida_kernwin.get_screen_ea())
    if not cfunc:
        print('Please move the cursor into a function.')
        return

    entry_ea = cfunc.entry_ea
    print("Dump of user-defined information for function at %x" % (entry_ea, ))

    # Display user defined labels.
    labels = ida_hexrays.restore_user_labels(entry_ea)
    if labels is not None:
        print("------- %u user defined labels" % (len(labels), ))
        for org_label, name in labels.items():
            print("Label %d: %s" % (org_label, str(name)))
        ida_hexrays.user_labels_free(labels)

    # Display user defined comments
    cmts = ida_hexrays.restore_user_cmts(entry_ea)
    if cmts is not None:
        print("------- %u user defined comments" % (len(cmts), ))
        for tl, cmt in cmts.items():
            print("Comment at %x, preciser %x:\n%s\n" %
                  (tl.ea, tl.itp, str(cmt)))
        ida_hexrays.user_cmts_free(cmts)

    # Display user defined citem iflags
    iflags = ida_hexrays.restore_user_iflags(entry_ea)
    if iflags is not None:
        print("------- %u user defined citem iflags" % (len(iflags), ))
        for cl, f in iflags.items():
            print("%x(%d): %08X%s" % (cl.ea, cl.op, f, " CIT_COLLAPSED" if f
                                      & ida_hexrays.CIT_COLLAPSED else ""))
        ida_hexrays.user_iflags_free(iflags)

    # Display user defined number formats
    numforms = ida_hexrays.restore_user_numforms(entry_ea)
    if numforms is not None:
        print("------- %u user defined number formats" % (len(numforms), ))
        for ol, nf in numforms.items():

            print("Number format at %a, operand %d: %s" %
                  (ol.ea, ol.opnum, "negated " if
                   (nf.props & NF_NEGATE) != 0 else ""))

            if nf.is_enum():
                print("enum %s (serial %d)" % (str(nf.type_name), nf.serial))

            elif nf.is_char():
                print("char")

            elif nf.is_stroff():
                print("struct offset %s" % (str(nf.type_name), ))

            else:
                print("number base=%d" %
                      (ida_bytes.get_radix(nf.flags, ol.opnum), ))

        ida_hexrays.user_numforms_free(numforms)

    # Display user-defined local variable information
    lvinf = ida_hexrays.lvar_uservec_t()
    if ida_hexrays.restore_user_lvar_settings(lvinf, entry_ea):
        print("------- User defined local variable information\n")
        for lv in lvinf.lvvec:
            print("Lvar defined at %x" % (lv.ll.defea, ))

            if len(str(lv.name)):
                print("  Name: %s" % (str(lv.name), ))

            if len(str(lv.type)):
                #~ print_type_to_one_line(buf, sizeof(buf), idati, .c_str());
                print("  Type: %s" % (str(lv.type), ))

            if len(str(lv.cmt)):
                print("  Comment: %s" % (str(lv.cmt), ))

    return