Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Récupération du chemin vers le dossier contenant le script
- $scriptPath = Split-Path $MyInvocation.MyCommand.Path
- # Vérification des droits administrateur
- $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
- if (-not $isAdmin) {
- # Redémarrage du script en mode administrateur
- Start-Process powershell.exe -Verb RunAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`""
- # Sortie du script actuel
- exit
- }
- # Récupération du chemin vers Themida en fonction de l'architecture
- $themidaPath = if ([IntPtr]::Size -eq 8) {
- Join-Path $scriptPath "themida64.exe"
- } else {
- Join-Path $scriptPath "themida.exe"
- }
- # Fonction de protection
- function Protect-File {
- param (
- [Parameter(Mandatory=$true, Position=0)]
- [string]$filePath
- )
- # Protection du fichier avec Themida
- & $themidaPath /protect $filePath
- # Renommage du fichier avec l'extension .thunder
- $newFilePath = Join-Path (Split-Path $filePath) "$([IO.Path]::GetFileNameWithoutExtension($filePath)).thunder"
- Rename-Item -Path $filePath -NewName $newFilePath -Force
- Write-Host "Fichier protégé avec succès : $newFilePath"
- }
- # Fonction de déprotection
- function Unprotect-File {
- param (
- [Parameter(Mandatory=$true, Position=0)]
- [string]$filePath
- )
- # Déprotection du fichier avec Themida
- & $themidaPath /unprotect $filePath
- # Renommage du fichier sans l'extension .thunder
- $newFilePath = Join-Path (Split-Path $filePath) "$([IO.Path]::GetFileNameWithoutExtension($filePath) -replace '\.thunder$')"
- Rename-Item -Path $filePath -NewName $newFilePath -Force
- Write-Host "Fichier déprotégé avec succès : $newFilePath"
- }
- # Création de la fenêtre principale
- Add-Type -AssemblyName System.Windows.Forms
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Protection de fichiers avec Themida"
- $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
- $form.MaximizeBox = $false
- $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- # Création du ComboBox pour le choix de l'action
- $actionComboBox = New-Object System.Windows.Forms.ComboBox
- $actionComboBox.Items.Add("Protéger")
- $actionComboBox.Items.Add("Déprotéger")
- $actionComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
- $actionComboBox.Location = New-Object System.Drawing.Point(10, 10)
- $actionComboBox.Size = New-Object System.Drawing.Size(150, 20)
- $form.Controls.Add($actionComboBox)
- # Création du ComboBox pour le choix de la configuration
- $configComboBox = New-Object System.Windows.Forms.ComboBox
- $configComboBox.Items.Add("Forte")
- $configComboBox.Items.Add("Moyenne")
- $configComboBox.Items.Add("Faible")
- $configComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
- $configComboBox.Location = New-Object System.Drawing.Point(170, 10)
- $configComboBox.Size = New-Object System.Drawing.Size(100, 20)
- $form.Controls.Add($configComboBox)
- # Création du bouton pour sélectionner le fichier
- $fileButton = New-Object System.Windows.Forms.Button
- $fileButton.Text = "Sélectionner un fichier"
- $fileButton.Location = New-Object System.Drawing.Point(10, 40)
- $fileButton.Size = New-Object System.Drawing.Size(260, 23)
- $fileButton.Add_Click({
- $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
- $openFileDialog.Filter = "All files (*.*)|*.*"
- $openFileDialog.Multiselect = $false
- $openFileDialog.InitialDirectory = [Environment]::GetFolderPath("Desktop")
- if ($openFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
- $filePathTextBox.Text = $openFileDialog.FileName
- }
- })
- $form.Controls.Add($fileButton)
- #Création de la zone de texte pour afficher le chemin du fichier
- $filePathTextBox = New-Object System.Windows.Forms.TextBox
- $filePathTextBox.Location = New-Object System.Drawing.Point(10, 70)
- $filePathTextBox.Size = New-Object System.Drawing.Size(260, 20)
- $filePathTextBox.ReadOnly = $true
- $form.Controls.Add($filePathTextBox)
- #Création du bouton pour lancer l'action
- $actionButton = New-Object System.Windows.Forms.Button
- $actionButton.Text = "Lancer l'action"
- $actionButton.Location = New-Object System.Drawing.Point(10, 100)
- $actionButton.Size = New-Object System.Drawing.Size(260, 23)
- $actionButton.Add_Click({
- if ($actionComboBox.SelectedItem -eq "Protéger") {
- Protect-File -filePath $filePathTextBox.Text
- } elseif ($actionComboBox.SelectedItem -eq "Déprotéger") {
- Unprotect-File -filePath $filePathTextBox.Text
- } else {
- Write-Host "Action inconnue : $($actionComboBox.SelectedItem)"
- }
- })
- $form.Controls.Add($actionButton)
- # Affichage de la fenêtre
- $form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement