Skip to content

Commit

Permalink
Tweak the custom swift demangler
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Jul 19, 2024
1 parent 879b705 commit 1bfdf0b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libr/bin/mangling/swift-sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ static const char *get_mangled_tail(const char **pp, RStrBuf *out) {
}
switch (p[1]) {
case 'T':
r_strbuf_append (out, "Swift.");
// type like 'SwiftObject'
break;
case 'W':
switch (p[2]) {
Expand Down Expand Up @@ -381,7 +379,7 @@ static char *my_swift_demangler(const char *s) {
// _TF or __TW
if (looks_valid (*p)) {
if (r_str_startswith (p + 1, "SS")) {
r_strbuf_append (out, "String.init(");
r_strbuf_append (out, "Swift.String.init(");
p += 3;
}
// TODO: move into get_tail()
Expand Down Expand Up @@ -839,6 +837,15 @@ repeat:;
}

R_API char *r_bin_demangle_swift(const char *s, bool syscmd, bool trylib) {
#if USE_THIS_CODE
syscmd = trylib = false; // useful for debugging the embedded demangler on macos
#endif
if (!trylib && !strcmp (s, "_TtCs12_SwiftObject")) {
// this hack is for class tests to work, but the parser should be fixed
// to support this: the "Swift" module comes from the known-module abbreviation "s",
// see https://github.com/swiftlang/swift/blob/c998bbc4d98b4b4ca16831b33054fa750456e053/docs/ABI/Mangling.rst#declaration-contexts
return strdup ("Swift._SwiftObject");
}
const char *os = s;
if (r_str_startswith (s, "_$")) {
s += 2;
Expand All @@ -847,9 +854,6 @@ R_API char *r_bin_demangle_swift(const char *s, bool syscmd, bool trylib) {
if (strstr (s, "UITableViewHeaderFoote")) {
eprintf ("==> (%s)\n", s);
}
#endif
#if USE_THIS_CODE
syscmd = trylib = false; // useful for debugging the embedded demangler on macos
#endif
const char *space = strchr (s, ' ');
if (space) {
Expand Down

0 comments on commit 1bfdf0b

Please sign in to comment.