Hyperz.. I need your help.

Status
Not open for further replies.

R4Z0R3

Active Member
27
2010
0
0
Ok Hyperz... I've been trying to use your source to Sharp Leech and all is well, and I must say you are a brilliant coder.

However I am not trying to use your script for my personal use. I am simply using your script as a reference to what I want to do. Basically what I want to do is create a Forum Leecher like yours. I have designed a layout that I am Satisfied with and am now ready to begin coding.

For my login area, I have a spot to select what forum, to enter username, and enter password, and a button t click that logs you in.

I have a small dilemma, This is my code that I have so far:

PHP:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Net.Configuration;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Web;
using HtmlAgilityPack;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void login_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                Thread.Sleep(5000); //Hangs the Cursor for a while
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
            #region Login Information
            {
                const string username = @"";
                const string password = @"";
                const string md5 = @"";

                CookieContainer cookieMonster = new CookieContainer();
                string postArgs = String.Format(
                    @"raw_login_password={0}&do=login&url=%2Fforum%2Fusercp.php&vb_login_md5password={2}&vb_login_md5password_utf={2}&s=&securitytoken=guest&vb_login_username={1}&vb_login_password=",
                        password,
                        username,
                       md5
                        );

                WebRequest req = (WebRequest)WebRequest.Create("forumpath" + "login.php");
                req.Method = "POST";
                req.CookieContainer = cookieMonster;
                req.Referrer = @"forumpath" + "login.php";
                req.ContentType = @"application/x-www-form-urlencoded";
                byte[] buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(postArgs);
                req.ContentLength = buffer.Length;
                req.AllowAutoRedirect = true;
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(buffer, 0, buffer.Length);
                    reqStream.Close();
                }
                WebResponse response = (WebResponse)req.GetResponse();
                using (Stream respStream = response.GetResponseStream()) ;
                {
                    using (StreamReader sr = new StreamReader(respStream))
                    {
                        string s = sr.ReadToEnd();
                        System.Diagnostics.Debugger.Break();
                    }
                }
            #endregion
            }
        }
    }
}

Visual Studio 2010 is telling me that there is no such thing as System.Net.WebRequest.CookieContainer

The code am having trouble with is this section:

PHP:
WebRequest req = (WebRequest)WebRequest.Create("forumpath" + "login.php");
                req.Method = "POST";
                req.CookieContainer = cookieMonster;
                req.Referrer = @"forumpath" + "login.php";
                req.ContentType = @"application/x-www-form-urlencoded";
                byte[] buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(postArgs);
                req.ContentLength = buffer.Length;
                req.AllowAutoRedirect = true;
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(buffer, 0, buffer.Length);
                    reqStream.Close();
                }

I was wondering if you could shed a little of you knowledge on to me....

Thanks.
 
8 comments
Change WebRequest to HttpWebRuest (same for WebResponse, cast that to HttpWebResponse). I should also add that the SL1 beta source code isn't a good reference. It can get you a working leecher but that's about it. You could call it throw away code :).

Why not use Hyperz.SharpLeech.Engine.dll that comes with SL2? It has everything you need to build a leecher (and more).

Lastly, your function looks a bit odd.
PHP:
        private void login_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            // Why let the user wait longer than needed lol
            // Thread.Sleep(5000); //Hangs the Cursor for a while
            
            #region Login Information
            string username = "";
            string password = "";
            string md5 = "";

            CookieContainer cookieMonster = new CookieContainer();
            string postArgs = String.Format(
                "raw_login_password={0}&do=login&url=%2Fforum%2Fusercp.php&" +
                "vb_login_md5password={2}&vb_login_md5password_utf={2}&" +
                "s=&securitytoken=guest&vb_login_username={1}&vb_login_password=",
                password,
                username,
                md5
            );
            byte[] buffer = System.Text.UTF8.GetBytes(postArgs);
            
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("forumpath" + "login.php");
            req.Method = "POST";
            req.CookieContainer = cookieMonster;
            req.Referrer = "forumpath" + "login.php";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = buffer.Length;
            req.AllowAutoRedirect = false; // dont turn it on, you'll loose cookies
            
            try
            {
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(buffer, 0, buffer.Length);
                    reqStream.Close();
                }
                
                HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                
                using (Stream respStream = response.GetResponseStream())
                using (StreamReader sr = new StreamReader(respStream))
                {
                    string s = sr.ReadToEnd();
                    System.Diagnostics.Debugger.Break();
                }
            }
            catch { /* ... */ }
            #endregion
            
            Cursor.Current = Cursors.Default;
        }
Or if you use the SL2 engine you can replace all that low-level crap with:
PHP:
        private void login_Click(object sender, EventArgs e)
        {
            var username = "username";
            var password = "password";
            var forum = DefaultSiteTypes.ByName("vBulletin 3.x.x").CreateInstance();

            // Site url
            forum.BaseUrl = "http://yoursite.com/forum_path";
            // Attach event handler
            forum.Login += (_sender, _e) =>
            {
                if (_e.LoggedIn)
                {
                    // Yay it worked
                }
                else
                {
                    // fail :(
                }
            };

            // Login
            forum.LoginUser(username, password);
        }
 
The past few months ive been Learning C# and im proud to say i fully understand the above namespace,class,methods etc :D i would not have used the namespace WindowsFormsApplication1 but sopmething like LeacherCore :D

Thought i would say..
 
First off... The Captcha told me to type : asses $2.1. :D

Second... I don't believe I have the SL2 source. I couldn't find a download link... Would you be so kind as to share me the link? <3

Thirdly, Does the SL2 SC come with the IRC chat code? Because I sorta developed my own and Its a bit rough in my opinion.

Ok. So the code you gave me for the SL2.DLL, I would need to add an assembly reference for the DLL right?

You'll have to forgive me. Im relatively new to C# and I spent all day making the code above.
 
If you're new to C# building a leecher is a bit of an impossible task. It ain't rocket science but it isn't an easy task for a beginner either.

There is no public SL2 source out atm. You can download the SharpLeech 2 ALPHA and use the dll that comes with it. Just add a reference to it in your project and add the namespaces:
Code:
using Hyperz.SharpLeech.Engine;
using Hyperz.SharpLeech.Engine.Html;
using Hyperz.SharpLeech.Engine.Net;
using Hyperz.SharpLeech.Engine.Irc;
// etc...
However don't count on me to provide you support on how to use the classes etc in the dll. Once you understand C# and .NET well enough you should be able to figure it out ;). The IRC and HTML DOM parser libraries in the dll are 3rd party open source projects though.
 
I am already learning. I've learned everything in the first post in a matter of hours, its only perfecting it that is difficult for me. As for learning C# I am doing quite well in my opinion.

Oh, P.S. - Ill have an Logo for SharpLeech by the end of Tonight (EST).

Also, When you created this Program the first build kit, did you use VS8 or VS10? Because I have to convert the original sources.

(Also, I learn very fast, EX. I learned PHP,Ajax,Javascript,HTML,and VB in 2 weeks...)

But thanks for you help Hyperz

_____________________________edit_____________________

oh yea... I've used your DLL from SL(Alpha) and in VS2010, sometimes it tells me that the reference could not be found, but I have it in .resx file and in the References... But Ill figure it out in a second.

Again, thanks for your Help! <3


edit (lol)

one more thing...

In SL 2.0.0Alpha you have the outside border transparent, and buttons in that space... I have to ask you how you did this.

I have a few theories.

1. You change the Transparency Key to BG color of SL, and then Added a BG image.
2. Some other code in the SL.Designer.cs file
 
Oh yea I remember having to install the .NET 4.0 Framework for SL2.0.

Please re-read the post above. I edited it with some more stuff...

I'm sorry if I'm bugging you with tones of questions. :S
 
While using this function:

CreateInstance();

I get the following Error:

; expected, even though there is one there.

-_-

oh nvm I got it.
 
Status
Not open for further replies.
Back
Top