1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| <job>
<runtime>
<description author="jcb">
---------------------------------------------------------------------
Ce script en ligne de commande décode tout fichier vbe,je,asp,html,...
encodé au préalable à l'aide de l'encodeur "screnc.exe" de Microsoft :
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp
ou à l'aide du script "screncode.wsf"
JCB © 2004 / Jean-Luc Antoine © 2002
---------------------------------------------------------------------
</description>
<unnamed
name = "srce"
helpstring = "Nom de fichier source à décoder"
type = "string"
required = "true" />
<unnamed
name = "dest"
helpstring = "Nom de fichier destination décodé"
type = "string"
required = "true" />
<unnamed
name = "A"
helpstring = "Affichage du fichier décodé dans le bloc-notes"
type = "string"
required = "false" />
<example>
Chaque nom de fichier doit être encadré par des guillemets
s'il contient des espaces.
Exemples :
----------
scrdecode.wsf h:\wsh\monscript.vbe "m:\mes scripts\monscript.vbs"
scrdecode.wsf D:\Inetpub\wwwroot\ident.asp "k:\mon site\identdec.asp" A
---------------------------------------------------------------------
</example>
</runtime>
<script language="VBScript">
Const SW_SHOWNORMAL=1
Const ForReading=1
Const ForWriting=2
'Tags qui encadrent les chaines codées
'--- Début
Const TagDeb1="#@~^"
Const TagDeb2="??????" '6 caractères variables,p.ex. "nQEAAA" ,"2BoAAA",...
Const TagDeb3="=="
LTD1=len(TagDeb1)
LTD2=len(TagDeb2)
LTD3=len(TagDeb3)
LTD=LTD1+LTD2+LTD3
'--- Fin
Const TagFin1="??????" '6 caractères variables,p.ex. "oX4HAA", "oW4AAA",...
Const TagFin2="==^#~@"
LTF1=len(TagFin1)
LTF2=len(TagFin2)
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set shell = WScript.CreateObject("WScript.Shell")
Set UnNamed = WScript.Arguments.UnNamed
nu=UnNamed.count
If nu<2 Then
WScript.Arguments.ShowUsage
WScript.Quit
End If
Srce=UnNamed(0)
Dest=UnNamed(1)
Display=false
If nu>=3 then if lcase(UnNamed(2))="a" Then Display=true
If not fso.FileExists(Srce) Then
MsgBox "Le fichier " & Srce & " n'a pas été trouvé", vbCritical + vbOKOnly, "Décodage de fichier"
WScript.Quit
End If
If fso.FileExists(Dest) Then
rep=MsgBox("Le fichier destination " & Dest & " existe déjà." & VBCRLF & _
"Faut-il l'écraser ?", vbQuestion+vbYesNo, "Décodage de fichier")
If rep<>vbYes Then WScript.Quit
End If
Set fs = fso.OpenTextFile(Srce,ForReading,false)
data=fs.readAll
fs.close
' boucle explorant les blocs codés
' repérés par les tags TagDeb1 et TagFin2
Do
IndexFin=0
IndexDeb=Instr(data,TagDeb1)
If IndexDeb>0 Then
' recherche de TagDeb3 ("==") LTD2 (6) caractères après le tag de début
If Instr(IndexDeb,data,TagDeb3)=IndexDeb+LTD1+LTD2 Then
' recherche du tag de fin
IndexFin=Instr(IndexDeb,data,TagFin2)
If IndexFin>0 Then
'données non codées initiales
data1=Left(data,IndexDeb-1)
'données codées
IndexDeb2=IndexDeb+LTD
'il faut soustraire LTF1 (6) caractères avant le tag de fin
data2=Mid(data,IndexDeb2,IndexFin-LTF1-IndexDeb2)
'données non codées finales
data3=Mid(data,IndexFin+LTF2)
data= data1 & Decode(data2) & data3
End If
End If
End If
Loop Until IndexFin=0
Set fd = fso.CreateTextFile(Dest, true,false)
fd.Write data
fd.close
If Display Then
cmd="notepad.exe """ & Dest & """"
shell.run cmd,SW_SHOWNORMAL,false
End If
WScript.Quit
'--------------------------------------------------------------------
'Partie inspirée de JL Antoine
'http://www.interclasse.com/scripts/decovbe.php
Function Decode(ChEnc)
Dim tDecode(127)
StrCod=array("@&","@#","@*","@!","@$")
StrDec=array(vbLf,vbCr,">" ,"<" ,"@" )
Const Combinaison="1231232332321323132311233213233211323231311231321323112331123132"
Set se=WScript.CreateObject("Scripting.Encoder")
For i=9 to 127
tDecode(i)="xxx"
Next
'encodage des chaines "xxx" avec x=chr(i), i=9 -> 127
For i=9 to 127
chd=string(3,i)
che=se.EncodeScriptFile(".vbs",chd,0,"")
S=Mid(che,13,3)
ch=""
For j=1 to 3
c=Asc(Mid(S,j,1))
if not ((c = 42) and (i = 62)) then tDecode(c)=Left(tDecode(c),j-1) & chr(i) & Mid(tDecode(c),j+1)
Next
Next
For i = lbound(StrCod) To ubound(StrCod)
ChEnc=Replace(ChEnc,StrCod(i),StrDec(i))
Next
index=-1
ChDec=""
For i=1 to Len(ChEnc)
oldcar=Mid(ChEnc,i,1)
newcar=oldcar
c=asc(oldcar)
If c<128 Then index=index+1
If (c=9) or ((c>31) and (c<128)) Then
If (c<>60) and (c<>62) and (c<>64) Then newcar=Mid(tDecode(c),Mid(Combinaison,(index mod 64)+1,1),1)
End If
ChDec=ChDec & newcar
Next
Decode=ChDec
End Function
'--------------------------------------------------------------------
</script>
</job> |
Partager