Skip to content

Commit

Permalink
Initial purge of R2_PREFIX towards dir.prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jan 16, 2018
1 parent 0d872e9 commit 303820d
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 80 deletions.
18 changes: 9 additions & 9 deletions binr/radare2/radare2.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ static int main_help(int line) {
char *homedir = r_str_home (R2_HOMEDIR);
printf (
"Scripts:\n"
" system "R2_PREFIX"/share/radare2/radare2rc\n"
" user ~/.radare2rc ${RHOMEDIR}/radare2/radare2rc (and radare2rc.d/)\n"
" file ${filename}.r2\n"
" system ${R2_PREFIX}/share/radare2/radare2rc\n"
" user ~/.radare2rc ${RHOMEDIR}/radare2/radare2rc (and radare2rc.d/)\n"
" file ${filename}.r2\n"
"Plugins:\n"
" binrc ~/.config/radare2/rc.d/bin-<format>/ (elf, elf64, mach0, ..)\n"
" plugins "R2_PREFIX"/lib/radare2/last\n"
" binrc ~/.config/radare2/rc.d/bin-<format>/ (elf, elf64, mach0, ..)\n"
" plugins "R2_PREFIX"/lib/radare2/last\n"
" USER_PLUGINS ~/.config/radare2/plugins\n"
" LIBR_PLUGINS "R2_PREFIX"/lib/radare2/"R2_VERSION"\n"
" USER_ZIGNS ~/.config/radare2/zigns\n"
Expand All @@ -168,10 +168,10 @@ static int main_help(int line) {
" VAPIDIR path to extra vapi directory\n"
" R2_NOPLUGINS do not load r2 shared plugins\n"
"Paths:\n"
" PREFIX "R2_PREFIX"\n"
" INCDIR "R2_INCDIR"\n"
" LIBDIR "R2_LIBDIR"\n"
" LIBEXT "R_LIB_EXT"\n"
" R2_PREFIX "R2_PREFIX"\n"
" R2_INCDIR "R2_INCDIR"\n"
" R2_LIBDIR "R2_LIBDIR"\n"
" R2_LIBEXT "R_LIB_EXT"\n"
, homedir);
free (homedir);
}
Expand Down
10 changes: 6 additions & 4 deletions libr/anal/anal.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */

#include <r_anal.h>
#include <r_util.h>
Expand Down Expand Up @@ -229,13 +229,15 @@ R_API bool r_anal_set_reg_profile(RAnal *anal) {
}

R_API bool r_anal_set_fcnsign(RAnal *anal, const char *name) {
#define FCNSIGNPATH R2_PREFIX "/share/radare2/" R2_VERSION "/fcnsign"
#define FCNSIGNPATH "share/radare2/" R2_VERSION "/fcnsign"
const char *dirPrefix = anal->coreb.cfgGet
? anal->coreb.cfgGet (anal->coreb.core, "dir.prefix") : R2_PREFIX;
char *file = NULL;
const char *arch = (anal->cur && anal->cur->arch) ? anal->cur->arch : R_SYS_ARCH;
if (name && *name) {
file = sdb_fmt (0, "%s/%s.sdb", FCNSIGNPATH, name);
file = sdb_fmt (0, "%s/%s/%s.sdb", dirPrefix, FCNSIGNPATH, name);
} else {
file = sdb_fmt (0, "%s/%s-%s-%d.sdb", FCNSIGNPATH,
file = sdb_fmt (0, "%s/%s/%s-%s-%d.sdb", dirPrefix, FCNSIGNPATH,
anal->os, arch, anal->bits);
}
if (r_file_exists (file)) {
Expand Down
7 changes: 4 additions & 3 deletions libr/anal/sign.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */

#include <r_anal.h>
#include <r_sign.h>
Expand Down Expand Up @@ -1180,8 +1180,9 @@ R_API char *r_sign_path(RAnal *a, const char *file) {
free (abs);
}

const char *pfx = R2_PREFIX "/share/radare2/" R2_VERSION "/zigns";
abs = r_str_newf ("%s%s%s", pfx, R_SYS_DIR, file);
/// XXX mixed / and R_SYS_DIR
const char *pfx = "/share/radare2/" R2_VERSION "/zigns";
abs = r_str_newf ("%s%s%s%s", a->coreb.cfgGet (a->coreb.core, "dir.prefix"), pfx, R_SYS_DIR, file);
if (r_file_is_regular (abs)) {
return abs;
}
Expand Down
18 changes: 12 additions & 6 deletions libr/asm/asm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */

#include <stdio.h>
#include <r_core.h>
Expand All @@ -8,6 +8,8 @@
#include <spp/spp.h>
#include <config.h>

#define R_ASM_OPCODES_PATH "/share/radare2/" R2_VERSION "/opcodes"

R_LIB_VERSION (r_asm);

char *directives[] = {
Expand Down Expand Up @@ -35,7 +37,7 @@ static int r_asm_pseudo_string(RAsmOp *op, char *input, int zero) {
if (*input == '"') {
input++;
}
len = r_str_unescape (input)+zero;
len = r_str_unescape (input) + zero;
r_hex_bin2str ((ut8*)input, len, op->buf_hex);
strncpy ((char*)op->buf, input, R_ASM_BUFSIZE - 1);
return len;
Expand Down Expand Up @@ -124,11 +126,14 @@ static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) {
int i, repeat=0, size=0, value=0;
sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use r_num?
size *= repeat;
if (size>0) {
for (i=0; i<size; i++)
if (size > 0) {
for (i = 0; i < size; i++) {
op->buf[i] = value;
}
r_hex_bin2str (op->buf, size, op->buf_hex);
} else size = 0;
} else {
size = 0;
}
return size;
}

Expand Down Expand Up @@ -270,6 +275,7 @@ R_API bool r_asm_use_assembler(RAsm *a, const char *name) {

// TODO: this can be optimized using r_str_hash()
R_API int r_asm_use(RAsm *a, const char *name) {
const char *dirPrefix = a->coreb.cfgGet ? a->coreb.cfgGet (a->coreb.core, "dir.prefix"): R2_PREFIX;
char file[1024];
RAsmPlugin *h;
RListIter *iter;
Expand All @@ -281,7 +287,7 @@ R_API int r_asm_use(RAsm *a, const char *name) {
if (!a->cur || (a->cur && strcmp (a->cur->arch, h->arch))) {
//const char *dop = r_config_get (core->config, "dir.opcodes");
// TODO: allow configurable path for sdb files
snprintf (file, sizeof (file), R_ASM_OPCODES_PATH"/%s.sdb", h->arch);
snprintf (file, sizeof (file), "%s/"R_ASM_OPCODES_PATH"/%s.sdb", dirPrefix, h->arch);
sdb_free (a->pair);
r_asm_set_cpu (a, NULL);
a->pair = sdb_new (NULL, file, 0);
Expand Down
3 changes: 2 additions & 1 deletion libr/bin/format/pe/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin,
filename = sdb_fmt (1, "share/radare2/"R2_VERSION "/format/dll/%s.sdb", symdllname);
}
#else
filename = sdb_fmt (1, R2_PREFIX "/share/radare2/" R2_VERSION "/format/dll/%s.sdb", symdllname);
const char *dirPrefix = R2_PREFIX; // XXX must be configurable
filename = sdb_fmt (1, "%s/share/radare2/" R2_VERSION "/format/dll/%s.sdb", dirPrefix, symdllname);
#endif
if (r_file_exists (filename)) {
db = sdb_new (NULL, filename, 0);
Expand Down
49 changes: 29 additions & 20 deletions libr/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <r_core.h>
#include "r_util.h"

#define DBSPATH "/share/radare2/" R2_VERSION "/fcnsign"
#define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz)))

#define VA_FALSE 0
Expand Down Expand Up @@ -597,7 +598,6 @@ static int is_executable(RBinObject *obj) {
return false;
}

#define DBSPATH R2_PREFIX "/share/radare2/" R2_VERSION "/fcnsign"
static void sdb_concat_by_path(Sdb *s, const char *path) {
Sdb *db = sdb_new (0, path, 0);
sdb_merge (s, db);
Expand All @@ -608,6 +608,7 @@ static void sdb_concat_by_path(Sdb *s, const char *path) {
R_API void r_core_anal_type_init(RCore *core) {
Sdb *types = NULL;
const char *anal_arch = NULL, *os = NULL;
const char *dir_prefix = r_config_get (core->config, "dir.prefix");
int bits = 0;
char *dbpath;
if (!core || !core->anal) {
Expand All @@ -619,35 +620,36 @@ R_API void r_core_anal_type_init(RCore *core) {
sdb_reset (types);
anal_arch = r_config_get (core->config, "anal.arch");
os = r_config_get (core->config, "asm.os");
if (r_file_exists (DBSPATH"/types.sdb")) {
sdb_concat_by_path (types, DBSPATH"/types.sdb");
// spaguetti ahead
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types.sdb", dir_prefix);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s.sdb", anal_arch);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s.sdb", dir_prefix, anal_arch);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s.sdb", os);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s.sdb", dir_prefix, os);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%d.sdb", bits);

dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%d.sdb", dir_prefix, bits);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s-%d.sdb", os, bits);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s-%d.sdb", dir_prefix, os, bits);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s-%d.sdb", anal_arch, bits);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s-%d.sdb", dir_prefix, anal_arch, bits);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s-%s.sdb", anal_arch, os);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s-%s.sdb", dir_prefix, anal_arch, os);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
dbpath = sdb_fmt (-1, DBSPATH"/types-%s-%s-%d.sdb", anal_arch, os, bits);
dbpath = sdb_fmt (-1, "%s/"DBSPATH"/types-%s-%s-%d.sdb", dir_prefix, anal_arch, os, bits);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (types, dbpath);
}
Expand All @@ -670,6 +672,7 @@ R_API void r_core_anal_cc_init(RCore *core) {
sdb_new0 (),
core->anal->sdb_cc
};
const char *dir_prefix = r_config_get (core->config, "dir.prefix");
//save pointers and values stored inside them
//to recover from freeing heeps
const char *defaultcc = sdb_const_get (sdbs[1], "default.cc", 0);
Expand All @@ -683,7 +686,7 @@ R_API void r_core_anal_cc_init(RCore *core) {
bits = 32;
}

char *dbpath = sdb_fmt (-1, DBSPATH"/cc-%s-%d.sdb", anal_arch, bits);
char *dbpath = sdb_fmt (-1, "%s/"DBSPATH"/cc-%s-%d.sdb", dir_prefix, anal_arch, bits);
if (r_file_exists (dbpath)) {
sdb_concat_by_path (core->anal->sdb_cc, dbpath);
}
Expand Down Expand Up @@ -1335,18 +1338,24 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char
if (r_file_exists (filename)) {
*db = sdb_new (NULL, filename, 0);
} else {
// XXX. we have dir.prefix, windows shouldnt work different
filename = sdb_fmt (1, "%s/share/radare2/" R2_VERSION"/format/dll/%s.sdb", r_config_get (r->config, "dir.prefix"), module);
if (r_file_exists (filename)) {
*db = sdb_new (NULL, filename, 0);
#if __WINDOWS__
char invoke_dir[MAX_PATH];
if (r_sys_get_src_dir_w32(invoke_dir)) {
filename = sdb_fmt (1, "%s/share/radare2/"R2_VERSION "/format/dll/%s.sdb", invoke_dir, module);
} else {
filename = sdb_fmt (1, "share/radare2/"R2_VERSION"/format/dll/%s.sdb", module);
}
char invoke_dir[MAX_PATH];
if (r_sys_get_src_dir_w32 (invoke_dir)) {
filename = sdb_fmt (1, "%s/share/radare2/"R2_VERSION "/format/dll/%s.sdb", invoke_dir, module);
} else {
filename = sdb_fmt (1, "share/radare2/"R2_VERSION"/format/dll/%s.sdb", module);
}
#else
filename = sdb_fmt (1, R2_PREFIX"/share/radare2/" R2_VERSION"/format/dll/%s.sdb", module);
filename = sdb_fmt (1, "%s/share/radare2/" R2_VERSION"/format/dll/%s.sdb", r_config_get (r->config, "dir.prefix"), module);
if (r_file_exists (filename)) {
*db = sdb_new (NULL, filename, 0);
}
#endif
if (r_file_exists (filename)) {
*db = sdb_new (NULL, filename, 0);
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions libr/core/cconfig.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake */
/* radare - LGPL - Copyright 2009-2018 - pancake */

#include <r_core.h>

Expand Down Expand Up @@ -858,7 +858,9 @@ static int cb_bigendian(void *user, void *data) {
// Set anal endianness the same as asm
r_anal_set_big_endian (core->anal, isbig);
// the big endian should also be assigned to dbg->bp->endian
core->dbg->bp->endian = isbig;
if (core->dbg && core->dbg->bp) {
core->dbg->bp->endian = isbig;
}
// Set printing endian to user's choice
core->print->big_endian = node->i_value;
return true;
Expand Down Expand Up @@ -2109,9 +2111,11 @@ static int cb_malloc(void *user, void *data) {
RCore *core = (RCore*) user;
RConfigNode *node = (RConfigNode*) data;

if (node->value){
if (node->value) {
if (!strcmp ("jemalloc", node->value) || !strcmp ("glibc", node->value)) {
core->dbg->malloc = data;
if (core->dbg) {
core->dbg->malloc = data;
}
}

}
Expand Down Expand Up @@ -2159,6 +2163,15 @@ R_API int r_core_config_init(RCore *core) {
}
cfg->cb_printf = r_cons_printf;
cfg->num = core->num;
/* dir.prefix is used in other modules, set it first */
{
char *pfx = r_sys_getenv("R2_PREFIX");
if (!pfx) {
pfx = strdup (R2_PREFIX);
}
SETPREF ("dir.prefix", pfx, "Default prefix r2 was compiled for");
free (pfx);
}
/* pdb */
SETPREF ("pdb.useragent", "Microsoft-Symbol-Server/6.11.0001.402", "User agent for Microsoft symbol server");
SETPREF ("pdb.server", "https://msdl.microsoft.com/download/symbols", "Base URL for Microsoft symbol server");
Expand Down
23 changes: 16 additions & 7 deletions libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ static int cfggeti(RCore *core, const char *k) {
return r_config_get_i (core->config, k);
}

static const char *cfgget(RCore *core, const char *k) {
return r_config_get (core->config, k);
}

R_API int r_core_bind(RCore *core, RCoreBind *bnd) {
bnd->core = core;
bnd->bphit = (RCoreDebugBpHit)r_core_debug_breakpoint_hit;
Expand All @@ -257,6 +261,7 @@ R_API int r_core_bind(RCore *core, RCoreBind *bnd) {
bnd->getNameDelta = (RCoreGetNameDelta)getNameDelta;
bnd->archbits = (RCoreSeekArchBits)archbits;
bnd->cfggeti = (RCoreConfigGetI)cfggeti;
bnd->cfgGet = (RCoreConfigGet)cfgget;
return true;
}

Expand Down Expand Up @@ -1792,6 +1797,15 @@ R_API bool r_core_init(RCore *core) {
core->asmqjmps = R_NEWS (ut64, core->asmqjmps_size);
}

core->file = NULL;
core->files = r_list_newf ((RListFree)r_core_file_free);
core->offset = 0LL;
r_core_cmd_init (core);
core->dbg = r_debug_new (true);

// initialize config before any corebind
r_core_config_init (core);

r_bin_bind (core->bin, &(core->assembler->binb));
r_bin_bind (core->bin, &(core->anal->binb));
r_bin_bind (core->bin, &(core->anal->binb));
Expand All @@ -1804,13 +1818,10 @@ R_API bool r_core_init(RCore *core) {
r_io_bind (core->io, &(core->bin->iob));
r_flag_bind (core->flags, &(core->anal->flb));
r_anal_bind (core->anal, &(core->parser->analb));

r_core_bind (core, &(core->anal->coreb));
r_core_bind (core, &(core->assembler->coreb));

core->file = NULL;
core->files = r_list_newf ((RListFree)r_core_file_free);
core->offset = 0LL;
r_core_cmd_init (core);
core->dbg = r_debug_new (true);
r_io_bind (core->io, &(core->dbg->iob));
r_io_bind (core->io, &(core->dbg->bp->iob));
r_core_bind (core, &core->dbg->corebind);
Expand All @@ -1823,8 +1834,6 @@ R_API bool r_core_init(RCore *core) {
core->dbg->cb_printf = r_cons_printf;
core->dbg->bp->cb_printf = r_cons_printf;

r_core_config_init (core);

r_core_loadlibs_init (core);
//r_core_loadlibs (core);

Expand Down
Loading

0 comments on commit 303820d

Please sign in to comment.