Fix and optimize support for blockdevice ##io

This commit is contained in:
pancake
2025-11-23 11:15:31 +01:00
committed by GitHub
parent d8b96050fc
commit 5f7a2a90c2
2 changed files with 36 additions and 14 deletions

View File

@@ -714,7 +714,6 @@ static RList *patch_relocs(RBinFile *bf) {
size_t symbol_size = 0;
size_t numaux_offset = 0;
if ((bin->type == COFF_TYPE_BIGOBJ && bin->bigobj_symbols) || bin->symbols) {
if (bin->type == COFF_TYPE_BIGOBJ) {
symbols = bin->bigobj_symbols;
f_nsyms = bin->bigobj_hdr.f_nsyms;
@@ -724,13 +723,14 @@ static RList *patch_relocs(RBinFile *bf) {
f_nsyms = bin->hdr.f_nsyms;
symbol_size = sizeof (struct coff_symbol);
}
for (i = 0; i < f_nsyms; i++) {
if (is_imported_symbol (bin, i)) {
nimports++;
if (symbols) {
for (i = 0; i < f_nsyms; i++) {
if (is_imported_symbol (bin, i)) {
nimports++;
}
ut8 n_numaux = *((ut8 *)symbols + i * symbol_size + numaux_offset);
i += n_numaux;
}
ut8 n_numaux = *((ut8 *)symbols + i * symbol_size + numaux_offset);
i += n_numaux;
}
}
ut64 m_vaddr = UT64_MAX;

View File

@@ -8,6 +8,7 @@ typedef struct r_io_mmo_t {
int mode;
int perm;
int fd;
int isblk;
ut64 addr;
bool rawio;
bool nocache;
@@ -15,6 +16,22 @@ typedef struct r_io_mmo_t {
RIO *io_backref;
} RIOMMapFileObj;
static bool check_for_blockdevice(RIOMMapFileObj *mmo) {
#if R2__UNIX__
R_RETURN_VAL_IF_FAIL (mmo, false);
if (mmo->isblk == -1) {
struct stat buf;
if (fstat (mmo->fd, &buf) == -1) {
mmo->isblk = 0;
} else {
mmo->isblk = ((buf.st_mode & S_IFBLK) == S_IFBLK)? 1: 0;
}
}
return mmo->isblk == 1;
#endif
return false;
}
static int open_file(const char *file, int perm, int mode) {
int fd;
if (r_str_startswith (file, "file://")) {
@@ -53,6 +70,14 @@ static int open_file(const char *file, int perm, int mode) {
static ut64 mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int whence) {
if (mmo->rawio) {
if (whence == 2) {
if (mmo->isblk == -1) {
check_for_blockdevice (mmo);
}
if (mmo->isblk) {
return UT64_MAX - 1;
}
}
mmo->addr = lseek (mmo->fd, offset, whence);
} else if (mmo->buf) {
mmo->addr = r_buf_seek (mmo->buf, offset, whence);
@@ -82,6 +107,7 @@ static bool mmap_refresh(RIOMMapFileObj *mmo) {
if (mmo->fd != -1 && cur) {
mmap_seek (io, mmo, cur, SEEK_SET);
}
check_for_blockdevice (mmo);
goto done;
}
if (mmo->fd == -1) {
@@ -89,6 +115,7 @@ static bool mmap_refresh(RIOMMapFileObj *mmo) {
if (mmo->fd == -1) {
return false;
}
check_for_blockdevice (mmo);
}
mmo->buf = r_buf_new_mmap (mmo->filename, mmo->perm);
if (mmo->buf) {
@@ -137,6 +164,7 @@ static RIOMMapFileObj *mmap_create(RIO *io, const char *filename, int perm, int
}
mmo->filename = strdup (filename);
mmo->perm = perm;
mmo->isblk = -1;
mmo->mode = mode;
mmo->io_backref = io;
if (!mmap_refresh (mmo)) {
@@ -311,17 +339,11 @@ static bool __resize(RIO *io, RIODesc *fd, ut64 size) {
return mmap_truncate (fd, mmo, size);
}
#if R2__UNIX__
static bool __is_blockdevice(RIODesc *desc) {
R_RETURN_VAL_IF_FAIL (desc && desc->data, false);
RIOMMapFileObj *mmo = desc->data;
struct stat buf;
if (fstat (mmo->fd, &buf) == -1) {
return false;
}
return ((buf.st_mode & S_IFBLK) == S_IFBLK);
return mmo? mmo->isblk == 1: false;
}
#endif
RIOPlugin r_io_plugin_default = {
.meta = {