mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-23 22:36:27 +00:00
Added autoload of zignatures (#8554)
This commit is contained in:
parent
bae2bdd42d
commit
729c528c80
@ -775,6 +775,25 @@ int main(int argc, char **argv, char **envp) {
|
||||
if (run_rc) {
|
||||
radare2_rc (&r);
|
||||
}
|
||||
|
||||
if (r_config_get_i (r.config, "zign.autoload")) {
|
||||
char *path = r_file_abspath (r_config_get (r.config, "dir.zigns"));
|
||||
RList *list = r_sys_dir (path);
|
||||
RListIter *iter;
|
||||
char *file = NULL;
|
||||
r_list_foreach (list, iter, file) {
|
||||
if (file && *file && *file != '.') {
|
||||
if (r_str_endswith (file, "gz")) {
|
||||
r_sign_load_gz (r.anal, file);
|
||||
} else {
|
||||
r_sign_load (r.anal, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
r_list_free (list);
|
||||
free (path);
|
||||
}
|
||||
|
||||
// if (argv[optind] && r_file_is_directory (argv[optind]))
|
||||
if (pfile && r_file_is_directory (pfile)) {
|
||||
if (debug) {
|
||||
|
@ -1210,6 +1210,57 @@ R_API bool r_sign_load(RAnal *a, const char *file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API bool r_sign_load_gz(RAnal *a, const char *filename) {
|
||||
ut8 *buf = NULL;
|
||||
int size = 0;
|
||||
char *tmpfile = NULL;
|
||||
bool retval = true;
|
||||
|
||||
char *path = r_sign_path (a, filename);
|
||||
if (!r_file_exists (path)) {
|
||||
eprintf ("error: file %s does not exist\n", filename);
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(buf = r_file_gzslurp (path, &size, 0))) {
|
||||
eprintf ("error: cannot decompress file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(tmpfile = r_file_temp ("r2zign"))) {
|
||||
eprintf ("error: cannot create temp file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_file_dump (tmpfile, buf, size, 0)) {
|
||||
eprintf ("error: cannot dump file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_sign_load (a, tmpfile)) {
|
||||
eprintf ("error: cannot load file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_file_rm (tmpfile)) {
|
||||
eprintf ("error: cannot delete temp file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
free (buf);
|
||||
free (tmpfile);
|
||||
free (path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
R_API bool r_sign_save(RAnal *a, const char *file) {
|
||||
bool retval = true;
|
||||
|
||||
|
@ -2325,6 +2325,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETPREF ("zign.bytes", "true", "Use bytes patterns for matching");
|
||||
SETPREF ("zign.offset", "true", "Use original offset for matching");
|
||||
SETPREF ("zign.refs", "true", "Use references for matching");
|
||||
SETPREF ("zign.autoload", "false", "Autoload all zignatures located in ~/.config/radare2/zigns");
|
||||
|
||||
/* diff */
|
||||
SETCB ("diff.sort", "addr", &cb_diff_sort, "Specify function diff sorting column see (e diff.sort=?)");
|
||||
|
@ -403,56 +403,6 @@ out_case_fcn:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool loadGzSdb(RAnal *a, const char *filename) {
|
||||
ut8 *buf = NULL;
|
||||
int size = 0;
|
||||
char *tmpfile = NULL;
|
||||
bool retval = true;
|
||||
|
||||
char *path = r_sign_path (a, filename);
|
||||
if (!r_file_exists (path)) {
|
||||
eprintf ("error: file %s does not exist\n", filename);
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(buf = r_file_gzslurp (path, &size, 0))) {
|
||||
eprintf ("error: cannot decompress file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(tmpfile = r_file_temp ("r2zign"))) {
|
||||
eprintf ("error: cannot create temp file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_file_dump (tmpfile, buf, size, 0)) {
|
||||
eprintf ("error: cannot dump file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_sign_load (a, tmpfile)) {
|
||||
eprintf ("error: cannot load file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!r_file_rm (tmpfile)) {
|
||||
eprintf ("error: cannot delete temp file\n");
|
||||
retval = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
free (buf);
|
||||
free (tmpfile);
|
||||
free (path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int cmdOpen(void *data, const char *input) {
|
||||
RCore *core = (RCore *) data;
|
||||
@ -472,7 +422,7 @@ static int cmdOpen(void *data, const char *input) {
|
||||
return false;
|
||||
case 'z':
|
||||
if (input[1] == ' ' && input[2]) {
|
||||
return loadGzSdb (core->anal, input + 2);
|
||||
return r_sign_load_gz (core->anal, input + 2);
|
||||
}
|
||||
eprintf ("usage: zoz filename\n");
|
||||
return false;
|
||||
|
@ -78,6 +78,7 @@ R_API bool r_sign_match_offset(RAnal *a, RAnalFunction *fcn, RSignOffsetMatchCal
|
||||
R_API bool r_sign_match_refs(RAnal *a, RAnalFunction *fcn, RSignRefsMatchCallback cb, void *user);
|
||||
|
||||
R_API bool r_sign_load(RAnal *a, const char *file);
|
||||
R_API bool r_sign_load_gz(RAnal *a, const char *filename);
|
||||
R_API char *r_sign_path(RAnal *a, const char *file);
|
||||
R_API bool r_sign_save(RAnal *a, const char *file);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user