Created
August 25, 2018 02:35
-
-
Save leobrines/cd0ac04a8427dcf6f01deebb10af89eb to your computer and use it in GitHub Desktop.
Yowsup utility to have the updated APK of WhatsApp, process it and obtain the version of WhatsApp and Classdex md5
This file contains 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
#!/usr/bin/python3 | |
# | |
# Yowsup utility to have the updated APK of WhatsApp, process it and obtain the version of WhatsApp and Classdex md5 | |
# Using this data in env_android.py will decrease the probability that WhatsApp will ban you | |
# | |
# Install dependencies before use: | |
# sudo pip3 install Request requests http cookiejar bs4 apkutils | |
# | |
# Example output: | |
# WhatsApp Version: 2.17.296 | |
# WhatsApp MD5 Classes: YrJNPljM3TuNFPIOZ+jziw== | |
# | |
# Based on: | |
# @masbog dexMD5.py https://gist.github.com/masbog/d29c779539581defbf542e70ce724ed8 | |
# @vjyanand yowsup-utilities.py https://gist.github.com/vjyanand/92c062f26b2235bc150062731ae2da63 | |
# | |
# By @leopoldobrines7 | |
# | |
import os, sys, base64, hashlib | |
import requests, zipfile | |
from http.cookiejar import CookieJar | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
from bs4 import BeautifulSoup | |
from xml.dom import minidom | |
from apkutils import AXML | |
try: | |
import urllib.request as urllib2 | |
except ImportError: | |
import urllib2 | |
# Remove this warning from output: | |
# | |
# InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) | |
# | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
# Variables | |
url = "https://www.cdn.whatsapp.net/android/" | |
whatsappFileName = "whatsapp.apk" | |
# Get download url from official WhatsApp CDN | |
response = requests.request("GET", url, verify=False) | |
soup = BeautifulSoup(response.text, "html.parser") | |
label = soup.find_all(attrs={"id": "action-button"}) | |
download_url = label[0]['href'] | |
## Remove old WhatsApp apk if there is | |
try: | |
os.remove(whatsappFileName) | |
except OSError: | |
pass | |
## Download WhatsApp apk | |
print("URL download for APK : "+download_url) | |
with open(whatsappFileName, "wb") as f: | |
print ("Downloading %s" % whatsappFileName) | |
response = requests.get(download_url, stream=True) | |
total_length = response.headers.get('content-length') | |
if total_length is None: # no content length header | |
f.write(response.content) | |
else: | |
dl = 0 | |
total_length = int(total_length) | |
for data in response.iter_content(chunk_size=4096): | |
dl += len(data) | |
f.write(data) | |
done = int(50 * dl / total_length) | |
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) ) | |
sys.stdout.flush() | |
## Process WhatsApp APK | |
print("\n=== Processing APK ===") | |
whatsappZipFile = zipfile.ZipFile(whatsappFileName,'r') | |
# Get actual version of WhatsApp | |
bytesAndroidManifest = whatsappZipFile.read('AndroidManifest.xml') | |
axml = AXML(bytesAndroidManifest) # Get AXML from app | |
xml = minidom.parseString(axml.get_buff()) # Convert to XML | |
whatsapp_version = xml.documentElement.getAttributeNS('http://schemas.android.com/apk/res/android', "versionName") # Get versionName Attribute | |
# Get MD5 of classes.dex file | |
bytesClasses = whatsappZipFile.read('classes.dex') | |
md5_classes = hashlib.md5() | |
md5_classes.update(bytesClasses) | |
md5_classes = md5_classes.digest() # Convert bytes to bytes-like object | |
md5_classes = base64.b64encode(md5_classes) # Convert from bytes-like object to Base64 | |
md5_classes = md5_classes.decode("utf-8") # Convert from bytes64 to UTF-8 | |
## Print WhatsApp info for Yowsup | |
print("WhatsApp Version: " + whatsapp_version) | |
print("WhatsApp MD5 Classes: " + md5_classes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment