mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 05:09:43 +00:00
Move rasign2 into RMain (#16819) ##tools
* Quote to prevent cmd injection * Added -q,-j,-h and -v options * Remove unneeded includes Co-authored-by: Dennis Goodlett <dennis@hurricanelabs.com>
This commit is contained in:
parent
529e192982
commit
ae04a73774
@ -6,7 +6,7 @@ BTOP=$(shell pwd)
|
||||
|
||||
.PHONY: all clean install install-symlink deinstall uninstall mrproper preload
|
||||
|
||||
BINS=rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarun2 ragg2 r2agent r2r
|
||||
BINS=rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarun2 ragg2 r2agent r2r rasign2
|
||||
|
||||
LIBR2=$(call libname-version,libr2.$(EXT_SO),${LIBVERSION})
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
BIN=rasign2
|
||||
BINDEPS=r_anal r_util r_search
|
||||
BINDEPS=r_anal r_util r_core r_search r_main
|
||||
|
||||
include ../../libr/main/deps.mk
|
||||
include ../rules.mk
|
||||
|
13
binr/rasign2/meson.build
Normal file
13
binr/rasign2/meson.build
Normal file
@ -0,0 +1,13 @@
|
||||
executable('rasign', 'rasign.c',
|
||||
include_directories: [platform_inc],
|
||||
dependencies: [
|
||||
r_util_dep,
|
||||
r_main_dep,
|
||||
r_search_dep,
|
||||
r_core_dep,
|
||||
r_bin_dep,
|
||||
],
|
||||
install: true,
|
||||
install_rpath: rpath,
|
||||
implicit_include_directories: false
|
||||
)
|
@ -1,69 +1,7 @@
|
||||
/* radare - LGPL - Copyright 2009-2019 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_getopt.h>
|
||||
#include <r_main.h>
|
||||
|
||||
#include "r_userconf.h"
|
||||
#include "r_sign.h"
|
||||
|
||||
static int rasign_show_help() {
|
||||
printf ("Usage: rasign2 [options] [file]\n"
|
||||
" -r show output in radare commands\n"
|
||||
" -j show output in json\n"
|
||||
" -s [sigfile] specify one or more signature files\n"
|
||||
"Examples:\n"
|
||||
" rasign2 libc.so.6 > libc.sig\n"
|
||||
" rasign2 -s libc.sig ls.static\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int c;
|
||||
int action = 0;
|
||||
int rad = 0;
|
||||
int json = 0;
|
||||
//RSign *sig = r_sign_new ();
|
||||
|
||||
while ((c=getopt (argc, argv, "o:hrsj:iV")) !=-1) {
|
||||
switch (c) {
|
||||
case 'o':
|
||||
//r_sign_option (&sig, optarg);
|
||||
break;
|
||||
case 's':
|
||||
action = c;
|
||||
//r_sign_load_file (&sig, optarg);
|
||||
break;
|
||||
case 'r':
|
||||
rad = 1;
|
||||
break;
|
||||
case 'j':
|
||||
json = 1;
|
||||
break;
|
||||
case 'V':
|
||||
return blob_version ("rasign2");
|
||||
default:
|
||||
return rasign_show_help ();
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[optind]==NULL)
|
||||
return rasign_show_help ();
|
||||
|
||||
//r_sign_list (sig, rad, json);
|
||||
|
||||
switch (action) {
|
||||
case 's':
|
||||
/* check sigfiles in optarg file */
|
||||
// r_sign_check (&sig, argv[optind]);
|
||||
break;
|
||||
default:
|
||||
/* generate signature file */
|
||||
//r_sign_generate (&sig, argv[optind], stdout);
|
||||
break;
|
||||
}
|
||||
|
||||
//r_sign_free (sig);
|
||||
|
||||
return 0;
|
||||
int main(int argc, const char **argv) {
|
||||
return r_main_rasign2 (argc, argv);
|
||||
}
|
||||
|
@ -31,5 +31,6 @@ R_API int r_main_r2agent(int argc, const char **argv);
|
||||
R_API int r_main_rafind2(int argc, const char **argv);
|
||||
R_API int r_main_radiff2(int argc, const char **argv);
|
||||
R_API int r_main_ragg2(int argc, const char **argv);
|
||||
R_API int r_main_rasign2(int argc, const char **argv);
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,7 @@ OBJS+=rasm2.o
|
||||
OBJS+=ragg2.o
|
||||
OBJS+=rarun2.o
|
||||
OBJS+=rabin2.o
|
||||
OBJS+=rasign2.o
|
||||
OBJS+=rafind2.o
|
||||
OBJS+=r2agent.o
|
||||
OBJS+=radiff2.o
|
||||
|
144
libr/main/rasign2.c
Normal file
144
libr/main/rasign2.c
Normal file
@ -0,0 +1,144 @@
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
#include <r_main.h>
|
||||
#include <r_core.h>
|
||||
|
||||
static void rasign_show_help() {
|
||||
printf ("Usage: rasign2 [options] [file]\n"
|
||||
" -a [-a] add extra 'a' to analysis command\n"
|
||||
" -o sigs.sdb add signatures to file, create if it does not exist\n"
|
||||
" -r show output in radare commands\n"
|
||||
" -j show signatures in json\n"
|
||||
" -q quiet mode\n"
|
||||
" -v show version information\n"
|
||||
" -h help menu\n"
|
||||
"Examples:\n"
|
||||
" rasign2 -o libc.sdb libc.so.6\n");
|
||||
}
|
||||
|
||||
static RCore *opencore(const char *fname) {
|
||||
RCoreFile * rfile = NULL;
|
||||
RCore *c = r_core_new ();
|
||||
if (!c) {
|
||||
eprintf ("Count not get core\n");
|
||||
return NULL;
|
||||
}
|
||||
r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL);
|
||||
r_config_set_i (c->config, "scr.interactive", false);
|
||||
if (fname) {
|
||||
#if __WINDOWS__
|
||||
char *winf = r_acp_to_utf8 (fname);
|
||||
rfile = r_core_file_open (c, winf, 0, 0);
|
||||
free (winf);
|
||||
#else
|
||||
rfile = r_core_file_open (c, fname, 0, 0);
|
||||
#endif
|
||||
|
||||
if (!rfile) {
|
||||
eprintf ("Could not open file %s\n", fname);
|
||||
r_core_free (c);
|
||||
return NULL;
|
||||
}
|
||||
(void)r_core_bin_load (c, NULL, UT64_MAX);
|
||||
(void)r_core_bin_update_arch_bits (c);
|
||||
r_cons_flush ();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static void find_functions(RCore *core, size_t count) {
|
||||
const char *cmd = NULL;
|
||||
switch (count) {
|
||||
case 0: cmd = "aa"; break;
|
||||
case 1: cmd = "aaa"; break;
|
||||
case 2: cmd = "aaaa"; break;
|
||||
}
|
||||
r_core_cmd0 (core, cmd);
|
||||
}
|
||||
|
||||
R_API int r_main_rasign2(int argc, const char **argv) {
|
||||
const char *ofile = NULL;
|
||||
int c;
|
||||
size_t a_cnt = 0;
|
||||
bool rad = false;
|
||||
bool quiet = false;
|
||||
bool json = false;
|
||||
RGetopt opt;
|
||||
|
||||
r_getopt_init (&opt, argc, argv, "ao:rjqvh");
|
||||
while ((c = r_getopt_next (&opt)) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
a_cnt++;
|
||||
break;
|
||||
case 'o':
|
||||
ofile = opt.arg;
|
||||
break;
|
||||
case 'r':
|
||||
rad = true;
|
||||
break;
|
||||
case 'j':
|
||||
json = true;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'v':
|
||||
return r_main_version_print ("rasign2");
|
||||
case 'h':
|
||||
rasign_show_help ();
|
||||
return 0;
|
||||
default:
|
||||
rasign_show_help ();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (a_cnt > 2) {
|
||||
eprintf ("Invalid analysis (too many -a's?)\n");
|
||||
rasign_show_help ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *ifile = NULL;
|
||||
if (opt.ind >= argc) {
|
||||
eprintf ("must provide a file\n");
|
||||
rasign_show_help ();
|
||||
return -1;
|
||||
}
|
||||
ifile = argv[opt.ind];
|
||||
|
||||
// get the core
|
||||
RCore *core = opencore (ifile);
|
||||
if (!core) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// quiet mode
|
||||
if (quiet) {
|
||||
r_config_set (core->config, "scr.interactive", "false");
|
||||
r_config_set (core->config, "scr.prompt", "false");
|
||||
r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED);
|
||||
}
|
||||
|
||||
// run analysis to find functions
|
||||
find_functions (core, a_cnt);
|
||||
|
||||
// create zignatures
|
||||
r_core_cmd0 (core, "zg");
|
||||
|
||||
// write sigs to file
|
||||
if (ofile) {
|
||||
r_core_cmdf (core, "\"zos %s\"", ofile);
|
||||
}
|
||||
|
||||
if (rad) {
|
||||
r_core_flush (core, "z*");
|
||||
}
|
||||
|
||||
if (json) {
|
||||
r_core_flush (core, "zj");
|
||||
}
|
||||
|
||||
r_core_free (core);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user