mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 20:22:38 +00:00
75 lines
1.8 KiB
C
75 lines
1.8 KiB
C
/* radare - LGPL - Copyright 2017-2018 - condret */
|
|
|
|
#include <r_io.h>
|
|
#include <r_util.h>
|
|
#include <r_types.h>
|
|
#include "io_private.h"
|
|
|
|
//This helper function only check if the given vaddr is mapped, it does not account
|
|
//for map perms
|
|
R_API bool r_io_addr_is_mapped(RIO *io, ut64 vaddr) {
|
|
if (io) {
|
|
if (io->va && r_io_map_get (io, vaddr)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// when io.va is true this checks if the highest priorized map at this
|
|
// offset has the same or high permissions set. When there is no map it
|
|
// check for the current desc permissions and size.
|
|
// when io.va is false it only checks for the desc
|
|
R_API bool r_io_is_valid_offset(RIO* io, ut64 offset, int hasperm) {
|
|
RIOMap* map;
|
|
if (!io) {
|
|
return false;
|
|
}
|
|
if (io->va) {
|
|
if (!hasperm) {
|
|
return r_io_map_is_mapped (io, offset);
|
|
}
|
|
if ((map = r_io_map_get (io, offset))) {
|
|
return ((map->perm & hasperm) == hasperm);
|
|
}
|
|
return false;
|
|
}
|
|
if (!io->desc) {
|
|
return false;
|
|
}
|
|
if (r_io_desc_size (io->desc) <= offset) {
|
|
return false;
|
|
}
|
|
return ((io->desc->perm & hasperm) == hasperm);
|
|
}
|
|
|
|
// this is wrong, there is more than big and little endian
|
|
R_API bool r_io_read_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) {
|
|
ut8 buf[8];
|
|
if (!val) {
|
|
return false;
|
|
}
|
|
size = R_DIM (size, 1, 8);
|
|
if (!r_io_read_at (io, addr, buf, size)) {
|
|
return false;
|
|
}
|
|
//size says the number of bytes to read transform to bits for r_read_ble
|
|
*val = r_read_ble (buf, endian, size * 8);
|
|
return true;
|
|
}
|
|
|
|
|
|
R_API bool r_io_write_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) {
|
|
ut8 buf[8];
|
|
if (!val) {
|
|
return false;
|
|
}
|
|
size = R_DIM (size, 1, 8);
|
|
//size says the number of bytes to read transform to bits for r_read_ble
|
|
r_write_ble (buf, *val, endian, size * 8);
|
|
if (!r_io_write_at (io, addr, buf, size)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|