def overwriteSymbolToggle(self): FrLSettings().setOverwriteSymbolName( not FrLSettings().getOverwriteSymbolName()) if FrLSettings().getOverwriteSymbolName(): fl_log("FridaLink: Symbol Overwrite enabled\n") else: fl_log("FridaLink: Symbol Overwrite disabled\n")
def loadProject(self): if self.clientSocket == None: fl_log("FridaLink: Frida not connected\n") return filePath = AskFile(0, "*.flp", "Open FridaLink project") if filePath is None: return with open(filePath, 'rb') as file: settings = pickle.load(file) hooks = pickle.load(file) repl = pickle.load(file) memory = pickle.load(file) frida = pickle.load(file) FrLSettings().restore(settings) self.deleteAllHooks() self.deleteAllReplaced() self.restoreHookData(hooks) self.restoreReplacedFuncData(repl) self.restoreMemoryData(memory) self.restoreFridaData(frida) file.close() fl_log("FridaLink: project loaded\n")
def termThread(self): if self.clientSocket is not None: self.clientSocket.shutdown(socket.SHUT_RDWR) if self.serverRunning == True: self.server.shutdown() self.serverStopped.wait(3) self.serverThread = None fl_log("FridaLink: unloaded\n")
def startServer(self): FrLModules.SanityChecks() FrLModules.GetNextModuleBase() if FrLSettings().getOverwriteSymbolName(): fl_log("FridaLink: Symbol Overwrite enabled\n") else: fl_log("FridaLink: Symbol Overwrite disabled\n") if self.server is None: self.serverThread = threading.Thread(target=self.serverTask) self.serverThread.start()
def init(self): # FIXME: make init method for modules super(FridaLinkPlugin, self).__init__() fl_log("FridaLink: loaded\n") self.server = None self.serverThread = None self.serverStopped = threading.Event() self.serverRunning = False self.clientSocket = None self.clientAddress = None return PLUGIN_KEEP
def saveProject(self): filePath = AskFile(1, "*.flp", "Save FridaLink project") if filePath is None: return with open(filePath, 'wb') as file: pickle.dump(FrLSettings(), file, pickle.HIGHEST_PROTOCOL) pickle.dump(self.backupHookData(), file, pickle.HIGHEST_PROTOCOL) pickle.dump(self.backupReplacedFuncData(), file, pickle.HIGHEST_PROTOCOL) pickle.dump(self.backupMemoryData(), file, pickle.HIGHEST_PROTOCOL) pickle.dump(self.backupFridaData(), file, pickle.HIGHEST_PROTOCOL) file.close() fl_log("FridaLink: project saved\n")
def handle(self): # allow only one FridaLink connection if self.server.engine.clientSocket is not None: return fl_log("FridaLink: established with " + str(self.client_address) + "\n") self.server.engine.clientSocket = self.request self.server.engine.clientAddress = self.client_address self.server.engine.clientConnected() while True: header = self.request.recv(8) if not header: break try: dataLength = int(header) except Exception as e: fl_log("FridaLink: invalid header %s" % header) msg = "" while dataLength != 0: bytesToRead = dataLength if dataLength < 4096 else 4096 data = self.request.recv(bytesToRead) msg += data dataLength -= bytesToRead self.handleFridaRequest(msg) self.server.engine.clientSocket = None self.server.engine.clientAddress = None fl_log("FridaLink: closed with " + str(self.client_address) + "\n") self.request.close()
def serverTask(self): try: self.server = SocketServer.ThreadingTCPServer( (FrLSettings().getHost(), FrLSettings().getPort()), MessageHandler) self.server.engine = self fl_log("FridaLink: SERVER STARTED!\n") self.serverStopped.clear() self.serverRunning = True self.server.serve_forever() self.serverRunning = False self.server.server_close() self.server = None fl_log("FridaLink: SERVER STOPPED!\n") self.serverStopped.set() except Exception, e: fl_log("FridaLink: Unable to start server!\n") self.server = None raise e
def logToggle(self): if FrLSettings().getLogEnabled(): fl_log("FridaLink: Debug Log disabled\n") FrLSettings().setLogEnabled(not FrLSettings().getLogEnabled()) if FrLSettings().getLogEnabled(): fl_log("FridaLink: Debug Log enabled\n")
def run(self, arg=0): fl_log("FridaLink: run()\n") IdaMainMenu.RegisterMenuActions(self) IdaPopupMenus.RegisterMenuActions(self) self.handleBuildImport() self.startServer()
def run(self, arg): fl_log("FridaLink: run(%d)\n" % arg)
def handleFridaRequest(self, message): decoder = json.JSONDecoder() while message: try: inJSON, idx = decoder.raw_decode(message) except Exception as e: fl_log( "FridaLink: unable to decode JSON message: %s\n-------%s\n-------\n" % (str(e), message)) return if inJSON['req_id'] == kFridaLink_TargetInfo: targetInfo = TargetInfoCallable(self.server.engine, inJSON['platform'], inJSON['arch']) execute_sync(targetInfo, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_ModulesResponse: modules = ModulesResponseCallable(self.server.engine, inJSON['response']) execute_sync(modules, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_HookResponse: hook = HookCallable(self.server.engine, inJSON['platform'], inJSON['arch'], inJSON['response']) execute_sync(hook, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_ReplaceResponse: replace = ReplaceCallable(self.server.engine, inJSON['response']) execute_sync(replace, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_FetchMemResponse: hook = MemoryCallable(self.server.engine, inJSON['platform'], inJSON['arch'], inJSON['response']) execute_sync(hook, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_FraplLogEntry: fraplLog = FraplLogCallable(self.server.engine, inJSON['log_type'], inJSON['log_entry']) execute_sync(fraplLog, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_TargetLogEntry: targetLog = TargetLogCallable(self.server.engine, inJSON['log_header'], inJSON['log_entry']) execute_sync(targetLog, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_DBQuery: query = QueryCallable(self.server.engine, inJSON['db_id'], inJSON['query']) execute_sync(query, 0) self.sendAck() elif inJSON['req_id'] == kFridaLink_ProcessBacktrace: backtrace = BacktraceCallable(self.server.engine, inJSON['platform'], inJSON['arch'], inJSON['request']) execute_sync(backtrace, 0) outJSON = json.dumps({ "req_id": kFridaLink_ProcessBacktrace, "request": backtrace.request }) self.request.sendto(outJSON, self.client_address) message = message[idx:].lstrip()