All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.datlag.sekret.SekretComponentRegistrar.kt Maven / Gradle / Ivy

The newest version!
package dev.datlag.sekret

import com.google.auto.service.AutoService
import dev.datlag.sekret.generator.DeobfuscatorGenerator
import dev.datlag.sekret.model.Config
import dev.datlag.sekret.transformer.DeobfuscatorTransformer
import dev.datlag.sekret.transformer.ElementTransformer
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.messageCollector
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import java.security.SecureRandom

@OptIn(ExperimentalCompilerApi::class)
@AutoService(CompilerPluginRegistrar::class)
class SekretComponentRegistrar : CompilerPluginRegistrar() {
    override val supportsK2: Boolean
        get() = true

    override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
        // available for jvm: ClassGeneratorExtension
        val messageCollector = configuration.get(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, configuration.messageCollector)
        val logger = Logger(true, messageCollector)

        val config = Config(
            secretMask = configuration[KEY_SECRET_MASK, "***"],
            secretMaskNull = configuration[KEY_SECRET_MASK_NULL, true],
            obfuscateSeed = configuration[KEY_OBFUSCATE_SEED, SecureRandom().nextInt()]
        )

        DeobfuscatorGenerator.setSeed(config.obfuscateSeed)

        IrGenerationExtension.registerExtension(object : IrGenerationExtension {
            override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
                // DeobfuscatorGenerator.createIrClass(pluginContext, logger)

                moduleFragment.transform(
                    transformer = ElementTransformer(config, logger, pluginContext),
                    data = null
                )

                // DeobfuscatorGenerator.generateList(pluginContext, logger)
            }
        })
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy