mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-11 00:06:19 +00:00
54617455de
* It's implemented in IO, Socket and Core * Remove duplicated apis and defines, everything in in RSocket now * RIO now owns an RCoreBind instead of 3 fcn pointers + 1 void* * Use proper filenames in libr/socket following public api names * Use RSocket.block apis in the rap client + server apis
60 lines
1.9 KiB
C
60 lines
1.9 KiB
C
/* radare - LGPL - Copyright 2017-2019 - 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) {
|
|
r_return_val_if_fail (io, false);
|
|
return (io->va && r_io_map_get (io, vaddr));
|
|
}
|
|
|
|
// 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) {
|
|
r_return_val_if_fail (io, false);
|
|
if (io->va) {
|
|
if (!hasperm) {
|
|
// return r_io_map_is_mapped (io, offset);
|
|
RIOMap* map = r_io_map_get (io, offset);
|
|
return map? map->perm & R_PERM_R: false;
|
|
}
|
|
RIOMap* map = r_io_map_get (io, offset);
|
|
return map? (map->perm & hasperm) == hasperm: false;
|
|
}
|
|
if (!io->desc) {
|
|
return false;
|
|
}
|
|
if (offset > r_io_desc_size (io->desc)) {
|
|
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];
|
|
r_return_val_if_fail (io && val, 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];
|
|
r_return_val_if_fail (io && val, 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);
|
|
return r_io_write_at (io, addr, buf, size) == size;
|
|
}
|