radare2/libr/io/ioutils.c
radare ae0d52f1a8
Fix issue when analyzing the last DEX method ##anal
* Deprecate the is_valid_offset() anal callback, that's task for IO!
* WIP: Fix the Dalvik analysis by skipping fields and imports
2019-05-16 23:38:27 +02:00

69 lines
1.8 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);
RIOMap* map;
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 (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];
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;
}