* Add manpage for ragg2-cc

* Fix rax2 -S (by @earada, reported by @sre)
* Fix typos in manpages reported by lintian (thx @sre)
* Add r_core_file_reopen()
  - 'do' is an alias for 'oo'
  - close previous file
  - breaks debugger reopen .. needs more work
This commit is contained in:
pancake 2011-12-05 02:42:06 +01:00
parent 84b1aa5495
commit dc1efdcdd8
8 changed files with 150 additions and 26 deletions

View File

@ -184,7 +184,10 @@ static int use_stdin () {
buf[n] = 0;
//fgets (buf, sizeof (buf), stdin);
if (feof (stdin)) break;
buf[strlen (buf)-1] = '\0';
if ((flags & 4) && strlen (buf) < sizeof (buf)) // -S
buf[strlen (buf)] = '\0';
else
buf[strlen (buf)-1] = '\0';
if (!rax (buf, n, 0)) break;
}
return 0;

View File

@ -1722,7 +1722,7 @@ static int cmd_info(void *data, const char *input) {
}
r_cons_printf ("file\t%s\n", fn);
core->file->size = r_file_size (fn);
if (dbg) dbg = R_IO_WRITE|R_IO_EXEC;
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
r_cons_printf ("fd\t%d\n", core->file->fd->fd);
r_cons_printf ("size\t0x%x\n", core->file->size);
r_cons_printf ("mode\t%s\n", r_str_rwx_i (core->file->rwx | dbg));
@ -4314,11 +4314,11 @@ static int cmd_system(void *data, const char *input) {
}
static int cmd_open(void *data, const char *input) {
ut64 addr;
int num = -1;
RCore *core = (RCore*)data;
RCoreFile *file;
ut64 addr;
char *ptr, *path;
int perm, num = -1;
char *ptr;
switch (*input) {
case '\0':
@ -4348,17 +4348,7 @@ static int cmd_open(void *data, const char *input) {
r_core_block_read (core, 0);
break;
case 'o':
perm = core->file->rwx;
addr = 0; // XXX ? check file->map ?
path = strdup (core->file->uri);
if (r_config_get_i (core->config, "cfg.debug"))
r_debug_kill (core->dbg, R_FALSE, 9); // KILL
r_core_file_close (core, core->file);
file = r_core_file_open (core, path, perm, addr);
if (file) eprintf ("File %s reopened\n", path);
else eprintf ("Cannot reopen '%s'\n", path);
// TODO: in debugger must select new PID
free (path);
r_core_file_reopen (core, input+2);
break;
case '?':
default:
@ -5841,12 +5831,16 @@ static int cmd_debug(void *data, const char *input) {
r_debug_use (core->dbg, input+2);
else r_debug_plugin_list (core->dbg);
break;
case 'o':
r_core_file_reopen (core, input[1]? input+2: NULL);
break;
default:
r_cons_printf ("Usage: d[sbhcrbo] [arg]\n"
" dh [handler] list or set debugger handler\n"
" dH [handler] transplant process to a new handler\n"
" dd file descriptors (!fd in r1)\n"
" ds[ol] N step, over, source line\n"
" do open process (reload, alias for 'oo')\n"
" dp[=*?t][pid] list, attach to process or thread id\n"
" dc[?] continue execution. dc? for more\n"
" dr[?] cpu registers, dr? for extended help\n"

View File

@ -8,6 +8,39 @@ R_API ut64 r_core_file_resize(struct r_core_t *core, ut64 newsize) {
return 0LL;
}
// TODO: add support for args
R_API int r_core_file_reopen(RCore *core, const char *args) {
char *path;
RCoreFile *file;
int ret = R_FALSE;
int newpid, perm;
if (!core->file) {
eprintf ("No file opened to reopen\n");
return R_FALSE;
}
newpid = core->file->fd->fd;
perm = core->file->rwx;
ut64 addr = 0; // XXX ? check file->map ?
path = strdup (core->file->uri);
if (r_config_get_i (core->config, "cfg.debug"))
r_debug_kill (core->dbg, R_FALSE, 9); // KILL
r_core_file_close (core, core->file);
file = r_core_file_open (core, path, perm, addr);
if (file) {
eprintf ("File %s reopened\n", path);
ret = R_TRUE;
}
// close old file
r_core_file_close_fd (core, newpid);
// TODO: in debugger must select new PID
if (r_config_get_i (core->config, "cfg.debug")) {
newpid = core->file->fd->fd;
r_debug_select (core->dbg, newpid, newpid);
}
free (path);
return ret;
}
// NOTE: probably not all environment vars takes sesnse
// because they can be replaced by commands in the given
// command.. we should only expose the most essential and
@ -133,8 +166,11 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode, ut64 loa
fh->uri = strdup (file);
fh->filename = strdup (fh->uri);
p = strstr (fh->filename, "://");
if (p != NULL)
fh->filename = p+3;
if (p != NULL) {
char *s = strdup (p+3);
free (fh->filename);
fh->filename = s;
}
fh->rwx = mode;
r->file = fh;
r->io->plugin = fd->plugin;

View File

@ -155,6 +155,7 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch);
R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb);
R_API int r_core_serve(RCore *core, RIODesc *fd);
R_API int r_core_file_reopen(RCore *core, const char *args);
R_API void r_core_file_free(RCoreFile *cf);
R_API struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *file, int mode, ut64 loadaddr);
R_API struct r_core_file_t *r_core_file_get_fd(struct r_core_t *core, int fd);

View File

@ -59,7 +59,7 @@ List linked libraries to the binary
.It Fl I
Show realocations
.It Fl O Ar str
Write/extract operations (-O help)
Write/extract operations (\-O help)
.It Fl o Ar str
Output file/folder for write operations (out by default)
.It Fl r

90
man/ragg2-cc.1 Normal file
View File

@ -0,0 +1,90 @@
.Dd Dec 5, 2011
.Dt RAGG2-CC 1
.Os
.Sh NAME
.Nm ragg2-cc
.Nd CC frontend for compiling shellcodes
.Sh SYNOPSIS
.Nm ragg2-cc
.Op Fl a Ar arch
.Op Fl b Ar bits
.Op Fl k Ar kernel
.Op Fl o Ar file
.Op Fl dscxvh
.Sh DESCRIPTION
ragg2-cc is a frontend of CC. It allows to create tiny binaries (1KB) or shellcodes in binary or hexpairs from a C source.
.Pp
The compiler used is the one configured by the CC environment. This has been tested with gcc, llvm-gcc and clang.
.Pp
Uses sflib (shellforge4) includes to get the syscall definitions.
.Pp
Only linux/darwin x86-32/64 is supported at the moment. Planned support for more architectures.
.Pp
.Sh OPTIONS
.Pp
.Bl -tag -width Fl
.It Fl a Ar arch
set architecture x86, arm
.It Fl b Ar bits
32 or 64
.It Fl k Ar kernel
windows, linux or osx
.It Fl o Ar file
output file to write result of compilation
.It Fl h
show help message
.It Fl v
show version
.It Fl d
show assembler code
.It Fl s
generate assembly file
.It Fl c
generate compiled shellcode
.It Fl x
show hexpair bytes
.El
.Sh EXAMPLE
.Pp
$ cat hi.c
int main() {
write (1, "Hello World\\n", 12);
exit (0);
}
.Pp
$ ragg2-cc hi.c
hi.c.bin
.Pp
# Linked into a tiny binary. This is 294 bytes
$ wc -c < hi.c.bin
294
.Pp
$ ./hi.c.bin
Hello World
.Pp
# The compiled shellcode has zeroes
$ ragg2-cc -x hi.c
e90000000083ec0ce800000000588d882a000000b804000000606a0651
6a0150cd8083c41061b8010000006a0050cd8083c40883c40cc368656c
6c6f0a00
.Pp
# Use a xor encoder with key 32 to bypass
$ ragg2 -e xor -c key=32 -B `ragg2-cc -x hi.c`
6a3e596a205be8ffffffffc15e4883c60d301e48ffc6e2f9c920202020
a3cc2cc82020202078ada80a2020209824202020404a26714a2170eda0
a3e4304198212020204a2070eda0a3e428a3e42ce348454c4c4f2a20
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr rafind2(1) ,
.Xr ranal2(1) ,
.Xr radiff2(1) ,
.Xr rasm2(1) ,
.Xr ragg2cc(1) ,
.Sh AUTHORS
.Pp
pancake <pancake@nopcode.org>

View File

@ -47,9 +47,9 @@ select binary format (pe, elf, mach0)
.It Fl o Ar file
output file to write result of compilation
.It Fl i Ar shellcode
specify shellcode name to be used (see -L)
specify shellcode name to be used (see \-L)
.It Fl e Ar encoder
specify encoder name to be used (see -L)
specify encoder name to be used (see \-L)
.It Fl B Ar hexpair
specify shellcode as hexpairs
.It Fl c Ar k=v

View File

@ -17,11 +17,11 @@ This command allows you to convert values between positive and negative integer,
.It Fl e
Swap endian.
.It Fl b
Convert from binary string to caracter (rax2 -b 01000101)
Convert from binary string to caracter (rax2 \-b 01000101)
.It Fl s
Convert from hex string to caracter (rax2 -s 43 4a 50)
Convert from hex string to caracter (rax2 \-s 43 4a 50)
.It Fl S
Convert from hex string to caracter (rax2 -S C J P)
Convert from hex string to caracter (rax2 \-S C J P)
.It Fl v
Show program version
.It Fl x
@ -37,8 +37,8 @@ Available variable types are:
.Pp
int -> hex rax2 10
hex -> int rax2 0xa
-int -> hex rax2 -77
-hex -> int rax2 0xffffffb3
\-int -> hex rax2 \-77
\-hex -> int rax2 0xffffffb3
int -> bin rax2 b30
bin -> int rax2 1010d
float -> hex rax2 3.33f