Ejemplo n.º 1
0
 def test_system(self):
     try:
         # this may fail if the user is not running as admin
         IDASettings(PLUGIN_1).system.set_value(KEY_1, VALUE_1)
         self.assertEqual(IDASettings(PLUGIN_1).system.get_value(KEY_1), VALUE_1)
     except PermissionError:
         g_logger.warning("swallowing PermissionError during testing")
    def init(self):
        self.lines = set()
        self.settings = IDASettings('HighlightCalls')
        try:
            self.set_color(self.settings['color'])
        except KeyError:
            self.settings.user['color'] = HIGHLIGHT_COLOR
            self.set_color(HIGHLIGHT_COLOR)
        self.ui_hooks = UiHooks(self.lines)

        self.toggle_action_desc = idaapi.action_desc_t(
            'HighlightCalls:Toggle', 'Toggle call highlighting',
            ToggleHighlightHandler(self.enable_highlights,
                                   self.disable_highlights), '',
            'Toggle call highlighting', -1)
        idaapi.register_action(self.toggle_action_desc)

        self.color_selector = idaapi.action_desc_t(
            'HighlightCalls:SelectColor', 'Select highlight color',
            SelectColorHandler(set_color=self.set_color), '',
            'Select highlight color', -1)
        idaapi.register_action(self.color_selector)

        idaapi.attach_action_to_menu('Edit/', self.toggle_action_desc.name,
                                     idaapi.SETMENU_APP)
        idaapi.attach_action_to_menu('Edit/', self.color_selector.name,
                                     idaapi.SETMENU_APP)

        return idaapi.PLUGIN_KEEP
Ejemplo n.º 3
0
class TestUserAndSystemSettings(unittest.TestCase):
    def setUp(self):
        self.system = IDASettings(PLUGIN_1).system
        self.user = IDASettings(PLUGIN_1).user

    def test_system_fallback(self):
        """
        QSettings instances with scope "user" automatically fall back to
         scope "system" if the key doesn't exist.
        """
        try:
            with clearing(self.system):
                with clearing(self.user):
                    self.system.set_value(KEY_1, VALUE_1)
                    self.assertEqual(self.user.get_value(KEY_1), VALUE_1)
        except PermissionError:
            g_logger.warning("swallowing PermissionError during testing")
Ejemplo n.º 4
0
    def init(self):
        self.settings = IDASettings('Autoruns')

        exec(self._code)

        self.menu_items = []
        idaapi.add_menu_item('View/', 'Edit Autoruns', '', idaapi.SETMENU_INS,
                             self._edit, tuple())
        return idaapi.PLUGIN_KEEP
Ejemplo n.º 5
0
def main():
    arguments = docopt.docopt(__doc__)
    directory = arguments['--dir']
    settings = IDASettings('PluginLoader', directory=directory)

    if arguments['add']:
        plugin_path = arguments['<path>']
        plugin_name = arguments['<name>']

        if arguments['--user']:
            settings.user[plugin_name] = plugin_path

        elif arguments['--system']:
            settings.system[plugin_name] = plugin_path

        elif arguments['--dir']:
            settings.directory[plugin_name] = plugin_path

        else:
            settings.user[plugin_name] = plugin_path

    if arguments['remove']:
        plugin_name = arguments['<name>']

        if arguments['--user']:
            del settings.user[plugin_name]

        elif arguments['--system']:
            del settings.system[plugin_name]

        elif arguments['--dir']:
            del settings.directory[plugin_name]

        else:
            del settings.user[plugin_name]

    if arguments['list']:
        for name, path in settings.items():
            print(name, path)

    if arguments['initialize']:
        # Copy `plugin_loader.py` to IDA's plugin directory.
        ida_path = arguments['<ida-path>']
        target_path = os.path.join(ida_path, 'plugins', 'plugin_loader.py')
        source_path = os.path.join(os.path.dirname(__file__),
                                   'plugin_loader.py')
        print('Installing the plugin loader to {}'.format(target_path))
        shutil.copyfile(source_path, target_path)

    if arguments['terminate']:
        # Remove `plugin_loader.py` from the IDA plugins directory.
        ida_path = arguments['<ida-path>']
        target_path = os.path.join(ida_path, 'plugins', 'plugin_loader.py')
        os.unlink(target_path)
Ejemplo n.º 6
0
def main():
    arguments = docopt.docopt(__doc__)
    directory = arguments['--dir']
    settings = IDASettings('PluginLoader', directory=directory)

    if arguments['add']:
        plugin_path = arguments['<path>']
        plugin_name = arguments['<name>']

        if arguments['--user']:
            settings.user[plugin_name] = plugin_path

        elif arguments['--system']:
            settings.system[plugin_name] = plugin_path

        elif arguments['--dir']:
            settings.directory[plugin_name] = plugin_path

        else:
            settings.user[plugin_name] = plugin_path

    if arguments['remove']:
        plugin_name = arguments['<name>']

        if arguments['--user']:
            del settings.user[plugin_name]

        elif arguments['--system']:
            del settings.system[plugin_name]

        elif arguments['--dir']:
            del settings.directory[plugin_name]

        else:
            del settings.user[plugin_name]

    if arguments['list']:
        for name, path in settings.iteritems():
            print name, path

    if arguments['initialize']:
        # Copy `plugin_loader.py` to IDA's plugin directory.
        ida_path = arguments['<ida-path>']
        target_path = os.path.join(ida_path, 'plugins', 'plugin_loader.py')
        source_path = os.path.join(os.path.dirname(__file__), 'plugin_loader.py')
        print 'Installing the plugin loader to {}'.format(target_path)
        shutil.copyfile(source_path, target_path)

    if arguments['terminate']:
        # Remove `plugin_loader.py` from the IDA plugins directory.
        ida_path = arguments['<ida-path>']
        target_path = os.path.join(ida_path, 'plugins', 'plugin_loader.py')
        os.unlink(target_path)
Ejemplo n.º 7
0
def main():
    arguments = docopt.docopt(__doc__)
    directory = arguments['--dir']
    settings = IDASettings('PluginLoader', directory=directory)

    if arguments['add']:
        plugin_path = arguments['<path>']
        plugin_name = arguments['<name>']

        if arguments['--user']:
            settings.user[plugin_name] = plugin_path

        elif arguments['--system']:
            settings.system[plugin_name] = plugin_path

        elif arguments['--dir']:
            settings.directory[plugin_name] = plugin_path

        else:
            settings.user[plugin_name] = plugin_path

    if arguments['remove']:
        plugin_name = arguments['<name>']

        if arguments['--user']:
            del settings.user[plugin_name]

        elif arguments['--system']:
            del settings.system[plugin_name]

        elif arguments['--dir']:
            del settings.directory[plugin_name]

        else:
            del settings.user[plugin_name]

    if arguments['list']:
        for name, path in settings.iteritems():
            print name, path

    if arguments['initialize']:
        ida_path = arguments['<ida-path>']
        # Copy `plugin_loader.py` to IDA directory.

    if arguments['terminate']:
        # Remove `plugin_loader.py` from IDA directory.
        pass
Ejemplo n.º 8
0
    def test_idb_plugin_names(self):
        try:
            self.assertEqual(set(IDASettings.get_idb_plugin_names()), set([]))

            s1 = IDASettings(PLUGIN_1).idb
            with clearing(s1):
                s1[KEY_1] = VALUE_1
                self.assertEqual(set(IDASettings.get_idb_plugin_names()), set([PLUGIN_1]))

                s2 = IDASettings(PLUGIN_2).idb
                with clearing(s2):
                    s2[KEY_1] = VALUE_1
                    self.assertEqual(set(IDASettings.get_idb_plugin_names()), set([PLUGIN_1, PLUGIN_2]))

            self.assertEqual(set(IDASettings.get_idb_plugin_names()), set([]))
        except PermissionError:
            g_logger.warning("swallowing PermissionError during testing")
Ejemplo n.º 9
0
 def test_idb(self):
     try:
         IDASettings(PLUGIN_1).idb.set_value(KEY_1, VALUE_1)
         self.assertEqual(IDASettings(PLUGIN_1).idb.get_value(KEY_1), VALUE_1)
     except PermissionError:
         g_logger.warning("swallowing PermissionError during testing")
Ejemplo n.º 10
0
 def setUp(self):
     self.system = IDASettings(PLUGIN_1).system
     self.user = IDASettings(PLUGIN_1).user
     self.directory = IDASettings(PLUGIN_1).directory
     self.idb = IDASettings(PLUGIN_1).idb
     self.mux = IDASettings(PLUGIN_1)
Ejemplo n.º 11
0
class TestSettingsPrecendence(unittest.TestCase):
    def setUp(self):
        self.system = IDASettings(PLUGIN_1).system
        self.user = IDASettings(PLUGIN_1).user
        self.directory = IDASettings(PLUGIN_1).directory
        self.idb = IDASettings(PLUGIN_1).idb
        self.mux = IDASettings(PLUGIN_1)

    def test_user_gt_system(self):
        try:
            with clearing(self.system):
                with clearing(self.user):
                    self.system.set_value(KEY_1, VALUE_1)
                    self.user.set_value(KEY_1, VALUE_2)
                    self.assertEqual(self.mux.get_value(KEY_1), VALUE_2)
        except PermissionError:
            g_logger.warning("swallowing PermissionError during testing")

    def test_directory_gt_user(self):
        try:
            with clearing(self.user):
                with clearing(self.directory):
                    self.user.set_value(KEY_1, VALUE_1)
                    self.directory.set_value(KEY_1, VALUE_2)
                    self.assertEqual(self.mux.get_value(KEY_1), VALUE_2)
        except PermissionError:
            g_logger.warning("swallowing PermissionError during testing")

    def test_idb_gt_directory(self):
        try:
            with clearing(self.directory):
                with clearing(self.idb):
                    self.directory.set_value(KEY_1, VALUE_1)
                    self.idb.set_value(KEY_1, VALUE_2)
                    self.assertEqual(self.mux.get_value(KEY_1), VALUE_2)
        except PermissionError:
            g_logger.warning("swallowing PermissionError during testing")
Ejemplo n.º 12
0
 def setUp(self):
     self.system = IDASettings(PLUGIN_1).system
     self.user = IDASettings(PLUGIN_1).user
Ejemplo n.º 13
0
 def setUp(self):
     self.settings = IDASettings(PLUGIN_1).idb
Ejemplo n.º 14
0
 def setUp(self):
     self.settings = IDASettings(PLUGIN_1).directory