CutterCore

class CutterCore : public QObject

Public Types

enum StringTypeFormats

Values:

enumerator None
enumerator ASCII_LATIN1
enumerator UTF8
enum HexdumpFormats

Values:

enumerator Normal
enumerator Half
enumerator Word
enumerator Quad
enumerator Signed
enumerator Octal

Public Functions

CutterCore(QObject *parent = nullptr)
~CutterCore()
void initialize(bool loadPlugins = true)
void loadCutterRC()
void loadDefaultCutterRC()
QDir getCutterRCDefaultDirectory() const
AsyncTaskManager *getAsyncTaskManager()
RVA getOffset() const
QString cmd(const char *str)

send a command to radare2

Return

command output

Note

if you want to seek to an address, you should use CutterCore::seek.

Parameters
  • str: the command you want to execute

QString cmd(const QString &str)
bool asyncCmd(const char *str, QSharedPointer<R2Task> &task)

send a command to radare2 asynchronously

Note

connect to the &R2Task::finished signal to add your own logic once the command is finished. Use task->getResult()/getResultJson() for the return value. Once you have setup connections you can start the task with task->startTask() If you want to seek to an address, you should use CutterCore::seek.

Parameters
  • str: the command you want to execute

  • task: a shared pointer that will be returned with the R2 command task

bool asyncCmd(const QString &str, QSharedPointer<R2Task> &task)
QString cmdRaw(const char *cmd)

Execute a radare2 command cmd. By nature, the API is executing raw commands, and thus ignores multiple commands and overcome command injections.

Return

the output of the command

Parameters
  • 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.

QString cmdRaw(const QString &cmd)

a wrapper around cmdRaw(const char *cmd,).

QString cmdRawAt(const char *cmd, RVA address)

Execute a radare2 command cmd at address. The function will preform a silent seek to the address without triggering the seekChanged event nor adding new entries to the seek history. By nature, the API is executing a single command without going through radare2 shell, and thus ignores multiple commands and tries to overcome command injections.

Return

the output of the command

Parameters
  • cmd: - a raw command to execute. If multiple commands will be passed (e.g “px 5; pd 7 && pdf”) then only the first command will be executed.

  • address: - an address to which Cutter will temporarily seek.

QString cmdRawAt(const QString &str, RVA address)

a wrapper around cmdRawAt(const char *cmd, RVA address).

QJsonDocument cmdj(const char *str)
QJsonDocument cmdj(const QString &str)
QJsonDocument cmdjAt(const char *str, RVA address)
QStringList cmdList(const char *str)
QStringList cmdList(const QString &str)
QString cmdTask(const QString &str)
QJsonDocument cmdjTask(const QString &str)
void cmdEsil(const char *command)

send a command to radare2 and check for ESIL errors

Note

If you want to seek to an address, you should use CutterCore::seek.

Parameters
  • command: the command you want to execute

void cmdEsil(const QString &command)
bool asyncCmdEsil(const char *command, QSharedPointer<R2Task> &task)

send a command to radare2 and check for ESIL errors

Note

connect to the &R2Task::finished signal to add your own logic once the command is finished. Use task->getResult()/getResultJson() for the return value. Once you have setup connections you can start the task with task->startTask() If you want to seek to an address, you should use CutterCore::seek.

Parameters
  • command: the command you want to execute

  • task: a shared pointer that will be returned with the R2 command task

bool asyncCmdEsil(const QString &command, QSharedPointer<R2Task> &task)
QString getVersionInformation()
QJsonDocument parseJson(const char *res, const char *cmd = nullptr)
QJsonDocument parseJson(const char *res, const QString &cmd = QString())
QStringList autocomplete(const QString &cmd, RLinePromptType promptType, size_t limit = 4096)
void renameFunction(const RVA offset, const QString &newName)
void delFunction(RVA addr)
void renameFlag(QString old_name, QString new_name)
void renameFunctionVariable(QString newName, QString oldName, RVA functionAddress)

Renames the specified local variable in the function specified by the address given.

Parameters
  • newName: Specifies the name to which the current name of the variable should be renamed.

  • oldName: Specifies the current name of the function variable.

  • functionAddress: Specifies the exact address of the function.

RAnalFunction *functionIn(ut64 addr)

Return

a function that contains addr or nullptr

Parameters
  • addr:

RAnalFunction *functionAt(ut64 addr)

Return

the function that has its entrypoint at addr or nullptr

Parameters
  • addr:

RVA getFunctionStart(RVA addr)

finds the start address of a function in a given address

Return

if function exists, return its start address. Otherwise return RVA_INVALID

Parameters
  • addr: - an address which belongs to a function

RVA getFunctionEnd(RVA addr)

finds the end address of a function in a given address

Return

if function exists, return its end address. Otherwise return RVA_INVALID

Parameters
  • addr: - an address which belongs to a function

RVA getLastFunctionInstruction(RVA addr)

finds the last instruction of a function in a given address

Return

if function exists, return the address of its last instruction. Otherwise return RVA_INVALID

Parameters
  • addr: - an address which belongs to a function

QString cmdFunctionAt(QString addr)
QString cmdFunctionAt(RVA addr)
QString createFunctionAt(RVA addr)
QString createFunctionAt(RVA addr, QString name)
QStringList getDisassemblyPreview(RVA address, int num_of_lines)

get a compact disassembly preview for tooltips

Parameters
  • address: - the address from which to print the disassembly

  • num_of_lines: - number of instructions to print

void delFlag(RVA addr)
void delFlag(const QString &name)
void addFlag(RVA offset, QString name, RVA size)
QString listFlagsAsStringAt(RVA addr)

Gets all the flags present at a specific address.

Return

String containing all the flags which are comma-separated

Parameters
  • addr: The address to be checked

QString nearestFlag(RVA offset, RVA *flagOffsetOut)

Get nearest flag at or before offset.

Return

flag name

Parameters
  • offset: search position

  • flagOffsetOut: address of returned flag

void triggerFlagsChanged()
QString getInstructionBytes(RVA addr)
QString getInstructionOpcode(RVA addr)
void editInstruction(RVA addr, const QString &inst)
void nopInstruction(RVA addr)
void jmpReverse(RVA addr)
void editBytes(RVA addr, const QString &inst)
void editBytesEndian(RVA addr, const QString &bytes)
void setToCode(RVA addr)
void setAsString(RVA addr, int size = 0, StringTypeFormats type = StringTypeFormats::None)

Adds string at address That function calls the ‘Cs’ command.

Parameters
  • addr: The address of the array where the string will be applied

  • size: The size of string

  • type: The type of string

void removeString(RVA addr)

Removes string at address That function calls the ‘Cs-‘ command.

Parameters
  • addr: The address of the array where the string will be applied

QString getString(RVA addr)

Gets string at address That function calls the ‘ps’ command.

Return

string at requested address

Parameters
  • addr: The address of the first byte of the array

void setToData(RVA addr, int size, int repeat = 1)
int sizeofDataMeta(RVA addr)
void setComment(RVA addr, const QString &cmt)
void delComment(RVA addr)
QString getCommentAt(RVA addr)

Gets the comment present at a specific address.

Return

String containing comment

Parameters
  • addr: The address to be checked

void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID)
void setCurrentBits(int bits, RVA offset = RVA_INVALID)
void applyStructureOffset(const QString &structureOffset, RVA offset = RVA_INVALID)

Changes immediate displacement to structure offset This function makes use of the “aht” command of r2 to apply structure offset to the immediate displacement used in the given instruction.

Parameters
  • structureOffset: The name of struct which will be applied

  • offset: The address of the instruction where the struct will be applied

QList<QString> getAllAnalClasses(bool sorted)
QList<AnalMethodDescription> getAnalClassMethods(const QString &cls)
QList<AnalBaseClassDescription> getAnalClassBaseClasses(const QString &cls)
QList<AnalVTableDescription> getAnalClassVTables(const QString &cls)
void createNewClass(const QString &cls)
void renameClass(const QString &oldName, const QString &newName)
void deleteClass(const QString &cls)
bool getAnalMethod(const QString &cls, const QString &meth, AnalMethodDescription *desc)
void renameAnalMethod(const QString &className, const QString &oldMethodName, const QString &newMethodName)
void setAnalMethod(const QString &cls, const AnalMethodDescription &meth)
bool loadFile(QString path, ut64 baddr = 0LL, ut64 mapaddr = 0LL, int perms = R_PERM_R, int va = 0, bool loadbin = false, const QString &forceBinPlugin = QString())

CutterCore::loadFile Load initial file. TODO Maybe use the “o” commands?

Return

Parameters
  • path: File path

  • baddr: Base (RBin) address

  • mapaddr: Map address

  • perms:

  • va:

  • loadbin: Load RBin information

  • forceBinPlugin:

bool tryFile(QString path, bool rw)
bool mapFile(QString path, RVA mapaddr)

Maps a file using r2 API.

Return

bool

Parameters
  • path: Path to file

  • mapaddr: Map Address

void loadScript(const QString &scriptname)
QJsonArray getOpenedFiles()
void seek(QString thing)
void seek(ut64 offset)
void seekSilent(ut64 offset)
void seekSilent(QString thing)
void seekPrev()
void seekNext()
void updateSeek()
void showMemoryWidget()

Raise a memory widget showing current offset, prefer last active memory widget.

void seekAndShow(ut64 offset)

Seek to offset and raise a memory widget showing it.

Parameters
  • offset:

void seekAndShow(QString thing)

See

CutterCore::show(ut64)

Parameters
  • thing: - addressable expression

RVA getOffset()
RVA prevOpAddr(RVA startAddr, int count)
RVA nextOpAddr(RVA startAddr, int count)
ut64 math(const QString &expr)
ut64 num(const QString &expr)
QString itoa(ut64 num, int rdx = 16)
void setConfig(const char *k, const char *v)
void setConfig(const QString &k, const char *v)
void setConfig(const char *k, const QString &v)
void setConfig(const QString &k, const QString &v)
void setConfig(const char *k, int v)
void setConfig(const QString &k, int v)
void setConfig(const char *k, bool v)
void setConfig(const QString &k, bool v)
void setConfig(const char *k, const QVariant &v)
void setConfig(const QString &k, const QVariant &v)
int getConfigi(const char *k)
int getConfigi(const QString &k)
ut64 getConfigut64(const char *k)
ut64 getConfigut64(const QString &k)
bool getConfigb(const char *k)
bool getConfigb(const QString &k)
QString getConfig(const char *k)
QString getConfig(const QString &k)
QString getConfigDescription(const char *k)
QList<QString> getColorThemes()
QByteArray assemble(const QString &code)
QString disassemble(const QByteArray &data)
QString disassembleSingleInstruction(RVA addr)
QList<DisassemblyLine> disassembleLines(RVA offset, int lines)
QString hexdump(RVA offset, int size, HexdumpFormats format)

return hexdump of <size> from an <offset> by a given formats

Parameters
  • address: - the address from which to print the hexdump

  • size: - number of bytes to print

  • format: - the type of hexdump (qwords, words. decimal, etc)

QString getHexdumpPreview(RVA offset, int size)

get a compact hexdump preview for tooltips

Parameters
  • address: - the address from which to print the hexdump

  • size: - number of bytes to print

void setCPU(QString arch, QString cpu, int bits)
void setEndianness(bool big)
QList<QString> sdbList(QString path)
QList<QString> sdbListKeys(QString path)
QString sdbGet(QString path, QString key)
bool sdbSet(QString path, QString key, QString val)
QJsonDocument getRegistersInfo()
QJsonDocument getRegisterValues()
QString getRegisterName(QString registerRole)
RVA getProgramCounterValue()
void setRegister(QString regName, QString regValue)
void setCurrentDebugThread(int tid)
void setCurrentDebugProcess(int pid)

Attach to a given pid from a debug session.

QList<QJsonObject> getStack(int size = 0x100, int depth = 6)

Returns a list of stack address and their telescoped references.

Parameters
  • size: number of bytes to scan

  • depth: telescoping depth

QJsonObject getAddrRefs(RVA addr, int depth)

Recursively dereferences pointers starting at the specified address up to a given depth.

Parameters
  • addr: telescoping addr

  • depth: telescoping depth

RefDescription formatRefDesc(QJsonObject ref)

return a RefDescription with a formatted ref string and configured colors

Parameters
  • ref: the “ref” JSON node from getAddrRefs

QJsonDocument getProcessThreads(int pid)

Get a list of a given process’s threads.

Return

JSON object result of dptj

Parameters
  • pid: The pid of the process, -1 for the currently debugged process

QJsonDocument getChildProcesses(int pid)

Get a list of a given process’s child processes.

Return

JSON object result of dptj

Parameters
  • pid: The pid of the process, -1 for the currently debugged process

QJsonDocument getBacktrace()
void startDebug()
void startEmulation()
void attachRemote(const QString &uri)

attach to a remote debugger

Note

attachedRemote(bool) signals the result

Parameters
  • uri: remote debugger uri

void attachDebug(int pid)
void stopDebug()
void suspendDebug()
void syncAndSeekProgramCounter()
void continueDebug()
void continueUntilCall()
void continueUntilSyscall()
void continueUntilDebug(QString offset)
void stepDebug()
void stepOverDebug()
void stepOutDebug()
void addBreakpoint(const BreakpointDescription &config)
void updateBreakpoint(int index, const BreakpointDescription &config)
void toggleBreakpoint(RVA addr)
void delBreakpoint(RVA addr)
void delAllBreakpoints()
void enableBreakpoint(RVA addr)
void disableBreakpoint(RVA addr)
void setBreakpointTrace(int index, bool enabled)

Enable or disable breakpoint tracing.

Parameters
  • index: - breakpoint index to modify

  • enabled: - true if tracing should be enabled

int breakpointIndexAt(RVA addr)
BreakpointDescription getBreakpointAt(RVA addr)
bool isBreakpoint(const QList<RVA> &breakpoints, RVA addr)
QList<RVA> getBreakpointsAddresses()
QList<RVA> getBreakpointsInFunction(RVA funcAddr)

Get all breakpoinst that are belong to a functions at this address.

QString getActiveDebugPlugin()
QStringList getDebugPlugins()
void setDebugPlugin(QString plugin)
bool isDebugTaskInProgress()
bool isRedirectableDebugee()

Check if we can use output/input redirection with the currently debugged process.

QList<Decompiler*> getDecompilers()
Decompiler *getDecompilerById(const QString &id)
bool registerDecompiler(Decompiler *decompiler)

Register a new decompiler

The decompiler must have a unique id, otherwise this method will fail. The decompiler’s parent will be set to this CutterCore instance, so it will automatically be freed later.

Return

whether the decompiler was registered successfully

RVA getOffsetJump(RVA addr)
QJsonDocument getFileInfo()
QJsonDocument getSignatureInfo()
QJsonDocument getFileVersionInfo()
QStringList getStats()
void setGraphEmpty(bool empty)
bool isGraphEmpty()
void getOpcodes()
void setSettings()
void loadPDB(const QString &file)
QByteArray ioRead(RVA addr, int len)
QList<RVA> getSeekHistory()
QStringList getAsmPluginNames()
QStringList getAnalPluginNames()
QStringList getProjectNames()
void openProject(const QString &name)
void saveProject(const QString &name)
void deleteProject(const QString &name)
QList<RBinPluginDescription> getRBinPluginDescriptions(const QString &type = QString())
QList<RIOPluginDescription> getRIOPluginDescriptions()
QList<RCorePluginDescription> getRCorePluginDescriptions()
QList<RAsmPluginDescription> getRAsmPluginDescriptions()
QList<FunctionDescription> getAllFunctions()
QList<ImportDescription> getAllImports()
QList<ExportDescription> getAllExports()
QList<SymbolDescription> getAllSymbols()
QList<HeaderDescription> getAllHeaders()
QList<ZignatureDescription> getAllZignatures()
QList<CommentDescription> getAllComments(const QString &filterType)
QList<RelocDescription> getAllRelocs()
QList<StringDescription> getAllStrings()
QList<FlagspaceDescription> getAllFlagspaces()
QList<FlagDescription> getAllFlags(QString flagspace = QString())
QList<SectionDescription> getAllSections()
QList<SegmentDescription> getAllSegments()
QList<EntrypointDescription> getAllEntrypoint()
QList<BinClassDescription> getAllClassesFromBin()
QList<BinClassDescription> getAllClassesFromFlags()
QList<ResourcesDescription> getAllResources()
QList<VTableDescription> getAllVTables()
QList<TypeDescription> getAllTypes()

Return

all loaded types

QList<TypeDescription> getAllPrimitiveTypes()

Return

all loaded primitive types

QList<TypeDescription> getAllUnions()

Return

all loaded unions

QList<TypeDescription> getAllStructs()

Return

all loaded structs

QList<TypeDescription> getAllEnums()

Return

all loaded enums

QList<TypeDescription> getAllTypedefs()

Return

all loaded typedefs

QString getTypeAsC(QString name, QString category)

Fetching the C representation of a given Type.

Return

The type decleration as C output

Parameters
  • name: - the name or the type of the given Type / Struct

  • category: - the category of the given Type (Struct, Union, Enum, …)

QString addTypes(const char *str)

Adds new types It first uses the r_parse_c_string() function from radare2 API to parse the supplied C file (in the form of a string). If there were errors, they are displayed. If there were no errors, it uses sdb_query_lines() function from radare2 API to save the parsed types returned by r_parse_c_string()

Return

returns an empty QString if there was no error, else returns the error

Parameters
  • str: Contains the definition of the data types

QString addTypes(const QString &str)
bool isAddressMapped(RVA addr)

Checks if the given address is mapped to a region.

Return

true if addr is mapped, false otherwise

Parameters
  • addr: The address to be checked

QList<MemoryMapDescription> getMemoryMap()
QList<SearchDescription> getAllSearch(QString search_for, QString space)
BlockStatistics getBlockStatistics(unsigned int blocksCount)
QList<BreakpointDescription> getBreakpoints()
QList<ProcessDescription> getAllProcesses()
QList<QJsonObject> getRegisterRefs(int depth = 6)

returns a list of reg values and their telescoped references

Parameters
  • depth: telescoping depth

QVector<RegisterRefValueDescription> getRegisterRefValues()
QList<VariableDescription> getVariables(RVA at)
QList<XrefDescription> getXRefsForVariable(QString variableName, bool findWrites, RVA offset)

Fetches all the writes or reads to the specified local variable ‘variableName’ in the function in which the specified offset is a part of.

Return

A list of XrefDescriptions that contains details of all the writes or reads that happen to the variable ‘variableName’.

Parameters
  • variableName: Name of the local variable.

  • findWrites: If this is true, then locations at which modification happen to the specified local variable is fetched. Else, the locations at which the local is variable is read is fetched.

  • offset: An offset in the function in which the specified local variable exist.

QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function, const QString &filterType = QString())
QList<StringDescription> parseStringsJson(const QJsonDocument &doc)
void handleREvent(int type, void *data)
void triggerVarsChanged()
void triggerFunctionRenamed(const RVA offset, const QString &newName)
void triggerRefreshAll()
void triggerAsmOptionsChanged()
void triggerGraphOptionsChanged()
void message(const QString &msg, bool debug = false)
QStringList getSectionList()
RCoreLocked core()
BasicBlockHighlighter *getBBHighlighter()
BasicInstructionHighlighter *getBIHighlighter()
void setIOCache(bool enabled)

Enable or dsiable Cache mode. Cache mode is used to imagine writing to the opened file without committing the changes to the disk.

Parameters
  • enabled:

bool isIOCacheEnabled() const

Check if Cache mode is enabled.

Return

true if Cache is enabled, otherwise return false.

void commitWriteCache()

Commit write cache to the file on disk.

void setWriteMode(bool enabled)

Enable or disable Write mode. When the file is opened in write mode, any changes to it will be immediately committed to the file on disk, thus modify the file. This function wrap radare2 function which re-open the file with the desired permissions.

Parameters
  • enabled:

bool isWriteModeEnabled()

Check if the file is opened in write mode.

Return

true if write mode is enabled, otherwise return false.

Public Members

bool currentlyDebugging = false
bool currentlyEmulating = false
int currentlyAttachedToPID = -1
QString currentlyOpenFile
QList<QString> opcodes
QList<QString> regs

Signals

void refreshAll()
void functionRenamed(const RVA offset, const QString &new_name)
void varsChanged()
void functionsChanged()
void flagsChanged()
void commentsChanged(RVA addr)
void registersChanged()
void instructionChanged(RVA offset)
void breakpointsChanged(RVA offset)
void refreshCodeViews()
void stackChanged()
void codeRebased()

update all the widgets that are affected by rebasing in debug mode

void switchedThread()
void switchedProcess()
void classNew(const QString &cls)
void classDeleted(const QString &cls)
void classRenamed(const QString &oldName, const QString &newName)
void classAttrsChanged(const QString &cls)
void debugProcessFinished(int pid)

end of current debug event received

void attachedRemote(bool successfully)
void projectSaved(bool successfully, const QString &name)
void ioCacheChanged(bool newval)
void writeModeChanged(bool newval)
void ioModeChanged()
void debugTaskStateChanged()

emitted when debugTask started or finished running

void asmOptionsChanged()

emitted when config regarding disassembly display changes

void graphOptionsChanged()

emitted when config regarding graph display changes

void seekChanged(RVA offset)

seekChanged is emitted each time radare2 seek value is modified

Parameters
  • offset:

void toggleDebugView()
void newMessage(const QString &msg)
void newDebugMessage(const QString &msg)
void showMemoryWidgetRequested()

Public Static Functions

CutterCore *instance()
QString sanitizeStringForCommand(QString s)
QByteArray hexStringToBytes(const QString &hex)
QString bytesToHexString(const QByteArray &bytes)
bool isProjectNameValid(const QString &name)
QString ansiEscapeToHtml(const QString &text)