Update radare2 and fix Cutter for it (#2017)

This commit is contained in:
Florian Märkl 2020-01-15 20:19:24 +01:00 committed by GitHub
parent c5c9d5201b
commit a9ed742cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 49 deletions

@ -1 +1 @@
Subproject commit 2461780fcd8140eb9fba6611ec54e468f82609dd
Subproject commit 14215350af35cc8b14710557c248d2e77baf380d

View File

@ -996,13 +996,21 @@ QString CutterCore::disassembleSingleInstruction(RVA addr)
return cmd("pi 1@" + QString::number(addr)).simplified();
}
RAnalFunction *CutterCore::functionIn(ut64 addr)
{
CORE_LOCK();
RList *fcns = r_anal_get_functions_in (core->anal, addr);
RAnalFunction *fcn = !r_list_empty(fcns) ? reinterpret_cast<RAnalFunction *>(r_list_first(fcns)) : nullptr;
r_list_free(fcns);
return fcn;
}
RAnalFunction *CutterCore::functionAt(ut64 addr)
{
CORE_LOCK();
return r_anal_get_fcn_in(core->anal, addr, 0);
return r_anal_get_function_at(core->anal, addr);
}
/**
* @brief finds the start address of a function in a given address
* @param addr - an address which belongs to a function
@ -1011,7 +1019,7 @@ RAnalFunction *CutterCore::functionAt(ut64 addr)
RVA CutterCore::getFunctionStart(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
RAnalFunction *fcn = Core()->functionIn(addr);
return fcn ? fcn->addr : RVA_INVALID;
}
@ -1023,7 +1031,7 @@ RVA CutterCore::getFunctionStart(RVA addr)
RVA CutterCore::getFunctionEnd(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
RAnalFunction *fcn = Core()->functionIn(addr);
return fcn ? fcn->addr : RVA_INVALID;
}
@ -1035,7 +1043,7 @@ RVA CutterCore::getFunctionEnd(RVA addr)
RVA CutterCore::getLastFunctionInstruction(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
RAnalFunction *fcn = Core()->functionIn(addr);
if (!fcn) {
return RVA_INVALID;
}
@ -2343,7 +2351,7 @@ QList<FunctionDescription> CutterCore::getAllFunctions()
CutterRListForeach (core->anal->fcns, iter, RAnalFunction, fcn) {
FunctionDescription function;
function.offset = fcn->addr;
function.size = r_anal_fcn_size(fcn);
function.linearSize = r_anal_function_linear_size(fcn);
function.nargs = r_anal_var_count(core->anal, fcn, 'b', 1) +
r_anal_var_count(core->anal, fcn, 'r', 1) +
r_anal_var_count(core->anal, fcn, 's', 1);

View File

@ -111,7 +111,19 @@ public:
void renameFunction(const QString &oldName, const QString &newName);
void delFunction(RVA addr);
void renameFlag(QString old_name, QString new_name);
/**
* @param addr
* @return a function that contains addr or nullptr
*/
RAnalFunction *functionIn(ut64 addr);
/**
* @param addr
* @return the function that has its entrypoint at addr or nullptr
*/
RAnalFunction *functionAt(ut64 addr);
RVA getFunctionStart(RVA addr);
RVA getFunctionEnd(RVA addr);
RVA getLastFunctionInstruction(RVA addr);

View File

@ -13,7 +13,7 @@
struct FunctionDescription {
RVA offset;
RVA size;
RVA linearSize;
RVA nargs;
RVA nbbs;
RVA nlocals;
@ -24,7 +24,9 @@ struct FunctionDescription {
bool contains(RVA addr) const
{
return addr >= offset && addr < offset + size;
// TODO: this is not exactly correct in edge cases.
// r_anal_function_contains() does it right.
return addr >= offset && addr < offset + linearSize;
}
};

View File

@ -33,17 +33,6 @@ void EditFunctionDialog::setStartAddrText(const QString &startAddr)
ui->startLineEdit->setText(startAddr);
}
QString EditFunctionDialog::getEndAddrText()
{
QString ret = ui->endLineEdit->text();
return ret;
}
void EditFunctionDialog::setEndAddrText(const QString &endAddr)
{
ui->endLineEdit->setText(endAddr);
}
QString EditFunctionDialog::getStackSizeText()
{
QString ret = ui->stackSizeLineEdit->text();

View File

@ -58,33 +58,23 @@
<widget class="QLineEdit" name="startLineEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="endLabel">
<property name="text">
<string>End address</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="endLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="stackSizeLabel">
<property name="text">
<string>Stack size</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="stackSizeLineEdit"/>
</item>
<item row="7" column="0">
<item row="6" column="0">
<widget class="QLabel" name="callConLabel">
<property name="text">
<string>Calling convention</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="callConComboBox"/>
</item>
</layout>

View File

@ -450,8 +450,8 @@ void DisassemblyContextMenu::aboutToShowSlot()
RCore *core = Core()->core();
RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL);
RAnalFunction *in_fcn = Core()->functionAt(offset);
RAnalFunction *fcn = Core()->functionAt(offset);
RAnalFunction *in_fcn = Core()->functionIn(offset);
RFlagItem *f = r_flag_get_i (core->flags, offset);
actionDeleteFlag.setVisible(f ? true : false);
@ -789,7 +789,7 @@ void DisassemblyContextMenu::on_actionRename_triggered()
RenameDialog dialog(mainWindow);
RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL);
RAnalFunction *fcn = Core()->functionIn (offset);
RFlagItem *f = r_flag_get_i (core->flags, offset);
if (fcn) {
/* Rename function */
@ -855,7 +855,7 @@ void DisassemblyContextMenu::on_actionRenameUsedHere_triggered()
void DisassemblyContextMenu::on_actionSetFunctionVarTypes_triggered()
{
RAnalFunction *fcn = Core()->functionAt(offset);
RAnalFunction *fcn = Core()->functionIn(offset);
if (!fcn) {
QMessageBox::critical(this, tr("Re-type function local vars"),
@ -1001,9 +1001,6 @@ void DisassemblyContextMenu::on_actionEditFunction_triggered()
QString startAddrText = "0x" + QString::number(fcn->addr, 16);
dialog.setStartAddrText(startAddrText);
QString endAddrText = "0x" + QString::number(fcn->addr + fcn->_size, 16);
dialog.setEndAddrText(endAddrText);
QString stackSizeText;
stackSizeText.sprintf("%d", fcn->stack);
dialog.setStackSizeText(stackSizeText);
@ -1019,8 +1016,6 @@ void DisassemblyContextMenu::on_actionEditFunction_triggered()
Core()->renameFunction(fcn->name, new_name);
QString new_start_addr = dialog.getStartAddrText();
fcn->addr = Core()->math(new_start_addr);
QString new_end_addr = dialog.getEndAddrText();
Core()->cmd("afu " + new_end_addr);
QString new_stack_size = dialog.getStackSizeText();
fcn->stack = int(Core()->math(new_stack_size));
Core()->cmd("afc " + dialog.getCallConSelected());

View File

@ -226,7 +226,7 @@ void DisassemblerGraphView::loadCurrentGraph()
.set("asm.lines.fcn", false);
QJsonArray functions;
RAnalFunction *fcn = Core()->functionAt(seekable->getOffset());
RAnalFunction *fcn = Core()->functionIn(seekable->getOffset());
if (fcn) {
currentFcnAddr = fcn->addr;
QJsonDocument functionsDoc = Core()->cmdj("agJ " + RAddressString(fcn->addr));
@ -1091,7 +1091,7 @@ void DisassemblerGraphView::on_actionExportGraph_triggered()
}
QString defaultName = "graph";
if (auto f = Core()->functionAt(currentFcnAddr)) {
if (auto f = Core()->functionIn(currentFcnAddr)) {
QString functionName = f->name;
// don't confuse image type guessing and make c++ names somewhat usable
functionName.replace(QRegularExpression("[.:]"), "_");

View File

@ -122,7 +122,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
case 0:
return tr("Offset: %1").arg(RAddressString(function.offset));
case 1:
return tr("Size: %1").arg(RSizeString(function.size));
return tr("Size: %1").arg(RSizeString(function.linearSize));
case 2:
return tr("Import: %1").arg(functionIsImport(function.offset) ? tr("true") : tr("false"));
case 3:
@ -147,7 +147,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
case NameColumn:
return function.name;
case SizeColumn:
return QString::number(function.size);
return QString::number(function.linearSize);
case OffsetColumn:
return RAddressString(function.offset);
case NargsColumn:
@ -383,8 +383,8 @@ bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QMode
case FunctionModel::OffsetColumn:
return left_function.offset < right_function.offset;
case FunctionModel::SizeColumn:
if (left_function.size != right_function.size)
return left_function.size < right_function.size;
if (left_function.linearSize != right_function.linearSize)
return left_function.linearSize < right_function.linearSize;
break;
case FunctionModel::ImportColumn: {
bool left_is_import = left.data(FunctionModel::IsImportRole).toBool();

View File

@ -134,7 +134,7 @@ public:
}
m_blocks.clear();
uint64_t addr = alignedAddr;
for (int i = 0; i < len / blockSize; ++i, addr += blockSize) {
for (ut64 i = 0; i < len / blockSize; ++i, addr += blockSize) {
m_blocks.append(Core()->ioRead(addr, blockSize));
}
}