Convert pdsf to API (#3010)

* convert `pdsf`
* remove unused
- `CutterCore.opcodes`
- `cmdList`
This commit is contained in:
billow 2022-08-11 20:46:18 +08:00 committed by GitHub
parent 6b7b1d1450
commit 617c79f976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 25 deletions

View File

@ -9,15 +9,6 @@ Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent)
core = Core();
keywordFormat.setForeground(QColor(65, 131, 215));
for (const QString &pattern : this->core->opcodes) {
rule.pattern.setPattern("\\b" + pattern + "\\b");
rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
rule.format = keywordFormat;
highlightingRules.append(rule);
}
regFormat.setForeground(QColor(236, 100, 75));
for (const QString &pattern : this->core->regs) {

View File

@ -2944,11 +2944,9 @@ bool CutterCore::isGraphEmpty()
return emptyGraph;
}
void CutterCore::getOpcodes()
void CutterCore::getRegs()
{
CORE_LOCK();
this->opcodes = cmdList("?O");
this->regs = {};
const RzList *rs = rz_reg_get_list(getReg(), RZ_REG_TYPE_ANY);
if (!rs) {

View File

@ -188,11 +188,6 @@ public:
CutterJson cmdj(const char *str);
CutterJson cmdj(const QString &str) { return cmdj(str.toUtf8().constData()); }
CutterJson cmdjAt(const char *str, RVA address);
QStringList cmdList(const char *str)
{
return cmd(str).split(QLatin1Char('\n'), CUTTER_QT_SKIP_EMPTY_PARTS);
}
QStringList cmdList(const QString &str) { return cmdList(str.toUtf8().constData()); }
QString cmdTask(const QString &str);
CutterJson cmdjTask(const QString &str);
/**
@ -595,8 +590,7 @@ public:
void setGraphEmpty(bool empty);
bool isGraphEmpty();
void getOpcodes();
QList<QString> opcodes;
void getRegs();
QList<QString> regs;
void setSettings();

View File

@ -637,7 +637,7 @@ bool MainWindow::openProject(const QString &file)
void MainWindow::finalizeOpen()
{
core->getOpcodes();
core->getRegs();
core->updateSeek();
refreshAll();
// Add fortune message
@ -1762,10 +1762,16 @@ void MainWindow::on_actionExport_as_code_triggered()
QTextStream fileOut(&file);
auto ps = core->seekTemp(0);
auto rc = core->core();
const auto size = static_cast<int>(rz_io_fd_size(rc->io, rc->file->fd));
auto buffer = std::vector<ut8>(size);
if (!rz_io_read_at(Core()->core()->io, 0, buffer.data(), size)) {
return;
}
std::unique_ptr<char, decltype(free) *> string {
dialog.selectedNameFilter() != instructionsInComments
? rz_lang_byte_array(rc->block, rc->blocksize, typMap[dialog.selectedNameFilter()])
: rz_core_print_bytes_with_inst(rc, rc->block, rc->offset, rc->blocksize),
? rz_lang_byte_array(buffer.data(), size, typMap[dialog.selectedNameFilter()])
: rz_core_print_bytes_with_inst(rc, buffer.data(), 0, size),
free
};
fileOut << string.get();

View File

@ -231,7 +231,17 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
QStringList disasmPreview =
Core()->getDisassemblyPreview(function.offset, kMaxTooltipDisasmPreviewLines);
const QStringList &summary = Core()->cmdList(QString("pdsf @ %1").arg(function.offset));
QStringList summary {};
{
auto seeker = Core()->seekTemp(function.offset);
auto strings = std::unique_ptr<char, decltype(free) *> {
rz_core_print_disasm_strings(Core()->core(), RZ_CORE_DISASM_STRINGS_MODE_FUNCTION,
0, NULL),
free
};
summary = QString(strings.get()).split('\n', CUTTER_QT_SKIP_EMPTY_PARTS);
}
const QFont &fnt = Config()->getFont();
QFontMetrics fm { fnt };
@ -245,7 +255,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
}
}
if (disasmPreview.isEmpty() && highlights.isEmpty())
return QVariant();
return {};
QString toolTipContent =
QString("<html><div style=\"font-family: %1; font-size: %2pt; white-space: "
@ -287,7 +297,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return importAddresses->contains(function.offset);
default:
return QVariant();
return {};
}
}