Skip to content

Commit 6bcadd4

Browse files
committed
Strip file:// to workaround a bug from r2-6.0.2
1 parent f5913b3 commit 6bcadd4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/core/Iaito.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <cassert>
1313
#include <memory>
14+
#include <cstring>
1415

1516
#include "Decompiler.h"
1617
#include "common/AsyncTask.h"
@@ -43,6 +44,20 @@ Q_GLOBAL_STATIC(IaitoCore, uniqueInstance)
4344
#define R_JSON_KEY(name) static const QString name = QStringLiteral(#name)
4445
#define CORE_LOCK() RCoreLocked core(this)
4546

47+
// Workaround for r2-6.0.2 bug: wrap r_core_file_open and
48+
// trim a leading "file://" URI prefix from the path argument.
49+
static RIODesc *core_file_open_strip_file_uri(RCore *core, const char *path, int perms, ut64 mapaddr) {
50+
if (!path) {
51+
return r_core_file_open(core, path, perms, mapaddr);
52+
}
53+
// If the path starts with the URI scheme "file://", skip it.
54+
// Example: "file:///tmp/a" -> "/tmp/a"
55+
if (!strncmp(path, "file://", 7)) {
56+
return r_core_file_open(core, path + 7, perms, mapaddr);
57+
}
58+
return r_core_file_open(core, path, perms, mapaddr);
59+
}
60+
4661
namespace RJsonKey {
4762
R_JSON_KEY(addr);
4863
R_JSON_KEY(addrs);
@@ -712,7 +727,7 @@ bool IaitoCore::loadFile(
712727
r_config_set_b(core->config, "bin.cache", bincache);
713728

714729
Core()->loadIaitoRC(0);
715-
RIODesc *f = r_core_file_open(core, path.toUtf8().constData(), perms, mapaddr);
730+
RIODesc *f = core_file_open_strip_file_uri(core, path.toUtf8().constData(), perms, mapaddr);
716731
if (!f) {
717732
R_LOG_ERROR("r_core_file_open failed");
718733
return false;
@@ -729,12 +744,12 @@ bool IaitoCore::loadFile(
729744
}
730745

731746
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
732-
if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | (rw ? R_IO_WRITE : 0, mapaddr))) {
747+
if (!core_file_open_strip_file_uri(core, path.toUtf8().constData(), R_IO_READ | (rw ? R_IO_WRITE : 0), mapaddr)) {
733748
R_LOG_ERROR("Cannot open file");
734749
} else {
735750
// load RBin information
736751
// XXX only for sub-bins
737-
r_core_bin_load(core, path.toUtf8(), baddr);
752+
r_core_bin_load(core, path.toUtf8().constData(), baddr);
738753
r_bin_select_idx(core->bin, NULL, idx);
739754
}
740755
#endif
@@ -779,7 +794,7 @@ bool IaitoCore::tryFile(QString path, bool rw)
779794
}
780795
CORE_LOCK();
781796
int flags = rw ? R_PERM_RW : R_PERM_R;
782-
RIODesc *cf = r_core_file_open(core, path.toUtf8().constData(), flags, 0LL);
797+
RIODesc *cf = core_file_open_strip_file_uri(core, path.toUtf8().constData(), flags, 0LL);
783798
if (!cf) {
784799
return false;
785800
}
@@ -800,7 +815,7 @@ bool IaitoCore::mapFile(QString path, RVA mapaddr)
800815
CORE_LOCK();
801816
RVA addr = mapaddr != RVA_INVALID ? mapaddr : 0;
802817
ut64 baddr = Core()->getFileInfo().object()["bin"].toObject()["baddr"].toVariant().toULongLong();
803-
if (r_core_file_open(core, path.toUtf8().constData(), R_PERM_RX, addr)) {
818+
if (core_file_open_strip_file_uri(core, path.toUtf8().constData(), R_PERM_RX, addr)) {
804819
r_core_bin_load(core, path.toUtf8().constData(), baddr);
805820
} else {
806821
return false;

0 commit comments

Comments
 (0)