def _database_downloaded(self, branch, progress, reply):
        """
        Called when the file has been downloaded.

        :param branch: the branch
        :param progress: the progress dialog
        :param reply: the reply from the server
        """
        # Close the progress dialog
        self._on_progress(progress, 1, 1)

        # Get the absolute path of the file
        appPath = QCoreApplication.applicationFilePath()
        appName = QFileInfo(appPath).fileName()
        fileExt = 'i64' if '64' in appName else 'idb'
        fileName = '%s_%s.%s' % (branch.repo, branch.name, fileExt)
        filePath = local_resource('files', fileName)

        # Write the packet content to disk
        with open(filePath, 'wb') as outputFile:
            outputFile.write(reply.content)
        logger.info("Saved file %s" % fileName)

        # Save the old database
        database = ida_loader.get_path(ida_loader.PATH_TYPE_IDB)
        if database:
            ida_loader.save_database(database, ida_loader.DBFL_KILL)
        # Save the current state
        self._plugin.core.save_state(True, database)
        # Open the new database
        QProcess.startDetached(qApp.applicationFilePath(), [filePath])
        qApp.quit()  # https://forum.hex-rays.com/viewtopic.php?f=8&t=4294
예제 #2
0
파일: hooks.py 프로젝트: yufengzjj/idapkg
def new_instance():
    """
    Simulates "New instance" action
    """
    path = QCoreApplication.applicationFilePath()
    if ' ' in path:
        path = '"' + path + '"'

    QProcess.startDetached(path)
예제 #3
0
파일: core.py 프로젝트: mewbak/IDArling
 def get_ida_dll(app_name=None):
     if app_name is None:
         app_path = QCoreApplication.applicationFilePath()
         app_name = QFileInfo(app_path).fileName()
     idaname = "ida64" if "64" in app_name else "ida"
     if sys.platform == "win32":
         dllname, dlltype = idaname + ".dll", ctypes.windll
     elif sys.platform in ["linux", "linux2"]:
         dllname, dlltype = "lib" + idaname + ".so", ctypes.cdll
     elif sys.platform == "darwin":
         dllname, dlltype = "lib" + idaname + ".dylib", ctypes.cdll
     dllpath = ida_diskio.idadir(None)
     if not os.path.exists(os.path.join(dllpath, dllname)):
         dllpath = dllpath.replace("ida64", "ida")
     return dlltype[os.path.join(dllpath, dllname)]
예제 #4
0
 def set_start_on_system(cls):
     """Habilita la opción de iniciar la aplicación con el sistema.
     Esta funcionalidad solo se habilita si el sistema es Windows y si se está ejecutando desde
     un .exe
     """
     app_path = QCoreApplication.applicationFilePath()
     if QSysInfo.productType() == "windows" \
     and os.path.basename(app_path) == "capounet_sync.exe":
         settings = QSettings(
             "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
             QSettings.NativeFormat)
         if cls.start_on_system:
             settings.setValue("CAPOUNET SYNC",
                               QDir.toNativeSeparators(app_path))
             settings.sync()
         else:
             settings.remove("CAPOUNET SYNC")
예제 #5
0
    def _file_downloaded(self, database, progress, reply):
        """Called when the file has been downloaded."""
        progress.close()

        # Get the absolute path of the file
        app_path = QCoreApplication.applicationFilePath()
        app_name = QFileInfo(app_path).fileName()
        file_ext = "i64" if "64" in app_name else "idb"
        file_name = "%s_%s.%s" % (database.project, database.name, file_ext)
        file_path = self._plugin.user_resource("files", file_name)

        # Write the file to disk
        with open(file_path, "wb") as output_file:
            output_file.write(reply.content)
        self._plugin.logger.info("Saved file %s" % file_name)

        # Save the old database
        database = ida_loader.get_path(ida_loader.PATH_TYPE_IDB)
        if database:
            ida_loader.save_database(database, ida_loader.DBFL_TEMP)

        # This is a very ugly hack used to open a database into IDA. We don't
        # have any function for this in the SDK, so I sorta hijacked the
        # snapshot functionality in this effect.

        # Get the library to call functions not present in the bindings
        idaname = "ida64" if "64" in app_name else "ida"
        if sys.platform == "win32":
            dllname, dlltype = idaname + ".dll", ctypes.windll
        elif sys.platform == "linux2":
            dllname, dlltype = "lib" + idaname + ".so", ctypes.cdll
        elif sys.platform == "darwin":
            dllname, dlltype = "lib" + idaname + ".dylib", ctypes.cdll
        dllpath = ida_diskio.idadir(None)
        if not os.path.exists(os.path.join(dllpath, dllname)):
            dllpath = dllpath.replace("ida64", "ida")
        dll = dlltype[os.path.join(dllpath, dllname)]

        # Close the old database using the term_database library function
        old_path = ida_loader.get_path(ida_loader.PATH_TYPE_IDB)
        if old_path:
            dll.term_database()

        # Open the new database using the init_database library function
        # This call only won't be enough because the user interface won't
        # be initialized, this is why the snapshot functionality is used for
        args = [app_name, file_path]
        argc = len(args)
        argv = (ctypes.POINTER(ctypes.c_char) * (argc + 1))()
        for i, arg in enumerate(args):
            arg = arg.encode("utf-8")
            argv[i] = ctypes.create_string_buffer(arg)

        v = ctypes.c_int(0)
        av = ctypes.addressof(v)
        pv = ctypes.cast(av, ctypes.POINTER(ctypes.c_int))
        dll.init_database(argc, argv, pv)

        # Create a temporary copy of the new database because we cannot use
        # the snapshot functionality to restore the currently opened database
        file_ext = ".i64" if "64" in app_name else ".idb"
        tmp_file, tmp_path = tempfile.mkstemp(suffix=file_ext)
        shutil.copyfile(file_path, tmp_path)

        # This hook is used to delete the temporary database when all done
        class UIHooks(ida_kernwin.UI_Hooks):
            def database_inited(self, is_new_database, idc_script):
                self.unhook()

                os.close(tmp_file)
                if os.path.exists(tmp_path):
                    os.remove(tmp_path)

        hooks = UIHooks()
        hooks.hook()

        # Call the restore_database_snapshot library function
        # This will initialize the user interface, completing the process
        s = ida_loader.snapshot_t()
        s.filename = tmp_path  # Use the temporary database
        ida_kernwin.restore_database_snapshot(s, None, None)
예제 #6
0
    def _database_downloaded(self, branch, progress, reply):
        """
        Called when the file has been downloaded.

        :param branch: the branch
        :param progress: the progress dialog
        :param reply: the reply from the server
        """
        # Close the progress dialog
        progress.close()

        # Get the absolute path of the file
        appPath = QCoreApplication.applicationFilePath()
        appName = QFileInfo(appPath).fileName()
        fileExt = 'i64' if '64' in appName else 'idb'
        fileName = '%s_%s.%s' % (branch.repo, branch.name, fileExt)
        filePath = local_resource('files', fileName)

        # Write the packet content to disk
        with open(filePath, 'wb') as outputFile:
            outputFile.write(reply.content)
        logger.info("Saved file %s" % fileName)

        # Save the old database
        database = ida_loader.get_path(ida_loader.PATH_TYPE_IDB)
        if database:
            ida_loader.save_database(database, ida_loader.DBFL_TEMP)

        # Get the dynamic library
        idaname = 'ida64' if '64' in appName else 'ida'
        if sys.platform == 'win32':
            dllname, dlltype = idaname + '.dll', ctypes.windll
        elif sys.platform == 'linux2':
            dllname, dlltype = 'lib' + idaname + '.so', ctypes.cdll
        elif sys.platform == 'darwin':
            dllname, dlltype = 'lib' + idaname + '.dylib', ctypes.cdll
        dllpath = ida_diskio.idadir(None)
        if not os.path.exists(os.path.join(dllpath, dllname)):
            dllpath = dllpath.replace('ida64', 'ida')
        dll = dlltype[os.path.join(dllpath, dllname)]

        # Close the old database
        oldPath = ida_loader.get_path(ida_loader.PATH_TYPE_IDB)
        if oldPath:
            dll.term_database()

        # Open the new database
        LP_c_char = ctypes.POINTER(ctypes.c_char)

        args = [appName, filePath]
        argc = len(args)
        argv = (LP_c_char * (argc + 1))()
        for i, arg in enumerate(args):
            arg = arg.encode('utf-8')
            argv[i] = ctypes.create_string_buffer(arg)

        LP_c_int = ctypes.POINTER(ctypes.c_int)
        v = ctypes.c_int(0)
        av = ctypes.addressof(v)
        pv = ctypes.cast(av, LP_c_int)
        dll.init_database(argc, argv, pv)

        # Create a copy of the new database
        fileExt = '.i64' if '64' in appName else '.idb'
        tmpFile, tmpPath = tempfile.mkstemp(suffix=fileExt)
        shutil.copyfile(filePath, tmpPath)

        class UIHooks(ida_kernwin.UI_Hooks):
            def database_inited(self, is_new_database, idc_script):
                self.unhook()

                # Remove the tmp database
                os.close(tmpFile)
                if os.path.exists(tmpPath):
                    os.remove(tmpPath)

        hooks = UIHooks()
        hooks.hook()

        # Open the tmp database
        s = ida_loader.snapshot_t()
        s.filename = tmpPath
        ida_kernwin.restore_database_snapshot(s, None, None)
 def applicationName():
     return QFileInfo(QCoreApplication.applicationFilePath()).fileName()