Example #1
0
 def handler(event, old=0):
     if event == idaapi.NW_OPENIDB:
         _do_load()
     elif event == idaapi.NW_TERMIDA:
         idaapi.notify_when(
             idaapi.NW_TERMIDA | idaapi.NW_OPENIDB | idaapi.NW_REMOVE,
             handler)
Example #2
0
def start():
    """
    Boots idb_push by:
        - Testing connectivity to the server
        - Opening the global socket
        - Hooks the relevant IDB events
        - Hooks the UI context-menu element
        - Installs a call to 'stop' when ida closes
    """
    print 'INFO - Configuration - \r\n' + pprint.pformat(CONFIGURATION)

    # test connectivity
    zmq_primitives.zmq_test_connectivity()
    # open global socket
    hooks.g_zmq_socket = zmq_primitives.zmq_open_pub_socket()  # default arguments

    if not g_idb_hook.hook():
        raise Exception('IDBHook installation FAILED')

    hooks.g_hooks_enabled = True

    global g_receive_thread
    g_receive_thread = ReceiveThread()
    g_receive_thread.start()

    global g_form
    g_form = idb_push_ui.IDBPushForm(_remove_hooks_and_stop_thread)
    g_form.Show('IDB PUSH')

    hooks.install_ui_hooks()

    # register for when IDA terminates
    idaapi.notify_when(idaapi.NW_TERMIDA, stop)
Example #3
0
def PLUGIN_ENTRY():
    settings.load_settings()
    logging.basicConfig(
        format='[%(levelname)s] %(message)s\t(%(module)s:%(funcName)s)')
    logging.root.setLevel(settings.DEBUG_MESSAGE_LEVEL)
    idaapi.notify_when(idaapi.NW_OPENIDB, cache.initialize_cache)
    return MyPlugin()
Example #4
0
def eventhook(event, old=0):
    if event == idaapi.NW_OPENIDB:
        on_open()
    elif event in (idaapi.NW_CLOSEIDB, idaapi.NW_TERMIDA):
        on_close()
    if event == idaapi.NW_TERMIDA:
        # remove hook on way out
        idaapi.notify_when(idaapi.NW_OPENIDB | idaapi.NW_CLOSEIDB | idaapi.NW_TERMIDA | idaapi.NW_REMOVE, eventhook)
Example #5
0
def setup():
    if idaapi.get_root_filename():
        on_open()
    else:
        idaapi.notify_when(
            idaapi.NW_OPENIDB | idaapi.NW_CLOSEIDB | idaapi.NW_TERMIDA,
            eventhook)
    return -1
Example #6
0
    def __init__(self):
        super(Continuum, self).__init__()

        self.project = None
        self.client = None
        self.server = None
        self._timer = None

        # Sign up for events.
        idaapi.notify_when(idaapi.NW_OPENIDB, self.handle_open_idb)
        idaapi.notify_when(idaapi.NW_CLOSEIDB, self.handle_close_idb)
Example #7
0
 def setup_terminator(self):
     """
         Register an exit callback
     """
     def end_notify_callback(nw_arg):
         """
             Callback that destroys the object when exiting
         """
         logger.debug("Being notified of exiting DB")
         self.end_skelenox()
     idaapi.notify_when(idaapi.NW_CLOSEIDB | idaapi.NW_TERMIDA,
                        end_notify_callback)
Example #8
0
 def setup_terminator(self):
     """
         Register an exit callback
     """
     def end_notify_callback(nw_arg):
         """
             Callback that destroys the object when exiting
         """
         g_logger.debug("Being notified of exiting DB")
         self.end_skelenox()
     idaapi.notify_when(idaapi.NW_CLOSEIDB | idaapi.NW_TERMIDA,
                        end_notify_callback)
Example #9
0
class strings(appwindow):
    """
    This namespace is for interacting with the Strings window.
    """
    __open__ = staticmethod(idaapi.open_strings_window)
    __open_defaults__ = (idaapi.BADADDR, idaapi.BADADDR, idaapi.BADADDR)

    @classmethod
    def __on_openidb__(cls, code, is_old_database):
        if code != idaapi.NW_OPENIDB or is_old_database:
            raise internal.exceptions.InvalidParameterError("{:s}.__on_openidb__({:#x}, {:b}) : Hook was called with an unexpected code or an old database.".format('.'.join((__name__, cls.__name__)), code, is_old_database))
        config = idaapi.strwinsetup_t()
        config.minlen = 3
        config.ea1, config.ea2 = idaapi.cvar.inf.minEA, idaapi.cvar.inf.maxEA
        config.display_only_existing_strings = True
        config.only_7bit = True
        config.ignore_heads = False

        res = [idaapi.ASCSTR_TERMCHR, idaapi.ASCSTR_PASCAL, idaapi.ASCSTR_LEN2, idaapi.ASCSTR_UNICODE, idaapi.ASCSTR_LEN4, idaapi.ASCSTR_ULEN2, idaapi.ASCSTR_ULEN4]
        config.strtypes = reduce(lambda t, c: t | (2**c), res, 0)
        assert idaapi.set_strlist_options(config)
        #assert idaapi.refresh_strlist(config.ea1, config.ea2), "{:#x}:{:#x}".format(config.ea1, config.ea2)

    # FIXME: I don't think that these callbacks are stackable
    idaapi.notify_when(idaapi.NW_OPENIDB, __on_openidb__)

    @classmethod
    def refresh(cls):
        '''Refresh the strings list.'''
        return idaapi.refresh_lists()
    @classmethod
    def size(cls):
        '''Return the number of elements in the strings list.'''
        return idaapi.get_strlist_qty()
    @classmethod
    def at(cls, index):
        '''Return the string at the specified `index`.'''
        string = idaapi.string_info_t()
        res = idaapi.get_strlist_item(index, string)
        if not res:
            raise internal.exceptions.DisassemblerError("{:s}.at({:d}) : The call to idaapi.get_strlist_item({:d}) returned {!r}.".format('.'.join((__name__, cls.__name__)), index, index, res))
        return string
    @classmethod
    def get(cls, index):
        '''Return the address and the string at the specified `index`.'''
        si = cls.at(index)
        return si.ea, idaapi.get_ascii_contents(si.ea, si.length, si.type)
    @classmethod
    def iterate(cls):
        '''Iterate through all of the address and strings in the strings list.'''
        for index in six.moves.range(cls.size()):
            si = cls.at(index)
            yield si.ea, idaapi.get_ascii_contents(si.ea, si.length, si.type)
        return
Example #10
0
def PLUGIN_ENTRY():
    settings.load_settings()
    logging.basicConfig(format='[%(levelname)s] %(message)s\t(%(module)s:%(funcName)s)')
    logging.root.setLevel(settings.DEBUG_MESSAGE_LEVEL)
    idaapi.notify_when(idaapi.NW_OPENIDB, cache.init_demangled_names)
    idaapi.notify_when(idaapi.NW_OPENIDB, cache.init_imported_ea)
    idaapi.notify_when(idaapi.NW_OPENIDB, cache.reset_touched_functions)
    helper.extend_ida()
    return MyPlugin()
Example #11
0
class Strings(object):
    """Grabbing contents from the Strings window"""
    @classmethod
    def on_openidb(cls, code, is_old_database):
        if code != idaapi.NW_OPENIDB or is_old_database:
            raise RuntimeError
        config = idaapi.strwinsetup_t()
        config.minlen = 3
        config.ea1, config.ea2 = idaapi.cvar.inf.minEA, idaapi.cvar.inf.maxEA
        config.display_only_existing_strings = True
        config.only_7bit = True
        config.ignore_heads = False

        res = [
            idaapi.ASCSTR_TERMCHR, idaapi.ASCSTR_PASCAL, idaapi.ASCSTR_LEN2,
            idaapi.ASCSTR_UNICODE, idaapi.ASCSTR_LEN4, idaapi.ASCSTR_ULEN2,
            idaapi.ASCSTR_ULEN4
        ]
        config.strtypes = reduce(lambda t, c: t | (2**c), res, 0)
        assert idaapi.set_strlist_options(config)
        #assert idaapi.refresh_strlist(config.ea1, config.ea2), "{:x}:{:x}".format(config.ea1, config.ea2)

    # FIXME: I don't think that these callbacks are stackable
    idaapi.notify_when(idaapi.NW_OPENIDB, on_openidb)

    @classmethod
    def size(cls):
        return idaapi.get_strlist_qty()

    @classmethod
    def at(cls, index):
        string = idaapi.string_info_t()
        res = idaapi.get_strlist_item(index, string)
        if not res:
            raise RuntimeError, "idaapi.get_strlist_item({:d}) -> {!r}".format(
                index, res)
        return string

    @classmethod
    def get(cls, index):
        si = cls.at(index)
        return si.ea, idaapi.get_ascii_contents(si.ea, si.length, si.type)

    @classmethod
    def iterate(cls):
        for index in xrange(cls.size()):
            si = cls.at(index)
            yield si.ea, idaapi.get_ascii_contents(si.ea, si.length, si.type)
        return
Example #12
0
 def _install():
     idaapi.notify_when(idaapi.NW_TERMIDA | idaapi.NW_OPENIDB, handler)
     # return -1 to remove the timer
     return -1
Example #13
0
 def handler(event, old=0):
     if event == idaapi.NW_OPENIDB:
         _do_load()
     elif event == idaapi.NW_TERMIDA:
         idaapi.notify_when(idaapi.NW_TERMIDA | idaapi.NW_OPENIDB | idaapi.NW_REMOVE, handler)
Example #14
0
        cleanup
    """
    global sample_id, skel_conn
    skel_conn.close_connection()
    cleanup_hooks()
    g_logger.info("Skelenox terminated")
    sample_id = 0
    return


def end_notify_callback(nw_arg):
    g_logger.debug("Being notified of exiting DB")
    end_skelenox()


idaapi.notify_when(idaapi.NW_CLOSEIDB | idaapi.NW_TERMIDA, end_notify_callback)


def init_skelenox():
    global crit_backup_file, backup_file, last_saved
    global last_timestamp
    global sample_id
    global uihook
    global is_updating
    global skel_conn
    global skel_settings, settings_filename

    is_updating = 0

    last_timestamp = -1
    sample_id = 0
def PLUGIN_ENTRY():
    idaapi.notify_when(idaapi.NW_OPENIDB, Helper.init_demangled_names)
    return MyPlugin()
Example #16
0
def PLUGIN_ENTRY():
    print "HexRaysPyTools PLUGIN_ENTRY"
    idaapi.notify_when(idaapi.NW_OPENIDB, Helper.init_demangled_names)
    return MyPlugin()
Example #17
0
def PLUGIN_ENTRY():
    idaapi.notify_when(idaapi.NW_OPENIDB, Cache.init_demangled_names)
    idaapi.notify_when(idaapi.NW_OPENIDB, Cache.init_imported_ea)
    idaapi.notify_when(idaapi.NW_OPENIDB, Cache.reset_touched_functions)
    Helper.extend_ida()
    return MyPlugin()
Example #18
0
 def _install():
     idaapi.notify_when(idaapi.NW_TERMIDA | idaapi.NW_OPENIDB, handler)
     # return -1 to remove the timer
     return -1
Example #19
0
# WORD length in bytes
WORD_LEN = None


def update_word_len(code, old=0):
    global WORD_LEN
    info = idaapi.get_inf_structure()
    if info.is_64bit():
        logging.debug("is 32 bit")
        WORD_LEN = 8
    elif info.is_32bit():
        logging.debug("is 32 bit")
        WORD_LEN = 4


idaapi.notify_when(idaapi.NW_OPENIDB, update_word_len)


def get_word(ea):
    if WORD_LEN == 4:
        return idaapi.get_32bit(ea)
    elif WORD_LEN == 8:
        return idaapi.get_64bit(ea)
    return None


def get_ptr(ea):
    return get_word(ea)


def make_word(ea):
Example #20
0
def end_skelenox():
    """
        cleanup
    """
    global sample_id, skel_conn
    skel_conn.close_connection()
    cleanup_hooks()
    g_logger.info("Skelenox terminated")
    sample_id = 0
    return

def end_notify_callback(nw_arg):
    g_logger.debug("Being notified of exiting DB")
    end_skelenox()

idaapi.notify_when(idaapi.NW_CLOSEIDB|idaapi.NW_TERMIDA,
                   end_notify_callback)


def init_skelenox():
    global crit_backup_file, backup_file, last_saved
    global last_timestamp
    global sample_id
    global uihook
    global is_updating
    global skel_conn
    global skel_settings, settings_filename

    is_updating = 0

    last_timestamp = -1
    sample_id = 0