-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import of the rapatch2 tool ##shell
- Loading branch information
Showing
12 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
BIN=rapatch2 | ||
|
||
BINDEPS=r_core r_search r_cons r_config | ||
BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io r_fs | ||
BINDEPS+=r_lang r_asm r_syscall r_main r_util r_esil | ||
BINDEPS+=r_magic r_socket r_flag r_egg r_crypto | ||
|
||
include ../rules.mk | ||
|
||
ifeq ($(OSTYPE),android) | ||
LDFLAGS+=${DL_LIBS} -lm | ||
endif | ||
|
||
include ../../libr/socket/deps.mk | ||
include ../../libr/main/deps.mk | ||
include ../../shlr/zip/deps.mk | ||
include ../../shlr/gdb/deps.mk | ||
include ../../shlr/bochs/deps.mk | ||
include ../../shlr/qnx/deps.mk | ||
include ../../shlr/ar/deps.mk | ||
|
||
LDFLAGS+=$(LINK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
executable('rapatch2', 'rapatch2.c', | ||
include_directories: [platform_inc], | ||
dependencies: [ | ||
r_util_dep, | ||
r_main_dep, | ||
r_io_dep, | ||
r_search_dep, | ||
r_cons_dep, | ||
r_core_dep, | ||
r_bin_dep, | ||
r_anal_dep, | ||
r_asm_dep, | ||
r_crypto_dep, | ||
r_config_dep | ||
], | ||
install: true, | ||
install_rpath: rpath_exe, | ||
implicit_include_directories: false | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* radare - LGPL - Copyright 2024 - pancake */ | ||
|
||
#include <r_main.h> | ||
|
||
int main (int argc, const char *argv[]) { | ||
return r_main_rapatch2 (argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* radare - LGPL - Copyright 2024 - pancake */ | ||
|
||
#define R_LOG_ORIGIN "rapatch2" | ||
|
||
#include <r_core.h> | ||
#include <r_main.h> | ||
|
||
static int show_help(int v) { | ||
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; | ||
} | ||
|
||
R_API int r_main_rapatch2(int argc, const char **argv) { | ||
RGetopt opt; | ||
int o; | ||
|
||
bool reverse = false; | ||
bool silent = false; | ||
int patchlevel = 0; | ||
|
||
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); | ||
} | ||
} | ||
|
||
if (argc < 3 || opt.ind + 2 > argc) { | ||
return show_help (0); | ||
} | ||
const char *file = (opt.ind < argc)? argv[opt.ind]: NULL; | ||
const char *patchfile = (opt.ind + 1 < argc)? argv[opt.ind + 1]: NULL; | ||
|
||
if (R_STR_ISEMPTY (file) || R_STR_ISEMPTY (patchfile)) { | ||
R_LOG_ERROR ("Cannot open empty path"); | ||
return 1; | ||
} | ||
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", | ||
patchfile, | ||
file, | ||
NULL | ||
}; | ||
r_main_radare2 (5, r2argv); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> |