Add initial rvc2 command ##shell (#18716)

This commit is contained in:
pancake 2021-05-20 03:34:23 +02:00 committed by GitHub
parent d01afcc9c6
commit 14e5afe6cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 198 additions and 92 deletions

2
.gitignore vendored
View File

@ -27,6 +27,8 @@ langs.cfg
*.ilk
binr/r2agent/r2agent
binr/r2agent/r2agent.exe
binr/rvc2/rvc2
binr/rvc2/rvc2.exe
binr/r2r/r2r
binr/r2r/r2r.exe
binr/rabin2/rabin2

View File

@ -6,7 +6,7 @@ BTOP=$(shell pwd)
.PHONY: all clean install install-symlink deinstall uninstall mrproper preload
BINS=r2r rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarun2 ragg2 r2agent rasign2
BINS=r2r rvc2 rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarun2 ragg2 r2agent rasign2
LIBR2=$(call libname-version,libr2.$(EXT_SO),${LIBVERSION})

View File

@ -1,7 +1,7 @@
PREFIX?=/usr
DESTDIR?=/
R2BINS=radare2 rabin2 rarun2 rasm2 ragg2 rahash2 rax2 rafind2 radiff2
R2BINS=radare2 rabin2 rarun2 rasm2 ragg2 rahash2 rax2 rvc2 rafind2 radiff2
BINS=r2blob
SOURCES= r2blob.c

10
binr/rvc2/Makefile Normal file
View File

@ -0,0 +1,10 @@
BIN=rvc2
BINDEPS=r_core r_main
include ../rules.mk
include ../../libr/main/deps.mk
include ../../shlr/zip/deps.mk
include ../../shlr/java/deps.mk
include ../../shlr/gdb/deps.mk
LDFLAGS+=$(LINK)

7
binr/rvc2/meson.build Normal file
View File

@ -0,0 +1,7 @@
executable('rvc2', 'rvc2.c',
include_directories: [platform_inc],
dependencies: [r_core_dep, r_main_dep],
install: true,
install_rpath: rpath_exe,
implicit_include_directories: false
)

7
binr/rvc2/rvc2.c Normal file
View File

@ -0,0 +1,7 @@
/* radare - LGPL - Copyright 2021 - pancake */
#include <r_main.h>
int main (int argc, const char *argv[]) {
return r_main_rvc2 (argc, argv);
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2021-2023 - RHL120, pancake */
/* radare - LGPL - Copyright 2021 - RHL120, pancake */
#include <rvc.h>
@ -114,7 +114,6 @@ static RvcBranch *branch_by_name(Rvc *repo, const char *name) {
return NULL;
}
static bool write_commit(Rvc *repo, RvcBranch *b, RvcCommit *commit) {
char *commit_path, *commit_string;
char *prev_path;
@ -177,6 +176,7 @@ static bool write_commit(Rvc *repo, RvcBranch *b, RvcCommit *commit) {
fclose (prev_file);
return true;
}
R_API bool r_vc_commit(Rvc *repo, RList *blobs, const char *auth, const char *message) {
RvcCommit *nc = R_NEW (RvcCommit);
if (!nc) {
@ -211,6 +211,7 @@ R_API bool r_vc_commit(Rvc *repo, RList *blobs, const char *auth, const char *me
repo->current_branch->head = nc;
return true;
}
R_API bool r_vc_branch(Rvc *repo, const char *name) {
char *bpath, *ppath;
RvcBranch *nb;
@ -259,6 +260,12 @@ R_API bool r_vc_branch(Rvc *repo, const char *name) {
return true;
}
R_API void r_vc_free(Rvc *vc) {
free (vc->path);
r_list_free (vc->branches);
free (vc);
}
R_API Rvc *r_vc_new(const char *path) {
Rvc *repo = R_NEW (Rvc);
char *blob_path;
@ -321,6 +328,7 @@ R_API Rvc *r_vc_new(const char *path) {
free (blob_path);
return repo;
}
R_API RList *r_vc_add(Rvc *repo, RList *files) {
RListIter *iter;
char *fname;
@ -514,21 +522,23 @@ R_API bool r_vc_checkout(Rvc *repo, const char *name) {
return true;
}
R_API int r_vc_git_init (const char *path) {
// GIT commands as APIs
R_API int r_vc_git_init(const char *path) {
return r_sys_cmdf ("git init %s", path);
}
R_API bool r_vc_git_branch (const char *path, const char *name) {
R_API bool r_vc_git_branch(const char *path, const char *name) {
return !r_sys_cmdf ("git -C %s branch %s", path, name);
}
R_API bool r_vc_git_checkout (const char *path, const char *name) {
R_API bool r_vc_git_checkout(const char *path, const char *name) {
return !r_sys_cmdf ("git -C %s checkout %s", path, name);
}
R_API int r_vc_git_add (const char *path, const char *fname) {
R_API int r_vc_git_add(const char *path, const char *fname) {
int ret;
char *cwd = r_sys_getdir();
char *cwd = r_sys_getdir ();
if (!cwd) {
return -1;
}
@ -546,7 +556,7 @@ R_API int r_vc_git_add (const char *path, const char *fname) {
return ret;
}
R_API int r_vc_git_commit (const char *path, const char *message) {
R_API int r_vc_git_commit(const char *path, const char *message) {
return message ? r_sys_cmdf ("git -C %s commit -m %s", path, message) :
r_sys_cmdf ("git -C %s commit", path);
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2020 - pancake */
/* radare - LGPL - Copyright 2008-2021 - pancake */
#ifndef R2_MAIN_H
#define R2_MAIN_H
@ -21,6 +21,7 @@ R_API void r_main_free(RMain *m);
R_API int r_main_run(RMain *m, int argc, const char **argv);
R_API int r_main_version_print(const char *program);
R_API int r_main_rvc2(int argc, const char **argv);
R_API int r_main_rax2(int argc, const char **argv);
R_API int r_main_rarun2(int argc, const char **argv);
R_API int r_main_rahash2(int argc, const char **argv);

View File

@ -38,6 +38,7 @@ R_API bool r_vc_commit(Rvc *repo, RList *blobs, const char *auth, const char *me
R_API bool r_vc_branch(Rvc *repo, const char *name);
R_API RList *r_vc_add(Rvc *repo, RList *files);
R_API Rvc *r_vc_new(const char *path);
R_API void r_vc_free(Rvc *vc);
R_API int r_vc_git_init(const char *path);
R_API bool r_vc_git_branch(const char *path, const char *name);
R_API bool r_vc_git_checkout(const char *path, const char *name);

View File

@ -3,6 +3,7 @@ include ../config.mk
NAME=r_main
OBJS+=main.o
OBJS+=rvc2.o
OBJS+=rax2.o
OBJS+=rasm2.o
OBJS+=ragg2.o

View File

@ -10,6 +10,7 @@ r_main_sources = [
'rarun2.c',
'rasign2.c',
'rasm2.c',
'rvc2.c',
'rax2.c'
]

94
libr/main/rvc2.c Normal file
View File

@ -0,0 +1,94 @@
/* radare - LGPL - Copyright 2021 - pancake */
#include <rvc.h>
static void rvc2_show_help(void) {
printf ("Usage: rvc2 [action] [file ...]\n"
" init initialize repository in current directory\n"
" add [file ..] add files to the current repository\n"
" checkout [name] checkout given branch name\n"
" log list commits in current branch\n"
" branch list all available branches\n"
" branch [name] change to another branch\n"
"Examples:\n"
" rvc2 init\n"
" man rvc2\n");
}
R_API int r_main_rvc2(int argc, const char **argv) {
RGetopt opt;
int c;
bool git = false;
r_getopt_init (&opt, argc, argv, "gvh");
while ((c = r_getopt_next (&opt)) != -1) {
switch (c) {
case 'g':
git = true;
break;
case 'v':
return r_main_version_print ("rvc2");
case 'h':
rvc2_show_help ();
return 0;
default:
rvc2_show_help ();
return -1;
}
}
if (git) {
eprintf ("TODO: r_vc_git APIs should be called from r_vc\n");
eprintf ("TODO: r_vc_new should accept options argument\n");
}
char *action = (optind < argc)? optarg: NULL;
if (action) {
if (!strcmp (action, "init")) {
char *path = r_sys_getdir ();
Rvc *vc = r_vc_new (path);
if (vc) {
r_vc_free (vc);
return 0;
}
return 1;
} else if (!strcmp (action, "branch")) {
char *path = r_sys_getdir ();
Rvc *vc = r_vc_new (path);
if (vc) {
if (optind + 1 < argc) {
const char *name = argv[optind + 1];
r_vc_branch (vc, name);
} else {
RListIter *iter;
RvcBranch *b;
r_list_foreach (vc->branches, iter, b) {
printf ("%s %s\n", b->head->hash, b->name);
}
}
r_vc_free (vc);
return 0;
}
return 1;
} else if (!strcmp (action, "add")) {
char *path = r_sys_getdir ();
Rvc *vc = r_vc_new (path);
if (vc) {
int i;
RList *files = r_list_newf (free);
for (i = optind; i < argc; i++) {
r_list_append (files, strdup (argv[i]));
}
RList *blobs = r_vc_add (vc, files); // print the blobs?
RListIter *iter;
RvcBlob *b;
r_list_foreach (blobs, iter, b) {
printf ("%s %s\n", b->hash, b->fname);
}
r_list_free (files);
r_vc_free (vc);
return 0;
}
return 1;
}
}
return 0;
}

View File

@ -57,13 +57,7 @@ Use the -n flag to dont run any test. Just load them.
.Pp
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr rafind2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>.

View File

@ -170,15 +170,7 @@ Load symbols and imports from radare2
[0x00000000]> .!rabin2 \-prsi $FILE
.Sh SEE ALSO
.Pp
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr radare2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr rax2(1) ,
.Xr rsc2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>.

View File

@ -1,4 +1,4 @@
.Dd May 17, 2020
.Dd May 20, 2021
.Dt RADARE2 1
.Sh NAME
.Nm radare2
@ -144,6 +144,7 @@ path to the current working file.
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr rax2(1) ,
.Xr rvc2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Sh AUTHORS

View File

@ -76,14 +76,7 @@ Perform diff using zignatures instead of function list (NEW)
.El
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rafind2(1) ,
.Xr rahash2(1) ,
.Xr rabin2(1) ,
.Xr rasm2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rax2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
pancake <pancake@nopcode.org>

View File

@ -65,14 +65,7 @@ Print version and exit
.El
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rax2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
pancake <pancake@nopcode.org>

View File

@ -144,13 +144,7 @@ show version
71bff87c4040404f45718083
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr rafind2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>.

View File

@ -83,15 +83,7 @@ Show usage help message.
When -c is used, exit status 0 indicates a match between the expected and computed hashes.
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rafind2(1) ,
.Xr rahash2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rax2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
pancake <pancake@nopcode.org>

View File

@ -160,13 +160,7 @@ Run a library function
$ rarun2 runlib=/lib/libc-2.25.so runlib.fcn=system arg1="ls /"
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr ragg2(1) ,
.Xr rasm2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>

View File

@ -34,12 +34,7 @@ Show version information.
.El
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rafind2(1) ,
.Xr rahash2(1) ,
.Xr rabin2(1) ,
.Xr rasm2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rax2(1) ,
.Xr radiff2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>

View File

@ -90,14 +90,7 @@ Disassemble opcode:
$ rasm2 \-d 90
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rafind2(1) ,
.Xr rahash2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rax2(1) ,
.Xr radare2(1)
.Sh AUTHORS
.Pp
pancake <pancake@nopcode.org>

View File

@ -97,14 +97,7 @@ It is a very useful tool for scripting, so you can read floating point values, o
.Pp
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr ragg2(1) ,
.Xr rarun2(1) ,
.Xr rasm2(1)
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>.

36
man/rvc2.1 Normal file
View File

@ -0,0 +1,36 @@
.Dd Dec 28, 2020
.Dt RVC2 1
.Sh NAME
.Nm rvc2
.Nd radare version control
.Sh SYNOPSIS
.Nm rvc2
.Op Fl ebBsSvxkKh
.Op [expr] ...
.Sh DESCRIPTION
This command is part of the radare project.
.Pp
Implements a simple version control system that aims to work as frontend for git, as well as its own structure for versioning project changes.
.Pp
This command is pretty new and experimental.
.Sh OPTIONS
.It Fl h
Show usage help message
.It Fl v
Display version
.El
.Sh USAGE
Available variable types are:
.Pp
rvc2 init
echo hello world > README.md
rvc2 add README.md
rvc2 branch
rvc2 commit
.Pp
.Sh SEE ALSO
.Pp
.Xr radare2(1)
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>.

View File

@ -629,6 +629,7 @@ if cli_enabled
subdir('binr/radiff2')
subdir('binr/rafind2')
subdir('binr/rasign2')
subdir('binr/rvc2')
subdir('binr/rax2')
endif
subdir('binr/r2pm')
@ -696,6 +697,7 @@ if cli_enabled
'man/rarun2.1',
'man/rasm2.1',
'man/rax2.1',
'man/rvc2.1',
'man/esil.7'
)