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 de4fad9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
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 de4fad9

Please sign in to comment.