@@ -10,16 +10,13 @@ import java.io.StringReader
10
10
import java.io.StringWriter
11
11
import java.net.HttpURLConnection
12
12
import java.net.URL
13
- import java.nio.file.Files
14
13
15
- val mappingsFile = Files .createTempDirectory(" mappings" ).toFile()
16
-
17
- fun getDeobfuscation (modded : Boolean , version : String , content : String , isClient : Boolean ): String? {
14
+ fun getDeobfuscation (modded : Boolean , version : String , content : String , isClient : Boolean , mappingsDirectory : File ): String? {
18
15
if (modded) {
19
16
return null
20
17
}
21
18
22
- if (version.isBlank() || version.contains(" \\ " ) || version.contains(" /" ) || isZipSlip(version)) {
19
+ if (version.isBlank() || version.contains(" \\ " ) || version.contains(" /" ) || isZipSlip(version, mappingsDirectory )) {
23
20
return null
24
21
}
25
22
@@ -29,10 +26,10 @@ fun getDeobfuscation(modded: Boolean, version: String, content: String, isClient
29
26
" $version -server"
30
27
}
31
28
32
- val mappingFile = synchronized(mappingsFile ) {
33
- val mappingFile = File (mappingsFile , name)
29
+ val mappingFile = synchronized(mappingsDirectory ) {
30
+ val mappingFile = File (mappingsDirectory , name)
34
31
if (! mappingFile.exists()) {
35
- downloadMapping(version, name, isClient)
32
+ downloadMapping(version, name, isClient, mappingsDirectory )
36
33
}
37
34
if (! mappingFile.exists()) {
38
35
return null
@@ -46,14 +43,14 @@ fun getDeobfuscation(modded: Boolean, version: String, content: String, isClient
46
43
return stringWriter.toString()
47
44
}
48
45
49
- fun isZipSlip (version : String ): Boolean {
50
- val canonicalDestinationDir = mappingsFile .canonicalPath
51
- val destinationFile = File (mappingsFile , version)
46
+ fun isZipSlip (version : String , mappingsDirectory : File ): Boolean {
47
+ val canonicalDestinationDir = mappingsDirectory .canonicalPath
48
+ val destinationFile = File (mappingsDirectory , version)
52
49
val canonicalDestinationFile = destinationFile.canonicalPath
53
50
return ! canonicalDestinationFile.startsWith(canonicalDestinationDir + File .separator)
54
51
}
55
52
56
- private fun downloadMapping (version : String , name : String , isClient : Boolean ) {
53
+ private fun downloadMapping (version : String , name : String , isClient : Boolean , mappingsDirectory : File ) {
57
54
val mapper = jacksonObjectMapper()
58
55
val manifest = mapper
59
56
.readValue(URL (" https://launchermeta.mojang.com/mc/game/version_manifest.json" ), VersionManifest ::class .java)
@@ -67,14 +64,14 @@ private fun downloadMapping(version: String, name: String, isClient: Boolean) {
67
64
if (mappingUrl == null ) {
68
65
return
69
66
}
70
- downloadFile(mappingUrl, name)
67
+ downloadFile(mappingUrl, name, mappingsDirectory )
71
68
}
72
69
73
- fun downloadFile (url : String , name : String ) {
70
+ fun downloadFile (url : String , name : String , mappingsDirectory : File ) {
74
71
val connection: HttpURLConnection = URL (url).openConnection() as HttpURLConnection
75
72
connection.requestMethod = " GET"
76
73
val stream = connection.inputStream
77
- val file = File (mappingsFile , name)
74
+ val file = File (mappingsDirectory , name)
78
75
file.createNewFile()
79
76
val out = FileOutputStream (file)
80
77
stream.transferTo(out )
0 commit comments