Rename r2 to rizin

This commit is contained in:
Anton Kochkov 2020-11-05 16:15:15 +08:00 committed by Anton Kochkov
parent 8e7fa80e97
commit afc45bec46
24 changed files with 172 additions and 504 deletions

View file

@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.
PROJECT_NAME = Radare2
PROJECT_NAME = Rizin
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
@ -51,7 +51,7 @@ PROJECT_BRIEF = "unix-like reverse engineering framework and cli tools"
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
# the logo to the output directory.
#PROJECT_LOGO = doc/images/r2.svg
#PROJECT_LOGO = doc/images/rizin.svg
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
# into which the generated documentation will be written. If a relative path is

View file

@ -7,15 +7,15 @@
#include <emscripten.h>
static RzCore *core = NULL;
void *r2_asmjs_new(const char *cmd) {
void *rz_asmjs_new(const char *cmd) {
return rz_core_new ();
}
void r2_asmjs_free(void *core) {
void rz_asmjs_free(void *core) {
rz_core_free (core);
}
char *r2_asmjs_cmd(void *kore, const char *cmd) {
char *rz_asmjs_cmd(void *kore, const char *cmd) {
if (kore) {
if (!cmd) {
rz_core_free (kore);
@ -34,7 +34,7 @@ static void wget_cb(const char *f) {
rz_core_cmdf (core, "o %s", f);
}
void r2_asmjs_openurl(void *kore, const char *url) {
void rz_asmjs_openurl(void *kore, const char *url) {
const char *file = rz_str_lchr (url, '/');
if (kore) {
core = kore;

View file

@ -897,7 +897,7 @@ static RzTestProcessOutput *run_rz_test(RzTestRunConfig *config, ut64 timeout_ms
#else
size_t env_size = load_plugins ? 0 : 1;
#endif
RzTestProcessOutput *out = runner (config->r2_cmd, args.v.a, rz_pvector_len (&args), envvars, envvals, env_size, timeout_ms, user);
RzTestProcessOutput *out = runner (config->rz_cmd, args.v.a, rz_pvector_len (&args), envvars, envvals, env_size, timeout_ms, user);
rz_pvector_clear (&args);
#if __WINDOWS__
free (wcmds);

View file

@ -284,7 +284,7 @@ int main(int argc, char **argv) {
ut64 time_start = rz_time_now_mono ();
RzTestState state = {{0}};
state.run_config.r2_cmd = rizin_cmd ? rizin_cmd : RIZIN_CMD_DEFAULT;
state.run_config.rz_cmd = rizin_cmd ? rizin_cmd : RIZIN_CMD_DEFAULT;
state.run_config.rz_asm_cmd = rz_asm_cmd ? rz_asm_cmd : RZ_ASM_CMD_DEFAULT;
state.run_config.json_test_file = json_test_file ? json_test_file : JSON_TEST_FILE_DEFAULT;
state.run_config.timeout_ms = timeout_sec > UT64_MAX / 1000 ? UT64_MAX : timeout_sec * 1000;

View file

@ -125,7 +125,7 @@ typedef struct rz_test_test_database_t {
} RzTestDatabase;
typedef struct rz_test_run_config_t {
const char *r2_cmd;
const char *rz_cmd;
const char *rz_asm_cmd;
const char *json_test_file;
ut64 timeout_ms;

View file

@ -9,7 +9,7 @@ Crosscompiling from OSX:
export IOSVER=7.1
./configure --prefix=/usr --with-ostype=darwin --with-compiler=ios-sdk --target=arm-unknown-darwin
make -j4
make install DESTDIR=/tmp/r2ios
make install DESTDIR=/tmp/rzios
Natively compiling on iOS
@ -43,7 +43,7 @@ Setup SDK for ARMv6
5) Get the varinclude tarball
wget lolcathost.org/b/varinclude.tar.gz
wget lolcathost.org/b/varinclude.tar.gz
tar xzvf varinclude.tar.gz -C /
Compilation
@ -57,30 +57,30 @@ Compilation
Usage
-----
export R2DIR=/private/var/rizin
export PATH=${R2DIR}/bin:$PATH
export DYLD_LIBRARY_PATH=${R2DIR}/lib
r2 ...
export RZDIR=/private/var/rizin
export PATH=${RZDIR}/bin:$PATH
export DYLD_LIBRARY_PATH=${RZDIR}/lib
rizin ...
Building with the ARMv7 SDK
---------------------------
From coolstar repo we get the ios toolchain
apt-get coreutils install wget inetutils
apt-get install basename git make expat
apt-get install basename git make expat
apt-get install org.coolstar.iostoolchain
* Copy crt1.o and dylib1.o from your iOS SDK into /usr/lib
/Applications//Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/
* Current r2 build requires 'gcc' as native compiler to
* Current rizin build requires 'gcc' as native compiler to
build a standalone 'sdb' to precompile some files. This
dependency will be probably
cd /usr/bin
ln -fs clang gcc
Build
-----
export CC=clang
@ -94,17 +94,17 @@ Packaging
---------
Make a fake install in a temporary directory:
rm -rf /tmp/r2
make install DESTDIR=/tmp/r2
cd /tmp/r2
tar czvpf ../r2.tgz *
rm -rf /tmp/rizin
make install DESTDIR=/tmp/rizin
cd /tmp/rizin
tar czvpf ../rizin.tgz *
Clone the cydia repo from rizin's github
git clone https://github.com/rizin/cydia
cd cydia/rizin*
mkdir root
tar xzvf r2.tgz -C root
tar xzvf rizin.tgz -C root
vim CONFIG # bump version
make

View file

@ -14,14 +14,10 @@ By default it is installed in /usr/local, you can specify a different prefix lik
$ sys/install.sh /custom/prefix
To install bindings you will need to install r2, valac, valabind and swig. The whole process can be automated by using scripts under sys/
$ rz_pm -s python
Code Signing
------------
After Mac OS X 10.6, binaries that need permissions to debug require to be signed and include a .plist describing them. The aforementioned `install.sh` script will install a new code signing certificate into the system keychain and sign r2 with it. Alternatively, you can manually create a code signing certificate by following the following steps:
After Mac OS X 10.6, binaries that need permissions to debug require to be signed and include a .plist describing them. The aforementioned `install.sh` script will install a new code signing certificate into the system keychain and sign rizin with it. Alternatively, you can manually create a code signing certificate by following the following steps:
(Based on https://llvm.org/svn/llvm-project/lldb/trunk/docs/code-signing.txt)
@ -52,11 +48,11 @@ As said before, the signing process can also be done manually following the next
$ make -C binrz/rizin macossign
But this is not enough. As long as r2 code is split into several libraries, you should sign every single dependency (librz*).
But this is not enough. As long as rizin code is split into several libraries, you should sign every single dependency (librz*).
$ make -C binrz/rizin macos-sign-libs
Another alternative is to build a static version of r2 and just sign it.
Another alternative is to build a static version of rizin and just sign it.
$ sys/static.sh
$ make -C binrz/rizin macossign
@ -71,7 +67,7 @@ Additionally, you can run the following command to add the non-privileged user (
After doing it you should be able to debug on macOS without root permissions!
$ r2 -d mybin
$ rizin -d mybin
Note: Apple-signed binaries cannot be debugged, since Apple's SIP (System Integrity Protection) prevents attaching to an Apple-signed binary. If you want to debug an Apple-signed binary, either remove its certificate (https://github.com/steakknife/unsign; WARNING: this cannot be reversed!) or disable SIP (`csrutil enable --without debug`).
@ -87,7 +83,7 @@ To create a macOS .pkg just run the following command:
Uninstall
---------
To uninstall the .pkg downloaded from the r2 website or the one you have generated with `sys/osx-pkg.sh`, run the following as root:
To uninstall the .pkg downloaded from the rizin website or the one you have generated with `sys/osx-pkg.sh`, run the following as root:
$ pkgutil --only-files --files org.rizin.rizin | sed 's/^/\//' | tr '\n' '\0' | xargs -o -n 1 -0 rm -i

View file

@ -219,11 +219,11 @@ RZ_API void rz_core_sysenv_end(RzCore *core, const char *cmd) {
rz_sys_setenv ("RZ_OFFSET", NULL);
// remove temporary RZ_CONFIG file
char *r2_config = rz_sys_getenv ("RZ_CONFIG");
if (r2_config) {
rz_file_rm (r2_config);
char *rz_config = rz_sys_getenv ("RZ_CONFIG");
if (rz_config) {
rz_file_rm (rz_config);
rz_sys_setenv ("RZ_CONFIG", NULL);
free (r2_config);
free (rz_config);
}
}

View file

@ -8359,12 +8359,12 @@ end:
return result;
}
static bool convert_dotcmd_to_image(RzCore *core, char *r2_cmd, const char *save_path) {
static bool convert_dotcmd_to_image(RzCore *core, char *rz_cmd, const char *save_path) {
if (save_path && *save_path) {
rz_cons_printf ("Saving to file '%s'...\n", save_path);
rz_cons_flush ();
}
rz_core_cmdf (core, "%s > a.dot", r2_cmd); // TODO: check error here
rz_core_cmdf (core, "%s > a.dot", rz_cmd); // TODO: check error here
return convert_dot_to_image (core, "a.dot", save_path);
}

View file

@ -55,7 +55,7 @@ typedef struct {
int output[2];
#endif
RzCoreBind coreb;
} R2Pipe;
} RzPipe;
typedef struct rz_socket_t {
#ifdef _MSC_VER
@ -261,24 +261,24 @@ RZ_API bool rz_run_parsefile(RRunProfile *p, const char *b);
RZ_API char *rz_run_get_environ_profile(char **env);
/* rapipe */
RZ_API R2Pipe *rap_open(const char *cmd);
RZ_API R2Pipe *rap_open_corebind(RzCoreBind *coreb);
RZ_API int rap_close(R2Pipe *rap);
RZ_API RzPipe *rap_open(const char *cmd);
RZ_API RzPipe *rap_open_corebind(RzCoreBind *coreb);
RZ_API int rap_close(RzPipe *rap);
RZ_API char *rap_cmd(R2Pipe *rap, const char *str);
RZ_API char *rap_cmdf(R2Pipe *rap, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
RZ_API char *rap_cmd(RzPipe *rap, const char *str);
RZ_API char *rap_cmdf(RzPipe *rap, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
RZ_API int rap_write(R2Pipe *rap, const char *str);
RZ_API char *rap_read(R2Pipe *rap);
RZ_API int rap_write(RzPipe *rap, const char *str);
RZ_API char *rap_read(RzPipe *rap);
RZ_API int rzpipe_write(R2Pipe *rzpipe, const char *str);
RZ_API char *rzpipe_read(R2Pipe *rzpipe);
RZ_API int rzpipe_close(R2Pipe *rzpipe);
RZ_API R2Pipe *rzpipe_open_corebind(RzCoreBind *coreb);
RZ_API R2Pipe *rzpipe_open(const char *cmd);
RZ_API R2Pipe *rzpipe_open_dl(const char *file);
RZ_API char *rzpipe_cmd(R2Pipe *rzpipe, const char *str);
RZ_API char *rzpipe_cmdf(R2Pipe *rzpipe, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
RZ_API int rzpipe_write(RzPipe *rzpipe, const char *str);
RZ_API char *rzpipe_read(RzPipe *rzpipe);
RZ_API int rzpipe_close(RzPipe *rzpipe);
RZ_API RzPipe *rzpipe_open_corebind(RzCoreBind *coreb);
RZ_API RzPipe *rzpipe_open(const char *cmd);
RZ_API RzPipe *rzpipe_open_dl(const char *file);
RZ_API char *rzpipe_cmd(RzPipe *rzpipe, const char *str);
RZ_API char *rzpipe_cmdf(RzPipe *rzpipe, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
#endif
#ifdef __cplusplus

View file

@ -1,23 +1,25 @@
import rzpipe
import json
def chk(x):
if x[1]['opcode'] == 'svc 0x80':
name = x[0]['flags'][0][8:]
sysnum = int(x[0]['opcode'].split(' ')[2], 16)
print ("%d\t%s"%(sysnum, name))
if x[1]["opcode"] == "svc 0x80":
name = x[0]["flags"][0][8:]
sysnum = int(x[0]["opcode"].split(" ")[2], 16)
print("%d\t%s" % (sysnum, name))
dev_pid = "23f88587e12c30376f8ab0b05236798fdfa4e853/4903"
r2 = rzpipe.open("frida://" + dev_pid)
rz = rzpipe.open("frida://" + dev_pid)
print("Importing symbols from libSystem...")
r2.cmd(".=!i*")
r2.cmd(".=!ie* libSystem.B.dylib")
rz.cmd(".=!i*")
rz.cmd(".=!ie* libSystem.B.dylib")
print("Finding syscalls...")
funcs = r2.cmd("pdj 2 @@ sym.fun.*")
funcs = rz.cmd("pdj 2 @@ sym.fun.*")
for doc in funcs.split('\n'):
if len(doc) > 1:
chk(json.loads(doc))
r2.quit()
for doc in funcs.split("\n"):
if len(doc) > 1:
chk(json.loads(doc))
rz.quit()
print("Thanks for waiting")

View file

@ -8,7 +8,7 @@
#include <sys/types.h>
/* --------------------------------------------------------- */
#define R2P(x) ((R2Pipe*)(x)->data)
#define RZP(x) ((RzPipe*)(x)->data)
// TODO: add rzpipe_assert
@ -34,12 +34,12 @@ static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) {
eprintf ("rzpipe_write: error, fmt string has been truncated\n");
return -1;
}
rv = rzpipe_write (R2P (fd), fmt);
rv = rzpipe_write (RZP (fd), fmt);
if (rv < 1) {
eprintf ("rzpipe_write: error\n");
return -1;
}
res = rzpipe_read (R2P (fd));
res = rzpipe_read (RZP (fd));
/* TODO: parse json back */
r = strstr (res, "result");
if (r) {
@ -63,12 +63,12 @@ static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) {
snprintf (fmt, sizeof (fmt),
"{\"op\":\"read\",\"address\":%"PFMT64d",\"count\":%d}",
io->off, count);
rv = rzpipe_write (R2P (fd), fmt);
rv = rzpipe_write (RZP (fd), fmt);
if (rv < 1) {
eprintf ("rzpipe_write: error\n");
return -1;
}
res = rzpipe_read (R2P (fd));
res = rzpipe_read (RZP (fd));
/* TODO: parse json back */
r = strstr (res, "result");
@ -143,12 +143,12 @@ static bool __check(RzIO *io, const char *pathname, bool many) {
}
static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) {
R2Pipe *r2p = NULL;
RzPipe *rzp = NULL;
if (__check (io, pathname, 0)) {
r2p = rzpipe_open (pathname + 9);
rzp = rzpipe_open (pathname + 9);
}
return r2p? rz_io_desc_new (io, &rz_io_plugin_rzpipe,
pathname, rw, mode, r2p): NULL;
return rzp? rz_io_desc_new (io, &rz_io_plugin_rzpipe,
pathname, rw, mode, rzp): NULL;
}
static char *__system(RzIO *io, RzIODesc *fd, const char *msg) {
@ -159,13 +159,13 @@ static char *__system(RzIO *io, RzIODesc *fd, const char *msg) {
pj_ks (pj, "cmd", msg);
pj_end (pj);
const char *fmt = pj_string (pj);
int rv = rzpipe_write (R2P (fd), fmt);
int rv = rzpipe_write (RZP (fd), fmt);
pj_free (pj);
if (rv < 1) {
eprintf ("rzpipe_write: error\n");
return NULL;
}
char *res = rzpipe_read (R2P (fd));
char *res = rzpipe_read (RZP (fd));
//eprintf ("%s\n", res);
/* TODO: parse json back */
char *r = strstr (res, "result");

View file

@ -96,7 +96,7 @@ static bool __plugin_open(RzIO *io, const char *file, bool many) {
}
// mingw32 toolchain doesnt have this symbol
static HANDLE (WINAPI *r2_OpenThread)(
static HANDLE (WINAPI *rz_OpenThread)(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwThreadId
@ -119,9 +119,9 @@ static int __w32_first_thread(int pid) {
do {
/* get all threads of process */
if (te32.th32OwnerProcessID == pid) {
r2_OpenThread = OpenThread;
thid = r2_OpenThread
? r2_OpenThread (THREAD_ALL_ACCESS, 0, te32.th32ThreadID) : NULL;
rz_OpenThread = OpenThread;
thid = rz_OpenThread
? rz_OpenThread (THREAD_ALL_ACCESS, 0, te32.th32ThreadID) : NULL;
if (!thid) {
rz_sys_perror ("__w32_first_thread/OpenThread");
goto err_first_th;
@ -152,7 +152,7 @@ static int __open_proc(RzIO *io, int pid, bool attach) {
W32DbgWInst *wrap = (W32DbgWInst *)io->w32dbg_wrap;
wrap->pi.dwProcessId = pid;
if (attach) {
/* Attach to the process */
/* Attach to the process */
wrap->params.type = W32_ATTACH;
w32dbg_wrap_wait_ret (wrap);
if (!w32dbgw_ret (wrap)) {

View file

@ -80,7 +80,7 @@ static int lang_cpipe_run(RzLang *lang, const char *code, int len) {
fputs ("#include <rz_socket.h>\n\n"
"#define R2P(x,y...) rzpipe_cmdf(r2p,x,##y)\n"
"int main() {\n"
" R2Pipe *r2p = rzpipe_open(NULL);", fd);
" RzPipe *r2p = rzpipe_open(NULL);", fd);
fputs (code, fd);
fputs ("\n}\n", fd);
fclose (fd);

View file

@ -1,5 +1,5 @@
#!/usr/bin/node
// $ r2 -qc '#!pipe node pipe-node.js' -
// $ rizin -qc '#!pipe node pipe-node.js' -
var isMain = process.argv[1] == __filename;
@ -9,17 +9,17 @@ function langPipe () {
var IN = +process.env.RZ_PIPE_IN;
var OUT = +process.env.RZ_PIPE_OUT;
var r2io = {
var rzio = {
r: fs.createReadStream (null, {fd: IN}),
w: fs.createWriteStream (null, {fd: OUT})
};
var replies = [];
r2io.cmd = function(cmd, cb) {
rzio.cmd = function(cmd, cb) {
replies.push (cb);
r2io.w.write (cmd);
rzio.w.write (cmd);
}
r2io.r.on ('data', function (foo) {
rzio.r.on ('data', function (foo) {
if (replies.length>0) {
var cb = replies[0];
replies = replies.slice(1);
@ -27,9 +27,9 @@ function langPipe () {
}
});
r2io.repl = function () {
/* r2 repl implemented in pipe-node.js */
r2io.r.pipe (process.stdout);
rzio.repl = function () {
/* rizin repl implemented in pipe-node.js */
rzio.r.pipe (process.stdout);
process.stdin.on ('data', function (chunk) {
if (replies.length>0) {
var cb = replies[0];
@ -37,10 +37,10 @@ function langPipe () {
var cb = replies.pop ();
if (cb) cb (''+chunk);
}
r2io.w.write (chunk);
rzio.w.write (chunk);
});
}
return r2io;
return rzio;
}
// Example:

View file

@ -85,7 +85,7 @@ static int lang_zig_run(RzLang *lang, const char *code, int len) {
"export fn entry(core: &u8) void {\n";
const char *zig_footer = \
"\n}\n" \
"pub fn r2cmd(core: &u8, cmd: u8) &u8 {\n" \
"pub fn rzcmd(core: &u8, cmd: u8) &u8 {\n" \
" return rz_core_cmd_str(core, cmd);\n" \
"}\n";
fputs (zig_header, fd);

View file

@ -544,9 +544,9 @@ RZ_API bool rz_run_parseline(RRunProfile *p, const char *b) {
p->_libpath = strdup (e);
} else if (!strcmp (b, "preload")) {
p->_preload = strdup (e);
} else if (!strcmp (b, "r2preload")) {
} else if (!strcmp (b, "rzpreload")) {
p->_rzpreload = parseBool (e);
} else if (!strcmp (b, "r2preweb")) {
} else if (!strcmp (b, "rzpreweb")) {
rz_sys_setenv ("RZ_RUN_WEB", "yes");
} else if (!strcmp (b, "setuid")) {
p->_setuid = strdup (e);
@ -661,7 +661,7 @@ RZ_API const char *rz_run_help(void) {
"# chdir=/\n"
"# chroot=/mnt/chroot\n"
"# libpath=$PWD:/tmp/lib\n"
"# r2preload=yes\n"
"# rzpreload=yes\n"
"# preload=/lib/libfoo.so\n"
"# setuid=2000\n"
"# seteuid=2000\n"

View file

@ -20,9 +20,9 @@ Usage Example:
#include <rz_lib.h>
#include <rz_socket.h>
#define R2P_PID(x) (((R2Pipe*)(x)->data)->pid)
#define R2P_INPUT(x) (((R2Pipe*)(x)->data)->input[0])
#define R2P_OUTPUT(x) (((R2Pipe*)(x)->data)->output[1])
#define RZP_PID(x) (((RzPipe*)(x)->data)->pid)
#define RZP_INPUT(x) (((RzPipe*)(x)->data)->input[0])
#define RZP_OUTPUT(x) (((RzPipe*)(x)->data)->output[1])
#if !__WINDOWS__
static void env(const char *s, int f) {
@ -32,7 +32,7 @@ static void env(const char *s, int f) {
}
#endif
RZ_API int rzpipe_write(R2Pipe *rzpipe, const char *str) {
RZ_API int rzpipe_write(RzPipe *rzpipe, const char *str) {
char *cmd;
int ret, len;
if (!rzpipe || !str) {
@ -57,7 +57,7 @@ RZ_API int rzpipe_write(R2Pipe *rzpipe, const char *str) {
}
/* TODO: add timeout here ? */
RZ_API char *rzpipe_read(R2Pipe *rzpipe) {
RZ_API char *rzpipe_read(RzPipe *rzpipe) {
int bufsz = 0;
char *buf = NULL;
if (!rzpipe) {
@ -106,7 +106,7 @@ RZ_API char *rzpipe_read(R2Pipe *rzpipe) {
return buf;
}
RZ_API int rzpipe_close(R2Pipe *rzpipe) {
RZ_API int rzpipe_close(RzPipe *rzpipe) {
if (!rzpipe) {
return 0;
}
@ -151,7 +151,7 @@ RZ_API int rzpipe_close(R2Pipe *rzpipe) {
}
#if __WINDOWS__
static int w32_createPipe(R2Pipe *rzpipe, const char *cmd) {
static int w32_createPipe(RzPipe *rzpipe, const char *cmd) {
CHAR buf[1024];
rzpipe->pipe = CreateNamedPipe (TEXT ("\\\\.\\pipe\\RZ_PIPE_IN"),
PIPE_ACCESS_DUPLEX,PIPE_TYPE_MESSAGE | \
@ -167,8 +167,8 @@ static int w32_createPipe(R2Pipe *rzpipe, const char *cmd) {
}
#endif
static R2Pipe* r2p_open_spawn(R2Pipe* r2p, const char *cmd) {
rz_return_val_if_fail (r2p, NULL);
static RzPipe* rzp_open_spawn(RzPipe* rzp, const char *cmd) {
rz_return_val_if_fail (rzp, NULL);
#if __UNIX__ || defined(__CYGWIN__)
char *out = rz_sys_getenv ("RZ_PIPE_IN");
char *in = rz_sys_getenv ("RZ_PIPE_OUT");
@ -177,26 +177,26 @@ static R2Pipe* r2p_open_spawn(R2Pipe* r2p, const char *cmd) {
int i_in = atoi (in);
int i_out = atoi (out);
if (i_in >= 0 && i_out >= 0) {
r2p->input[0] = r2p->input[1] = i_in;
r2p->output[0] = r2p->output[1] = i_out;
rzp->input[0] = rzp->input[1] = i_in;
rzp->output[0] = rzp->output[1] = i_out;
done = true;
}
}
if (!done) {
eprintf ("Cannot find RZ_PIPE_IN or RZ_PIPE_OUT environment\n");
RZ_FREE (r2p);
RZ_FREE (rzp);
}
free (in);
free (out);
return r2p;
return rzp;
#else
eprintf ("rzpipe_open(NULL) not supported on windows\n");
return NULL;
#endif
}
static R2Pipe *rzpipe_new(void) {
R2Pipe *rzpipe = RZ_NEW0 (R2Pipe);
static RzPipe *rzpipe_new(void) {
RzPipe *rzpipe = RZ_NEW0 (RzPipe);
if (rzpipe) {
#if __UNIX__
rzpipe->input[0] = rzpipe->input[1] = -1;
@ -207,21 +207,21 @@ static R2Pipe *rzpipe_new(void) {
return rzpipe;
}
RZ_API R2Pipe *rzpipe_open_corebind(RzCoreBind *coreb) {
R2Pipe *rzpipe = rzpipe_new ();
RZ_API RzPipe *rzpipe_open_corebind(RzCoreBind *coreb) {
RzPipe *rzpipe = rzpipe_new ();
if (rzpipe) {
memcpy (&rzpipe->coreb, coreb, sizeof (RzCoreBind));
}
return rzpipe;
}
RZ_API R2Pipe *rzpipe_open_dl(const char *libr_path) {
RZ_API RzPipe *rzpipe_open_dl(const char *libr_path) {
void *librz = rz_lib_dl_open (libr_path);
void* (*rnew)() = rz_lib_dl_sym (librz, "rz_core_new");
char* (*rcmd)(void *c, const char *cmd) = rz_lib_dl_sym (librz, "rz_core_cmd_str");
if (rnew && rcmd) {
R2Pipe *rzpipe = rzpipe_new ();
RzPipe *rzpipe = rzpipe_new ();
if (rzpipe) {
rzpipe->coreb.core = rnew ();
rzpipe->coreb.cmdstr = rcmd;
@ -233,101 +233,101 @@ RZ_API R2Pipe *rzpipe_open_dl(const char *libr_path) {
return NULL;
}
RZ_API R2Pipe *rzpipe_open(const char *cmd) {
R2Pipe *r2p = rzpipe_new ();
if (!r2p) {
RZ_API RzPipe *rzpipe_open(const char *cmd) {
RzPipe *rzp = rzpipe_new ();
if (!rzp) {
return NULL;
}
if (RZ_STR_ISEMPTY (cmd)) {
r2p->child = -1;
return r2p_open_spawn (r2p, cmd);
rzp->child = -1;
return rzp_open_spawn (rzp, cmd);
}
#if __WINDOWS__
w32_createPipe (r2p, cmd);
r2p->child = (int)(r2p->pipe);
w32_createPipe (rzp, cmd);
rzp->child = (int)(rzp->pipe);
#else
int r = pipe (r2p->input);
int r = pipe (rzp->input);
if (r != 0) {
eprintf ("pipe failed on input\n");
rzpipe_close (r2p);
rzpipe_close (rzp);
return NULL;
}
r = pipe (r2p->output);
r = pipe (rzp->output);
if (r != 0) {
eprintf ("pipe failed on output\n");
rzpipe_close (r2p);
rzpipe_close (rzp);
return NULL;
}
#if LIBC_HAVE_FORK
r2p->child = fork ();
rzp->child = fork ();
#else
r2p->child = -1;
rzp->child = -1;
#endif
if (r2p->child == -1) {
rzpipe_close (r2p);
if (rzp->child == -1) {
rzpipe_close (rzp);
return NULL;
}
env ("RZ_PIPE_IN", r2p->input[0]);
env ("RZ_PIPE_OUT", r2p->output[1]);
env ("RZ_PIPE_IN", rzp->input[0]);
env ("RZ_PIPE_OUT", rzp->output[1]);
if (r2p->child) {
if (rzp->child) {
signed char ch = -1;
// eprintf ("[+] rzpipeipe child is %d\n", rzpipe->child);
if (read (r2p->output[0], &ch, 1) != 1) {
if (read (rzp->output[0], &ch, 1) != 1) {
eprintf ("Failed to read 1 byte\n");
rzpipe_close (r2p);
rzpipe_close (rzp);
return NULL;
}
if (ch == -1) {
eprintf ("[+] rzpipe link error.\n");
rzpipe_close (r2p);
rzpipe_close (rzp);
return NULL;
}
// Close parent's end of pipes
close (r2p->input[0]);
close (r2p->output[1]);
r2p->input[0] = -1;
r2p->output[1] = -1;
close (rzp->input[0]);
close (rzp->output[1]);
rzp->input[0] = -1;
rzp->output[1] = -1;
} else {
int rc = 0;
if (cmd && *cmd) {
close (0);
close (1);
dup2 (r2p->input[0], 0);
dup2 (r2p->output[1], 1);
close (r2p->input[1]);
close (r2p->output[0]);
r2p->input[1] = -1;
r2p->output[0] = -1;
dup2 (rzp->input[0], 0);
dup2 (rzp->output[1], 1);
close (rzp->input[1]);
close (rzp->output[0]);
rzp->input[1] = -1;
rzp->output[0] = -1;
rc = rz_sandbox_system (cmd, 1);
if (rc != 0) {
eprintf ("return code %d for %s\n", rc, cmd);
}
// trigger the blocking read
write (1, "\xff", 1);
close (r2p->output[1]);
close (rzp->output[1]);
close (0);
close (1);
}
r2p->child = -1;
rzpipe_close (r2p);
rzp->child = -1;
rzpipe_close (rzp);
exit (rc);
return NULL;
}
#endif
return r2p;
return rzp;
}
RZ_API char *rzpipe_cmd(R2Pipe *r2p, const char *str) {
rz_return_val_if_fail (r2p && str, NULL);
if (!*str || !rzpipe_write (r2p, str)) {
RZ_API char *rzpipe_cmd(RzPipe *rzp, const char *str) {
rz_return_val_if_fail (rzp && str, NULL);
if (!*str || !rzpipe_write (rzp, str)) {
perror ("rzpipe_write");
return NULL;
}
return rzpipe_read (r2p);
return rzpipe_read (rzp);
}
RZ_API char *rzpipe_cmdf(R2Pipe *r2p, const char *fmt, ...) {
RZ_API char *rzpipe_cmdf(RzPipe *rzp, const char *fmt, ...) {
int ret, ret2;
char *p, string[1024];
va_list ap, ap2;
@ -348,10 +348,10 @@ RZ_API char *rzpipe_cmdf(R2Pipe *r2p, const char *fmt, ...) {
va_end (ap);
return NULL;
}
fmt = rzpipe_cmd (r2p, p);
fmt = rzpipe_cmd (rzp, p);
free (p);
} else {
fmt = rzpipe_cmd (r2p, string);
fmt = rzpipe_cmd (rzp, string);
}
va_end (ap2);
va_end (ap);

View file

@ -35,7 +35,7 @@ Programs generated by r_egg are relocatable and can be injected in a running pro
Since the rz-gg-cc merge, rz-gg can now generate shellcodes from C code. The final code can be linked with rz-bin and it is relocatable, so it can be used to inject it on any remote process. This feature is conceptually based on shellforge4, but only linux/osx x86-32/64 platforms are supported.
.Sh DIRECTIVES
.Pp
The rr2 (rz-gg) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'.
The rrz (rz-gg) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'.
.Bl -tag -width Fl
.It Fl a Ar arch
set architecture x86, arm

View file

@ -68,10 +68,10 @@ use execve instead of posix_spawn (osx tricks)
path to the library to be executed
.It Ar runlib.fcn
function name to call from runlib library
.It Ar r2preload
preload with librz, kill -USR1 to get an rizin shell or -USR2 to spawn a webserver in a thread
.It Ar r2preweb
run the webserver in a thread just at starting the r2preload
.It Ar rzpreload
preload with librz, kill -USR1 to get an rizin shell or -USRZ to spawn a webserver in a thread
.It Ar rzpreweb
run the webserver in a thread just at starting the rzpreload
.It Ar setenv
set value for given environment variable
.It Ar setegid

View file

@ -11,7 +11,7 @@
.Op Fl v
.Op Fl V
.Op Fl j Ar threads
.Op Fl r Ar r2-path
.Op Fl r Ar rz-path
.Op Fl m Ar rz-asm-pth
.Op Fl f Ar bin-for-json-tests
.Op Fl C Ar chdir
@ -36,7 +36,7 @@ Show version number
Be verbose
.It Fl j Ar threads
Specify the number of tasks to run in parallel
.It Fl r Ar r2-path
.It Fl r Ar rz-path
Set path to rizin executable
.It Fl n Ar rz-asm-path
Set path to rz-asmexecutable

View file

@ -1,330 +0,0 @@
#!/bin/sh
# r2docker
# ========
#
# Requires ~140MB of free disk space
#
# Build docker image with:
# $ ./sys/docker_build_alpine_image.sh
#
# Run the docker image:
#
# $ r2d() {
# local rm
# case "$1" in
# "-r"|"--rm") rm="--rm" && shift ;;
# esac
# docker run --cap-drop=ALL --cap-add=SYS_PTRACE -i \
# `--name r2_$(date +%F_%H%M%S%N) $rm -tv $(pwd):/r2 \
# r2_alpine:latest $@
# }
# $ r2d # Optional --rm
#
# Once you quit the session, get the container id with something like:
#
# $ containerid="$(docker ps -a | awk '/r2_alpine/ {print $NF}')"
#
# To get into that shell again just type:
#
# $ docker start -ai $containerid
#
# To share those images:
#
# $ docker export $containerid | xz >container.tar.xz
# $ xz -d <container.tar.xz | docker import -
#
# When finished:
#
# $ docker rm -f $containerid
#
# If you are unwilling to debug a program within Docker, remove
# --cap-add=SYS_PTRACE from the r2d function. If you need sudo to
# install more packages within Docker, remove --cap-drop=ALL from the
# r2d function.
### Helpers begin
checkdeps() {
for d in curl docker jq; do
if [ -z "$(command -v "$d")" ]; then
echo "[!] $d is not installed"
exit 128
fi
done
unset d
}
long_opt() {
arg=""
shift="0"
case "$1" in
"--"*"="*) arg="${1#*=}"; [ -n "$arg" ] || usage 127 ;;
*) shift="1"; shift; [ $# -gt 0 ] || usage 127; arg="$1" ;;
esac
echo "$arg"
unset arg
return $shift
}
### Helpers end
cleanup() {
rm -rf "$tmp_docker_dir"
[ "${1:-0}" -eq 0 ] || exit "$1"
}
usage() {
cat <<EOF
Usage: ${0##*/} [OPTIONS]
Build a Radare2 docker image that uses local user/group IDs.
Options:
-b, --branch=BRANCH Use specified rizin branch (default:
master)
-h, --help Display this help message
--node=VERSION Use specified Node.js version (default: 10)
-n, --npm=VERSION Use specified version of rzpipe npm binding
(default: newest)
-p, --py=VERSION Use specified version of rzpipe python
binding (default: newest)
EOF
exit "$1"
}
args=""
unset help rzpipe_npm rzpipe_py
github="https://github.com/rizinorg/rizin.git"
r2branch="master"
# Check for missing dependencies
checkdeps
# Parse command line options
while [ $# -gt 0 ]; do
case "$1" in
"--") shift && args="$args${args:+ }$*" && break ;;
"-b"|"--branch"*) r2branch="$(long_opt "$@")" || shift ;;
"-h"|"--help") help="true" ;;
"-n"|"--npm"*) rzpipe_npm="@$(long_opt "$@")" || shift ;;
"-p"|"--py"*) rzpipe_py="==$(long_opt "$@")" || shift ;;
*) args="$args${args:+ }$1" ;;
esac
shift
done
[ -z "$args" ] || set -- "$args"
# Check for valid params
[ -z "$help" ] || usage 0
[ $# -eq 0 ] || usage 1
if [ "`uname`" = Linux ]; then
if [ "$(id -u)" -ne 0 ] && id -Gn | grep -qvw "docker"; then
echo "[!] You are not part of the docker group"
exit 2
fi
fi
trap "cleanup 126" INT
# Create Dockerfile
tmp_docker_dir=".docker_alpine"
gid="$(id -g)"
gname="$(id -gn)"
r2commit="$(
curl -Ls \
"http://api.github.com/repos/rizin/rizin/commits/$r2branch" | \
jq -cMrS ".sha"
)"
uid="$(id -u)"
uname="$(id -nu)"
mkdir -p $tmp_docker_dir
cat >$tmp_docker_dir/Dockerfile <<EOF
# Using super tiny alpine base image
FROM alpine:latest
# Install bash b/c it's better
RUN apk upgrade && apk add bash
# Bash is better than sh
SHELL ["/bin/bash", "-c"]
# Build rizin in a volume to minimize space used by build
VOLUME ["/mnt"]
# All one RUN layer, splitting into 3 increases size to ~360MB, wtf
# 1. Install dependencies
# 2. Install Node.js and Python bindings (do we need these?)
# 3. Create id and gid to match current local user
# 4. Add new user to sudoers without password
# 5. Add some convenient aliases to .bashrc
# 6. Clone and install rizin
# 7. Clean up unnecessary files and packages
RUN set -o pipefail && \
( \
apk upgrade && \
apk add \
g++ \
gcc \
git \
libc6-compat \
linux-headers \
make \
ncurses-libs \
nodejs-current \
npm \
py2-pip \
shadow \
sudo \
) && ( \
npm install -g --unsafe-perm "rzpipe$rzpipe_npm" && \
pip install --upgrade pip && \
pip install rzpipe$rzpipe_py \
) && ( \
[ "$gname" != "root" ] || \
( \
echo "alias la=\"\\ls -AF\"" >>/root/.bashrc && \
echo "alias ll=\"\\ls -Fhl\"" >>/root/.bashrc && \
echo "alias ls=\"\\ls -F\"" >>/root/.bashrc && \
echo "alias q=\"exit\"" >>/root/.bashrc \
) \
) && ( \
[ "$gname" == "root" ] || \
( \
groupadd -f $gname && \
(groupmod -g $gid $gname 2>/dev/null || true) && \
useradd -g $gid -mou $uid $uname && \
echo "$uname ALL=(ALL) NOPASSWD: ALL" \
>/etc/sudoers.d/$uname && \
echo "alias la=\"\\ls -AF\"" >>/home/$uname/.bashrc && \
echo "alias ll=\"\\ls -Fhl\"" >>/home/$uname/.bashrc && \
echo "alias ls=\"\\ls -F\"" >>/home/$uname/.bashrc && \
echo "alias q=\"exit\"" >>/home/$uname/.bashrc \
) \
) && ( \
cd /mnt && \
git clone -b $r2branch --depth 1 $github && \
cd rizin && \
git checkout $r2commit && \
./sys/install.sh && \
make install \
) && ( \
apk del --purge -r \
g++ \
gcc \
linux-headers \
make \
npm \
py2-pip && \
rm -rf /tmp/* /var/cache/apk/* /var/tmp/* \
)
# Initialize env
USER $(id -nu)
WORKDIR /r2
# Setup rz-pm
RUN set -o pipefail && \
rz-pm init && \
rz-pm update
CMD ["/bin/bash"]
EOF
# Tag old images
echo "[*] Tagging any old r2_alpine images"
docker images | awk '{print $1":"$3}' | while read -r tag; do
case "$tag" in
"r2_alpine:"*) docker image tag "${tag#*:}" "$tag" ;;
esac
done
unset tag
findbase="$(
docker images | grep -E "^(docker\.io\/)?alpine +latest "
)"
# Build image (may take a while)
echo "[*] Building image..."
echo "[*] This may take a long time..."
# Pull newest base image and build r2_alpine image
docker pull alpine:latest
(
if [ ! -d "$tmp_docker_dir" ]; then
echo "$tmp_docker_dir not found"
fi
cd $tmp_docker_dir || exit 3
# shellcheck disable=SC2154
docker build \
${http_proxy:+--build-arg http_proxy=$http_proxy} \
${https_proxy:+--build-arg https_proxy=$https_proxy} \
-t r2_alpine:latest .
)
# Only remove base image if it didn't already exist
[ -n "$findbase" ] || docker rmi alpine:latest
echo "[*] done"
old_base="^(docker\.io\/)?alpine +<none>"
old_rz="^r2_alpine +[^l ]"
found="$(
docker images | grep -E "($old_base)|($old_rz)"
)"
if [ -n "$found" ]; then
# List old images
echo
echo "[*] Old images:"
docker images | head -n 1
docker images | grep -E "($old_base)|($old_rz)" | \
while read -r line; do
echo "$line"
done
unset line
# Prompt to remove old images
unset remove
echo
while :; do
echo "Remove old images (y/N/q)?"
read -r ans
echo
case "$ans" in
""|"n"|"N"|"q"|"Q") break ;;
"y"|"Y") remove="true"; break ;;
*) echo "Invalid choice" ;;
esac
done
if [ -n "$remove" ]; then
# Remove old images
docker images | awk "/$old_rz/ {print \$1\":\"\$3}" | \
while read -r tag; do
docker rmi "$tag"
done
unset tag
docker images | awk "/$old_base/ {print \$3}" | \
while read -r id; do
docker rmi "$id"
done
unset id
fi
fi
unset found
cleanup 0
cat <<EOF
It's suggested you add something like the following to your ~/.bashrc:
r2d() {
local rm
case "\$1" in
"-r"|"--rm") rm="--rm" && shift ;;
esac
docker run --cap-drop=ALL --cap-add=SYS_PTRACE -i \\
--name r2_\$(date +%F_%H%M%S%N) \$rm -tv \$(pwd):/r2 \\
r2_alpine:latest \$@
}
EOF

View file

@ -162,27 +162,27 @@ def xp_compat(builddir):
def build(args):
""" Build rizin """
log.info('Building rizin')
r2_builddir = os.path.join(ROOT, args.dir)
rz_builddir = os.path.join(ROOT, args.dir)
options = ['-D%s' % x for x in args.options]
if args.webui:
options.append('-Duse_webui=true')
if args.local:
options.append('-Dlocal=true')
if not os.path.exists(r2_builddir):
meson('setup', builddir=r2_builddir, prefix=args.prefix, backend=args.backend,
if not os.path.exists(rz_builddir):
meson('setup', builddir=rz_builddir, prefix=args.prefix, backend=args.backend,
release=args.release, shared=args.shared, options=options)
if args.backend != 'ninja':
# XP support was dropped in Visual Studio 2019 v142 platform
if args.backend == 'vs2017' and args.xp:
xp_compat(r2_builddir)
xp_compat(rz_builddir)
if not args.project:
project = os.path.join(r2_builddir, 'rizin.sln')
project = os.path.join(rz_builddir, 'rizin.sln')
params = ['/m', '/clp:Summary;Verbosity=minimal']
if args.backend == 'vs2017' and args.xp:
params.append('/p:XPDeprecationWarning=false')
msbuild(project, *params)
else:
ninja(r2_builddir)
ninja(rz_builddir)
def install(args):
""" Install rizin """

View file

@ -3,7 +3,7 @@
#include "minunit.h"
static bool test_rzpipe(void) {
R2Pipe *r = rzpipe_open ("rizin -q0 -");
RzPipe *r = rzpipe_open ("rizin -q0 -");
mu_assert ("rzpipe can spawn", r);
char *hello = rzpipe_cmd (r, "?e hello world");
mu_assert_streq (hello, "hello world\n", "rzpipe hello world");
@ -13,7 +13,7 @@ static bool test_rzpipe(void) {
}
static bool test_rzpipe_404(void) {
R2Pipe *r = rzpipe_open ("rodoro2 -q0 -");
RzPipe *r = rzpipe_open ("ricin -q0 -");
mu_assert ("rzpipe can spawn", !r);
mu_end;
}