jingobd

Google Play DOWNLOADER PERL SCRIPT. jingobd.blogspot.com

Dec 15th, 2012
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.62 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. # This file is part of GooglePlay Downloader.
  4. #
  5. # Copyright(c) 2012-2013 Simone Margaritelli aka evilsocket
  6. # http://www.evilsocket.net
  7. #
  8. # This file may be licensed under the terms of of the
  9. # GNU General Public License Version 2 (the ``GPL'').
  10. #
  11. # Software distributed under the License is distributed
  12. # on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
  13. # express or implied. See the GPL for the specific language
  14. # governing rights and limitations.
  15. #
  16. # You should have received a copy of the GPL along with this
  17. # program. If not, go to http://www.gnu.org/licenses/gpl.html
  18. # or write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. import httplib, urllib, base64, zlib, re, optparse
  21.  
  22. class Market:
  23. LOGIN_HOST = "www.google.com"
  24. LOGIN_PAGE = "/accounts/ClientLogin"
  25. LOGIN_SERVICE = "androidsecure"
  26. LOGIN_TYPE = "HOSTED_OR_GOOGLE"
  27. API_HOST = "android.clients.google.com"
  28. API_PAGE = "/market/api/ApiRequest"
  29.  
  30. def __init__( self, email, password ):
  31. self.email = email
  32. self.password = password
  33. self.token = None
  34.  
  35. def login( self ):
  36. params = urllib.urlencode({
  37. "Email" : self.email,
  38. "Passwd" : self.password,
  39. "service" : Market.LOGIN_SERVICE,
  40. "accountType" : Market.LOGIN_TYPE
  41. })
  42.  
  43. headers = {"Content-type": "application/x-www-form-urlencoded"}
  44.  
  45. connection = httplib.HTTPSConnection( Market.LOGIN_HOST )
  46.  
  47. connection.request("POST", Market.LOGIN_PAGE, params, headers )
  48.  
  49. response = connection.getresponse().read()
  50.  
  51. connection.close()
  52.  
  53. if "Error" in response:
  54. raise Exception( "Invalid login credentials." )
  55.  
  56. for line in response.split("\n"):
  57. if "Auth=" in line:
  58. self.token = line.split("=")[1]
  59.  
  60. if self.token is None:
  61. raise Exception( "Unexpected response." )
  62.  
  63. def get_asset( self, request ):
  64. params = urllib.urlencode({
  65. "version" : 2,
  66. "request" : request
  67. })
  68.  
  69. headers = {"Content-type": "application/x-www-form-urlencoded"}
  70.  
  71. connection = httplib.HTTPSConnection( Market.API_HOST )
  72.  
  73. connection.request( "POST", Market.API_PAGE, params, headers )
  74. gzipped = connection.getresponse().read()
  75.  
  76. connection.close()
  77.  
  78. response = zlib.decompress( gzipped, 16 + zlib.MAX_WBITS )
  79.  
  80. dl_url = ""
  81. dl_cookie = ""
  82.  
  83. match = re.search( "(https?:\/\/[^:]+)", response )
  84.  
  85. if match is None:
  86. raise Exception( "Unexpected response." )
  87.  
  88. else:
  89. dl_url = match.group(1)
  90.  
  91. match = re.search( "MarketDA.*?(\d+)", response )
  92.  
  93. if match is None:
  94. raise Exception( "Unexpected response." )
  95.  
  96. else:
  97. dl_cookie = match.group(1)
  98.  
  99. return dl_url + "#" + dl_cookie
  100.  
  101. class ProtocolBuffer:
  102. def __init__( self ):
  103. self.buffer = []
  104.  
  105. def __encode_int( self, number ):
  106. while number:
  107. mod = number % 128
  108. number >>= 7
  109. if number:
  110. mod += 128
  111.  
  112. self.buffer.append( mod )
  113.  
  114. def reset( self ):
  115. self.buffer = []
  116.  
  117. def update( self, data, raw = False ):
  118.  
  119. if raw is True:
  120. self.buffer.append( data )
  121.  
  122. else:
  123. data_type = type(data).__name__
  124.  
  125. if data_type == "bool":
  126. self.buffer.append( 1 if data is True else 0 )
  127.  
  128. elif data_type == "int":
  129. self.__encode_int( data )
  130.  
  131. elif data_type == "str":
  132. self.__encode_int( len(data) )
  133. for c in data:
  134. self.buffer.append( ord(c) )
  135.  
  136. else:
  137. raise Exception( "Unhandled data type : " + data_type )
  138.  
  139. return self.buffer
  140.  
  141. def finalize( self, b64 = True ):
  142. stream = ""
  143. for data in self.buffer:
  144. stream += chr( data )
  145.  
  146. return stream if b64 is False else base64.b64encode( stream, "-_" )
  147.  
  148. class Operator:
  149. OPERATORS = {
  150. "Brazil" : {'TIM': '72402', 'Claro': '72405', 'Vivo': '72406', 'Oi': '72431'},
  151. "Canada" : {'MicroCell': '302370', 'Fido Canada': '30200001', 'Telus': '302220', 'Rogers A&T': '302720'},
  152. "Guinea-Bissau" : {'Orange': '63203', 'Arreba': '63202'},
  153. "Kuwait" : {'Viva': '41904', 'Wataniya': '41903', 'zain KW': '41902'},
  154. "Panama" : {'Claro': '71403', 'Cable & Wireless': '71401', 'Digicel': '71404', 'Movistar': '71402'},
  155. "Mali" : {'Orange': '61002', 'Malitel': '61001'},
  156. "Lithuania" : {'BITE': '24602', 'Tele 2': '24603', 'Omnitel': '24601'},
  157. "Costa Rica" : {'ICE': '71203'},
  158. "Cambodia" : {'Star-Cell': '45605', 'qb': '45604', 'Beeline': '45609', 'Smart Mobile': '45606', 'Mobitel': '45601', 'Metfone': '45608', 'hello': '45602', 'Mfone': '45618'},
  159. "Bahamas" : {'BaTelCo': '364390'},
  160. "Aruba" : {'SETAB': '36301', 'Digicel': '36302'},
  161. "Arab Emirates" : {'du': '42403', 'Etisalat': '42402'},
  162. "Ireland" : {'Eircom': '27207', 'Vodafone': '27201', 'O2': '27202', 'Meteor': '27203'},
  163. "Argentina" : {'Claro': '722330', 'Personnal': '722341', 'Nextel': '722020', 'Movistar': '722010'},
  164. "Bolivia" : {'Tigo': '73603', 'Nuavatel': '73601', 'Encel': '73602'},
  165. "Cameroon" : {'Orange': '62402', 'MTN Cameroon': '62401'},
  166. "Burkina Faso" : {'Telmob': '61301', 'Telecel Faso': '61303', 'Zain': '61302'},
  167. "Cote Ivore" : {'Koz': '61204', 'Moov': '61204'},
  168. "Czech Republic" : {'O2': '23002', 'Vodafone': '23003', 'T-Mobile': '23001'},
  169. "Bahrain" : {'VIVA': '42604', 'BaTelCo': '42601', 'zain BH': '42602'},
  170. "Saudi Arabia" : {'Mobily': '42003', 'Zain SA': '42004', 'Al Jawal': '42001'},
  171. "Australia" : {'Optus': '50502', 'OneTel': '50509', 'Vodafone': '50503', 'Telstra Mobile': '50502'},
  172. "Columbia" : {'Edatel': '732002', 'Comcel': '732101'},
  173. "Algeria" : {'Djezzy': '60302', 'Mobilis': '60301', 'Nedjma': '60303'},
  174. "El Salvador" : {'Claro': '70611', 'Tigo': '70603', 'Digicel': '70602', 'CTE Telecom': '70601', 'Movistar': '70604'},
  175. "Japan" : {'KDDI': '44008', 'SoftBank': '44004', 'DoCoMo': '44010', 'eMobile': '44000', 'TU-KA': '44081'},
  176. "Jordan" : {'Orange': '41677', 'Umniah': '41603', 'zain JO': '41601', 'Xpress Telecom': '41602'},
  177. "Slovenia" : {'Mobitel': '29341', 'Si.mobil': '29140', 'Tusmobil': '29370'},
  178. "Guatemala" : {'Claro': '70401', 'Comcel\\/Tigo': '70402', 'Movistar': '70403'},
  179. "Chile" : {'Claro': '73003', 'Nextel': '73009', 'Entel': '73001', 'Will': '73099', 'Movistar': '73002', 'VTR Movil': '73005'},
  180. "Belgium" : {'Mobistar': '20610', 'Base': '20620', 'Proximus': '20601', 'Telenet': '20605'},
  181. "Germany" : {'MobilCom': '26213', 'E-Plus': '26203', 'T-Mobile': '26201', 'Quam': '26214', 'O2': '26207', 'Vodafone': '26202'},
  182. "Haiti" : {'Digicel': '37202', 'Voila': '37201'},
  183. "Belize" : {'Digicell': '70267', 'Smart': '70299'},
  184. "Hong Kong" : {'New World PCS': '45410', 'HK Telecom': '45400', 'Smartone Mobile': '45406', 'Peoples Telephone': '45412', 'P Plus': '45422', 'Pacific Link': '45418', 'Hutchison': '45404', 'Mandarin Com.': '45416'},
  185. "Taiwan" : {'TransAsia': '46699', 'TINGSM': '46697', 'KG Telecom': '46688', 'TUNTEX': '46606', 'Chunghwa': '46692', 'Far Eastone': '46601', 'Mobitel': '46693'},
  186. "Spain" : {'Xfera': '21404', 'Telefonica': '21407', 'Amena': '21403', 'Vodafone': '21401', 'Movistar': '21402'},
  187. "Georgia" : {'Geocell': '28201', 'SILKNET': '28205', 'Iberiatel': '28203', 'Beeline': '28204', 'MagtiCom': '28202'},
  188. "Pakistan" : {'Zong': '41004', 'Ufone': '41003', 'Telenor': '41006', 'Warid': '41007', 'Mobilink': '41001', 'Vodafone': '41008'},
  189. "Denmark" : {'Orange': '23830', 'Debitel': '23800001', 'Telia Denmark': '23820', 'Denmark Mobil': '23801', 'Sonofon': '23802'},
  190. "Philippines" : {'Sun': '51505', 'Globe': '51502', 'Islacom': '51501', 'Smart': '51503'},
  191. "Vietnam" : {'3G EVNTelecom': '45208', 'S-Fone': '45203', 'Vietnam Mobile': '45205', 'EVNTelecom': '45206', 'Vinaphone': '45202', 'Beeline VN': '45207', 'MobiFone': '45201', 'Viettel Mobile': '45204'},
  192. "Turkmenistan" : {'MTS': '43801', 'TM-Cell': '43802'},
  193. "Moldova" : {'Orange': '25901', 'Moldcell': '25903', 'IDC': '25903'},
  194. "Morocco" : {'IAM': '60401', 'Meditel': '60400', 'INWI': '60402'},
  195. "Croatia" : {'Tele2': '21902', 'VIPNet': '21910', 'T-Mobile': '21901'},
  196. "Luxembourg" : {'Luxgsm': '27801', 'Orange': '27099', 'Tango': '27077'},
  197. "Antigua" : {'APUA': '344030', 'Digicel': '338050', 'LIME': '344920'},
  198. "Thailand" : {'Orange': '52010', 'GSM 1800': '52023', 'DTotal': '52018', 'AIS': '52001'},
  199. "Switzerland" : {'Orange': '22803', 'Swisscom': '22801', 'Sunrise': '22802'},
  200. "Honduras" : {'Claro': '70801', 'Digicel': '70840', 'Hondutel': '70830'},
  201. "New Zealand" : {'Telecom': '53000', 'Vodafone': '53001'},
  202. "Jamaica" : {'Claro': '338070', 'Digicel': '338050', 'LIME': '338180'},
  203. "Albania" : {'AMC': '27601', 'Plus': '27604', 'Vodafone': '27602', 'Eagle Mobile': '27603'},
  204. "Estonia" : {'EMT': '24801', 'Estonian Mobile': '24801', 'Tele 2': '24803', 'Elisa': '24802', 'RadioLinja': '24802'},
  205. "Uruguay" : {'Ancel': '74801', 'Claro': '74810', 'Movistar': '74807'},
  206. "Nicaragua" : {'Claro': '71021', 'Movistar': '71030'},
  207. "South Africa" : {'Vodacom': '65501', 'Cell C': '65507', 'MTN': '65510'},
  208. "India" : {'Escotel Mobile': '40412', 'TATA Cellular': '40407', 'Ina Spice': '40014', 'Hutch': '40405', 'Dolphin': '40468', 'Videocon': '40584', 'Idea': '40422', 'Usha Martin Tel.': '40426', 'Orange': '40020', 'Oasis': '40470', 'Bharti Telecom': '40402', 'Ushafon': '40408', 'Airtel Digilink': '40401', 'BSNL Mobile': '40455', 'INA AIRTel': '40440', 'Ushafone': '40432', 'BPL USWest': '40421', 'Spice': '40441'},
  209. "Azerbaijan" : {'Bakcell': '40002', 'Azercell': '40001', 'Nar Mobile': '40004', 'FONEX': '40003'},
  210. "Uzbekistan" : {'MTS': '73407', 'Ucell': '73405', 'Beeline': '73404'},
  211. "Tunisia" : {'Orange': '60501', 'Tunisiana': '60503', 'Tunicell': '60502'},
  212. "Rwanda" : {'Tigo': '63513', 'MTN': '63510'},
  213. "Colombia" : {'Tigo': '732111', 'Movistar': '732102'},
  214. "Burundi" : {'Omatel': '64203', 'Smart Mobile': '64207', 'Spacetel': '64201', 'Africell': '64202', 'U-COM Burundi': '64282'},
  215. "Kenya" : {'yu': '69305', 'Safaricom': '63902', 'Orange Kenya': '63907'},
  216. "South Korea" : {'SKT': '45005', 'Power 017': '45003', 'Olleh': '45008', 'LGT': '45006', 'KT': '45002'},
  217. "Cyprus" : {'MTN': '28010', 'Vodafone': '28001'},
  218. "Mamibia" : {'MTC': '64901', 'Switch': '64902', 'Leo': '64903'},
  219. "Turkey" : {'Avea': '28603', 'Turkcell': '28601', 'Vodafone': '28602'},
  220. "Qatar" : {'Qtel': '42701', 'Vodafone': '42702'},
  221. "Netherlands Antilles" : {'Telcell': '36251', 'UTS': '36291', 'Digicel': '36269', 'MIO': '36295', 'Bayos': '36294'},
  222. "Italy" : {'BLU': '22298', '3': '22299', 'Wind Tel.': '22288', 'Telecom Italia': '22201', 'Vodafone': '22210'},
  223. "Bangladesh" : {'TeleTalk': '47004', 'Gremenphone': '47001', 'CityCell': '47005', 'Banglalink': '47003', 'Warid Telecom': '47007', 'Airtel': '47006', 'Robi': '47002'},
  224. "USA" : {'Wireless 2000': '31011', 'Powertel': '31027', 'BellSouth': '31015', 'Aerial': '31031', 'Iowa Wireless': '31077', 'Western Wireless': '31026', 'Cingular': '31017', 'AT&T': '31038', 'Sprint': '31002', 'T-Mobile': '31020'},
  225. "Lebanon" : {'Ogero Mobile': '41505', 'Alfa': '41501', 'mtc touch': '41503'},
  226. "Hungary" : {'Westel GSM': '21630', 'Pannon GSM': '21601', 'Vodafone': '21670'},
  227. "Tanzania" : {'SasaTel': '64006', 'Vodacom': '64004', 'Life': '64007', 'tiGO': '64002', 'Zantel': '64003'},
  228. "Mongolia" : {'Skytel': '42891', 'Unitel': '42888', 'MobiCom': '42899', 'G-Mobile': '42898'},
  229. "France" : {'Bouygues Telecom': '20820', 'Orange': '20801', 'SFR': '20810'},
  230. "Netherlands" : {'Telfort': '20412', 'Tele 2': '20402', 'T-Mobile': '20416', '6GMobile': '20414', 'Vodafone': '20404', 'Orange': '20420', 'KPN': '20408'},
  231. "Slovakia" : {'Orange': '23101', 'O2': '23106', 'T-Mobile': '23102'},
  232. "Peru" : {'Claro': '71610', 'NEXTEL': '71607', 'Movistar': '21606'},
  233. "Laos" : {'Unitel': '45703', 'LaoTel': '45701', 'Tigo': '45708', 'ETL': '45702'},
  234. "Norway" : {'Telenor': '24201', 'NetCom': '24202'},
  235. "Nigeria" : {'M-TEL': '62140', 'Glo': '62150', 'MTN': '62130', 'Airtel': '62120', 'Etsalat': '62160'},
  236. "Benin" : {'Moov': '61602', 'Libercom': '61601', 'MTN': '61603', 'BBCOM': 'BBCOM', 'Glo': '61605'},
  237. "Israel" : {'Orange': '42501', 'JAWAL': '42505', 'Cellcom': '42502'},
  238. "Singapore" : {'StarHub': '52205', 'GSM 900': '52501', 'GSM 1800': '52502', 'MobileOne Asia': '52503', 'M1-3GSM': '52504'},
  239. "Iceland" : {'Simmin': '27401', 'Vodafone': '27402'},
  240. "Senegal" : {'Orange': '60801', 'Expresso': '60803', 'Tigo': '60802'},
  241. "Papua New Guinea" : {'B-Mobile': '53701', 'Digicel': '53703'},
  242. "Togo" : {'Togo Cell': '61501', 'Moov': '61503'},
  243. "Trinidad and Tobago" : {'Digicel': '37413', 'Bmobile': '37412'},
  244. "China" : {'China Telecom': '46005', 'China Tietong': '46020', 'China Mobile': '46000', 'China Unicom': '46001'},
  245. "Ecuador" : {'Porta': '74001', 'Alegro': '74002', 'Movistar': '74000'},
  246. "Armenia" : {'Orange': '28310', 'VivaCell': '28305', 'Beeline': '28301'},
  247. "Oman" : {'Oman Mobile': '41202', 'Nawras': '42203'},
  248. "Tajikistan" : {'Babilon-M': '43604', 'Beeline': '43605', 'MLT': '43603', 'Tcell': '43602'},
  249. "Dominican Republic" : {'Orange': '37001', 'Tricom': '37003', 'Claro': '37002', 'Viva': '37004'},
  250. "Kazakhstan" : {'Beeline': '40101', 'Kcell': '40102'},
  251. "Poland" : {'ERA GSM': '26002', 'IDA Centertel': '26003', 'Play': '26006', 'Polkomtel PLUS': '26001'},
  252. "Ukraine" : {'MTS': '25501', 'kylvstar': '25503', 'Beeline': '25502', 'Life': '25507'},
  253. "Ghana" : {'tiGO': '62003', 'MTN': '62001', 'Airtel': '62006', 'Vodafone': '62002'},
  254. "Kyrgyzstan" : {'MegaCom': '43705', 'Beeline': '43701', 'O': '43709', 'Fonex': '43703'},
  255. "Indonesia" : {'Ceria': '51027', 'XL': '51011', 'StarOne': '51003', 'TELKOMMobile': '51020', 'PSN': '51000', 'SMART': '51009', 'AXIS': '51008', 'TelkomFlexi': '51007', 'Fren\\/Hepi': '51028', '3': '51089', 'Telkomsel': '51010', 'INDOSAT': '51001'},
  256. "Finland" : {'Radjolinja': '24405', 'Finnet Group': '24409', '2G': '24412', 'Telia Finland': '24403', 'Sonera Corp.': '24409', 'AMT': '24414'},
  257. "Macedonia" : {'VIP MK': '29403', 'T-Mobile MK': '29401', 'ONE': '29402'},
  258. "Sri Lanka" : {'Mobitel': '41301', 'Hutch': '41308', 'Etisalat': '41303', 'Airtel': '41305', 'Dialog': '41302'},
  259. "Sweden" : {'Orange': '24003', 'Vodafone': '24008', '3 Sweden': '24002', 'Telia Mobitel': '24001', 'Comviq': '24007'},
  260. "Belarus" : {'MTS': '25702', 'Life': '25704', 'Velcom': '25701', 'DIALLOG': '25703'},
  261. "Cap Verde" : {'T+': '62502', 'CVMOVEL': '62501'},
  262. "Nepal" : {'Sky\\/C-Phone': '42903', 'SmartCell': '42904', 'Ncell': '42904', 'Namaste\\/NT Mobile': '42901'},
  263. "Russia" : {'North Caucasian': '25044', 'Megafon': '25002', 'BeeLine': '25099', 'New Telephone Cy': '25012', 'Don Telecom': '25010', 'MTS Moscow': '25001', 'Uratel': '25039', 'Kuban GSM': '25213', 'Zao Smarts': '25007', 'Siberian Cellular': '25005'},
  264. "Bulgaria" : {'M-Tel': '28401', 'Vivatel': '28401', 'Globul': '28405'},
  265. "Romania" : {'Mobifon': '22601', 'Cosmorom': '22603', 'Mobil Rom': '22610'},
  266. "Angola" : {'Unitel': '63102'},
  267. "Portugal" : {'Telecom Moveis': '26806', 'Optimus Telecom': '26803', 'Vodafone': '26801'},
  268. "Mexico" : {'Telcel': '33402', 'Lusacell': '33405', 'Nextel': '33401', 'Movistar': '33403'},
  269. "Egypt" : {'Etisalat': '60203', 'Vodafone': '60202', 'Mobinil': '60201'},
  270. "Fiji" : {'Digicel': '54202', 'Vodafone': '54201'},
  271. "Serbia" : {'Telenor': '22001', 'VIP Mobile': '22005', 'Telekom Srbija': '22003'},
  272. "Botswana" : {'Orange': '65202', 'Mascom': '65201', 'BTC Mobile': '65203'},
  273. "United Kingdom" : {'3': '23420', 'Manx Pronto': '23450', 'Orange': '23433', 'Jersey Telecom': '23450', 'Guermsey Tel.': '23455', 'O2': '23410', 'Vodafone': '23415', 'T-Mobile': '23430'},
  274. "Malaysia" : {'Celcom': '50219', 'U Mobilz': '50218', 'Maxis': '50212', 'DiGi': '50216', 'TM CDMA': '50201'},
  275. "Austria" : {'Mobilkom': '23101', 'Tele.ring': '23205', 'T-Mobile': '23203', '3AT': '23210'},
  276. "Latvia" : {'Tele 2': '24702', 'Latvian Mobile': '24701'},
  277. "Mozambique" : {'Vodacom': '64304', 'mCel': '64301'},
  278. "Uganda" : {'Orange': '64114', 'MTN': '64110', 'Zain': '64101', 'Warid Telecom': '64122'},
  279. "Greece" : {'Telestet': '20210', 'Cosmote': '20201', 'Wind': '20209', 'Vodafone': '20205'},
  280. "Paraguay" : {'Personal': '74405', 'Claro': '74402', 'Tigo': '74404', 'VOX': '74406'},
  281. "Gabon" : {'Liberts': '62801', 'Azur': '62804', 'Airtel': '62803', 'Moov': '62802'},
  282. "Niger" : {'Orange': '61404', 'Airtel': '61402', 'SahelCom': '61401', 'Telecel': '61403'},
  283. "Bosnia-Herzegovina" : {'BH Mobile': '21890', 'm:tel': '21805', 'HT-ERONET': '21803'}
  284. }
  285.  
  286. def __init__( self, country, name ):
  287. self.country = country
  288. self.name = name
  289. self.code = Operator.OPERATORS[country][name]
  290.  
  291. class AssetRequest:
  292. def __init__( self, package_name, auth_token, device_id, operator, device_name, sdk_version):
  293. self.encode_table = [0, [16], 2, [24], 4, [34], 6, [42], 8, [50], 10, [58], 12, [66], 14, [74], 16, [82], 18, [90], 20, [19, 82], 22, [10], 24, [20]]
  294. self.pad = [ 10 ]
  295. self.buffer = ProtocolBuffer()
  296.  
  297. self.auth_token = auth_token
  298. self.is_secure = True
  299. self.sdk_version = 2009011
  300. self.device_id = device_id
  301. self.device_name = device_name
  302. self.sdk_version = sdk_version
  303. self.locale = "en"
  304. self.country = "us"
  305. self.operator_alpha = operator.name
  306. self.sim_operator_alpha = operator.name
  307. self.operator_code = operator.code
  308. self.sim_operator_code = operator.code
  309. self.package_name = package_name
  310.  
  311. def encode( self ):
  312. self.buffer.reset()
  313.  
  314. header_len = 0
  315.  
  316. for encoder in self.encode_table:
  317. enc_type = type(encoder).__name__
  318.  
  319. if enc_type == "list":
  320. self.buffer.buffer += encoder
  321.  
  322. elif enc_type == "int":
  323. if encoder == 0:
  324. self.buffer.update( self.auth_token )
  325.  
  326. elif encoder == 2:
  327. self.buffer.update( self.is_secure )
  328.  
  329. elif encoder == 4:
  330. self.buffer.update( self.sdk_version )
  331.  
  332. elif encoder == 6:
  333. self.buffer.update( self.device_id )
  334.  
  335. elif encoder == 8:
  336. self.buffer.update( '%s:%d' % (self.device_name, self.sdk_version) )
  337.  
  338. elif encoder == 10:
  339. self.buffer.update( self.locale )
  340.  
  341. elif encoder == 12:
  342. self.buffer.update( self.country )
  343.  
  344. elif encoder == 14:
  345. self.buffer.update( self.operator_alpha )
  346.  
  347. elif encoder == 16:
  348. self.buffer.update( self.sim_operator_alpha )
  349.  
  350. elif encoder == 18:
  351. self.buffer.update( self.operator_code )
  352.  
  353. elif encoder == 20:
  354. self.buffer.update( self.sim_operator_code )
  355. header_len = len( self.buffer.buffer ) + 1
  356.  
  357. elif encoder == 22:
  358. self.buffer.update( len( self.package_name ) + 2 )
  359.  
  360. elif encoder == 24:
  361. self.buffer.update( self.package_name )
  362.  
  363. self.buffer.buffer = self.pad + ProtocolBuffer().update( header_len ) + self.pad + self.buffer.buffer
  364.  
  365. return self.buffer.finalize()
  366.  
  367. if __name__ == '__main__':
  368. try:
  369.  
  370. print( "\n\tGooglePlay Downloader - Directly download apks from GooglePlay to your PC.\n" +
  371. "\tCopyleft Simone Margaritelli <[email protected]>\n" +
  372. "\thttp://www.evilsocket.net\n\n" );
  373.  
  374. parser = optparse.OptionParser( usage = "usage: %prog [options]\n\n" +
  375. "EXAMPLE:\n" +
  376. "\t%prog --email [email protected] --password your-password --name com.arttech.xbugsfree --country \"Italy\" --operator \"3\" --device your-device-id"
  377. )
  378.  
  379. parser.add_option( "-e", "--email", action="store", dest="email", default=None, help="Your android account email.")
  380. parser.add_option( "-p", "--password", action="store", dest="password", default=None, help="Your android account password.")
  381. parser.add_option( "-n", "--name", action="store", dest="package", default=None, help="Package identifier ( com.something.name ).")
  382. parser.add_option( "-c", "--country", action="store", dest="country", default=None, help="Your country.")
  383. parser.add_option( "-o", "--operator", action="store", dest="operator", default=None, help="Your phone operator.")
  384. parser.add_option( "-d", "--device", action="store", dest="device", default=None, help="Your device ID ( can be obtained with this app https://play.google.com/store/apps/details?id=com.redphx.deviceid ) .")
  385. parser.add_option( "-s", "--sdklevel", action="store", type="int", dest="sdklevel", default=9, help="Android SDK API level (default is 9 like Android 2.3.1).")
  386. parser.add_option( "-m", "--devname", action="store", dest="devname", default="passion", help="Device name (default 'passion' like HTC Passion aka Google Nexus One.")
  387.  
  388. (o,args) = parser.parse_args()
  389.  
  390. if o.email is None:
  391. print "No email specified."
  392.  
  393. elif o.password is None:
  394. print "No password specified."
  395.  
  396. elif o.package is None:
  397. print "No package specified."
  398.  
  399. elif o.country is None or o.country not in Operator.OPERATORS:
  400. print "Empty or invalid country specified, choose from : \n\n" + ", ".join( Operator.OPERATORS.keys() )
  401.  
  402. elif o.operator is None or o.operator not in Operator.OPERATORS[ o.country ]:
  403. print "Empty or invalid operator specified, choose from : \n\n" + ", ".join( Operator.OPERATORS[ o.country ].keys() )
  404.  
  405. elif o.device is None:
  406. print "No device id specified."
  407.  
  408. elif o.sdklevel < 2:
  409. print "The SDK API level cannot be less than 2."
  410.  
  411. else:
  412. print "@ Logging in ..."
  413.  
  414. market = Market( o.email, o.password )
  415. market.login()
  416.  
  417. print "@ Requesting package ..."
  418.  
  419. operator = Operator( o.country, o.operator )
  420. request = AssetRequest( o.package, market.token, o.device, operator, o.devname, o.sdklevel )
  421. asset = market.get_asset( request.encode() )
  422.  
  423. print "@ Download %s from :\n %s" % ( o.package, asset )
  424.  
  425. except Exception as e:
  426. print e
Add Comment
Please, Sign In to add comment