"Fossies" - the Fresh Open Source Software Archive

Member "cutter-1.10.3/src/core/Cutter.h" (8 May 2020, 26255 Bytes) of package /linux/privat/cutter-1.10.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Cutter.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.10.2_vs_1.10.3.

    1 #ifndef CUTTER_H
    2 #define CUTTER_H
    3 
    4 #include "core/CutterCommon.h"
    5 #include "core/CutterDescriptions.h"
    6 #include "common/BasicInstructionHighlighter.h"
    7 
    8 #include <QMap>
    9 #include <QMenu>
   10 #include <QDebug>
   11 #include <QObject>
   12 #include <QStringList>
   13 #include <QMessageBox>
   14 #include <QJsonDocument>
   15 #include <QErrorMessage>
   16 #include <QMutex>
   17 #include <QDir>
   18 
   19 class AsyncTaskManager;
   20 class BasicInstructionHighlighter;
   21 class CutterCore;
   22 class Decompiler;
   23 class R2Task;
   24 class R2TaskDialog;
   25 
   26 #include "plugins/CutterPlugin.h"
   27 #include "common/BasicBlockHighlighter.h"
   28 #include "common/R2Task.h"
   29 #include "dialogs/R2TaskDialog.h"
   30 
   31 #define Core() (CutterCore::instance())
   32 
   33 class RCoreLocked;
   34 
   35 class CutterCore: public QObject
   36 {
   37     Q_OBJECT
   38 
   39     friend class RCoreLocked;
   40     friend class R2Task;
   41 
   42 public:
   43     explicit CutterCore(QObject *parent = nullptr);
   44     ~CutterCore();
   45     static CutterCore *instance();
   46 
   47     void initialize(bool loadPlugins = true);
   48     void loadCutterRC();
   49 
   50     AsyncTaskManager *getAsyncTaskManager() { return asyncTaskManager; }
   51 
   52     RVA getOffset() const                   { return core_->offset; }
   53 
   54     /* Core functions (commands) */
   55     static QString sanitizeStringForCommand(QString s);
   56     /**
   57      * @brief send a command to radare2
   58      * @param str the command you want to execute
   59      * @return command output
   60      * @note if you want to seek to an address, you should use CutterCore::seek.
   61      */
   62     QString cmd(const char *str);
   63     QString cmd(const QString &str) { return cmd(str.toUtf8().constData()); }
   64     /**
   65      * @brief send a command to radare2 asynchronously
   66      * @param str the command you want to execute
   67      * @param task a shared pointer that will be returned with the R2 command task
   68      * @note connect to the &R2Task::finished signal to add your own logic once
   69      *       the command is finished. Use task->getResult()/getResultJson() for the 
   70      *       return value.
   71      *       Once you have setup connections you can start the task with task->startTask()
   72      *       If you want to seek to an address, you should use CutterCore::seek.
   73      */
   74     bool asyncCmd(const char *str, QSharedPointer<R2Task> &task);
   75     bool asyncCmd(const QString &str, QSharedPointer<R2Task> &task) { return asyncCmd(str.toUtf8().constData(), task); }
   76 
   77     /**
   78      * @brief Execute a radare2 command \a cmd.  By nature, the API
   79      * is executing raw commands, and thus ignores multiple commands and overcome command injections.
   80      * @param cmd - a raw command to execute. Passing multiple commands (e.g "px 5; pd 7 && pdf") will result in them treated as arguments to first command.
   81      * @return the output of the command
   82      */
   83     QString cmdRaw(const char *cmd);
   84 
   85     /**
   86      * @brief a wrapper around cmdRaw(const char *cmd,).
   87      */
   88     QString cmdRaw(const QString &cmd) { return cmdRaw(cmd.toUtf8().constData()); };
   89 
   90     /**
   91      * @brief Execute a radare2 command \a cmd at \a address. The function will preform a silent seek to the address
   92      * without triggering the seekChanged event nor adding new entries to the seek history. By nature, the
   93      * API is executing a single command without going through radare2 shell, and thus ignores multiple commands 
   94      * and tries to overcome command injections.
   95      * @param cmd - a raw command to execute. If multiple commands will be passed (e.g "px 5; pd 7 && pdf") then
   96      * only the first command will be executed.
   97      * @param address - an address to which Cutter will temporarily seek.
   98      * @return the output of the command
   99      */
  100     QString cmdRawAt(const char *cmd, RVA address);
  101     
  102     /**
  103      * @brief a wrapper around cmdRawAt(const char *cmd, RVA address).
  104      */
  105     QString cmdRawAt(const QString &str, RVA address) { return cmdRawAt(str.toUtf8().constData(), address); }
  106     
  107     QJsonDocument cmdj(const char *str);
  108     QJsonDocument cmdj(const QString &str) { return cmdj(str.toUtf8().constData()); }
  109     QStringList cmdList(const char *str) { return cmd(str).split(QLatin1Char('\n'), QString::SkipEmptyParts); }
  110     QStringList cmdList(const QString &str) { return cmdList(str.toUtf8().constData()); }
  111     QString cmdTask(const QString &str);
  112     QJsonDocument cmdjTask(const QString &str);
  113     /**
  114      * @brief send a command to radare2 and check for ESIL errors
  115      * @param command the command you want to execute
  116      * @note If you want to seek to an address, you should use CutterCore::seek.
  117      */
  118     void cmdEsil(const char *command);
  119     void cmdEsil(const QString &command) { cmdEsil(command.toUtf8().constData()); }
  120     /**
  121      * @brief send a command to radare2 and check for ESIL errors
  122      * @param command the command you want to execute
  123      * @param task a shared pointer that will be returned with the R2 command task
  124      * @note connect to the &R2Task::finished signal to add your own logic once
  125      *       the command is finished. Use task->getResult()/getResultJson() for the 
  126      *       return value.
  127      *       Once you have setup connections you can start the task with task->startTask()
  128      *       If you want to seek to an address, you should use CutterCore::seek.
  129      */
  130     bool asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task);
  131     bool asyncCmdEsil(const QString &command, QSharedPointer<R2Task> &task) { return asyncCmdEsil(command.toUtf8().constData(), task); }
  132     QString getVersionInformation();
  133 
  134     QJsonDocument parseJson(const char *res, const char *cmd = nullptr);
  135     QJsonDocument parseJson(const char *res, const QString &cmd = QString())
  136     {
  137         return parseJson(res, cmd.isNull() ? nullptr : cmd.toLocal8Bit().constData());
  138     }
  139 
  140     QStringList autocomplete(const QString &cmd, RLinePromptType promptType, size_t limit = 4096);
  141 
  142     /* Functions methods */
  143     void renameFunction(const QString &oldName, const QString &newName);
  144     void delFunction(RVA addr);
  145     void renameFlag(QString old_name, QString new_name);
  146 
  147     /**
  148      * @param addr
  149      * @return a function that contains addr or nullptr
  150      */
  151     RAnalFunction *functionIn(ut64 addr);
  152 
  153     /**
  154      * @param addr
  155      * @return the function that has its entrypoint at addr or nullptr
  156      */
  157     RAnalFunction *functionAt(ut64 addr);
  158 
  159     RVA getFunctionStart(RVA addr);
  160     RVA getFunctionEnd(RVA addr);
  161     RVA getLastFunctionInstruction(RVA addr);
  162     QString cmdFunctionAt(QString addr);
  163     QString cmdFunctionAt(RVA addr);
  164     QString createFunctionAt(RVA addr);
  165     QString createFunctionAt(RVA addr, QString name);
  166     QStringList getDisassemblyPreview(RVA address, int num_of_lines);
  167 
  168     /* Flags */
  169     void delFlag(RVA addr);
  170     void delFlag(const QString &name);
  171     void addFlag(RVA offset, QString name, RVA size);
  172     QString listFlagsAsStringAt(RVA addr);
  173     /**
  174      * @brief Get nearest flag at or before offset.
  175      * @param offset search position
  176      * @param flagOffsetOut address of returned flag
  177      * @return flag name
  178      */
  179     QString nearestFlag(RVA offset, RVA *flagOffsetOut);
  180     void triggerFlagsChanged();
  181 
  182     /* Edition functions */
  183     QString getInstructionBytes(RVA addr);
  184     QString getInstructionOpcode(RVA addr);
  185     void editInstruction(RVA addr, const QString &inst);
  186     void nopInstruction(RVA addr);
  187     void jmpReverse(RVA addr);
  188     void editBytes(RVA addr, const QString &inst);
  189     void editBytesEndian(RVA addr, const QString &bytes);
  190 
  191     /* Code/Data */
  192     void setToCode(RVA addr);
  193     enum class StringTypeFormats { None, ASCII_LATIN1, UTF8 };
  194     /**
  195      * @brief Adds string at address
  196      * That function calls the 'Cs' command
  197      * \param addr The address of the array where the string will be applied
  198      * \param size The size of string
  199      * \param type The type of string
  200      */
  201     void setAsString(RVA addr, int size = 0, StringTypeFormats type = StringTypeFormats::None);
  202     /**
  203      * @brief Removes string at address
  204      * That function calls the 'Cs-' command
  205      * \param addr The address of the array where the string will be applied
  206      */
  207     void removeString(RVA addr);
  208     /**
  209      * @brief Gets string at address
  210      * That function calls the 'ps' command
  211      * \param addr The address of the first byte of the array
  212      * @return string at requested address
  213      */
  214     QString getString(RVA addr);
  215     void setToData(RVA addr, int size, int repeat = 1);
  216     int sizeofDataMeta(RVA addr);
  217 
  218     /* Comments */
  219     void setComment(RVA addr, const QString &cmt);
  220     void delComment(RVA addr);
  221     QString getCommentAt(RVA addr);
  222     void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
  223     void setCurrentBits(int bits, RVA offset = RVA_INVALID);
  224 
  225     /**
  226      * @brief Changes immediate displacement to structure offset
  227      * This function makes use of the "aht" command of r2 to apply structure
  228      * offset to the immediate displacement used in the given instruction
  229      * \param structureOffset The name of struct which will be applied
  230      * \param offset The address of the instruction where the struct will be applied
  231      */
  232     void applyStructureOffset(const QString &structureOffset, RVA offset = RVA_INVALID);
  233 
  234     /* Classes */
  235     QList<QString> getAllAnalClasses(bool sorted);
  236     QList<AnalMethodDescription> getAnalClassMethods(const QString &cls);
  237     QList<AnalBaseClassDescription> getAnalClassBaseClasses(const QString &cls);
  238     QList<AnalVTableDescription> getAnalClassVTables(const QString &cls);
  239     void createNewClass(const QString &cls);
  240     void renameClass(const QString &oldName, const QString &newName);
  241     void deleteClass(const QString &cls);
  242     bool getAnalMethod(const QString &cls, const QString &meth, AnalMethodDescription *desc);
  243     void renameAnalMethod(const QString &className, const QString &oldMethodName, const QString &newMethodName);
  244     void setAnalMethod(const QString &cls, const AnalMethodDescription &meth);
  245 
  246     /* File related methods */
  247     bool loadFile(QString path, ut64 baddr = 0LL, ut64 mapaddr = 0LL, int perms = R_PERM_R,
  248                   int va = 0, bool loadbin = false, const QString &forceBinPlugin = QString());
  249     bool tryFile(QString path, bool rw);
  250     bool mapFile(QString path, RVA mapaddr);
  251     void loadScript(const QString &scriptname);
  252     QJsonArray getOpenedFiles();
  253 
  254     /* Seek functions */
  255     void seek(QString thing);
  256     void seek(ut64 offset);
  257     void seekSilent(ut64 offset);
  258     void seekSilent(QString thing) { seekSilent(math(thing)); }
  259     void seekPrev();
  260     void seekNext();
  261     void updateSeek();
  262     /**
  263      * @brief Raise a memory widget showing current offset, prefer last active
  264      * memory widget.
  265      */
  266     void showMemoryWidget();
  267     /**
  268      * @brief Seek to \p offset and raise a memory widget showing it.
  269      * @param offset
  270      */
  271     void seekAndShow(ut64 offset);
  272     /**
  273      * @brief \see CutterCore::show(ut64)
  274      * @param thing - addressable expression
  275      */
  276     void seekAndShow(QString thing);
  277     RVA getOffset();
  278     RVA prevOpAddr(RVA startAddr, int count);
  279     RVA nextOpAddr(RVA startAddr, int count);
  280 
  281     /* Math functions */
  282     ut64 math(const QString &expr);
  283     ut64 num(const QString &expr);
  284     QString itoa(ut64 num, int rdx = 16);
  285 
  286     /* Config functions */
  287     void setConfig(const char *k, const QString &v);
  288     void setConfig(const QString &k, const QString &v) { setConfig(k.toUtf8().constData(), v); }
  289     void setConfig(const char *k, int v);
  290     void setConfig(const QString &k, int v) { setConfig(k.toUtf8().constData(), v); }
  291     void setConfig(const char *k, bool v);
  292     void setConfig(const QString &k, bool v) { setConfig(k.toUtf8().constData(), v); }
  293     void setConfig(const char *k, const QVariant &v);
  294     void setConfig(const QString &k, const QVariant &v) { setConfig(k.toUtf8().constData(), v); }
  295     int getConfigi(const char *k);
  296     int getConfigi(const QString &k) { return getConfigi(k.toUtf8().constData()); }
  297     ut64 getConfigut64(const char *k);
  298     ut64 getConfigut64(const QString &k) { return getConfigut64(k.toUtf8().constData()); }
  299     bool getConfigb(const char *k);
  300     bool getConfigb(const QString &k) { return getConfigb(k.toUtf8().constData()); }
  301     QString getConfig(const char *k);
  302     QString getConfig(const QString &k) { return getConfig(k.toUtf8().constData()); }
  303     QString getConfigDescription(const char *k);
  304     QList<QString> getColorThemes();
  305 
  306     /* Assembly\Hexdump related methods */
  307     QByteArray assemble(const QString &code);
  308     QString disassemble(const QByteArray &data);
  309     QString disassembleSingleInstruction(RVA addr);
  310     QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
  311 
  312     static QByteArray hexStringToBytes(const QString &hex);
  313     static QString bytesToHexString(const QByteArray &bytes);
  314     enum class HexdumpFormats { Normal, Half, Word, Quad, Signed, Octal };
  315     QString hexdump(RVA offset, int size, HexdumpFormats format);
  316     QString getHexdumpPreview(RVA offset, int size);
  317 
  318     void setCPU(QString arch, QString cpu, int bits);
  319     void setEndianness(bool big);
  320 
  321     /* SDB */
  322     QList<QString> sdbList(QString path);
  323     QList<QString> sdbListKeys(QString path);
  324     QString sdbGet(QString path, QString key);
  325     bool sdbSet(QString path, QString key, QString val);
  326 
  327     /* Debug */
  328     QJsonDocument getRegistersInfo();
  329     QJsonDocument getRegisterValues();
  330     QString getRegisterName(QString registerRole);
  331     RVA getProgramCounterValue();
  332     void setRegister(QString regName, QString regValue);
  333     void setCurrentDebugThread(int tid);
  334     /**
  335      * @brief Attach to a given pid from a debug session
  336      */
  337     void setCurrentDebugProcess(int pid);
  338     /**
  339      * @brief Returns a list of stack address and their telescoped references
  340      * @param size number of bytes to scan
  341      * @param depth telescoping depth 
  342      */
  343     QList<QJsonObject> getStack(int size = 0x100, int depth = 6);
  344     /**
  345      * @brief Recursively dereferences pointers starting at the specified address
  346      *        up to a given depth
  347      * @param addr telescoping addr
  348      * @param depth telescoping depth 
  349      */
  350     QJsonObject getAddrRefs(RVA addr, int depth);
  351     /**
  352      * @brief return a RefDescription with a formatted ref string and configured colors
  353      * @param ref the "ref" JSON node from getAddrRefs
  354      */
  355     RefDescription formatRefDesc(QJsonObject ref);
  356     /**
  357      * @brief Get a list of a given process's threads
  358      * @param pid The pid of the process, -1 for the currently debugged process
  359      * @return JSON object result of dptj
  360      */
  361     QJsonDocument getProcessThreads(int pid);
  362     /**
  363      * @brief Get a list of a given process's child processes
  364      * @param pid The pid of the process, -1 for the currently debugged process
  365      * @return JSON object result of dptj
  366      */
  367     QJsonDocument getChildProcesses(int pid);
  368     QJsonDocument getBacktrace();
  369     void startDebug();
  370     void startEmulation();
  371     /**
  372      * @brief attach to a remote debugger
  373      * @param uri remote debugger uri
  374      * @note attachedRemote(bool) signals the result
  375      */
  376     void attachRemote(const QString &uri);
  377     void attachDebug(int pid);
  378     void stopDebug();
  379     void suspendDebug();
  380     void syncAndSeekProgramCounter();
  381     void continueDebug();
  382     void continueUntilCall();
  383     void continueUntilSyscall();
  384     void continueUntilDebug(QString offset);
  385     void stepDebug();
  386     void stepOverDebug();
  387     void stepOutDebug();
  388 
  389     void addBreakpoint(QString addr);
  390     void addBreakpoint(const BreakpointDescription &config);
  391     void updateBreakpoint(int index, const BreakpointDescription &config);
  392     void toggleBreakpoint(RVA addr);
  393     void toggleBreakpoint(QString addr);
  394     void delBreakpoint(RVA addr);
  395     void delAllBreakpoints();
  396     void enableBreakpoint(RVA addr);
  397     void disableBreakpoint(RVA addr);
  398     /**
  399      * @brief Enable or disable breakpoint tracing.
  400      * @param index - breakpoint index to modify
  401      * @param enabled - true if tracing should be enabled
  402      */
  403     void setBreakpointTrace(int index, bool enabled);
  404     int breakpointIndexAt(RVA addr);
  405     BreakpointDescription getBreakpointAt(RVA addr);
  406 
  407     bool isBreakpoint(const QList<RVA> &breakpoints, RVA addr);
  408     QList<RVA> getBreakpointsAddresses();
  409     
  410     /**
  411      * @brief Get all breakpoinst that are belong to a functions at this address
  412      */
  413     QList<RVA> getBreakpointsInFunction(RVA funcAddr);
  414     QString getActiveDebugPlugin();
  415     QStringList getDebugPlugins();
  416     void setDebugPlugin(QString plugin);
  417     bool isDebugTaskInProgress();
  418     /**
  419      * @brief Check if we can use output/input redirection with the currently debugged process
  420      */
  421     bool isRedirectableDebugee();
  422     bool currentlyDebugging = false;
  423     bool currentlyEmulating = false;
  424     int currentlyAttachedToPID = -1;
  425     QString currentlyOpenFile;
  426 
  427     /* Decompilers */
  428     QList<Decompiler *> getDecompilers();
  429     Decompiler *getDecompilerById(const QString &id);
  430 
  431     /**
  432      * Register a new decompiler
  433      *
  434      * The decompiler must have a unique id, otherwise this method will fail.
  435      * The decompiler's parent will be set to this CutterCore instance, so it will automatically be freed later.
  436      *
  437      * @return whether the decompiler was registered successfully
  438      */
  439     bool registerDecompiler(Decompiler *decompiler);
  440 
  441     RVA getOffsetJump(RVA addr);
  442     QJsonDocument getFileInfo();
  443     QJsonDocument getSignatureInfo();
  444     QJsonDocument getFileVersionInfo();
  445     QStringList getStats();
  446     void setGraphEmpty(bool empty);
  447     bool isGraphEmpty();
  448 
  449     void getOpcodes();
  450     QList<QString> opcodes;
  451     QList<QString> regs;
  452     void setSettings();
  453 
  454     void loadPDB(const QString &file);
  455 
  456     QByteArray ioRead(RVA addr, int len);
  457 
  458     QList<RVA> getSeekHistory();
  459 
  460     /* Plugins */
  461     QStringList getAsmPluginNames();
  462     QStringList getAnalPluginNames();
  463 
  464     /* Projects */
  465     QStringList getProjectNames();
  466     void openProject(const QString &name);
  467     void saveProject(const QString &name);
  468     void deleteProject(const QString &name);
  469     static bool isProjectNameValid(const QString &name);
  470 
  471     /* Widgets */
  472     QList<RBinPluginDescription> getRBinPluginDescriptions(const QString &type = QString());
  473     QList<RIOPluginDescription> getRIOPluginDescriptions();
  474     QList<RCorePluginDescription> getRCorePluginDescriptions();
  475     QList<RAsmPluginDescription> getRAsmPluginDescriptions();
  476     QList<FunctionDescription> getAllFunctions();
  477     QList<ImportDescription> getAllImports();
  478     QList<ExportDescription> getAllExports();
  479     QList<SymbolDescription> getAllSymbols();
  480     QList<HeaderDescription> getAllHeaders();
  481     QList<ZignatureDescription> getAllZignatures();
  482     QList<CommentDescription> getAllComments(const QString &filterType);
  483     QList<RelocDescription> getAllRelocs();
  484     QList<StringDescription> getAllStrings();
  485     QList<FlagspaceDescription> getAllFlagspaces();
  486     QList<FlagDescription> getAllFlags(QString flagspace = QString());
  487     QList<SectionDescription> getAllSections();
  488     QList<SegmentDescription> getAllSegments();
  489     QList<EntrypointDescription> getAllEntrypoint();
  490     QList<BinClassDescription> getAllClassesFromBin();
  491     QList<BinClassDescription> getAllClassesFromFlags();
  492     QList<ResourcesDescription> getAllResources();
  493     QList<VTableDescription> getAllVTables();
  494 
  495     /**
  496      * @return all loaded types
  497      */
  498     QList<TypeDescription> getAllTypes();
  499 
  500     /**
  501      * @return all loaded primitive types
  502      */
  503     QList<TypeDescription> getAllPrimitiveTypes();
  504 
  505     /**
  506      * @return all loaded unions
  507      */
  508     QList<TypeDescription> getAllUnions();
  509 
  510     /**
  511      * @return all loaded structs
  512      */
  513     QList<TypeDescription> getAllStructs();
  514 
  515     /**
  516      * @return all loaded enums
  517      */
  518     QList<TypeDescription> getAllEnums();
  519 
  520     /**
  521      * @return all loaded typedefs
  522      */
  523     QList<TypeDescription> getAllTypedefs();
  524 
  525     /**
  526      * @brief Fetching the C representation of a given Type
  527      * @param name - the name or the type of the given Type / Struct
  528      * @param category - the category of the given Type (Struct, Union, Enum, ...)
  529      * @return The type decleration as C output
  530      */
  531     QString getTypeAsC(QString name, QString category);
  532 
  533 
  534     /**
  535      * @brief Adds new types
  536      * It first uses the r_parse_c_string() function from radare2 API to parse the
  537      * supplied C file (in the form of a string). If there were errors, they are displayed.
  538      * If there were no errors, it uses sdb_query_lines() function from radare2 API
  539      * to save the parsed types returned by r_parse_c_string()
  540      * \param str Contains the definition of the data types
  541      * \return returns an empty QString if there was no error, else returns the error
  542      */
  543     QString addTypes(const char *str);
  544     QString addTypes(const QString &str) { return addTypes(str.toUtf8().constData()); }
  545 
  546     /**
  547      * @brief Checks if the given address is mapped to a region
  548      * @param addr The address to be checked
  549      * @return true if addr is mapped, false otherwise
  550      */
  551     bool isAddressMapped(RVA addr);
  552 
  553     QList<MemoryMapDescription> getMemoryMap();
  554     QList<SearchDescription> getAllSearch(QString search_for, QString space);
  555     BlockStatistics getBlockStatistics(unsigned int blocksCount);
  556     QList<BreakpointDescription> getBreakpoints();
  557     QList<ProcessDescription> getAllProcesses();
  558     /**
  559      * @brief returns a list of reg values and their telescoped references
  560      * @param depth telescoping depth
  561      */
  562     QList<QJsonObject> getRegisterRefs(int depth = 6);
  563     QVector<RegisterRefValueDescription> getRegisterRefValues();
  564     QList<VariableDescription> getVariables(RVA at);
  565 
  566     QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function,
  567                                     const QString &filterType = QString());
  568 
  569     QList<StringDescription> parseStringsJson(const QJsonDocument &doc);
  570 
  571     void handleREvent(int type, void *data);
  572 
  573     /* Signals related */
  574     void triggerVarsChanged();
  575     void triggerFunctionRenamed(const QString &prevName, const QString &newName);
  576     void triggerRefreshAll();
  577     void triggerAsmOptionsChanged();
  578     void triggerGraphOptionsChanged();
  579 
  580     void message(const QString &msg, bool debug = false);
  581 
  582     QStringList getSectionList();
  583 
  584     RCoreLocked core();
  585 
  586     static QString ansiEscapeToHtml(const QString &text);
  587     BasicBlockHighlighter *getBBHighlighter();
  588     BasicInstructionHighlighter *getBIHighlighter();
  589 
  590     /**
  591      * @brief Enable or dsiable Cache mode. Cache mode is used to imagine writing to the opened file
  592      * without committing the changes to the disk.
  593      * @param enabled
  594      */
  595     void setIOCache(bool enabled);
  596 
  597     /**
  598      * @brief Check if Cache mode is enabled.
  599      * @return true if Cache is enabled, otherwise return false.
  600      */
  601     bool isIOCacheEnabled() const;
  602 
  603     /**
  604      * @brief Commit write cache to the file on disk.
  605      */
  606     void commitWriteCache();
  607 
  608     /**
  609      * @brief Enable or disable Write mode. When the file is opened in write mode, any changes to it will be immediately
  610      * committed to the file on disk, thus modify the file. This function wrap radare2 function which re-open the file with
  611      * the desired permissions.
  612      * @param enabled
  613      */
  614     void setWriteMode(bool enabled);
  615     /**
  616      * @brief Check if the file is opened in write mode.
  617      * @return true if write mode is enabled, otherwise return false.
  618      */
  619     bool isWriteModeEnabled();
  620 
  621 signals:
  622     void refreshAll();
  623 
  624     void functionRenamed(const QString &prev_name, const QString &new_name);
  625     void varsChanged();
  626     void functionsChanged();
  627     void flagsChanged();
  628     void commentsChanged();
  629     void registersChanged();
  630     void instructionChanged(RVA offset);
  631     void breakpointsChanged();
  632     void refreshCodeViews();
  633     void stackChanged();
  634     /**
  635      * @brief update all the widgets that are affected by rebasing in debug mode
  636      */
  637     void codeRebased();
  638 
  639     void switchedThread();
  640     void switchedProcess();
  641 
  642     void classNew(const QString &cls);
  643     void classDeleted(const QString &cls);
  644     void classRenamed(const QString &oldName, const QString &newName);
  645     void classAttrsChanged(const QString &cls);
  646 
  647     /**
  648      * @brief end of current debug event received
  649      */
  650     void debugProcessFinished(int pid);
  651 
  652     void attachedRemote(bool successfully);
  653 
  654     void projectSaved(bool successfully, const QString &name);
  655 
  656     void ioCacheChanged(bool newval);
  657     void writeModeChanged(bool newval);
  658 
  659     /**
  660      * emitted when debugTask started or finished running
  661      */
  662     void debugTaskStateChanged();
  663 
  664     /**
  665      * emitted when config regarding disassembly display changes
  666      */
  667     void asmOptionsChanged();
  668 
  669     /**
  670      * emitted when config regarding graph display changes
  671      */
  672     void graphOptionsChanged();
  673 
  674     /**
  675      * @brief seekChanged is emitted each time radare2 seek value is modified
  676      * @param offset
  677      */
  678     void seekChanged(RVA offset);
  679 
  680     void toggleDebugView();
  681 
  682     void newMessage(const QString &msg);
  683     void newDebugMessage(const QString &msg);
  684 
  685     void showMemoryWidgetRequested();
  686 
  687 private:
  688     QString notes;
  689 
  690     /**
  691      * Internal reference to the RCore.
  692      * NEVER use this directly! Always use the CORE_LOCK(); macro and access it like core->...
  693      */
  694     RCore *core_ = nullptr;
  695     QMutex coreMutex;
  696     int coreLockDepth = 0;
  697     void *coreBed = nullptr;
  698 
  699     AsyncTaskManager *asyncTaskManager;
  700     RVA offsetPriorDebugging = RVA_INVALID;
  701     QErrorMessage msgBox;
  702 
  703     QList<Decompiler *> decompilers;
  704 
  705     bool emptyGraph = false;
  706     BasicBlockHighlighter *bbHighlighter;
  707     bool iocache = false;
  708     BasicInstructionHighlighter biHighlighter;
  709 
  710     QSharedPointer<R2Task> debugTask;
  711     R2TaskDialog *debugTaskDialog;
  712     
  713     QVector<QDir> getCutterRCDirectories() const;
  714 };
  715 
  716 class RCoreLocked
  717 {
  718     CutterCore * const core;
  719 
  720 public:
  721     explicit RCoreLocked(CutterCore *core);
  722     RCoreLocked(const RCoreLocked &) = delete;
  723     RCoreLocked &operator=(const RCoreLocked &) = delete;
  724     RCoreLocked(RCoreLocked &&);
  725     ~RCoreLocked();
  726     operator RCore *() const;
  727     RCore *operator->() const;
  728 };
  729 
  730 #endif // CUTTER_H