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

View File

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

View File

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