diff --git a/swift.go b/swift.go index 43dbc15..286e8ce 100644 --- a/swift.go +++ b/swift.go @@ -2527,8 +2527,21 @@ func (f *File) makeSymbolicMangledNameStringRef(addr uint64) (string, error) { } else if strings.HasPrefix(part, "y") && strings.HasSuffix(part, "G") { // part = fmt.Sprintf("<%s>", strings.TrimSuffix(strings.TrimPrefix(part, "y"), "G")) part = strings.TrimSuffix(strings.TrimPrefix(part, "y"), "G") - } else if strings.HasSuffix(part, "G") && idx == len(parts)-1 { - part = strings.TrimSuffix(part, "G") + } else if idx == len(parts)-1 { // last part + if strings.HasSuffix(part, "G") { + part = strings.TrimSuffix(part, "G") + } + if part == "G" { + continue + } + if strings.HasPrefix(part, "_p") { // I believe this just means that it's a protocol + part = strings.TrimPrefix(part, "_p") + } + if (part == "Qz" || part == "Qy_" || part == "Qy0_") && len(out) == 2 { + tmp := out[0] + out[0] = out[1] + "." + tmp + out = out[:1] + } } } if part == "" { diff --git a/types/swift/mangling.go b/types/swift/mangling.go index c19187c..91048db 100644 --- a/types/swift/mangling.go +++ b/types/swift/mangling.go @@ -100,6 +100,7 @@ var MangledType = map[string]string{ "_pSg": "?", "SgSg": "??", "ypG": "Any", + "p": "Any", "SSG": "String", "SSGSg": "String?", "SSSgG": "String?", @@ -120,5 +121,10 @@ var MangledType = map[string]string{ "x": "A", // generic param, depth=0, idx=0 "q_": "B", // dependent generic parameter "yxq_G": "", + "xq_": "", "Sb": "Swift.Bool", + "Qz": "==", + "Qy_": "==", + "Qy0_": "==", + "SgXw": "?", } diff --git a/types/swift/types.go b/types/swift/types.go index 8b36509..87fc4b1 100644 --- a/types/swift/types.go +++ b/types/swift/types.go @@ -176,12 +176,27 @@ func (t Type) dump(verbose bool) string { var size string if t.Type.(Class).GenericContext != nil { if len(t.Type.(Class).GenericContext.Requirements) > 0 { - var parts []string + var keyargs []string + var where []string for _, req := range t.Type.(Class).GenericContext.Requirements { - parts = append(parts, fmt.Sprintf("%s: %s", req.Param, req.Kind)) + if req.Flags.HasKeyArgument() { + keyargs = append(keyargs, fmt.Sprintf("%s: %s", req.Param, req.Kind)) + } else { + switch req.Flags.Kind() { + case GRKindBaseClass: + keyargs = append(keyargs, fmt.Sprintf("%s: %s, B", req.Param, req.Kind)) + case GRKindSameType: + where = append(where, fmt.Sprintf("%s %s", req.Param, req.Kind)) + default: + fmt.Println(req.Flags.String()) + } + } } - if len(parts) > 0 { - ctx = fmt.Sprintf("<%s>", strings.Join(parts, ", ")) + if len(keyargs) > 0 { + ctx = fmt.Sprintf("<%s>", strings.Join(keyargs, ", ")) + } + if len(where) > 0 { + ctx += fmt.Sprintf("\n where %s", strings.Join(where, ", ")) } } if t.Type.(Class).GenericContext.GenericMetadataPattern != nil && t.Type.(Class).GenericContext.GenericMetadataPattern.ValueWitnessTable != nil { @@ -248,12 +263,27 @@ func (t Type) dump(verbose bool) string { var size string if t.Type.(Struct).GenericContext != nil { if len(t.Type.(Struct).GenericContext.Requirements) > 0 { - var parts []string + var keyargs []string + var where []string for _, req := range t.Type.(Struct).GenericContext.Requirements { - parts = append(parts, fmt.Sprintf("%s: %s", req.Param, req.Kind)) + if req.Flags.HasKeyArgument() { + keyargs = append(keyargs, fmt.Sprintf("%s: %s", req.Param, req.Kind)) + } else { + switch req.Flags.Kind() { + case GRKindBaseClass: + keyargs = append(keyargs, fmt.Sprintf("%s: %s, B", req.Param, req.Kind)) + case GRKindSameType: + where = append(where, fmt.Sprintf("%s %s", req.Param, req.Kind)) + default: + fmt.Println(req.Flags.String()) + } + } } - if len(parts) > 0 { - ctx = fmt.Sprintf("<%s>", strings.Join(parts, ", ")) + if len(keyargs) > 0 { + ctx = fmt.Sprintf("<%s>", strings.Join(keyargs, ", ")) + } + if len(where) > 0 { + ctx += fmt.Sprintf("\n where %s", strings.Join(where, ", ")) } } if t.Type.(Struct).GenericContext.GenericMetadataPattern != nil && t.Type.(Struct).GenericContext.GenericMetadataPattern.ValueWitnessTable != nil {