Guest User

RainbowUtility Source

a guest
Sep 22nd, 2014
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.11 KB | None | 0 0
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Text
  4. Imports System.Windows.Forms
  5.  
  6. Public Class Tools
  7.     Dim DebugToggle As Boolean = False
  8.  
  9.     Public Sub Debug(ByVal bool As Boolean)
  10.         If bool = True Then
  11.             DebugToggle = True
  12.         Else
  13.             DebugToggle = False
  14.         End If
  15.     End Sub
  16.  
  17.     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
  18.         Try
  19.             'RandomString Function by sim0n @ sim0n.wordpress.com
  20.             Dim randomG As New Random
  21.             Dim randomN As Integer
  22.             Const pwChars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  23.             Const pwNumbers As String = "0123456789"
  24.             Const pwSymbols As String = "`¬!""£$%^&*()_)+-=[]{};':@#~/?.>,<|"""
  25.             Dim str As String = ""
  26.             While str.Length < StringLength
  27.                 Dim pwcharList As String = ""
  28.                 If Letters = True Then pwcharList &= pwChars
  29.                 If Numbers = True Then pwcharList &= pwNumbers
  30.                 If Symbols = True Then pwcharList &= pwSymbols
  31.                 pwcharList &= CustomCharacters
  32.                 randomN = randomG.Next(0, pwcharList.Length)
  33.                 If UpperCase = True And LowerCase = True Then
  34.                     Dim randomN2 = randomG.Next(0, 2)
  35.                     If randomN2 = 0 Then
  36.                         str &= Char.ToUpper(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
  37.                     Else
  38.                         str &= Char.ToLower(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
  39.                     End If
  40.                 ElseIf UpperCase = True Then
  41.                     str &= Char.ToUpper(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
  42.                 ElseIf LowerCase = True Then
  43.                     str &= Char.ToLower(pwcharList(randomN), System.Globalization.CultureInfo.CurrentCulture)
  44.                 Else
  45.                     str &= pwcharList(randomN)
  46.                 End If
  47.             End While
  48.             Return str
  49.         Catch ex As Exception
  50.             If DebugToggle = True Then
  51.                 MessageBox.Show(ex.Message, "Error")
  52.             End If
  53.             Return Nothing
  54.         End Try
  55.     End Function
  56.  
  57.     Public Function HexToString(ByVal hex As String) As String
  58.         Try
  59.             Dim text As New System.Text.StringBuilder(hex.Length \ 2)
  60.             For i As Integer = 0 To hex.Length - 2 Step 2
  61.                 text.Append(Chr(Convert.ToByte(hex.Substring(i, 2), 16)))
  62.             Next
  63.             Return text.ToString
  64.         Catch ex As Exception
  65.             If DebugToggle = True Then
  66.                 MessageBox.Show(ex.Message, "Error")
  67.             End If
  68.             Return Nothing
  69.         End Try
  70.     End Function
  71.  
  72.     Public Function StringToBinary(ByVal Text As String, Optional ByVal Separator As String = " ") As String
  73.         Try
  74.             Dim oReturn As New System.Text.StringBuilder
  75.             For Each Character As Byte In System.Text.ASCIIEncoding.ASCII.GetBytes(Text)
  76.                 oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
  77.                 oReturn.Append(Separator)
  78.             Next
  79.             Return oReturn.ToString
  80.         Catch ex As Exception
  81.             If DebugToggle = True Then
  82.                 MessageBox.Show(ex.Message, "Error")
  83.             End If
  84.             Return Nothing
  85.         End Try
  86.     End Function
  87.  
  88.     Public Function BinaryToString(ByVal Binary As String) As String
  89.         Try
  90.             Dim Characters As String = System.Text.RegularExpressions.Regex.Replace(Binary, "[^01]", "")
  91.             Dim ByteArray((Characters.Length / 8) - 1) As Byte
  92.             For Index As Integer = 0 To ByteArray.Length - 1
  93.                 ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)
  94.             Next
  95.             Return System.Text.ASCIIEncoding.ASCII.GetString(ByteArray)
  96.         Catch ex As Exception
  97.             If DebugToggle = True Then
  98.                 MessageBox.Show(ex.Message, "Error")
  99.             End If
  100.             Return Nothing
  101.         End Try
  102.     End Function
  103.  
  104.     Public Function SendPOSTData(ByVal PostData As String, ByVal Site As String) As String
  105.         Try
  106.             Dim Request As HttpWebRequest = DirectCast(WebRequest.Create(Site), HttpWebRequest)
  107.             Request.Method = "POST"
  108.             Request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
  109.             Request.ContentType = "application/x-www-form-urlencoded"
  110.             Request.AllowAutoRedirect = True
  111.             Request.ServicePoint.Expect100Continue = False
  112.             Request.ContentLength = PostData.Length
  113.             Using ReqStream As Stream = Request.GetRequestStream()
  114.                 Dim Encoding As New UTF8Encoding()
  115.                 Dim PostBytes As Byte() = Encoding.GetBytes(PostData)
  116.                 ReqStream.Write(PostBytes, 0, PostBytes.Length)
  117.             End Using
  118.             Dim Result As String = String.Empty
  119.             Using Response As HttpWebResponse = Request.GetResponse()
  120.                 Using RespStream As Stream = Response.GetResponseStream()
  121.                     Using Reader As New StreamReader(RespStream)
  122.                         Result = Reader.ReadToEnd()
  123.                     End Using
  124.                 End Using
  125.             End Using
  126.             Return Result
  127.         Catch ex As Exception
  128.             If DebugToggle = True Then
  129.                 MessageBox.Show(ex.Message, "Error")
  130.             End If
  131.             Return Nothing
  132.         End Try
  133.     End Function
  134.  
  135.     Public Function getDMYT()
  136.         Try
  137.             Dim output = Format(Date.Now, "[yyyy-MM-dd HH:mm:ss] ")
  138.             Return output
  139.         Catch ex As Exception
  140.             If DebugToggle = True Then
  141.                 MessageBox.Show(ex.Message, "Error")
  142.             End If
  143.             Return Nothing
  144.         End Try
  145.     End Function
  146.  
  147.     Public Function StringToBase64(ByVal text As String)
  148.         Try
  149.             Dim data As Byte() = System.Text.Encoding.UTF8.GetBytes(text)
  150.             Return System.Convert.ToBase64String(data)
  151.         Catch ex As Exception
  152.             If DebugToggle = True Then
  153.                 MessageBox.Show(ex.Message, "Error")
  154.             End If
  155.             Return Nothing
  156.         End Try
  157.     End Function
  158.  
  159.     Public Function Base64ToString(ByRef base64 As String)
  160.         Try
  161.             Dim data As String = New ASCIIEncoding().GetString(Convert.FromBase64String(base64))
  162.             Return data
  163.         Catch ex As Exception
  164.             If DebugToggle = True Then
  165.                 MessageBox.Show(ex.Message, "Error")
  166.             End If
  167.             Return Nothing
  168.         End Try
  169.     End Function
  170.  
  171.     Public Function HostToIP(ByVal Host As String) As String
  172.         Try
  173.             Return System.Net.Dns.GetHostAddresses(Host)(0).ToString()
  174.         Catch ex As Exception
  175.             If DebugToggle = True Then
  176.                 MessageBox.Show(ex.Message, "Error")
  177.             End If
  178.             Return Nothing
  179.         End Try
  180.     End Function
  181.  
  182.     Public Sub PastebinUpdate(ByVal PasteID As String, ByVal Version As String, Optional ByVal SplitChar As String = "-")
  183.         Try
  184.             Dim wc As New WebClient
  185.             Dim tmp As String = wc.DownloadString("http://pastebin.com/raw.php?i=" & PasteID)
  186.             Dim data() As String = tmp.Split(SplitChar)
  187.             If Not data(0) = Version Then
  188.                 Dim r As Integer = MessageBox.Show("There is an update available!" & vbCrLf & vbCrLf & "Download now?", "Updater", MessageBoxButtons.YesNo)
  189.                 If r = DialogResult.Yes Then
  190.                     Process.Start(data(1))
  191.                 End If
  192.             End If
  193.         Catch ex As Exception
  194.             If DebugToggle = True Then
  195.                 MessageBox.Show(ex.Message)
  196.             End If
  197.         End Try
  198.     End Sub
  199.  
  200. End Class
Advertisement
Add Comment
Please, Sign In to add comment