Skip to content

Instantly share code, notes, and snippets.

@levisre
Created November 13, 2019 10:19
Show Gist options
  • Save levisre/8df28d21e26272e3b69746498356d76d to your computer and use it in GitHub Desktop.
Save levisre/8df28d21e26272e3b69746498356d76d to your computer and use it in GitHub Desktop.
' 4 t3h F4cK'3n w0w 5h17
Option Explicit
Const TypeBinary = 1
Const ForReading = 1, ForWriting = 2, ForAppending = 8
main
Sub main
Dim strMode, strInput, strOutput
strMode = WScript.Arguments.Item(0)
strInput = WScript.Arguments.Item(1)
strOutput = ""
Dim bytes, data
if StrComp( strMode, "e" ) = 0 Then
strOutput = strInput & ".b64"
bytes = readBytes(strInput)
data = encodeBase64(bytes)
writeStr strOutput, data
Else
if StrComp( strMode, "d" ) = 0 Then
strOutput = Left(strInput, Len(strInput) - 4)
bytes = readStr(strInput)
data = decodeBase64(bytes)
writeBytes strOutput, data
End If
End If
End Sub
function readBytes(file)
dim inStream
' ADODB stream object used
set inStream = WScript.CreateObject("ADODB.Stream")
' open with no arguments makes the stream an empty container
inStream.Open
inStream.type= TypeBinary
inStream.LoadFromFile(file)
readBytes = inStream.Read()
end function
function encodeBase64(bytes)
dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.createElement("tmp")
EL.DataType = "bin.base64"
' Set bytes, get encoded String
EL.NodeTypedValue = bytes
encodeBase64 = EL.Text
end function
function decodeBase64(base64)
dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.createElement("tmp")
EL.DataType = "bin.base64"
' Set encoded String, get bytes
EL.Text = base64
decodeBase64 = EL.NodeTypedValue
end function
Sub writeBytes(file, bytes)
Dim binaryStream
Set binaryStream = CreateObject("ADODB.Stream")
binaryStream.Type = TypeBinary
'Open the stream and write binary data
binaryStream.Open
binaryStream.Write bytes
'Save binary data to disk
binaryStream.SaveToFile file, ForWriting
End Sub
Sub writeStr(file, str)
dim objFSO, objFile
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(file,True)
objFile.Write str
objFile.Close
End Sub
function readStr(file)
dim objFSO, objFile
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(file, 1)
readStr = objFile.ReadAll
End function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment