Vbs code that converts a file to a vbs statement

Source: Internet
Author: User

Author: xiaolu [BST]
Source: evil baboons Information Security Team (www.eviloctal.com)

This is not an exe2vbs file of all types that can be converted, but it is limited to the size of the string file. It cannot be too large. I have tested 3 M files.
Save the following code as: file2vbs. vbsCopy codeThe Code is as follows: 'program By xiaolu
'Name: file2vbs. vbs
On error resume next
Do while 1
Fname = InputBox ("enter the name of the file to be converted (including the path):", "input file name", "f: \ hhh.exe ")
If fname = "" then Wscript. quit
Err. number = 0
Set Ado = createObject ("adodb. stream ")
With Ado
. Type = 1
. Open
. Loadfromfile fname
Ss =. read
End
If err. number <> 0 then
If msgbox ("file opening error! ", 1," File2VBS ") = 2 then Wscript. quit
Else
Exit do
End if
Loop
Fname = InputBox ("Enter the vbs name (including the path):", "input file name", "f: \ hhh. vbs ")
If fname = "" then Wscript. quit
Set Fso = createObject ("Scripting. FileSystemObject ")
Set File = fso. OpenTextFile (fname, 2, True)
Lens = lenB (ss) mod 500.
For j = 0 to int (lenB (ss)/500)-1
If j = 0 then
File. writeline "ss =" "& Bin2Str (midb (ss, 500 * j + 1,500 ))&"""_"
Else
File. writeline "+" "& Bin2Str (midb (ss, 500 * j + 1,500 ))&"""_"
End if
Next
If lens> 0 then
File. writeline "+" "& Bin2Str (rightb (ss, lens ))&""""
Else
File. writeline "+" & chr (34) & chr (34)
End if
File. writeline ""
File. writeline "Set RS = createObject (" "ADODB. recordset ""): L = Len (ss)/2: RS. fields. append "" m "", 205, L: RS. open: RS. addNew: RS ("" m "") = ss & ChrB (0): RS. update: ss = RS ("" m ""). getChunk (L )"
File. writeline "Set s = createObject (" "ADODB. stream ""): with s :. mode = 3 :. type = 1 :. open ():. write ss :. saveToFile wscript. arguments (0), 2: end"
File. close
Set fso = nothing
Ado. close
Set Abo = nothing
Function Bin2Str (Re)
For I = 1 To lenB (Re)
Bt = AscB (MidB (Re, I, 1 ))
If bt <16 Then Bin2Str = Bin2Str & "0"
Bin2Str = Bin2Str & Hex (bt)
Next
End Function

File Generation Method
Copy codeThe Code is as follows: cscript file2vbs. vbs c: \ test.exe

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.