470,587 Members | 2,284 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,587 developers. It's quick & easy.

VBscript hell

112 100+
hi all, first its my first time to post question in internet, but vbs really let me crazy.

my problem is :
i wanna to transfer exe file to machine that i can access by real ip no VPN and i cant access machine sharing but i can remote to this machine using remote desktop, sure u will ask me for download, but this machine cant go online because of physical security and firewall.

i was think about 2 solution

1-i was thinking about what the problem if i open exe file in notebad and copy data in clipboard and then past it to new file, but this solution isnt work, almost clipboard cant work with unprintable & control characters

then i think about the second solution

2-what if i convert exe file to ascii of characters example and separate them by dot char as, now this file can transfer using clipboard and no problem except convert it back to exe using vbscript

i do all of that and this idea working good and i convert exe to digits and back to exe using Visual Basic 6, but sure the remote machine dont have visual basic then i must use VBscript , and i can copy script text too using clipboard

the same functions i was made in vb6 didnt work in vbs

my first problem was in textstream.write(Str) in VBS it result run-time error (invalid procedure call or arguments) and i dont know why!!!!!, i was trace what character write function fail in, and i think it any character greater than 128

second problem i was search and search and i was found that i can use ADODB.Stream to write binary data and i was meet the very funny thing in the world :D lol , Stream.Write(Buff) take one argument as Array Of Bytes and i cant define Array of byte in VBS, just array of variants!!!!!, when i pass my array of variant variable to stream.write function i got error (wrong number of arguments, or argument type is conflict with another and so on)....and sure because array of variants and array of bytes conflict type!!!!!, then i was think and i got another solution, i was open file using stream.read(n) and i was check about Vartype of returned array and it was array of bytes not variant ,,thats very good!!!!, i got it!!!!,when im trying to access this array of bytes as array using brakets bytearr(n) i got type mismatch lol, vbs is still working with anytype as variant as soon as vartype(var) return vbarray | vbbyte type, when i pass it to stream.write (bytearr) ir working , but i cant assign or get value from this array byt using brackets, then im trying to work with it using mid instead of array brakets i got type mistamch too because Mid() function work wih string and it not string type lool

i will past my two ways for converting to exe , and sry about my dancing english :D

Ascii File Example

'================================================= =======
'you can ignore this function it just as visual basic Val Function and it work to muliple numbers by 10 , 100 , and ignore unicode second byte character=0 placed by last convert exe to ascii function and sure i must leave it using unicode to copy it using clipboard

Function Val(ByVal Strvar)
Dim CurrentChr
Dim ChrValue
Dim GetChar
Dim FieldValue
For CurrentChr = LenB(Strvar) To 1 step -1
If (GetChar = False) Then
if(CurrentChr<(LenB(Strvar)-1)) Then FieldValue=FieldValue * 10
ChrValue =ChrValue +((AscB(MidB(Strvar, CurrentChr, 1))-48) * FieldValue)
End If
GetChar = Not GetChar
Val =cbyte(ChrValue)
End Function
================================================== ======
Function ConvertToExeUsingFSO(ByVal FilePath)
Dim FileSys
Dim ExeFile
Dim FileData
Dim CurrentChar
Dim DotOffset
Dim NewString
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set ExeFile = FileSys.OpenTextFile(FilePath)
FileData = ExeFile.ReadAll
DotOffset = InStr(FileData, ".") 'search about dot char
If (DotOffset = 0) Then Exit Do 'if no dot char found then file comlpete
CurrentChar = Val(Mid(FileData, 1, DotOffset - 1)) 'call my val function
FileData = Mid(FileData, DotOffset + 1) 'clear char ascii value and dot
NewString = NewString & Chr(CurrentChar) 'ascii back to 1 byte
'exmaple in file it 77 in 2 byte memory now it will be 1 byte = 77
'using chr() or chrB() or chrW() is not the problem i was try
Call ExeFile.Close
Set ExeFile = FileSys.CreateTextFile(Left(FilePath, Len(FilePath) - 4)) '
Call ExeFile.Write(NewString) * the problem here invalid procudure call :49
Call ExeFile.Close
MsgBox "done"
End Function

================================================== ======

Function ConvertExeUsingADOSTREAM(ByVal FilePath)
Dim FileSys
Dim ExeFile
Dim FileData
Dim CurrentChar
Dim DotOffset
Dim NewString()
Dim CharOffset
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set ExeFile = FileSys.OpenTextFile(FilePath)
FileData = ExeFile.ReadAll
Call ExeFile.Close
Set ExeFile = CreateObject("ADODB.Stream")
ExeFile.Type = 1
Call ExeFile.Open
CharOffset = CharOffset + 1
DotOffset = InStr(FileData, ".")
If (DotOffset = 0) Then Exit Do
CurrentChar = Val(Mid(FileData, 1, DotOffset - 1))
FileData = Mid(FileData, DotOffset + 1)
Redim Preserve NewString(CharOffset-1)
NewString(CharOffset - 1) = CurrentChar
Call ExeFile.Write(NewString)
Call ExeFile.SaveToFile(Left(FilePath, Len(FilePath) - 4), 2)
Call ExeFile.Close
Set FileSys = Nothing
Set ExeFile = Nothing
MsgBox "done"
End Function

Nov 15 '07 #1
0 1713

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

29 posts views Thread by Christopher Brandsdal | last post: by
22 posts views Thread by Jim Hubbard | last post: by
1 post views Thread by GreatB | last post: by
2 posts views Thread by VBS | last post: by
1 post views Thread by JNariss | last post: by
4 posts views Thread by sparky | last post: by
7 posts views Thread by Larro91 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.