mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-17 04:39:36 +00:00
Use RFile.new instead of R_JOIN in the fortunes code
This commit is contained in:
parent
9f30ab1458
commit
b98cc92046
@ -296,8 +296,9 @@ R_API bool r_anal_set_os(RAnal *anal, const char *os) {
|
||||
return r_anal_set_triplet (anal, os, NULL, -1);
|
||||
}
|
||||
// char *ff = r_str_newf ("types-%s.sdb", os);
|
||||
// char *dbpath = r_file_new (dir_prefix, r2_sdb_fcnsign, ff);
|
||||
char *dbpath = r_str_newf ("%s/%s/types-%s.sdb", dir_prefix, R2_SDB_FCNSIGN, os);
|
||||
// char *dbpath = r_file_new (dir_prefix, r2_sdb_fcnsign, ff, NULL);
|
||||
char *dbpath = r_str_newf ("%s%s%s%stypes-%s.sdb",
|
||||
dir_prefix, R_SYS_DIR, R2_SDB_FCNSIGN, R_SYS_DIR, os);
|
||||
if (r_file_exists (dbpath)) {
|
||||
sdb_concat_by_path (types, dbpath);
|
||||
}
|
||||
|
@ -2977,7 +2977,8 @@ R_API char *r_sign_path(RAnal *a, const char *file) {
|
||||
free (abs);
|
||||
}
|
||||
|
||||
abs = r_str_newf (R_JOIN_3_PATHS ("%s", R2_ZIGNS, "%s"), r_sys_prefix (NULL), file);
|
||||
// abs = r_str_newf (R_JOIN_3_PATHS ("%s", R2_ZIGNS, "%s"), r_sys_prefix (NULL), file);
|
||||
abs = r_file_new (r_sys_prefix (NULL), R2_ZIGNS, file, NULL);
|
||||
if (r_file_is_regular (abs)) {
|
||||
return abs;
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ static void load_scripts_for(RCore *core, const char *name) {
|
||||
// imho nobody uses this: run scripts depending on a specific filetype
|
||||
char *file;
|
||||
RListIter *iter;
|
||||
char *hdir = r_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name);
|
||||
char *hdir = r_str_newf ("%s%s%s%sbin-%s", R2_HOME_BINRC, R_SYS_DIR, "bin-%s", R_SYS_DIR, name);
|
||||
char *path = r_file_home (hdir);
|
||||
RList *files = r_sys_dir (path);
|
||||
if (!r_list_empty (files)) {
|
||||
|
@ -1,18 +1,17 @@
|
||||
/* radare2 - LGPL - Copyright 2009-2023 - pancake, condret */
|
||||
/* radare2 - LGPL - Copyright 2009-2024 - pancake, condret */
|
||||
|
||||
#include <r_core.h>
|
||||
|
||||
static char *getFortuneFile(RCore *core, const char *type) {
|
||||
r_strf_var (fname, 64, "fortunes.%s", type);
|
||||
char *fortunedir = r_xdg_datadir ("fortunes");
|
||||
char *path = r_str_newf (R_JOIN_2_PATHS ("%s", "fortunes.%s"),
|
||||
fortunedir, type);
|
||||
char *path = path = r_file_new (fortunedir, fname, NULL);
|
||||
free (fortunedir);
|
||||
if (path && r_file_exists (path)) {
|
||||
return path;
|
||||
}
|
||||
free (path);
|
||||
path = r_str_newf (R_JOIN_3_PATHS ("%s", R2_FORTUNES, "fortunes.%s"),
|
||||
r_sys_prefix (NULL), type);
|
||||
path = r_file_new (r_sys_prefix (NULL), R2_FORTUNES, fname, NULL);
|
||||
if (path && r_file_exists (path)) {
|
||||
return path;
|
||||
}
|
||||
@ -36,12 +35,12 @@ static bool _push_types(RList *type_list, char *fortune_dir) {
|
||||
return true;
|
||||
}
|
||||
|
||||
R_IPI RList *r_core_fortune_types(void) { // R_API 5.8
|
||||
R_IPI RList *r_core_fortune_types(void) {
|
||||
RList *types = r_list_newf (free);
|
||||
if (!types) {
|
||||
return NULL;
|
||||
}
|
||||
char *fortune_dir = r_str_newf (R_JOIN_2_PATHS ("%s", R2_FORTUNES), r_sys_prefix (NULL));
|
||||
char *fortune_dir = r_file_new (r_sys_prefix (NULL), R2_FORTUNES, NULL);
|
||||
if (!fortune_dir) {
|
||||
r_list_free (types);
|
||||
return NULL;
|
||||
@ -69,6 +68,7 @@ R_API void r_core_fortune_list_types(void) {
|
||||
}
|
||||
|
||||
R_API void r_core_fortune_list(RCore *core) {
|
||||
R_RETURN_IF_FAIL (core);
|
||||
// TODO: use file.fortunes // can be dangerous in sandbox mode
|
||||
const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type");
|
||||
|
||||
@ -135,6 +135,7 @@ static char *getrandomline(RCore *core) {
|
||||
}
|
||||
|
||||
R_API void r_core_fortune_print_random(RCore *core) {
|
||||
R_RETURN_IF_FAIL (core);
|
||||
// TODO: use file.fortunes // can be dangerous in sandbox mode
|
||||
char *line = getrandomline (core);
|
||||
if (!line) {
|
||||
|
@ -1,8 +1,10 @@
|
||||
/* radare - LGPL - Copyright 2010-2022 - nibble, pancake */
|
||||
/* radare - LGPL - Copyright 2010-2024 - nibble, pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
|
||||
// R2_600 -return bool instead of int
|
||||
R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2) {
|
||||
R_RETURN_VAL_IF_FAIL (c, false);
|
||||
RAnalFunction *fa = r_anal_get_function_at (c->anal, addr);
|
||||
RAnalFunction *fb = r_anal_get_function_at (c->anal, addr2);
|
||||
if (!fa || !fb) {
|
||||
@ -35,6 +37,7 @@ R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2) {
|
||||
|
||||
/* Fingerprint functions and blocks, then diff. */
|
||||
R_API bool r_core_gdiff(RCore *c, RCore *c2) {
|
||||
// R_RETURN_VAL_IF_FAIL (c && c2, false);
|
||||
RCore *cores[2] = {c, c2};
|
||||
RAnalFunction *fcn;
|
||||
RAnalBlock *bb;
|
||||
@ -45,7 +48,7 @@ R_API bool r_core_gdiff(RCore *c, RCore *c2) {
|
||||
return false;
|
||||
}
|
||||
if (c == c2) {
|
||||
eprintf ("sama\n");
|
||||
R_LOG_ERROR ("Can't diff over the same core instance");
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
@ -77,6 +80,7 @@ R_API bool r_core_gdiff(RCore *c, RCore *c2) {
|
||||
static void diffrow(ut64 addr, const char *name, ut32 size, int maxnamelen,
|
||||
int digits, ut64 addr2, const char *name2, ut32 size2,
|
||||
const char *match, double dist, int bare) {
|
||||
// TODO: use RCons.printf
|
||||
if (bare) {
|
||||
if (addr2 == UT64_MAX || !name2) {
|
||||
printf ("0x%016"PFMT64x" |%8s (%f)\n", addr, match, dist);
|
||||
@ -149,6 +153,7 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) {
|
||||
default:
|
||||
match = "NEW";
|
||||
f->diff->dist = 0;
|
||||
break;
|
||||
}
|
||||
diffrow (f->addr, f->name, r_anal_function_linear_size (f), maxnamelen, digits,
|
||||
f->diff->addr, f->diff->name, f->diff->size,
|
||||
@ -204,7 +209,6 @@ R_API void r_core_diff_show_json(RCore *c, RCore *c2) {
|
||||
match = "NEW";
|
||||
f->diff->dist = 0;
|
||||
}
|
||||
|
||||
pj_o (pj);
|
||||
pj_kn (pj, "addr", f->addr);
|
||||
pj_ks (pj, "name", f->name? f->name: "");
|
||||
@ -240,6 +244,7 @@ R_API void r_core_diff_show_json(RCore *c, RCore *c2) {
|
||||
pj_end (pj);
|
||||
|
||||
char *s = pj_drain (pj);
|
||||
// XXX Use RCons instead
|
||||
printf ("%s\n", s);
|
||||
free (s);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2011-2023 - pancake */
|
||||
/* radare - LGPL - Copyright 2011-2024 - pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
|
||||
@ -303,7 +303,7 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) {
|
||||
}
|
||||
|
||||
R_API bool r_core_hack(RCore *core, const char *op) {
|
||||
r_return_val_if_fail (core && op, false);
|
||||
R_RETURN_VAL_IF_FAIL (core && op, false);
|
||||
bool (*hack)(RCore *core, const char *op, const RAnalOp *analop) = NULL;
|
||||
const char *asmarch = r_config_get (core->config, "asm.arch");
|
||||
const int asmbits = core->rasm->config->bits;
|
||||
@ -353,14 +353,15 @@ R_API bool r_core_hack(RCore *core, const char *op) {
|
||||
R_LOG_WARN ("Write hacks are only implemented for x86, arm32, arm64 and dalvik");
|
||||
}
|
||||
if (hack) {
|
||||
RAnalOp aop = {0};
|
||||
aop.addr = core->offset;
|
||||
RAnalOp aop = { .addr = core->offset };
|
||||
r_anal_op_set_bytes (&aop, core->offset, core->block, 4);
|
||||
// TODO: use r_arch_decode
|
||||
if (!r_anal_op (core->anal, &aop, core->offset, core->block, core->blocksize, R_ARCH_OP_MASK_BASIC)) {
|
||||
R_LOG_ERROR ("anal op fail");
|
||||
r_anal_op_fini (&aop);
|
||||
return false;
|
||||
}
|
||||
r_anal_op_fini (&aop);
|
||||
bool res = hack (core, op, &aop);
|
||||
if (doseek) {
|
||||
r_core_seek (core, core->offset + aop.size, 1);
|
||||
|
@ -574,8 +574,7 @@ static RList *get_blobs(Rvc *rvc, RList *ignore) {
|
||||
RListIter *i;
|
||||
char *hash;
|
||||
r_list_foreach (commits, i, hash) {
|
||||
char *commit_path = r_file_new (rvc->path, ".rvc", "commits",
|
||||
hash, NULL);
|
||||
char *commit_path = r_file_new (rvc->path, ".rvc", "commits", hash, NULL);
|
||||
if (!commit_path) {
|
||||
goto fail_ret;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ cd "$(dirname $0)"/..
|
||||
(git grep -n 'cmp(' libr | grep -v "R_API" | grep -v "R_IPI" |grep -v static | grep c:) && exit 1
|
||||
# (git grep -n 'len(' libr | grep -v R_API | grep -v static | grep c:) && exit 1
|
||||
# (git grep -n ',"' libr | grep -v R_API | grep -v static | grep c:) && exit 1
|
||||
(git grep r_file_new | grep -v ", NULL" | grep '"')
|
||||
(git grep -n 'for(' libr | grep -v _for | grep -v colorfor) && exit 1
|
||||
(git grep -n 'for (' libr | grep "; ++" | grep -v arch ) && exit 1
|
||||
(git grep -n 'for (int' | grep -v sys/) && exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user