dev.datlag.sekret.SekretComponentRegistrar.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler-plugin Show documentation
Show all versions of compiler-plugin Show documentation
Compiler plugin for sekret annotations
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)
}
})
}
}