mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-04 04:17:25 +00:00
Pass R2_CONFIG file to ! commands and serialize methods ##config
This commit is contained in:
parent
595cb21ad4
commit
fd1f980eca
@ -29,7 +29,7 @@ matrix:
|
||||
env: COMPILER_NAME=gcc CXX=g++ CC=gcc INSTALL_SYSTEM=meson COVERAGE=1 CFLAGS="-DR2_ASSERT_STDOUT=1"
|
||||
# OS X with clang
|
||||
- os: osx
|
||||
env: COMPILER_NAME=clang CXX=clang++ CC=clang CFLAGS="-DR2_ASSERT_STDOUT=1" LC_ALL=C
|
||||
env: COMPILER_NAME=clang CXX=clang++ CC=clang CFLAGS="-DR2_ASSERT_STDOUT=1"
|
||||
# Run Fuzzing Sanity Test on every push
|
||||
# XXX its broken it complains about invalid key
|
||||
#- os: linux
|
||||
|
@ -693,3 +693,26 @@ R_API void r_config_bump(RConfig *cfg, const char *key) {
|
||||
free (orig);
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db) {
|
||||
RListIter *iter;
|
||||
RConfigNode *node;
|
||||
r_list_foreach (config->nodes, iter, node) {
|
||||
sdb_set (db, node->name, node->value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int load_config_cb(void *user, const char *k, const char *v) {
|
||||
RConfig *config = user;
|
||||
RConfigNode *node = r_config_node_get (config, k);
|
||||
if (!node) {
|
||||
return 1;
|
||||
}
|
||||
r_config_set (config, k, v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
R_API bool r_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err) {
|
||||
sdb_foreach (db, load_config_cb, config);
|
||||
return true;
|
||||
}
|
||||
|
@ -208,6 +208,14 @@ R_API void r_core_sysenv_end(RCore *core, const char *cmd) {
|
||||
r_sys_setenv ("R2_FILE", NULL);
|
||||
r_sys_setenv ("R2_BYTES", NULL);
|
||||
r_sys_setenv ("R2_OFFSET", NULL);
|
||||
|
||||
// remove temporary R2_CONFIG file
|
||||
char *r2_config = r_sys_getenv ("R2_CONFIG");
|
||||
if (r2_config) {
|
||||
r_file_rm (r2_config);
|
||||
r_sys_setenv ("R2_CONFIG", NULL);
|
||||
free (r2_config);
|
||||
}
|
||||
}
|
||||
|
||||
#if DISCUSS
|
||||
@ -238,12 +246,24 @@ R_API char *r_core_sysenv_begin(RCore * core, const char *cmd) {
|
||||
}
|
||||
}
|
||||
}
|
||||
r_sys_setenv ("RABIN2_LANG", r_config_get (core->config, "bin.lang"));
|
||||
r_sys_setenv ("RABIN2_DEMANGLE", r_config_get (core->config, "bin.demangle"));
|
||||
r_sys_setenv ("R2_OFFSET", sdb_fmt ("%"PFMT64d, core->offset));
|
||||
r_sys_setenv ("R2_XOFFSET", sdb_fmt ("0x%08"PFMT64x, core->offset));
|
||||
r_sys_setenv ("R2_ENDIAN", core->assembler->big_endian? "big": "little");
|
||||
r_sys_setenv ("R2_BSIZE", sdb_fmt ("%d", core->blocksize));
|
||||
|
||||
// dump current config file so other r2 tools can use the same options
|
||||
char *config_sdb_path = NULL;
|
||||
int config_sdb_fd = r_file_mkstemp (NULL, &config_sdb_path);
|
||||
close (config_sdb_fd);
|
||||
|
||||
Sdb *config_sdb = sdb_new (NULL, config_sdb_path, 0);
|
||||
r_config_serialize (core->config, config_sdb);
|
||||
sdb_sync (config_sdb);
|
||||
sdb_free (config_sdb);
|
||||
r_sys_setenv ("R2_CONFIG", config_sdb_path);
|
||||
|
||||
r_sys_setenv ("RABIN2_LANG", r_config_get (core->config, "bin.lang"));
|
||||
r_sys_setenv ("RABIN2_DEMANGLE", r_config_get (core->config, "bin.demangle"));
|
||||
r_sys_setenv ("R2_ARCH", r_config_get (core->config, "asm.arch"));
|
||||
r_sys_setenv ("R2_BITS", sdb_fmt ("%d", r_config_get_i (core->config, "asm.bits")));
|
||||
r_sys_setenv ("R2_COLOR", r_config_get_i (core->config, "scr.color")? "1": "0");
|
||||
|
@ -95,6 +95,9 @@ R_API bool r_config_readonly (RConfig *cfg, const char *key);
|
||||
R_API void r_config_set_sort_column (char *column);
|
||||
R_API bool r_config_set_setter (RConfig *cfg, const char *key, RConfigCallback cb);
|
||||
R_API bool r_config_set_getter (RConfig *cfg, const char *key, RConfigCallback cb);
|
||||
|
||||
R_API void r_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db);
|
||||
R_API bool r_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -94,7 +94,8 @@ static int rabin_show_help(int v) {
|
||||
" RABIN2_DMNGLRCMD: e bin.demanglercmd # try to purge false positives\n"
|
||||
" RABIN2_PDBSERVER: e pdb.server # use alternative PDB server\n"
|
||||
" RABIN2_SYMSTORE: e pdb.symstore # path to downstream symbol store\n"
|
||||
" RABIN2_PREFIX: e bin.prefix # prefix symbols/sections/relocs with a specific string\n");
|
||||
" RABIN2_PREFIX: e bin.prefix # prefix symbols/sections/relocs with a specific string\n"
|
||||
" R2_CONFIG: # sdb config file\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -590,6 +591,16 @@ R_API int r_main_rabin2(int argc, char **argv) {
|
||||
}
|
||||
free (tmp);
|
||||
|
||||
if ((tmp = r_sys_getenv ("R2_CONFIG"))) {
|
||||
Sdb *config_sdb = sdb_new (NULL, tmp, 0);
|
||||
if (config_sdb) {
|
||||
r_config_unserialize (core.config, config_sdb, NULL);
|
||||
sdb_free (config_sdb);
|
||||
} else {
|
||||
printf ("Cannot open file specified in RADARE2_CONFIG\n");
|
||||
}
|
||||
free (tmp);
|
||||
}
|
||||
if ((tmp = r_sys_getenv ("RABIN2_DMNGLRCMD"))) {
|
||||
r_config_set (core.config, "bin.demanglecmd", tmp);
|
||||
free (tmp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user