I'll be posting back when I've worked the regular expression into the code, not sure this is going to work though as I think the actual link is obtained through AJAX. I'm still playing with this.
AJAX concerns discussed: StackOverflow related question
Based on the php code provided in the comments:
- 1st Response->fetch the value passed
to a function called
"cG(var1,var2,var3)" I don't think
mediafire still uses that function,
it seems it's called
"cu(var1,var2,var3)" now, not sure if
the php you gave will still work.
anyway, we can do the same thing get
the values from the cu function &
post our request to
http://www.mediafire.com/dynamic/download.php?
with the cookie we retrieved from our
first response.
- The 2nd response creates this huge
list of random generated variables,
then generates the download url
concatenating some of those
variables, the only way to get the
url out if this is by using the
Microsoft.JScript engine to evaluate
this code. I'll be posting my
code asap
Code (warning this code is ugly & needs to be cleaned up):
string sURL = "http://www.mediafire.com/?syzjuytmdkn";
HttpWebRequest wrGETURL = (HttpWebRequest)WebRequest.Create(sURL);
wrGETURL.CookieContainer = new CookieContainer();
wrGETURL.Referer = "http://www.mediafire.com";
wrGETURL.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
HttpWebResponse wrResponse = (HttpWebResponse)wrGETURL.GetResponse();
CookieCollection cookies = wrResponse.Cookies;
Here we send the first request & Store the cookies received. Next we want to parse the page to find out the keys for the 2nd request:
StreamReader objReader = new StreamReader(wrResponse.GetResponseStream());
string[] parameters = {};//will contain the parameters fetched
string html = objReader.ReadToEnd();
int cupos1 = html.IndexOf("cu(");
int cupos2 = html.IndexOf("')",cupos1);
string[] separators = { "','"};
parameters = html.Substring(cupos1 + 4, cupos2 - cupos1 - 4)
.Split(separators, StringSplitOptions.None);
Fetch the 2nd page which will contain the encoded download url:
string sURL2 = String.Format("http://www.mediafire.com/dynamic/download.php?qk={0}&pk={1}&r={2}",
parameters[0],parameters[1],parameters[2]);
HttpWebRequest wrGETURL2 = (HttpWebRequest)WebRequest.Create(sURL2);
wrGETURL2.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
wrGETURL2.Referer = "http://www.mediafire.com";
wrGETURL2.CookieContainer = new CookieContainer();
wrGETURL2.CookieContainer.Add(cookies);
wrResponse = (HttpWebResponse)wrGETURL2.GetResponse();
objReader = new StreamReader(wrResponse.GetResponseStream());
html = objReader.ReadToEnd();
This html contains the Javascript that will generate the download url, here we extract it, then evaluate it & finaly write it to the console:
int varpos1 = html.IndexOf("<script language=\"Javascript\">")+35;
//The variables are declared just before the 'function'
int varpos2 = html.IndexOf("function",varpos1);
string vardata = html.Substring(varpos1, varpos2 - varpos1);
int hrefpos1 = html.IndexOf("href=\\\"http://", varpos2)+6 ;
int hrefpos2 = html.IndexOf(">", hrefpos1);
string hrefdata = String.Format("var url = {0};", html.Substring(hrefpos1, hrefpos2 - hrefpos1-5));
object Result = EvalJScript(vardata + "\n" + hrefdata);
Console.WriteLine(Result.ToString());
This stuff worked for me, but needs to be rewritten, I also leave the EvalJScript function for you to work as the one I'm using (from Evaluating JScript in c#) is deprecated