mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-24 22:05:25 +00:00
Update radare2 and adapt Cutter (#1406)
* Update radare2 and adapt Cutter * Fix QByteArray creation in CutterCore::assemble()
This commit is contained in:
parent
c50b19df90
commit
41af189312
2
radare2
2
radare2
@ -1 +1 @@
|
|||||||
Subproject commit 82d1e96b7af0f56d7168179946c51fe93f5d4fe4
|
Subproject commit 399bba4152e47e15126a69a21c8163f610bd932f
|
@ -773,20 +773,26 @@ void CutterCore::setBBSize(int size)
|
|||||||
setConfig("anal.bb.maxsize", size);
|
setConfig("anal.bb.maxsize", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CutterCore::assemble(const QString &code)
|
QByteArray CutterCore::assemble(const QString &code)
|
||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
RAsmCode *ac = r_asm_massemble(core_->assembler, code.toUtf8().constData());
|
RAsmCode *ac = r_asm_massemble(core_->assembler, code.toUtf8().constData());
|
||||||
QString hex(ac != nullptr ? ac->buf_hex : "");
|
QByteArray res;
|
||||||
|
if (ac && ac->bytes) {
|
||||||
|
res = QByteArray(reinterpret_cast<const char *>(ac->bytes), ac->len);
|
||||||
|
}
|
||||||
r_asm_code_free(ac);
|
r_asm_code_free(ac);
|
||||||
return hex;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CutterCore::disassemble(const QString &hex)
|
QString CutterCore::disassemble(const QByteArray &data)
|
||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
RAsmCode *ac = r_asm_mdisassemble_hexstr(core_->assembler, NULL, hex.toUtf8().constData());
|
RAsmCode *ac = r_asm_mdisassemble(core_->assembler, reinterpret_cast<const ut8 *>(data.constData()), data.length());
|
||||||
QString code = QString(ac != nullptr ? ac->buf_asm : "");
|
QString code;
|
||||||
|
if (ac && ac->assembly) {
|
||||||
|
code = QString::fromUtf8(ac->assembly);
|
||||||
|
}
|
||||||
r_asm_code_free(ac);
|
r_asm_code_free(ac);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
@ -2570,6 +2576,24 @@ QList<DisassemblyLine> CutterCore::disassembleLines(RVA offset, int lines)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray CutterCore::hexStringToBytes(const QString &hex)
|
||||||
|
{
|
||||||
|
QByteArray hexChars = hex.toUtf8();
|
||||||
|
QByteArray bytes;
|
||||||
|
bytes.reserve(hexChars.length() / 2);
|
||||||
|
int size = r_hex_str2bin(hexChars.constData(), reinterpret_cast<ut8 *>(bytes.data()));
|
||||||
|
bytes.resize(size);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CutterCore::bytesToHexString(const QByteArray &bytes)
|
||||||
|
{
|
||||||
|
QByteArray hex;
|
||||||
|
hex.resize(bytes.length() * 2);
|
||||||
|
r_hex_bin2str(reinterpret_cast<const ut8 *>(bytes.constData()), bytes.size(), hex.data());
|
||||||
|
return QString::fromUtf8(hex);
|
||||||
|
}
|
||||||
|
|
||||||
void CutterCore::loadScript(const QString &scriptname)
|
void CutterCore::loadScript(const QString &scriptname)
|
||||||
{
|
{
|
||||||
r_core_task_sync_begin(core_);
|
r_core_task_sync_begin(core_);
|
||||||
|
@ -185,10 +185,14 @@ public:
|
|||||||
QList<QString> getColorThemes();
|
QList<QString> getColorThemes();
|
||||||
|
|
||||||
/* Assembly related methods */
|
/* Assembly related methods */
|
||||||
QString assemble(const QString &code);
|
QByteArray assemble(const QString &code);
|
||||||
QString disassemble(const QString &hex);
|
QString disassemble(const QByteArray &data);
|
||||||
QString disassembleSingleInstruction(RVA addr);
|
QString disassembleSingleInstruction(RVA addr);
|
||||||
QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
|
QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
|
||||||
|
|
||||||
|
static QByteArray hexStringToBytes(const QString &hex);
|
||||||
|
static QString bytesToHexString(const QByteArray &bytes);
|
||||||
|
|
||||||
void setCPU(QString arch, QString cpu, int bits);
|
void setCPU(QString arch, QString cpu, int bits);
|
||||||
void setEndianness(bool big);
|
void setEndianness(bool big);
|
||||||
void setBBSize(int size);
|
void setBBSize(int size);
|
||||||
|
@ -45,9 +45,11 @@ void EditInstructionDialog::updatePreview(const QString &input)
|
|||||||
ui->instructionLabel->setText("");
|
ui->instructionLabel->setText("");
|
||||||
return;
|
return;
|
||||||
} else if (editMode == EDIT_BYTES) {
|
} else if (editMode == EDIT_BYTES) {
|
||||||
result = Core()->disassemble(input).trimmed();
|
QByteArray data = CutterCore::hexStringToBytes(input);
|
||||||
|
result = Core()->disassemble(data).trimmed();
|
||||||
} else if (editMode == EDIT_TEXT) {
|
} else if (editMode == EDIT_TEXT) {
|
||||||
result = Core()->assemble(input).trimmed();
|
QByteArray data = Core()->assemble(input);
|
||||||
|
result = CutterCore::bytesToHexString(data).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.isEmpty() || result.contains(QLatin1Char('\n'))) {
|
if (result.isEmpty() || result.contains(QLatin1Char('\n'))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user