mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
Fix #11112 - Rename {srwx,flags,perms} to perm. (-21 LOC)
Unify R_IO, R_BIN, R_BP, .. into R_PERM_* using 1 letter syntax
This commit is contained in:
parent
798ef9519e
commit
41ec949204
@ -16,7 +16,7 @@ static RCoreFile *openself(void) {
|
||||
char *out = r_core_cmd_str (core, "o");
|
||||
if (out) {
|
||||
if (!strstr (out, "self://")) {
|
||||
fd = r_core_file_open (core, "self://", R_IO_RW, 0);
|
||||
fd = r_core_file_open (core, "self://", R_PERM_RW, 0);
|
||||
}
|
||||
free (out);
|
||||
}
|
||||
@ -74,7 +74,7 @@ void alloc_console() {
|
||||
static void start_r2() {
|
||||
core = r_core_new ();
|
||||
r_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL);
|
||||
RCoreFile *fd = r_core_file_open (core, "self://", R_IO_RW, 0);
|
||||
RCoreFile *fd = r_core_file_open (core, "self://", R_PERM_RW, 0);
|
||||
r_core_prompt_loop (core);
|
||||
r_core_file_close (core, fd);
|
||||
}
|
||||
|
@ -978,7 +978,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (file && *file) {
|
||||
if ((fh = r_core_file_open (&core, file, R_IO_READ, 0))) {
|
||||
if ((fh = r_core_file_open (&core, file, R_PERM_R, 0))) {
|
||||
fd = r_io_fd_get_current (core.io);
|
||||
if (fd == -1) {
|
||||
eprintf ("r_core: Cannot open file '%s'\n", file);
|
||||
|
@ -477,7 +477,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
int help = 0;
|
||||
int run_anal = 1;
|
||||
int run_rc = 1;
|
||||
int ret, c, perms = R_IO_READ | R_IO_EXEC;
|
||||
int ret, c, perms = R_PERM_RX;
|
||||
bool sandbox = false;
|
||||
ut64 baddr = UT64_MAX;
|
||||
ut64 seek = UT64_MAX;
|
||||
@ -722,10 +722,10 @@ int main(int argc, char **argv, char **envp) {
|
||||
case 'V':
|
||||
return verify_version (1);
|
||||
case 'w':
|
||||
perms |= R_IO_WRITE;
|
||||
perms |= R_PERM_W;
|
||||
break;
|
||||
case 'x':
|
||||
perms &= ~R_IO_EXEC;
|
||||
perms &= ~R_PERM_X;
|
||||
r_config_set (r.config, "io.exec", "false");
|
||||
break;
|
||||
default:
|
||||
@ -971,7 +971,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
}
|
||||
r_config_set (r.config, "search.in", "dbg.map"); // implicit?
|
||||
r_config_set (r.config, "cfg.debug", "true");
|
||||
perms = R_IO_READ | R_IO_WRITE | R_IO_EXEC;
|
||||
perms = R_PERM_RWX;
|
||||
if (optind >= argc) {
|
||||
eprintf ("No program given to -d\n");
|
||||
LISTS_FREE ();
|
||||
@ -984,7 +984,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
if (!haveRarunProfile) {
|
||||
pfile = strdup (argv[optind++]);
|
||||
}
|
||||
perms = R_IO_READ | R_IO_EXEC; // XXX. should work with rw too
|
||||
perms = R_PERM_RX; // XXX. should work with rw too
|
||||
debug = 2;
|
||||
if (!strstr (pfile, "://")) {
|
||||
optind--; // take filename
|
||||
@ -1099,11 +1099,11 @@ int main(int argc, char **argv, char **envp) {
|
||||
while (optind < argc) {
|
||||
pfile = argv[optind++];
|
||||
fh = r_core_file_open (&r, pfile, perms, mapaddr);
|
||||
if (!fh && perms & R_IO_WRITE) {
|
||||
perms |= R_IO_CREAT;
|
||||
if (!fh && perms & R_PERM_W) {
|
||||
perms |= R_PERM_CREAT;
|
||||
fh = r_core_file_open (&r, pfile, perms, mapaddr);
|
||||
}
|
||||
if (perms & R_IO_CREAT) {
|
||||
if (perms & R_PERM_CREAT) {
|
||||
if (fh) {
|
||||
r_config_set_i (r.config, "io.va", false);
|
||||
} else {
|
||||
@ -1112,8 +1112,8 @@ int main(int argc, char **argv, char **envp) {
|
||||
}
|
||||
if (fh) {
|
||||
iod = r.io ? r_io_desc_get (r.io, fh->fd) : NULL;
|
||||
if (perms & R_IO_EXEC) {
|
||||
iod->flags |= R_IO_EXEC;
|
||||
if (perms & R_PERM_X) {
|
||||
iod->perm |= R_PERM_X;
|
||||
}
|
||||
if (run_anal > 0) {
|
||||
#if USE_THREADS
|
||||
@ -1161,7 +1161,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
if (fh) {
|
||||
iod = r.io ? r_io_desc_get (r.io, fh->fd) : NULL;
|
||||
if (iod) {
|
||||
perms = iod->flags;
|
||||
perms = iod->perm;
|
||||
r_io_map_new (r.io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod));
|
||||
}
|
||||
}
|
||||
@ -1219,7 +1219,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
if (!fh) {
|
||||
if (pfile && *pfile) {
|
||||
r_cons_flush ();
|
||||
if (perms & R_IO_WRITE) {
|
||||
if (perms & R_PERM_W) {
|
||||
eprintf ("[w] Cannot open '%s' for writing.\n", pfile);
|
||||
} else {
|
||||
eprintf ("[r] Cannot open '%s'\n", pfile);
|
||||
@ -1380,7 +1380,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
if (fullfile) {
|
||||
r_core_block_size (&r, r_io_desc_size (iod));
|
||||
}
|
||||
if (perms & R_IO_WRITE) {
|
||||
if (perms & R_PERM_W) {
|
||||
r_core_cmd0 (&r, "omfg+w");
|
||||
}
|
||||
ret = run_commands (cmds, files, quiet);
|
||||
|
@ -130,7 +130,7 @@ static int rafind_open_file(char *file) {
|
||||
}
|
||||
|
||||
io = r_io_new ();
|
||||
fd = r_io_open_nomap (io, file, R_IO_READ, 0);
|
||||
fd = r_io_open_nomap (io, file, R_PERM_R, 0);
|
||||
if (!fd) {
|
||||
eprintf ("Cannot open file '%s'\n", file);
|
||||
return 1;
|
||||
|
@ -681,7 +681,7 @@ int main(int argc, char **argv) {
|
||||
ut8 *buf = (ut8 *) r_stdin_slurp (&sz);
|
||||
char *uri = r_str_newf ("malloc://%d", sz);
|
||||
if (sz > 0) {
|
||||
desc = r_io_open_nomap (io, uri, R_IO_READ, 0);
|
||||
desc = r_io_open_nomap (io, uri, R_PERM_R, 0);
|
||||
if (!desc) {
|
||||
eprintf ("rahash2: Cannot open malloc://1024\n");
|
||||
return 1;
|
||||
@ -694,7 +694,7 @@ int main(int argc, char **argv) {
|
||||
eprintf ("rahash2: Cannot hash directories\n");
|
||||
return 1;
|
||||
}
|
||||
desc = r_io_open_nomap (io, argv[i], R_IO_READ, 0);
|
||||
desc = r_io_open_nomap (io, argv[i], R_PERM_R, 0);
|
||||
if (!desc) {
|
||||
eprintf ("rahash2: Cannot open '%s'\n", argv[i]);
|
||||
return 1;
|
||||
|
@ -89,7 +89,7 @@ static void map_cpu_memory (RAnal *anal, int entry, ut32 addr, ut32 size, bool f
|
||||
} else {
|
||||
// allocate memory for address space
|
||||
char *mstr = r_str_newf ("malloc://%d", size);
|
||||
desc = anal->iob.open_at (anal->iob.io, mstr, R_IO_READ | R_IO_WRITE, 0, addr);
|
||||
desc = anal->iob.open_at (anal->iob.io, mstr, R_PERM_RW, 0, addr);
|
||||
r_str_free (mstr);
|
||||
// set 8051 address space as name of mapped memory
|
||||
if (desc && anal->iob.fd_get_name (anal->iob.io, desc->fd)) {
|
||||
|
@ -640,14 +640,13 @@ static RIODesc *cpu_memory_map (RIOBind *iob, RIODesc *desc, ut32 addr,
|
||||
if (desc && iob->fd_get_name (iob->io, desc->fd)) {
|
||||
iob->fd_remap (iob->io, desc->fd, addr);
|
||||
} else {
|
||||
desc = iob->open_at (iob->io, mstr, R_IO_READ | R_IO_WRITE, 0, addr);
|
||||
desc = iob->open_at (iob->io, mstr, R_PERM_RW, 0, addr);
|
||||
}
|
||||
free (mstr);
|
||||
return desc;
|
||||
}
|
||||
|
||||
static bool pic_midrange_reg_write (RReg *reg, const char *regname,
|
||||
ut32 num) {
|
||||
static bool pic_midrange_reg_write (RReg *reg, const char *regname, ut32 num) {
|
||||
if (reg) {
|
||||
RRegItem *item = r_reg_get (reg, regname, R_REG_TYPE_GPR);
|
||||
if (item) {
|
||||
|
@ -245,7 +245,7 @@ R_API int r_bin_load(RBin *bin, const char *file, ut64 baseaddr, ut64 loadaddr,
|
||||
iob = &bin->iob;
|
||||
}
|
||||
if (!iob->desc_get (iob->io, fd)) {
|
||||
fd = iob->fd_open (iob->io, file, R_IO_READ, 0644);
|
||||
fd = iob->fd_open (iob->io, file, R_PERM_R, 0644);
|
||||
}
|
||||
bin->rawstr = rawstr;
|
||||
// Use the current RIODesc otherwise r_io_map_select can swap them later on
|
||||
@ -269,7 +269,7 @@ R_API int r_bin_load_as(RBin *bin, const char *file, ut64 baseaddr,
|
||||
return false;
|
||||
}
|
||||
if (fd < 0) {
|
||||
fd = iob->fd_open (iob->io, file, R_IO_READ, 0644);
|
||||
fd = iob->fd_open (iob->io, file, R_PERM_R, 0644);
|
||||
}
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
@ -320,7 +320,7 @@ R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) {
|
||||
// load the bin-properly. Many of the plugins require all
|
||||
// content and are not
|
||||
// stream based loaders
|
||||
int tfd = iob->fd_open (iob->io, name, R_IO_READ, 0);
|
||||
int tfd = iob->fd_open (iob->io, name, R_PERM_R, 0);
|
||||
if (tfd < 0) {
|
||||
res = false;
|
||||
goto error;
|
||||
@ -403,7 +403,7 @@ R_API bool r_bin_load_io2(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int x
|
||||
file_sz = iob->fd_size (io, fd);
|
||||
// file_sz = UT64_MAX happens when attaching to frida:// and other non-debugger io plugins which results in double opening
|
||||
if (is_debugger && file_sz == UT64_MAX) {
|
||||
tfd = iob->fd_open (io, fname, R_IO_READ, 0644);
|
||||
tfd = iob->fd_open (io, fname, R_PERM_R, 0644);
|
||||
if (tfd >= 1) {
|
||||
file_sz = iob->fd_size (io, tfd);
|
||||
}
|
||||
@ -458,7 +458,7 @@ R_API bool r_bin_load_io2(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int x
|
||||
if (is_debugger && sz != file_sz) {
|
||||
R_FREE (buf_bytes);
|
||||
if (tfd < 0) {
|
||||
tfd = iob->fd_open (io, fname, R_IO_READ, 0);
|
||||
tfd = iob->fd_open (io, fname, R_PERM_R, 0);
|
||||
}
|
||||
sz = iob->fd_size (io, tfd);
|
||||
if (sz != UT64_MAX) {
|
||||
@ -1540,7 +1540,7 @@ R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) {
|
||||
if (bin->cur->o->info->bits == 16) {
|
||||
RBinSection *s = r_bin_get_section_at (bin->cur->o, paddr, false);
|
||||
// autodetect thumb
|
||||
if (s && s->srwx & 1 && strstr (s->name, "text")) {
|
||||
if (s && (s->perm & R_PERM_X) && strstr (s->name, "text")) {
|
||||
if (!strcmp (bin->cur->o->info->arch, "arm") && (vaddr & 1)) {
|
||||
vaddr = (vaddr >> 1) << 1;
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ static void parseCodeDirectory (RBuffer *b, int offset, int datasize) {
|
||||
ut8 *hash = p + cscd.hashOffset;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
eprintf ("Hashed region: 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", 0, cscd.codeLimit);
|
||||
eprintf ("Hashed region: 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", (ut64)0, (ut64)cscd.codeLimit);
|
||||
for (j = 0; j < cscd.nCodeSlots; j++) {
|
||||
int fof = 4096 * j;
|
||||
int idx = j * hashSize;
|
||||
@ -1604,7 +1604,7 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
|
||||
sectname[16] = 0;
|
||||
r_str_filter (sectname, -1);
|
||||
// hack to support multiple sections with same name
|
||||
sections[i].srwx = prot2perm (seg->initprot);
|
||||
sections[i].perm = prot2perm (seg->initprot);
|
||||
sections[i].last = 0;
|
||||
}
|
||||
sections[i].last = 1;
|
||||
@ -1638,7 +1638,7 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
|
||||
for (j = 0; j < bin->nsegs; j++) {
|
||||
if (sections[i].addr >= bin->segs[j].vmaddr &&
|
||||
sections[i].addr < (bin->segs[j].vmaddr + bin->segs[j].vmsize)) {
|
||||
sections[i].srwx = prot2perm (bin->segs[j].initprot);
|
||||
sections[i].perm = prot2perm (bin->segs[j].initprot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct section_t {
|
||||
ut64 vsize;
|
||||
ut32 align;
|
||||
ut32 flags;
|
||||
int srwx;
|
||||
int perm;
|
||||
char name[R_BIN_MACH0_STRING_LENGTH];
|
||||
int last;
|
||||
};
|
||||
|
@ -40,27 +40,27 @@ struct minidump_memory_info *r_bin_mdmp_get_mem_info(struct r_bin_mdmp_obj *obj,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ut32 r_bin_mdmp_get_srwx(struct r_bin_mdmp_obj *obj, ut64 vaddr) {
|
||||
ut32 r_bin_mdmp_get_perm(struct r_bin_mdmp_obj *obj, ut64 vaddr) {
|
||||
struct minidump_memory_info *mem_info;
|
||||
|
||||
if (!(mem_info = r_bin_mdmp_get_mem_info(obj, vaddr))) {
|
||||
/* if there is no mem info in the dump, assume default permission */
|
||||
return R_BIN_SCN_READABLE;
|
||||
return R_PERM_R;
|
||||
}
|
||||
|
||||
/* FIXME: Have I got these mappings right, I am not sure I have!!! */
|
||||
|
||||
switch (mem_info->protect) {
|
||||
case MINIDUMP_PAGE_READONLY:
|
||||
return R_BIN_SCN_READABLE;
|
||||
return R_PERM_R;
|
||||
case MINIDUMP_PAGE_READWRITE:
|
||||
return R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE;
|
||||
return R_PERM_RW;
|
||||
case MINIDUMP_PAGE_EXECUTE:
|
||||
return R_BIN_SCN_EXECUTABLE;
|
||||
return R_PERM_X;
|
||||
case MINIDUMP_PAGE_EXECUTE_READ:
|
||||
return R_BIN_SCN_EXECUTABLE | R_BIN_SCN_READABLE;
|
||||
return R_PERM_RX;
|
||||
case MINIDUMP_PAGE_EXECUTE_READWRITE:
|
||||
return R_BIN_SCN_EXECUTABLE | R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE;
|
||||
return R_PERM_RWX;
|
||||
case MINIDUMP_PAGE_NOACCESS:
|
||||
case MINIDUMP_PAGE_WRITECOPY:
|
||||
case MINIDUMP_PAGE_EXECUTE_WRITECOPY:
|
||||
|
@ -58,7 +58,7 @@ struct r_bin_mdmp_obj {
|
||||
struct r_bin_mdmp_obj *r_bin_mdmp_new_buf(struct r_buf_t *buf);
|
||||
void r_bin_mdmp_free(struct r_bin_mdmp_obj *obj);
|
||||
ut64 r_bin_mdmp_get_paddr(struct r_bin_mdmp_obj *obj, ut64 vaddr);
|
||||
ut32 r_bin_mdmp_get_srwx(struct r_bin_mdmp_obj *obj, ut64 vaddr);
|
||||
ut32 r_bin_mdmp_get_perm(struct r_bin_mdmp_obj *obj, ut64 vaddr);
|
||||
struct minidump_memory_info *r_bin_mdmp_get_mem_info(struct r_bin_mdmp_obj *obj, ut64 vaddr);
|
||||
|
||||
#endif /* MDMP_H */
|
||||
|
@ -177,22 +177,22 @@ RList *PE_(r_bin_mdmp_pe_get_sections)(struct PE_(r_bin_mdmp_pe_bin) *pe_bin) {
|
||||
ptr->paddr = sections[i].paddr + pe_bin->paddr;
|
||||
ptr->vaddr = sections[i].vaddr + ba;
|
||||
ptr->add = false;
|
||||
ptr->srwx = 0;
|
||||
if (R_BIN_PE_SCN_IS_EXECUTABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = 0;
|
||||
if (R_BIN_PE_SCN_IS_EXECUTABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_X;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_WRITABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_WRITABLE;
|
||||
if (R_BIN_PE_SCN_IS_WRITABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_W;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_READABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
if (R_BIN_PE_SCN_IS_READABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_X;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_SHAREABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_SHAREABLE;
|
||||
if (R_BIN_PE_SCN_IS_SHAREABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_SHAR;
|
||||
}
|
||||
#define X 1
|
||||
#define ROW (4 | 2)
|
||||
if (ptr->srwx & ROW && !(ptr->srwx & X) && ptr->size > 0) {
|
||||
if (ptr->perm & ROW && !(ptr->perm & X) && ptr->size > 0) {
|
||||
if (!strcmp (ptr->name, ".rsrc") ||
|
||||
!strcmp (ptr->name, ".data") ||
|
||||
!strcmp (ptr->name, ".rdata")) {
|
||||
|
@ -749,8 +749,7 @@ int r_bin_omf_send_sections(RList *list, OMF_segment *section, r_bin_omf_obj *ob
|
||||
new->vsize = data->size;
|
||||
new->paddr = data->paddr;
|
||||
new->vaddr = section->vaddr + data->offset + OMF_BASE_ADDR;
|
||||
new->srwx = R_BIN_SCN_EXECUTABLE | R_BIN_SCN_WRITABLE |
|
||||
R_BIN_SCN_READABLE;
|
||||
new->perm = R_PERM_RWX;
|
||||
new->add = true;
|
||||
r_list_append (list, new);
|
||||
data = data->next;
|
||||
|
@ -2568,7 +2568,7 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)*
|
||||
"trying to fix it but i do not promise nothing\n");
|
||||
}
|
||||
for (i = 0; i < bin->num_sections; i++) {
|
||||
if (sections[i].flags & PE_IMAGE_SCN_MEM_EXECUTE) {
|
||||
if (sections[i].perm & PE_IMAGE_SCN_MEM_EXECUTE) {
|
||||
entry->paddr = sections[i].paddr;
|
||||
entry->vaddr = sections[i].vaddr + base_addr;
|
||||
paddr = 1;
|
||||
@ -2602,7 +2602,7 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)*
|
||||
struct r_bin_pe_section_t* sections = bin->sections;
|
||||
for (i = 0; i < bin->num_sections; i++) {
|
||||
//If there is a section with x without w perm is a good candidate to be the entrypoint
|
||||
if (sections[i].flags & PE_IMAGE_SCN_MEM_EXECUTE && !(sections[i].flags & PE_IMAGE_SCN_MEM_WRITE)) {
|
||||
if (sections[i].perm & PE_IMAGE_SCN_MEM_EXECUTE && !(sections[i].perm & PE_IMAGE_SCN_MEM_WRITE)) {
|
||||
entry->paddr = sections[i].paddr;
|
||||
entry->vaddr = sections[i].vaddr + base_addr;
|
||||
break;
|
||||
@ -3247,7 +3247,7 @@ void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_
|
||||
}
|
||||
//look for other segment with x that is already mapped and hold entrypoint
|
||||
for (j = 0; !sections[j].last; j++) {
|
||||
if (sections[j].flags & PE_IMAGE_SCN_MEM_EXECUTE) {
|
||||
if (sections[j].perm & PE_IMAGE_SCN_MEM_EXECUTE) {
|
||||
addr_beg = sections[j].paddr;
|
||||
addr_end = addr_beg + sections[j].size;
|
||||
if (addr_beg <= entry->paddr && entry->paddr < addr_end) {
|
||||
@ -3270,7 +3270,7 @@ void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_
|
||||
sections[i].paddr = entry->paddr;
|
||||
sections[i].vaddr = entry->vaddr - base_addr;
|
||||
sections[i].size = sections[i].vsize = new_section_size;
|
||||
sections[i].flags = new_perm;
|
||||
sections[i].perm = new_perm;
|
||||
}
|
||||
goto out_function;
|
||||
}
|
||||
@ -3306,7 +3306,7 @@ void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_
|
||||
sections[i].paddr = entry->paddr;
|
||||
sections[i].vaddr = entry->vaddr - base_addr;
|
||||
sections[i].size = sections[i].vsize = new_section_size;
|
||||
sections[i].flags = new_perm;
|
||||
sections[i].perm = new_perm;
|
||||
sections[i + 1].last = 1;
|
||||
*sects = sections;
|
||||
out_function:
|
||||
@ -3387,7 +3387,7 @@ static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe
|
||||
}
|
||||
}
|
||||
sections[j].paddr = shdr[i].PointerToRawData;
|
||||
sections[j].flags = shdr[i].Characteristics;
|
||||
sections[j].perm = shdr[i].Characteristics;
|
||||
sections[j].last = 0;
|
||||
j++;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ struct r_bin_pe_section_t {
|
||||
ut64 vsize;
|
||||
ut64 vaddr;
|
||||
ut64 paddr;
|
||||
ut64 flags;
|
||||
ut64 perm;
|
||||
int last;
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2010-2017 pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2010-2018 pancake, nibble */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -20,28 +20,27 @@ bool PE_(r_bin_pe_section_perms)(struct PE_(r_bin_pe_obj_t) *bin, const char *na
|
||||
ut32 newperms_le;
|
||||
|
||||
/* Apply permission flags */
|
||||
if (perms & R_BIN_SCN_EXECUTABLE) {
|
||||
if (perms & R_PERM_X) {
|
||||
newperms |= PE_IMAGE_SCN_MEM_EXECUTE;
|
||||
} else {
|
||||
newperms &= ~PE_IMAGE_SCN_MEM_EXECUTE;
|
||||
}
|
||||
if (perms & R_BIN_SCN_WRITABLE) {
|
||||
if (perms & R_PERM_W) {
|
||||
newperms |= PE_IMAGE_SCN_MEM_WRITE;
|
||||
} else {
|
||||
newperms &= ~PE_IMAGE_SCN_MEM_WRITE;
|
||||
}
|
||||
if (perms & R_BIN_SCN_READABLE) {
|
||||
if (perms & R_PERM_R) {
|
||||
newperms |= PE_IMAGE_SCN_MEM_READ;
|
||||
} else {
|
||||
newperms &= ~PE_IMAGE_SCN_MEM_READ;
|
||||
}
|
||||
if (perms & R_BIN_SCN_SHAREABLE) {
|
||||
if (perms & R_PERM_SHAR) {
|
||||
newperms |= PE_IMAGE_SCN_MEM_SHARED;
|
||||
} else {
|
||||
newperms &= ~PE_IMAGE_SCN_MEM_SHARED;
|
||||
}
|
||||
|
||||
|
||||
patchoff = bin->section_header_offset;
|
||||
patchoff += i * sizeof (PE_(image_section_header));
|
||||
patchoff += r_offsetof (PE_(image_section_header), Characteristics);
|
||||
@ -52,4 +51,4 @@ bool PE_(r_bin_pe_section_perms)(struct PE_(r_bin_pe_obj_t) *bin, const char *na
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2015-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2015-2018 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -171,7 +171,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = art.image_size; // TODO: align?
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = art.image_base;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -183,7 +183,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = art.bitmap_size;
|
||||
ptr->paddr = art.bitmap_offset;
|
||||
ptr->vaddr = art.image_base + art.bitmap_offset;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -195,7 +195,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vaddr = art.oat_file_begin;
|
||||
ptr->size = art.oat_file_end - art.oat_file_begin;
|
||||
ptr->vsize = ptr->size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -207,7 +207,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vaddr = art.oat_data_begin;
|
||||
ptr->size = art.oat_data_end - art.oat_data_begin;
|
||||
ptr->vsize = ptr->size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
|
@ -72,7 +72,7 @@ static RList *patch_relocs(RBin *b) {
|
||||
if (!b || !b->iob.io || !b->iob.io->desc) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(b->iob.io->cached & R_IO_WRITE)) {
|
||||
if (!(b->iob.io->cached & R_PERM_W)) {
|
||||
eprintf (
|
||||
"Warning: please run r2 with -e io.cache=true to patch "
|
||||
"relocations\n");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2013-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2013-2018 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -11,14 +11,14 @@ static bool check_bytes(const ut8 *buf, ut64 length) {
|
||||
/* hacky check to avoid detecting multidex bins as bios */
|
||||
/* need better fix for this */
|
||||
if (!memcmp (buf, "dex", 3)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
/* Check if this a 'jmp' opcode */
|
||||
if ((buf[ep] == 0xea) || (buf[ep] == 0xe9)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void *load_bytes(RBinFile *bf, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) {
|
||||
@ -84,8 +84,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = ptr->size = 0x10000;
|
||||
ptr->paddr = bf->buf->length - ptr->size;
|
||||
ptr->vaddr = 0xf0000;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE |
|
||||
R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
return ret;
|
||||
|
@ -195,7 +195,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = bi->page_size;
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = 0;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -207,7 +207,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = ADD_REMAINDER (ptr->size, bi->page_size);
|
||||
ptr->paddr = bi->page_size;
|
||||
ptr->vaddr = bi->kernel_addr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -221,7 +221,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = ADD_REMAINDER (bi->ramdisk_size, bi->page_size);
|
||||
ptr->paddr = ROUND_DOWN (base, bi->page_size);
|
||||
ptr->vaddr = bi->ramdisk_addr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -236,7 +236,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = ADD_REMAINDER (bi->second_size, bi->page_size);
|
||||
ptr->paddr = ROUND_DOWN (base, bi->page_size);
|
||||
ptr->vaddr = bi->second_addr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -151,15 +151,15 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = obj->scn_hdrs[i].s_size;
|
||||
ptr->paddr = obj->scn_hdrs[i].s_scnptr;
|
||||
ptr->add = true;
|
||||
ptr->srwx = 0;
|
||||
ptr->perm = 0;
|
||||
if (obj->scn_hdrs[i].s_flags & COFF_SCN_MEM_READ) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
ptr->perm |= R_PERM_R;
|
||||
}
|
||||
if (obj->scn_hdrs[i].s_flags & COFF_SCN_MEM_WRITE) {
|
||||
ptr->srwx |= R_BIN_SCN_WRITABLE;
|
||||
ptr->perm |= R_PERM_W;
|
||||
}
|
||||
if (obj->scn_hdrs[i].s_flags & COFF_SCN_MEM_EXECUTE) {
|
||||
ptr->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm |= R_PERM_X;
|
||||
}
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -1921,7 +1921,7 @@ static RList *sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "header");
|
||||
ptr->size = ptr->vsize = sizeof (struct dex_header_t);
|
||||
ptr->paddr= ptr->vaddr = 0;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -1931,7 +1931,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->paddr= ptr->vaddr = sizeof (struct dex_header_t);
|
||||
ptr->size = bin->code_from - ptr->vaddr; // fix size
|
||||
ptr->vsize = ptr->size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -1940,7 +1940,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vaddr = ptr->paddr = bin->code_from; //ptr->vaddr = fsym;
|
||||
ptr->size = bin->code_to - ptr->paddr;
|
||||
ptr->vsize = ptr->size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -1956,7 +1956,7 @@ static RList *sections(RBinFile *bf) {
|
||||
// hacky workaround
|
||||
//ptr->size = ptr->vsize = 1024;
|
||||
}
|
||||
ptr->srwx = R_BIN_SCN_READABLE; //|2;
|
||||
ptr->perm = R_PERM_R; //|2;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static RList *sections(RBinFile *bf) {
|
||||
s->vaddr = dol->text_vaddr[i];
|
||||
s->size = dol->text_size[i];
|
||||
s->vsize = s->size;
|
||||
s->srwx = r_str_rwx ("r-x");
|
||||
s->perm = r_str_rwx ("r-x");
|
||||
s->add = true;
|
||||
r_list_append (ret, s);
|
||||
}
|
||||
@ -129,7 +129,7 @@ static RList *sections(RBinFile *bf) {
|
||||
s->vaddr = dol->data_vaddr[i];
|
||||
s->size = dol->data_size[i];
|
||||
s->vsize = s->size;
|
||||
s->srwx = r_str_rwx ("r--");
|
||||
s->perm = r_str_rwx ("r--");
|
||||
s->add = true;
|
||||
r_list_append (ret, s);
|
||||
}
|
||||
@ -140,7 +140,7 @@ static RList *sections(RBinFile *bf) {
|
||||
s->vaddr = dol->bss_addr;
|
||||
s->size = dol->bss_size;
|
||||
s->vsize = s->size;
|
||||
s->srwx = r_str_rwx ("rw-");
|
||||
s->perm = r_str_rwx ("rw-");
|
||||
s->add = true;
|
||||
r_list_append (ret, s);
|
||||
|
||||
|
@ -300,7 +300,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache) {
|
||||
int i;
|
||||
for (i = 0; i < cache->hdr->mappingCount; ++i) {
|
||||
int perm = prot2perm (cache->maps[i].initProt);
|
||||
if (!(perm & R_BIN_SCN_EXECUTABLE)) {
|
||||
if (!(perm & R_PERM_X)) {
|
||||
start_of_data = cache->maps[i].fileOffset;// + bf->o->boffset;
|
||||
break;
|
||||
}
|
||||
@ -1044,7 +1044,7 @@ static void sections_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin) {
|
||||
if (!ptr->vaddr) {
|
||||
ptr->vaddr = ptr->paddr;
|
||||
}
|
||||
ptr->srwx = sections[i].srwx;
|
||||
ptr->perm = sections[i].perm;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
free (sections);
|
||||
@ -1080,7 +1080,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->paddr = cache->maps[i].fileOffset;// + bf->o->boffset;
|
||||
ptr->vaddr = cache->maps[i].address;
|
||||
ptr->add = true;
|
||||
ptr->srwx = prot2perm (cache->maps[i].initProt);
|
||||
ptr->perm = prot2perm (cache->maps[i].initProt);
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
||||
|
@ -196,15 +196,15 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->paddr = section[i].offset;
|
||||
ptr->vaddr = section[i].rva;
|
||||
ptr->add = !obj->phdr; // Load sections if there is no PHDR
|
||||
ptr->srwx = 0;
|
||||
ptr->perm = 0;
|
||||
if (R_BIN_ELF_SCN_IS_EXECUTABLE (section[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm |= R_PERM_X;
|
||||
}
|
||||
if (R_BIN_ELF_SCN_IS_WRITABLE (section[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_WRITABLE;
|
||||
ptr->perm |= R_PERM_W;
|
||||
}
|
||||
if (R_BIN_ELF_SCN_IS_READABLE (section[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
ptr->perm |= R_PERM_R;
|
||||
}
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -224,7 +224,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = phdr[i].p_memsz;
|
||||
ptr->paddr = phdr[i].p_offset;
|
||||
ptr->vaddr = phdr[i].p_vaddr;
|
||||
ptr->srwx = phdr[i].p_flags;
|
||||
ptr->perm = phdr[i].p_flags;
|
||||
ptr->is_segment = true;
|
||||
switch (phdr[i].p_type) {
|
||||
case PT_DYNAMIC:
|
||||
@ -280,8 +280,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = 0x10000;
|
||||
ptr->add = true;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE |
|
||||
R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
}
|
||||
@ -301,7 +300,7 @@ static RList* sections(RBinFile *bf) {
|
||||
if (obj->ehdr.e_type == ET_REL) {
|
||||
ptr->add = true;
|
||||
}
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE;
|
||||
ptr->perm = R_PERM_RW;
|
||||
ptr->is_segment = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -980,7 +979,7 @@ static RList* patch_relocs(RBin *b) {
|
||||
n_vaddr = g->vaddr + g->vsize;
|
||||
//reserve at least that space
|
||||
size = bin->reloc_num * 4;
|
||||
if (!b->iob.section_add (io, n_off, n_vaddr, size, size, R_BIN_SCN_READABLE, ".got.r2", 0, io->desc->fd)) {
|
||||
if (!b->iob.section_add (io, n_off, n_vaddr, size, size, R_PERM_R, ".got.r2", 0, io->desc->fd)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(relcs = Elf_(r_bin_elf_get_relocs) (bin))) {
|
||||
|
@ -154,7 +154,7 @@ static RList* sections(RBinFile *bf) {
|
||||
// eprintf ("mapping text to va = 0\n");
|
||||
// ptr->vaddr = ptr->paddr;
|
||||
}
|
||||
ptr->srwx = sections[i].srwx;
|
||||
ptr->perm = sections[i].perm;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
free (sections);
|
||||
|
@ -132,7 +132,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = sb.psize;
|
||||
ptr->paddr = sb.paddr + 40;
|
||||
ptr->vaddr = sb.vaddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
ptr->has_strings = true;
|
||||
r_list_append (ret, ptr);
|
||||
@ -145,7 +145,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = sb.sign_sz;
|
||||
ptr->paddr = sb.sign_va - sb.vaddr;
|
||||
ptr->vaddr = sb.sign_va;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->has_strings = true;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
@ -159,7 +159,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = sb.cert_sz;
|
||||
ptr->paddr = sb.cert_va - sb.vaddr;
|
||||
ptr->vaddr = sb.cert_va;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->has_strings = true;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
@ -249,7 +249,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->add = true;
|
||||
ptr->has_strings = false;
|
||||
|
||||
ptr->srwx = r_bin_mdmp_get_srwx (obj, ptr->vaddr);
|
||||
ptr->perm = r_bin_mdmp_get_perm (obj, ptr->vaddr);
|
||||
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -268,7 +268,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->add = true;
|
||||
ptr->has_strings = false;
|
||||
|
||||
ptr->srwx = r_bin_mdmp_get_srwx (obj, ptr->vaddr);
|
||||
ptr->perm = r_bin_mdmp_get_perm (obj, ptr->vaddr);
|
||||
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -293,7 +293,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->add = false;
|
||||
ptr->has_strings = false;
|
||||
/* As this is an encompassing section we will set the RWX to 0 */
|
||||
ptr->srwx = 0;
|
||||
ptr->perm = 0;
|
||||
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -345,7 +345,7 @@ static RList *mem (RBinFile *bf) {
|
||||
}
|
||||
ptr->addr = module->start_of_memory_range;
|
||||
ptr->size = location? location->data_size: 0;
|
||||
ptr->perms = r_bin_mdmp_get_srwx (obj, ptr->addr);
|
||||
ptr->perms = r_bin_mdmp_get_perm (obj, ptr->addr);
|
||||
|
||||
/* [1] */
|
||||
state = type = a_protect = 0;
|
||||
@ -367,7 +367,7 @@ static RList *mem (RBinFile *bf) {
|
||||
}
|
||||
ptr->addr = module64->start_of_memory_range;
|
||||
ptr->size = module64->data_size;
|
||||
ptr->perms = r_bin_mdmp_get_srwx (obj, ptr->addr);
|
||||
ptr->perms = r_bin_mdmp_get_perm (obj, ptr->addr);
|
||||
|
||||
/* [1] */
|
||||
state = type = a_protect = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2016 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2016-2018 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -132,7 +132,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = ptr->size + (ptr->size % 4096);
|
||||
ptr->paddr = r_read_ble32 (buf + 12, false);
|
||||
ptr->vaddr = ptr->paddr + baddr (bf);
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -148,7 +148,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->vsize = ptr->size + (ptr->size % 4096);
|
||||
ptr->paddr = r_read_ble32 (buf + 40, false);
|
||||
ptr->vaddr = ptr->paddr + baddr (bf);
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ static RList * sections(RBinFile *bf) {
|
||||
ptr->vsize = segments[i].size;
|
||||
ptr->paddr = segments[i].paddr;
|
||||
ptr->vaddr = segments[i].paddr;
|
||||
ptr->srwx = r_str_rwx ("rwx");
|
||||
ptr->perm = r_str_rwx ("rwx");
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->size = ihdr.prg_page_count_16k * PRG_PAGE_SIZE;
|
||||
ptr->vaddr = ROM_START_ADDRESS;
|
||||
ptr->vsize = ROM_SIZE;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
return ret;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - 2016 - a0rtega */
|
||||
/* radare - LGPL - 2018 - a0rtega */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -66,7 +66,7 @@ static RList *sections(RBinFile *bf) {
|
||||
sections[i]->vsize = loaded_header.sections[i].size;
|
||||
sections[i]->paddr = loaded_header.sections[i].offset;
|
||||
sections[i]->vaddr = loaded_header.sections[i].address;
|
||||
sections[i]->srwx = r_str_rwx ("rwx");
|
||||
sections[i]->perm = r_str_rwx ("rwx");
|
||||
sections[i]->add = true;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr9->vsize = loaded_header.arm9_size;
|
||||
ptr9->paddr = loaded_header.arm9_rom_offset;
|
||||
ptr9->vaddr = loaded_header.arm9_ram_address;
|
||||
ptr9->srwx = r_str_rwx ("rwx");
|
||||
ptr9->perm = r_str_rwx ("rwx");
|
||||
ptr9->add = true;
|
||||
r_list_append (ret, ptr9);
|
||||
|
||||
@ -79,7 +79,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr7->vsize = loaded_header.arm7_size;
|
||||
ptr7->paddr = loaded_header.arm7_rom_offset;
|
||||
ptr7->vaddr = loaded_header.arm7_ram_address;
|
||||
ptr7->srwx = r_str_rwx ("rwx");
|
||||
ptr7->perm = r_str_rwx ("rwx");
|
||||
ptr7->add = true;
|
||||
r_list_append (ret, ptr7);
|
||||
|
||||
|
@ -114,7 +114,7 @@ static RList* sections(RBinFile *bf){
|
||||
rombank[0]->size = 0x4000;
|
||||
rombank[0]->vsize = 0x4000;
|
||||
rombank[0]->vaddr = 0;
|
||||
rombank[0]->srwx = r_str_rwx ("rx");
|
||||
rombank[0]->perm = r_str_rwx ("rx");
|
||||
rombank[0]->add = true;
|
||||
|
||||
r_list_append (ret, rombank[0]);
|
||||
@ -125,7 +125,7 @@ static RList* sections(RBinFile *bf){
|
||||
rombank[i]->paddr = i*0x4000;
|
||||
rombank[i]->vaddr = i*0x10000-0xc000; //spaaaaaaaaaaaaaaaace!!!
|
||||
rombank[i]->size = rombank[i]->vsize = 0x4000;
|
||||
rombank[i]->srwx = r_str_rwx ("rx");
|
||||
rombank[i]->perm = r_str_rwx ("rx");
|
||||
rombank[i]->add = true;
|
||||
r_list_append (ret,rombank[i]);
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ static RList *sections(RBinFile *bf) {
|
||||
RList *ret = NULL;
|
||||
RBinSection *s = R_NEW0 (RBinSection);
|
||||
ut64 sz = r_buf_size (bf->buf);
|
||||
|
||||
if (!(ret = r_list_new ())) {
|
||||
free (s);
|
||||
return NULL;
|
||||
@ -90,7 +89,7 @@ static RList *sections(RBinFile *bf) {
|
||||
s->vaddr = 0x8000000;
|
||||
s->size = sz;
|
||||
s->vsize = 0x2000000;
|
||||
s->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
s->perm = R_PERM_RX;
|
||||
s->add = true;
|
||||
|
||||
r_list_append (ret, s);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2017 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2017-2018 - pancake */
|
||||
|
||||
// TODO: Support NRR and MODF
|
||||
#include <r_types.h>
|
||||
@ -119,7 +119,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = 0x80;
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = 0;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = false;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -136,7 +136,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = mod0sz;
|
||||
ptr->paddr = mod0;
|
||||
ptr->vaddr = mod0 + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // rw-
|
||||
ptr->perm = R_PERM_R; // rw-
|
||||
ptr->add = false;
|
||||
r_list_append (ret, ptr);
|
||||
} else {
|
||||
@ -154,7 +154,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = sig0sz;
|
||||
ptr->paddr = sig0;
|
||||
ptr->vaddr = sig0 + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
} else {
|
||||
@ -170,7 +170,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NRO_OFF (text_memoffset));
|
||||
ptr->vaddr = ptr->paddr + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -183,7 +183,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NRO_OFF (ro_memoffset));
|
||||
ptr->vaddr = ptr->paddr + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r-x
|
||||
ptr->perm = R_PERM_R; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -196,7 +196,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NRO_OFF (data_memoffset));
|
||||
ptr->vaddr = ptr->paddr + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE; // rw-
|
||||
ptr->perm = R_PERM_RW;
|
||||
ptr->add = true;
|
||||
eprintf ("Base Address 0x%08"PFMT64x "\n", ba);
|
||||
eprintf ("BSS Size 0x%08"PFMT64x "\n", (ut64)
|
||||
|
@ -67,7 +67,7 @@ static void *load_bytes(RBinFile *bf, const ut8 *buf, ut64 sz, ut64 loadaddr, Sd
|
||||
RBuffer *newbuf = r_buf_new_empty (total_size);
|
||||
ut64 ba = baddr (bf);
|
||||
|
||||
if (rbin->iob.io && !(rbin->iob.io->cached & R_IO_WRITE)) {
|
||||
if (rbin->iob.io && !(rbin->iob.io->cached & R_PERM_W)) {
|
||||
eprintf ("Please add \'-e io.cache=true\' option to r2 command\n");
|
||||
goto fail;
|
||||
}
|
||||
@ -165,7 +165,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = readLE32 (b, NSO_OFF (text_memoffset));
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = 0;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = false;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -178,7 +178,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NSO_OFF (text_memoffset));
|
||||
ptr->vaddr = readLE32 (b, NSO_OFF (text_loc)) + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -191,7 +191,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NSO_OFF (ro_memoffset));
|
||||
ptr->vaddr = readLE32 (b, NSO_OFF (ro_loc)) + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -204,7 +204,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->size = ptr->vsize;
|
||||
ptr->paddr = readLE32 (b, NSO_OFF (data_memoffset));
|
||||
ptr->vaddr = readLE32 (b, NSO_OFF (data_loc)) + ba;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE; // rw-
|
||||
ptr->perm = R_PERM_RW;
|
||||
ptr->add = true;
|
||||
eprintf ("BSS Size 0x%08"PFMT64x "\n", (ut64)
|
||||
readLE32 (bf->buf, NSO_OFF (bss_size)));
|
||||
@ -213,15 +213,11 @@ static RList *sections(RBinFile *bf) {
|
||||
}
|
||||
|
||||
static RList *symbols(RBinFile *bf) {
|
||||
RBinNXOObj *bin;
|
||||
if (!bf || !bf->o || !bf->o->bin_obj) {
|
||||
return NULL;
|
||||
}
|
||||
bin = (RBinNXOObj*) bf->o->bin_obj;
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
return bin->methods_list;
|
||||
RBinNXOObj *bin = (RBinNXOObj*) bf->o->bin_obj;
|
||||
return bin? bin->methods_list: NULL;
|
||||
}
|
||||
|
||||
static RList *imports(RBinFile *bf) {
|
||||
|
@ -78,7 +78,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = textsize + (textsize % 4096);
|
||||
ptr->paddr = 8 * 4;
|
||||
ptr->vaddr = ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
ptr->perm = R_PERM_RX; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
// add data segment
|
||||
@ -92,7 +92,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = datasize + (datasize % 4096);
|
||||
ptr->paddr = textsize + (8 * 4);
|
||||
ptr->vaddr = ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE; // rw-
|
||||
ptr->perm = R_PERM_RW;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -108,7 +108,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = symssize + (symssize % 4096);
|
||||
ptr->paddr = datasize + textsize + (8 * 4);
|
||||
ptr->vaddr = ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -123,7 +123,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = spszsize + (spszsize % 4096);
|
||||
ptr->paddr = symssize + datasize + textsize + (8 * 4);
|
||||
ptr->vaddr = ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
@ -138,7 +138,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = pcszsize + (pcszsize % 4096);
|
||||
ptr->paddr = spszsize + symssize + datasize + textsize + (8 * 4);
|
||||
ptr->vaddr = ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE; // r--
|
||||
ptr->perm = R_PERM_R; // r--
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ static bool check_bytes(const ut8 *buf, ut64 length) {
|
||||
*/
|
||||
if (!memcmp (buf, "MZ", 2)) {
|
||||
if (!memcmp (buf+idx, "PE", 2) &&
|
||||
!memcmp (buf+idx+0x18, "\x0b\x01", 2)) {
|
||||
!memcmp (buf + idx + 0x18, "\x0b\x01", 2)) {
|
||||
return true;
|
||||
}
|
||||
// TODO: Add one more indicator, to prevent false positives
|
||||
|
@ -185,28 +185,22 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->paddr = sections[i].paddr;
|
||||
ptr->vaddr = sections[i].vaddr + ba;
|
||||
ptr->add = true;
|
||||
ptr->srwx = 0;
|
||||
if (R_BIN_PE_SCN_IS_EXECUTABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = 0;
|
||||
if (R_BIN_PE_SCN_IS_EXECUTABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_X;
|
||||
ptr->perm |= R_PERM_R; // implicit
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_WRITABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_WRITABLE;
|
||||
if (R_BIN_PE_SCN_IS_WRITABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_W;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_READABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
} else {
|
||||
//fix those sections that could have been fucked up
|
||||
//if the section does have -x- but not -r- add it
|
||||
if (R_BIN_PE_SCN_IS_EXECUTABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_READABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_R;
|
||||
}
|
||||
if (R_BIN_PE_SCN_IS_SHAREABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_SHAREABLE;
|
||||
// this is causing may tests to fail because rx != srx
|
||||
if (R_BIN_PE_SCN_IS_SHAREABLE (sections[i].perm)) {
|
||||
ptr->perm |= R_PERM_SHAR;
|
||||
}
|
||||
#define X 1
|
||||
#define ROW (4 | 2)
|
||||
if (ptr->srwx & ROW && !(ptr->srwx & X) && ptr->size > 0) {
|
||||
if ((ptr->perm & R_PERM_RW) && !(ptr->perm & R_PERM_X) && ptr->size > 0) {
|
||||
if (!strcmp (ptr->name, ".rsrc") ||
|
||||
!strcmp (ptr->name, ".data") ||
|
||||
!strcmp (ptr->name, ".rdata")) {
|
||||
|
@ -97,8 +97,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ut64 textsize = UT64_MAX;
|
||||
RList *ret = NULL;
|
||||
RBinSection *ptr = NULL;
|
||||
PebbleAppInfo pai;
|
||||
memset (&pai, 0, sizeof (pai));
|
||||
PebbleAppInfo pai = {{0}};
|
||||
if (!r_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof(pai))) {
|
||||
eprintf ("Truncated Header\n");
|
||||
return NULL;
|
||||
@ -114,7 +113,7 @@ static RList* sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "relocs");
|
||||
ptr->vsize = ptr->size = pai.num_reloc_entries * sizeof (ut32);
|
||||
ptr->vaddr = ptr->paddr = pai.reloc_list_start;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE;
|
||||
ptr->perm = R_PERM_RW;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
if (ptr->vaddr < textsize) {
|
||||
@ -128,7 +127,7 @@ static RList* sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "symtab");
|
||||
ptr->vsize = ptr->size = 0;
|
||||
ptr->vaddr = ptr->paddr = pai.sym_table_addr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
if (ptr->vaddr < textsize) {
|
||||
@ -141,8 +140,7 @@ static RList* sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "text");
|
||||
ptr->vaddr = ptr->paddr = 0x80;
|
||||
ptr->vsize = ptr->size = textsize - ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE |
|
||||
R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -152,7 +150,7 @@ static RList* sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "header");
|
||||
ptr->vsize = ptr->size = sizeof (PebbleAppInfo);
|
||||
ptr->vaddr = ptr->paddr = 0;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
|
@ -70,7 +70,7 @@ static RList* sections(RBinFile* bf) {
|
||||
sect->size = sz - PSXEXE_TEXTSECTION_OFFSET;
|
||||
sect->vaddr = psxheader.t_addr;
|
||||
sect->vsize = psxheader.t_size;
|
||||
sect->srwx = R_BIN_SCN_EXECUTABLE | R_BIN_SCN_READABLE;
|
||||
sect->perm = R_PERM_RX;
|
||||
sect->add = true;
|
||||
sect->has_strings = true;
|
||||
|
||||
|
@ -90,7 +90,7 @@ static void addrom(RList *ret, const char *name, int i, ut64 paddr, ut64 vaddr,
|
||||
ptr->paddr = paddr;
|
||||
ptr->vaddr = vaddr;
|
||||
ptr->size = ptr->vsize = size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ static RList *sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "vtable");
|
||||
ptr->paddr = ptr->vaddr = 0;
|
||||
ptr->size = ptr->vsize = 0x100;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -269,7 +269,7 @@ static RList *sections(RBinFile *bf) {
|
||||
strcpy (ptr->name, "header");
|
||||
ptr->paddr = ptr->vaddr = 0x100;
|
||||
ptr->size = ptr->vsize = sizeof (SMD_Header);
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -285,7 +285,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vaddr += baddr;
|
||||
}
|
||||
ptr->size = ptr->vsize = bf->buf->length - ptr->paddr;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
return ret;
|
||||
|
@ -61,7 +61,7 @@ static RList* sections(RBinFile *bf) {
|
||||
ptr->size = RAM_SIZE;
|
||||
ptr->vaddr = 0x0;
|
||||
ptr->vsize = RAM_SIZE;
|
||||
ptr->srwx = R_BIN_SCN_READABLE;
|
||||
ptr->perm = R_PERM_R;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
return ret;
|
||||
|
@ -117,19 +117,19 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->vsize = sections[i].vsize;
|
||||
ptr->paddr = sections[i].paddr;
|
||||
ptr->vaddr = sections[i].vaddr;
|
||||
ptr->srwx = 0;
|
||||
ptr->perm = 0;
|
||||
ptr->add = true;
|
||||
if (R_BIN_TE_SCN_IS_EXECUTABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm |= R_PERM_X;
|
||||
}
|
||||
if (R_BIN_TE_SCN_IS_WRITABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_WRITABLE;
|
||||
ptr->perm |= R_PERM_W;
|
||||
}
|
||||
if (R_BIN_TE_SCN_IS_READABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_READABLE;
|
||||
ptr->perm |= R_PERM_R;
|
||||
}
|
||||
if (R_BIN_TE_SCN_IS_SHAREABLE (sections[i].flags)) {
|
||||
ptr->srwx |= R_BIN_SCN_SHAREABLE;
|
||||
ptr->perm |= R_PERM_SHAR;
|
||||
}
|
||||
/* All TE files have _TEXT_RE section, which is 16-bit, because of
|
||||
* CPU start in this mode */
|
||||
|
@ -115,7 +115,7 @@ static RList *mem(RBinFile *bf) {
|
||||
}
|
||||
RList *ret;
|
||||
RBinMem *m;
|
||||
if (!(ret = r_list_new())) {
|
||||
if (!(ret = r_list_new ())) {
|
||||
return NULL;
|
||||
}
|
||||
ret->free = free;
|
||||
@ -161,7 +161,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 8; // (8k)
|
||||
ptr->vaddr = 0xa000;
|
||||
ptr->vsize = 1024 * 8; // BASIC size (8k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -176,7 +176,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 8; // (8k)
|
||||
ptr->vaddr = 0xe000;
|
||||
ptr->vsize = 1024 * 8; // KERNAL size (8k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -194,7 +194,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 28; // (28k)
|
||||
ptr->vaddr = 0x4000;
|
||||
ptr->vsize = 1024 * 28; // BASIC size (28k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -210,7 +210,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 4; // (4k)
|
||||
ptr->vaddr = 0xb000;
|
||||
ptr->vsize = 1024 * 4; // BASIC size (4k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -225,7 +225,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 4; // (4k)
|
||||
ptr->vaddr = 0xc000;
|
||||
ptr->vsize = 1024 * 4; // BASIC size (4k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -240,7 +240,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = 1024 * 8; // (8k)
|
||||
ptr->vaddr = 0xe000;
|
||||
ptr->vsize = 1024 * 8; // KERNAL size (8k)
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -261,7 +261,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = size;
|
||||
ptr->vaddr = 0x0;
|
||||
ptr->vsize = size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
} else {
|
||||
@ -278,7 +278,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = size;
|
||||
ptr->vaddr = 0x0;
|
||||
ptr->vsize = size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
|
||||
@ -290,7 +290,7 @@ static RList* sections(RBinFile* bf) {
|
||||
ptr->size = size;
|
||||
ptr->vaddr = 0x0;
|
||||
ptr->vsize = size;
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_WRITABLE | R_BIN_SCN_EXECUTABLE;
|
||||
ptr->perm = R_PERM_RWX;
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static RList *sections(RBinFile *bf) {
|
||||
ptr->paddr = sec->offset;
|
||||
ptr->add = true;
|
||||
// TODO permissions
|
||||
ptr->srwx = 0;
|
||||
ptr->perm = 0;
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
return ret;
|
||||
|
@ -152,12 +152,12 @@ static RList *sections(RBinFile *bf) {
|
||||
item->vsize = sect[i].vsize;
|
||||
item->add = true;
|
||||
|
||||
item->srwx = R_BIN_SCN_READABLE;
|
||||
item->perm = R_PERM_R;
|
||||
if (sect[i].flags & SECT_FLAG_X) {
|
||||
item->srwx |= R_BIN_SCN_EXECUTABLE;
|
||||
item->perm |= R_PERM_X;
|
||||
}
|
||||
if (sect[i].flags & SECT_FLAG_W) {
|
||||
item->srwx |= R_BIN_SCN_WRITABLE;
|
||||
item->perm |= R_PERM_W;
|
||||
}
|
||||
r_list_append (ret, item);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ static RList *sections(RBinFile *bf) {
|
||||
text->vsize = text->size;
|
||||
text->paddr = N64_ROM_START;
|
||||
text->vaddr = baddr (bf);
|
||||
text->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE; // r-x
|
||||
text->perm = R_PERM_RX;
|
||||
text->add = true;
|
||||
r_list_append (ret, text);
|
||||
return ret;
|
||||
|
40
libr/bp/bp.c
40
libr/bp/bp.c
@ -103,17 +103,17 @@ static inline bool inRange(RBreakpointItem *b, ut64 addr) {
|
||||
return (addr >= b->addr && addr < (b->addr + b->size));
|
||||
}
|
||||
|
||||
static inline bool matchProt(RBreakpointItem *b, int rwx) {
|
||||
return (!rwx || (rwx && b->rwx));
|
||||
static inline bool matchProt(RBreakpointItem *b, int perm) {
|
||||
return (!perm || (perm && b->perm));
|
||||
}
|
||||
|
||||
R_API RBreakpointItem *r_bp_get_in(RBreakpoint *bp, ut64 addr, int rwx) {
|
||||
R_API RBreakpointItem *r_bp_get_in(RBreakpoint *bp, ut64 addr, int perm) {
|
||||
RBreakpointItem *b;
|
||||
RListIter *iter;
|
||||
r_list_foreach (bp->bps, iter, b) {
|
||||
// eprintf ("---ataddr--- 0x%08"PFMT64x" %d %d %x\n", b->addr, b->size, b->recoil, b->rwx);
|
||||
// Check addr within range and provided rwx matches (or null)
|
||||
if (inRange (b, addr) && matchProt (b, rwx)) {
|
||||
// eprintf ("---ataddr--- 0x%08"PFMT64x" %d %d %x\n", b->addr, b->size, b->recoil, b->perm);
|
||||
// Check addr within range and provided perm matches (or null)
|
||||
if (inRange (b, addr) && matchProt (b, perm)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
@ -155,13 +155,13 @@ static void unlinkBreakpoint(RBreakpoint *bp, RBreakpointItem *b) {
|
||||
}
|
||||
|
||||
/* TODO: detect overlapping of breakpoints */
|
||||
static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, int size, int hw, int rwx) {
|
||||
static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, int size, int hw, int perm) {
|
||||
int ret;
|
||||
RBreakpointItem *b;
|
||||
if (addr == UT64_MAX || size < 1) {
|
||||
return NULL;
|
||||
}
|
||||
if (r_bp_get_in (bp, addr, rwx)) {
|
||||
if (r_bp_get_in (bp, addr, perm)) {
|
||||
eprintf ("Breakpoint already set at this address.\n");
|
||||
return NULL;
|
||||
}
|
||||
@ -169,7 +169,7 @@ static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr,
|
||||
b->addr = addr + bp->delta;
|
||||
b->size = size;
|
||||
b->enabled = true;
|
||||
b->rwx = rwx;
|
||||
b->perm = perm;
|
||||
b->hw = hw;
|
||||
// NOTE: for hw breakpoints there are no bytes to save/restore
|
||||
if (!hw) {
|
||||
@ -201,12 +201,12 @@ static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr,
|
||||
return b;
|
||||
}
|
||||
|
||||
R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int rwx) {
|
||||
R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int rwx) {
|
||||
R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm) {
|
||||
RBreakpointItem *item;
|
||||
ut8 *bytes;
|
||||
if (size < 1) {
|
||||
@ -219,13 +219,13 @@ R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int rwx
|
||||
if (bp->iob.read_at) {
|
||||
bp->iob.read_at (bp->iob.io, addr, bytes, size);
|
||||
}
|
||||
item = r_bp_add (bp, bytes, addr, size, R_BP_TYPE_SW, rwx);
|
||||
item = r_bp_add (bp, bytes, addr, size, R_BP_TYPE_SW, perm);
|
||||
free (bytes);
|
||||
return item;
|
||||
}
|
||||
|
||||
R_API RBreakpointItem* r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int rwx) {
|
||||
return r_bp_add (bp, NULL, addr, size, R_BP_TYPE_HW, rwx);
|
||||
R_API RBreakpointItem* r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm) {
|
||||
return r_bp_add (bp, NULL, addr, size, R_BP_TYPE_HW, perm);
|
||||
}
|
||||
|
||||
R_API int r_bp_del_all(RBreakpoint *bp) {
|
||||
@ -284,9 +284,9 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) {
|
||||
" %d %c%c%c %s %s %s cmd=\"%s\" cond=\"%s\" " \
|
||||
"name=\"%s\" module=\"%s\"\n",
|
||||
b->addr, b->addr + b->size, b->size,
|
||||
((b->rwx & R_BP_PROT_READ) | (b->rwx & R_BP_PROT_ACCESS)) ? 'r' : '-',
|
||||
((b->rwx & R_BP_PROT_WRITE)| (b->rwx & R_BP_PROT_ACCESS)) ? 'w' : '-',
|
||||
(b->rwx & R_BP_PROT_EXEC) ? 'x' : '-',
|
||||
((b->perm & R_BP_PROT_READ) | (b->perm & R_BP_PROT_ACCESS)) ? 'r' : '-',
|
||||
((b->perm & R_BP_PROT_WRITE)| (b->perm & R_BP_PROT_ACCESS)) ? 'w' : '-',
|
||||
(b->perm & R_BP_PROT_EXEC) ? 'x' : '-',
|
||||
b->hw ? "hw": "sw",
|
||||
b->trace ? "trace" : "break",
|
||||
b->enabled ? "enabled" : "disabled",
|
||||
@ -316,9 +316,9 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) {
|
||||
"\"cond\":\"%s\"}",
|
||||
iter->p ? "," : "",
|
||||
b->addr, b->size,
|
||||
(b->rwx & R_BP_PROT_READ) ? 'r' : '-',
|
||||
(b->rwx & R_BP_PROT_WRITE) ? 'w' : '-',
|
||||
(b->rwx & R_BP_PROT_EXEC) ? 'x' : '-',
|
||||
(b->perm & R_BP_PROT_READ) ? 'r' : '-',
|
||||
(b->perm & R_BP_PROT_WRITE) ? 'w' : '-',
|
||||
(b->perm & R_BP_PROT_EXEC) ? 'x' : '-',
|
||||
b->hw ? "true" : "false",
|
||||
b->trace ? "true" : "false",
|
||||
b->enabled ? "true" : "false",
|
||||
|
@ -8,12 +8,12 @@ static void r_bp_watch_add_hw(RBreakpoint *bp, RBreakpointItem *b) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int rw) {
|
||||
R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int perm) {
|
||||
RBreakpointItem *b;
|
||||
if (addr == UT64_MAX || size < 1) {
|
||||
return NULL;
|
||||
}
|
||||
if (r_bp_get_in (bp, addr, rw)) {
|
||||
if (r_bp_get_in (bp, addr, perm)) {
|
||||
eprintf ("Breakpoint already set at this address.\n");
|
||||
return NULL;
|
||||
}
|
||||
@ -21,7 +21,7 @@ R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int
|
||||
b->addr = addr + bp->delta;
|
||||
b->size = size;
|
||||
b->enabled = true;
|
||||
b->rwx = rw;
|
||||
b->perm = perm;
|
||||
b->hw = hw;
|
||||
if (hw) {
|
||||
r_bp_watch_add_hw (bp, b);
|
||||
|
@ -98,8 +98,8 @@ static bool iscodesection(RCore *core, ut64 addr) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// BSS return (s && s->flags & R_IO_WRITE)? 0: 1;
|
||||
// Cstring return (s && s->flags & R_IO_EXEC)? 1: 0;
|
||||
// BSS return (s && s->flags & R_PERM_W)? 0: 1;
|
||||
// Cstring return (s && s->flags & R_PERM_X)? 1: 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -227,13 +227,13 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) {
|
||||
types |= R_ANAL_ADDR_TYPE_LIBRARY;
|
||||
}
|
||||
}
|
||||
if (map->perm & R_IO_EXEC) {
|
||||
if (map->perm & R_PERM_X) {
|
||||
types |= R_ANAL_ADDR_TYPE_EXEC;
|
||||
}
|
||||
if (map->perm & R_IO_READ) {
|
||||
if (map->perm & R_PERM_R) {
|
||||
types |= R_ANAL_ADDR_TYPE_READ;
|
||||
}
|
||||
if (map->perm & R_IO_WRITE) {
|
||||
if (map->perm & R_PERM_W) {
|
||||
types |= R_ANAL_ADDR_TYPE_WRITE;
|
||||
}
|
||||
// find function
|
||||
@ -247,7 +247,7 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int _rwx = -1;
|
||||
int _perm = -1;
|
||||
RIOSection *ios;
|
||||
SdbListIter *iter;
|
||||
if (core->io) {
|
||||
@ -255,7 +255,7 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) {
|
||||
ls_foreach (core->io->sections, iter, ios) {
|
||||
if (addr >= ios->vaddr && addr < (ios->vaddr + ios->vsize)) {
|
||||
// sections overlap, so we want to get the one with lower perms
|
||||
_rwx = (_rwx != -1) ? R_MIN (_rwx, ios->flags) : ios->flags;
|
||||
_perm = (_perm != -1) ? R_MIN (_perm, ios->perm) : ios->perm;
|
||||
// TODO: we should identify which maps come from the program or other
|
||||
//types |= R_ANAL_ADDR_TYPE_PROGRAM;
|
||||
// find function those sections should be created by hand or esil init
|
||||
@ -268,14 +268,14 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_rwx != -1) {
|
||||
if (_rwx & R_IO_EXEC) {
|
||||
if (_perm != -1) {
|
||||
if (_perm & R_PERM_X) {
|
||||
types |= R_ANAL_ADDR_TYPE_EXEC;
|
||||
}
|
||||
if (_rwx & R_IO_READ) {
|
||||
if (_perm & R_PERM_R) {
|
||||
types |= R_ANAL_ADDR_TYPE_READ;
|
||||
}
|
||||
if (_rwx & R_IO_WRITE) {
|
||||
if (_perm & R_PERM_W) {
|
||||
types |= R_ANAL_ADDR_TYPE_WRITE;
|
||||
}
|
||||
}
|
||||
@ -527,7 +527,7 @@ static int r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int refd
|
||||
}
|
||||
r_io_read_at (core->io, ref->addr, buf, bufsz);
|
||||
|
||||
if (sec->flags & R_IO_EXEC &&
|
||||
if (sec->perm & R_PERM_X &&
|
||||
r_anal_check_fcn (core->anal, buf, bufsz, ref->addr, sec->vaddr,
|
||||
sec->vaddr + sec->vsize)) {
|
||||
if (core->anal->limit) {
|
||||
@ -794,7 +794,7 @@ static int core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth
|
||||
ut64 addr = fcn->addr + r_anal_fcn_size (fcn);
|
||||
RIOSection *sect = r_io_section_vget (core->io, addr);
|
||||
// only get next if found on an executable section
|
||||
if (!sect || (sect && sect->flags & 1)) {
|
||||
if (!sect || (sect && sect->perm & R_PERM_X)) {
|
||||
for (i = 0; i < nexti; i++) {
|
||||
if (next[i] == addr) {
|
||||
break;
|
||||
@ -860,7 +860,7 @@ error:
|
||||
if (fcn && has_next) {
|
||||
ut64 newaddr = fcn->addr + r_anal_fcn_size (fcn);
|
||||
RIOSection *sect = r_io_section_vget (core->io, newaddr);
|
||||
if (!sect || (sect && (sect->flags & 1))) {
|
||||
if (!sect || (sect && (sect->perm & R_PERM_X))) {
|
||||
next = next_append (next, &nexti, newaddr);
|
||||
for (i = 0; i < nexti; i++) {
|
||||
if (!next[i]) {
|
||||
@ -3195,7 +3195,7 @@ R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad) {
|
||||
at = from;
|
||||
while (at < to && !r_cons_is_breaked ()) {
|
||||
int i = 0, ret = bsz;
|
||||
if (!r_io_is_valid_offset (core->io, at, R_IO_EXEC)) {
|
||||
if (!r_io_is_valid_offset (core->io, at, R_PERM_X)) {
|
||||
break;
|
||||
}
|
||||
(void)r_io_read_at (core->io, at, buf, bsz);
|
||||
@ -3441,8 +3441,8 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6
|
||||
for (at = from; at < to; at += step) {
|
||||
RIOSection *sec = r_io_section_get (core->io, at);
|
||||
piece = (at - from) / step;
|
||||
as->block[piece].rwx = sec ? sec->flags :
|
||||
(core->io->desc ? core->io->desc->flags: 0);
|
||||
as->block[piece].perm = sec ? sec->perm:
|
||||
(core->io->desc ? core->io->desc->perm: 0);
|
||||
}
|
||||
// iter all flags
|
||||
r_list_foreach (core->flags->flags, iter, f) {
|
||||
|
@ -481,7 +481,7 @@ static int is_executable(RBinObject *obj) {
|
||||
return true;
|
||||
}
|
||||
r_list_foreach (obj->sections, it, sec) {
|
||||
if (R_BIN_SCN_EXECUTABLE & sec->srwx) {
|
||||
if (sec->perm & R_PERM_X) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1393,7 +1393,7 @@ static void add_metadata(RCore *r, RBinReloc *reloc, ut64 addr, int mode) {
|
||||
}
|
||||
|
||||
section = r_io_section_vget (r->io, addr);
|
||||
if (!section || section->flags & R_IO_EXEC) {
|
||||
if (!section || section->perm & R_PERM_X) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2223,7 +2223,7 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
|
||||
int va_sect = va;
|
||||
ut64 addr;
|
||||
|
||||
if (va && !(section->srwx & R_BIN_SCN_READABLE)) {
|
||||
if (va && !(section->perm & R_PERM_R)) {
|
||||
va_sect = VA_NOREBASE;
|
||||
}
|
||||
addr = rva (r->bin, section->paddr, section->vaddr, va_sect);
|
||||
@ -2246,16 +2246,16 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
|
||||
continue;
|
||||
}
|
||||
|
||||
if (section->srwx & R_BIN_SCN_SHAREABLE) {
|
||||
if (section->perm & R_PERM_SHAR) {
|
||||
perms[0] = 's';
|
||||
}
|
||||
if (section->srwx & R_BIN_SCN_READABLE) {
|
||||
if (section->perm & R_PERM_R) {
|
||||
perms[1] = 'r';
|
||||
}
|
||||
if (section->srwx & R_BIN_SCN_WRITABLE) {
|
||||
if (section->perm & R_PERM_W) {
|
||||
perms[2] = 'w';
|
||||
}
|
||||
if (section->srwx & R_BIN_SCN_EXECUTABLE) {
|
||||
if (section->perm & R_PERM_X) {
|
||||
perms[3] = 'x';
|
||||
}
|
||||
|
||||
@ -2317,10 +2317,10 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
|
||||
}
|
||||
if (section->add) {
|
||||
str = r_str_newf ("%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT32u".%s.%"PFMT32u".%d",
|
||||
section->paddr, addr, section->size, section->vsize, section->srwx, section->name, r->bin->cur->id, fd);
|
||||
section->paddr, addr, section->size, section->vsize, section->perm, section->name, r->bin->cur->id, fd);
|
||||
if (!ht_find (dup_chk_ht, str, NULL) && r_io_section_add (r->io, section->paddr, addr,
|
||||
section->size, section->vsize,
|
||||
section->srwx, section->name,
|
||||
section->perm, section->name,
|
||||
r->bin->cur->id, fd)) {
|
||||
ht_insert (dup_chk_ht, str, NULL);
|
||||
}
|
||||
@ -2363,7 +2363,7 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
|
||||
r_cons_printf ("%s{\"name\":\"%s\","
|
||||
"\"size\":%"PFMT64d","
|
||||
"\"vsize\":%"PFMT64d","
|
||||
"\"flags\":\"%s\","
|
||||
"\"perm\":\"%s\","
|
||||
"%s"
|
||||
"\"paddr\":%"PFMT64d","
|
||||
"\"vaddr\":%"PFMT64d"}",
|
||||
@ -2386,11 +2386,11 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
|
||||
if (r->bin->prefix) {
|
||||
r_cons_printf ("S 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s.%s %d\n",
|
||||
section->paddr, addr, section->size, section->vsize,
|
||||
r->bin->prefix, section->name, (int)section->srwx);
|
||||
r->bin->prefix, section->name, (int)section->perm);
|
||||
} else {
|
||||
r_cons_printf ("S 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s %d\n",
|
||||
section->paddr, addr, section->size, section->vsize,
|
||||
section->name, (int)section->srwx);
|
||||
section->name, (int)section->perm);
|
||||
|
||||
}
|
||||
if (section->arch || section->bits) {
|
||||
|
@ -1529,9 +1529,9 @@ static int cb_io_cache_read(void *user, void *data) {
|
||||
RCore *core = (RCore *)user;
|
||||
RConfigNode *node = (RConfigNode *)data;
|
||||
if (node->i_value) {
|
||||
core->io->cached |= R_IO_READ;
|
||||
core->io->cached |= R_PERM_R;
|
||||
} else {
|
||||
core->io->cached &= ~R_IO_READ;
|
||||
core->io->cached &= ~R_PERM_R;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1540,9 +1540,9 @@ static int cb_io_cache_write(void *user, void *data) {
|
||||
RCore *core = (RCore *)user;
|
||||
RConfigNode *node = (RConfigNode *)data;
|
||||
if (node->i_value) {
|
||||
core->io->cached |= R_IO_WRITE;
|
||||
core->io->cached |= R_PERM_W;
|
||||
} else {
|
||||
core->io->cached &= ~R_IO_WRITE;
|
||||
core->io->cached &= ~R_PERM_W;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
perm = 7;
|
||||
} else {
|
||||
if (!perm) {
|
||||
perm = 4; //R_IO_READ;
|
||||
perm = 4; //R_PERM_R;
|
||||
}
|
||||
}
|
||||
if (!ofilepath) {
|
||||
@ -79,7 +79,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
odesc = NULL;
|
||||
// core->file = file;
|
||||
eprintf ("File %s reopened in %s mode\n", path,
|
||||
(perm & R_IO_WRITE)? "read-write": "read-only");
|
||||
(perm & R_PERM_W)? "read-write": "read-only");
|
||||
|
||||
if (loadbin && (loadbin == 2 || had_rbin_info)) {
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
@ -99,7 +99,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
eprintf ("r_core_file_reopen: Cannot reopen file: %s with perms 0x%04x,"
|
||||
" attempting to open read-only.\n", path, perm);
|
||||
// lower it down back
|
||||
//ofile = r_core_file_open (core, path, R_IO_READ, addr);
|
||||
//ofile = r_core_file_open (core, path, R_PERM_R, addr);
|
||||
r_core_file_set_by_file (core, ofile);
|
||||
} else {
|
||||
eprintf ("Cannot reopen\n");
|
||||
@ -568,7 +568,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
|
||||
if (plugin && plugin->name) {
|
||||
if (!strncmp (plugin->name, "any", 3)) {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
|
||||
// set use of raw strings
|
||||
//r_config_set (r->config, "bin.rawstr", "true");
|
||||
// r_config_set_i (r->config, "io.va", false);
|
||||
@ -584,7 +584,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
}
|
||||
//workaround to map correctly malloc:// and raw binaries
|
||||
if (r_io_desc_is_dbg (desc) || (!obj->sections || !va)) {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
|
||||
}
|
||||
|
||||
RBinInfo *info = obj->info;
|
||||
@ -598,7 +598,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
|
||||
if (binfile) {
|
||||
r_core_bin_set_arch_bits (r, binfile->file,
|
||||
r_config_get (r->config, "asm.arch"),
|
||||
@ -606,7 +606,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
}
|
||||
}
|
||||
if (desc && r_config_get_i (r->config, "io.exec")) {
|
||||
desc->flags |= R_IO_EXEC;
|
||||
desc->perm |= R_PERM_X;
|
||||
}
|
||||
if (plugin && plugin->name && !strcmp (plugin->name, "dex")) {
|
||||
r_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ;"
|
||||
@ -743,7 +743,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 lo
|
||||
}
|
||||
//if not flags was passed open it with -r--
|
||||
if (!flags) {
|
||||
flags = R_IO_READ;
|
||||
flags = R_PERM_R;
|
||||
}
|
||||
r->io->bits = r->assembler->bits; // TODO: we need an api for this
|
||||
RIODesc *fd = r_io_open_nomap (r->io, file, flags, 0644);
|
||||
@ -755,7 +755,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 lo
|
||||
}
|
||||
}
|
||||
if (!fd) {
|
||||
if (flags & R_IO_WRITE) {
|
||||
if (flags & R_PERM_W) {
|
||||
// flags |= R_IO_CREAT;
|
||||
if (!(fd = r_io_open_nomap (r->io, file, flags, 0644))) {
|
||||
goto beach;
|
||||
@ -928,7 +928,7 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
PFMT64d ",\"writable\":%s,\"size\":%d}%s",
|
||||
core->io->desc->fd == f->fd ? "true": "false",
|
||||
(int) f->fd, desc->uri, (ut64) from,
|
||||
desc->flags & R_IO_WRITE? "true": "false",
|
||||
desc->perm & R_PERM_W? "true": "false",
|
||||
(int) r_io_desc_size (desc),
|
||||
iter->n? ",": "");
|
||||
break;
|
||||
@ -988,7 +988,7 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
core->io->desc->fd == f->fd ? '*': '-',
|
||||
count,
|
||||
(int) f->fd, desc->uri, (ut64) from,
|
||||
desc->flags & R_IO_WRITE? "rw": "r",
|
||||
desc->perm & R_PERM_W? "rw": "r",
|
||||
r_io_desc_size (desc));
|
||||
}
|
||||
break;
|
||||
@ -1039,7 +1039,7 @@ R_API int r_core_file_binlist(RCore *core) {
|
||||
if (cf) {
|
||||
r_cons_printf ("%c %d %s ; %s\n",
|
||||
core->io->desc == desc ? '*': '-',
|
||||
fd, desc->uri, desc->flags & R_IO_WRITE? "rw": "r");
|
||||
fd, desc->uri, desc->perm & R_PERM_W? "rw": "r");
|
||||
}
|
||||
}
|
||||
r_core_file_set_by_file (core, cur_cf);
|
||||
|
@ -3121,7 +3121,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@
|
||||
ut64 addr = sec->vaddr;
|
||||
ut64 size = sec->vsize;
|
||||
// TODO:
|
||||
//if (R_BIN_SCN_EXECUTABLE & sec->srwx) {
|
||||
//if (R_BIN_SCN_EXECUTABLE & sec->perm) {
|
||||
// continue;
|
||||
//}
|
||||
r_core_seek_size (core, addr, size);
|
||||
|
@ -3420,7 +3420,7 @@ repeat:
|
||||
*prev_addr = addr;
|
||||
}
|
||||
if (esil->exectrap) {
|
||||
if (!r_io_is_valid_offset (core->io, addr, R_IO_EXEC)) {
|
||||
if (!r_io_is_valid_offset (core->io, addr, R_PERM_X)) {
|
||||
esil->trap = R_ANAL_TRAP_EXEC_ERR;
|
||||
esil->trap_code = addr;
|
||||
eprintf ("[ESIL] Trap, trying to execute on non-executable memory\n");
|
||||
@ -3821,9 +3821,8 @@ static void cmd_esil_mem(RCore *core, const char *input) {
|
||||
}
|
||||
|
||||
snprintf (uri, sizeof (uri), "malloc://%d", (int)size);
|
||||
esil->stack_fd = r_io_fd_open (core->io, uri, R_IO_RW, 0);
|
||||
if (!(stack_map = r_io_map_add (core->io, esil->stack_fd,
|
||||
R_IO_RW, 0LL, addr, size))) {
|
||||
esil->stack_fd = r_io_fd_open (core->io, uri, R_PERM_RW, 0);
|
||||
if (!(stack_map = r_io_map_add (core->io, esil->stack_fd, R_PERM_RW, 0LL, addr, size))) {
|
||||
r_io_fd_close (core->io, esil->stack_fd);
|
||||
eprintf ("Cannot create map for tha stack, fd %d got closed again\n", esil->stack_fd);
|
||||
esil->stack_fd = 0;
|
||||
@ -4928,7 +4927,7 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) {
|
||||
if (!len) {
|
||||
// ignore search.in to avoid problems. analysis != search
|
||||
RIOSection *sec = r_io_section_vget (core->io, addr);
|
||||
if (sec && sec->flags & 1) {
|
||||
if (sec && (sec->perm & R_PERM_X)) {
|
||||
// search in current section
|
||||
if (sec->size > binfile->size) {
|
||||
addr = sec->vaddr;
|
||||
@ -5011,7 +5010,7 @@ static void cmd_anal_blocks(RCore *core, const char *input) {
|
||||
#if 0
|
||||
ls_foreach (core->io->sections, iter, s) {
|
||||
/* is executable */
|
||||
if (!(s->flags & R_IO_EXEC)) {
|
||||
if (!(s->flags & R_PERM_X)) {
|
||||
continue;
|
||||
}
|
||||
min = s->vaddr;
|
||||
@ -5031,7 +5030,7 @@ static void cmd_anal_blocks(RCore *core, const char *input) {
|
||||
}
|
||||
#endif
|
||||
if (!arg) {
|
||||
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, NULL, "anal");
|
||||
RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal");
|
||||
RListIter *iter;
|
||||
RIOMap* map;
|
||||
r_list_foreach (list, iter, map) {
|
||||
@ -5158,7 +5157,7 @@ static void cmd_anal_calls(RCore *core, const char *input, bool only_print_flag)
|
||||
m->itv.size = len;
|
||||
r_list_append (ranges, m);
|
||||
} else {
|
||||
ranges = r_core_get_boundaries_prot (core, R_IO_EXEC, NULL, "anal");
|
||||
ranges = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal");
|
||||
}
|
||||
}
|
||||
r_cons_break_push (NULL, NULL);
|
||||
@ -6686,7 +6685,7 @@ R_API int r_core_anal_refs(RCore *core, const char *input) {
|
||||
to = map->addr_end;
|
||||
}
|
||||
} else {
|
||||
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, NULL, "anal");
|
||||
RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal");
|
||||
RListIter *iter;
|
||||
RIOMap* map;
|
||||
r_list_foreach (list, iter, map) {
|
||||
@ -6747,9 +6746,11 @@ static void rowlog_done(RCore *core) {
|
||||
int use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
||||
bool verbose = r_config_get_i (core->config, "scr.prompt");
|
||||
if (verbose) {
|
||||
if (use_color)
|
||||
if (use_color) {
|
||||
eprintf ("\r"Color_GREEN"[x]"Color_RESET" %s\n", oldstr);
|
||||
else eprintf ("\r[x] %s\n", oldstr);
|
||||
} else {
|
||||
eprintf ("\r[x] %s\n", oldstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6761,7 +6762,7 @@ static int compute_coverage(RCore *core) {
|
||||
int cov = 0;
|
||||
r_list_foreach (core->anal->fcns, iter, fcn) {
|
||||
ls_foreach (core->io->sections, iter2, sec) {
|
||||
if (sec->flags & 1) {
|
||||
if (sec->perm & R_PERM_X) {
|
||||
ut64 section_end = sec->vaddr + sec->vsize;
|
||||
ut64 s = r_anal_fcn_realsize (fcn);
|
||||
if (fcn->addr >= sec->vaddr && (fcn->addr + s) < section_end) {
|
||||
@ -6778,7 +6779,7 @@ static int compute_code (RCore* core) {
|
||||
SdbListIter *iter;
|
||||
RIOSection *sec;
|
||||
ls_foreach (core->io->sections, iter, sec) {
|
||||
if (sec->flags & 1) {
|
||||
if (sec->perm & R_PERM_X) {
|
||||
code += sec->vsize;
|
||||
}
|
||||
}
|
||||
@ -7187,7 +7188,7 @@ static int cmd_anal_all(RCore *core, const char *input) {
|
||||
bool hasnext = r_config_get_i (core->config, "anal.hasnext");
|
||||
RListIter *iter;
|
||||
RIOMap* map;
|
||||
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, NULL, "anal");
|
||||
RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal");
|
||||
r_list_foreach (list, iter, map) {
|
||||
r_core_seek (core, map->itv.addr, 1);
|
||||
r_config_set_i (core->config, "anal.hasnext", 1);
|
||||
|
@ -22,7 +22,7 @@ static const char *help_msg_d[] = {
|
||||
"dbt", "[?]", "Display backtrace based on dbg.btdepth and dbg.btalgo",
|
||||
"dc", "[?]", "Continue execution",
|
||||
"dd", "[?]", "File descriptors (!fd in r1)",
|
||||
"de", "[-sc] [rwx] [rm] [e]", "Debug with ESIL (see de?)",
|
||||
"de", "[-sc] [perm] [rm] [e]", "Debug with ESIL (see de?)",
|
||||
"dg", " <file>", "Generate a core-file (WIP)",
|
||||
"dH", " [handler]", "Transplant process to a new handler",
|
||||
"di", "[?]", "Show debugger backend information (See dh)",
|
||||
@ -77,7 +77,7 @@ static const char *help_msg_db[] = {
|
||||
"dbt", "[?]", "Show backtrace. See dbt? for more details",
|
||||
"dbx", " [expr]", "Set expression for bp in current offset",
|
||||
"dbw", " <addr> <r/w/rw>", "Add watchpoint",
|
||||
"drx", " number addr len rwx", "Modify hardware breakpoint",
|
||||
"drx", " number addr len perm", "Modify hardware breakpoint",
|
||||
"drx-", "number", "Clear hardware breakpoint",
|
||||
NULL
|
||||
};
|
||||
@ -157,10 +157,10 @@ static const char *help_msg_dd[] = {
|
||||
};
|
||||
|
||||
static const char *help_msg_de[] = {
|
||||
"Usage:", "de", "[-sc] [rwx] [rm] [expr]",
|
||||
"Usage:", "de", "[-sc] [perm] [rm] [expr]",
|
||||
"de", "", "List esil watchpoints",
|
||||
"de-*", "", "Delete all esil watchpoints",
|
||||
"de", " [rwx] [rm] [addr|reg|from..to]", "Stop on condition",
|
||||
"de", " [perm] [rm] [addr|reg|from..to]", "Stop on condition",
|
||||
"dec", "", "Continue execution until matching expression",
|
||||
"des", "[?] [N]", "Step-in N instructions with esildebug",
|
||||
"desu", " [addr]", "Esildebug until specific address",
|
||||
@ -220,7 +220,7 @@ static const char *help_msg_dm[] = {
|
||||
"dmj", "", "List memmaps in JSON format",
|
||||
"dml", " <file>", "Load contents of file into the current map region (see Sl)",
|
||||
"dmm", "[?][j*]", "List modules (libraries, binaries loaded in memory)",
|
||||
"dmp", "[?] <address> <size> <perms>", "Change page at <address> with <size>, protection <perms> (rwx)",
|
||||
"dmp", "[?] <address> <size> <perms>", "Change page at <address> with <size>, protection <perms> (perm)",
|
||||
"dms", "[?] <id> <mapaddr>", "Take memory snapshot",
|
||||
"dms-", " <id> <mapaddr>", "Restore memory snapshot",
|
||||
"dmS", " [addr|libname] [sectname]", "List sections of target lib",
|
||||
@ -338,7 +338,7 @@ static const char *help_msg_dr[] = {
|
||||
"drt", "[?]", "Show all register types",
|
||||
"drw"," <hexnum>", "Set contents of the register arena",
|
||||
"drx", "[?]", "Show all debug registers",
|
||||
"drx", " idx addr len rwx", "Modify hardware breakpoint",
|
||||
"drx", " idx addr len perm", "Modify hardware breakpoint",
|
||||
"drx-", "number", "Clear hardware breakpoint",
|
||||
".dr", "*", "Include common register values in flags",
|
||||
".dr", "-", "Unflag all registers",
|
||||
@ -1260,7 +1260,7 @@ static int cmd_debug_map_snapshot(RCore *core, const char *input) {
|
||||
r_debug_snap_all (core->dbg, 0);
|
||||
break;
|
||||
case 'w':
|
||||
r_debug_snap_all (core->dbg, R_IO_RW);
|
||||
r_debug_snap_all (core->dbg, R_PERM_RW);
|
||||
break;
|
||||
case 0:
|
||||
case 'j':
|
||||
@ -1612,7 +1612,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
|
||||
case 'd': // "dmd"
|
||||
switch (input[1]) {
|
||||
case 'a': return dump_maps (core, 0, NULL);
|
||||
case 'w': return dump_maps (core, R_IO_RW, NULL);
|
||||
case 'w': return dump_maps (core, R_PERM_RW, NULL);
|
||||
case ' ': return dump_maps (core, -1, input + 2);
|
||||
case 0: return dump_maps (core, -1, NULL);
|
||||
case '?':
|
||||
@ -2335,7 +2335,7 @@ static void cmd_debug_reg(RCore *core, const char *str) {
|
||||
break;
|
||||
case ' ': {
|
||||
char *s = strdup (str+2);
|
||||
char sl, n, rwx;
|
||||
char sl, n, perm;
|
||||
int len;
|
||||
ut64 off;
|
||||
|
||||
@ -2345,18 +2345,18 @@ static void cmd_debug_reg(RCore *core, const char *str) {
|
||||
n = (char)r_num_math (core->num, arg(0));
|
||||
off = r_num_math (core->num, arg(1));
|
||||
len = (int)r_num_math (core->num, arg(2));
|
||||
rwx = (char)r_str_rwx (arg (3));
|
||||
perm = (char)r_str_rwx (arg (3));
|
||||
if (len == -1) {
|
||||
r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false);
|
||||
r_debug_drx_set (core->dbg, n, 0, 0, 0, 0);
|
||||
r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true);
|
||||
} else {
|
||||
r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false);
|
||||
r_debug_drx_set (core->dbg, n, off, len, rwx, 0);
|
||||
r_debug_drx_set (core->dbg, n, off, len, perm, 0);
|
||||
r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true);
|
||||
}
|
||||
} else {
|
||||
eprintf ("|usage: drx n [address] [length] [rwx]\n");
|
||||
eprintf ("|usage: drx n [address] [length] [perm]\n");
|
||||
}
|
||||
free (s);
|
||||
} break;
|
||||
@ -3027,7 +3027,7 @@ static void r_core_cmd_bp(RCore *core, const char *input) {
|
||||
bpi = r_bp_get_at (core->dbg->bp, core->offset);
|
||||
if (bpi) {
|
||||
r_cons_printf ("breakpoint %s %s %s\n",
|
||||
r_str_rwx_i (bpi->rwx),
|
||||
r_str_rwx_i (bpi->perm),
|
||||
bpi->enabled ? "enabled" : "disabled",
|
||||
bpi->name ? bpi->name : "");
|
||||
}
|
||||
@ -3672,26 +3672,26 @@ static void r_core_debug_esil (RCore *core, const char *input) {
|
||||
char *line = strdup (input + 1);
|
||||
char *p, *q;
|
||||
int done = 0;
|
||||
int rwx = 0, dev = 0;
|
||||
int perm = 0, dev = 0;
|
||||
p = strchr (line, ' ');
|
||||
if (p) {
|
||||
*p++ = 0;
|
||||
if (strchr (line, 'r')) rwx |= R_IO_READ;
|
||||
if (strchr (line, 'w')) rwx |= R_IO_WRITE;
|
||||
if (strchr (line, 'x')) rwx |= R_IO_EXEC;
|
||||
if (strchr (line, 'r')) perm |= R_PERM_R;
|
||||
if (strchr (line, 'w')) perm |= R_PERM_W;
|
||||
if (strchr (line, 'x')) perm |= R_PERM_X;
|
||||
q = strchr (p, ' ');
|
||||
if (q) {
|
||||
*q++ = 0;
|
||||
dev = p[0];
|
||||
if (q) {
|
||||
r_debug_esil_watch (core->dbg, rwx, dev, q);
|
||||
r_debug_esil_watch (core->dbg, perm, dev, q);
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
const char *help_de_msg[] = {
|
||||
"Usage:", "de", " [rwx] [reg|mem] [expr]",
|
||||
"Usage:", "de", " [perm] [reg|mem] [expr]",
|
||||
NULL
|
||||
};
|
||||
r_core_cmd_help (core, help_de_msg);
|
||||
|
@ -174,7 +174,7 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
free (escapedFile);
|
||||
}
|
||||
if (dbg) {
|
||||
dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
dbg = R_PERM_WX;
|
||||
}
|
||||
if (desc) {
|
||||
ut64 fsz = r_io_desc_size (desc);
|
||||
@ -187,10 +187,8 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
free (humansz);
|
||||
}
|
||||
}
|
||||
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache ||\
|
||||
desc->flags & R_IO_WRITE ));
|
||||
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (
|
||||
desc->flags & 7 ));
|
||||
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache || desc->perm & R_PERM_W));
|
||||
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (desc->perm & R_PERM_RWX));
|
||||
r_cons_printf (",\"obsz\":%"PFMT64d, (ut64) core->io->desc->obsz);
|
||||
if (desc->referer && *desc->referer) {
|
||||
r_cons_printf (",\"referer\":\"%s\"", desc->referer);
|
||||
@ -211,7 +209,7 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
} else if (desc && mode != R_CORE_BIN_SIMPLE) {
|
||||
//r_cons_printf ("# Core file info\n");
|
||||
if (dbg) {
|
||||
dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
dbg = R_PERM_WX;
|
||||
}
|
||||
if (desc) {
|
||||
pair ("blksz", sdb_fmt ("0x%"PFMT64x, (ut64) core->io->desc->obsz));
|
||||
@ -227,8 +225,8 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
pair ("format", plugin->name);
|
||||
}
|
||||
if (desc) {
|
||||
pair ("iorw", r_str_bool (io_cache || desc->flags & R_IO_WRITE ));
|
||||
pair ("mode", r_str_rwx_i (desc->flags & 7));
|
||||
pair ("iorw", r_str_bool (io_cache || desc->perm & R_PERM_W));
|
||||
pair ("mode", r_str_rwx_i (desc->perm & R_PERM_RWX));
|
||||
}
|
||||
if (binfile && binfile->curxtr) {
|
||||
pair ("packet", binfile->curxtr->name);
|
||||
@ -261,7 +259,7 @@ static int bin_is_executable(RBinObject *obj){
|
||||
return true;
|
||||
}
|
||||
r_list_foreach (obj->sections, it, sec){
|
||||
if (R_BIN_SCN_EXECUTABLE & sec->srwx) {
|
||||
if (sec->perm & R_PERM_X) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ static int cmd_mount(void *data, const char *_input) {
|
||||
if (file) {
|
||||
r_fs_read (core->fs, file, 0, file->size);
|
||||
char *uri = r_str_newf ("malloc://%d", file->size);
|
||||
RIODesc *fd = r_io_open (core->io, uri, R_IO_READ | R_IO_WRITE, 0);
|
||||
RIODesc *fd = r_io_open (core->io, uri, R_PERM_RW, 0);
|
||||
if (fd) {
|
||||
r_io_desc_write (fd, file->data, file->size);
|
||||
}
|
||||
|
@ -217,9 +217,9 @@ static void list_maps_visual(RIO *io, ut64 seek, ut64 len, int width, int use_co
|
||||
ls_foreach_prev (io->maps, iter, s) {
|
||||
if (use_color) {
|
||||
color_end = Color_RESET;
|
||||
if (s->flags & 1) { // exec bit
|
||||
if (s->perm & R_PERM_X) { // exec bit
|
||||
color = Color_GREEN;
|
||||
} else if (s->flags & 2) { // write bit
|
||||
} else if (s->perm & R_PERM_W) { // write bit
|
||||
color = Color_RED;
|
||||
} else {
|
||||
color = "";
|
||||
@ -246,7 +246,7 @@ static void list_maps_visual(RIO *io, ut64 seek, ut64 len, int width, int use_co
|
||||
}
|
||||
io->cb_printf ("| %s0x%08"PFMT64x"%s %s %d %s\n",
|
||||
color, r_itv_end (s->itv), color_end,
|
||||
r_str_rwx_i (s->flags), s->fd, s->name);
|
||||
r_str_rwx_i (s->perm), s->fd, s->name);
|
||||
i++;
|
||||
}
|
||||
/* current seek */
|
||||
@ -287,7 +287,7 @@ static void cmd_open_bin(RCore *core, const char *input) {
|
||||
char *arg = strdup (input + 3);
|
||||
char *filename = strchr (arg, ' ');
|
||||
if (filename) {
|
||||
RIODesc *desc = r_io_open (core->io, filename + 1, R_IO_READ, 0);
|
||||
RIODesc *desc = r_io_open (core->io, filename + 1, R_PERM_R, 0);
|
||||
if (desc) {
|
||||
*filename = 0;
|
||||
ut64 addr = r_num_math (core->num, arg);
|
||||
@ -459,22 +459,22 @@ static void map_list(RIO *io, int mode, RPrint *print, int fd) {
|
||||
}
|
||||
first = false;
|
||||
print->cb_printf ("{\"map\":%i,\"fd\":%d,\"delta\":%"PFMT64u",\"from\":%"PFMT64u
|
||||
",\"to\":%"PFMT64u",\"flags\":\"%s\",\"name\":\"%s\"}", map->id, map->fd,
|
||||
",\"to\":%"PFMT64u",\"perm\":\"%s\",\"name\":\"%s\"}", map->id, map->fd,
|
||||
map->delta, map->itv.addr, r_itv_end (map->itv),
|
||||
r_str_rwx_i (map->flags), (map->name ? map->name : ""));
|
||||
r_str_rwx_i (map->perm), (map->name ? map->name : ""));
|
||||
break;
|
||||
case 1:
|
||||
case '*':
|
||||
case 'r':
|
||||
print->cb_printf ("om %d 0x%"PFMT64x" 0x%"PFMT64x" 0x%"PFMT64x" %s%s%s\n", map->fd,
|
||||
map->itv.addr, map->itv.size, map->delta, r_str_rwx_i(map->flags),
|
||||
map->itv.addr, map->itv.size, map->delta, r_str_rwx_i(map->perm),
|
||||
map->name ? " " : "", map->name ? map->name : "");
|
||||
break;
|
||||
default:
|
||||
print->cb_printf ("%2d fd: %i +0x%08"PFMT64x" 0x%08"PFMT64x
|
||||
" - 0x%08"PFMT64x" %s %s\n", map->id, map->fd,
|
||||
map->delta, map->itv.addr, r_itv_end (map->itv) - 1,
|
||||
r_str_rwx_i (map->flags), (map->name ? map->name : ""));
|
||||
r_str_rwx_i (map->perm), (map->name ? map->name : ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -488,7 +488,7 @@ static void cmd_omfg (RCore *core, const char *input) {
|
||||
RIOMap *map;
|
||||
input = r_str_trim_ro (input);
|
||||
if (input) {
|
||||
int flags = *input
|
||||
int perm = *input
|
||||
? (*input == '+' || *input == '-')
|
||||
? r_str_rwx (input + 1)
|
||||
: r_str_rwx (input)
|
||||
@ -496,17 +496,17 @@ static void cmd_omfg (RCore *core, const char *input) {
|
||||
switch (*input) {
|
||||
case '+':
|
||||
ls_foreach (core->io->maps, iter, map) {
|
||||
map->flags |= flags;
|
||||
map->perm |= perm;
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
ls_foreach (core->io->maps, iter, map) {
|
||||
map->flags &= ~flags;
|
||||
map->perm &= ~perm;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ls_foreach (core->io->maps, iter, map) {
|
||||
map->flags = flags;
|
||||
map->perm = perm;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -525,19 +525,19 @@ static void cmd_omf (RCore *core, const char *input) {
|
||||
// change perms of Nth map
|
||||
*sp++ = 0;
|
||||
int id = r_num_math (core->num, arg);
|
||||
int flags = (*sp)? r_str_rwx (sp): 7;
|
||||
int perm = (*sp)? r_str_rwx (sp): R_PERM_RWX;
|
||||
ls_foreach (core->io->maps, iter, map) {
|
||||
if (map->id == id) {
|
||||
map->flags = flags;
|
||||
map->perm = perm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// change perms of current map
|
||||
int flags = (arg && *arg)? r_str_rwx (arg): 7;
|
||||
int perm = (arg && *arg)? r_str_rwx (arg): R_PERM_RWX;
|
||||
ls_foreach (core->io->maps, iter, map) {
|
||||
if (r_itv_contain (map->itv, core->offset)) {
|
||||
map->flags = flags;
|
||||
map->perm = perm;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -560,7 +560,7 @@ static void cmd_open_map(RCore *core, const char *input) {
|
||||
core->print->cb_printf ("map: %i fd: %i +0x%"PFMT64x" 0x%"PFMT64x
|
||||
" - 0x%"PFMT64x" ; %s : %s\n", map->id, map->fd,
|
||||
map->delta, map->itv.addr, r_itv_end (map->itv),
|
||||
r_str_rwx_i (map->flags), map->name ? map->name : "");
|
||||
r_str_rwx_i (map->perm), map->name ? map->name : "");
|
||||
}
|
||||
break;
|
||||
case 'r': // "omr"
|
||||
@ -676,7 +676,7 @@ static void cmd_open_map(RCore *core, const char *input) {
|
||||
if (!size) {
|
||||
size = r_io_fd_size (core->io, fd);
|
||||
}
|
||||
map = r_io_map_add (core->io, fd, rwx_arg ? rwx : desc->flags, paddr, vaddr, size);
|
||||
map = r_io_map_add (core->io, fd, rwx_arg ? rwx : desc->perm, paddr, vaddr, size);
|
||||
r_io_map_set_name (map, name);
|
||||
}
|
||||
} else {
|
||||
@ -755,7 +755,7 @@ static void cmd_open_map(RCore *core, const char *input) {
|
||||
RIODesc *desc = r_io_desc_get (core->io, fd);
|
||||
if (desc) {
|
||||
ut64 size = r_io_desc_size (desc);
|
||||
map = r_io_map_add (core->io, fd, desc->flags, 0, 0, size);
|
||||
map = r_io_map_add (core->io, fd, desc->perm, 0, 0, size);
|
||||
r_io_map_set_name (map, desc->name);
|
||||
} else {
|
||||
eprintf ("Usage: omm [fd]\n");
|
||||
@ -836,7 +836,7 @@ static bool reopen_in_malloc_cb(void *user, void *data, ut32 id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RIODesc *ndesc = r_io_open_nomap (io, uri, R_IO_RW, 0);
|
||||
RIODesc *ndesc = r_io_open_nomap (io, uri, R_PERM_RW, 0);
|
||||
free (uri);
|
||||
if (!ndesc) {
|
||||
free (buf);
|
||||
@ -926,7 +926,7 @@ static bool desc_list_visual_cb(void *user, void *data, ut32 id) {
|
||||
RIODesc *desc = (RIODesc *)data;
|
||||
ut64 sz = r_io_desc_size (desc);
|
||||
r_cons_printf ("%2d %c %s 0x%08"PFMT64x" ", desc->fd,
|
||||
(desc->io && (desc->io->desc == desc)) ? '*' : '-', r_str_rwx_i (desc->flags), sz);
|
||||
(desc->io && (desc->io->desc == desc)) ? '*' : '-', r_str_rwx_i (desc->perm), sz);
|
||||
int flags = p->flags;
|
||||
p->flags &= ~R_PRINT_FLAGS_HEADER;
|
||||
r_print_progressbar (p, sz * 100 / fdsz, r_cons_get_size (NULL) - 40);
|
||||
@ -968,7 +968,7 @@ static bool desc_list_cb(void *user, void *data, ut32 id) {
|
||||
RIODesc *desc = (RIODesc *)data;
|
||||
p->cb_printf ("%2d %c %s 0x%08"PFMT64x" %s\n", desc->fd,
|
||||
(desc->io && (desc->io->desc == desc)) ? '*' : '-',
|
||||
r_str_rwx_i (desc->flags), r_io_desc_size (desc), desc->uri);
|
||||
r_str_rwx_i (desc->perm), r_io_desc_size (desc), desc->uri);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -981,14 +981,14 @@ static bool desc_list_json_cb(void *user, void *data, ut32 id) {
|
||||
PFMT64d ",\"writable\":%s,\"size\":%" PFMT64d "}%s",
|
||||
(desc->io && (desc->io->desc == desc)) ? "true" : "false",
|
||||
desc->fd, desc->uri, from,
|
||||
(desc->flags & R_IO_WRITE ? "true": "false"),
|
||||
((desc->perm & R_PERM_W) ? "true": "false"),
|
||||
r_io_desc_size (desc), (desc->io->files->top_id == id) ? "" : ",");
|
||||
return true;
|
||||
}
|
||||
|
||||
static int cmd_open(void *data, const char *input) {
|
||||
RCore *core = (RCore*)data;
|
||||
int perms = R_IO_READ;
|
||||
int perms = R_PERM_R;
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
ut64 addr = 0LL;
|
||||
int nowarn = r_config_get_i (core->config, "file.nowarn");
|
||||
@ -1059,7 +1059,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
return 0;
|
||||
} else if (input[1] == '+') { // "on+"
|
||||
write = true;
|
||||
perms |= R_IO_WRITE;
|
||||
perms |= R_PERM_W;
|
||||
if (input[2] != ' ') {
|
||||
eprintf ("Usage: on+ file [addr] [rwx]\n");
|
||||
return 0;
|
||||
@ -1069,7 +1069,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
silence = true;
|
||||
if (input[2] == '+') { // "ons+"
|
||||
write = true;
|
||||
perms |= R_IO_WRITE;
|
||||
perms |= R_PERM_W;
|
||||
if (input[3] != ' ') {
|
||||
eprintf ("Usage: ons+ file [addr] [rwx]\n");
|
||||
return 0;
|
||||
@ -1190,7 +1190,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
return 0;
|
||||
break;
|
||||
case '+': // "o+"
|
||||
perms |= R_IO_WRITE;
|
||||
perms |= R_PERM_W;
|
||||
case 's': // "os"
|
||||
silence = true;
|
||||
case ' ': // "o" "o "
|
||||
@ -1394,7 +1394,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
char *uri = r_str_newf ("malloc://%d", len);
|
||||
ut8 *data = calloc (len, 1);
|
||||
r_io_read_at (core->io, core->offset, data, len);
|
||||
RIODesc *fd = r_io_open (core->io, uri, R_IO_READ | R_IO_WRITE, 0);
|
||||
RIODesc *fd = r_io_open (core->io, uri, R_PERM_R | R_PERM_W, 0);
|
||||
if (fd) {
|
||||
r_io_desc_write (fd, data, len);
|
||||
}
|
||||
@ -1434,7 +1434,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
r_core_cmd_help (core, help_msg_oonn);
|
||||
break;
|
||||
}
|
||||
perms = (input[3] == '+')? R_IO_READ|R_IO_WRITE: 0;
|
||||
perms = (input[3] == '+')? R_PERM_R|R_PERM_W: 0;
|
||||
r_core_file_reopen (core, input + 4, perms, 0);
|
||||
// TODO: Use API instead of !rabin2 -rk
|
||||
if (desc) {
|
||||
@ -1445,7 +1445,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
break;
|
||||
}
|
||||
|
||||
perms = ('+' == input[2])? R_IO_READ | R_IO_WRITE: 0;
|
||||
perms = ('+' == input[2])? R_PERM_R | R_PERM_W: 0;
|
||||
r_core_file_reopen (core, input + 3, perms, 0);
|
||||
break;
|
||||
case '+': // "oo+"
|
||||
@ -1453,20 +1453,19 @@ static int cmd_open(void *data, const char *input) {
|
||||
r_core_cmd_help (core, help_msg_oo_plus);
|
||||
} else if (core && core->io && core->io->desc) {
|
||||
int fd;
|
||||
int perms = R_IO_READ | R_IO_WRITE;
|
||||
int perms = R_PERM_RW;
|
||||
if ((ptr = strrchr (input, ' ')) && ptr[1]) {
|
||||
fd = (int)r_num_math (core->num, ptr + 1);
|
||||
} else {
|
||||
fd = core->io->desc->fd;
|
||||
perms |= core->io->desc->flags;
|
||||
perms |= core->io->desc->perm;
|
||||
}
|
||||
if (r_io_reopen (core->io, fd, perms, 644)) {
|
||||
SdbListIter *iter;
|
||||
RIOMap *map;
|
||||
ls_foreach_prev (core->io->maps, iter, map) {
|
||||
if (map->fd == fd) {
|
||||
map->flags |= R_IO_WRITE;
|
||||
map->flags |= R_IO_EXEC;
|
||||
map->perm |= R_PERM_WX;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1498,7 +1497,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
eprintf ("Nothing to do.\n");
|
||||
}
|
||||
} else {
|
||||
r_io_reopen (core->io, fd, R_IO_READ, 644);
|
||||
r_io_reopen (core->io, fd, R_PERM_R, 644);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1518,7 +1517,7 @@ static int cmd_open(void *data, const char *input) {
|
||||
// if load fails does not fallbacks to previous file
|
||||
r_core_fini (core);
|
||||
r_core_init (core);
|
||||
if (!r_core_file_open (core, input + 2, R_IO_READ, 0)) {
|
||||
if (!r_core_file_open (core, input + 2, R_PERM_R, 0)) {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
(void)r_core_bin_load (core, NULL, baddr);
|
||||
|
@ -2511,7 +2511,7 @@ static int cmd_print_blocks(RCore *core, const char *input) {
|
||||
|| (as->block[p].functions)
|
||||
|| (as->block[p].comments)
|
||||
|| (as->block[p].symbols)
|
||||
|| (as->block[p].rwx)
|
||||
|| (as->block[p].perm)
|
||||
|| (as->block[p].strings)) {
|
||||
r_cons_printf ("\"offset\":%"PFMT64u ",", at);
|
||||
r_cons_printf ("\"size\":%"PFMT64u ",", piece);
|
||||
@ -2528,7 +2528,7 @@ static int cmd_print_blocks(RCore *core, const char *input) {
|
||||
PRINT_VALUE2 ("comments", as->block[p].comments);
|
||||
PRINT_VALUE2 ("symbols", as->block[p].symbols);
|
||||
PRINT_VALUE2 ("strings", as->block[p].strings);
|
||||
PRINT_VALUE ("rwx", as->block[p].rwx, r_str_rwx_i (as->block[p].rwx));
|
||||
PRINT_VALUE ("perm", as->block[p].perm, r_str_rwx_i (as->block[p].perm));
|
||||
#undef PRINT_VALUE
|
||||
#undef PRINT_VALUE2
|
||||
r_cons_strcat ("}");
|
||||
@ -2560,7 +2560,7 @@ static int cmd_print_blocks(RCore *core, const char *input) {
|
||||
RIOSection *s = r_io_section_vget (core->io, at);
|
||||
if (use_color) {
|
||||
if (s) {
|
||||
if (s->flags & 1) {
|
||||
if (s->perm & R_PERM_X) {
|
||||
r_cons_print (Color_BGBLUE);
|
||||
} else {
|
||||
r_cons_print (Color_BGGREEN);
|
||||
|
@ -328,15 +328,15 @@ R_API int r_core_search_preludes(RCore *core) {
|
||||
ut64 to = UT64_MAX;
|
||||
const char *where = r_config_get (core->config, "anal.in");
|
||||
|
||||
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, where, "search");
|
||||
RList *list = r_core_get_boundaries_prot (core, R_PERM_X, where, "search");
|
||||
RListIter *iter;
|
||||
RIOMap *p;
|
||||
|
||||
int fc0 = count_functions (core);
|
||||
r_list_foreach (list, iter, p) {
|
||||
eprintf ("\r[>] Scanning %s 0x%"PFMT64x " - 0x%"PFMT64x " ",
|
||||
r_str_rwx_i (p->flags), p->itv.addr, r_itv_end (p->itv));
|
||||
if (!(p->flags & R_IO_EXEC)) {
|
||||
r_str_rwx_i (p->perm), p->itv.addr, r_itv_end (p->itv));
|
||||
if (!(p->perm & R_PERM_X)) {
|
||||
eprintf ("skip\n");
|
||||
continue;
|
||||
}
|
||||
@ -576,7 +576,7 @@ static void append_bound(RList *list, RIO *io, RInterval search_itv, ut64 from,
|
||||
if (io && io->desc) {
|
||||
map->fd = r_io_fd_get_current (io);
|
||||
}
|
||||
map->flags = perms;
|
||||
map->perm = perms;
|
||||
RInterval itv = {from, size};
|
||||
// TODO UT64_MAX is a valid address. search.from and search.to are not specified
|
||||
if (search_itv.addr == UT64_MAX && !search_itv.size) {
|
||||
@ -594,18 +594,18 @@ static void append_bound(RList *list, RIO *io, RInterval search_itv, ut64 from,
|
||||
}
|
||||
}
|
||||
|
||||
static bool maskMatches(int srwx, int mask, bool only) {
|
||||
static bool maskMatches(int perm, int mask, bool only) {
|
||||
if (mask) {
|
||||
if (only) {
|
||||
return ((srwx & 7) != mask);
|
||||
return ((perm & 7) != mask);
|
||||
}
|
||||
return (srwx & mask) != mask;
|
||||
return (perm & mask) != mask;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(maskray) returns RList<RInterval>
|
||||
R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char *mode, const char *prefix) {
|
||||
R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, const char *prefix) {
|
||||
RList *list = r_list_newf (free); // XXX r_io_map_free);
|
||||
char bound_in[32];
|
||||
char bound_from[32];
|
||||
@ -625,8 +625,8 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
if (!mode) {
|
||||
mode = r_config_get (core->config, bound_in);
|
||||
}
|
||||
if (protection == -1) {
|
||||
protection = R_IO_RWX;
|
||||
if (perm == -1) {
|
||||
perm = R_PERM_RWX;
|
||||
}
|
||||
if (!core) {
|
||||
r_list_free (list);
|
||||
@ -639,7 +639,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
} else if (!strcmp (mode, "io.map")) {
|
||||
RIOMap *m = r_io_map_get (core->io, core->offset);
|
||||
if (m) {
|
||||
append_bound (list, core->io, search_itv, m->itv.addr, m->itv.size, m->flags);
|
||||
append_bound (list, core->io, search_itv, m->itv.addr, m->itv.size, m->perm);
|
||||
}
|
||||
} else if (!strcmp (mode, "io.maps")) { // Non-overlapping RIOMap parts not overriden by others (skyline)
|
||||
const RPVector *skyline = &core->io->map_skyline;
|
||||
@ -648,7 +648,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
size_t i;
|
||||
for (i = 0; i < r_pvector_len (skyline); i++) {
|
||||
const RIOMapSkyline *part = r_pvector_at (skyline, i);
|
||||
int srwx = part->map->flags;
|
||||
int perm = part->map->perm;
|
||||
ut64 from = r_itv_begin (part->itv);
|
||||
ut64 to = r_itv_end (part->itv);
|
||||
// eprintf ("--------- %llx %llx (%llx %llx)\n", from, to, begin, end);
|
||||
@ -662,7 +662,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
end = to;
|
||||
} else {
|
||||
// eprintf ("[%llx - %llx]\n", begin, end);
|
||||
append_bound (list, NULL, search_itv, begin, end - begin, srwx);
|
||||
append_bound (list, NULL, search_itv, begin, end - begin, perm);
|
||||
begin = from;
|
||||
end = to;
|
||||
}
|
||||
@ -681,12 +681,12 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
RBinSection *s;
|
||||
RListIter *iter;
|
||||
r_list_foreach (obj->sections, iter, s) {
|
||||
if (maskMatches (s->srwx, mask, only)) {
|
||||
if (maskMatches (s->perm, mask, only)) {
|
||||
continue;
|
||||
}
|
||||
ut64 addr = core->io->va? s->vaddr: s->paddr;
|
||||
ut64 size = core->io->va? s->vsize: s->size;
|
||||
append_bound (list, core->io, search_itv, addr, size, s->srwx);
|
||||
append_bound (list, core->io, search_itv, addr, size, s->perm);
|
||||
}
|
||||
}
|
||||
const RPVector *skyline = &core->io->map_skyline;
|
||||
@ -697,8 +697,8 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
const RIOMapSkyline *part = r_pvector_at (skyline, i);
|
||||
ut64 from = part->itv.addr;
|
||||
ut64 to = part->itv.addr + part->itv.size;
|
||||
int srwx = part->map->flags;
|
||||
if (maskMatches (srwx, mask, only)) {
|
||||
int perm = part->map->perm;
|
||||
if (maskMatches (perm, mask, only)) {
|
||||
continue;
|
||||
}
|
||||
// eprintf ("--------- %llx %llx (%llx %llx)\n", from, to, begin, end);
|
||||
@ -712,7 +712,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
end = to;
|
||||
} else {
|
||||
// eprintf ("[%llx - %llx]\n", begin, end);
|
||||
append_bound (list, NULL, search_itv, begin, end - begin, srwx);
|
||||
append_bound (list, NULL, search_itv, begin, end - begin, perm);
|
||||
begin = from;
|
||||
end = to;
|
||||
}
|
||||
@ -730,12 +730,12 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
RBinSection *s;
|
||||
RListIter *iter;
|
||||
r_list_foreach (obj->sections, iter, s) {
|
||||
if (maskMatches (s->srwx, mask, only)) {
|
||||
if (maskMatches (s->perm, mask, only)) {
|
||||
continue;
|
||||
}
|
||||
ut64 addr = core->io->va? s->vaddr: s->paddr;
|
||||
ut64 size = core->io->va? s->vsize: s->size;
|
||||
append_bound (list, core->io, search_itv, addr, size, s->srwx);
|
||||
append_bound (list, core->io, search_itv, addr, size, s->perm);
|
||||
}
|
||||
}
|
||||
} else if (!strcmp (mode, "bin.section")) {
|
||||
@ -747,7 +747,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
ut64 addr = core->io->va? s->vaddr: s->paddr;
|
||||
ut64 size = core->io->va? s->vsize: s->size;
|
||||
if (R_BETWEEN (addr, core->offset, addr + size)) {
|
||||
append_bound (list, core->io, search_itv, addr, size, s->srwx);
|
||||
append_bound (list, core->io, search_itv, addr, size, s->perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -808,7 +808,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
// nmap->fd = core->io->desc->fd;
|
||||
nmap->itv.addr = from;
|
||||
nmap->itv.size = to - from;
|
||||
nmap->flags = perm;
|
||||
nmap->perm = perm;
|
||||
nmap->delta = 0;
|
||||
r_list_append (list, nmap);
|
||||
}
|
||||
@ -818,7 +818,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
mask = 0;
|
||||
if (!strcmp (mode, "dbg.program")) {
|
||||
first = true;
|
||||
mask = R_IO_EXEC;
|
||||
mask = R_PERM_X;
|
||||
} else if (!strcmp (mode, "dbg.maps")) {
|
||||
all = true;
|
||||
} else if (r_str_startswith (mode, "dbg.maps.")) {
|
||||
@ -837,7 +837,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
continue;
|
||||
}
|
||||
add = (stack && strstr (map->name, "stack"))? 1: 0;
|
||||
if (!add && (heap && (map->perm & R_IO_WRITE)) && strstr (map->name, "heap")) {
|
||||
if (!add && (heap && (map->perm & R_PERM_W)) && strstr (map->name, "heap")) {
|
||||
add = 1;
|
||||
}
|
||||
if ((mask && (map->perm & mask)) || add || all) {
|
||||
@ -854,7 +854,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
|
||||
from = R_MIN (from, nmap->itv.addr);
|
||||
to = R_MAX (to - 1, r_itv_end (nmap->itv) - 1) + 1;
|
||||
}
|
||||
nmap->flags = map->perm;
|
||||
nmap->perm = map->perm;
|
||||
nmap->delta = 0;
|
||||
r_list_append (list, nmap);
|
||||
if (first) {
|
||||
|
@ -87,9 +87,9 @@ static void list_section_visual(RIO *io, ut64 seek, ut64 len, int use_color, int
|
||||
r_num_units (buf, s->size);
|
||||
if (use_color) {
|
||||
color_end = Color_RESET;
|
||||
if (s->flags & 1) { // exec bit
|
||||
if (s->perm & R_PERM_X) { // exec bit
|
||||
color = Color_GREEN;
|
||||
} else if (s->flags & 2) { // write bit
|
||||
} else if (s->perm & R_PERM_W) { // write bit
|
||||
color = Color_RED;
|
||||
} else {
|
||||
color = "";
|
||||
@ -118,11 +118,11 @@ static void list_section_visual(RIO *io, ut64 seek, ut64 len, int use_color, int
|
||||
if (io->va) {
|
||||
io->cb_printf ("| %s0x%08"PFMT64x"%s %5s %s %04s\n",
|
||||
color, s->vaddr + s->vsize, color_end, buf,
|
||||
r_str_rwx_i (s->flags), s->name);
|
||||
r_str_rwx_i (s->perm), s->name);
|
||||
} else {
|
||||
io->cb_printf ("| %s0x%08"PFMT64x"%s %5s %s %04s\n",
|
||||
color, s->paddr+s->size, color_end, buf,
|
||||
r_str_rwx_i (s->flags), s->name);
|
||||
r_str_rwx_i (s->perm), s->name);
|
||||
}
|
||||
|
||||
i++;
|
||||
@ -148,7 +148,7 @@ static void __section_list (RIO *io, ut64 offset, RPrint *print, int rad) {
|
||||
print->cb_printf ("f section.%s %"PFMT64d" 0x%"PFMT64x"\n", n, s->size, s->vaddr);
|
||||
print->cb_printf ("S 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"
|
||||
PFMT64x" 0x%08"PFMT64x" %s %s\n", s->paddr,
|
||||
s->vaddr, s->size, s->vsize, n, r_str_rwx_i (s->flags));
|
||||
s->vaddr, s->size, s->vsize, n, r_str_rwx_i (s->perm));
|
||||
free (n);
|
||||
}
|
||||
} else {
|
||||
@ -169,7 +169,7 @@ static void __section_list (RIO *io, ut64 offset, RPrint *print, int rad) {
|
||||
}
|
||||
print->cb_printf ("pa=0x%08"PFMT64x" %s va=0x%08"PFMT64x
|
||||
" sz=0x%04"PFMT64x" vsz=0x%04"PFMT64x" %s", s->paddr,
|
||||
r_str_rwx_i (s->flags), s->vaddr, s->size, s->vsize, s->name);
|
||||
r_str_rwx_i (s->perm), s->vaddr, s->size, s->vsize, s->name);
|
||||
if (s->arch && s->bits) {
|
||||
print->cb_printf (" ; %s %d", r_sys_arch_str (s->arch),
|
||||
s->bits);
|
||||
|
@ -2783,9 +2783,9 @@ reaccept:
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.laddr");
|
||||
r_socket_read_block (c, ptr, cmd);
|
||||
ptr[cmd] = 0;
|
||||
ut32 perm = R_IO_READ;
|
||||
if (flg & R_IO_WRITE) {
|
||||
perm |= R_IO_WRITE;
|
||||
ut32 perm = R_PERM_R;
|
||||
if (flg & R_PERM_W) {
|
||||
perm |= R_PERM_W;
|
||||
}
|
||||
if (r_core_file_open (core, (const char *)ptr, perm, 0)) {
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
|
@ -640,8 +640,8 @@ static RDisasmState * ds_init(RCore *core) {
|
||||
ut64 addr = r_reg_getv (core->anal->reg, "SP") - (size / 2);
|
||||
emustack_min = addr;
|
||||
emustack_max = addr + size;
|
||||
ds->stackFd = r_io_fd_open (core->io, uri, R_IO_RW, 0);
|
||||
RIOMap *map = r_io_map_add (core->io, ds->stackFd, R_IO_RW, 0LL, addr, size);
|
||||
ds->stackFd = r_io_fd_open (core->io, uri, R_PERM_RW, 0);
|
||||
RIOMap *map = r_io_map_add (core->io, ds->stackFd, R_PERM_RW, 0LL, addr, size);
|
||||
if (!map) {
|
||||
r_io_fd_close (core->io, ds->stackFd);
|
||||
eprintf ("Cannot create map for tha stack, fd %d got closed again\n", ds->stackFd);
|
||||
|
@ -535,11 +535,11 @@ static bool store_files_and_maps (RCore *core, RIODesc *desc, ut32 id) {
|
||||
RListIter *iter;
|
||||
RIOMap *map;
|
||||
if (desc) {
|
||||
r_cons_printf ("ofs %s %s\n", desc->uri, r_str_rwx_i (desc->flags));
|
||||
r_cons_printf ("ofs %s %s\n", desc->uri, r_str_rwx_i (desc->perm));
|
||||
if ((maps = r_io_map_get_for_fd (core->io, id))) {
|
||||
r_list_foreach (maps, iter, map) {
|
||||
r_cons_printf ("om %d 0x%"PFMT64x" 0x%"PFMT64x" 0x%"PFMT64x" %s%s%s\n", fdc,
|
||||
map->itv.addr, map->itv.size, map->delta, r_str_rwx_i(map->flags),
|
||||
map->itv.addr, map->itv.size, map->delta, r_str_rwx_i (map->perm),
|
||||
map->name ? " " : "", map->name ? map->name : "");
|
||||
}
|
||||
r_list_free (maps);
|
||||
|
@ -1284,7 +1284,7 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) {
|
||||
args = "";
|
||||
}
|
||||
|
||||
if (!r_core_file_open (core, file, R_IO_READ, 0)) {
|
||||
if (!r_core_file_open (core, file, R_PERM_R, 0)) {
|
||||
eprintf ("Cannot open file (%s)\n", file);
|
||||
return -1;
|
||||
}
|
||||
@ -1714,7 +1714,7 @@ static void r_rap_packet_fill(ut8 *buf, const ut8* src, int len) {
|
||||
|
||||
static bool r_core_rtr_rap_run(RCore *core, const char *input) {
|
||||
char *file = r_str_newf ("rap://%s", input);
|
||||
int flags = R_IO_READ | R_IO_WRITE;
|
||||
int flags = R_PERM_RW;
|
||||
RIODesc *fd = r_io_open_nomap (core->io, file, flags, 0644);
|
||||
if (fd) {
|
||||
if (r_io_is_listener (core->io)) {
|
||||
|
@ -1937,7 +1937,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
||||
break;
|
||||
case 'a':
|
||||
{
|
||||
if (core->file && core->io && !(r_io_desc_get (core->io, core->file->fd)->flags & 2)) {
|
||||
if (core->file && core->io && !(r_io_desc_get (core->io, core->file->fd)->perm & R_PERM_W)) {
|
||||
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
||||
r_cons_any_key (NULL);
|
||||
return true;
|
||||
@ -2148,7 +2148,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (core->file && core->io && !(r_io_desc_get (core->io, core->file->fd)->flags & 2)) {
|
||||
if (core->file && core->io && !(r_io_desc_get (core->io, core->file->fd)->perm & R_PERM_W)) {
|
||||
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
||||
r_cons_any_key (NULL);
|
||||
return true;
|
||||
|
@ -45,11 +45,11 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
|
||||
if (filename && *filename) {
|
||||
ut64 load_align = r_config_get_i (core->config, "file.loadalign");
|
||||
RIOMap *map = NULL;
|
||||
yankdesc = r_io_open_nomap (core->io, filename, R_IO_READ, 0644);
|
||||
yankdesc = r_io_open_nomap (core->io, filename, R_PERM_R, 0644);
|
||||
// map the file in for IO operations.
|
||||
if (yankdesc && load_align) {
|
||||
yank_file_sz = r_io_size (core->io);
|
||||
map = r_io_map_add_next_available (core->io, yankdesc->fd, R_IO_READ, 0, 0, yank_file_sz, load_align);
|
||||
map = r_io_map_add_next_available (core->io, yankdesc->fd, R_PERM_R, 0, 0, yank_file_sz, load_align);
|
||||
loadaddr = map? map->itv.addr: -1;
|
||||
if (yankdesc && map && loadaddr != -1) {
|
||||
// ***NOTE*** this is important, we need to
|
||||
|
@ -82,8 +82,8 @@ R_API int r_debug_desc_list(RDebug *dbg, int rad) {
|
||||
list = dbg->h->desc.list (dbg->pid);
|
||||
r_list_foreach (list, iter, p) {
|
||||
dbg->cb_printf ("%i 0x%"PFMT64x" %c%c%c %s\n", p->fd, p->off,
|
||||
(p->perm & R_IO_READ)?'r':'-',
|
||||
(p->perm & R_IO_WRITE)?'w':'-',
|
||||
(p->perm & R_PERM_R)?'r':'-',
|
||||
(p->perm & R_PERM_W)?'w':'-',
|
||||
p->type, p->path);
|
||||
}
|
||||
r_list_purge (list);
|
||||
|
@ -74,7 +74,7 @@ static int esilbreak_check_pc (RDebug *dbg, ut64 pc) {
|
||||
pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
|
||||
}
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
if (ew->rwx & R_IO_EXEC) {
|
||||
if (ew->rwx & R_PERM_X) {
|
||||
if (exprmatch (dbg, pc, ew->expr)) {
|
||||
return 1;
|
||||
}
|
||||
@ -88,7 +88,7 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
RListIter *iter;
|
||||
eprintf (Color_GREEN"MEM READ 0x%"PFMT64x"\n"Color_RESET, addr);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
if (ew->rwx & R_IO_READ && ew->dev == 'm') {
|
||||
if (ew->rwx & R_PERM_R && ew->dev == 'm') {
|
||||
if (exprmatch (dbg, addr, ew->expr)) {
|
||||
has_match = 1;
|
||||
return 1;
|
||||
@ -103,7 +103,7 @@ static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int l
|
||||
RListIter *iter;
|
||||
eprintf (Color_RED"MEM WRTE 0x%"PFMT64x"\n"Color_RESET, addr);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
if (ew->rwx & R_IO_WRITE && ew->dev == 'm') {
|
||||
if (ew->rwx & R_PERM_W && ew->dev == 'm') {
|
||||
if (exprmatch (dbg, addr, ew->expr)) {
|
||||
has_match = 1;
|
||||
return 1;
|
||||
@ -122,7 +122,7 @@ static int esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, i
|
||||
}
|
||||
eprintf (Color_YELLOW"REG READ %s\n"Color_RESET, regname);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
if (ew->rwx & R_IO_READ && ew->dev == 'r') {
|
||||
if (ew->rwx & R_PERM_R && ew->dev == 'r') {
|
||||
// XXX: support array of regs in expr
|
||||
if (!strcmp (regname, ew->expr)) {
|
||||
has_match = 1;
|
||||
@ -198,7 +198,7 @@ static int esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num)
|
||||
}
|
||||
eprintf (Color_MAGENTA"REG WRTE %s 0x%"PFMT64x"\n"Color_RESET, regname, *num);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
if (ew->rwx & R_IO_WRITE && ew->dev == 'r') {
|
||||
if ((ew->rwx & R_PERM_W) && (ew->dev == 'r')) {
|
||||
// XXX: support array of regs in expr
|
||||
if (exprmatchreg (dbg, regname, ew->expr)) {
|
||||
has_match = 1;
|
||||
|
@ -104,8 +104,7 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO
|
||||
return NULL;
|
||||
}
|
||||
RDebugMap *map;
|
||||
if (!(map = r_debug_map_new ("", baddr, baddr,
|
||||
R_IO_READ | R_IO_EXEC, 0))) {
|
||||
if (!(map = r_debug_map_new ("", baddr, baddr, R_PERM_RX, 0))) {
|
||||
r_list_free (retlist);
|
||||
return NULL;
|
||||
}
|
||||
@ -196,9 +195,9 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO
|
||||
perm = 0;
|
||||
for (i = 0; perms[i] && i < 5; i++) {
|
||||
switch (perms[i]) {
|
||||
case 'r': perm |= R_IO_READ; break;
|
||||
case 'w': perm |= R_IO_WRITE; break;
|
||||
case 'x': perm |= R_IO_EXEC; break;
|
||||
case 'r': perm |= R_PERM_R; break;
|
||||
case 'w': perm |= R_PERM_W; break;
|
||||
case 'x': perm |= R_PERM_X; break;
|
||||
case 'p': map_is_shared = false; break;
|
||||
case 's': map_is_shared = true; break;
|
||||
}
|
||||
@ -981,7 +980,7 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set
|
||||
}
|
||||
bpsize = b->size;
|
||||
// TODO handle conditions
|
||||
switch (b->rwx){
|
||||
switch (b->perm) {
|
||||
case R_BP_PROT_EXEC : {
|
||||
if (set) {
|
||||
ret = b->hw?
|
||||
@ -993,7 +992,7 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set
|
||||
break;
|
||||
}
|
||||
// TODO handle size (area of watch in upper layer and then bpsize. For the moment watches are set on exact on byte
|
||||
case R_BP_PROT_WRITE : {
|
||||
case R_PERM_W: {
|
||||
if (set) {
|
||||
gdbr_set_hww (desc, b->addr, "", 1);
|
||||
} else {
|
||||
@ -1001,7 +1000,7 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set
|
||||
}
|
||||
break;
|
||||
}
|
||||
case R_BP_PROT_READ : {
|
||||
case R_PERM_R: {
|
||||
if (set) {
|
||||
gdbr_set_hwr (desc, b->addr, "", 1);
|
||||
} else {
|
||||
@ -1009,7 +1008,7 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set
|
||||
}
|
||||
break;
|
||||
}
|
||||
case R_BP_PROT_ACCESS : {
|
||||
case R_PERM_ACCESS: {
|
||||
if (set) {
|
||||
gdbr_set_hwa (desc, b->addr, "", 1);
|
||||
} else {
|
||||
|
@ -938,13 +938,13 @@ static RList *r_debug_native_sysctl_map (RDebug *dbg) {
|
||||
static int io_perms_to_prot (int io_perms) {
|
||||
int prot_perms = PROT_NONE;
|
||||
|
||||
if (io_perms & R_IO_READ) {
|
||||
if (io_perms & R_PERM_R) {
|
||||
prot_perms |= PROT_READ;
|
||||
}
|
||||
if (io_perms & R_IO_WRITE) {
|
||||
if (io_perms & R_PERM_W) {
|
||||
prot_perms |= PROT_WRITE;
|
||||
}
|
||||
if (io_perms & R_IO_EXEC) {
|
||||
if (io_perms & R_PERM_X) {
|
||||
prot_perms |= PROT_EXEC;
|
||||
}
|
||||
return prot_perms;
|
||||
@ -1043,19 +1043,19 @@ err_linux_map_dealloc:
|
||||
static int io_perms_to_prot (int io_perms) {
|
||||
int prot_perms;
|
||||
|
||||
if ((io_perms & R_IO_RWX) == R_IO_RWX) {
|
||||
if ((io_perms & R_PERM_RWX) == R_PERM_RWX) {
|
||||
prot_perms = PAGE_EXECUTE_READWRITE;
|
||||
} else if ((io_perms & (R_IO_WRITE | R_IO_EXEC)) == (R_IO_WRITE | R_IO_EXEC)) {
|
||||
} else if ((io_perms & (R_PERM_W | R_PERM_X)) == (R_PERM_W | R_PERM_X)) {
|
||||
prot_perms = PAGE_EXECUTE_READWRITE;
|
||||
} else if ((io_perms & (R_IO_READ | R_IO_EXEC)) == (R_IO_READ | R_IO_EXEC)) {
|
||||
} else if ((io_perms & (R_PERM_R | R_PERM_X)) == (R_PERM_R | R_PERM_X)) {
|
||||
prot_perms = PAGE_EXECUTE_READ;
|
||||
} else if ((io_perms & R_IO_RW) == R_IO_RW) {
|
||||
} else if ((io_perms & R_PERM_RW) == R_PERM_RW) {
|
||||
prot_perms = PAGE_READWRITE;
|
||||
} else if (io_perms & R_IO_WRITE) {
|
||||
} else if (io_perms & R_PERM_W) {
|
||||
prot_perms = PAGE_READWRITE;
|
||||
} else if (io_perms & R_IO_EXEC) {
|
||||
} else if (io_perms & R_PERM_X) {
|
||||
prot_perms = PAGE_EXECUTE;
|
||||
} else if (io_perms & R_IO_READ) {
|
||||
} else if (io_perms & R_PERM_R) {
|
||||
prot_perms = PAGE_READONLY;
|
||||
} else {
|
||||
prot_perms = PAGE_NOACCESS;
|
||||
@ -1250,9 +1250,9 @@ static RList *r_debug_native_map_get (RDebug *dbg) {
|
||||
perm = 0;
|
||||
for (i = 0; i < 5 && perms[i]; i++) {
|
||||
switch (perms[i]) {
|
||||
case 'r': perm |= R_IO_READ; break;
|
||||
case 'w': perm |= R_IO_WRITE; break;
|
||||
case 'x': perm |= R_IO_EXEC; break;
|
||||
case 'r': perm |= R_PERM_R; break;
|
||||
case 'w': perm |= R_PERM_W; break;
|
||||
case 'x': perm |= R_PERM_X; break;
|
||||
case 'p': map_is_shared = false; break;
|
||||
case 's': map_is_shared = true; break;
|
||||
}
|
||||
@ -1805,11 +1805,12 @@ static RList *r_debug_desc_native_list (int pid) {
|
||||
case KF_TYPE_UNKNOWN:
|
||||
default: type = '-'; break;
|
||||
}
|
||||
perm = (kve->kf_flags & KF_FLAG_READ)?R_IO_READ:0;
|
||||
perm |= (kve->kf_flags & KF_FLAG_WRITE)?R_IO_WRITE:0;
|
||||
desc = r_debug_desc_new (kve->kf_fd, str, perm, type,
|
||||
kve->kf_offset);
|
||||
if (!desc) break;
|
||||
perm = (kve->kf_flags & KF_FLAG_READ)? R_PERM_R: 0;
|
||||
perm |= (kve->kf_flags & KF_FLAG_WRITE)? R_PERM_W: 0;
|
||||
desc = r_debug_desc_new (kve->kf_fd, str, perm, type, kve->kf_offset);
|
||||
if (!desc) {
|
||||
break;
|
||||
}
|
||||
r_list_append (ret, desc);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ void drx_enable(drxt *r, int n, int enabled) {
|
||||
bool drx_add(RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) {
|
||||
if (bp->nhwbps < 4) {
|
||||
r_debug_reg_sync (dbg, R_REG_TYPE_DRX, false);
|
||||
r_debug_drx_set (dbg, bp->nhwbps, b->addr, b->size, b->rwx, 0);
|
||||
r_debug_drx_set (dbg, bp->nhwbps, b->addr, b->size, b->perm, 0);
|
||||
r_debug_reg_sync (dbg, R_REG_TYPE_DRX, true);
|
||||
bp->nhwbps++;
|
||||
return true;
|
||||
|
@ -334,7 +334,7 @@ static bool dump_this_map(char *buff_smaps, linux_map_entry_t *entry, ut8 filter
|
||||
return false;
|
||||
}
|
||||
/* if the map doesn't have r/w quit right here */
|
||||
if ((!(perms & R_IO_READ) && !(perms & R_IO_WRITE))) {
|
||||
if ((!(perms & R_PERM_R) && !(perms & R_PERM_W))) {
|
||||
free (identity);
|
||||
return false;
|
||||
}
|
||||
@ -649,7 +649,7 @@ static int get_info_mappings(linux_map_entry_t *me_head, size_t *maps_size) {
|
||||
int n_entries;
|
||||
for (n_entries = 0, p = me_head; p; p = p->n) {
|
||||
/* We don't count maps which does not have r/w perms */
|
||||
if (((p->perms & R_IO_READ) || (p->perms & R_IO_WRITE)) && p->dumpeable) {
|
||||
if (((p->perms & R_PERM_R) || (p->perms & R_PERM_W)) && p->dumpeable) {
|
||||
*maps_size += p->end_addr - p->start_addr;
|
||||
n_entries++;
|
||||
}
|
||||
@ -723,7 +723,7 @@ static bool dump_elf_pheaders(RBuffer *dest, linux_map_entry_t *maps, elf_offset
|
||||
|
||||
/* write program headers */
|
||||
for (me_p = maps; me_p; me_p = me_p->n) {
|
||||
if ((!(me_p->perms & R_IO_READ) && !(me_p->perms & R_IO_WRITE)) || !me_p->dumpeable) {
|
||||
if ((!(me_p->perms & R_PERM_R) && !(me_p->perms & R_PERM_W)) || !me_p->dumpeable) {
|
||||
continue;
|
||||
}
|
||||
phdr.p_type = PT_LOAD;
|
||||
|
@ -997,10 +997,10 @@ RList *linux_desc_list (int pid) {
|
||||
}
|
||||
if (lstat(path, &st) != -1) {
|
||||
if (st.st_mode & S_IRUSR) {
|
||||
perm |= R_IO_READ;
|
||||
perm |= R_PERM_R;
|
||||
}
|
||||
if (st.st_mode & S_IWUSR) {
|
||||
perm |= R_IO_WRITE;
|
||||
perm |= R_PERM_W;
|
||||
}
|
||||
}
|
||||
//TODO: Offset
|
||||
|
@ -31,25 +31,25 @@ static RDebugMap *add_map(RList *list, const char *name, ut64 addr, ut64 len, ME
|
||||
|
||||
switch (mbi->Protect) {
|
||||
case PAGE_EXECUTE:
|
||||
perm = R_IO_EXEC;
|
||||
perm = R_PERM_X;
|
||||
break;
|
||||
case PAGE_EXECUTE_READ:
|
||||
perm = R_IO_READ | R_IO_EXEC;
|
||||
perm = R_PERM_RX;
|
||||
break;
|
||||
case PAGE_EXECUTE_READWRITE:
|
||||
perm = R_IO_READ | R_IO_WRITE | R_IO_EXEC;
|
||||
perm = R_PERM_RWX;
|
||||
break;
|
||||
case PAGE_READONLY:
|
||||
perm = R_IO_READ;
|
||||
perm = R_PERM_R;
|
||||
break;
|
||||
case PAGE_READWRITE:
|
||||
perm = R_IO_READ | R_IO_WRITE;
|
||||
perm = R_PERM_RW;
|
||||
break;
|
||||
case PAGE_WRITECOPY:
|
||||
perm = R_IO_WRITE;
|
||||
perm = R_PERM_W;
|
||||
break;
|
||||
case PAGE_EXECUTE_WRITECOPY:
|
||||
perm = R_IO_EXEC;
|
||||
perm = R_PERM_X;
|
||||
break;
|
||||
default:
|
||||
perm = 0;
|
||||
@ -59,9 +59,8 @@ static RDebugMap *add_map(RList *list, const char *name, ut64 addr, ut64 len, ME
|
||||
perror ("r_str_newf");
|
||||
goto err_add_map;
|
||||
}
|
||||
mr = r_debug_map_new (map_name,
|
||||
addr,
|
||||
addr + len, perm, mbi->Type == MEM_PRIVATE);
|
||||
mr = r_debug_map_new (map_name, addr,
|
||||
addr + len, perm, mbi->Type == MEM_PRIVATE);
|
||||
if (mr) {
|
||||
r_list_append (list, mr);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ R_API RDebugSession *r_debug_session_add(RDebug *dbg, RListIter **tail) {
|
||||
RListIter *iter;
|
||||
RDebugMap *map;
|
||||
ut64 addr;
|
||||
int i, perms = R_IO_RW;
|
||||
int i, perms = R_PERM_RW;
|
||||
|
||||
addr = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
|
||||
/* Session has already existed at this addr? */
|
||||
|
@ -14,11 +14,6 @@ extern "C" {
|
||||
|
||||
R_LIB_VERSION_HEADER (r_bin);
|
||||
|
||||
#define R_BIN_SCN_EXECUTABLE (1 << 0)
|
||||
#define R_BIN_SCN_WRITABLE (1 << 1)
|
||||
#define R_BIN_SCN_READABLE (1 << 2)
|
||||
#define R_BIN_SCN_SHAREABLE (1 << 3)
|
||||
|
||||
#define R_BIN_DBG_STRIPPED 0x01
|
||||
#define R_BIN_DBG_STATIC 0x02
|
||||
#define R_BIN_DBG_LINENUMS 0x04
|
||||
@ -445,7 +440,7 @@ typedef struct r_bin_section_t {
|
||||
ut64 vsize;
|
||||
ut64 vaddr;
|
||||
ut64 paddr;
|
||||
ut32 srwx;
|
||||
ut32 perm;
|
||||
// per section platform info
|
||||
const char *arch;
|
||||
char *format;
|
||||
|
@ -47,7 +47,7 @@ typedef struct r_bp_item_t {
|
||||
int size; /* size of breakpoint area */
|
||||
int recoil; /* recoil */
|
||||
bool swstep; /* is this breakpoint from a swstep? */
|
||||
int rwx;
|
||||
int perm;
|
||||
int hw;
|
||||
int trace;
|
||||
int internal; /* used for internal purposes */
|
||||
@ -85,6 +85,7 @@ typedef struct r_bp_t {
|
||||
st64 delta;
|
||||
} RBreakpoint;
|
||||
|
||||
// DEPRECATED: USE R_PERM
|
||||
enum {
|
||||
R_BP_PROT_EXEC = 1,
|
||||
R_BP_PROT_WRITE = 2,
|
||||
@ -114,7 +115,7 @@ R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits);
|
||||
R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name);
|
||||
R_API void r_bp_plugin_list(RBreakpoint *bp);
|
||||
|
||||
R_API int r_bp_in(RBreakpoint *bp, ut64 addr, int rwx);
|
||||
R_API int r_bp_in(RBreakpoint *bp, ut64 addr, int perm);
|
||||
// deprecate?
|
||||
R_API int r_bp_list(RBreakpoint *bp, int rad);
|
||||
R_API int r_bp_size(RBreakpoint *bp);
|
||||
@ -133,14 +134,14 @@ R_API int r_bp_get_index_at (RBreakpoint *bp, ut64 addr);
|
||||
R_API RBreakpointItem *r_bp_item_new (RBreakpoint *bp);
|
||||
|
||||
R_API RBreakpointItem *r_bp_get_at (RBreakpoint *bp, ut64 addr);
|
||||
R_API RBreakpointItem *r_bp_get_in (RBreakpoint *bp, ut64 addr, int rwx);
|
||||
R_API RBreakpointItem *r_bp_get_in (RBreakpoint *bp, ut64 addr, int perm);
|
||||
|
||||
R_API int r_bp_add_cond(RBreakpoint *bp, const char *cond);
|
||||
R_API int r_bp_del_cond(RBreakpoint *bp, int idx);
|
||||
R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int rwx);
|
||||
R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm);
|
||||
|
||||
R_API RBreakpointItem *r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int rwx);
|
||||
R_API RBreakpointItem *r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int rwx);
|
||||
R_API RBreakpointItem *r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm);
|
||||
R_API RBreakpointItem *r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm);
|
||||
R_API void r_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set);
|
||||
R_API int r_bp_restore(RBreakpoint *bp, bool set);
|
||||
R_API bool r_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr);
|
||||
|
@ -711,7 +711,7 @@ typedef struct {
|
||||
ut32 in_functions;
|
||||
ut32 symbols;
|
||||
ut32 strings;
|
||||
ut32 rwx;
|
||||
ut32 perm;
|
||||
} RCoreAnalStatsItem;
|
||||
typedef struct {
|
||||
RCoreAnalStatsItem *block;
|
||||
|
@ -11,15 +11,6 @@
|
||||
#include "r_util.h"
|
||||
#include "r_vector.h"
|
||||
|
||||
#define R_IO_READ 4
|
||||
#define R_IO_WRITE 2
|
||||
#define R_IO_EXEC 1
|
||||
#define R_IO_RW (R_IO_READ|R_IO_WRITE)
|
||||
#define R_IO_RWX (R_IO_READ|R_IO_WRITE|R_IO_EXEC)
|
||||
#define R_IO_PRIV 16
|
||||
#define R_IO_SHAR 32
|
||||
#define R_IO_CREAT 64
|
||||
|
||||
#define R_IO_SEEK_SET 0
|
||||
#define R_IO_SEEK_CUR 1
|
||||
#define R_IO_SEEK_END 2
|
||||
@ -98,7 +89,7 @@ typedef struct r_io_t {
|
||||
|
||||
typedef struct r_io_desc_t {
|
||||
int fd;
|
||||
int flags;
|
||||
int perm;
|
||||
int obsz; //optimal blocksize// do we really need this here?
|
||||
char *uri;
|
||||
char *name;
|
||||
@ -166,7 +157,7 @@ typedef struct r_io_plugin_t {
|
||||
|
||||
typedef struct r_io_map_t {
|
||||
int fd;
|
||||
int flags;
|
||||
int perm;
|
||||
ut32 id;
|
||||
RInterval itv;
|
||||
ut64 delta; //this delta means paddr when talking about section
|
||||
@ -178,13 +169,14 @@ typedef struct r_io_map_skyline_t {
|
||||
RInterval itv;
|
||||
} RIOMapSkyline;
|
||||
|
||||
// XXX must be deprecated maps should be enough
|
||||
typedef struct r_io_section_t {
|
||||
char *name;
|
||||
ut64 paddr;
|
||||
ut64 size;
|
||||
ut64 vaddr;
|
||||
ut64 vsize;
|
||||
int flags;
|
||||
int perm;
|
||||
ut32 id;
|
||||
ut32 bin_id;
|
||||
int arch;
|
||||
|
@ -42,6 +42,19 @@
|
||||
#undef R_NEWCOPY
|
||||
#endif
|
||||
|
||||
// used in debug, io, bin, anal, ...
|
||||
#define R_PERM_R 4
|
||||
#define R_PERM_W 2
|
||||
#define R_PERM_X 1
|
||||
#define R_PERM_RW (R_PERM_R|R_PERM_W)
|
||||
#define R_PERM_RX (R_PERM_R|R_PERM_X)
|
||||
#define R_PERM_RWX (R_PERM_R|R_PERM_W|R_PERM_X)
|
||||
#define R_PERM_WX (R_PERM_W|R_PERM_X)
|
||||
#define R_PERM_SHAR 8
|
||||
#define R_PERM_PRIV 16
|
||||
#define R_PERM_ACCESS 32
|
||||
#define R_PERM_CREAT 64
|
||||
|
||||
// HACK to fix capstone-android-mips build
|
||||
#undef mips
|
||||
#define mips mips
|
||||
|
@ -18,7 +18,7 @@ R_API bool r_io_desc_init(RIO* io) {
|
||||
|
||||
//shall be used by plugins for creating descs
|
||||
//XXX kill mode
|
||||
R_API RIODesc* r_io_desc_new(RIO* io, RIOPlugin* plugin, const char* uri, int flags, int mode, void* data) {
|
||||
R_API RIODesc* r_io_desc_new(RIO* io, RIOPlugin* plugin, const char* uri, int perm, int mode, void* data) {
|
||||
ut32 fd32 = 0;
|
||||
// this is because emscript is a bitch
|
||||
if (!io || !plugin || !uri) {
|
||||
@ -35,7 +35,7 @@ R_API RIODesc* r_io_desc_new(RIO* io, RIOPlugin* plugin, const char* uri, int fl
|
||||
desc->io = io;
|
||||
desc->plugin = plugin;
|
||||
desc->data = data;
|
||||
desc->flags = flags;
|
||||
desc->perm = perm;
|
||||
//because the uri-arg may live on the stack
|
||||
desc->uri = strdup (uri);
|
||||
}
|
||||
@ -95,7 +95,7 @@ R_API RIODesc* r_io_desc_get(RIO* io, int fd) {
|
||||
return (RIODesc*) r_id_storage_get (io->files, fd);
|
||||
}
|
||||
|
||||
R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int flags, int mode) {
|
||||
R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int perm, int mode) {
|
||||
if (!io || !io->files || !uri) {
|
||||
return NULL;
|
||||
}
|
||||
@ -103,7 +103,7 @@ R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int flags, int mode) {
|
||||
if (!plugin || !plugin->open) {
|
||||
return NULL;
|
||||
}
|
||||
RIODesc *desc = plugin->open (io, uri, flags, mode);
|
||||
RIODesc *desc = plugin->open (io, uri, perm, mode);
|
||||
if (!desc) {
|
||||
return NULL;
|
||||
}
|
||||
@ -121,14 +121,14 @@ R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int flags, int mode) {
|
||||
return desc;
|
||||
}
|
||||
|
||||
R_API RIODesc *r_io_desc_open_plugin(RIO *io, RIOPlugin *plugin, const char *uri, int flags, int mode) {
|
||||
R_API RIODesc *r_io_desc_open_plugin(RIO *io, RIOPlugin *plugin, const char *uri, int perm, int mode) {
|
||||
if (!io || !io->files || !uri) {
|
||||
return NULL;
|
||||
}
|
||||
if (!plugin || !plugin->open || !plugin->check || !plugin->check (io, uri, false)) {
|
||||
return NULL;
|
||||
}
|
||||
RIODesc *desc = plugin->open (io, uri, flags, mode);
|
||||
RIODesc *desc = plugin->open (io, uri, perm, mode);
|
||||
if (!desc) {
|
||||
return NULL;
|
||||
}
|
||||
@ -182,7 +182,7 @@ R_API int r_io_desc_write(RIODesc *desc, const ut8* buf, int len) {
|
||||
R_API int r_io_desc_read(RIODesc *desc, ut8 *buf, int len) {
|
||||
ut64 seek;
|
||||
// check pointers and permissions
|
||||
if (!buf || !desc || !desc->plugin || len < 1 || !(desc->flags & R_IO_READ)) {
|
||||
if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & R_PERM_R)) {
|
||||
return 0;
|
||||
}
|
||||
seek = r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR);
|
||||
@ -243,18 +243,6 @@ R_API bool r_io_desc_is_chardevice(RIODesc *desc) {
|
||||
return desc->plugin->is_chardevice (desc);
|
||||
}
|
||||
|
||||
|
||||
static bool _map_flags_cb(void *user, void *data, ut32 id) {
|
||||
RIODesc *desc = (RIODesc *)user;
|
||||
RIOMap *map = (RIOMap *)data;
|
||||
|
||||
if(map->fd == desc->fd) {
|
||||
map->flags &= (desc->flags | R_IO_EXEC);
|
||||
return false; //break
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API bool r_io_desc_exchange(RIO* io, int fd, int fdx) {
|
||||
RIODesc* desc, * descx;
|
||||
SdbListIter* iter;
|
||||
@ -276,9 +264,9 @@ R_API bool r_io_desc_exchange(RIO* io, int fd, int fdx) {
|
||||
if (io->maps) {
|
||||
ls_foreach (io->maps, iter, map) {
|
||||
if (map->fd == fdx) {
|
||||
map->flags &= (desc->flags | R_IO_EXEC);
|
||||
map->perm &= (desc->perm | R_PERM_X);
|
||||
} else if (map->fd == fd) {
|
||||
map->flags &= (descx->flags | R_IO_EXEC);
|
||||
map->perm &= (descx->perm | R_PERM_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
52
libr/io/io.c
52
libr/io/io.c
@ -60,7 +60,7 @@ static st64 on_map_skyline(RIO *io, ut64 vaddr, ut8 *buf, int len, int match_flg
|
||||
// Now left endpoint <= addr < right endpoint
|
||||
ut64 len1 = R_MIN (vaddr + len - addr, r_itv_end (part->itv) - addr);
|
||||
// The map satisfies the permission requirement or p_cache is enabled
|
||||
if (((part->map->flags & match_flg) == match_flg || io->p_cache)) {
|
||||
if (((part->map->perm & match_flg) == match_flg || io->p_cache)) {
|
||||
st64 result = op (io, part->map->fd, part->map->delta + addr - part->map->itv.addr,
|
||||
buf + (addr - vaddr), len1, part->map, NULL);
|
||||
if (prefix_mode) {
|
||||
@ -142,21 +142,21 @@ R_API void r_io_free(RIO *io) {
|
||||
free (io);
|
||||
}
|
||||
|
||||
R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *b, int flags, int mode) {
|
||||
R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *b, int perm, int mode) {
|
||||
const int bufSize = r_buf_size (b);
|
||||
char *uri = r_str_newf ("malloc://%d", bufSize);
|
||||
RIODesc *desc = r_io_open_nomap (io, uri, flags, mode);
|
||||
RIODesc *desc = r_io_open_nomap (io, uri, perm, mode);
|
||||
if (desc) {
|
||||
r_io_desc_write (desc, r_buf_get_at (b, 0, NULL), bufSize);
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
R_API RIODesc *r_io_open_nomap(RIO *io, const char *uri, int flags, int mode) {
|
||||
R_API RIODesc *r_io_open_nomap(RIO *io, const char *uri, int perm, int mode) {
|
||||
if (!io || !uri) {
|
||||
return NULL;
|
||||
}
|
||||
RIODesc *desc = r_io_desc_open (io, uri, flags, mode);
|
||||
RIODesc *desc = r_io_desc_open (io, uri, perm, mode);
|
||||
if ((io->autofd || !io->desc) && desc) {
|
||||
io->desc = desc;
|
||||
}
|
||||
@ -165,26 +165,26 @@ R_API RIODesc *r_io_open_nomap(RIO *io, const char *uri, int flags, int mode) {
|
||||
}
|
||||
|
||||
/* opens a file and maps it to 0x0 */
|
||||
R_API RIODesc* r_io_open(RIO* io, const char* uri, int flags, int mode) {
|
||||
R_API RIODesc* r_io_open(RIO* io, const char* uri, int perm, int mode) {
|
||||
if (!io || !io->maps) {
|
||||
return NULL;
|
||||
}
|
||||
RIODesc* desc = r_io_open_nomap (io, uri, flags, mode);
|
||||
RIODesc* desc = r_io_open_nomap (io, uri, perm, mode);
|
||||
if (!desc) {
|
||||
return NULL;
|
||||
}
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, 0LL, r_io_desc_size (desc));
|
||||
r_io_map_new (io, desc->fd, desc->perm, 0LL, 0LL, r_io_desc_size (desc));
|
||||
return desc;
|
||||
}
|
||||
|
||||
/* opens a file and maps it to an offset specified by the "at"-parameter */
|
||||
R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int flags, int mode, ut64 at) {
|
||||
R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int perm, int mode, ut64 at) {
|
||||
RIODesc* desc;
|
||||
ut64 size;
|
||||
if (!io || !io->maps) {
|
||||
return NULL;
|
||||
}
|
||||
desc = r_io_open_nomap (io, uri, flags, mode);
|
||||
desc = r_io_open_nomap (io, uri, perm, mode);
|
||||
if (!desc) {
|
||||
return NULL;
|
||||
}
|
||||
@ -192,17 +192,17 @@ R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int flags, int mode, ut64
|
||||
// second map
|
||||
if (size && ((UT64_MAX - size + 1) < at)) {
|
||||
// split map into 2 maps if only 1 big map results into interger overflow
|
||||
io_map_new (io, desc->fd, desc->flags, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1, false);
|
||||
io_map_new (io, desc->fd, desc->perm, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1, false);
|
||||
// someone pls take a look at this confusing stuff
|
||||
size = UT64_MAX - at + 1;
|
||||
}
|
||||
// skyline not updated
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, at, size);
|
||||
r_io_map_new (io, desc->fd, desc->perm, 0LL, at, size);
|
||||
return desc;
|
||||
}
|
||||
|
||||
/* opens many files, without mapping them. This should be discussed */
|
||||
R_API RList* r_io_open_many(RIO* io, const char* uri, int flags, int mode) {
|
||||
R_API RList* r_io_open_many(RIO* io, const char* uri, int perm, int mode) {
|
||||
RList* desc_list;
|
||||
RListIter* iter;
|
||||
RIODesc* desc;
|
||||
@ -213,7 +213,7 @@ R_API RList* r_io_open_many(RIO* io, const char* uri, int flags, int mode) {
|
||||
if (!plugin || !plugin->open_many || !plugin->close) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(desc_list = plugin->open_many (io, uri, flags, mode))) {
|
||||
if (!(desc_list = plugin->open_many (io, uri, perm, mode))) {
|
||||
return NULL;
|
||||
}
|
||||
r_list_foreach (desc_list, iter, desc) {
|
||||
@ -234,7 +234,7 @@ R_API RList* r_io_open_many(RIO* io, const char* uri, int flags, int mode) {
|
||||
return desc_list;
|
||||
}
|
||||
|
||||
R_API bool r_io_reopen(RIO* io, int fd, int flags, int mode) {
|
||||
R_API bool r_io_reopen(RIO* io, int fd, int perm, int mode) {
|
||||
RIODesc *old, *new;
|
||||
char *uri;
|
||||
if (!(old = r_io_desc_get (io, fd))) {
|
||||
@ -246,13 +246,13 @@ R_API bool r_io_reopen(RIO* io, int fd, int flags, int mode) {
|
||||
if (!r_io_desc_close (old)) {
|
||||
return false; // TODO: this is an unrecoverable scenario
|
||||
}
|
||||
if (!(new = r_io_open_nomap (io, uri, flags, mode))) {
|
||||
if (!(new = r_io_open_nomap (io, uri, perm, mode))) {
|
||||
return false;
|
||||
}
|
||||
r_io_desc_exchange (io, old->fd, new->fd);
|
||||
return true;
|
||||
#else
|
||||
if (!(new = r_io_open_nomap (io, uri, flags, mode))) {
|
||||
if (!(new = r_io_open_nomap (io, uri, perm, mode))) {
|
||||
return false;
|
||||
}
|
||||
r_io_desc_exchange (io, old->fd, new->fd);
|
||||
@ -304,7 +304,7 @@ R_API bool r_io_vread_at_mapped(RIO* io, ut64 vaddr, ut8* buf, int len) {
|
||||
if (!io->maps) {
|
||||
return false;
|
||||
}
|
||||
return on_map_skyline (io, vaddr, buf, len, R_IO_READ, fd_read_at_wrap, false);
|
||||
return on_map_skyline (io, vaddr, buf, len, R_PERM_R, fd_read_at_wrap, false);
|
||||
}
|
||||
|
||||
static bool r_io_vwrite_at(RIO* io, ut64 vaddr, const ut8* buf, int len) {
|
||||
@ -314,7 +314,7 @@ static bool r_io_vwrite_at(RIO* io, ut64 vaddr, const ut8* buf, int len) {
|
||||
if (!io->maps) {
|
||||
return false;
|
||||
}
|
||||
return on_map_skyline (io, vaddr, (ut8*)buf, len, R_IO_WRITE, fd_write_at_wrap, false);
|
||||
return on_map_skyline (io, vaddr, (ut8*)buf, len, R_PERM_W, fd_write_at_wrap, false);
|
||||
}
|
||||
|
||||
// Deprecated, use either r_io_read_at_mapped or r_io_nread_at instead.
|
||||
@ -332,7 +332,7 @@ R_API bool r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
} else {
|
||||
ret = r_io_pread_at (io, addr, buf, len) > 0;
|
||||
}
|
||||
if (io->cached & R_IO_READ) {
|
||||
if (io->cached & R_PERM_R) {
|
||||
(void)r_io_cache_read (io, addr, buf, len);
|
||||
}
|
||||
return ret;
|
||||
@ -351,11 +351,11 @@ R_API bool r_io_read_at_mapped(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
memset (buf, io->Oxff, len);
|
||||
}
|
||||
if (io->va) {
|
||||
ret = on_map_skyline (io, addr, buf, len, R_IO_READ, fd_read_at_wrap, false);
|
||||
ret = on_map_skyline (io, addr, buf, len, R_PERM_R, fd_read_at_wrap, false);
|
||||
} else {
|
||||
ret = r_io_pread_at (io, addr, buf, len) > 0;
|
||||
}
|
||||
if (io->cached & R_IO_READ) {
|
||||
if (io->cached & R_PERM_R) {
|
||||
(void)r_io_cache_read(io, addr, buf, len);
|
||||
}
|
||||
return ret;
|
||||
@ -373,11 +373,11 @@ R_API int r_io_nread_at(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
if (io->ff) {
|
||||
memset (buf, io->Oxff, len);
|
||||
}
|
||||
ret = on_map_skyline (io, addr, buf, len, R_IO_READ, fd_read_at_wrap, true);
|
||||
ret = on_map_skyline (io, addr, buf, len, R_PERM_R, fd_read_at_wrap, true);
|
||||
} else {
|
||||
ret = r_io_pread_at (io, addr, buf, len);
|
||||
}
|
||||
if (ret > 0 && io->cached & R_IO_READ) {
|
||||
if (ret > 0 && io->cached & R_PERM_R) {
|
||||
(void)r_io_cache_read (io, addr, buf, len);
|
||||
}
|
||||
return ret;
|
||||
@ -397,7 +397,7 @@ R_API bool r_io_write_at(RIO* io, ut64 addr, const ut8* buf, int len) {
|
||||
mybuf[i] &= io->write_mask[i % io->write_mask_len];
|
||||
}
|
||||
}
|
||||
if (io->cached & R_IO_WRITE) {
|
||||
if (io->cached & R_PERM_W) {
|
||||
ret = r_io_cache_write (io, addr, mybuf, len);
|
||||
} else if (io->va) {
|
||||
ret = r_io_vwrite_at (io, addr, mybuf, len);
|
||||
@ -482,7 +482,7 @@ R_API int r_io_extend_at(RIO* io, ut64 addr, ut64 size) {
|
||||
io->off = cur_off;
|
||||
return ret;
|
||||
}
|
||||
if ((io->desc->flags & R_IO_RW) != R_IO_RW) {
|
||||
if ((io->desc->perm & R_PERM_RW) != R_PERM_RW) {
|
||||
return false;
|
||||
}
|
||||
cur_size = r_io_desc_size (io->desc);
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
typedef struct {
|
||||
const char *uri;
|
||||
int flags;
|
||||
int perm;
|
||||
RIODesc *desc;
|
||||
} FindFile;
|
||||
|
||||
@ -19,17 +19,17 @@ typedef struct {
|
||||
static bool findFile(void *user, void *data, ut32 id) {
|
||||
FindFile *res = (FindFile*)user;
|
||||
RIODesc *desc = (RIODesc*)data;
|
||||
if (desc->flags && res->flags && !strcmp (desc->uri, res->uri)) {
|
||||
if (desc->perm && res->perm && !strcmp (desc->uri, res->uri)) {
|
||||
res->desc = desc;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static RIODesc *findReusableFile(RIO *io, const char *uri, int flags) {
|
||||
static RIODesc *findReusableFile(RIO *io, const char *uri, int perm) {
|
||||
FindFile arg = {
|
||||
.uri = uri,
|
||||
.flags = flags,
|
||||
.perm = perm,
|
||||
.desc = NULL,
|
||||
};
|
||||
r_id_storage_foreach (io->files, findFile, &arg);
|
||||
@ -38,7 +38,7 @@ static RIODesc *findReusableFile(RIO *io, const char *uri, int flags) {
|
||||
|
||||
#else
|
||||
|
||||
static RIODesc *findReusableFile(RIO *io, const char *uri, int flags) {
|
||||
static RIODesc *findReusableFile(RIO *io, const char *uri, int perm) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -55,11 +55,11 @@ bool io_create_mem_map(RIO *io, RIOSection *sec, ut64 at, bool null, bool do_sky
|
||||
ut64 gap = sec->vsize - sec->size;
|
||||
if (null) {
|
||||
uri = r_str_newf ("null://%"PFMT64u, gap);
|
||||
desc = findReusableFile (io, uri, sec->flags);
|
||||
desc = findReusableFile (io, uri, sec->perm);
|
||||
if (desc) {
|
||||
RIOMap *map = r_io_map_get (io, at);
|
||||
if (!map) {
|
||||
io_map_new (io, desc->fd, desc->flags, 0LL, at, gap, false);
|
||||
io_map_new (io, desc->fd, desc->perm, 0LL, at, gap, false);
|
||||
}
|
||||
reused = true;
|
||||
}
|
||||
@ -67,7 +67,7 @@ bool io_create_mem_map(RIO *io, RIOSection *sec, ut64 at, bool null, bool do_sky
|
||||
uri = r_str_newf ("malloc://%"PFMT64u, gap);
|
||||
}
|
||||
if (!desc) {
|
||||
desc = r_io_open_at (io, uri, sec->flags, 664, at);
|
||||
desc = r_io_open_at (io, uri, sec->perm, 0664, at);
|
||||
}
|
||||
free (uri);
|
||||
if (!desc) {
|
||||
@ -93,7 +93,7 @@ bool io_create_mem_map(RIO *io, RIOSection *sec, ut64 at, bool null, bool do_sky
|
||||
|
||||
bool io_create_file_map(RIO *io, RIOSection *sec, ut64 size, bool patch, bool do_skyline) {
|
||||
RIOMap *map = NULL;
|
||||
int flags = 0;
|
||||
int perm = 0;
|
||||
RIODesc *desc;
|
||||
if (!io || !sec) {
|
||||
return false;
|
||||
@ -102,14 +102,14 @@ bool io_create_file_map(RIO *io, RIOSection *sec, ut64 size, bool patch, bool do
|
||||
if (!desc) {
|
||||
return false;
|
||||
}
|
||||
flags = sec->flags;
|
||||
perm = sec->perm;
|
||||
//create file map for patching
|
||||
if (patch) {
|
||||
//add -w to the map for patching if needed
|
||||
//if the file was not opened with -w desc->flags won't have that bit active
|
||||
flags = flags | desc->flags;
|
||||
//if the file was not opened with -w desc->perm won't have that bit active
|
||||
perm = perm | desc->perm;
|
||||
}
|
||||
map = io_map_add (io, sec->fd, flags, sec->paddr, sec->vaddr, size, do_skyline);
|
||||
map = io_map_add (io, sec->fd, perm, sec->paddr, sec->vaddr, size, do_skyline);
|
||||
if (map) {
|
||||
sec->filemap = map->id;
|
||||
map->name = r_str_newf ("fmap.%s", sec->name);
|
||||
@ -162,7 +162,7 @@ R_API bool r_io_is_valid_offset(RIO* io, ut64 offset, int hasperm) {
|
||||
}
|
||||
if (io->va) {
|
||||
if ((map = r_io_map_get (io, offset))) {
|
||||
return ((map->flags & hasperm) == hasperm);
|
||||
return ((map->perm & hasperm) == hasperm);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -172,7 +172,7 @@ R_API bool r_io_is_valid_offset(RIO* io, ut64 offset, int hasperm) {
|
||||
if (r_io_desc_size (io->desc) <= offset) {
|
||||
return false;
|
||||
}
|
||||
return ((io->desc->flags & hasperm) == hasperm);
|
||||
return ((io->desc->perm & hasperm) == hasperm);
|
||||
}
|
||||
|
||||
// this is wrong, there is more than big and little endian
|
||||
|
@ -145,7 +145,7 @@ out:
|
||||
free (deleted);
|
||||
}
|
||||
|
||||
RIOMap* io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
RIOMap* io_map_new(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
if (!size || !io || !io->maps || !io->map_ids) {
|
||||
return NULL;
|
||||
}
|
||||
@ -158,12 +158,12 @@ RIOMap* io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size,
|
||||
map->delta = delta;
|
||||
if ((UT64_MAX - size + 1) < addr) {
|
||||
/// XXX: this is leaking a map!!!
|
||||
io_map_new (io, fd, flags, delta - addr, 0LL, size + addr, do_skyline);
|
||||
io_map_new (io, fd, perm, delta - addr, 0LL, size + addr, do_skyline);
|
||||
size = -(st64)addr;
|
||||
}
|
||||
// RIOMap describes an interval of addresses (map->from; map->to)
|
||||
map->itv = (RInterval){ addr, size };
|
||||
map->flags = flags;
|
||||
map->perm = perm;
|
||||
map->delta = delta;
|
||||
// new map lives on the top, being top the list's tail
|
||||
ls_append (io->maps, map);
|
||||
@ -173,8 +173,8 @@ RIOMap* io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size,
|
||||
return map;
|
||||
}
|
||||
|
||||
R_API RIOMap *r_io_map_new (RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size) {
|
||||
return io_map_new (io, fd, flags, delta, addr, size, true);
|
||||
R_API RIOMap *r_io_map_new (RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) {
|
||||
return io_map_new (io, fd, perm, delta, addr, size, true);
|
||||
}
|
||||
|
||||
R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr) {
|
||||
@ -184,7 +184,7 @@ R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr) {
|
||||
map->itv.addr = addr;
|
||||
if (UT64_MAX - size + 1 < addr) {
|
||||
map->itv.size = -addr;
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, size + addr);
|
||||
r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, size + addr);
|
||||
return true;
|
||||
}
|
||||
io_map_calculate_skyline (io);
|
||||
@ -260,19 +260,19 @@ R_API RIOMap* r_io_map_resolve(RIO* io, ut32 id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RIOMap* io_map_add(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
RIOMap* io_map_add(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
//check if desc exists
|
||||
RIODesc* desc = r_io_desc_get (io, fd);
|
||||
if (desc) {
|
||||
//a map cannot have higher permissions than the desc belonging to it
|
||||
return io_map_new (io, fd, (flags & desc->flags) | (flags & R_IO_EXEC),
|
||||
return io_map_new (io, fd, (perm & desc->perm) | (perm & R_PERM_X),
|
||||
delta, addr, size, do_skyline);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API RIOMap *r_io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size) {
|
||||
return io_map_add (io, fd, flags, delta, addr, size, true);
|
||||
R_API RIOMap *r_io_map_add(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) {
|
||||
return io_map_add (io, fd, perm, delta, addr, size, true);
|
||||
}
|
||||
|
||||
R_API RIOMap* r_io_map_get_paddr(RIO* io, ut64 paddr) {
|
||||
@ -470,7 +470,7 @@ R_API void r_io_map_del_name(RIOMap* map) {
|
||||
}
|
||||
|
||||
//TODO: Kill it with fire
|
||||
R_API RIOMap* r_io_map_add_next_available(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, ut64 load_align) {
|
||||
R_API RIOMap* r_io_map_add_next_available(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size, ut64 load_align) {
|
||||
RIOMap* map;
|
||||
SdbListIter* iter;
|
||||
ut64 next_addr = addr,
|
||||
@ -486,11 +486,11 @@ R_API RIOMap* r_io_map_add_next_available(RIO* io, int fd, int flags, ut64 delta
|
||||
if (map->fd == fd && ((map->itv.addr <= next_addr && next_addr < to) ||
|
||||
r_itv_contain (map->itv, end_addr))) {
|
||||
next_addr = to + (load_align - (to % load_align)) % load_align;
|
||||
return r_io_map_add_next_available (io, fd, flags, delta, next_addr, size, load_align);
|
||||
return r_io_map_add_next_available (io, fd, perm, delta, next_addr, size, load_align);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return r_io_map_new (io, fd, flags, delta, next_addr, size);
|
||||
return r_io_map_new (io, fd, perm, delta, next_addr, size);
|
||||
}
|
||||
|
||||
R_API ut64 r_io_map_next_address(RIO* io, ut64 addr) {
|
||||
@ -534,7 +534,7 @@ R_API bool r_io_map_resize(RIO *io, ut32 id, ut64 newsize) {
|
||||
ut64 addr = map->itv.addr;
|
||||
if (UT64_MAX - newsize + 1 < addr) {
|
||||
map->itv.size = -addr;
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, newsize + addr);
|
||||
r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, newsize + addr);
|
||||
return true;
|
||||
}
|
||||
map->itv.size = newsize;
|
||||
|
@ -8,7 +8,7 @@
|
||||
typedef struct r_io_mmo_t {
|
||||
char * filename;
|
||||
int mode;
|
||||
int flags;
|
||||
int perm;
|
||||
int fd;
|
||||
int opened;
|
||||
bool nocache;
|
||||
@ -18,7 +18,7 @@ typedef struct r_io_mmo_t {
|
||||
int rawio;
|
||||
} RIOMMapFileObj;
|
||||
|
||||
static int __io_posix_open(const char *file, int flags, int mode) {
|
||||
static int __io_posix_open(const char *file, int perm, int mode) {
|
||||
int fd;
|
||||
if (r_str_startswith (file, "file://")) {
|
||||
file += strlen ("file://");
|
||||
@ -28,9 +28,9 @@ static int __io_posix_open(const char *file, int flags, int mode) {
|
||||
}
|
||||
#if __WINDOWS__
|
||||
// probably unnecessary to have this ifdef nowadays windows is posix enough
|
||||
if (flags & R_IO_WRITE) {
|
||||
if (perm & R_PERM_W) {
|
||||
fd = r_sandbox_open (file, O_BINARY | O_RDWR, 0);
|
||||
if (fd == -1 && flags & R_IO_CREAT) {
|
||||
if (fd == -1 && perm & R_PERM_CREAT) {
|
||||
r_sandbox_creat (file, 0644);
|
||||
fd = r_sandbox_open (file, O_BINARY | O_RDWR | O_CREAT, 0);
|
||||
}
|
||||
@ -38,7 +38,7 @@ static int __io_posix_open(const char *file, int flags, int mode) {
|
||||
fd = r_sandbox_open (file, O_BINARY, 0);
|
||||
}
|
||||
#else
|
||||
const int posixFlags = (flags & R_IO_WRITE) ? (flags & R_IO_CREAT)
|
||||
const int posixFlags = (perm & R_PERM_W) ? (perm & R_PERM_CREAT)
|
||||
? (O_RDWR | O_CREAT) : O_RDWR : O_RDONLY;
|
||||
fd = r_sandbox_open (file, posixFlags, mode);
|
||||
#endif
|
||||
@ -90,7 +90,7 @@ static int r_io_def_mmap_refresh_def_mmap_buf(RIOMMapFileObj *mmo) {
|
||||
mmo->rawio = 1;
|
||||
}
|
||||
if (mmo->rawio) {
|
||||
mmo->fd = __io_posix_open (mmo->filename, mmo->flags, mmo->mode);
|
||||
mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode);
|
||||
if (mmo->nocache) {
|
||||
#ifdef F_NOCACHE
|
||||
fcntl (mmo->fd, F_NOCACHE, 1);
|
||||
@ -98,13 +98,13 @@ static int r_io_def_mmap_refresh_def_mmap_buf(RIOMMapFileObj *mmo) {
|
||||
}
|
||||
return (mmo->fd != -1);
|
||||
}
|
||||
mmo->buf = r_buf_mmap (mmo->filename, mmo->flags);
|
||||
mmo->buf = r_buf_mmap (mmo->filename, mmo->perm);
|
||||
if (mmo->buf) {
|
||||
r_io_def_mmap_seek (io, mmo, cur, SEEK_SET);
|
||||
return true;
|
||||
} else {
|
||||
mmo->rawio = 1;
|
||||
mmo->fd = __io_posix_open (mmo->filename, mmo->flags, mmo->mode);
|
||||
mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode);
|
||||
if (mmo->nocache) {
|
||||
#ifdef F_NOCACHE
|
||||
fcntl (mmo->fd, F_NOCACHE, 1);
|
||||
@ -123,7 +123,7 @@ static void r_io_def_mmap_free (RIOMMapFileObj *mmo) {
|
||||
free (mmo);
|
||||
}
|
||||
|
||||
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO *io, const char *filename, int mode, int flags) {
|
||||
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO *io, const char *filename, int mode, int perm) {
|
||||
if (!io) {
|
||||
return NULL;
|
||||
}
|
||||
@ -137,9 +137,9 @@ RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO *io, const char *filename, in
|
||||
}
|
||||
mmo->filename = strdup (filename);
|
||||
mmo->mode = mode;
|
||||
mmo->flags = flags;
|
||||
mmo->perm = perm;
|
||||
mmo->io_backref = io;
|
||||
const int posixFlags = (flags & R_IO_WRITE) ? (flags & R_IO_CREAT)
|
||||
const int posixFlags = (perm & R_PERM_W) ? (perm & R_PERM_CREAT)
|
||||
? (O_RDWR | O_CREAT) : O_RDWR : O_RDONLY;
|
||||
mmo->fd = r_sandbox_open (filename, posixFlags, mode);
|
||||
if (mmo->fd == -1) {
|
||||
@ -288,7 +288,7 @@ static int r_io_def_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count)
|
||||
}
|
||||
|
||||
if (mmo && mmo->buf) {
|
||||
if (!(mmo->flags & R_IO_WRITE)) {
|
||||
if (!(mmo->perm & R_PERM_W)) {
|
||||
return -1;
|
||||
}
|
||||
if ( (count + addr > mmo->buf->length) || mmo->buf->empty) {
|
||||
@ -312,12 +312,12 @@ static int r_io_def_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count)
|
||||
return len;
|
||||
}
|
||||
|
||||
static RIODesc *r_io_def_mmap_open(RIO *io, const char *file, int flags, int mode) {
|
||||
RIOMMapFileObj *mmo = r_io_def_mmap_create_new_file (io, file, mode, flags);
|
||||
static RIODesc *r_io_def_mmap_open(RIO *io, const char *file, int perm, int mode) {
|
||||
RIOMMapFileObj *mmo = r_io_def_mmap_create_new_file (io, file, mode, perm);
|
||||
if (!mmo) {
|
||||
return NULL;
|
||||
}
|
||||
return r_io_desc_new (io, &r_io_plugin_default, mmo->filename, flags, mode, mmo);
|
||||
return r_io_desc_new (io, &r_io_plugin_default, mmo->filename, perm, mode, mmo);
|
||||
}
|
||||
|
||||
|
||||
@ -343,17 +343,17 @@ static bool __plugin_open_default(RIO *io, const char *file, bool many) {
|
||||
}
|
||||
|
||||
// default open should permit opening
|
||||
static RIODesc *__open_default(RIO *io, const char *file, int flags, int mode) {
|
||||
static RIODesc *__open_default(RIO *io, const char *file, int perm, int mode) {
|
||||
if (r_str_startswith (file, "file://")) {
|
||||
file += strlen ("file://");
|
||||
}
|
||||
if (!r_io_def_mmap_check_default (file)) {
|
||||
return NULL;
|
||||
}
|
||||
RIODesc *iod = r_io_def_mmap_open (io, file, flags, mode);
|
||||
RIODesc *iod = r_io_def_mmap_open (io, file, perm, mode);
|
||||
return iod;
|
||||
// NTOE: uncomment this line to support loading files in ro as fallback is rw fails
|
||||
// return iod? iod: r_io_def_mmap_open (io, file, R_IO_READ, mode);
|
||||
// return iod? iod: r_io_def_mmap_open (io, file, R_PERM_R, mode);
|
||||
}
|
||||
|
||||
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
|
||||
@ -377,7 +377,7 @@ static bool __resize(RIO *io, RIODesc *fd, ut64 size) {
|
||||
return false;
|
||||
}
|
||||
RIOMMapFileObj *mmo = fd->data;
|
||||
if (!(mmo->flags & R_IO_WRITE)) {
|
||||
if (!(mmo->perm & R_PERM_W)) {
|
||||
return false;
|
||||
}
|
||||
return r_io_def_mmap_truncate (mmo, size);
|
||||
|
@ -70,7 +70,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
isdev = true;
|
||||
}
|
||||
|
||||
rw |= R_IO_WRITE;
|
||||
rw |= R_PERM_W;
|
||||
if (isdev) {
|
||||
port = strchr (host, '@');
|
||||
if (port) {
|
||||
@ -127,7 +127,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
} else if ((i_pid = desc->pid) < 0) {
|
||||
i_pid = -1;
|
||||
}
|
||||
riogdb = r_io_desc_new (io, &r_io_plugin_gdb, file, R_IO_RWX, mode, riog);
|
||||
riogdb = r_io_desc_new (io, &r_io_plugin_gdb, file, R_PERM_RWX, mode, riog);
|
||||
}
|
||||
// Get name
|
||||
if (riogdb) {
|
||||
|
@ -49,7 +49,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
|
||||
RBufferSparse *rbs;
|
||||
RListIter *iter;
|
||||
|
||||
if (!fd || !fd->data || (fd->flags & R_IO_WRITE) == 0 || count <= 0) {
|
||||
if (!fd || !fd->data || (fd->perm & R_PERM_W) == 0 || count <= 0) {
|
||||
return -1;
|
||||
}
|
||||
rih = fd->data;
|
||||
|
@ -418,10 +418,10 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
: strdup ("kernel");
|
||||
if (!strncmp (file, "smach://", 8)) {
|
||||
ret = r_io_desc_new (io, &r_io_plugin_mach, &file[1],
|
||||
rw | R_IO_EXEC, mode, iodd);
|
||||
rw | R_PERM_X, mode, iodd);
|
||||
} else {
|
||||
ret = r_io_desc_new (io, &r_io_plugin_mach, file,
|
||||
rw | R_IO_EXEC, mode, iodd);
|
||||
rw | R_PERM_X, mode, iodd);
|
||||
}
|
||||
ret->name = pidpath;
|
||||
return ret;
|
||||
|
@ -182,7 +182,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
mal->buf = calloc (1, mal->size + 1);
|
||||
}
|
||||
if (mal->buf) {
|
||||
return r_io_desc_new (io, &r_io_plugin_malloc, pathname, R_IO_RW | rw, mode, mal);
|
||||
return r_io_desc_new (io, &r_io_plugin_malloc, pathname, R_PERM_RW | rw, mode, mal);
|
||||
}
|
||||
eprintf ("Cannot allocate (%s) %d byte(s)\n", pathname + 9, mal->size);
|
||||
free (mal);
|
||||
|
@ -113,7 +113,7 @@ static int r_io_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
|
||||
}
|
||||
mmo = fd->data;
|
||||
addr = io->off;
|
||||
if ( !(mmo->flags & R_IO_WRITE)) {
|
||||
if ( !(mmo->flags & R_PERM_W)) {
|
||||
return -1;
|
||||
}
|
||||
if ( (count + addr > mmo->buf->length) || mmo->buf->empty) {
|
||||
|
@ -205,7 +205,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
}
|
||||
riop->pid = riop->tid = pid;
|
||||
open_pidmem (riop);
|
||||
desc = r_io_desc_new (io, &r_io_plugin_ptrace, file, rw | R_IO_EXEC, mode, riop);
|
||||
desc = r_io_desc_new (io, &r_io_plugin_ptrace, file, rw | R_PERM_X, mode, riop);
|
||||
desc->name = r_sys_pid_to_path (pid);
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,7 @@ static char *r2k__system(RIO *io, RIODesc *fd, const char *cmd) {
|
||||
|
||||
static RIODesc *r2k__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
if (!strncmp (pathname, "r2k://", 6)) {
|
||||
rw |= R_IO_WRITE;
|
||||
rw |= R_IO_EXEC;
|
||||
rw |= R_PERM_WX;
|
||||
#if __WINDOWS__
|
||||
RIOW32 *w32 = R_NEW0 (RIOW32);
|
||||
if (Init (&pathname[6]) == FALSE) {
|
||||
|
@ -23,10 +23,6 @@ void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int
|
||||
#include <process.h> // to compile getpid for msvc windows
|
||||
#endif
|
||||
|
||||
#define PERM_READ 4
|
||||
#define PERM_WRITE 2
|
||||
#define PERM_EXEC 1
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
ut64 from;
|
||||
@ -99,9 +95,9 @@ static int update_self_regions(RIO *io, int pid) {
|
||||
perm = 0;
|
||||
for (i = 0; i < 4 && perms[i]; i++) {
|
||||
switch (perms[i]) {
|
||||
case 'r': perm |= R_IO_READ; break;
|
||||
case 'w': perm |= R_IO_WRITE; break;
|
||||
case 'x': perm |= R_IO_EXEC; break;
|
||||
case 'r': perm |= R_PERM_R; break;
|
||||
case 'w': perm |= R_PERM_W; break;
|
||||
case 'x': perm |= R_PERM_X; break;
|
||||
}
|
||||
}
|
||||
self_sections[self_sections_count].from = r_num_get (NULL, region);
|
||||
@ -145,7 +141,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
|
||||
int left, perm;
|
||||
if (self_in_section (io, io->off, &left, &perm)) {
|
||||
if (perm & R_IO_READ) {
|
||||
if (perm & R_PERM_R) {
|
||||
int newlen = R_MIN (len, left);
|
||||
ut8 *ptr = (ut8*)(size_t)io->off;
|
||||
memcpy (buf, ptr, newlen);
|
||||
@ -156,7 +152,7 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
|
||||
if (fd->flags & R_IO_WRITE) {
|
||||
if (fd->perm & R_PERM_W) {
|
||||
int left, perm;
|
||||
if (self_in_section (io, io->off, &left, &perm)) {
|
||||
int newlen = R_MIN (len, left);
|
||||
@ -480,9 +476,8 @@ void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int
|
||||
|
||||
self_sections[self_sections_count].from = prev_address;
|
||||
self_sections[self_sections_count].to = prev_address+prev_size;
|
||||
self_sections[self_sections_count].perm = PERM_READ; //prev_info.protection;
|
||||
self_sections[self_sections_count].perm = R_PERM_R; //prev_info.protection;
|
||||
self_sections_count++;
|
||||
|
||||
if (nsubregions > 1) {
|
||||
io->cb_printf (" (%d sub-regions)", nsubregions);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||
}
|
||||
pidpath = r_sys_pid_to_path (dbg->pid);
|
||||
ret = r_io_desc_new (io, &r_io_plugin_w32dbg,
|
||||
file, rw | R_IO_EXEC, mode, dbg);
|
||||
file, rw | R_PERM_X, mode, dbg);
|
||||
ret->name = pidpath;
|
||||
return ret;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user