Created
November 15, 2009 21:19
-
-
Save antimatter15/235461 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wavehttp | |
import random | |
import time | |
import urllib | |
import Cookie | |
import json | |
#http://stackoverflow.com/questions/1694507/difference-between-operator-in-js-and-python/1694524#1694524 | |
def xor32bit(a, b): | |
m = (a ^ b) % (2**32) | |
if m > (2**16): | |
m -= 2**32 | |
return m | |
#Modified From: http://en.wikipedia.org/wiki/Base_36#Python%5FConversion%5FCode | |
def base36encode(number): | |
sign = "" | |
if not isinstance(number, (int, long)): | |
raise TypeError('number must be an integer') | |
if number < 0: | |
sign = "-" | |
number = abs(number) | |
#raise ValueError('number must be positive') | |
alphabet = '0123456789abcdefghijklmnopqrstuvwxyz' | |
base36 = '' | |
while number: | |
number, i = divmod(number, 36) | |
base36 = alphabet[i] + base36 | |
return sign+base36 | |
def zxgen(): | |
#THIS FUNCTION DOESNT ACTUALLY WORK | |
return base36encode(random.randint(0,2147483648)) + base36encode(xor32bit(random.randint(0,2147483648),int(time.time()*1000))) | |
#return base36encode(random.randint(0,2147483648)) + "-" + base36encode(random.randint(1000000000,9999999999)) | |
def ridgen(): | |
num = random.randint(1, 100000) | |
#print "RID",num | |
return num | |
def getsid(): | |
getparams = { | |
'VER': 6, | |
'RID': ridgen(), | |
'CVER': 3, | |
'zx': zxgen(), | |
't': 1 | |
} | |
r1 = wavehttp.post("/wave/wfe/channel?"+urllib.urlencode(getparams), "count=0") | |
#print "SID Value",r1.status, r1.reason, r1.version, r1.read() | |
data = parseresponse(r1.read()) | |
#print data | |
if data[0][0][1][0] != "c": | |
print "ERROR: Value not expected" | |
exit() | |
return data[0][0][1][1] | |
def search(sid, query): | |
rid = ridgen() | |
getparams = { | |
'VER': 6, | |
'RID': rid, | |
'CVER': 3, | |
'SID': sid, | |
'zx': zxgen(), | |
't': 1 | |
} | |
postparams = { | |
'count': 2, | |
'req0_key': '{"a":"Do2gQSaE","r":"53","t":2007,"p":{"1000":[0,0],"2":"Do2gQSaE5"}}', | |
'req1_key': '{"a":"Do2gQSaE","r":"54","t":2602,"p":{"1000":[0,0],"2":"Do2gQSaE6","3":"is:note","4":{"2":25,"1":0},"6":null}}' | |
} | |
#print sid | |
#print "PARAMS",urllib.urlencode(getparams) | |
#print "PARAMS",urllib.urlencode(postparams) | |
#print "Cookie",wavehttp.cookie | |
r1 = wavehttp.post("/wave/wfe/channel?"+urllib.urlencode(getparams), urllib.urlencode(postparams)) | |
text = r1.read() | |
#print "Search Response", r1.status, r1.reason, r1.version, text | |
if text != "4\ny2f%": | |
if "Unknown SID" in text: | |
print "FAILED (SID)"#, text | |
global magicsid | |
magicsid = getsid() | |
elif "not in valid window": | |
print "FAILED (RID)",rid#, text | |
else: | |
print "GENERIC UNKNOWN ERROR", text | |
else: | |
print "WORK",rid | |
return True | |
return False | |
#print "SET COOK",r1.getheader("Set-Cookie") | |
#https://wave.google.com/wave/wfe/channel?VER=6&SID=47307C2F1505FFF9&RID=52982&zx=g5m14c-e9ephq&t=1 | |
def getresponse(sid, aid=0): | |
getparams = { | |
'VER': 6, | |
'RID': 'rpc', | |
'SID': sid, | |
'AID': aid, | |
'CI': 1, | |
'TYPE': 'xmlhttp', | |
'zx': zxgen(), | |
't': 1 | |
} | |
r1 = wavehttp.get("/wave/wfe/channel?"+urllib.urlencode(getparams)) | |
text = r1.read() | |
print text | |
data = parseresponse(text) | |
return data | |
def testlogin(): | |
wavehttp.get("/wave/wfe/testLogin?t="+str(int(time.time()*1000))) | |
#cookie management code has moved to wavehttp.py so theres nothign to do | |
def test(): | |
getparams = { | |
'VER': 6, | |
'MODE': 'init', | |
'zx': zxgen(), | |
't': 1 | |
} | |
r1 = wavehttp.get("/wave/wfe/test?"+urllib.urlencode(getparams)) | |
return r1.read() | |
def parseresponse(string): | |
#wave has a freaky format for JSON | |
string = string.strip() | |
first = string.splitlines()[0] #TODO: Replace with sometthing else to just grab teh first line | |
data = string[len(first):len(first)+int(first)] | |
out = [json.loads(data.replace(",]","]"))] #Wave JSON has tons of random ,] which neeed to be murdered to be parsed | |
if len(first)+int(first) + 1 < len(string): | |
out += parseresponse(string[len(first)+int(first):]) | |
return out | |
#print parseresponse("""17 | |
#[[1,["noop"] | |
#] | |
#] | |
#17 | |
#[[2,["noop"] | |
#] | |
#] | |
#""") | |
magicsid = getsid() | |
testlogin() | |
#print magicsid | |
#print "TEST",test() | |
while search(magicsid, "is:note") is False: #try, try again. | |
pass | |
print getresponse(magicsid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment