1515import org .spongepowered .asm .mixin .Shadow ;
1616import org .spongepowered .asm .mixin .injection .At ;
1717
18+ <<<<<<< HEAD
1819import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
1920import com .llamalad7 .mixinextras .sugar .Local ;
2021
2324
2425@ Mixin (Downloader .class )
2526public abstract class DownloaderMixin
27+ =======
28+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
29+ import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
30+
31+ import net .minecraft .client .session .Session ;
32+ import net .minecraft .util .Downloader ;
33+ import net .minecraft .util .Uuids ;
34+ import net .wurstclient .WurstClient ;
35+
36+ @ Mixin (Downloader .class )
37+ public abstract class DownloaderMixin implements AutoCloseable
38+ >>>>>>> upstream /master
2639{
2740 @ Shadow
2841 @ Final
2942 private Path directory ;
3043
44+ <<<<<<< HEAD
3145 @ ModifyExpressionValue (method = "method_55485" ,
3246 at = @ At (value = "INVOKE" ,
3347 target = "Ljava/nio/file/Path;resolve(Ljava/lang/String;)Ljava/nio/file/Path;" ))
@@ -36,5 +50,41 @@ public abstract class DownloaderMixin
3650 {
3751 return ResourcePackProtector .remapDownloadPath (directory , original ,
3852 packId );
53+ =======
54+ /**
55+ * Patches a fingerprinting vulnerability by creating a separate cache
56+ * folder for each Minecraft account.
57+ *
58+ * <p>
59+ * This mixin targets the <code>entries.forEach()</code> lambda in
60+ * <code>download(Config, Map)</code>.
61+ *
62+ * @see https://github.com/Wurst-Imperium/Wurst7/issues/1226
63+ */
64+ @ WrapOperation (at = @ At (value = "INVOKE" ,
65+ target = "Ljava/nio/file/Path;resolve(Ljava/lang/String;)Ljava/nio/file/Path;" ,
66+ ordinal = 0 ,
67+ remap = false ), method = "method_55485" )
68+ private Path wrapResolve (Path instance , String filename ,
69+ Operation <Path > original )
70+ {
71+ Path result = original .call (instance , filename );
72+
73+ // If the path has already been modified by another mod (likely trying
74+ // to patch the same exploit), don't modify it further.
75+ if (result == null || !result .getParent ().equals (directory ))
76+ return result ;
77+
78+ // "getUuidOrNull" seems to be an outdated Yarn name, as Minecraft
79+ // 1.21.10 treats this like a non-null method. Just in case, we manually
80+ // fallback to the offline UUID if it ever does return null.
81+ Session session = WurstClient .MC .getSession ();
82+ UUID uuid = session .getUuidOrNull ();
83+ if (uuid == null )
84+ uuid = Uuids .getOfflinePlayerUuid (session .getUsername ());
85+
86+ return result .getParent ().resolve (uuid .toString ())
87+ .resolve (result .getFileName ());
88+ >>>>>>> upstream /master
3989 }
4090}
0 commit comments