From 0738d61eb38f4760c14e5da88874d954d95786dd Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 27 Sep 2024 03:16:30 +0200 Subject: [PATCH] ai --- libr/main/rapatch2.c | 23 ++++++++++++-- man/rapatch2.1 | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 man/rapatch2.1 diff --git a/libr/main/rapatch2.c b/libr/main/rapatch2.c index 01f17bd90a..56cf845343 100644 --- a/libr/main/rapatch2.c +++ b/libr/main/rapatch2.c @@ -6,10 +6,13 @@ #include static int show_help(int v) { - printf ("Usage: rapatch2 [-R] [origfile] ([patchfile])\n"); + printf ("Usage: rapatch2 [-p N] [-sv] [-R] [origfile] ([patchfile])\n"); if (v) { printf ( + " -p N patch level, skip N directories\n" " -R reverse patch\n" + " -s be silent\n" + " -v show version\n" ); } return 1; @@ -20,15 +23,25 @@ R_API int r_main_rapatch2(int argc, const char **argv) { int o; bool reverse = false; + bool silent = false; + int patchlevel = 0; - r_getopt_init (&opt, argc, argv, "hR"); + r_getopt_init (&opt, argc, argv, "hRvsp:"); while ((o = r_getopt_next (&opt)) != -1) { switch (o) { case 'h': return show_help (1); + case 's': + silent = true; + break; + case 'p': + patchlevel = atoi (opt.arg); + break; case 'R': reverse = true; break; + case 'v': + return r_main_version_print ("rapatch2", 0); default: return show_help (0); } @@ -47,6 +60,12 @@ R_API int r_main_rapatch2(int argc, const char **argv) { if (reverse) { R_LOG_TODO ("reverse patch not yet supported"); } + if (silent) { + R_LOG_TODO ("silent not yet supported"); + } + if (patchlevel) { + R_LOG_TODO ("patchlevel not yet supported"); + } const char *r2argv[5] = { "radare2", "-qwP", diff --git a/man/rapatch2.1 b/man/rapatch2.1 new file mode 100644 index 0000000000..b191b5c830 --- /dev/null +++ b/man/rapatch2.1 @@ -0,0 +1,72 @@ +.TH RAPATCH2 1 "rapatch2 tool" "Sep 27, 2024" +.SH NAME +rapatch2 - binary patching utility +.SH SYNOPSIS +.B rapatch2 +[-p #] [-R] file patch + +.SH DESCRIPTION +rapatch2 is a tool from the radare2 suite designed for binary patching code and data. +.PP +Human friendly text format to apply patches to binary files. +.Pp +It supports a wide range of formats and features, including architecture and +bits specification, delta patching, graph patching, and more. +.Pp +Those patches must be written in files and the syntax looks like the following: + +.RS +.nf +^# -> comments +. -> execute command +! -> execute command +OFFSET { code block } +OFFSET "string" +OFFSET 01020304 +OFFSET : assembly ++ {code}|"str"|0210|: asm +.fi +.RE + +.SH OPTIONS +.TP +.B -h +Show this help message +.TP +.B -R +Reverse patch +.TP +.B -p [num] +Skip num directories from patch file + +.TP +.B -s +Be silent + +.TP +.B -v +Show version string + +.SH USAGE EXAMPLES +.TP +.B "Comparing two binaries" +radiff2 -u bin1 bin2 > patch + +rapatch2 -p 1 < patch + +.TP +.B "Patch only one file" +rapatch2 bin1 patch + +.SH COMMAND IN R2 + +See the -p flag and command. + +.SH SEE ALSO +radare2(1) + +.Sh WWW +.Pp +https://www.radare.org/ +.SH AUTHOR +pancake