Récemment, j'ai réalisé que cette immonde écriture inclusive était revenue dans Firefox et Thunderbird.
J'ai donc réexécuté mes scripts de désinfection, mais ils ne fonctionnaient plus.
Cela signifie 2 choses :
1 - Les traducteurs ne sont pas allés voir un psychiatre, comme je le leur avait pourtant conseillé.
Je leur ai bien expliqué leur maladie mentale ci-dessus, mais bon, c'est le principe de la folie : on ne sait pas qu'on est fou.
Laissons donc ces déchets de l'humanité rater leur vie et finir dans la poubelle de la sélection naturelle.
2 - Je n'aurais pas dû laisser ce code à ChatGPT. C'était de la flemme, et ce n'est jamais une bonne chose.
J'ai donc regardé de près de code que ChatGPT avait pondu et en effet... c'est du code dégueulasse. Je m'en excuse.
On en parle beaucoup, mais quand on y regarde de près, même la version 4.0 de ChatGPT ne semble pas très efficace pour coder.
ChatGPT est utile pour "pisser" du code simple en grosse quantité, genre pour faire un site Internet vite fait.
Mais dès qu'il s'agit d'un code complexe, pour l'instant l'intelligence artificielle est plus de la bêtise artificielle.
J'ai donc pris une journée pour faire un vrai code potable.
Voici donc un nouveau code. Cette fois c'est le même pour Firefox et Thunderbird, seule l'entête change.
De plus, vous pouvez ajouter autant de lignes à modifier que vous voulez, et pas besoin qu'elles soient dans l'ordre ou présentes dans le fichier à modifier.
C'était légèrement plus complexe à coder, mais cette fois ce code ne deviendra pas obsolète.
Thunderbird en Powershell :
# Character encoding = UTF-16 LE (Byte Order Mark = FF FE)
# End-of-line = Windows (CR LF)
# Composants requis :
$current_folder = $PWD.Path
# _____________________________________________________________________________
# Partie à modifier pour ajouter des fichiers et erreurs à corriger :
# Emplacement personnalisé du dossier contenant le fichier "thunderbird.exe".
# Vous pouvez le laisser vide. Exemple :
# $program_folder = "$current_folder\Mozilla Thunderbird"
$program_folder = ""
# Emplacements connus :
$program_folder_portable_32 = "$current_folder\App\Thunderbird"
$program_folder_portable_64 = "$current_folder\App\Thunderbird64"
$program_folder_installed_32 = "${env:ProgramFiles(x86)}\Mozilla Thunderbird"
$program_folder_installed_64 = "${$env:ProgramFiles}\Mozilla Thunderbird"
# Fichier(s) à réparer :
$corrupted_file_1 = "omni.ja"
# Réparations à faire :
$corrupted_file_1_error_ori = @()
$corrupted_file_1_error_fix = @()
# away=absent·e => away=absent
$corrupted_file_1_error_ori += "6E74C2B7650A" # nt·e
$corrupted_file_1_error_fix += "6E740A0A0A0A" # nt
# utilisateur·trice => utilisateur
$corrupted_file_1_error_ori += "C2B774726963650A" # ·trice
$corrupted_file_1_error_fix += "0A0A0A0A0A0A0A0A" #
# Jean·ne Dupont => Jean Dupont
$corrupted_file_1_error_ori += "C2B76E65204475706F6E740A" # ·ne Dupont
$corrupted_file_1_error_fix += "204475706F6E740A0A0A0A0A" # Dupont
# jean.ne.dupont@example.com => jean.dupont@exemple.com
$corrupted_file_1_error_ori += "2E6E652E6475706F6E74406578616D706C652E636F6D0A" # .ne.dupont@example.com
$corrupted_file_1_error_fix += "2E6475706F6E74406578656D706C652E636F6D0A0A0A0A" # .dupont@exemple.com
# averti·e lorsque la génération de clé sera terminée. => averti lorsque la génération de clé sera terminée.
$corrupted_file_1_error_ori += "C2B765206C6F7273717565206C612067C3A96EC3A9726174696F6E20646520636CC3A92073657261207465726D696EC3A9652E0A" # ·e lorsque la génération de clé sera terminée.
$corrupted_file_1_error_fix += "206C6F7273717565206C612067C3A96EC3A9726174696F6E20646520636CC3A92073657261207465726D696EC3A9652E0A0A0A0A" # lorsque la génération de clé sera terminée.
# satisfait·e du résultat. => satisfait du résultat.
$corrupted_file_1_error_ori += "C2B7652064752072C3A973756C7461742E0A" # ·e du résultat.
$corrupted_file_1_error_fix += "2064752072C3A973756C7461742E0A0A0A0A" # du résultat.
# connecté·e plusieurs fois, une autre session peut avoir reçu le message. => connecté plusieurs fois, une autre session peut avoir reçu le message.
$corrupted_file_1_error_ori += "C2B76520706C7573696575727320666F69732C20756E652061757472652073657373696F6E20706575742061766F6972207265C3A775206C65206D6573736167652E0A" # ·e plusieurs fois, une autre session peut avoir reçu le message.
$corrupted_file_1_error_fix += "20706C7573696575727320666F69732C20756E652061757472652073657373696F6E20706575742061766F6972207265C3A775206C65206D6573736167652E0A0A0A0A" # plusieurs fois, une autre session peut avoir reçu le message.
# pisté·e => pisté
$corrupted_file_1_error_ori += "C3A9C2B7650A" # é·e
$corrupted_file_1_error_fix += "C3A90A0A0A0A" # é
# _____________________________________________________________________________
# Partie à ne pas modifier :
function i_my_replace_array_hex_strings_in_file([string[]]$array_hex_strings_to_find, [string[]]$array_hex_strings_to_replace, [string]$file_fullname)
{
if ($array_hex_strings_to_find.GetUpperBound(0) -ne $array_hex_strings_to_replace.GetUpperBound(0))
{
Write-Host "Erreur :`r`nLe nombre de cases dans le tableau des chaînes hexadécimales à détecter ($($array_hex_strings_to_find.GetUpperBound(0) + 1))`r`net dans le tableau des chaînes hexadécimales à remplacer ($($array_hex_strings_to_replace.GetUpperBound(0) + 1))`r`nn'est pas identique."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true) # Si le buffer n'est pas vide, au cas où une touche aurait déjà été pressée.
{
while ($Host.UI.RawUI.KeyAvailable -eq $true) # Vide le buffer et met en pause.
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") # Met en pause.
}
exit 0
}
for ($i = 0; $i -le $array_hex_strings_to_find.GetUpperBound(0); $i++)
{
if ($array_hex_strings_to_find[$i].Length -ne $array_hex_strings_to_replace[$i].Length)
{
Write-Host "Erreur :`r`nLa variable $($array_hex_strings_to_find[$i]) et`r`nla variable $($array_hex_strings_to_replace[$i])"
Write-Host "n'ont pas le même nombre de caractères ($($array_hex_strings_to_find[$i].Length) contre $($array_hex_strings_to_replace[$i].Length))."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($array_hex_strings_to_find[$i].Length % 2 -ne 0)
{
Write-Host "Erreur, les variables :`r`n$($array_hex_strings_to_find[$i]) et`r`n$($array_hex_strings_to_replace[$i])`r`nont un nombre impair de caractères."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($array_hex_strings_to_find[$i].Length -lt 12)
{
Write-Host "Erreur, les variables :`r`n$($array_hex_strings_to_find[$i]) et`r`n$($array_hex_strings_to_replace[$i])"
Write-Host "doivent avoir au moins 12 caractères hexadécimaux pour représenter"
Write-Host "au moins 6 octets. Or ici, elles n'en contiennent que $($array_hex_strings_to_find[$i].Length)."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
}
Out-File -FilePath "$file_fullname.temporary" -Force -Encoding ASCII # (Force = Écraser si existe déjà) (Encoding ASCII = Utiliser ASCII au lieu d'Unicode UTF16LE donc pas de Byte Order Mark FFFE)
if ((Test-Path "$file_fullname.temporary") -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname.temporary"
Write-Host "n'a pas pu être créé. L'écriture dans ce dossier nécessite probablement`r`ndes privilèges d'administrateur. Veuillez exécuter ce script en tant qu'administrateur."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
# Pour aller plus vite, on crée 5 tableaux en 2 dimensions.
# Nous sommes obligés de créer chaque dimension indépendamment car
# il est impossible de redimensionner dynamiquement les 2 dimensions.
# Concernant la 1ère dimension :
# Le 1er tableau contiendra les premiers octets de toutes les chaînes
# à rechercher, convertis en décimal et en éliminant les doublons.
# Le 2ème tableau contiendra les deuxièmes octets, etc.
# Le 3ème tableau contiendra les troisièmes octets, etc.
$array_bytes_to_find_1 = @()
$array_bytes_to_find_2 = @()
$array_bytes_to_find_3 = @()
$array_bytes_to_find_4 = @()
$array_bytes_to_find_5 = @()
for ($i_1 = 0; $i_1 -le $array_hex_strings_to_find.GetUpperBound(0); $i_1++)
{
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_1.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(0, 2), 16) -eq $array_bytes_to_find_1[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_1 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(0, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_2.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(2, 2), 16) -eq $array_bytes_to_find_2[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_2 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(2, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_3.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(4, 2), 16) -eq $array_bytes_to_find_3[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_3 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(4, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_4.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(6, 2), 16) -eq $array_bytes_to_find_4[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_4 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(6, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_5.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(8, 2), 16) -eq $array_bytes_to_find_5[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_5 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(8, 2), 16)
}
}
# Concernant la 2ème dimension :
# Pour chaque tableau, elle contiendra les numéros des chaînes
# auxquelles les octets correspondent (en commençant par 0).
# Imaginons que la 1ère case du 1er tableau contient l'octet C2 = 194
# et que plusieurs chaînes commencent par C2 (doublons), par exemple
# les chaînes 1 2 4 5 6, alors les chiffres 0 1 3 4 5 seront inscrits
# dans la 2ème dimension de la 1ère case du 1er tableau.
$array_bytes_to_find_1_2D = New-Object 'object[,]' ($array_bytes_to_find_1.GetUpperBound(0) + 1), 1
$array_bytes_to_find_2_2D = New-Object 'object[,]' ($array_bytes_to_find_2.GetUpperBound(0) + 1), 1
$array_bytes_to_find_3_2D = New-Object 'object[,]' ($array_bytes_to_find_3.GetUpperBound(0) + 1), 1
$array_bytes_to_find_4_2D = New-Object 'object[,]' ($array_bytes_to_find_4.GetUpperBound(0) + 1), 1
$array_bytes_to_find_5_2D = New-Object 'object[,]' ($array_bytes_to_find_5.GetUpperBound(0) + 1), 1
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_1_2D[$i_1, 0] = $array_bytes_to_find_1[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(0, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_1_2D[$i_1, 0])
{
if ($array_bytes_to_find_1_2D.GetUpperBound(1) -lt $i_2)
{
# En PowerShell il n'existe pas d'équivalent à la commande
# ReDim Preserve array_bytes_to_find_1_2D(ubound,ubound+1)
# du VBScript pour redimensionner la 2ème dimension du tableau.
# La notation "+=" ajoute un élément à la fin d'un tableau,
# mais seulement s'il est en 1 dimension, pas en 2 dimensions.
# Il faut donc créer un autre tableau $array_subarray_2D
# avec une case supplémentaire puis recopier le tableau dedans
# en utilisant une boucle for.
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_1_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_1_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_1_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_1_2D[$i, $j]
}
}
$array_bytes_to_find_1_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_1_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_2_2D[$i_1, 0] = $array_bytes_to_find_2[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(2, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_2_2D[$i_1, 0])
{
if ($array_bytes_to_find_2_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_2_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_2_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_2_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_2_2D[$i, $j]
}
}
$array_bytes_to_find_2_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_2_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_3_2D[$i_1, 0] = $array_bytes_to_find_3[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(4, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_3_2D[$i_1, 0])
{
if ($array_bytes_to_find_3_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_3_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_3_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_3_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_3_2D[$i, $j]
}
}
$array_bytes_to_find_3_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_3_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_4_2D[$i_1, 0] = $array_bytes_to_find_4[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(6, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_4_2D[$i_1, 0])
{
if ($array_bytes_to_find_4_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_4_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_4_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_4_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_4_2D[$i, $j]
}
}
$array_bytes_to_find_4_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_4_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_5_2D[$i_1, 0] = $array_bytes_to_find_5[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(8, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_5_2D[$i_1, 0])
{
if ($array_bytes_to_find_5_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_5_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_5_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_5_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_5_2D[$i, $j]
}
}
$array_bytes_to_find_5_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_5_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
<#
Write-Host "1ers octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_1_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_1_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_1_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_1_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_1_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "2èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_2_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_2_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_2_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_2_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_2_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "3èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_3_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_3_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_3_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_3_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_3_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "4èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_4_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_4_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_4_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_4_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_4_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "5èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_5_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_5_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_5_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_5_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_5_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
Write-Host
#>
Write-Host -NoNewline "`r`nAnalyse en cours... "
$file_input = [System.IO.File]::OpenRead($file_fullname) # Ouverture du fichier en lecture
$file_output = [System.IO.File]::Create("$file_fullname.temporary") # Ouverture du fichier en écriture
$array_bytes_to_find_1_2D_ubound = $array_bytes_to_find_1_2D.GetUpperBound(0)
$array_bytes_to_find_2_2D_ubound = $array_bytes_to_find_2_2D.GetUpperBound(0)
$array_bytes_to_find_3_2D_ubound = $array_bytes_to_find_3_2D.GetUpperBound(0)
$array_bytes_to_find_4_2D_ubound = $array_bytes_to_find_4_2D.GetUpperBound(0)
$array_bytes_to_find_5_2D_ubound = $array_bytes_to_find_5_2D.GetUpperBound(0)
$array_byte_buffer_1 = @()
$array_byte_buffer_2 = @()
$array_match_found_1 = @()
$array_match_found_2 = @()
$byte_buffer_read = New-Object byte[] 1
$byte_read = 0
$i_byte_check = 0
$i_replacement_count = 0
while ($file_input.Read($byte_buffer_read, 0, 1) -ne 0)
{
$byte_read = $byte_buffer_read[0]
# Write-Host "Caractère lu (hexadécimal $($byte_read.ToString("X2")) = décimal $byte_read) : ""$([char]$byte_read)"""
# L'octet lu est stocké dans la dernière case d'un tableau (buffer).
$array_byte_buffer_1 += $byte_read
# Write-Host "Contenu du buffer : $($array_byte_buffer_1 -join " ")"
switch ($i_byte_check)
{
0
{
# On considère que le buffer peut contenir plusieurs octets en attente d'être traités,
# c'est-à-dire écrits dans le fichier de sortie s'il n'existe aucune correspondance.
# Chaque 1er octet traité disparaît du buffer, dont la taille se réduit.
# Lorsque sa taille atteint 0 (GetUpperBound = -1), le buffer est vide,
# tous les octets ont été traités.
$b_exit_while_1 = $flase
while ($array_byte_buffer_1.GetUpperBound(0) -ge 0 -and $b_exit_while_1 -eq $flase)
{
# Première boucle de vérification.
# On compare le 1er octet ($i_byte_check = 0) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 1er tableau.
$i_0 = 0
while ($i_0 -le $array_bytes_to_find_1_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# l'écriture du fichier de sortie est suspendue ($i_byte_check ≠ 0)
# et l'octet reste stocké dans le buffer.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_1_2D[$i_0, 0])
{
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_1_2D[$i_0, 0])"
$b_exit_while_1 = $true
$i_byte_check++ # $i_byte_check = 1
$i_0--
}
$i_0++
}
# Si il ne correspond pas, l'octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
if ($b_exit_while_1 -eq $flase)
{
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
}
break
}
1
{
# Deuxième boucle de vérification.
# On compare le 2ème octet ($i_byte_check = 1) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 2ème tableau.
$b_exit_while_1 = $flase
$i_1 = 0
while ($i_1 -le $array_bytes_to_find_2_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# on compare la 2ème dimension de la case du 1er tableau précédent
# à la 2ème dimension de cette case de ce 2ème tableau et
# on stocke les numéros communs dans un tableau : $array_match_found_1.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_2_2D[$i_1, 0])
{
$b_exit_while_1 = $true
$array_match_found_1 = @()
$i_0_2D = 1
$b_exit_while_2 = $false
while ($i_0_2D -le $array_bytes_to_find_1_2D.GetUpperBound(1) -and $b_exit_while_2 -eq $false)
{
if ($array_bytes_to_find_1_2D[$i_0, $i_0_2D] -ne $null)
{
$i_1_2D = 1
$b_exit_while_3 = $false
while ($i_1_2D -le $array_bytes_to_find_2_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_2_2D[$i_1, $i_1_2D] -ne $null)
{
if ($array_bytes_to_find_1_2D[$i_0, $i_0_2D] -eq $array_bytes_to_find_2_2D[$i_1, $i_1_2D])
{
$array_match_found_1 += $array_bytes_to_find_1_2D[$i_0, $i_0_2D]
}
$i_1_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_0_2D++
}
else
{
$b_exit_while_2 = $true
}
}
# Si le tableau n'est pas vide, il indique le ou les numéros
# des chaînes qui commencent par ces 2 octets. Dans ce cas :
# l'écriture du fichier de sortie reste suspendue ($i_byte_check ≠ 0)
# et les octets restent stockés dans le buffer.
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_2_2D[$i_1, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 2
}
# Si le tableau est vide, les 2 octets ne correspondent
# à aucune chaîne à rechercher. C'est la même situation que
# si le 2ème octet ne correspond à aucune case du 2ème tableau.
}
$i_1++
}
# Si il ne correspond pas, le premier octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
# De plus $i_byte_check est réinitialisée donc on retourne
# à la première boucle de vérification pour vider le buffer.
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
2
{
# Troisième boucle de vérification.
# On compare le 3ème octet ($i_byte_check = 2) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 3ème tableau.
$b_exit_while_1 = $flase
$i_2 = 0
while ($i_2 -le $array_bytes_to_find_3_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# on compare le tableau précédent $array_match_found_1
# à la 2ème dimension de cette case de ce 3ème tableau et
# on stocke les numéros communs dans $array_match_found_1
# par l'intermédiaire d'un tableau temporaire : $array_match_found_2.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_3_2D[$i_2, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_1_2D = 0
$b_exit_while_2 = $false
while ($i_1_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_1_2D] -ne $null)
{
$i_2_2D = 1
$b_exit_while_3 = $false
while ($i_2_2D -le $array_bytes_to_find_3_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_3_2D[$i_2, $i_2_2D] -ne $null)
{
if ($array_match_found_1[$i_1_2D] -eq $array_bytes_to_find_3_2D[$i_2, $i_2_2D])
{
$array_match_found_2 += $array_match_found_1[$i_1_2D]
}
$i_2_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_1_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
# Si le tableau n'est pas vide, il indique le ou les numéros
# des chaînes qui commencent par ces 3 octets. Dans ce cas :
# l'écriture du fichier de sortie reste suspendue ($i_byte_check ≠ 0)
# et les octets restent stockés dans le buffer.
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_3_2D[$i_2, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 3
}
# Si le tableau est vide, les 3 octets ne correspondent
# à aucune chaîne à rechercher. C'est la même situation que
# si le 3ème octet ne correspond à aucune case du 3ème tableau.
}
$i_2++
}
# Si il ne correspond pas, le premier octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
# De plus $i_byte_check est réinitialisée donc on retourne
# à la première boucle de vérification pour vider le buffer.
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
3
{
$b_exit_while_1 = $flase
$i_3 = 0
while ($i_3 -le $array_bytes_to_find_4_2D_ubound -and $b_exit_while_1 -eq $flase)
{
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_4_2D[$i_3, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_2_2D = 0
$b_exit_while_2 = $false
while ($i_2_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_2_2D] -ne $null)
{
$i_3_2D = 1
$b_exit_while_3 = $false
while ($i_3_2D -le $array_bytes_to_find_4_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_4_2D[$i_3, $i_3_2D] -ne $null)
{
if ($array_match_found_1[$i_2_2D] -eq $array_bytes_to_find_4_2D[$i_3, $i_3_2D])
{
$array_match_found_2 += $array_match_found_1[$i_2_2D]
}
$i_3_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_2_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_4_2D[$i_3, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 4
}
}
$i_3++
}
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
4
{
$b_exit_while_1 = $flase
$i_4 = 0
while ($i_4 -le $array_bytes_to_find_5_2D_ubound -and $b_exit_while_1 -eq $flase)
{
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_5_2D[$i_4, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_3_2D = 0
$b_exit_while_2 = $false
while ($i_3_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_3_2D] -ne $null)
{
$i_4_2D = 1
$b_exit_while_3 = $false
while ($i_4_2D -le $array_bytes_to_find_5_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_5_2D[$i_4, $i_4_2D] -ne $null)
{
if ($array_match_found_1[$i_3_2D] -eq $array_bytes_to_find_5_2D[$i_4, $i_4_2D])
{
$array_match_found_2 += $array_match_found_1[$i_3_2D]
}
$i_4_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_3_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_5_2D[$i_4, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 5
}
}
$i_4++
}
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
default
{
# On prend le tableau $array_match_found_1, il contient le
# (ou les) numéro de case du tableau $array_hex_strings_to_find
# qui lui-même contient la chaîne complète des octets à analyser
# dont les 5 premiers octets correspondent.
# Remarque : il se peut que plusieurs chaînes aient leurs 5 premiers
# octets en commun. Voire que seul le dernier octet soit différent.
# Donc on analyse chaque case du tableau $array_match_found_1.
$b_exit_while_1 = $flase
$i_5 = 0 # (Inutile car i_5 reste à 0)
while ($i_5 -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_1 -eq $flase)
{
# On analyse la chaîne contenue dans $array_hex_strings_to_find.
# Si la chaîne continue à correspondre, on teste l'octet suivant.
if ($array_byte_buffer_1[$i_byte_check].ToString("X2") -eq $array_hex_strings_to_find[$array_match_found_1[$i_5]].Substring(2 * $i_byte_check, 2))
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_hex_strings_to_find[$array_match_found_1[$i_5]].Substring(2 * $i_byte_check, 2))"
$b_exit_while_1 = $true
$i_byte_check++
}
# Si la chaîne ne correspond plus, alors on retire son numéro du tableau $array_match_found_1.
# Et si le tableau est vide, alors aucune chaîne ne correspondait,
# donc le premier octet est traité et $i_byte_check est réinitialisée.
else
{
if ($array_match_found_1.GetUpperBound(0) -ge 1)
{
$array_match_found_2 = @()
$array_match_found_2 = $array_match_found_1[1..($($array_match_found_1.GetUpperBound(0) + 1) - 1)]
$array_match_found_1 = $array_match_found_2
}
else
{
$array_match_found_1 = @()
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
}
if ($i_byte_check -gt 0)
{
# Si la correspondance va jusqu'au bout de la chaîne, alors la chaîne a été détectée.
if ($i_byte_check -eq $array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)
{
# Dans ce cas on écrit la nouvelle chaîne et on vide le buffer.
for ($i = 0; $i -le $array_hex_strings_to_replace[$array_match_found_1[$i_5]].Length - 1; $i += 2)
{
$file_output.WriteByte([byte]::Parse($array_hex_strings_to_replace[$array_match_found_1[$i_5]].Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber))
}
# Write-Host `r`n"Contenu de la chaîne n°$($array_match_found_1[$i_5] + 1) ($($array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2) cases) : $($array_hex_strings_to_find[$array_match_found_1[$i_5]])`r`nContenu du buffer ($($array_byte_buffer_1.GetUpperBound(0) + 1) cases) : $($array_byte_buffer_1 -join " ")"
# On vide le buffer de la chaîne à rechercher.
if ($array_byte_buffer_1.GetUpperBound(0) -ge $array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[($array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
# Write-Host "Contenu restant du buffer = : $($array_byte_buffer_1 -join " ")"
}
else
{
$array_byte_buffer_1 = @()
}
$i_byte_check = 0
$i_replacement_count++
Write-Host "`r`nFichier :`r`n$file_fullname`r`nSéquence n°$($array_match_found_1[$i_5] + 1) trouvée :`r`n$($array_hex_strings_to_find[$array_match_found_1[$i_5]])`r`nRemplacée par :`r`n$($array_hex_strings_to_replace[$array_match_found_1[$i_5]])`r`n"
Write-Host -NoNewline "`r`nAnalyse en cours... "
}
}
}
}
}
}
$file_input.Close()
$file_output.Close()
$file_input.Dispose()
$file_output.Dispose()
return $i_replacement_count
}
function i_my_rename_file([string]$file_fullname, [string]$file_fullname_new)
{
if ((Test-Path $file_fullname) -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname`r`nn'existe pas, impossible de le renommer en :`r`n$file_fullname_new"
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
Rename-Item -Path $file_fullname -NewName $file_fullname_new -ErrorAction Stop
Write-Host "Le fichier :`r`n$file_fullname`r`na été renommé en :`r`n$file_fullname_new`r`n"
if ((Test-Path $file_fullname_new) -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname`r`nn'a pas pu être renommé."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
return 0
}
function i_my_fix_corrupted_file([string[]]$corrupted_file_error_ori, [string[]]$corrupted_file_error_fix, [string]$corrupted_file)
{
$i_installation_type = 0
if ($program_folder -ne "")
{
if ((Test-Path "$program_folder\$corrupted_file") -eq $false)
{
Write-Host "Erreur, fichier non détecté :`r`n$program_folder\$corrupted_file"
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
$i_installation_type = 1
Write-Host "Fichier détecté :`r`n$program_folder\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_portable_32\$corrupted_file") -eq $true)
{
$i_installation_type = 2
Write-Host "Fichier détecté :`r`n$program_folder_portable_32\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_portable_64\$corrupted_file") -eq $true)
{
$i_installation_type += 3
Write-Host "Fichier détecté :`r`n$program_folder_portable_64\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_installed_32\$corrupted_file") -eq $true)
{
$i_installation_type = 6
Write-Host "Fichier détecté :`r`n$program_folder_portable_32\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_installed_64\$corrupted_file") -eq $true)
{
$i_installation_type = 7
Write-Host "Fichier détecté :`r`n$program_folder_portable_64\$corrupted_file`r`n"
}
if ($i_installation_type -eq 0)
{
Write-Host "Erreur, aucun fichier détecté."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($i_installation_type -eq 1)
{
if ((Test-Path -Path "$program_folder\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder\$corrupted_file" "$program_folder\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder\$corrupted_file.temporary" "$program_folder\$corrupted_file"
}
if ($i_installation_type -eq 2 -or $i_installation_type -eq 5)
{
if ((Test-Path -Path "$program_folder_portable_32\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_portable_32\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_portable_32\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_portable_32\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_portable_32\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_portable_32\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_portable_32\$corrupted_file" "$program_folder_portable_32\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_portable_32\$corrupted_file.temporary" "$program_folder_portable_32\$corrupted_file"
}
if ($i_installation_type -eq 3 -or $i_installation_type -eq 5)
{
if ((Test-Path -Path "$program_folder_portable_64\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_portable_64\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_portable_64\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_portable_64\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_portable_64\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_portable_64\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_portable_64\$corrupted_file" "$program_folder_portable_64\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_portable_64\$corrupted_file.temporary" "$program_folder_portable_64\$corrupted_file"
}
if ($i_installation_type -eq 6)
{
if ((Test-Path -Path "$program_folder_installed_32\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_installed_32\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_installed_32\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_installed_32\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_installed_32\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_installed_32\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_installed_32\$corrupted_file" "$program_folder_installed_32\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_installed_32\$corrupted_file.temporary" "$program_folder_installed_32\$corrupted_file"
}
if ($i_installation_type -eq 7)
{
if ((Test-Path -Path "$program_folder_installed_64\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_installed_64\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_installed_64\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_installed_64\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_installed_64\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_installed_64\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_installed_64\$corrupted_file" "$program_folder_installed_64\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_installed_64\$corrupted_file.temporary" "$program_folder_installed_64\$corrupted_file"
}
return $number_of_replacements
}
# _____________________________________________________________________________
# Partie à modifier pour ajouter des fichiers à corriger :
# Lancement du script :
$number_of_replacements = i_my_fix_corrupted_file $corrupted_file_1_error_ori $corrupted_file_1_error_fix ("$corrupted_file_1")
# _____________________________________________________________________________
# Partie à ne pas modifier :
$pause_message = "L'exécution de ce programme est terminée."
Write-Host "$pause_message`r`n`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
Thunderbird en VBScript
' Character encoding = UTF-16 LE (Byte Order Mark = FF FE)
' End-of-line = Windows (CR LF)
' Composants requis :
set object_shell = WScript.CreateObject("WScript.Shell")
set object_file_system = WScript.CreateObject("Scripting.FileSystemObject")
current_folder = object_file_system.GetParentFolderName(WScript.ScriptFullName)
' _____________________________________________________________________________
' Partie à modifier pour ajouter des fichiers et erreurs à corriger :
' Emplacement personnalisé du dossier contenant le fichier "thunderbird.exe".
' Vous pouvez le laisser vide. Exemple :
' program_folder = current_folder & "\Mozilla Thunderbird"
program_folder = ""
' Emplacements connus :
program_folder_portable_32 = current_folder & "\App\Thunderbird"
program_folder_portable_64 = current_folder & "\App\Thunderbird64"
program_folder_installed_32 = object_shell.ExpandEnvironmentStrings("%ProgramFiles(x86)%") & "\Mozilla Thunderbird"
program_folder_installed_64 = object_shell.ExpandEnvironmentStrings("%ProgramFiles%") & "\Mozilla Thunderbird"
' Fichiers à réparer :
corrupted_file_1 = "omni.ja"
' Réparations à faire :
dim corrupted_file_1_error_ori()
redim corrupted_file_1_error_ori(-1)
dim corrupted_file_1_error_fix()
redim corrupted_file_1_error_fix(-1)
' away=absent·e => away=absent
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "6E74C2B7650A" ' é·e
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "6E740A0A0A0A" ' nt
' utilisateur·trice => utilisateur
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B774726963650A" ' ·trice
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "0A0A0A0A0A0A0A0A" '
' Jean·ne Dupont => Jean Dupont
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B76E65204475706F6E740A" ' ·ne Dupont
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "204475706F6E740A0A0A0A0A" ' Dupont
' jean.ne.dupont@example.com => jean.dupont@example.com
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "2E6E652E6475706F6E74406578616D706C652E636F6D0A" ' .ne.dupont@example.com
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "2E6475706F6E74406578656D706C652E636F6D0A0A0A0A" ' .dupont@exemple.com
' averti·e lorsque la génération de clé sera terminée. => averti lorsque la génération de clé sera terminée.
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B765206C6F7273717565206C612067C3A96EC3A9726174696F6E20646520636CC3A92073657261207465726D696EC3A9652E0A" ' ·e lorsque la génération de clé sera terminée.
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "206C6F7273717565206C612067C3A96EC3A9726174696F6E20646520636CC3A92073657261207465726D696EC3A9652E0A0A0A0A" ' lorsque la génération de clé sera terminée.
' satisfait·e du résultat. => satisfait du résultat.
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B7652064752072C3A973756C7461742E0A" ' ·e du résultat.
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "2064752072C3A973756C7461742E0A0A0A0A" ' du résultat.
' connecté·e plusieurs fois, une autre session peut avoir reçu le message. => connecté plusieurs fois, une autre session peut avoir reçu le message.
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B76520706C7573696575727320666F69732C20756E652061757472652073657373696F6E20706575742061766F6972207265C3A775206C65206D6573736167652E0A" ' ·e plusieurs fois, une autre session peut avoir reçu le message.
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "20706C7573696575727320666F69732C20756E652061757472652073657373696F6E20706575742061766F6972207265C3A775206C65206D6573736167652E0A0A0A0A" ' plusieurs fois, une autre session peut avoir reçu le message.
' pisté·e => pisté
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C3A9C2B7650A" ' é·e
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "C3A90A0A0A0A" ' é
' _____________________________________________________________________________
' Partie à ne pas modifier :
function i_my_replace_array_hex_strings_in_file(byval array_hex_strings_to_find, byval array_hex_strings_to_replace, byval file_fullname)
if ubound(array_hex_strings_to_find) <> ubound(array_hex_strings_to_replace) then
MsgBox "Erreur :" & vbCrLf & "Le nombre de cases dans le tableau des chaînes hexadécimales à détecter (" & ubound(array_hex_strings_to_find) + 1 & ")" & vbCrLf & "et dans le tableau des chaînes hexadécimales à remplacer (" & ubound(array_hex_strings_to_replace) + 1 & ")" & vbCrLf & "n'est pas identique.", 48, "Erreur" ' 0 = vbOKOnly vbDefaultButton1 vbApplicationModal 48 = vbExclamation
WScript.Quit(0)
end if
for i = 0 to ubound(array_hex_strings_to_find) step 1
if len(array_hex_strings_to_find(i)) <> len(array_hex_strings_to_replace(i)) then
MsgBox "Erreur :" & vbCrLf & "La variable " & array_hex_strings_to_find(i) & " et" & vbCrLf & "la variable " & array_hex_strings_to_replace(i) & vbCrLf _
& "n'ont pas le même nombre de caractères (" & len(array_hex_strings_to_find(i)) & " contre " & len(array_hex_strings_to_replace(i)) & ").", 48, "Erreur"
WScript.Quit(0)
end if
if len(array_hex_strings_to_find(i)) MOD 2 <> 0 then
MsgBox "Erreur, les variables :" & vbCrLf & array_hex_strings_to_find(i) & " et" & vbCrLf & array_hex_strings_to_replace(i) & vbCrLf & "ont un nombre impair de caractères.", 48, "Erreur"
WScript.Quit(0)
end if
if len(array_hex_strings_to_find(i)) < 12 then
MsgBox "Erreur, les variables :" & vbCrLf & array_hex_strings_to_find(i) & " et" & vbCrLf & array_hex_strings_to_replace(i) & vbCrLf _
& "doivent avoir au moins 12 caractères hexadécimaux pour représenter" & vbCrLf _
& "au moins 6 octets. Or ici, elles n'en contiennent que " & len(array_hex_strings_to_find(i)) & ".", 48, "Erreur"
WScript.Quit(0)
end if
next
set object_file = object_file_system.CreateTextFile(file_fullname & ".temporary", TRUE, FALSE) ' (TRUE = Écraser si existe déjà) (FALSE = Utiliser ASCII au lieu d'Unicode UTF16LE donc pas de Byte Order Mark FFFE)
object_file.Close
if object_file_system.FileExists(file_fullname & ".temporary") = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & ".temporary" & vbCrLf _
& "n'a pas pu être créé. L'écriture dans ce dossier nécessite probablement" & vbCrLf & "des privilèges d'administrateur. Veuillez exécuter ce script en tant qu'administrateur.", 48, "Erreur"
WScript.Quit(0)
end if
' Pour aller plus vite, on crée 5 tableaux en 2 dimensions.
' Nous sommes obligés de créer chaque dimension indépendamment car
' il est impossible de redimensionner dynamiquement les 2 dimensions.
' Concernant la 1ère dimension :
' Le 1er tableau contiendra les premiers octets de toutes les chaînes
' à rechercher, convertis en décimal et en éliminant les doublons.
' Le 2ème tableau contiendra les deuxièmes octets, etc.
' Le 3ème tableau contiendra les troisièmes octets, etc.
dim array_bytes_to_find_1()
redim array_bytes_to_find_1(-1)
dim array_bytes_to_find_2()
redim array_bytes_to_find_2(-1)
dim array_bytes_to_find_3()
redim array_bytes_to_find_3(-1)
dim array_bytes_to_find_4()
redim array_bytes_to_find_4(-1)
dim array_bytes_to_find_5()
redim array_bytes_to_find_5(-1)
for i_1 = 0 to ubound(array_hex_strings_to_find) step 1
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_1) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 1, 2)) = array_bytes_to_find_1(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_1(ubound(array_bytes_to_find_1) + 1)
array_bytes_to_find_1(ubound(array_bytes_to_find_1)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 1, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_2) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 3, 2)) = array_bytes_to_find_2(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_2(ubound(array_bytes_to_find_2) + 1)
array_bytes_to_find_2(ubound(array_bytes_to_find_2)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 3, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_3) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 5, 2)) = array_bytes_to_find_3(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_3(ubound(array_bytes_to_find_3) + 1)
array_bytes_to_find_3(ubound(array_bytes_to_find_3)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 5, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_4) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 7, 2)) = array_bytes_to_find_4(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_4(ubound(array_bytes_to_find_4) + 1)
array_bytes_to_find_4(ubound(array_bytes_to_find_4)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 7, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_5) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 9, 2)) = array_bytes_to_find_5(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_5(ubound(array_bytes_to_find_5) + 1)
array_bytes_to_find_5(ubound(array_bytes_to_find_5)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 9, 2))
end if
next
' Concernant la 2ème dimension :
' Pour chaque tableau, elle contiendra les numéros des chaînes
' auxquelles les octets correspondent (en commençant par 0).
' Imaginons que la 1ère case du 1er tableau contient l'octet C2 = 194
' et plusieurs chaînes commencent par C2 (doublons), par exemple les
' chaînes 1 2 4 5 6, alors les chiffres 0 1 3 4 5 seront inscrits
' dans la 2ème dimension de la 1ère case du 1er tableau.
dim array_bytes_to_find_1_2D()
redim array_bytes_to_find_1_2D(ubound(array_bytes_to_find_1), 0)
dim array_bytes_to_find_2_2D()
redim array_bytes_to_find_2_2D(ubound(array_bytes_to_find_2), 0)
dim array_bytes_to_find_3_2D()
redim array_bytes_to_find_3_2D(ubound(array_bytes_to_find_3), 0)
dim array_bytes_to_find_4_2D()
redim array_bytes_to_find_4_2D(ubound(array_bytes_to_find_4), 0)
dim array_bytes_to_find_5_2D()
redim array_bytes_to_find_5_2D(ubound(array_bytes_to_find_5), 0)
for i_1 = 0 to ubound(array_bytes_to_find_1_2D, 1) step 1
array_bytes_to_find_1_2D(i_1, 0) = array_bytes_to_find_1(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 1, 2)) = array_bytes_to_find_1_2D(i_1, 0) then
if ubound(array_bytes_to_find_1_2D, 2) < i_2 then
redim preserve array_bytes_to_find_1_2D(ubound(array_bytes_to_find_1_2D, 1), ubound(array_bytes_to_find_1_2D, 2) + 1)
end if
array_bytes_to_find_1_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_2_2D, 1) step 1
array_bytes_to_find_2_2D(i_1, 0) = array_bytes_to_find_2(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 3, 2)) = array_bytes_to_find_2_2D(i_1, 0) then
if ubound(array_bytes_to_find_2_2D, 2) < i_2 then
redim preserve array_bytes_to_find_2_2D(ubound(array_bytes_to_find_2_2D, 1), ubound(array_bytes_to_find_2_2D, 2) + 1)
end if
array_bytes_to_find_2_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_3_2D, 1) step 1
array_bytes_to_find_3_2D(i_1, 0) = array_bytes_to_find_3(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 5, 2)) = array_bytes_to_find_3_2D(i_1, 0) then
if ubound(array_bytes_to_find_3_2D, 2) < i_2 then
redim preserve array_bytes_to_find_3_2D(ubound(array_bytes_to_find_3_2D, 1), ubound(array_bytes_to_find_3_2D, 2) + 1)
end if
array_bytes_to_find_3_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_4_2D, 1) step 1
array_bytes_to_find_4_2D(i_1, 0) = array_bytes_to_find_4(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 7, 2)) = array_bytes_to_find_4_2D(i_1, 0) then
if ubound(array_bytes_to_find_4_2D, 2) < i_2 then
redim preserve array_bytes_to_find_4_2D(ubound(array_bytes_to_find_4_2D, 1), ubound(array_bytes_to_find_4_2D, 2) + 1)
end if
array_bytes_to_find_4_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_5_2D, 1) step 1
array_bytes_to_find_5_2D(i_1, 0) = array_bytes_to_find_5(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 9, 2)) = array_bytes_to_find_5_2D(i_1, 0) then
if ubound(array_bytes_to_find_5_2D, 2) < i_2 then
redim preserve array_bytes_to_find_5_2D(ubound(array_bytes_to_find_5_2D, 1), ubound(array_bytes_to_find_5_2D, 2) + 1)
end if
array_bytes_to_find_5_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
WScript_Echo_variable = "1ers octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_1_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_1_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_1_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_1_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_1_2D, 2) then
if array_bytes_to_find_1_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "2èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_2_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_2_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_2_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_2_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_2_2D, 2) then
if array_bytes_to_find_2_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "3èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_3_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_3_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_3_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_3_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_3_2D, 2) then
if array_bytes_to_find_3_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "4èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_4_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_4_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_4_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_4_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_4_2D, 2) then
if array_bytes_to_find_4_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "5èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_5_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_5_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_5_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_5_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_5_2D, 2) then
if array_bytes_to_find_5_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
set file_input = object_file_system.OpenTextFile(file_fullname, 1) ' 1 = Ouverture du fichier en lecture
set file_output = object_file_system.OpenTextFile(file_fullname & ".temporary", 2, TRUE, 0) ' 2 = Ouverture du fichier en écriture (TRUE = Fichier créé si n'existe pas) (0 = ASCII, -1 = Unicode, -2 = Par défaut)
array_bytes_to_find_1_2D_ubound = ubound(array_bytes_to_find_1_2D, 1)
array_bytes_to_find_2_2D_ubound = ubound(array_bytes_to_find_2_2D, 1)
array_bytes_to_find_3_2D_ubound = ubound(array_bytes_to_find_3_2D, 1)
array_bytes_to_find_4_2D_ubound = ubound(array_bytes_to_find_4_2D, 1)
array_bytes_to_find_5_2D_ubound = ubound(array_bytes_to_find_5_2D, 1)
dim array_byte_buffer_1()
redim array_byte_buffer_1(-1)
dim array_byte_buffer_2()
redim array_byte_buffer_2(-1)
dim array_match_found_1()
redim array_match_found_1(-1)
dim array_match_found_2()
redim array_match_found_2(-1)
byte_read = 0
i_byte_check = 0
i_replacement_count = 0
do until file_input.AtEndOfStream
byte_read = asc(file_input.Read(1))
' WScript.Echo "Caractère lu (hexadécimal " & string(2 - len(hex(byte_read)), "0") & ucase((hex(byte_read))) & " = décimal " & byte_read & ") : """ & chr(byte_read) & """"
' L'octet lu est stocké dans la dernière case d'un tableau (buffer).
redim preserve array_byte_buffer_1(ubound(array_byte_buffer_1) + 1)
array_byte_buffer_1(ubound(array_byte_buffer_1)) = byte_read
' WScript.Echo "Contenu du buffer : " & join(array_byte_buffer_1, " ")
select case i_byte_check
case 0
' On considère que le buffer peut contenir plusieurs octets en attente d'être traités,
' c'est-à-dire écrits dans le fichier de sortie s'il n'existe aucune correspondance.
' Chaque 1er octet traité disparaît du buffer, dont la taille se réduit.
' Lorsque sa taille atteint 0 (ubound = -1), le buffer est vide,
' tous les octets ont été traités.
b_exit_while_1 = FALSE
while ubound(array_byte_buffer_1) >= 0 AND b_exit_while_1 = FALSE
' Première boucle de vérification.
' On compare le 1er octet (i_byte_check = 0) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 1er tableau.
i_0 = 0
while i_0 <= array_bytes_to_find_1_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' l'écriture du fichier de sortie est suspendue (i_byte_check ≠ 0)
' et l'octet reste stocké dans le buffer.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_1_2D(i_0, 0) then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_1_2D(i_0, 0)
b_exit_while_1 = TRUE
i_byte_check = i_byte_check + 1 ' i_byte_check = 1
i_0 = i_0 - 1
end if
i_0 = i_0 + 1
wend
' Si il ne correspond pas, l'octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
if b_exit_while_1 = FALSE then
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
wend
' break
case 1
' Deuxième boucle de vérification.
' On compare le 2ème octet (i_byte_check = 1) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 2ème tableau.
b_exit_while_1 = FALSE
i_1 = 0
while i_1 <= array_bytes_to_find_2_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' on compare la 2ème dimension de la case du 1er tableau précédent
' à la 2ème dimension de cette case de ce 2ème tableau et
' on stocke les numéros communs dans un tableau : array_match_found_1.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_2_2D(i_1, 0) then
b_exit_while_1 = TRUE
redim array_match_found_1(-1)
i_0_2D = 1
b_exit_while_2 = FALSE
while i_0_2D <= ubound(array_bytes_to_find_1_2D, 2) AND b_exit_while_2 = FALSE
if array_bytes_to_find_1_2D(i_0, i_0_2D) <> "" then
i_1_2D = 1
b_exit_while_3 = FALSE
while i_1_2D <= ubound(array_bytes_to_find_2_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_2_2D(i_1, i_1_2D) <> "" then
if array_bytes_to_find_1_2D(i_0, i_0_2D) = array_bytes_to_find_2_2D(i_1, i_1_2D) then
redim preserve array_match_found_1(ubound(array_match_found_1) + 1)
array_match_found_1(ubound(array_match_found_1)) = array_bytes_to_find_1_2D(i_0, i_0_2D)
end if
i_1_2D = i_1_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_0_2D = i_0_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
' Si le tableau n'est pas vide, il indique le ou les numéros
' des chaînes qui commencent par ces 2 octets. Dans ce cas :
' l'écriture du fichier de sortie reste suspendue (i_byte_check ≠ 0)
' et les octets restent stockés dans le buffer.
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_2_2D(i_1, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 2
end if
' Si le tableau est vide, les 2 octets ne correspondent
' à aucune chaîne à rechercher. C'est la même situation que
' si le 2ème octet ne correspond à aucune case du 2ème tableau.
end if
i_1 = i_1 + 1
wend
' Si il ne correspond pas, le premier octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
' De plus i_byte_check est réinitialisée donc on retourne
' à la première boucle de vérification pour vider le buffer.
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 2
' Troisième boucle de vérification.
' On compare le 3ème octet (i_byte_check = 2) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 3ème tableau.
b_exit_while_1 = FALSE
i_2 = 0
while i_2 <= array_bytes_to_find_3_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' on compare le tableau précédent array_match_found_1
' à la 2ème dimension de cette case de ce 3ème tableau et
' on stocke les numéros communs dans array_match_found_1
' par l'intermédiaire d'un tableau temporaire : array_match_found_2.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_3_2D(i_2, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_1_2D = 0
b_exit_while_2 = FALSE
while i_1_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_1_2D) <> "" then
i_2_2D = 1
b_exit_while_3 = FALSE
while i_2_2D <= ubound(array_bytes_to_find_3_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_3_2D(i_2, i_2_2D) <> "" then
if array_match_found_1(i_1_2D) = array_bytes_to_find_3_2D(i_2, i_2_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_1_2D)
end if
i_2_2D = i_2_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_1_2D = i_1_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
' Si le tableau n'est pas vide, il indique le ou les numéros
' des chaînes qui commencent par ces 3 octets. Dans ce cas :
' l'écriture du fichier de sortie reste suspendue (i_byte_check ≠ 0)
' et les octets restent stockés dans le buffer.
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_3_2D(i_2, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 3
end if
' Si le tableau est vide, les 3 octets ne correspondent
' à aucune chaîne à rechercher. C'est la même situation que
' si le 3ème octet ne correspond à aucune case du 3ème tableau.
end if
i_2 = i_2 + 1
wend
' Si il ne correspond pas, le premier octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
' De plus i_byte_check est réinitialisée donc on retourne
' à la première boucle de vérification pour vider le buffer.
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 3
b_exit_while_1 = FALSE
i_3 = 0
while i_3 <= array_bytes_to_find_4_2D_ubound AND b_exit_while_1 = FALSE
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_4_2D(i_3, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_2_2D = 0
b_exit_while_2 = FALSE
while i_2_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_2_2D) <> "" then
i_3_2D = 1
b_exit_while_3 = FALSE
while i_3_2D <= ubound(array_bytes_to_find_4_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_4_2D(i_3, i_3_2D) <> "" then
if array_match_found_1(i_2_2D) = array_bytes_to_find_4_2D(i_3, i_3_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_2_2D)
end if
i_3_2D = i_3_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_2_2D = i_2_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_4_2D(i_3, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 4
end if
end if
i_3 = i_3 + 1
wend
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 4
b_exit_while_1 = FALSE
i_4 = 0
while i_4 <= array_bytes_to_find_5_2D_ubound AND b_exit_while_1 = FALSE
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_5_2D(i_4, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_3_2D = 0
b_exit_while_2 = FALSE
while i_3_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_3_2D) <> "" then
i_4_2D = 1
b_exit_while_3 = FALSE
while i_4_2D <= ubound(array_bytes_to_find_5_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_5_2D(i_4, i_4_2D) <> "" then
if array_match_found_1(i_3_2D) = array_bytes_to_find_5_2D(i_4, i_4_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_3_2D)
end if
i_4_2D = i_4_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_3_2D = i_3_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_5_2D(i_4, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 5
end if
end if
i_4 = i_4 + 1
wend
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 2 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case else
' On prend le tableau array_match_found_1, il contient le
' (ou les) numéro de case du tableau array_hex_strings_to_find
' qui lui-même contient la chaîne complète des octets à analyser
' dont les 5 premiers octets correspondent.
' Remarque : il se peut que plusieurs chaînes aient leurs 5 premiers
' octets en commun. Voire que seul le dernier octet soit différent.
' Donc on analyse chaque case du tableau array_match_found_1.
b_exit_while_1 = FALSE
i_5 = 0 ' (Inutile car i_5 reste à 0)
while i_5 <= ubound(array_match_found_1) AND b_exit_while_1 = FALSE
' On analyse la chaîne contenue dans array_hex_strings_to_find.
' Si la chaîne continue à correspondre, on teste l'octet suivant.
if string(2 - len(hex(array_byte_buffer_1(i_byte_check))), "0") & ucase((hex(array_byte_buffer_1(i_byte_check)))) = mid(array_hex_strings_to_find(array_match_found_1(i_5)), 2 * i_byte_check + 1, 2) then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & mid(array_hex_strings_to_find(array_match_found_1(i_5)), 2 * i_byte_check + 1, 2)
b_exit_while_1 = TRUE
i_byte_check = i_byte_check + 1
' Si la chaîne ne correspond plus, alors on retire son numéro du tableau array_match_found_1.
' Et si le tableau est vide, alors aucune chaîne ne correspondait,
' donc le premier octet est traité et i_byte_check est réinitialisée.
else
if ubound(array_match_found_1) >= 1 then
redim array_match_found_2(ubound(array_match_found_1) - 1)
for i = 1 to ubound(array_match_found_1)
array_match_found_2(i - 1) = array_match_found_1(i)
next
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
else
redim array_match_found_1(-1)
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
end if
if i_byte_check > 0 then
' Si la correspondance va jusqu'au bout de la chaîne, alors la chaîne a été détectée.
if i_byte_check = len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 then
' Dans ce cas on écrit la nouvelle chaîne et on vide le buffer.
for i = 0 to len(array_hex_strings_to_replace(array_match_found_1(i_5))) - 1 step 2
file_output.Write(chr(cbyte("&H" & Mid(array_hex_strings_to_replace(array_match_found_1(i_5)), i + 1, 2))))
next
' WScript.Echo vbCrLf & "Contenu de la chaîne n°" & array_match_found_1(i_5) + 1 & " (" & len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 & " cases) : " & array_hex_strings_to_find(array_match_found_1(i_5)) & vbCrLf & "Contenu du buffer (" & ubound(array_byte_buffer_1) + 1 & " cases) : " & join(array_byte_buffer_1, " ")
' On vide le buffer de la chaîne à rechercher.
if ubound(array_byte_buffer_1) >= len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - (len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2))
for i = len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 to ubound(array_byte_buffer_1) step 1
array_byte_buffer_2(i - len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
' WScript.Echo "Contenu restant du buffer = : " & join(array_byte_buffer_1, " ")
else
redim array_byte_buffer_1(-1)
end if
i_byte_check = 0
i_replacement_count = i_replacement_count + 1
' WScript.Echo vbCrLf & "Fichier :" & vbCrLf & file_fullname & vbCrLf & "Séquence n°" & array_match_found_1(i_5) + 1 & " trouvée :" & vbCrLf & array_hex_strings_to_find(array_match_found_1(i_5)) & vbCrLf & "Remplacée par :" & vbCrLf & array_hex_strings_to_replace(array_match_found_1(i_5)) & vbCrLf
end if
end if
wend
end select
loop
file_input.Close
file_output.Close
i_my_replace_array_hex_strings_in_file = i_replacement_count
end function
Function i_my_rename_file(byval file_fullname, byval file_fullname_new)
if object_file_system.FileExists(file_fullname) = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & vbCrLf & "n'existe pas, impossible de le renommer en :" & vbCrLf & file_fullname_new, 48, "Erreur"
WScript.Quit(0)
end if
' WScript.Echo "Le fichier :" & vbCrLf & file_fullname & vbCrLf & "a été renommé en :" & vbCrLf & file_fullname_new & vbCrLf
object_file_system.MoveFile file_fullname, file_fullname_new
if object_file_system.FileExists(file_fullname_new) = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & vbCrLf & "n'a pas pu être renommé.", 48, "Erreur"
WScript.Quit(0)
end if
i_my_rename_file = 0
end function
function i_my_fix_corrupted_file(byval corrupted_file_error_ori, byval corrupted_file_error_fix, byval corrupted_file)
i_installation_type = 0
if program_folder <> "" then
if object_file_system.FileExists(program_folder & "\" & corrupted_file) = FALSE then
MsgBox "Erreur, fichier non détecté :" & vbCrLf & program_folder & "\" & corrupted_file, 48, "Erreur"
WScript.Quit(0)
end if
i_installation_type = 1
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_portable_32 & "\" & corrupted_file) = TRUE then
i_installation_type = 2
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_portable_64 & "\" & corrupted_file) = TRUE then
i_installation_type = i_installation_type + 3
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_installed_32 & "\" & corrupted_file) = TRUE then
i_installation_type = 6
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_installed_64 & "\" & corrupted_file) = TRUE then
i_installation_type = 7
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & vbCrLf
end if
if i_installation_type = 0 then
MsgBox "Erreur, aucun fichier détecté.", 48, "Erreur"
WScript.Quit(0)
end if
if i_installation_type = 1 then
if object_file_system.FileExists(program_folder & "\" & corrupted_file & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question") ' 4 = vbYesNo 32 = vbQuestion 256 = vbDefaultButton2 0 = vbApplicationModal
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder & "\" & corrupted_file, program_folder & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder & "\" & corrupted_file & ".temporary", program_folder & "\" & corrupted_file
end if
if i_installation_type = 2 OR i_installation_type = 5 then
if object_file_system.FileExists(program_folder_portable_32 & "\" & corrupted_file & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_portable_32 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_portable_32 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_portable_32 & "\" & corrupted_file, program_folder_portable_32 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_portable_32 & "\" & corrupted_file & ".temporary", program_folder_portable_32 & "\" & corrupted_file
end if
if i_installation_type = 3 OR i_installation_type = 5 then
if object_file_system.FileExists(program_folder_portable_64 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_portable_64 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_portable_64 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_portable_64 & "\" & corrupted_file, program_folder_portable_64 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_portable_64 & "\" & corrupted_file & ".temporary", program_folder_portable_64 & "\" & corrupted_file
end if
if i_installation_type = 6 then
if object_file_system.FileExists(program_folder_installed_32 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_installed_32 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_installed_32 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_installed_32 & "\" & corrupted_file, program_folder_installed_32 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_installed_32 & "\" & corrupted_file & ".temporary", program_folder_installed_32 & "\" & corrupted_file
end if
if i_installation_type = 7 then
if object_file_system.FileExists(program_folder_installed_64 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_installed_64 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_installed_64 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_installed_64 & "\" & corrupted_file, program_folder_installed_64 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_installed_64 & "\" & corrupted_file & ".temporary", program_folder_installed_64 & "\" & corrupted_file
end if
i_my_fix_corrupted_file = number_of_replacements
end function
' _____________________________________________________________________________
' Partie à modifier pour ajouter des fichiers à corriger :
' Lancement du script :
number_of_replacements = i_my_fix_corrupted_file(corrupted_file_1_error_ori, corrupted_file_1_error_fix, corrupted_file_1)
' _____________________________________________________________________________
' Partie à ne pas modifier :
pause_message = "L'exécution de ce programme est terminée."
MsgBox pause_message & vbCrLf & vbCrLf & "Appuyez sur une touche pour continuer...", 64, "Pause" ' 0 = vbOKOnly vbDefaultButton1 vbApplicationModal 64 = vbInformation
WScript.Quit(0)
Firefox en Powershell
# Character encoding = UTF-16 LE (Byte Order Mark = FF FE)
# End-of-line = Windows (CR LF)
# Composants requis :
$current_folder = $PWD.Path
# _____________________________________________________________________________
# Partie à modifier pour ajouter des fichiers et erreurs à corriger :
# Emplacement personnalisé du dossier contenant le fichier "firefox.exe".
# Vous pouvez le laisser vide. Exemple :
# $program_folder = "$current_folder\Mozilla Firefox"
$program_folder = ""
# Emplacements connus :
$program_folder_portable_32 = "$current_folder\App\Firefox"
$program_folder_portable_64 = "$current_folder\App\Firefox64"
$program_folder_installed_32 = "${env:ProgramFiles(x86)}\Mozilla Firefox"
$program_folder_installed_64 = "${$env:ProgramFiles}\Mozilla Firefox"
# Fichier(s) à réparer :
$corrupted_file_1 = "omni.ja"
$corrupted_file_2 = "browser\omni.ja"
# Réparations à faire :
$corrupted_file_1_error_ori = @()
$corrupted_file_1_error_fix = @()
# utilisateur·trice => utilisateur
$corrupted_file_1_error_ori += "C2B774726963650A" # ·trice
$corrupted_file_1_error_fix += "0A0A0A0A0A0A0A0A" #
$corrupted_file_2_error_ori = @()
$corrupted_file_2_error_fix = @()
# administrateur·trice a désactivé la synchronisation. => administrateur a désactivé la synchronisation.
$corrupted_file_2_error_ori += "C2B7747269636520612064C3A9736163746976C3A9206C612073796E6368726F6E69736174696F6E2E0A" # ·trice a désactivé la synchronisation.
$corrupted_file_2_error_fix += "20612064C3A9736163746976C3A9206C612073796E6368726F6E69736174696F6E2E0A0A0A0A0A0A0A0A" # a désactivé la synchronisation.
# connecté·e. => connecté.
$corrupted_file_2_error_ori += "C3A9C2B7652E0A" # é·e.
$corrupted_file_2_error_fix += "C3A92E0A0A0A0A" # é.
# connecté·e avec succès => connecté avec succès
$corrupted_file_2_error_ori += "C2B76520617665632073756363C3A8730A" # ·e avec succès
$corrupted_file_2_error_fix += "20617665632073756363C3A8730A0A0A0A" # avec succès
# suivi·e => suivi
$corrupted_file_2_error_ori += "7669C2B7650A" # vi·e
$corrupted_file_2_error_fix += "76690A0A0A0A" # vi
# Prêt·e à scanner</strong> et maintenez votre appareil au-dessus de ce code => Prêt à scanner</strong> et maintenez votre appareil au-dessus de ce code
$corrupted_file_2_error_ori += "C2B76520C3A0207363616E6E65723C2F7374726F6E673E206574206D61696E74656E657A20766F74726520617070617265696C2061752D64657373757320646520636520636F64650A" # ·e à scanner</strong> et maintenez votre appareil au-dessus de ce code
$corrupted_file_2_error_fix += "20C3A0207363616E6E65723C2F7374726F6E673E206574206D61696E74656E657A20766F74726520617070617265696C2061752D64657373757320646520636520636F64650A0A0A0A" # à scanner</strong> et maintenez votre appareil au-dessus de ce code
# pisté·e => pisté
$corrupted_file_2_error_ori += "C3A9C2B7650A" # é·e
$corrupted_file_2_error_fix += "C3A90A0A0A0A" # é
# véritables client·e·s qui ont laissé des avis sincères et objectifs.
$corrupted_file_2_error_ori += "C2B765C2B77320717569206F6E74206C61697373C3A92064657320617669732073696E63C3A8726573206574206F626A6563746966732E0A" # ·e·s qui ont laissé des avis sincères et objectifs.
$corrupted_file_2_error_fix += "7320717569206F6E74206C61697373C3A92064657320617669732073696E63C3A8726573206574206F626A6563746966732E0A0A0A0A0A0A" # s qui ont laissé des avis sincères et objectifs.
# _____________________________________________________________________________
# Partie à ne pas modifier :
function i_my_replace_array_hex_strings_in_file([string[]]$array_hex_strings_to_find, [string[]]$array_hex_strings_to_replace, [string]$file_fullname)
{
if ($array_hex_strings_to_find.GetUpperBound(0) -ne $array_hex_strings_to_replace.GetUpperBound(0))
{
Write-Host "Erreur :`r`nLe nombre de cases dans le tableau des chaînes hexadécimales à détecter ($($array_hex_strings_to_find.GetUpperBound(0) + 1))`r`net dans le tableau des chaînes hexadécimales à remplacer ($($array_hex_strings_to_replace.GetUpperBound(0) + 1))`r`nn'est pas identique."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true) # Si le buffer n'est pas vide, au cas où une touche aurait déjà été pressée.
{
while ($Host.UI.RawUI.KeyAvailable -eq $true) # Vide le buffer et met en pause.
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") # Met en pause.
}
exit 0
}
for ($i = 0; $i -le $array_hex_strings_to_find.GetUpperBound(0); $i++)
{
if ($array_hex_strings_to_find[$i].Length -ne $array_hex_strings_to_replace[$i].Length)
{
Write-Host "Erreur :`r`nLa variable $($array_hex_strings_to_find[$i]) et`r`nla variable $($array_hex_strings_to_replace[$i])"
Write-Host "n'ont pas le même nombre de caractères ($($array_hex_strings_to_find[$i].Length) contre $($array_hex_strings_to_replace[$i].Length))."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($array_hex_strings_to_find[$i].Length % 2 -ne 0)
{
Write-Host "Erreur, les variables :`r`n$($array_hex_strings_to_find[$i]) et`r`n$($array_hex_strings_to_replace[$i])`r`nont un nombre impair de caractères."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($array_hex_strings_to_find[$i].Length -lt 12)
{
Write-Host "Erreur, les variables :`r`n$($array_hex_strings_to_find[$i]) et`r`n$($array_hex_strings_to_replace[$i])"
Write-Host "doivent avoir au moins 12 caractères hexadécimaux pour représenter"
Write-Host "au moins 6 octets. Or ici, elles n'en contiennent que $($array_hex_strings_to_find[$i].Length)."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
}
Out-File -FilePath "$file_fullname.temporary" -Force -Encoding ASCII # (Force = Écraser si existe déjà) (Encoding ASCII = Utiliser ASCII au lieu d'Unicode UTF16LE donc pas de Byte Order Mark FFFE)
if ((Test-Path "$file_fullname.temporary") -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname.temporary"
Write-Host "n'a pas pu être créé. L'écriture dans ce dossier nécessite probablement`r`ndes privilèges d'administrateur. Veuillez exécuter ce script en tant qu'administrateur."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
# Pour aller plus vite, on crée 5 tableaux en 2 dimensions.
# Nous sommes obligés de créer chaque dimension indépendamment car
# il est impossible de redimensionner dynamiquement les 2 dimensions.
# Concernant la 1ère dimension :
# Le 1er tableau contiendra les premiers octets de toutes les chaînes
# à rechercher, convertis en décimal et en éliminant les doublons.
# Le 2ème tableau contiendra les deuxièmes octets, etc.
# Le 3ème tableau contiendra les troisièmes octets, etc.
$array_bytes_to_find_1 = @()
$array_bytes_to_find_2 = @()
$array_bytes_to_find_3 = @()
$array_bytes_to_find_4 = @()
$array_bytes_to_find_5 = @()
for ($i_1 = 0; $i_1 -le $array_hex_strings_to_find.GetUpperBound(0); $i_1++)
{
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_1.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(0, 2), 16) -eq $array_bytes_to_find_1[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_1 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(0, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_2.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(2, 2), 16) -eq $array_bytes_to_find_2[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_2 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(2, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_3.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(4, 2), 16) -eq $array_bytes_to_find_3[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_3 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(4, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_4.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(6, 2), 16) -eq $array_bytes_to_find_4[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_4 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(6, 2), 16)
}
$b_already_exists = $false
for ($i_2 = 0; $i_2 -le $array_bytes_to_find_5.GetUpperBound(0); $i_2++)
{
if ([Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(8, 2), 16) -eq $array_bytes_to_find_5[$i_2])
{
$b_already_exists = $true
}
}
if ($b_already_exists -eq $false)
{
$array_bytes_to_find_5 += [Convert]::ToInt32($array_hex_strings_to_find[$i_1].Substring(8, 2), 16)
}
}
# Concernant la 2ème dimension :
# Pour chaque tableau, elle contiendra les numéros des chaînes
# auxquelles les octets correspondent (en commençant par 0).
# Imaginons que la 1ère case du 1er tableau contient l'octet C2 = 194
# et que plusieurs chaînes commencent par C2 (doublons), par exemple
# les chaînes 1 2 4 5 6, alors les chiffres 0 1 3 4 5 seront inscrits
# dans la 2ème dimension de la 1ère case du 1er tableau.
$array_bytes_to_find_1_2D = New-Object 'object[,]' ($array_bytes_to_find_1.GetUpperBound(0) + 1), 1
$array_bytes_to_find_2_2D = New-Object 'object[,]' ($array_bytes_to_find_2.GetUpperBound(0) + 1), 1
$array_bytes_to_find_3_2D = New-Object 'object[,]' ($array_bytes_to_find_3.GetUpperBound(0) + 1), 1
$array_bytes_to_find_4_2D = New-Object 'object[,]' ($array_bytes_to_find_4.GetUpperBound(0) + 1), 1
$array_bytes_to_find_5_2D = New-Object 'object[,]' ($array_bytes_to_find_5.GetUpperBound(0) + 1), 1
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_1_2D[$i_1, 0] = $array_bytes_to_find_1[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(0, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_1_2D[$i_1, 0])
{
if ($array_bytes_to_find_1_2D.GetUpperBound(1) -lt $i_2)
{
# En PowerShell il n'existe pas d'équivalent à la commande
# ReDim Preserve array_bytes_to_find_1_2D(ubound,ubound+1)
# du VBScript pour redimensionner la 2ème dimension du tableau.
# La notation "+=" ajoute un élément à la fin d'un tableau,
# mais seulement s'il est en 1 dimension, pas en 2 dimensions.
# Il faut donc créer un autre tableau $array_subarray_2D
# avec une case supplémentaire puis recopier le tableau dedans
# en utilisant une boucle for.
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_1_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_1_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_1_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_1_2D[$i, $j]
}
}
$array_bytes_to_find_1_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_1_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_2_2D[$i_1, 0] = $array_bytes_to_find_2[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(2, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_2_2D[$i_1, 0])
{
if ($array_bytes_to_find_2_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_2_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_2_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_2_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_2_2D[$i, $j]
}
}
$array_bytes_to_find_2_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_2_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_3_2D[$i_1, 0] = $array_bytes_to_find_3[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(4, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_3_2D[$i_1, 0])
{
if ($array_bytes_to_find_3_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_3_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_3_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_3_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_3_2D[$i, $j]
}
}
$array_bytes_to_find_3_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_3_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_4_2D[$i_1, 0] = $array_bytes_to_find_4[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(6, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_4_2D[$i_1, 0])
{
if ($array_bytes_to_find_4_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_4_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_4_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_4_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_4_2D[$i, $j]
}
}
$array_bytes_to_find_4_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_4_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i_1++)
{
$array_bytes_to_find_5_2D[$i_1, 0] = $array_bytes_to_find_5[$i_1]
$i_2 = 1
for ($i_3 = 0; $i_3 -le $array_hex_strings_to_find.GetUpperBound(0); $i_3++)
{
if ([int]::Parse($array_hex_strings_to_find[$i_3].Substring(8, 2), [System.Globalization.NumberStyles]::HexNumber) -eq $array_bytes_to_find_5_2D[$i_1, 0])
{
if ($array_bytes_to_find_5_2D.GetUpperBound(1) -lt $i_2)
{
$array_subarray_2D = New-Object 'object[,]' ($array_bytes_to_find_5_2D.GetUpperBound(0) + 1), ($array_bytes_to_find_5_2D.GetUpperBound(1) + 2)
for ($i = 0; $i -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i++)
{
for ($j = 0; $j -le $array_bytes_to_find_5_2D.GetUpperBound(1); $j++)
{
$array_subarray_2D[$i, $j] = $array_bytes_to_find_5_2D[$i, $j]
}
}
$array_bytes_to_find_5_2D = $array_subarray_2D
Remove-Variable -Name array_subarray_2D
}
$array_bytes_to_find_5_2D[$i_1, $i_2] = $i_3
$i_2++
}
}
}
<#
Write-Host "1ers octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_1_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_1_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_1_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_1_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_1_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_1_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "2èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_2_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_2_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_2_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_2_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_2_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_2_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "3èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_3_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_3_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_3_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_3_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_3_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_3_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "4èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_4_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_4_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_4_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_4_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_4_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_4_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "5èmes octets à rechercher => Dans les chaînes : "
for ($i_1 = 0; $i_1 -le $array_bytes_to_find_5_2D.GetUpperBound(0); $i_1++)
{
Write-Host -NoNewline "$($array_bytes_to_find_5_2D[$i_1, 0]) => "
for ($i_2 = 1; $i_2 -le ($array_bytes_to_find_5_2D.GetUpperBound(1)); $i_2++)
{
Write-Host -NoNewline "$($array_bytes_to_find_5_2D[$i_1, $i_2])"
if ($i_2 + 1 -le $array_bytes_to_find_5_2D.GetUpperBound(1))
{
if ($array_bytes_to_find_5_2D[$i_1, $($i_2 + 1)] -ne $null)
{
Write-Host -NoNewline " "
}
}
}
Write-Host
}
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
Write-Host
#>
Write-Host -NoNewline "`r`nAnalyse en cours... "
$file_input = [System.IO.File]::OpenRead($file_fullname) # Ouverture du fichier en lecture
$file_output = [System.IO.File]::Create("$file_fullname.temporary") # Ouverture du fichier en écriture
$array_bytes_to_find_1_2D_ubound = $array_bytes_to_find_1_2D.GetUpperBound(0)
$array_bytes_to_find_2_2D_ubound = $array_bytes_to_find_2_2D.GetUpperBound(0)
$array_bytes_to_find_3_2D_ubound = $array_bytes_to_find_3_2D.GetUpperBound(0)
$array_bytes_to_find_4_2D_ubound = $array_bytes_to_find_4_2D.GetUpperBound(0)
$array_bytes_to_find_5_2D_ubound = $array_bytes_to_find_5_2D.GetUpperBound(0)
$array_byte_buffer_1 = @()
$array_byte_buffer_2 = @()
$array_match_found_1 = @()
$array_match_found_2 = @()
$byte_buffer_read = New-Object byte[] 1
$byte_read = 0
$i_byte_check = 0
$i_replacement_count = 0
while ($file_input.Read($byte_buffer_read, 0, 1) -ne 0)
{
$byte_read = $byte_buffer_read[0]
# Write-Host "Caractère lu (hexadécimal $($byte_read.ToString("X2")) = décimal $byte_read) : ""$([char]$byte_read)"""
# L'octet lu est stocké dans la dernière case d'un tableau (buffer).
$array_byte_buffer_1 += $byte_read
# Write-Host "Contenu du buffer : $($array_byte_buffer_1 -join " ")"
switch ($i_byte_check)
{
0
{
# On considère que le buffer peut contenir plusieurs octets en attente d'être traités,
# c'est-à-dire écrits dans le fichier de sortie s'il n'existe aucune correspondance.
# Chaque 1er octet traité disparaît du buffer, dont la taille se réduit.
# Lorsque sa taille atteint 0 (GetUpperBound = -1), le buffer est vide,
# tous les octets ont été traités.
$b_exit_while_1 = $flase
while ($array_byte_buffer_1.GetUpperBound(0) -ge 0 -and $b_exit_while_1 -eq $flase)
{
# Première boucle de vérification.
# On compare le 1er octet ($i_byte_check = 0) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 1er tableau.
$i_0 = 0
while ($i_0 -le $array_bytes_to_find_1_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# l'écriture du fichier de sortie est suspendue ($i_byte_check ≠ 0)
# et l'octet reste stocké dans le buffer.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_1_2D[$i_0, 0])
{
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_1_2D[$i_0, 0])"
$b_exit_while_1 = $true
$i_byte_check++ # $i_byte_check = 1
$i_0--
}
$i_0++
}
# Si il ne correspond pas, l'octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
if ($b_exit_while_1 -eq $flase)
{
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
}
break
}
1
{
# Deuxième boucle de vérification.
# On compare le 2ème octet ($i_byte_check = 1) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 2ème tableau.
$b_exit_while_1 = $flase
$i_1 = 0
while ($i_1 -le $array_bytes_to_find_2_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# on compare la 2ème dimension de la case du 1er tableau précédent
# à la 2ème dimension de cette case de ce 2ème tableau et
# on stocke les numéros communs dans un tableau : $array_match_found_1.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_2_2D[$i_1, 0])
{
$b_exit_while_1 = $true
$array_match_found_1 = @()
$i_0_2D = 1
$b_exit_while_2 = $false
while ($i_0_2D -le $array_bytes_to_find_1_2D.GetUpperBound(1) -and $b_exit_while_2 -eq $false)
{
if ($array_bytes_to_find_1_2D[$i_0, $i_0_2D] -ne $null)
{
$i_1_2D = 1
$b_exit_while_3 = $false
while ($i_1_2D -le $array_bytes_to_find_2_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_2_2D[$i_1, $i_1_2D] -ne $null)
{
if ($array_bytes_to_find_1_2D[$i_0, $i_0_2D] -eq $array_bytes_to_find_2_2D[$i_1, $i_1_2D])
{
$array_match_found_1 += $array_bytes_to_find_1_2D[$i_0, $i_0_2D]
}
$i_1_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_0_2D++
}
else
{
$b_exit_while_2 = $true
}
}
# Si le tableau n'est pas vide, il indique le ou les numéros
# des chaînes qui commencent par ces 2 octets. Dans ce cas :
# l'écriture du fichier de sortie reste suspendue ($i_byte_check ≠ 0)
# et les octets restent stockés dans le buffer.
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_2_2D[$i_1, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 2
}
# Si le tableau est vide, les 2 octets ne correspondent
# à aucune chaîne à rechercher. C'est la même situation que
# si le 2ème octet ne correspond à aucune case du 2ème tableau.
}
$i_1++
}
# Si il ne correspond pas, le premier octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
# De plus $i_byte_check est réinitialisée donc on retourne
# à la première boucle de vérification pour vider le buffer.
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
2
{
# Troisième boucle de vérification.
# On compare le 3ème octet ($i_byte_check = 2) du buffer
# aux octets stockés dans les cases de la 1ère dimension du 3ème tableau.
$b_exit_while_1 = $flase
$i_2 = 0
while ($i_2 -le $array_bytes_to_find_3_2D_ubound -and $b_exit_while_1 -eq $flase)
{
# Si il correspond à une case,
# on compare le tableau précédent $array_match_found_1
# à la 2ème dimension de cette case de ce 3ème tableau et
# on stocke les numéros communs dans $array_match_found_1
# par l'intermédiaire d'un tableau temporaire : $array_match_found_2.
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_3_2D[$i_2, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_1_2D = 0
$b_exit_while_2 = $false
while ($i_1_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_1_2D] -ne $null)
{
$i_2_2D = 1
$b_exit_while_3 = $false
while ($i_2_2D -le $array_bytes_to_find_3_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_3_2D[$i_2, $i_2_2D] -ne $null)
{
if ($array_match_found_1[$i_1_2D] -eq $array_bytes_to_find_3_2D[$i_2, $i_2_2D])
{
$array_match_found_2 += $array_match_found_1[$i_1_2D]
}
$i_2_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_1_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
# Si le tableau n'est pas vide, il indique le ou les numéros
# des chaînes qui commencent par ces 3 octets. Dans ce cas :
# l'écriture du fichier de sortie reste suspendue ($i_byte_check ≠ 0)
# et les octets restent stockés dans le buffer.
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_3_2D[$i_2, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 3
}
# Si le tableau est vide, les 3 octets ne correspondent
# à aucune chaîne à rechercher. C'est la même situation que
# si le 3ème octet ne correspond à aucune case du 3ème tableau.
}
$i_2++
}
# Si il ne correspond pas, le premier octet est traité,
# c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
# De plus $i_byte_check est réinitialisée donc on retourne
# à la première boucle de vérification pour vider le buffer.
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
# Si le buffer contient plusieurs cases,
# on les décale vers l'arrière et on le raccourcit d'une case.
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
3
{
$b_exit_while_1 = $flase
$i_3 = 0
while ($i_3 -le $array_bytes_to_find_4_2D_ubound -and $b_exit_while_1 -eq $flase)
{
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_4_2D[$i_3, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_2_2D = 0
$b_exit_while_2 = $false
while ($i_2_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_2_2D] -ne $null)
{
$i_3_2D = 1
$b_exit_while_3 = $false
while ($i_3_2D -le $array_bytes_to_find_4_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_4_2D[$i_3, $i_3_2D] -ne $null)
{
if ($array_match_found_1[$i_2_2D] -eq $array_bytes_to_find_4_2D[$i_3, $i_3_2D])
{
$array_match_found_2 += $array_match_found_1[$i_2_2D]
}
$i_3_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_2_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_4_2D[$i_3, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 4
}
}
$i_3++
}
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
4
{
$b_exit_while_1 = $flase
$i_4 = 0
while ($i_4 -le $array_bytes_to_find_5_2D_ubound -and $b_exit_while_1 -eq $flase)
{
if ($array_byte_buffer_1[$i_byte_check] -eq $array_bytes_to_find_5_2D[$i_4, 0])
{
$b_exit_while_1 = $true
$array_match_found_2 = @()
$i_3_2D = 0
$b_exit_while_2 = $false
while ($i_3_2D -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_2 -eq $false)
{
if ($array_match_found_1[$i_3_2D] -ne $null)
{
$i_4_2D = 1
$b_exit_while_3 = $false
while ($i_4_2D -le $array_bytes_to_find_5_2D.GetUpperBound(1) -and $b_exit_while_3 -eq $false)
{
if ($array_bytes_to_find_5_2D[$i_4, $i_4_2D] -ne $null)
{
if ($array_match_found_1[$i_3_2D] -eq $array_bytes_to_find_5_2D[$i_4, $i_4_2D])
{
$array_match_found_2 += $array_match_found_1[$i_3_2D]
}
$i_4_2D++
}
else
{
$b_exit_while_3 = $true
}
}
$i_3_2D++
}
else
{
$b_exit_while_2 = $true
}
}
$array_match_found_1 = $array_match_found_2
if ($array_match_found_1.GetUpperBound(0) -ge 0)
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_bytes_to_find_5_2D[$i_4, 0])"
# Write-Host "Les octets du buffer ""$($array_byte_buffer_1 -join " ")"" doivent commencer la/les chaîne(s) ""$($array_match_found_1 -join " ")"""
$i_byte_check++ # $i_byte_check = 5
}
}
$i_4++
}
if ($b_exit_while_1 -eq $flase -or $array_match_found_1.GetUpperBound(0) -lt 0)
{
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
break
}
default
{
# On prend le tableau $array_match_found_1, il contient le
# (ou les) numéro de case du tableau $array_hex_strings_to_find
# qui lui-même contient la chaîne complète des octets à analyser
# dont les 5 premiers octets correspondent.
# Remarque : il se peut que plusieurs chaînes aient leurs 5 premiers
# octets en commun. Voire que seul le dernier octet soit différent.
# Donc on analyse chaque case du tableau $array_match_found_1.
$b_exit_while_1 = $flase
$i_5 = 0 # (Inutile car i_5 reste à 0)
while ($i_5 -le $array_match_found_1.GetUpperBound(0) -and $b_exit_while_1 -eq $flase)
{
# On analyse la chaîne contenue dans $array_hex_strings_to_find.
# Si la chaîne continue à correspondre, on teste l'octet suivant.
if ($array_byte_buffer_1[$i_byte_check].ToString("X2") -eq $array_hex_strings_to_find[$array_match_found_1[$i_5]].Substring(2 * $i_byte_check, 2))
{
Write-Host -NoNewline "*"
# Write-Host "Étape $i_byte_check - Correspondance trouvée : $($array_byte_buffer_1[$i_byte_check]) = $($array_hex_strings_to_find[$array_match_found_1[$i_5]].Substring(2 * $i_byte_check, 2))"
$b_exit_while_1 = $true
$i_byte_check++
}
# Si la chaîne ne correspond plus, alors on retire son numéro du tableau $array_match_found_1.
# Et si le tableau est vide, alors aucune chaîne ne correspondait,
# donc le premier octet est traité et $i_byte_check est réinitialisée.
else
{
if ($array_match_found_1.GetUpperBound(0) -ge 1)
{
$array_match_found_2 = @()
$array_match_found_2 = $array_match_found_1[1..($($array_match_found_1.GetUpperBound(0) + 1) - 1)]
$array_match_found_1 = $array_match_found_2
}
else
{
$array_match_found_1 = @()
$i_byte_check = 0
$file_output.WriteByte($array_byte_buffer_1[$i_byte_check])
if ($array_byte_buffer_1.GetUpperBound(0) -ge 1)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[1..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
}
else
{
$array_byte_buffer_1 = @()
}
}
}
if ($i_byte_check -gt 0)
{
# Si la correspondance va jusqu'au bout de la chaîne, alors la chaîne a été détectée.
if ($i_byte_check -eq $array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)
{
# Dans ce cas on écrit la nouvelle chaîne et on vide le buffer.
for ($i = 0; $i -le $array_hex_strings_to_replace[$array_match_found_1[$i_5]].Length - 1; $i += 2)
{
$file_output.WriteByte([byte]::Parse($array_hex_strings_to_replace[$array_match_found_1[$i_5]].Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber))
}
# Write-Host `r`n"Contenu de la chaîne n°$($array_match_found_1[$i_5] + 1) ($($array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2) cases) : $($array_hex_strings_to_find[$array_match_found_1[$i_5]])`r`nContenu du buffer ($($array_byte_buffer_1.GetUpperBound(0) + 1) cases) : $($array_byte_buffer_1 -join " ")"
# On vide le buffer de la chaîne à rechercher.
if ($array_byte_buffer_1.GetUpperBound(0) -ge $array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)
{
$array_byte_buffer_2 = @()
$array_byte_buffer_2 = $array_byte_buffer_1[($array_hex_strings_to_find[$array_match_found_1[$i_5]].Length / 2)..($($array_byte_buffer_1.GetUpperBound(0) + 1) - 1)]
$array_byte_buffer_1 = $array_byte_buffer_2
# Write-Host "Contenu restant du buffer = : $($array_byte_buffer_1 -join " ")"
}
else
{
$array_byte_buffer_1 = @()
}
$i_byte_check = 0
$i_replacement_count++
Write-Host "`r`nFichier :`r`n$file_fullname`r`nSéquence n°$($array_match_found_1[$i_5] + 1) trouvée :`r`n$($array_hex_strings_to_find[$array_match_found_1[$i_5]])`r`nRemplacée par :`r`n$($array_hex_strings_to_replace[$array_match_found_1[$i_5]])`r`n"
Write-Host -NoNewline "`r`nAnalyse en cours... "
}
}
}
}
}
}
$file_input.Close()
$file_output.Close()
$file_input.Dispose()
$file_output.Dispose()
return $i_replacement_count
}
function i_my_rename_file([string]$file_fullname, [string]$file_fullname_new)
{
if ((Test-Path $file_fullname) -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname`r`nn'existe pas, impossible de le renommer en :`r`n$file_fullname_new"
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
Rename-Item -Path $file_fullname -NewName $file_fullname_new -ErrorAction Stop
Write-Host "Le fichier :`r`n$file_fullname`r`na été renommé en :`r`n$file_fullname_new`r`n"
if ((Test-Path $file_fullname_new) -eq $false)
{
Write-Host "Erreur, le fichier :`r`n$file_fullname`r`nn'a pas pu être renommé."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
return 0
}
function i_my_fix_corrupted_file([string[]]$corrupted_file_error_ori, [string[]]$corrupted_file_error_fix, [string]$corrupted_file)
{
$i_installation_type = 0
if ($program_folder -ne "")
{
if ((Test-Path "$program_folder\$corrupted_file") -eq $false)
{
Write-Host "Erreur, fichier non détecté :`r`n$program_folder\$corrupted_file"
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
$i_installation_type = 1
Write-Host "Fichier détecté :`r`n$program_folder\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_portable_32\$corrupted_file") -eq $true)
{
$i_installation_type = 2
Write-Host "Fichier détecté :`r`n$program_folder_portable_32\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_portable_64\$corrupted_file") -eq $true)
{
$i_installation_type += 3
Write-Host "Fichier détecté :`r`n$program_folder_portable_64\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_installed_32\$corrupted_file") -eq $true)
{
$i_installation_type = 6
Write-Host "Fichier détecté :`r`n$program_folder_portable_32\$corrupted_file`r`n"
}
if ((Test-Path "$program_folder_installed_64\$corrupted_file") -eq $true)
{
$i_installation_type = 7
Write-Host "Fichier détecté :`r`n$program_folder_portable_64\$corrupted_file`r`n"
}
if ($i_installation_type -eq 0)
{
Write-Host "Erreur, aucun fichier détecté."
Write-Host "`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
}
if ($i_installation_type -eq 1)
{
if ((Test-Path -Path "$program_folder\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder\$corrupted_file" "$program_folder\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder\$corrupted_file.temporary" "$program_folder\$corrupted_file"
}
if ($i_installation_type -eq 2 -or $i_installation_type -eq 5)
{
if ((Test-Path -Path "$program_folder_portable_32\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_portable_32\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_portable_32\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_portable_32\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_portable_32\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_portable_32\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_portable_32\$corrupted_file" "$program_folder_portable_32\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_portable_32\$corrupted_file.temporary" "$program_folder_portable_32\$corrupted_file"
}
if ($i_installation_type -eq 3 -or $i_installation_type -eq 5)
{
if ((Test-Path -Path "$program_folder_portable_64\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_portable_64\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_portable_64\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_portable_64\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_portable_64\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_portable_64\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_portable_64\$corrupted_file" "$program_folder_portable_64\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_portable_64\$corrupted_file.temporary" "$program_folder_portable_64\$corrupted_file"
}
if ($i_installation_type -eq 6)
{
if ((Test-Path -Path "$program_folder_installed_32\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_installed_32\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_installed_32\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_installed_32\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_installed_32\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_installed_32\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_installed_32\$corrupted_file" "$program_folder_installed_32\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_installed_32\$corrupted_file.temporary" "$program_folder_installed_32\$corrupted_file"
}
if ($i_installation_type -eq 7)
{
if ((Test-Path -Path "$program_folder_installed_64\$corrupted_file.bak" -PathType Leaf) -eq $true)
{
Write-Host "Attention, le fichier de sauvegarde :`r`n$program_folder_installed_64\$corrupted_file.bak"
Write-Host "existe déjà. Si vous avez déjà utilisé ce script mais que`r`nl'écriture inclusive est revenue à la suite d'une mise à jour,"
Write-Host "appuyez sur ""o"" pour supprimer le fichier "".bak"" et continuer,`r`nsinon appuyez sur une autre touche pour quitter."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
Write-Host "`r`nAppuyez sur une touche pour continuer..."
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
$user_response = Read-Host "`r`nVoulez-vous continuer ? (o = oui)"
$user_response = $user_response.ToLower()
if ($user_response -ne "o")
{
exit 0
}
Remove-Item -Path "$program_folder_installed_64\$corrupted_file.bak" -Force
Write-Host "Le fichier :`r`n$program_folder_installed_64\$corrupted_file.bak`r`na été supprimé."
}
$number_of_replacements = i_my_replace_array_hex_strings_in_file $corrupted_file_error_ori $corrupted_file_error_fix ("$program_folder_installed_64\$corrupted_file")
Write-Host "`r`n`r`n$number_of_replacements remplacement(s) effectué(s) sur le fichier :`r`n$program_folder_installed_64\$corrupted_file`r`n"
$i_return = i_my_rename_file "$program_folder_installed_64\$corrupted_file" "$program_folder_installed_64\$corrupted_file.bak"
$i_return = i_my_rename_file "$program_folder_installed_64\$corrupted_file.temporary" "$program_folder_installed_64\$corrupted_file"
}
return $number_of_replacements
}
# _____________________________________________________________________________
# Partie à modifier pour ajouter des fichiers à corriger :
# Lancement du script :
$number_of_replacements = i_my_fix_corrupted_file $corrupted_file_1_error_ori $corrupted_file_1_error_fix ("$corrupted_file_1")
$number_of_replacements = i_my_fix_corrupted_file $corrupted_file_2_error_ori $corrupted_file_2_error_fix ("$corrupted_file_2")
# _____________________________________________________________________________
# Partie à ne pas modifier :
$pause_message = "L'exécution de ce programme est terminée."
Write-Host "$pause_message`r`n`r`nAppuyez sur une touche pour continuer..."
if ($Host.UI.RawUI.KeyAvailable -eq $true)
{
while ($Host.UI.RawUI.KeyAvailable -eq $true)
{
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}
}
else
{
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
exit 0
Firefox en VBScript
' Character encoding = UTF-16 LE (Byte Order Mark = FF FE)
' End-of-line = Windows (CR LF)
' Composants requis :
set object_shell = WScript.CreateObject("WScript.Shell")
set object_file_system = WScript.CreateObject("Scripting.FileSystemObject")
current_folder = object_file_system.GetParentFolderName(WScript.ScriptFullName)
' _____________________________________________________________________________
' Partie à modifier pour ajouter des fichiers et erreurs à corriger :
' Emplacement personnalisé du dossier contenant le fichier "firefox.exe".
' Vous pouvez le laisser vide. Exemple :
' program_folder = current_folder & "\Mozilla Firefox"
program_folder = ""
' Emplacements connus :
program_folder_portable_32 = current_folder & "\App\Firefox"
program_folder_portable_64 = current_folder & "\App\Firefox64"
program_folder_installed_32 = object_shell.ExpandEnvironmentStrings("%ProgramFiles(x86)%") & "\Mozilla Firefox"
program_folder_installed_64 = object_shell.ExpandEnvironmentStrings("%ProgramFiles%") & "\Mozilla Firefox"
' Fichiers à réparer :
corrupted_file_1 = "omni.ja"
corrupted_file_2 = "browser\omni.ja"
' Réparations à faire :
dim corrupted_file_1_error_ori()
redim corrupted_file_1_error_ori(-1)
dim corrupted_file_1_error_fix()
redim corrupted_file_1_error_fix(-1)
' utilisateur·trice => utilisateur
redim preserve corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori) + 1)
corrupted_file_1_error_ori(ubound(corrupted_file_1_error_ori)) = "C2B774726963650A" ' ·trice
redim preserve corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix) + 1)
corrupted_file_1_error_fix(ubound(corrupted_file_1_error_fix)) = "0A0A0A0A0A0A0A0A" '
dim corrupted_file_2_error_ori()
redim corrupted_file_2_error_ori(-1)
dim corrupted_file_2_error_fix()
redim corrupted_file_2_error_fix(-1)
' administrateur·trice a désactivé la synchronisation. => administrateur a désactivé la synchronisation.
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C2B7747269636520612064C3A9736163746976C3A9206C612073796E6368726F6E69736174696F6E2E0A" ' ·trice a désactivé la synchronisation.
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "20612064C3A9736163746976C3A9206C612073796E6368726F6E69736174696F6E2E0A0A0A0A0A0A0A0A" ' a désactivé la synchronisation.
' connecté·e. => connecté.
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C3A9C2B7652E0A" ' é·e.
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "C3A92E0A0A0A0A" ' é.
' connecté·e avec succès => connecté avec succès
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C2B76520617665632073756363C3A8730A" ' ·e avec succès
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "20617665632073756363C3A8730A0A0A0A" ' avec succès
' suivi·e => suivi
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "7669C2B7650A" ' vi·e
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "76690A0A0A0A" ' vi
' Prêt·e à scanner</strong> et maintenez votre appareil au-dessus de ce code => Prêt à scanner</strong> et maintenez votre appareil au-dessus de ce code
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C2B76520C3A0207363616E6E65723C2F7374726F6E673E206574206D61696E74656E657A20766F74726520617070617265696C2061752D64657373757320646520636520636F64650A" ' ·e à scanner</strong> et maintenez votre appareil au-dessus de ce code
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "20C3A0207363616E6E65723C2F7374726F6E673E206574206D61696E74656E657A20766F74726520617070617265696C2061752D64657373757320646520636520636F64650A0A0A0A" ' à scanner</strong> et maintenez votre appareil au-dessus de ce code
' pisté·e => pisté
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C3A9C2B7650A" ' é·e
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "C3A90A0A0A0A" ' é
' véritables client·e·s qui ont laissé des avis sincères et objectifs.
redim preserve corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori) + 1)
corrupted_file_2_error_ori(ubound(corrupted_file_2_error_ori)) = "C2B765C2B77320717569206F6E74206C61697373C3A92064657320617669732073696E63C3A8726573206574206F626A6563746966732E0A" ' ·e·s qui ont laissé des avis sincères et objectifs.
redim preserve corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix) + 1)
corrupted_file_2_error_fix(ubound(corrupted_file_2_error_fix)) = "7320717569206F6E74206C61697373C3A92064657320617669732073696E63C3A8726573206574206F626A6563746966732E0A0A0A0A0A0A" ' s qui ont laissé des avis sincères et objectifs.
' _____________________________________________________________________________
' Partie à ne pas modifier :
function i_my_replace_array_hex_strings_in_file(byval array_hex_strings_to_find, byval array_hex_strings_to_replace, byval file_fullname)
if ubound(array_hex_strings_to_find) <> ubound(array_hex_strings_to_replace) then
MsgBox "Erreur :" & vbCrLf & "Le nombre de cases dans le tableau des chaînes hexadécimales à détecter (" & ubound(array_hex_strings_to_find) + 1 & ")" & vbCrLf & "et dans le tableau des chaînes hexadécimales à remplacer (" & ubound(array_hex_strings_to_replace) + 1 & ")" & vbCrLf & "n'est pas identique.", 48, "Erreur" ' 0 = vbOKOnly vbDefaultButton1 vbApplicationModal 48 = vbExclamation
WScript.Quit(0)
end if
for i = 0 to ubound(array_hex_strings_to_find) step 1
if len(array_hex_strings_to_find(i)) <> len(array_hex_strings_to_replace(i)) then
MsgBox "Erreur :" & vbCrLf & "La variable " & array_hex_strings_to_find(i) & " et" & vbCrLf & "la variable " & array_hex_strings_to_replace(i) & vbCrLf _
& "n'ont pas le même nombre de caractères (" & len(array_hex_strings_to_find(i)) & " contre " & len(array_hex_strings_to_replace(i)) & ").", 48, "Erreur"
WScript.Quit(0)
end if
if len(array_hex_strings_to_find(i)) MOD 2 <> 0 then
MsgBox "Erreur, les variables :" & vbCrLf & array_hex_strings_to_find(i) & " et" & vbCrLf & array_hex_strings_to_replace(i) & vbCrLf & "ont un nombre impair de caractères.", 48, "Erreur"
WScript.Quit(0)
end if
if len(array_hex_strings_to_find(i)) < 12 then
MsgBox "Erreur, les variables :" & vbCrLf & array_hex_strings_to_find(i) & " et" & vbCrLf & array_hex_strings_to_replace(i) & vbCrLf _
& "doivent avoir au moins 12 caractères hexadécimaux pour représenter" & vbCrLf _
& "au moins 6 octets. Or ici, elles n'en contiennent que " & len(array_hex_strings_to_find(i)) & ".", 48, "Erreur"
WScript.Quit(0)
end if
next
set object_file = object_file_system.CreateTextFile(file_fullname & ".temporary", TRUE, FALSE) ' (TRUE = Écraser si existe déjà) (FALSE = Utiliser ASCII au lieu d'Unicode UTF16LE donc pas de Byte Order Mark FFFE)
object_file.Close
if object_file_system.FileExists(file_fullname & ".temporary") = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & ".temporary" & vbCrLf _
& "n'a pas pu être créé. L'écriture dans ce dossier nécessite probablement" & vbCrLf & "des privilèges d'administrateur. Veuillez exécuter ce script en tant qu'administrateur.", 48, "Erreur"
WScript.Quit(0)
end if
' Pour aller plus vite, on crée 5 tableaux en 2 dimensions.
' Nous sommes obligés de créer chaque dimension indépendamment car
' il est impossible de redimensionner dynamiquement les 2 dimensions.
' Concernant la 1ère dimension :
' Le 1er tableau contiendra les premiers octets de toutes les chaînes
' à rechercher, convertis en décimal et en éliminant les doublons.
' Le 2ème tableau contiendra les deuxièmes octets, etc.
' Le 3ème tableau contiendra les troisièmes octets, etc.
dim array_bytes_to_find_1()
redim array_bytes_to_find_1(-1)
dim array_bytes_to_find_2()
redim array_bytes_to_find_2(-1)
dim array_bytes_to_find_3()
redim array_bytes_to_find_3(-1)
dim array_bytes_to_find_4()
redim array_bytes_to_find_4(-1)
dim array_bytes_to_find_5()
redim array_bytes_to_find_5(-1)
for i_1 = 0 to ubound(array_hex_strings_to_find) step 1
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_1) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 1, 2)) = array_bytes_to_find_1(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_1(ubound(array_bytes_to_find_1) + 1)
array_bytes_to_find_1(ubound(array_bytes_to_find_1)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 1, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_2) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 3, 2)) = array_bytes_to_find_2(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_2(ubound(array_bytes_to_find_2) + 1)
array_bytes_to_find_2(ubound(array_bytes_to_find_2)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 3, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_3) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 5, 2)) = array_bytes_to_find_3(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_3(ubound(array_bytes_to_find_3) + 1)
array_bytes_to_find_3(ubound(array_bytes_to_find_3)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 5, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_4) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 7, 2)) = array_bytes_to_find_4(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_4(ubound(array_bytes_to_find_4) + 1)
array_bytes_to_find_4(ubound(array_bytes_to_find_4)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 7, 2))
end if
b_already_exists = FALSE
for i_2 = 0 to ubound(array_bytes_to_find_5) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_1), 9, 2)) = array_bytes_to_find_5(i_2) then
b_already_exists = TRUE
end if
next
if b_already_exists = FALSE then
redim preserve array_bytes_to_find_5(ubound(array_bytes_to_find_5) + 1)
array_bytes_to_find_5(ubound(array_bytes_to_find_5)) = cint("&H" & mid(array_hex_strings_to_find(i_1), 9, 2))
end if
next
' Concernant la 2ème dimension :
' Pour chaque tableau, elle contiendra les numéros des chaînes
' auxquelles les octets correspondent (en commençant par 0).
' Imaginons que la 1ère case du 1er tableau contient l'octet C2 = 194
' et plusieurs chaînes commencent par C2 (doublons), par exemple les
' chaînes 1 2 4 5 6, alors les chiffres 0 1 3 4 5 seront inscrits
' dans la 2ème dimension de la 1ère case du 1er tableau.
dim array_bytes_to_find_1_2D()
redim array_bytes_to_find_1_2D(ubound(array_bytes_to_find_1), 0)
dim array_bytes_to_find_2_2D()
redim array_bytes_to_find_2_2D(ubound(array_bytes_to_find_2), 0)
dim array_bytes_to_find_3_2D()
redim array_bytes_to_find_3_2D(ubound(array_bytes_to_find_3), 0)
dim array_bytes_to_find_4_2D()
redim array_bytes_to_find_4_2D(ubound(array_bytes_to_find_4), 0)
dim array_bytes_to_find_5_2D()
redim array_bytes_to_find_5_2D(ubound(array_bytes_to_find_5), 0)
for i_1 = 0 to ubound(array_bytes_to_find_1_2D, 1) step 1
array_bytes_to_find_1_2D(i_1, 0) = array_bytes_to_find_1(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 1, 2)) = array_bytes_to_find_1_2D(i_1, 0) then
if ubound(array_bytes_to_find_1_2D, 2) < i_2 then
redim preserve array_bytes_to_find_1_2D(ubound(array_bytes_to_find_1_2D, 1), ubound(array_bytes_to_find_1_2D, 2) + 1)
end if
array_bytes_to_find_1_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_2_2D, 1) step 1
array_bytes_to_find_2_2D(i_1, 0) = array_bytes_to_find_2(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 3, 2)) = array_bytes_to_find_2_2D(i_1, 0) then
if ubound(array_bytes_to_find_2_2D, 2) < i_2 then
redim preserve array_bytes_to_find_2_2D(ubound(array_bytes_to_find_2_2D, 1), ubound(array_bytes_to_find_2_2D, 2) + 1)
end if
array_bytes_to_find_2_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_3_2D, 1) step 1
array_bytes_to_find_3_2D(i_1, 0) = array_bytes_to_find_3(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 5, 2)) = array_bytes_to_find_3_2D(i_1, 0) then
if ubound(array_bytes_to_find_3_2D, 2) < i_2 then
redim preserve array_bytes_to_find_3_2D(ubound(array_bytes_to_find_3_2D, 1), ubound(array_bytes_to_find_3_2D, 2) + 1)
end if
array_bytes_to_find_3_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_4_2D, 1) step 1
array_bytes_to_find_4_2D(i_1, 0) = array_bytes_to_find_4(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 7, 2)) = array_bytes_to_find_4_2D(i_1, 0) then
if ubound(array_bytes_to_find_4_2D, 2) < i_2 then
redim preserve array_bytes_to_find_4_2D(ubound(array_bytes_to_find_4_2D, 1), ubound(array_bytes_to_find_4_2D, 2) + 1)
end if
array_bytes_to_find_4_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
for i_1 = 0 to ubound(array_bytes_to_find_5_2D, 1) step 1
array_bytes_to_find_5_2D(i_1, 0) = array_bytes_to_find_5(i_1)
i_2 = 1
for i_3 = 0 to ubound(array_hex_strings_to_find) step 1
if cint("&H" & mid(array_hex_strings_to_find(i_3), 9, 2)) = array_bytes_to_find_5_2D(i_1, 0) then
if ubound(array_bytes_to_find_5_2D, 2) < i_2 then
redim preserve array_bytes_to_find_5_2D(ubound(array_bytes_to_find_5_2D, 1), ubound(array_bytes_to_find_5_2D, 2) + 1)
end if
array_bytes_to_find_5_2D(i_1, i_2) = i_3
i_2 = i_2 + 1
end if
next
next
WScript_Echo_variable = "1ers octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_1_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_1_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_1_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_1_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_1_2D, 2) then
if array_bytes_to_find_1_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "2èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_2_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_2_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_2_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_2_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_2_2D, 2) then
if array_bytes_to_find_2_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "3èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_3_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_3_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_3_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_3_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_3_2D, 2) then
if array_bytes_to_find_3_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "4èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_4_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_4_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_4_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_4_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_4_2D, 2) then
if array_bytes_to_find_4_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
WScript_Echo_variable = "5èmes octets à rechercher => Dans les chaînes : " & vbCrLf
for i_1 = 0 to ubound(array_bytes_to_find_5_2D, 1) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_5_2D(i_1, 0) & " => "
for i_2 = 1 to ubound(array_bytes_to_find_5_2D, 2) step 1
WScript_Echo_variable = WScript_Echo_variable & array_bytes_to_find_5_2D(i_1, i_2)
if i_2 + 1 <= ubound(array_bytes_to_find_5_2D, 2) then
if array_bytes_to_find_5_2D(i_1, i_2 + 1) <> "" then
WScript_Echo_variable = WScript_Echo_variable & " "
end if
end if
next
WScript_Echo_variable = WScript_Echo_variable & vbCrLf
Next
' WScript.Echo WScript_Echo_variable
set file_input = object_file_system.OpenTextFile(file_fullname, 1) ' 1 = Ouverture du fichier en lecture
set file_output = object_file_system.OpenTextFile(file_fullname & ".temporary", 2, TRUE, 0) ' 2 = Ouverture du fichier en écriture (TRUE = Fichier créé si n'existe pas) (0 = ASCII, -1 = Unicode, -2 = Par défaut)
array_bytes_to_find_1_2D_ubound = ubound(array_bytes_to_find_1_2D, 1)
array_bytes_to_find_2_2D_ubound = ubound(array_bytes_to_find_2_2D, 1)
array_bytes_to_find_3_2D_ubound = ubound(array_bytes_to_find_3_2D, 1)
array_bytes_to_find_4_2D_ubound = ubound(array_bytes_to_find_4_2D, 1)
array_bytes_to_find_5_2D_ubound = ubound(array_bytes_to_find_5_2D, 1)
dim array_byte_buffer_1()
redim array_byte_buffer_1(-1)
dim array_byte_buffer_2()
redim array_byte_buffer_2(-1)
dim array_match_found_1()
redim array_match_found_1(-1)
dim array_match_found_2()
redim array_match_found_2(-1)
byte_read = 0
i_byte_check = 0
i_replacement_count = 0
do until file_input.AtEndOfStream
byte_read = asc(file_input.Read(1))
' WScript.Echo "Caractère lu (hexadécimal " & string(2 - len(hex(byte_read)), "0") & ucase((hex(byte_read))) & " = décimal " & byte_read & ") : """ & chr(byte_read) & """"
' L'octet lu est stocké dans la dernière case d'un tableau (buffer).
redim preserve array_byte_buffer_1(ubound(array_byte_buffer_1) + 1)
array_byte_buffer_1(ubound(array_byte_buffer_1)) = byte_read
' WScript.Echo "Contenu du buffer : " & join(array_byte_buffer_1, " ")
select case i_byte_check
case 0
' On considère que le buffer peut contenir plusieurs octets en attente d'être traités,
' c'est-à-dire écrits dans le fichier de sortie s'il n'existe aucune correspondance.
' Chaque 1er octet traité disparaît du buffer, dont la taille se réduit.
' Lorsque sa taille atteint 0 (ubound = -1), le buffer est vide,
' tous les octets ont été traités.
b_exit_while_1 = FALSE
while ubound(array_byte_buffer_1) >= 0 AND b_exit_while_1 = FALSE
' Première boucle de vérification.
' On compare le 1er octet (i_byte_check = 0) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 1er tableau.
i_0 = 0
while i_0 <= array_bytes_to_find_1_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' l'écriture du fichier de sortie est suspendue (i_byte_check ≠ 0)
' et l'octet reste stocké dans le buffer.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_1_2D(i_0, 0) then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_1_2D(i_0, 0)
b_exit_while_1 = TRUE
i_byte_check = i_byte_check + 1 ' i_byte_check = 1
i_0 = i_0 - 1
end if
i_0 = i_0 + 1
wend
' Si il ne correspond pas, l'octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
if b_exit_while_1 = FALSE then
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
wend
' break
case 1
' Deuxième boucle de vérification.
' On compare le 2ème octet (i_byte_check = 1) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 2ème tableau.
b_exit_while_1 = FALSE
i_1 = 0
while i_1 <= array_bytes_to_find_2_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' on compare la 2ème dimension de la case du 1er tableau précédent
' à la 2ème dimension de cette case de ce 2ème tableau et
' on stocke les numéros communs dans un tableau : array_match_found_1.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_2_2D(i_1, 0) then
b_exit_while_1 = TRUE
redim array_match_found_1(-1)
i_0_2D = 1
b_exit_while_2 = FALSE
while i_0_2D <= ubound(array_bytes_to_find_1_2D, 2) AND b_exit_while_2 = FALSE
if array_bytes_to_find_1_2D(i_0, i_0_2D) <> "" then
i_1_2D = 1
b_exit_while_3 = FALSE
while i_1_2D <= ubound(array_bytes_to_find_2_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_2_2D(i_1, i_1_2D) <> "" then
if array_bytes_to_find_1_2D(i_0, i_0_2D) = array_bytes_to_find_2_2D(i_1, i_1_2D) then
redim preserve array_match_found_1(ubound(array_match_found_1) + 1)
array_match_found_1(ubound(array_match_found_1)) = array_bytes_to_find_1_2D(i_0, i_0_2D)
end if
i_1_2D = i_1_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_0_2D = i_0_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
' Si le tableau n'est pas vide, il indique le ou les numéros
' des chaînes qui commencent par ces 2 octets. Dans ce cas :
' l'écriture du fichier de sortie reste suspendue (i_byte_check ≠ 0)
' et les octets restent stockés dans le buffer.
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_2_2D(i_1, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 2
end if
' Si le tableau est vide, les 2 octets ne correspondent
' à aucune chaîne à rechercher. C'est la même situation que
' si le 2ème octet ne correspond à aucune case du 2ème tableau.
end if
i_1 = i_1 + 1
wend
' Si il ne correspond pas, le premier octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
' De plus i_byte_check est réinitialisée donc on retourne
' à la première boucle de vérification pour vider le buffer.
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 2
' Troisième boucle de vérification.
' On compare le 3ème octet (i_byte_check = 2) du buffer
' aux octets stockés dans les cases de la 1ère dimension du 3ème tableau.
b_exit_while_1 = FALSE
i_2 = 0
while i_2 <= array_bytes_to_find_3_2D_ubound AND b_exit_while_1 = FALSE
' Si il correspond à une case,
' on compare le tableau précédent array_match_found_1
' à la 2ème dimension de cette case de ce 3ème tableau et
' on stocke les numéros communs dans array_match_found_1
' par l'intermédiaire d'un tableau temporaire : array_match_found_2.
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_3_2D(i_2, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_1_2D = 0
b_exit_while_2 = FALSE
while i_1_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_1_2D) <> "" then
i_2_2D = 1
b_exit_while_3 = FALSE
while i_2_2D <= ubound(array_bytes_to_find_3_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_3_2D(i_2, i_2_2D) <> "" then
if array_match_found_1(i_1_2D) = array_bytes_to_find_3_2D(i_2, i_2_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_1_2D)
end if
i_2_2D = i_2_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_1_2D = i_1_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
' Si le tableau n'est pas vide, il indique le ou les numéros
' des chaînes qui commencent par ces 3 octets. Dans ce cas :
' l'écriture du fichier de sortie reste suspendue (i_byte_check ≠ 0)
' et les octets restent stockés dans le buffer.
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_3_2D(i_2, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 3
end if
' Si le tableau est vide, les 3 octets ne correspondent
' à aucune chaîne à rechercher. C'est la même situation que
' si le 3ème octet ne correspond à aucune case du 3ème tableau.
end if
i_2 = i_2 + 1
wend
' Si il ne correspond pas, le premier octet est traité,
' c'est-à-dire écrit dans le fichier de sortie puis retiré du buffer.
' De plus i_byte_check est réinitialisée donc on retourne
' à la première boucle de vérification pour vider le buffer.
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
' Si le buffer contient plusieurs cases,
' on les décale vers l'arrière et on le raccourcit d'une case.
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 3
b_exit_while_1 = FALSE
i_3 = 0
while i_3 <= array_bytes_to_find_4_2D_ubound AND b_exit_while_1 = FALSE
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_4_2D(i_3, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_2_2D = 0
b_exit_while_2 = FALSE
while i_2_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_2_2D) <> "" then
i_3_2D = 1
b_exit_while_3 = FALSE
while i_3_2D <= ubound(array_bytes_to_find_4_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_4_2D(i_3, i_3_2D) <> "" then
if array_match_found_1(i_2_2D) = array_bytes_to_find_4_2D(i_3, i_3_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_2_2D)
end if
i_3_2D = i_3_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_2_2D = i_2_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_4_2D(i_3, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 4
end if
end if
i_3 = i_3 + 1
wend
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case 4
b_exit_while_1 = FALSE
i_4 = 0
while i_4 <= array_bytes_to_find_5_2D_ubound AND b_exit_while_1 = FALSE
if array_byte_buffer_1(i_byte_check) = array_bytes_to_find_5_2D(i_4, 0) then
b_exit_while_1 = TRUE
redim array_match_found_2(-1)
i_3_2D = 0
b_exit_while_2 = FALSE
while i_3_2D <= ubound(array_match_found_1) AND b_exit_while_2 = FALSE
if array_match_found_1(i_3_2D) <> "" then
i_4_2D = 1
b_exit_while_3 = FALSE
while i_4_2D <= ubound(array_bytes_to_find_5_2D, 2) AND b_exit_while_3 = FALSE
if array_bytes_to_find_5_2D(i_4, i_4_2D) <> "" then
if array_match_found_1(i_3_2D) = array_bytes_to_find_5_2D(i_4, i_4_2D) then
redim preserve array_match_found_2(ubound(array_match_found_2) + 1)
array_match_found_2(ubound(array_match_found_2)) = array_match_found_1(i_3_2D)
end if
i_4_2D = i_4_2D + 1
else
b_exit_while_3 = TRUE
end if
wend
i_3_2D = i_3_2D + 1
else
b_exit_while_2 = TRUE
end if
wend
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
if ubound(array_match_found_1) >= 0 then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & array_bytes_to_find_5_2D(i_4, 0)
' WScript.Echo "Les octets du buffer """ & join(array_byte_buffer_1, " ") & """ doivent commencer la/les chaîne(s) """ & join(array_match_found_1, " ") & """"
i_byte_check = i_byte_check + 1 ' i_byte_check = 5
end if
end if
i_4 = i_4 + 1
wend
if b_exit_while_1 = FALSE OR ubound(array_match_found_1) < 0 then
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 2 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
' break
case else
' On prend le tableau array_match_found_1, il contient le
' (ou les) numéro de case du tableau array_hex_strings_to_find
' qui lui-même contient la chaîne complète des octets à analyser
' dont les 5 premiers octets correspondent.
' Remarque : il se peut que plusieurs chaînes aient leurs 5 premiers
' octets en commun. Voire que seul le dernier octet soit différent.
' Donc on analyse chaque case du tableau array_match_found_1.
b_exit_while_1 = FALSE
i_5 = 0 ' (Inutile car i_5 reste à 0)
while i_5 <= ubound(array_match_found_1) AND b_exit_while_1 = FALSE
' On analyse la chaîne contenue dans array_hex_strings_to_find.
' Si la chaîne continue à correspondre, on teste l'octet suivant.
if string(2 - len(hex(array_byte_buffer_1(i_byte_check))), "0") & ucase((hex(array_byte_buffer_1(i_byte_check)))) = mid(array_hex_strings_to_find(array_match_found_1(i_5)), 2 * i_byte_check + 1, 2) then
' WScript.Echo "Étape " & i_byte_check & " - Correspondance trouvée : " & array_byte_buffer_1(i_byte_check) & " = " & mid(array_hex_strings_to_find(array_match_found_1(i_5)), 2 * i_byte_check + 1, 2)
b_exit_while_1 = TRUE
i_byte_check = i_byte_check + 1
' Si la chaîne ne correspond plus, alors on retire son numéro du tableau array_match_found_1.
' Et si le tableau est vide, alors aucune chaîne ne correspondait,
' donc le premier octet est traité et i_byte_check est réinitialisée.
else
if ubound(array_match_found_1) >= 1 then
redim array_match_found_2(ubound(array_match_found_1) - 1)
for i = 1 to ubound(array_match_found_1)
array_match_found_2(i - 1) = array_match_found_1(i)
next
redim array_match_found_1(ubound(array_match_found_2))
for i = 0 to ubound(array_match_found_2)
array_match_found_1(i) = array_match_found_2(i)
next
else
redim array_match_found_1(-1)
i_byte_check = 0
file_output.Write(chr(array_byte_buffer_1(i_byte_check)))
if ubound(array_byte_buffer_1) >= 1 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - 1)
for i = 1 to ubound(array_byte_buffer_1)
array_byte_buffer_2(i - 1) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
else
redim array_byte_buffer_1(-1)
end if
end if
end if
if i_byte_check > 0 then
' Si la correspondance va jusqu'au bout de la chaîne, alors la chaîne a été détectée.
if i_byte_check = len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 then
' Dans ce cas on écrit la nouvelle chaîne et on vide le buffer.
for i = 0 to len(array_hex_strings_to_replace(array_match_found_1(i_5))) - 1 step 2
file_output.Write(chr(cbyte("&H" & Mid(array_hex_strings_to_replace(array_match_found_1(i_5)), i + 1, 2))))
next
' WScript.Echo vbCrLf & "Contenu de la chaîne n°" & array_match_found_1(i_5) + 1 & " (" & len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 & " cases) : " & array_hex_strings_to_find(array_match_found_1(i_5)) & vbCrLf & "Contenu du buffer (" & ubound(array_byte_buffer_1) + 1 & " cases) : " & join(array_byte_buffer_1, " ")
' On vide le buffer de la chaîne à rechercher.
if ubound(array_byte_buffer_1) >= len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 then
redim array_byte_buffer_2(ubound(array_byte_buffer_1) - (len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2))
for i = len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2 to ubound(array_byte_buffer_1) step 1
array_byte_buffer_2(i - len(array_hex_strings_to_find(array_match_found_1(i_5))) / 2) = array_byte_buffer_1(i)
next
redim array_byte_buffer_1(ubound(array_byte_buffer_2))
for i = 0 to ubound(array_byte_buffer_2)
array_byte_buffer_1(i) = array_byte_buffer_2(i)
next
' WScript.Echo "Contenu restant du buffer = : " & join(array_byte_buffer_1, " ")
else
redim array_byte_buffer_1(-1)
end if
i_byte_check = 0
i_replacement_count = i_replacement_count + 1
' WScript.Echo vbCrLf & "Fichier :" & vbCrLf & file_fullname & vbCrLf & "Séquence n°" & array_match_found_1(i_5) + 1 & " trouvée :" & vbCrLf & array_hex_strings_to_find(array_match_found_1(i_5)) & vbCrLf & "Remplacée par :" & vbCrLf & array_hex_strings_to_replace(array_match_found_1(i_5)) & vbCrLf
end if
end if
wend
end select
loop
file_input.Close
file_output.Close
i_my_replace_array_hex_strings_in_file = i_replacement_count
end function
Function i_my_rename_file(byval file_fullname, byval file_fullname_new)
if object_file_system.FileExists(file_fullname) = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & vbCrLf & "n'existe pas, impossible de le renommer en :" & vbCrLf & file_fullname_new, 48, "Erreur"
WScript.Quit(0)
end if
' WScript.Echo "Le fichier :" & vbCrLf & file_fullname & vbCrLf & "a été renommé en :" & vbCrLf & file_fullname_new & vbCrLf
object_file_system.MoveFile file_fullname, file_fullname_new
if object_file_system.FileExists(file_fullname_new) = FALSE then
MsgBox "Erreur, le fichier :" & vbCrLf & file_fullname & vbCrLf & "n'a pas pu être renommé.", 48, "Erreur"
WScript.Quit(0)
end if
i_my_rename_file = 0
end function
function i_my_fix_corrupted_file(byval corrupted_file_error_ori, byval corrupted_file_error_fix, byval corrupted_file)
i_installation_type = 0
if program_folder <> "" then
if object_file_system.FileExists(program_folder & "\" & corrupted_file) = FALSE then
MsgBox "Erreur, fichier non détecté :" & vbCrLf & program_folder & "\" & corrupted_file, 48, "Erreur"
WScript.Quit(0)
end if
i_installation_type = 1
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_portable_32 & "\" & corrupted_file) = TRUE then
i_installation_type = 2
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_portable_64 & "\" & corrupted_file) = TRUE then
i_installation_type = i_installation_type + 3
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_installed_32 & "\" & corrupted_file) = TRUE then
i_installation_type = 6
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & vbCrLf
end if
if object_file_system.FileExists(program_folder_installed_64 & "\" & corrupted_file) = TRUE then
i_installation_type = 7
WScript.Echo "Fichier détecté :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & vbCrLf
end if
if i_installation_type = 0 then
MsgBox "Erreur, aucun fichier détecté.", 48, "Erreur"
WScript.Quit(0)
end if
if i_installation_type = 1 then
if object_file_system.FileExists(program_folder & "\" & corrupted_file & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question") ' 4 = vbYesNo 32 = vbQuestion 256 = vbDefaultButton2 0 = vbApplicationModal
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder & "\" & corrupted_file, program_folder & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder & "\" & corrupted_file & ".temporary", program_folder & "\" & corrupted_file
end if
if i_installation_type = 2 OR i_installation_type = 5 then
if object_file_system.FileExists(program_folder_portable_32 & "\" & corrupted_file & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_portable_32 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_portable_32 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_portable_32 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_portable_32 & "\" & corrupted_file, program_folder_portable_32 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_portable_32 & "\" & corrupted_file & ".temporary", program_folder_portable_32 & "\" & corrupted_file
end if
if i_installation_type = 3 OR i_installation_type = 5 then
if object_file_system.FileExists(program_folder_portable_64 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_portable_64 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_portable_64 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_portable_64 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_portable_64 & "\" & corrupted_file, program_folder_portable_64 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_portable_64 & "\" & corrupted_file & ".temporary", program_folder_portable_64 & "\" & corrupted_file
end if
if i_installation_type = 6 then
if object_file_system.FileExists(program_folder_installed_32 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_installed_32 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_installed_32 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_installed_32 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_installed_32 & "\" & corrupted_file, program_folder_installed_32 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_installed_32 & "\" & corrupted_file & ".temporary", program_folder_installed_32 & "\" & corrupted_file
end if
if i_installation_type = 7 then
if object_file_system.FileExists(program_folder_installed_64 & "\" & corrupted_file_1 & ".bak") = TRUE then
user_response = MsgBox("Attention, le fichier de sauvegarde :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & ".bak" & vbCrLf _
& "existe déjà. Si vous avez déjà utilisé ce script mais que" & vbCrLf & "l'écriture inclusive est revenue à la suite d'une mise à jour," & vbCrLf _
& "appuyez sur ""Oui"" pour supprimer le fichier "".bak"" et continuer," & vbCrLf & "sinon appuyez sur ""Non"" pour quitter." & vbCrLf _
& "Voulez-vous continuer ?", 292, "Question")
if user_response <> "6" then
WScript.Quit(0)
end if
object_file_system.DeleteFile program_folder_installed_64 & "\" & corrupted_file & ".bak", TRUE
WScript.Echo "Le fichier :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & ".bak" & vbCrLf & "a été supprimé."
end if
number_of_replacements = i_my_replace_array_hex_strings_in_file(corrupted_file_error_ori, corrupted_file_error_fix, program_folder_installed_64 & "\" & corrupted_file)
WScript.Echo vbCrLf & vbCrLf & number_of_replacements & " remplacement(s) effectué(s) sur le fichier :" & vbCrLf & program_folder_installed_64 & "\" & corrupted_file & vbCrLf
i_my_rename_file program_folder_installed_64 & "\" & corrupted_file, program_folder_installed_64 & "\" & corrupted_file & ".bak"
i_my_rename_file program_folder_installed_64 & "\" & corrupted_file & ".temporary", program_folder_installed_64 & "\" & corrupted_file
end if
i_my_fix_corrupted_file = number_of_replacements
end function
' _____________________________________________________________________________
' Partie à modifier pour ajouter des fichiers à corriger :
' Lancement du script :
number_of_replacements = i_my_fix_corrupted_file(corrupted_file_1_error_ori, corrupted_file_1_error_fix, corrupted_file_1)
number_of_replacements = i_my_fix_corrupted_file(corrupted_file_2_error_ori, corrupted_file_2_error_fix, corrupted_file_2)
' _____________________________________________________________________________
' Partie à ne pas modifier :
pause_message = "L'exécution de ce programme est terminée."
MsgBox pause_message & vbCrLf & vbCrLf & "Appuyez sur une touche pour continuer...", 64, "Pause" ' 0 = vbOKOnly vbDefaultButton1 vbApplicationModal 64 = vbInformation
WScript.Quit(0)