Skip to content

Commit

Permalink
Fix RABIN2_SWIFTLIB and add tests from r2 and rabin2 ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 20, 2024
1 parent 7ad255b commit be299a6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libr/arch/p/x86_nz/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static bool replace(int argc, char *argv[], char *newstr) {
{ "jle", "if (var <= 0) goto loc_#", {1}},
{ "jmp", "goto loc_#", {1}},
{ "jne", "if (var) goto loc_#", {1}},
{ "leav", ";", {}},
{ "leav", ";", {0}},
{ "lea", "# = #", {1, 2}},
{ "mov", "# = #", {1, 2}},
{ "movabs", "# = #", {1, 2}},
Expand Down
6 changes: 4 additions & 2 deletions libr/main/rabin2.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static void setup_trylib_from_environment(RBin *bin, int type) {
bool trylib = false;
if (type == R_BIN_LANG_SWIFT) {
trylib = true;
char *swiftlib = r_sys_getenv ("RABIN2_TRYLIB");
char *swiftlib = r_sys_getenv ("RABIN2_SWIFTLIB");
if (swiftlib) {
trylib = r_str_is_true (swiftlib);
free (swiftlib);
Expand Down Expand Up @@ -645,6 +645,8 @@ R_API int r_main_rabin2(int argc, const char **argv) {
if (r_sys_getenv_asbool ("RABIN2_VERBOSE")) {
r_config_set_b (core.config, "bin.verbose", true);
}
r_config_set_b (core.config, "bin.demangle.trylib",
r_sys_getenv_asbool ("RABIN2_SWIFTLIB"));
if ((tmp = r_sys_getenv ("RABIN2_DEMANGLE"))) {
r_config_set (core.config, "bin.demangle", tmp);
free (tmp);
Expand Down Expand Up @@ -920,7 +922,7 @@ R_API int r_main_rabin2(int argc, const char **argv) {
free (state.stdin_buf);
return 1;
}
if (res && *res) {
if (R_STR_ISNOTEMPTY (res)) {
printf ("%s\n", res);
} else if (file && *file) {
printf ("%s\n", file);
Expand Down
43 changes: 43 additions & 0 deletions test/db/archos/darwin-arm_64/swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
NAME=swift demangling trylib false
FILE=-
CMDS=<<EOF
%RABIN2_SWIFTLIB=0
!!rabin2 -D swift _TFC4test7MyClass9calculatefS0_FT1xSi_Si
EOF
EXPECT=<<EOF
Swift.test.MyClass.calculate (self) -> (): , ) ()
EOF
RUN

NAME=swift demangling trylib true
FILE=-
CMDS=<<EOF
%RABIN2_SWIFTLIB=1
!!rabin2 -D swift _TFC4test7MyClass9calculatefS0_FT1xSi_Si
EOF
EXPECT=<<EOF
test.MyClass.calculate(test.MyClass) -> (x: Swift.Int) -> Swift.Int
EOF
RUN

NAME=swift demangling config var internal
FILE=-
CMDS=<<EOF
-e bin.demangle.trylib=false
iD swift _TFC4test7MyClass9calculatefS0_FT1xSi_Si
EOF
EXPECT=<<EOF
Swift.test.MyClass.calculate (self) -> (): , ) ()
EOF
RUN

NAME=swift demangling config var system library
FILE=-
CMDS=<<EOF
-e bin.demangle.trylib=true
iD swift _TFC4test7MyClass9calculatefS0_FT1xSi_Si
EOF
EXPECT=<<EOF
test.MyClass.calculate(test.MyClass) -> (x: Swift.Int) -> Swift.Int
EOF
RUN

0 comments on commit be299a6

Please sign in to comment.