Bqyahoo
What are you doing for us?
In essence, Bqyahoo just replaced some things you have made in other ways. For example, instead of logging in the mailbox, instead of downloading attachments. Then let's take a look, there is no help of bqyahoo, how should we do these things.
Step 1: Let's first come to the mail to log in to the web, enter your own username and password, and finally click Login.
Step 2: Enter the mailbox, but did not enter the inbox. At this time, you can't see the email, you can't download the attachment, you have to click the link to the inbox.
Step 3: Enter the inbox, this time you see the email, if you want to download the attachment, then you need to enter a specific message, then click the related link download attachment. However, for Bqyahoo, everything is over. Now this eate, even the procedure should pay attention to intelligence, in fact, the source code of the inbox page has already told you more information. Bqyahoo analyzes this information and eventually calculates the download address of the attachment.
Next, explain how to explain how to log in and download attachments in Bqyahoo.
Choose a handful sword
When writing Bqyahoo, I always have exhaust a machine at the choice of class library. Sometimes there will be contradictory situations, if you use the A class library, then you can use the B library at the same time. In general, you should choose the class library provided by a company as much as possible, such as Microsoft.
In the process of logging in to email and download attachments, you have to use the HTTP library, because the interaction of Yahoo China Server is built on the HTTP protocol. Of course, you can also use Windows Sockets to encapsulate your own http library, don't think I am joking, I am doing this, I will do this (later in the article will mention why I do this).
There are currently a variety of HTTP libraries to choose from, and only the function libraries provided by Microsoft have the following four:
l MFC HTTP
l ATL Server HTTP
l Windows HTTP
l Windows Internet
The last type is used in Bqyahoo: Windows Internet. It is the lowest package in these function libraries, but I feel that the extra information is mostly used, and the additional information you need is very small. About the details of the Windows Internet Library, please read the MSDN, here only introduce the functions used in the source code and their related knowledge.
In order to use the Windows Internet Library, you must use the header file wininet.h and library file Wininet.LIB in the program.
In fact, in bqyahoo, a total of three functions in this library:
l Internetopen
l Internetopenurl
l InternetReadFile
how about it? Do you feel very refreshing?
/// This can be briefly introduced to the usage of the above three functions, depending on the situation. /
Alibaba, open the door
If I tell you, don't enter the username and password in IE, just calculate a URL according to the username, password, and other information on the login page, then enter the address bar of IE, you can log in to Yahoo Mail normally, you Do you feel possible?
In fact, you can try it, first enter the username and password (deliberately enter the wrong message), then click Login, Finally, you will see a string of very long URLs on the address bar. If you enter the correct username and password, you can't see this URL because IE will automatically jump to the mailbox, then you see is the URL of the mailbox. The source code of the web page can be obtained by the following source code.
Bool WebClient :: BeForelogin () // Enter the landing page
{
HSession = :: Internetopen ("BIQIONG", Internet_Open_Type_Preconfig, NULL, NULL, NULL;
Hconnect = :: Internetopenurl (hsession, beforloginurl.c_str (), null, null, connect_flag, null;
GetResponse ();
GetHead ();
Xlog.log ("Enter Land"); // Record Day Information
Xlog.log (HEAD);
Xlog.log (response);
IF (TestResponse () == false) Return False;
IF (strs, "showfolder? rb = inbox")! = null) Maybein = true; // Currently login success
Return True;
}
How is the key to the problem now how to calculate this URL? How does it generate? What information do you need?
At the time of login, Yahoo China will use the MD5 encrypted username and password. Ciphertext will verify on the server side and finalize your identity. The following Yahoo China's web source code may give you some revelations (... ... indicated to delete).
/ *
* A JavaScript Implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, As Defined IN RFC 1321.
* CopyRight (c) Paul
Johnston
1999 - 2000.
* Updated by Greg Holt 2000 - 2001.
* See http://pajhome.org.uk/site/legal.html for details.
* /
Var HEX_C
HR
= "0123456789Abcdef";
Function Rhex (NUM)
{
Str = "";
For (j = 0; j <= 3; J )
STR = HEX_C
HR
.charat ((NUM >> (J * 8 4)) & 0x
0F
)
HEX_C
HR
.charat ((NUM >> (J * 8)) & 0x
0F
);
Return Str;
}
Function STR2BLKS_MD5 (STR)
{
NBLK = (Str.Length 8) >> 6) 1;
BLKS = New Array (NBLK * 16);
For (i = 0; i For (i = 0; i BLKS [I >> 2] | = Str.Charcodeat (i) << (i% 4) * 8); BLKS [I >> 2] | = 0x80 << ((i% 4) * 8); BLKS [NBLK * 16 - 2] = Str.Length * 8; Return BLKS; } Function add (x, y) { VAR LSW = (X & 0xFFFF) (Y & 0xFFF); VAR MSW = (x >> 16) (Y >> 16) (LSW >> 16); Return (MSW << 16) | (LSW & 0xFFF); } Function ROL (NUM, CNT) { Return (NUM << CNT) | (NUM >>> (32 - CNT)); } ... ... Function II (A, B, C, D, X, S, T) { RETURN CMN (C ^ (B | (~ D)), A, B, X, S, T); } FUNCTION MD5 (STR) { X = STR2BLKS_MD5 (STR); VAR A = 1732584193; VAR b = -271733879; VAR C = -1732584194; VAR D = 271733878; For (i = 0; i { VAR OLDA = a; VAR oldb = b; VAR OLDC = C; VAR Oldd = D; A = FF (A, B, C, D, X [i 0], 7, -680876936); ... ... B = II (B, C, D, A, X [i 9], 21, -343485551); A = Add (a, OLDA); B = add (b, oldb); C = add (c, oldc); D = Add (d, oldd); } RETURN RHEX (A) RHEX (B) Rhex (C) Rhex (D); } Function hash (form, login_url) { Var URL; IF (Arguments.Length> 1 && login_url! = ") {// in case login_url is not passed in URL = Login_URL; } else { URL = "http://edit.bjs.yahoo.com/config/login"; } URL = "?"; IF (Navigator.USERAGENT.INDEXOF ("Mozilla / 4") == 0) { Var Passwd = form.passwd.value; Var Hash1 = MD5 (Form.Passwd.Value); VAR challenge = form [". challenge"]. value; Var hash2 = md5 (form.passwd.value) challenge; Var hash; IF (Form.Passwd.Value) { Hash = md5 (haveh2); } else { Hash = ""; VAR JS = 0; For (i = 0; I IF (form.e] .name.Length <= 0) { CONTINUE; } IF (i> 0) { URL = "&"; } URL = form.elements [i] .name; URL = "="; IF (form.e] .Name == "passwd") { URL = Hash; } else if (form.elements [i] .type == "Checkbox" &&! form.eferences [i] .checked) { URL = "" } else if (form.elements [i] .name == ".save") { URL = "1"; } else if (form.elements [i] .Name == ".js") { JS = 1; URL = "1"; } else { URL = Escape (form.elements [i] .value); } } URL = "& .hash = 1"; IF (js == 0) { URL = "& .js = 1"; } URL = "& .md5 = 1"; Location. HR EF = URL; Form.οnsubmit = null; Return False; } Return True; } script> Yahoo China uses JavaScript to implement MD5 encryption, and what we have to do is to implement the above process in the program and produce the same result. /// This can be given a brief introduction to MD5 encryption, depending on the situation. / In the calculated process, we need to know the username and password, but also need to know the challenge value on the current web page. Every time you open the login page, this value has random changes, which is also a safe guarantee. The following code can tell you the role of this value. VAR challenge = form [". challenge"]. value; Var hash2 = md5 (form.passwd.value) challenge; The following code calculates the login URL with C . Const char * cgliu :: getLoginURL () { // The following code calculates the URL from the open source project YPOPS! // The following MD5 encryption completely reproduces the encryption process on the Yahoo China webpage Char Hash [256]; MD5_CTX CTX; MD5_INIT (& CTX); MD5_UPDATE (& CTX, Password, Strlen (Password); MD5_Final (ReinterPret_cast Hash [0] = '/ 0'; RHEX (CTX.a, Data); STRCAT (HASH, DATA); RHEX (CTX.B, DATA); STRCAT (HASH, DATA); RHEX (CTX.c, DATA); STRCAT (HASH, DATA); RHEX (CTX.D, DATA); STRCAT (HASH, DATA); Strcat (hash, challengetext); MD5_INIT (& CTX); MD5_UPDATE (& CTX, Hash, Strlen (Hash); MD5_Final (ReinterPret_cast Hash [0] = '/ 0'; RHEX (CTX.a, Data); STRCAT (HASH, DATA); RHEX (CTX.B, DATA); STRCAT (HASH, DATA); RHEX (CTX.c, DATA); STRCAT (HASH, DATA); RHEX (CTX.D, DATA); STRCAT (HASH, DATA); Sprintf (data, "% s? login =% s & passwd =% s & .save = 1 & .Intl = cn & .src = ym & .challenge =% s & .hash = 1 & .js = 1 & .md5 = 1", http_login, user, Hash, challengetext); STRCPY (LoginURL, DATA); Return (const char *) loginurl; } Inline void rhex (unsigned int number) { CSTDSTRING HEX_C HR = "0123456789Abcdef"; CSTDSTRING STR; For (int J = 0; j <= 3; j ) { STR = HEX_C HR [(NUM >> (J * 8 4)) & 0x 0F ]; STR = HEX_C HR [(NUM >> (J * 8)) & 0x 0F ]; } STRCPY (DATA, STR); } Function getLoginURL () Returns the login URL and we can log in to Yahoo Mail. Tuning On the above, we mention that if you enter the correct username and password, IE will automatically jump to the mailbox. The same is true in the program, when we send the correct login website to the Yahoo Chinese server, then we will accept the web content after entering the mailbox. So far, we finally log in successfully and entered the mailbox. The next thing to do is to enter the inbox. Bool WebClient :: IninBox (const string mailhosturl) { String Inboxurl; INBOXURL = MailhostURL "YM / ShowFolder? RB = Inbox & Box = Inbox"; Hconnect = :: Internetopenurl (HSession, Inboxurl.c_STR (), NULL, NULL, CONNECT_FLAG, NULL; GetResponse (); GetHead (); Xlog.log ("Enter Inbox"); // Record Day Information Xlog.log (HEAD); Xlog.log (response); IF (TestResponse () == false) Return False; Return True; } destination The inbox is our destination. To this page, Bqyahoo can get all the information you need through web page analysis, and finally get all the download URLs of all email attachments. Next is the download attachment. Bool WebClient :: Download Filesavename (String Downloadurl) { // All downloads, eventually executed by the following code. // Although it is simple and vulgar, it is very practical. Const unsigned long cachesize = 100 * 1024; // block download, each 100K Hinternet Hfile; Char cache [cachesize]; Unsigned long byteofread = cachesize; File * fdest; FDEST = FOPEN (filesavename.c_str (), "wb"); Hfile = :: Internetopenurl (HSession, Downloadurl.c_STR (), NULL, NULL, NULL, NULL); While (:: InternetReadfile (Hfile, Cache, Cachesize, & Byteofread) == True) { FWRITE (Cache, Sizeof (Char), ByteOfread, FDEST); IF (ByteOfread == 0) Break; } Fclose (fdest); Return True; } I spent a lot of energy in downloading this place. I have always wanted to achieve and have never achieved the goal: multithreaded download. I am not interested in blocking a file and then using multithreaded downloads. Because the contents of each attachment of Bqyahoo is not much, you can't exceed 10m And Yahoo China's network speed is not bad, there is no need to do this. I look forward to a long time for downloading multiple files while using multithreading. I tried various multi-thread libraries and HTTP libraries, even with Windows Sockets to encapsulate a self-HTTP library, but this seems to have no effect. Whenever I launched a request at the same time, only one request will get a reply, while other requests can wait. From the perspective of the thread, there is indeed multi-thread in that time. That is to say, even if you use multithreaded, the file is still a downloaded one after another. And use multithreading will bring unstable, and the thread behind it is often "no end", and there is no download. to sum up In general, Bqyahoo is equivalent to a "IE" that is extremely simple. In the interaction of the Yahoo China server, we just do two things: get web pages and get files. In the entire login process, the difficulty is to calculate the login website. If you are familiar with JavaScript, it is not so difficult, and the most is a scoop. In fact, in this article, there are many key content I have not said, for example, how to get Challenge. I have left the next article to explain this article because they are all about web pages.