VBS script encryption A few small details summary below _vbs

Source: Internet
Author: User
Tags readline

Copy Code code as follows:

Dxy
How are you doing!
I've been learning vbs for a short time, and recently I've seen a book about the encryption of the VBS script, I tried, but there is a problem, low-level grammatical errors I have fixed, but the script does not work after running. So I'd like to ask you a question. The principle of scripting is this: it converts code into 16, Then write a decryption code, through this decryption to execute the encrypted code, the string into 16 code as follows:
Function Str2hex (Byval strhex)
For I=1 to Len (Strhex)
ShEx = ShEx & Hex (ASC (strhex,i,1))
Next
Str2hex = ShEx
End Function

The decrypted code is as follows:

Function hextostr (data)
Hextostr = "Execute" "" "" "" ""
C= "&CHR" (&h)
N= ")"
Do while Len (data) >1
If IsNumeric (left (data,1)) Then
Hextostr=hextostr&c&left (data,2) &n
Data=mid (data,3)
Else
Hextostr=hextostr&c&left (data,4) &n
Data=mid (data,5)
End If
Loop
End Function

The decryption code seems to have a problem, please correct me, I can't find

The entire finished product is:

On Error Resume Next
Set arg=wscript.arguement ' Declare external parameters
If arg.count=0 Then wscript.quit ' exit script if no parameters
Set Fso=creatobject ("Scripting.filesystem Object") ' Declares the FSO component
When Fso.opentextfile (ARG (0), 1,flase)
data = Readall:.close ' reads text content
If err.number<>0 then Wscript.Quit ' If an error occurs, exit
With Fso.opentextfile (ARG (0) & "*.vbs", 2,true) ' writes the converted well into a new VBS
If err.number<>0 then Wscript.Quit ' If an error occurs, exit
. WriteLine "Execute (Hextostr (" "&str2hex (data) &" "))" ' Perform decryption and execute decrypted code
. WriteLine "Function hextostr (data)"
. WriteLine "hextostr=" "" "" "" "" "" "" "" "" "" "
. WriteLine "c=" "&AMP;CHR" (&h "" "
. WriteLine "n="
. WriteLine "Do While Len (data) >1"
. WriteLine "If IsNumeric (left (data,1)) then"
. WriteLine "Hextostr=hextostr&c&left (data,2) &n"
. WriteLine "data = (data,3)"
. WriteLine "Else"
. WriteLine "Hextostr=hex to Str&c&left (data,4) &n"
. WriteLine "Data=mid (data,5)"
. WriteLine "End If"
. WriteLine "Loop"
. WriteLine "End Function"
' Write the decryption function in
. Close ' Closes the text
Set fso=nothing ' Logoff FSO component
End With
MsgBox "OK"
' The following is the cryptographic function
Function Str2hex (Byval strhex)
For I=1 to Len (Strhex)
ShEx = ShEx & Hex (ASC (strhex,i,1))
Next
Str2hex = ShEx
End Function
' All the code is here, so long ~

The book said, to the encryption of the VBS script dragged to the script on the line, but I did not succeed, do not know there are problems, please help me, thank you ~

The code above takes note of several situations:
1, set arg=wscript.arguements
There's an s in the back door.
2, set Fso=creatobject ("Scripting.filesystem Object") ' Declares the FSO component
It should be filesystemboject.
3. WriteLine "n="
The way to "n=" with VBS (double quotes) is to use the two ""
. WriteLine "n=" "" "" "
4. WriteLine "data = (data,3)" Here is less mid
That's basically it.
Do.vbs Save As Do.vbs, will be encrypted JS file dragged to this file can be
Copy Code code as follows:

' On Error Resume Next
Set arg=wscript.arguments ' Declare external parameters
If arg.count=0 Then wscript.quit ' exit script if no parameters
Set Fso=createobject ("Scripting.FileSystemObject") ' Declares the FSO component
Filename=wscript.arguments (0)
Set Readline=fso.opentextfile (filename,1,flase)
Data=readline.readall:
Readline.close ' Read text content
If err.number<>0 then Wscript.Quit ' If an error occurs, exit
With Fso.opentextfile (filename& "_out.vbs", 2,true) ' writes the converted good into a new VBS
If err.number<>0 then Wscript.Quit ' If an error occurs, exit
. WriteLine "Execute (Hextostr (" "&str2hex (data) &" "))" ' Perform decryption and execute decrypted code
. WriteLine "Function hextostr (data)"
. WriteLine "hextostr=" "" "" "" "" "" "" "" "" "" "
. WriteLine "c=" "&AMP;CHR" (&h "" "
. WriteLine "n=" "" "" "
. WriteLine "Do While Len (data) >1"
. WriteLine "If IsNumeric (left (data,1)) then"
. WriteLine "Hextostr=hextostr&c&left (data,2) &n"
. WriteLine "Data = Mid (data,3)"
. WriteLine "Else"
. WriteLine "Hextostr=hextostr&c&left (data,4) &n"
. WriteLine "Data=mid (data,5)"
. WriteLine "End If"
. WriteLine "Loop"
. WriteLine "End Function"
' Write the decryption function in
. Close ' Closes the text
End With
Set fso=nothing ' Logoff FSO component
MsgBox "OK"
' The following is the cryptographic function
Function Str2hex (Byval strhex)
For I=1 to Len (Strhex)
ShEx = ShEx & Hex (ASC (strhex,i,1))
Next
Str2hex = ShEx
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.