def _on_new_branch_reply(self, repo, branch, _): self._plugin.core.branch = branch.uuid # Save the current database self._plugin.core.save_netnode() idc.save_database(idc.GetIdbPath(), 0) # Create the packet that will hold the database packet = UploadDatabase.Query(repo.hash, branch.uuid) inputPath = idc.GetIdbPath() with open(inputPath, 'rb') as inputFile: packet.content = inputFile.read() # Create the progress dialog text = "Uploading database to server, please wait..." progress = QProgressDialog(text, "Cancel", 0, len(packet.content)) progress.setCancelButton(None) # Remove cancel button progress.setModal(True) # Set as a modal dialog windowFlags = progress.windowFlags() # Disable close button progress.setWindowFlags(windowFlags & ~Qt.WindowCloseButtonHint) progress.setWindowTitle("Save to server") iconPath = self._plugin.resource('upload.png') progress.setWindowIcon(QIcon(iconPath)) progress.show() # Send the packet to upload the file packet.upback = partial(self._progress_callback, progress) d = self._plugin.network.send_packet(packet) d.add_callback(partial(self._database_uploaded, repo, branch)) d.add_errback(logger.exception)
def backup_database(): """ Backup the database to a file similar to IDA's snapshot function. """ time_string = strftime('%Y%m%d%H%M%S') file = idc.get_root_filename() if not file: raise NoInputFileException('No input file provided') input_file = file.rsplit('.', 1)[0] backup_file = '%s_%s.idb' % (input_file, time_string) g_logger.info('Backing up database to file ' + backup_file) idc.save_database(backup_file, idaapi.DBFL_BAK)
def __init__(self, settings_filename): """ Prepare for execution """ SkelUtils.header() logger.info("[+] Init Skelenox") # Load settings self.skel_settings = SkelConfig(settings_filename) self.skel_conn = SkelIDAConnection(self.skel_settings) # If having 3 idbs in your current path bother you, change this self.crit_backup_file = idc.get_idb_path()[:-4] + "_backup_preskel.idb" self.backup_file = idc.get_idb_path()[:-4] + "_backup.idb" atexit.register(self.end_skelenox) logger.info( "Backuping IDB before any intervention (_backup_preskel)") idc.save_database(self.crit_backup_file, idaapi.DBFL_TEMP) logger.info("Creating regular backup file IDB (_backup)") idc.save_database(self.backup_file, idaapi.DBFL_TEMP) self.last_saved = time.time() if self.skel_hooks is not None: self.skel_hooks.cleanup_hooks() if not self.skel_conn.get_online(): logger.error("Cannot get online =(") # Synchronize the sample self.skel_sync_agent = SkelSyncAgent() self.skel_sync_agent.setup_config(settings_filename) # setup hooks self.skel_hooks = SkelHooks(self.skel_conn) # setup UI if self.skel_settings.use_ui: self.skel_ui = SkelUI(settings_filename) # setup skelenox terminator self.setup_terminator() logger.info("Skelenox init finished")
def __init__(self, settings_filename): """ Prepare for execution """ SkelUtils.header() logger.info("[+] Init Skelenox") # Load settings self.skel_settings = SkelConfig(settings_filename) self.skel_conn = SkelIDAConnection(self.skel_settings) # If having 3 idbs in your current path bother you, change this self.crit_backup_file = idc.get_idb_path()[:-4] + "_backup_preskel.idb" self.backup_file = idc.get_idb_path()[:-4] + "_backup.idb" atexit.register(self.end_skelenox) logger.info("Backuping IDB before any intervention (_backup_preskel)") idc.save_database(self.crit_backup_file, idaapi.DBFL_TEMP) logger.info("Creating regular backup file IDB (_backup)") idc.save_database(self.backup_file, idaapi.DBFL_TEMP) self.last_saved = time.time() if self.skel_hooks is not None: self.skel_hooks.cleanup_hooks() if not self.skel_conn.get_online(): logger.error("Cannot get online =(") # Synchronize the sample self.skel_sync_agent = SkelSyncAgent() self.skel_sync_agent.setup_config(settings_filename) # setup hooks self.skel_hooks = SkelHooks(self.skel_conn) # setup UI if self.skel_settings.use_ui: self.skel_ui = SkelUI(settings_filename) # setup skelenox terminator self.setup_terminator() logger.info("Skelenox init finished")
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._progress_callback(progress, 1, 1) # Get the absolute path of the file fileName = branch.uuid + ('.i64' if branch.bits == 64 else '.idb') 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) # Show a success dialog # success = QMessageBox() # success.setIcon(QMessageBox.Information) # success.setStandardButtons(QMessageBox.Ok) # success.setText("Database successfully downloaded!") # success.setWindowTitle("Open from server") # iconPath = self._plugin.getResource('download.png') # success.setWindowIcon(QIcon(iconPath)) # success.exec_() # Save the old database idbPath = idc.GetIdbPath() if idbPath: idc.save_database(idbPath, 0) # Save the current state self._plugin.core.save_state(idbPath) # Open the new database QProcess.startDetached(qApp.applicationFilePath(), [filePath]) qApp.quit() # FIXME: Find an alternative, if any
from xmlrpc.server import SimpleXMLRPCServer from xml.sax.saxutils import escape import idaapi import idc # Wait for any processing to get done idaapi.auto_wait() # On Windows with NTFS filesystem a filepath with ':' # is treated as NTFS ADS (Alternative Data Stream) # and so saving file with such name fails dt = datetime.datetime.now().isoformat().replace(":", "-") # Save the database so nothing gets lost. idc.save_database(idc.get_idb_path() + "." + dt) DEBUG_MARSHALLING = False def create_marshaller(use_format=None, just_to_str=False): assert ( use_format or just_to_str ), "Either pass format to use or make it converting the value to str." def wrapper(_marshaller, value, appender): if use_format: marshalled = use_format % value elif just_to_str: marshalled = "<value><string>%s</string></value>" % escape( str(value))