3
3
import com .google .common .collect .ArrayListMultimap ;
4
4
import com .google .common .collect .Multimap ;
5
5
import com .google .common .collect .Multimaps ;
6
+ import me .coley .recaf .util .CollectionUtil ;
6
7
7
- import java .util .AbstractMap ;
8
- import java .util .Collection ;
9
- import java .util .HashMap ;
10
- import java .util .Map ;
11
- import java .util .Objects ;
8
+ import java .util .*;
12
9
import java .util .stream .Collectors ;
13
10
14
11
/**
@@ -86,10 +83,21 @@ public static void applyMappingToExisting(Map<String, String> existing, Map<Stri
86
83
+ key + " gave more than 1 result: " + String .join (", " + classPreimages ));
87
84
}
88
85
// if we have a preimage for the class, apply the mapping to that preimage class name
89
- if (classPreimages .size () == 1 ) {
90
- String classPreimage = classPreimages .iterator ().next ();
91
- String memberName = key .substring (key .indexOf ('.' ) + 1 );
92
- key = classPreimage + "." + memberName ;
86
+ // otherwise use given name
87
+ String targetClassName = classPreimages .isEmpty () ? className : classPreimages .iterator ().next ();
88
+ String memberInfo = key .substring (key .indexOf ('.' ) + 1 );
89
+ if (memberInfo .contains (" " )) {
90
+ int x = memberInfo .indexOf (" " );
91
+ String fieldName = memberInfo .substring (0 , x );
92
+ String fieldDesc = memberInfo .substring (x + 1 );
93
+ key = targetClassName + "." + fieldName + " " + mapDesc (existing , fieldDesc );
94
+ } else if (memberInfo .contains ("(" )) {
95
+ int x = memberInfo .indexOf ("(" );
96
+ String methodName = memberInfo .substring (0 , x );
97
+ String methodDesc = memberInfo .substring (x );
98
+ key = targetClassName + "." + methodName + mapDesc (existing , methodDesc );
99
+ } else {
100
+ key = targetClassName + "." + memberInfo ;
93
101
}
94
102
}
95
103
@@ -109,6 +117,22 @@ public static void applyMappingToExisting(Map<String, String> existing, Map<Stri
109
117
existing .putAll (preimageAwareUpdates );
110
118
}
111
119
120
+ /**
121
+ * @param existing
122
+ * Current aggregate mappings.
123
+ * @param desc
124
+ * Descriptor to map.
125
+ *
126
+ * @return Mapped descriptor.
127
+ */
128
+ private static String mapDesc (Map <String , String > existing , String desc ) {
129
+ SimpleRecordingRemapper remapper = new SimpleRecordingRemapper (
130
+ CollectionUtil .invert (existing ), false , false , false , null );
131
+ return desc .charAt (0 ) == '(' ?
132
+ remapper .mapMethodDesc (desc ) :
133
+ remapper .mapDesc (desc );
134
+ }
135
+
112
136
/**
113
137
* Transforms a given mapping in ASM format (See
114
138
* {@link org.objectweb.asm.commons.SimpleRemapper#SimpleRemapper(Map)}) to a mapping where the values are in the
0 commit comments