mirror of
https://github.com/revanced/revanced-cli.git
synced 2024-06-02 03:16:32 +02:00
37ecc5eaa6
I spent almost an entire day on this, you better be happy!
31 lines
942 B
Kotlin
31 lines
942 B
Kotlin
package app.revanced.cli.utils
|
|
|
|
import lanchon.multidexlib2.BasicDexFileNamer
|
|
import org.jf.dexlib2.writer.io.MemoryDataStore
|
|
import java.io.File
|
|
import java.nio.file.FileSystems
|
|
import java.nio.file.Files
|
|
|
|
val NAMER = BasicDexFileNamer()
|
|
|
|
object DexReplacer {
|
|
fun replaceDex(source: File, dexFiles: Map<String, MemoryDataStore>) {
|
|
FileSystems.newFileSystem(
|
|
source.toPath(),
|
|
null
|
|
).use { fs ->
|
|
// Delete all classes?.dex files
|
|
Files.walk(fs.rootDirectories.first()).forEach {
|
|
if (
|
|
it.toString().endsWith(".dex") &&
|
|
NAMER.isValidName(it.fileName.toString())
|
|
) Files.delete(it)
|
|
}
|
|
// Write new dex files
|
|
dexFiles
|
|
.forEach { (dexName, dexData) ->
|
|
Files.write(fs.getPath("/$dexName"), dexData.data)
|
|
}
|
|
}
|
|
}
|
|
} |