def Uncompress(userZip): if(not str(userZip).endswith('7z')): userZip = userZip + '.7z' if(not os.path.isfile(extracted + userZip)): CustomPrint('Could not find ' + extracted + userZip) elif(os.path.getsize(extracted + userZip) <= 0): CustomPrint(extracted + userZip + ' is empty.') Exit() else: password = CustomInput('Enter password, leave empty for none : ') if(password): password = '******' + password os.system(sevenZip + ' e -aot ' + extracted + userZip + ' -o' + extracted + userZip.replace('.7z', '') + password) print('\n') CustomPrint( 'If you see \'Everything is OK\' in above line then you can delete user zip file.') deleteUserZip = CustomInput( 'Delete ' + userZip + ' ? (default n) : ') or 'n' print('\n') CustomPrint('\aYour extracted \'' + userZip.replace('.7z', '') + '\' folder is in extracted folder.', 'yellow') print('\n') CustomInput('Hit Enter key to continue.') if(deleteUserZip.upper() == 'Y'): DeleteUserZip(userZip) else: Exit()
def ReinstallWhatsApp(): CustomPrint('Reinstallting original WhatsApp.') try: os.system(adb + ' install -r -d ' + tmp + 'WhatsAppbackup.apk') except Exception as e: CustomPrint(e, 'red') CustomPrint('Could not install WhatsApp, install by running \'restore_whatsapp.py\' or manually installing from Play Store.\nHowever if it crashes then you have to clear storage/clear data from settings => app settings => WhatsApp.')
def InstallLegacy(SDKVersion): CustomPrint('Installing legacy WhatsApp V2.11.431, hold tight now.') if (SDKVersion >= 17): os.system(adb + ' install -r -d ' + helpers + 'LegacyWhatsApp.apk') else: os.system(adb + ' install -r ' + helpers + 'LegacyWhatsApp.apk') CustomPrint('Installation Complete.')
def RealDeal(SDKVersion, WhatsAppapkPath, versionName, sdPath): BackupWhatsAppApk(SDKVersion, versionName, WhatsAppapkPath) UninstallWhatsApp(SDKVersion) # Reboot here. if (isAllowReboot): if (not tcpIP): print('\n') CustomPrint('Rebooting device, please wait.', 'yellow') os.system(adb + ' reboot') while (subprocess.getoutput(adb + ' get-state') != 'device'): CustomPrint('Waiting for device...') time.sleep(5) CustomInput('Hit Enter key after unlocking device.', 'yellow') else: CustomPrint( 'Rebooting device in TCP mode break the connection and won\'t work until explicitly turned on in device and/or in PC. Skipping...', 'yellow') InstallLegacy(SDKVersion) # Before backup run app os.system(adb + ' shell am start -n com.whatsapp/.Main') CustomInput( '\aHit Enter key after running Legacy WhatsApp for a while. Ignore invalid date warning.', 'yellow') BackupWhatsAppDataasAb(SDKVersion) ReinstallWhatsApp() print('\n') CustomPrint( '\aOur work with device has finished, it is safe to remove it now.', 'yellow') print('\n') ExtractAB(isJAVAInstalled, sdPath=sdPath, ADBSerialId=ADBSerialId, isTarOnly=isTarOnly)
def main(): os.system('cls' if os.name == 'nt' else 'clear') CheckBin() ShowBanner() global isJAVAInstalled isJAVAInstalled = CheckJAVA() print('\n') try: CustomPrint('Arguments passed : ' + str(args)) print('\n') except: pass try: CustomPrint('System Info : ' + json.dumps(GetSysInfo(), indent=2, default=str)) print('\n') except: CustomPrint('Can\'t get system information. Continuing anyway...', 'yellow') CustomPrint('Current release date : 29/06/2021', 'cyan') print('\n') readInstruction = CustomInput( '\aPlease read above instructions carefully \u2191 . Continue? (default y) : ', 'yellow') or 'y' if (readInstruction.upper() == 'Y'): print('\n') CustomInput( '\aIf you haven\'t already, it is adviced to take a WhatsApp chat backup by going to WhatsApp settings \u2192 Chat Settings \u2192 Chat Backup. Hit Enter key to continue.', 'yellow') USBMode() else: Exit()
def Compress(userFolder): if(not os.path.isdir(extracted + userFolder)): CustomPrint('Could not find directory ' + extracted + userFolder) elif(len(os.listdir(extracted + userFolder)) == 0): CustomPrint('User folder is empty.') Exit() else: password = CustomInput('Choose a password for zip : ') if(password): password = '******' + password os.system(sevenZip + ' a -t7z -mhe ' + extracted + userFolder + ' ' + extracted + userFolder + '/* ' + password) print('\n') CustomPrint( 'If you see \'Everything is OK\' in above line then it is recommended to delete user folder.') deleteUserFolder = CustomInput( 'Delete ' + userFolder + ' folder? (default y) : ') or 'y' print('\n') CustomPrint('\aYour \'' + userFolder + '.7z\' file is in extracted folder. Password is : ' + password.replace(' -p', ''), 'yellow') print('\n') CustomInput('Hit Enter key to continue.') if(deleteUserFolder.upper() == 'Y'): DeleteUserFolder(userFolder) else: Exit()
def TakingOutOnlyTar(userName): os.mkdir(extracted) if not (os.path.isdir(extracted)) else CustomPrint( 'Folder ' + extracted + ' already exists.', 'yellow') try: CustomPrint('Moving tmp/whatsapp.tar to ' + extracted + userName + '.tar') os.replace(tmp + 'whatsapp.tar', extracted + userName + '.tar') except Exception as e: CustomPrint('\a' + e, 'red') Exit() CleanTmp() print('\n') CustomPrint('\aYour ' + userName + '.tar is in ' + os.path.realpath(extracted) + ' folder.', 'yellow') print('\n') CustomInput('Hit Enter key to continue.') try: # Open in explorer. if(isWindows): os.startfile(os.path.realpath(extracted)) elif(isLinux): os.system('xdg-open ' + os.path.realpath(extracted)) else: os.system('open ' + os.path.realpath(extracted)) except: Exit()
def BackupWhatsAppDataasAb(SDKVersion): CustomPrint('Backing up WhatsApp data as ' + tmp + 'whatsapp.ab. May take time, don\'t panic.') CustomPrint('Enter \'' + abPass + '\' as password when promted on device.', 'yellow') try : os.system(adb + ' backup -f '+ tmp + 'whatsapp.ab com.whatsapp') if(SDKVersion >= 23) else os.system(adb + ' backup -f '+ tmp + 'whatsapp.ab -noapk com.whatsapp') except Exception as e : CustomPrint(e) CustomPrint('Done backing up data.')
def DeleteUserZip(userZip): CustomPrint('Deleting...') try: os.remove(extracted + userZip) except Exception as e: CustomPrint(e) CustomPrint('Please manually delete it.') Exit()
def DeleteUserFolder(userFolder): CustomPrint('Deleting...') try: shutil.rmtree(extracted + userFolder) except Exception as e: CustomPrint(e) CustomPrint('Please manually delete it.') Exit()
def BackupWhatsAppDataasAb(SDKVersion): CustomPrint('Backing up WhatsApp data as ' + tmp + 'whatsapp.ab. May take time, don\'t panic.') try: os.system(adb + ' backup -f ' + tmp + 'whatsapp.ab com.whatsapp') if(SDKVersion >= 23) else os.system(adb + ' backup -f ' + tmp + 'whatsapp.ab -noapk com.whatsapp') except Exception as e: CustomPrint(e, 'red') CustomPrint('Done backing up data. Size : ' + str(os.path.getsize(tmp + 'whatsapp.ab')) + ' bytes.')
def UninstallWhatsApp(SDKVersion): if (SDKVersion >= 23): try: CustomPrint('Uninstalling WhatsApp, skipping data.') os.system(adb + ' shell pm uninstall -k com.whatsapp') CustomPrint('Uninstalled.') except Exception as e: CustomPrint('Could not uninstall WhatsApp.') CustomPrint(e, 'red') Exit()
def ListUserFolders(): print('\n') CustomPrint('Available user folders in extracted directory.') print('\n') allFolders = next(os.walk(extracted))[1] if (len(allFolders) == 0): CustomPrint('No folders found in ' + extracted + ' folder.', 'red') Exit() for folder in allFolders: CustomPrint(folder)
def ListUserFiles(): print('\n') CustomPrint('Available user files in extracted directory.') print('\n') allFiles = next(os.walk(extracted))[2] if(len(allFiles) == 1 and os.path.isfile(extracted + '.placeholder')): CustomPrint('No user files found in ' + extracted + ' folder.', 'red') Exit() for file in allFiles: if(file != '.placeholder'): CustomPrint(file)
def ReinstallWhatsApp(adb): CustomPrint('Reinstallting original WhatsApp.') if(os.path.isfile(tmp + 'WhatsAppbackup.apk')): try: os.system(adb + ' install -r -d ' + tmp + 'WhatsAppbackup.apk') except Exception as e: CustomPrint(e, 'red') CustomPrint('Could not restore WhatsApp, install from Play Store.\nHowever if it crashes then you have to clear storage/clear data from settings => app settings => WhatsApp.', 'red') else: CustomPrint('Could not find backup APK, install from play store.\nHowever if it crashes then you have to clear storage/clear data from settings => app settings => WhatsApp.', 'red')
def ShowBanner(): banner_path = 'non_essentials/banner.txt' try: banner = open(banner_path, 'r') banner_content = banner.read() CustomPrint(banner_content, 'green', ['bold']) banner.close() except Exception as e: CustomPrint(e) CustomPrint( '============ WhatsApp Key / Database Extrator for non-rooted Android ============\n', 'green', ['bold'])
def CheckJAVA() : JAVAVersion = re.search('(?<=version ")(.*)(?=")', str(subprocess.check_output('java -version'.split(), stderr=subprocess.STDOUT))).group(1) isJAVAInstalled = True if(JAVAVersion) else False if (isJAVAInstalled) : CustomPrint('Found Java installed on system.') return isJAVAInstalled else : noJAVAContinue = CustomInput('It looks like you don\'t have JAVA installed on your system. Would you like to (C)ontinue with the process and \'view extract\' later? or (S)top? : ', 'red') or 'c' if(noJAVAContinue=='c') : CustomPrint('Continuing without JAVA, once JAVA is installed on system run \'view_extract.py\'', 'yellow') return isJAVAInstalled else : Exit()
def BackupWhatsAppApk(SDKVersion, versionName, WhatsAppapkPath): os.system(adb + ' shell am force-stop com.whatsapp') if(SDKVersion > 11) else os.system(adb + ' shell am kill com.whatsapp') CustomPrint('Backing up WhatsApp ' + versionName + ' apk, the one installed on device to ' + tmp + 'WhatsAppbackup.apk') os.mkdir(tmp) if not (os.path.isdir(tmp)) else CustomPrint( 'Folder ' + tmp + ' already exists.', 'yellow') os.system(adb + ' shell cp ' + WhatsAppapkPath + ' /sdcard/WhatsAppbackup.apk') os.system(adb + ' pull /sdcard/WhatsAppbackup.apk ' + tmp + 'WhatsAppbackup.apk') # Delete temp apk from /sdcard. os.system(adb + ' shell rm -rf /sdcard/WhatsAppbackup.apk') CustomPrint('Apk backup complete.')
def TakingOutMainFiles(userName, protectPass): os.mkdir(extracted + userName) if not (os.path.isdir(extracted + userName) ) else CustomPrint('Folder already exists.') CustomPrint('Taking out main files in ' + tmp + ' folder temporaily.') try: bin = '' if (isLinux) else 'bin\\' os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' + tmp + ' apps/com.whatsapp/f/key') os.replace('tmp/apps/com.whatsapp/f/key', extracted + userName + '/key') os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' + tmp + ' apps/com.whatsapp/db/msgstore.db') os.replace('tmp/apps/com.whatsapp/db/msgstore.db', extracted + userName + '/msgstore.db') os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' + tmp + ' apps/com.whatsapp/db/wa.db') os.replace('tmp/apps/com.whatsapp/db/wa.db', extracted + userName + '/wa.db') os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' + tmp + ' apps/com.whatsapp/db/axolotl.db') os.replace('tmp/apps/com.whatsapp/db/axolotl.db', extracted + userName + '/axolotl.db') os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' + tmp + ' apps/com.whatsapp/db/chatsettings.db') os.replace('tmp/apps/com.whatsapp/db/chatsettings.db', extracted + userName + '/chatsettings.db') # TODO : use -y flag to cleantmp automatically. CustomPrint( '\nIf you do not see any errors in above lines in extracting/fluffing whatsapp.ab you SHOULD choose to clean temporary folder. It contains your chats in UN-ENCRYPTED format.', 'yellow') _cleanTemp = CustomInput( 'Would you like to clean tmp folder? (default y) : ') or 'y' if (_cleanTemp.upper() == 'y'.upper()): CleanTmp() if (protectPass): CustomPrint( 'Now an archive will be created in extracted folder with password \'' + protectPass + '\' and original files will be deleted. To later \'un-archive\' and access these files you need to run \'python protect.py\' from root directory of this project.', 'yellow') protect.Compress(userName, protectPass) except Exception as e: CustomPrint(e) CleanTmp()
def Exit(): print('\n') CustomPrint('Exiting...') os.system( 'bin\\adb.exe kill-server') if(isWindows) else os.system('adb kill-server') CustomInput('Hit \'Enter\' key to continue....', 'cyan') quit()
def ShowBanner(): banner_content = ''' ================================================================================ ======== ======== ======== db d8b db .d8b. db dD d8888b. d8888b. d88888b ======== ======== 88 I8I 88 d8' `8b 88 ,8P' 88 `8D 88 `8D 88' ======== ======== 88 I8I 88 88ooo88 88,8P 88 88 88oooY' 88ooooo ======== ======== Y8 I8I 88 88~~~88 C8888D 88`8b 88 88 88~~~b. 88~~~~~ ======== ======== `8b d8'8b d8' 88 88 88 `88. 88 .8D 88 8D 88. ======== ======== `8b8' `8d8' YP YP YP YD Y8888D' Y8888P' Y88888P ======== ======== ======== ================================================================================ ''' CustomPrint(banner_content, 'green', ['bold'], False) CustomPrint('============ WhatsApp Key / Database Extrator for non-rooted Android ===========\n', 'green', ['bold'], False)
def RealDeal(SDKVersion, WhatsAppapkPath, versionName) : BackupWhatsAppApk(SDKVersion, versionName, WhatsAppapkPath) UninstallWhatsApp(SDKVersion) InstallLegacy(SDKVersion) BackupWhatsAppDataasAb(SDKVersion) ReinstallWhatsApp() CustomPrint('Our work with device has finished, it is safe to remove it now.', 'yellow') ExtractAB(isJAVAInstalled, abPass, userName, protectPass)
def main(): CustomPrint( 'This utility is for archiving your output folder with password to enchance it\'s security. Secure is a relative term. Choose longer password.' ) if (isCompress): Compress(userName, protectPass) if (isDecompress): Decompress(userName, protectPass)
def ShowBanner(): banner_content = ''' ================================================================================ ======== ======== ======== db d8b db .d8b. db dD d8888b. d8888b. d88888b ======== ======== 88 I8I 88 d8' `8b 88 ,8P' 88 `8D 88 `8D 88' ======== ======== 88 I8I 88 88ooo88 88,8P 88 88 88oooY' 88ooooo ======== ======== Y8 I8I 88 88~~~88 C8888D 88`8b 88 88 88~~~b. 88~~~~~ ======== ======== `8b d8'8b d8' 88 88 88 `88. 88 .8D 88 8D 88. ======== ======== `8b8' `8d8' YP YP YP YD Y8888D' Y8888P' Y88888P ======== ======== ======== ================================================================================ ''' CustomPrint(banner_content, 'green', ['bold'], False) CustomPrint( '============ WhatsApp Key / Database Extrator for non-rooted Android ===========', 'green', ['bold'], False) intro_content = ''' ================================================================================ === === === xxxxx PLEASE TAKE WHATSAPP CHAT BACKUP BEFORE GETTING STARTED. xxxxx === === === === For that go to 'WhatsApp settings \u2192 Chat Settings \u2192 Chat Backup' === === here take a local backup. Prepare for Worst. === === === === This script can extract your WhatsApp msgstore.db (non crypt12, === === unencrypted file) and your 'key' file from '/data/data/com.whatsapp' === === directory in Android 4.0+ device without root access. However you need === === to have JAVA installed on your system in order to 'view the extract'. === === If you don't have JAVA installed then you can 'view extract' later by === === running 'view_extract.py'. The idea is to install a 'Legacy WhatsApp' === === temporarily on your device in order to get the android backup === === permission. You should not lose any data and your current WhatsApp === === version will be installed after this process so don't panic and don't === === stop this script while it's working. However if something fails you can === === run 'restore_whatsapp.py' and reinstall current WhatsApp or simply === === update that from Google Play Store. === === === === Script by : Yuvraj Raghuvanshi === === Github.com/YuvrajRaghuvanshiS === ================================================================================ ''' CustomPrint(intro_content, 'green', ['bold'], False)
def Compress(userFolder, protectPass): if (not os.path.isdir(extracted + userFolder)): CustomPrint('Could not find directory ' + extracted + userFolder) elif (len(os.listdir(extracted + userFolder)) == 0): CustomPrint('User folder is empty.') Exit() else: protectPass = '******' + protectPass os.system(sevenZip + ' a -t7z -mhe ' + extracted + userFolder + ' ' + extracted + userFolder + '/* ' + protectPass) CustomPrint( '\nIf you see \'Everything is OK\' in above line then it is recommended to delete user folder.' ) deleteUserFolder = CustomInput('Delete ' + userFolder + ' folder? (default y) : ') or 'y' # TODO : use -y flag to deleteuserfolder automatically. if (deleteUserFolder.upper() == 'Y'): DeleteUserFolder(userFolder) else: Exit()
def Exit(): print('\n') CustomPrint('Exiting...') try: # Open in explorer. if(isWindows): os.startfile(os.path.realpath(extracted)) elif(isLinux): os.system('xdg-open ' + os.path.realpath(extracted)) else: os.system('open ' + os.path.realpath(extracted)) except: pass quit()
def Exit(): print('\n') CustomPrint('Exiting...') try: # Open in explorer. if (isWindows): os.startfile(os.path.realpath(extracted)) elif (isLinux): os.system('xdg-open ' + os.path.realpath(extracted)) else: os.system('open ' + os.path.realpath(extracted)) except: pass CustomInput('Hit \'Enter\' key to continue....', 'cyan') quit()
def Decompress(userZip, protectPass): if (not str(userZip).endswith('7z')): userZip = userZip + '.7z' if (not os.path.isfile(extracted + userZip)): CustomPrint('Could not find ' + extracted + userZip) elif (os.path.getsize(extracted + userZip) <= 0): CustomPrint(extracted + userZip + ' is empty.') Exit() else: if (protectPass): protectPass = '******' + protectPass os.system(sevenZip + ' e -aot ' + extracted + userZip + ' -o' + extracted + userZip.replace('.7z', '') + protectPass) CustomPrint( '\nIf you see \'Everything is OK\' in above line then you can delete user zip file.' ) deleteUserZip = CustomInput('Delete ' + userZip + ' ? (default n) : ') or 'n' if (deleteUserZip.upper() == 'Y'): DeleteUserZip(userZip) else: Exit()
def main(): CustomPrint('This utility is for archiving your output folder with password to enchance it\'s security. Secure is a relative term. Choose longer password.') isCompressing = CustomInput('Are you (C)ompressing or (D)ecompressing? : ') while(True): if(isCompressing.upper() == 'C'): ListUserFolders() print('\n') userFolder = CustomInput( 'Enter a name of folder from above (case sensitive) : ') Compress(userFolder) break elif(isCompressing.upper() == 'D'): ListUserFiles() print('\n') userZip = CustomInput( 'Enter a name of file from above (case sensitive) : ') Uncompress(userZip) break else: isCompressing = CustomInput('Choose either \'c\' or \'d\' : ') continue
def ExtractAB(isJAVAInstalled, abPass, userName, protectPass, callingFromOtherModule=True): if not (isJAVAInstalled): CustomPrint('Can not detect JAVA on system.') # move whatsapp.ab from tmp to user specified folder. os.mkdir(extracted + userName) if not ( os.path.isdir(extracted + userName)) else CustomPrint('Folder ' + extracted + userName + ' exists.') os.rename(tmp + 'whatsapp.ab', extracted + userName + '/whatsapp.ab') CustomPrint( 'Moved whatsapp.ab to ' + extracted + userName + ' folder. Run view_extract.py after installing Java on system.') Exit() # Ask if already have whatsapp.ab file and continuing the process, if so then check in extracted folder first and continue. if (not callingFromOtherModule): if (CustomInput( 'Have you already made whatsapp.ab and just extracting it now ? : ' ).upper() == 'y'.upper()): if (os.path.isfile(extracted + userName + '/whatsapp.ab')): try: CustomPrint( 'Fluffing whatsapp.ab file, may take some time. Be patient.' ) os.system('java -jar ' + bin + 'abe.jar unpack ' + extracted + userName + '/whatsapp.ab ' + tmp + 'whatsapp.tar ' + str(abPass)) CustomPrint('Successfully \'fluffed\' ' + extracted + userName + '/whatsapp.ab ' + tmp + 'whatsapp.tar ') TakingOutMainFiles(userName, protectPass) except Exception as e: CustomPrint(e) else: CustomPrint('Could not find whatsapp.ab in ' + extracted + userName + ' folder, did you name your user properly?') CustomPrint('May be that \'whatsapp.ab\' file is still in ' + tmp + ' folder. Enter \'n\' next time.') Exit() if (os.path.isfile(tmp + 'whatsapp.ab')): CustomPrint('Found whatsapp.ab in tmp folder. Continuing') try: CustomPrint( 'Fluffing whatsapp.ab file, may take some time. Be patient.') os.system('java -jar ' + bin + 'abe.jar unpack ' + tmp + 'whatsapp.ab ' + tmp + 'whatsapp.tar ' + str(abPass)) CustomPrint('Successfully \'fluffed\' ' + tmp + 'whatsapp.ab to ' + tmp + 'whatsapp.tar ') TakingOutMainFiles(userName, protectPass) except Exception as e: CustomPrint(e)