VB.net question (frmMain is not declared)

Discussion in 'World of SPAM' started by Fexxel, Apr 18, 2009.

  1. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Using this wrapper:
    Code (Text):
    1.  
    2. Public Class TCPWrapper
    3.     Inherits System.Windows.Forms.UserControl
    4. #Region " Windows Form Designer generated code "
    5.     Public Sub New()
    6.         MyBase.New()
    7.         'This call is required by the Windows Form Designer.
    8.         InitializeComponent()
    9.         'Add any initialization after the InitializeComponent() call
    10.     End Sub
    11.     'UserControl overrides dispose to clean up the component list.
    12.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    13.         If disposing Then
    14.             If Not (components Is Nothing) Then
    15.                 components.Dispose()
    16.             End If
    17.         End If
    18.         MyBase.Dispose(disposing)
    19.     End Sub
    20.     'Required by the Windows Form Designer
    21.     Private components As System.ComponentModel.IContainer
    22.     'NOTE: The following procedure is required by the Windows Form Designer
    23.     'It can be modified using the Windows Form Designer.
    24.     'Do not modify it using the code editor.
    25.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    26.         components = New System.ComponentModel.Container
    27.     End Sub
    28. #End Region
    29.     Private colCookies As New Collection
    30.     Dim strCookies As String
    31.     Public LastPage As String
    32.     Public bGzip As Boolean
    33.     Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
    34.         Dim Host As String = Nothing
    35.         Dim strFile As String = Nothing
    36.         Dim strPost As String = Nothing
    37.         Dim pos As Integer = 0
    38.         If Referer Is Nothing Then
    39.             Referer = LastPage
    40.         End If
    41.         If URL.Contains("http://") Then
    42.             Host = URL.Substring(7)
    43.         Else
    44.             Host = URL
    45.         End If
    46.         If Host.Contains("/") Then
    47.             pos = Host.IndexOf("/", 0)
    48.             strFile = Host.Substring(pos)
    49.             Host = Host.Substring(0, pos)
    50.         Else
    51.             strFile = "/"
    52.         End If
    53.         If Method = "POST" Then
    54.             pos = strFile.IndexOf("?")
    55.             If Not (pos = -1) Then
    56.                 strPost = strFile.Substring(pos + 1)
    57.                 strFile = strFile.Substring(0, pos)
    58.             Else
    59.                 strPost = Nothing
    60.             End If
    61.         End If
    62.         LastPage = URL
    63.         Dim ReqHeaders As String = Nothing
    64.         If bGzip = True Then
    65.             If Method = "GET" OrElse Method = "PIC" Then
    66.                 ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
    67.             Else
    68.                 ReqHeaders = "POST " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: " + strPost.Length.ToString + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
    69.             End If
    70.             If Method = "PIC" Then
    71.                 ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
    72.             End If
    73.         Else
    74.             If Method = "GET" OrElse Method = "PIC" Then
    75.                 ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
    76.             Else
    77.                 ReqHeaders = "POST " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: " + strPost.Length.ToString + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
    78.             End If
    79.             If Method = "PIC" Then
    80.                 ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
    81.             End If
    82.         End If
    83.  
    84.         Dim tcp As New System.Net.Sockets.TcpClient
    85.         Dim netstream As System.Net.Sockets.NetworkStream
    86.         Dim TN(1) As Long
    87.         If Referer = "" Then Referer = LastPage
    88.         If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
    89.         If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
    90.         If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
    91.         If Mid$(Host, 1, 4) = "www." Then Host = Mid$(Host, 5)
    92.         LastPage = URL
    93.         Try
    94.             tcp.Connect(Host, 80)
    95.         Catch ex As Exception
    96.             Return ex.Message
    97.         End Try
    98.  
    99.         Dim sendbytes As Byte()
    100.         sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
    101.         netstream = tcp.GetStream()
    102.         netstream.Write(sendbytes, 0, sendbytes.Length)
    103.         Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
    104.         Dim strHTML As String = sr.ReadToEnd
    105.         Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
    106.         strCookies = ParseCookies(strParts(0))
    107.         If strParts(0).Contains("Content-Encoding") Then
    108.             strParts(1) = DecompressGzip(strParts(1))
    109.         End If
    110.         Dim uppBound As Integer = strParts.GetUpperBound(0)
    111.         Dim strReturn As String = ""
    112.         For i As Integer = 1 To uppBound
    113.             strReturn += strParts(i)
    114.         Next
    115.         If InStr(strReturn, "not logged in") Then
    116.             If frmMain.chkWarn.Checked = False Then
    117.                 frmMain.TimerAutobuy.Enabled = False
    118.                 frmMain.lblStatus.Text = "Logged out!"
    119.                 frmMain.GroupBox1.Enabled = True
    120.                 frmMain.cmdLogout.Enabled = False
    121.                 frmMain.cmdLogin.Enabled = True
    122.                 frmMain.cmdStop.Enabled = False
    123.                 frmMain.cmdStart.Enabled = True
    124.                 MsgBox("You have been logged out!", MsgBoxStyle.Critical, "Logged out!")
    125.                 ClearCookies()
    126.             Else
    127.                 frmMain.lblStatus.Text = "Logged out!"
    128.                 frmMain.TimerAutobuy.Enabled = False
    129.                 ClearCookies()
    130.                 Pause(5)
    131.                 frmMain.Login(frmMain.txtUsername.Text, frmMain.txtPassword.Text)
    132.                 Pause(5)
    133.                 frmMain.lblStatus.Text = "Looking for Items"
    134.                 frmMain.TimerAutobuy.Enabled = True
    135.                 frmMain.cmdStop.Enabled = True
    136.                 frmMain.cmdStart.Enabled = False
    137.             End If
    138.         End If
    139.         Return strReturn
    140.     End Function
    141.     Public Function DecompressGzip(ByVal compressed As String) As String
    142.         Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
    143.         Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
    144.         Dim endBytes(4) As Byte
    145.         Dim position As Integer = CType(memStream.Length, Integer) - 4
    146.         memStream.Position = position
    147.         memStream.Read(endBytes, 0, 4)
    148.         memStream.Position = 0
    149.         Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
    150.         Dim offset As Integer = 0
    151.         Dim total As Integer = 0
    152.         While True
    153.             Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
    154.             If bytesRead = 0 Then
    155.                 Exit While
    156.             End If
    157.             offset += bytesRead
    158.             total += bytesRead
    159.         End While
    160.         Return Encoding.ASCII.GetString(buffer)
    161.     End Function
    162.     Public Function ParseCookies(ByVal Headers As String) As String
    163.         ParseCookies = ""
    164.         Dim reg As Regex
    165.         Dim matches As MatchCollection
    166.         Dim match As Match
    167.         reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
    168.         If reg.IsMatch(Headers) Then
    169.             matches = reg.Matches(Headers)
    170.             For Each match In matches
    171.                 Try
    172.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    173.                 Catch ex As Exception
    174.                     colCookies.Remove(match.Groups(1).ToString)
    175.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    176.                 End Try
    177.             Next
    178.         End If
    179.         Dim i As Long
    180.         For i = 1 To colCookies.Count Step 1
    181.             ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
    182.         Next
    183.     End Function
    184.     Public Function StripHeaders(ByVal strSource As String) As String
    185.         Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine)
    186.         Return strParts(1)
    187.     End Function
    188.     Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    189.         ClearCookies()
    190.         Dim strHTML As String = Nothing
    191.         Request("GET", "http://neopets.com/loginpage.phtml", "http://google.com")
    192.         Pause(1)
    193.         Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Fpetcentral.phtml&username=" + user, "http://neopets.com/loginpage.phtml")
    194.         Pause(1)
    195.         Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Fpetcentral.phtml", "http://neopets.com/hi.phtml")
    196.         strHTML = Request("GET", "http://www.neopets.com/objects.phtml", "http://www.neopets.com/petcentral.phtml")
    197.         If strHTML.Contains("Welcome, ") Then
    198.             loggedIn = True
    199.             Return "Logged In"
    200.         Else
    201.             If strHTML.Contains("too many times") Then
    202.                 loggedIn = False
    203.                 Return "To Many Login Attempts"
    204.             Else
    205.                 If strHTML.Contains("not logged in") Then
    206.                     loggedIn = False
    207.                     Return "Wrong Password"
    208.                 Else
    209.                     If strHTML.Contains("frozen") Then
    210.                         loggedIn = False
    211.                         Return "Account Frozen"
    212.                     Else
    213.                         If strHTML.Contains("just a technical problem") Then
    214.                             loggedIn = False
    215.                             Return "Neopets is down for maintenance."
    216.                         Else
    217.                             loggedIn = False
    218.                             Return strHTML
    219.                         End If
    220.                     End If
    221.                 End If
    222.             End If
    223.         End If
    224.     End Function
    225.     Public Sub Pause(ByVal seconds As Double)
    226.         Dim num As Double = seconds * 1000
    227.         Dim t1 As DateTime = DateTime.Now
    228.         Dim t2 As DateTime = DateTime.Now
    229.         Dim tmDiff As TimeSpan = t2 - t1
    230.         While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
    231.             t2 = DateTime.Now
    232.             tmDiff = t2 - t1
    233.             Application.DoEvents()
    234.         End While
    235.     End Sub
    236.     Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
    237.         Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
    238.         GrabPic = Image.FromStream(memStream)
    239.         Return GrabPic
    240.     End Function
    241.     Public Function DownloadImage(ByVal URL As String) As System.Drawing.Image
    242.         Dim imageFile As New WebClient
    243.         Dim bytes() As Byte = imageFile.DownloadData(URL)
    244.  
    245.         Dim imageStream As New MemoryStream(bytes)
    246.         Dim downloadedImage As System.Drawing.Image = Image.FromStream(imageStream)
    247.  
    248.         DownloadImage = downloadedImage
    249.     End Function
    250.     Public Sub ClearCookies()
    251.         colCookies.Clear()
    252.         strCookies = Nothing
    253.     End Sub
    254.  
    255.     Public Function GetCookie()
    256.         Return strCookies
    257.     End Function
    258. End Class
    259.  
    It says that frmMain is not declared. Any suggestions to fix?
    PS: This is in the spam section because this is a quick question, and I want to have the excuse of being tired. xD
     
  2. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Just remove
    Code (Text):
    1.         If InStr(strReturn, "not logged in") Then
    2.             If frmMain.chkWarn.Checked = False Then
    3.                 frmMain.TimerAutobuy.Enabled = False
    4.                 frmMain.lblStatus.Text = "Logged out!"
    5.                 frmMain.GroupBox1.Enabled = True
    6.                 frmMain.cmdLogout.Enabled = False
    7.                 frmMain.cmdLogin.Enabled = True
    8.                 frmMain.cmdStop.Enabled = False
    9.                 frmMain.cmdStart.Enabled = True
    10.                 MsgBox("You have been logged out!", MsgBoxStyle.Critical, "Logged out!")
    11.                 ClearCookies()
    12.             Else
    13.                 frmMain.lblStatus.Text = "Logged out!"
    14.                 frmMain.TimerAutobuy.Enabled = False
    15.                 ClearCookies()
    16.                 Pause(5)
    17.                 frmMain.Login(frmMain.txtUsername.Text, frmMain.txtPassword.Text)
    18.                 Pause(5)
    19.                 frmMain.lblStatus.Text = "Looking for Items"
    20.                 frmMain.TimerAutobuy.Enabled = True
    21.                 frmMain.cmdStop.Enabled = True
    22.                 frmMain.cmdStart.Enabled = False
    23.             End If
    24.         End If
    this part ^

    It was put by expon to check if the account was still logged in.
     
  3. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Oh.. That's how you do it... xD I thought it'd mess up things.
    Could I just do that for everything in the wrapper?
    xD
    Thanks!!!