Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.IO
- Imports System.Text
- Imports System.Windows.Forms
- Public Class Tools
- Dim DebugToggle As Boolean = False
- Public Sub Debug(ByVal bool As Boolean)
- If bool = True Then
- DebugToggle = True
- Else
- DebugToggle = False
- End If
- End Sub
- Public Function RandomString(ByVal StringLength As Integer, Optional ByVal CustomCharacters As String = "", Optional ByVal Letters As Boolean = True, Optional ByVal Numbers As Boolean = True, Optional ByVal Symbols As Boolean = False, Optional ByVal UpperCase As Boolean = True, Optional ByVal LowerCase As Boolean = True) As String
- Try
- 'RandomString Function by sim0n @ sim0n.wordpress.com
- Dim randomG As New Random
- Dim randomN As Integer
- Const pwChars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- Const pwNumbers As String = "0123456789"
- Const pwSymbols As String = "`¬!""£$%^&*()_)+-=[]{};':@#~/?.>,<|"""
- Dim str As String = ""
- While str.Length < StringLength
- Dim pwcharList As String = ""
- If Letters = True Then pwcharList &= pwChars
- If Numbers = True Then pwcharList &= pwNumbers
- If Symbols = True Then pwcharList &= pwSymbols
- pwcharList &= CustomCharacters
- randomN = randomG.Next(0, pwcharList.Length)
- If UpperCase = True And LowerCase = True Then
- Dim randomN2 = randomG.Next(0, 2)
- If randomN2 = 0 Then
- str &= Char.ToUpper(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
- Else
- str &= Char.ToLower(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
- End If
- ElseIf UpperCase = True Then
- str &= Char.ToUpper(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
- ElseIf LowerCase = True Then
- str &= Char.ToLower(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
- Else
- str &= pwcharList(randomN)
- End If
- End While
- Return str
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function HexToString(ByVal hex As String) As String
- Try
- Dim text As New System.Text.StringBuilder(hex.Length \ 2)
- For i As Integer = 0 To hex.Length - 2 Step 2
- text.Append(Chr(Convert.ToByte(hex.Substring(i, 2), 16)))
- Next
- Return text.ToString
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function StringToBinary(ByVal Text As String, Optional ByVal Separator As String = " ") As String
- Try
- Dim oReturn As New System.Text.StringBuilder
- For Each Character As Byte In System.Text.ASCIIEncoding.ASCII.GetBytes(Text)
- oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
- oReturn.Append(Separator)
- Next
- Return oReturn.ToString
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function BinaryToString(ByVal Binary As String) As String
- Try
- Dim Characters As String = System.Text.RegularExpressions.Regex.Replace(Binary, "[^01]", "")
- Dim ByteArray((Characters.Length / 8) - 1) As Byte
- For Index As Integer = 0 To ByteArray.Length - 1
- ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)
- Next
- Return System.Text.ASCIIEncoding.ASCII.GetString(ByteArray)
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function SendPOSTData(ByVal PostData As String, ByVal Site As String) As String
- Try
- Dim Request As HttpWebRequest = DirectCast(WebRequest.Create(Site), HttpWebRequest)
- Request.Method = "POST"
- Request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
- Request.ContentType = "application/x-www-form-urlencoded"
- Request.AllowAutoRedirect = True
- Request.ServicePoint.Expect100Continue = False
- Request.ContentLength = PostData.Length
- Using ReqStream As Stream = Request.GetRequestStream()
- Dim Encoding As New UTF8Encoding()
- Dim PostBytes As Byte() = Encoding.GetBytes(PostData)
- ReqStream.Write(PostBytes, 0, PostBytes.Length)
- End Using
- Dim Result As String = String.Empty
- Using Response As HttpWebResponse = Request.GetResponse()
- Using RespStream As Stream = Response.GetResponseStream()
- Using Reader As New StreamReader(RespStream)
- Result = Reader.ReadToEnd()
- End Using
- End Using
- End Using
- Return Result
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function getDMYT()
- Try
- Dim output = Format(Date.Now, "[yyyy-MM-dd HH:mm:ss] ")
- Return output
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function StringToBase64(ByVal text As String)
- Try
- Dim data As Byte() = System.Text.Encoding.UTF8.GetBytes(text)
- Return System.Convert.ToBase64String(data)
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function Base64ToString(ByRef base64 As String)
- Try
- Dim data As String = New ASCIIEncoding().GetString(Convert.FromBase64String(base64))
- Return data
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Function HostToIP(ByVal Host As String) As String
- Try
- Return System.Net.Dns.GetHostAddresses(Host)(0).ToString()
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message, "Error")
- End If
- Return Nothing
- End Try
- End Function
- Public Sub PastebinUpdate(ByVal PasteID As String, ByVal Version As String, Optional ByVal SplitChar As String = "-")
- Try
- Dim wc As New WebClient
- Dim tmp As String = wc.DownloadString("http://pastebin.com/raw.php?i=" & PasteID)
- Dim data() As String = tmp.Split(SplitChar)
- If Not data(0) = Version Then
- Dim r As Integer = MessageBox.Show("There is an update available!" & vbCrLf & vbCrLf & "Download now?", "Updater", MessageBoxButtons.YesNo)
- If r = DialogResult.Yes Then
- Process.Start(data(1))
- End If
- End If
- Catch ex As Exception
- If DebugToggle = True Then
- MessageBox.Show(ex.Message)
- End If
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment