Use open API instead of commands (#2757)

This commit is contained in:
Anton Kochkov 2021-09-15 05:40:01 +08:00 committed by GitHub
parent 8fd35f2109
commit 57f34bfb98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 26 deletions

View File

@ -19,8 +19,9 @@ void AnalTask::interrupt()
QString AnalTask::getTitle() QString AnalTask::getTitle()
{ {
// If no file is loaded we consider it's Initial Analysis // If no file is loaded we consider it's Initial Analysis
QJsonArray openedFiles = Core()->getOpenedFiles(); RzCoreLocked core(Core());
if (!openedFiles.size()) { RzList *descs = rz_id_storage_list(core->io->files);
if (rz_list_empty(descs)) {
return tr("Initial Analysis"); return tr("Initial Analysis");
} }
return tr("Analyzing Program"); return tr("Analyzing Program");
@ -38,8 +39,9 @@ void AnalTask::runTask()
Core()->setConfig("bin.demangle", options.demangle); Core()->setConfig("bin.demangle", options.demangle);
// Do not reload the file if already loaded // Do not reload the file if already loaded
QJsonArray openedFiles = Core()->getOpenedFiles(); RzCoreLocked core(Core());
if (!openedFiles.size() && options.filename.length()) { RzList *descs = rz_id_storage_list(core->io->files);
if (rz_list_empty(descs) && options.filename.length()) {
log(tr("Loading the file...")); log(tr("Loading the file..."));
openFailed = false; openFailed = false;
bool fileLoaded = bool fileLoaded =

View File

@ -386,11 +386,12 @@ bool CutterCore::isRedirectableDebugee()
} }
// We are only able to redirect locally debugged unix processes // We are only able to redirect locally debugged unix processes
QJsonArray openFilesArray = cmdj("oj").array(); RzCoreLocked core(Core());
; RzList *descs = rz_id_storage_list(core->io->files);
for (QJsonValue value : openFilesArray) { RzListIter *it;
QJsonObject openFile = value.toObject(); RzIODesc *desc;
QString URI = openFile["uri"].toString(); CutterRzListForeach(descs, it, RzIODesc, desc) {
QString URI = QString(desc->uri);
if (URI.contains("ptrace") | URI.contains("mach")) { if (URI.contains("ptrace") | URI.contains("mach")) {
return true; return true;
} }
@ -1913,10 +1914,12 @@ void CutterCore::attachRemote(const QString &uri)
debugTask.clear(); debugTask.clear();
// Check if we actually connected // Check if we actually connected
bool connected = false; bool connected = false;
QJsonArray openFilesArray = getOpenedFiles(); RzCoreLocked core(Core());
for (QJsonValue value : openFilesArray) { RzList *descs = rz_id_storage_list(core->io->files);
QJsonObject openFile = value.toObject(); RzListIter *it;
QString fileUri = openFile["uri"].toString(); RzIODesc *desc;
CutterRzListForeach(descs, it, RzIODesc, desc) {
QString fileUri = QString(desc->uri);
if (!fileUri.compare(uri)) { if (!fileUri.compare(uri)) {
connected = true; connected = true;
} }
@ -2023,13 +2026,14 @@ void CutterCore::stopDebug()
} else { } else {
QString ptraceFiles = ""; QString ptraceFiles = "";
// close ptrace file descriptors left open // close ptrace file descriptors left open
QJsonArray openFilesArray = cmdj("oj").array(); RzCoreLocked core(Core());
; RzList *descs = rz_id_storage_list(core->io->files);
for (QJsonValue value : openFilesArray) { RzListIter *it;
QJsonObject openFile = value.toObject(); RzIODesc *desc;
QString URI = openFile["uri"].toString(); CutterRzListForeach(descs, it, RzIODesc, desc) {
QString URI = QString(desc->uri);
if (URI.contains("ptrace")) { if (URI.contains("ptrace")) {
ptraceFiles += "o-" + QString::number(openFile["fd"].toInt()) + ";"; ptraceFiles += "o-" + QString::number(desc->fd) + ";";
} }
} }
// Use cmd because cmdRaw would not work with command concatenation // Use cmd because cmdRaw would not work with command concatenation
@ -4025,12 +4029,6 @@ QString CutterCore::getVersionInformation()
return versionInfo; return versionInfo;
} }
QJsonArray CutterCore::getOpenedFiles()
{
QJsonDocument files = cmdj("oj");
return files.array();
}
QList<QString> CutterCore::getColorThemes() QList<QString> CutterCore::getColorThemes()
{ {
QList<QString> r; QList<QString> r;

View File

@ -278,7 +278,6 @@ public:
bool tryFile(QString path, bool rw); bool tryFile(QString path, bool rw);
bool mapFile(QString path, RVA mapaddr); bool mapFile(QString path, RVA mapaddr);
void loadScript(const QString &scriptname); void loadScript(const QString &scriptname);
QJsonArray getOpenedFiles();
/* Seek functions */ /* Seek functions */
void seek(QString thing); void seek(QString thing);