Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<img src="https://raw.githubusercontent.com/yuvrajraghuvanshis/WhatsApp-Key-Database-Extractor/master/helpers/banner.png" alt="Logo" width="320" height="100">
</a>

<h3 align="center">WhatsApp Key/Database Extractor</h3>
<h3 align="center">WhatsApp Key/Database Extractor </h3>
<h4 align="center">NO LONGER MAINTAINED </h4>

<p align="center">
Extract key/msgstore.db from /data/data/com.whatsapp in Android v4.0+ without root.
Expand Down
1 change: 1 addition & 0 deletions helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# For relative imports to work in Python 3.6
import os
import sys

sys.path.append(os.path.dirname(os.path.realpath(__file__)))
42 changes: 25 additions & 17 deletions helpers/custom_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,45 @@
from termcolor import colored, cprint
except ImportError:
try:
os.system('pip3 install termcolor')
os.system("pip3 install termcolor")
except Exception:
os.system('python3 -m pip install termcolor')
os.system("python3 -m pip install termcolor")

if not (os.path.isdir('log')):
os.mkdir('log')
logging.basicConfig(filename='log/wa_kdbe.log', level=logging.DEBUG, format='')
if not (os.path.isdir("log")):
os.mkdir("log")
logging.basicConfig(filename="log/wa_kdbe.log", level=logging.DEBUG, format="")
masked = []


def custom_input(text_to_input, color='green', attr=[], is_get_time=True, is_log=True):
time = get_time() if is_get_time else ''
data = input(colored(f'{time}{text_to_input}', color, attrs=attr))
if(is_log):
logging.debug(f'{time}{text_to_input}{data}')
def custom_input(text_to_input, color="green", attr=[], is_get_time=True, is_log=True):
time = get_time() if is_get_time else ""
data = input(colored(f"{time}{text_to_input}", color, attrs=attr))
if is_log:
logging.debug(f"{time}{text_to_input}{data}")
else:
logging.debug(f'{time}{text_to_input}********')
logging.debug(f"{time}{text_to_input}********")
# Add that password in list, and mask that while printing also.
masked.append(data)
return data


def custom_print(text_to_print, color='green', attr=[], is_get_time=True, is_log=True, is_print=True, end='\n'):
time = get_time() if is_get_time else ''
def custom_print(
text_to_print,
color="green",
attr=[],
is_get_time=True,
is_log=True,
is_print=True,
end="\n",
):
time = get_time() if is_get_time else ""
text_to_print = str(text_to_print)
if(is_print):
cprint(f'{time}{text_to_print}', color, attrs=attr, end=end)
if is_print:
cprint(f"{time}{text_to_print}", color, attrs=attr, end=end)
else:
pass
if(is_log):
logging.debug(f'{time}{text_to_print}')
if is_log:
logging.debug(f"{time}{text_to_print}")
else:
# Search for password and mask.
for i in masked:
Expand Down
138 changes: 81 additions & 57 deletions helpers/device_serial_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,124 +5,148 @@
from custom_ci import custom_input, custom_print


def init(mode, tcp_ip='', tcp_port=''):
def init(mode, tcp_ip="", tcp_port=""):
custom_print(
f'>>> I am in device_serial_id.init({mode=!s}, {tcp_ip=!s}, {tcp_port=!s})', is_print=False)
f">>> I am in device_serial_id.init(mode={mode}, tcp_ip{tcp_ip}, tcp_port={tcp_port})",
is_print=False,
)
# Detect OS
is_windows = False
if platform.system() == 'Windows':
if platform.system() == "Windows":
is_windows = True

# Global command line helpers
curr_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(curr_dir, '..'))
root_dir = os.path.abspath(os.path.join(curr_dir, ".."))

if(is_windows):
adb = f'{root_dir}\\bin\\adb.exe'
if is_windows:
adb = f"{root_dir}\\bin\\adb.exe"
else:
adb = 'adb'
adb = "adb"

# Kill server before getting list to avoid daemon texts.
os.system(f'{adb} kill-server')
os.system(f'{adb} start-server')

combo = f'{tcp_ip}:{tcp_port}'
cmd = ''
if mode == 'USB':
cmd = f'{adb} devices'
elif mode == 'TCP':
cmd = f'{adb} connect {combo}'
os.system(f"{adb} kill-server")
os.system(f"{adb} start-server")

combo = f"{tcp_ip}:{tcp_port}"
cmd = ""
if mode == "USB":
cmd = f"{adb} devices"
elif mode == "TCP":
cmd = f"{adb} connect {combo}"
else:
pass
# FIXME: Wrong choice.
proc = sp.Popen(cmd.split(), stdin=sp.PIPE, stdout=sp.PIPE,
stderr=sp.PIPE, shell=False)
proc = sp.Popen(
cmd.split(), stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE, shell=False
)
output, error = proc.communicate()
output = output.decode('utf-8')
error = error.decode('utf-8')
output = output.decode("utf-8")
error = error.decode("utf-8")

if len(output) == 0 or error:
output = None
custom_print(error, 'red')
custom_print(error, "red")
kill_me()

if mode == 'USB':
output = [x.strip() for x in output.split('\n') if len(x.strip()) > 0]
if mode == "USB":
output = [x.strip() for x in output.split("\n") if len(x.strip()) > 0]

if(len(output) == 1):
if len(output) == 1:
custom_print(
'Could not find any connected device. Is USB Debugging on?', 'red')
return ''
"Could not find any connected device. Is USB Debugging on?", "red"
)
return ""

device_to_connect = None
if(len(output) == 2):
if(output[1].split()[1] == 'offline'):
if len(output) == 2:
if output[1].split()[1] == "offline":
custom_print(
'Device is offline, try turning off USB debugging and turn on again.', 'yellow')
"Device is offline, try turning off USB debugging and turn on again.",
"yellow",
)
kill_me()
if(output[1].split()[1] == 'unauthorized'):
if output[1].split()[1] == "unauthorized":
custom_print(
'Device unauthorized. Please check the confirmation dialog on your device.', 'red')
"Device unauthorized. Please check the confirmation dialog on your device.",
"red",
)
kill_me()
return output[1].split()[0]

custom_print(output[0])
custom_print('\n', is_get_time=False)
custom_print("\n", is_get_time=False)
if device_to_connect is None:
padding = f' {" " * 25}'
for index, device in enumerate(output[1:]):
serial = device.split()[0]
state = device.split()[1]
name = 'Unknown' if state == 'unauthorized' else sp.getoutput(
f'{adb} -s {device.split()[0]} shell getprop ro.product.model').strip()
custom_print('{}. {:.15s} {:.15s} {}'
.format(index + 1, serial + padding, state + padding, name))
name = (
"Unknown"
if state == "unauthorized"
else sp.getoutput(
f"{adb} -s {device.split()[0]} shell getprop ro.product.model"
).strip()
)
custom_print(
"{}. {:.15s} {:.15s} {}".format(
index + 1, serial + padding, state + padding, name
)
)

while device_to_connect is None:
device_index = int(custom_input(
'Enter device number (for ex: 2): '))
device_index = int(custom_input("Enter device number (for ex: 2): "))
if device_index <= 0 or device_index + 1 > len(output):
continue
device_to_connect = output[device_index]

if(device_to_connect.split()[1] == 'offline'):
if device_to_connect.split()[1] == "offline":
custom_print(
'Device is offline, try turning off USB debugging and turn on again.', 'yellow')
"Device is offline, try turning off USB debugging and turn on again.",
"yellow",
)
kill_me()
if(device_to_connect.split()[1] == 'unauthorized'):
if device_to_connect.split()[1] == "unauthorized":
custom_print(
'Device unauthorized. Please check the confirmation dialog on your device.', 'red')
"Device unauthorized. Please check the confirmation dialog on your device.",
"red",
)
kill_me()
return device_to_connect.split()[0]

elif mode == 'TCP':
elif mode == "TCP":
output = [x.strip() for x in output.split() if len(x.strip()) > 0]
if('connected' in (x.lower() for x in output)):
if "connected" in (x.lower() for x in output):
return combo
if('authenticate' in (x.lower() for x in output)):
if "authenticate" in (x.lower() for x in output):
custom_print(
'Device unauthorized. Please check the confirmation dialog on your device.', 'red')
"Device unauthorized. Please check the confirmation dialog on your device.",
"red",
)
kill_me()
if('refused' in (x.lower() for x in output)):
if "refused" in (x.lower() for x in output):
custom_print(
'Could not find any connected device. Either USB Debugging is off or device is not running ADB over TCP', 'red')
return ''
''' Possible outputs
"Could not find any connected device. Either USB Debugging is off or device is not running ADB over TCP",
"red",
)
return ""
""" Possible outputs
['connected', 'to', '192.168.43.130:5555']
['failed', 'to', 'authenticate', 'to', '192.168.43.130:5555']
['cannot', 'connect', 'to', '192.168.43.130:5555:', 'No', 'connection', 'could', 'be', 'made', 'because', 'the', 'target', 'machine', 'actively', 'refused', 'it.', '(10061)']
'''
"""
else:
pass
# FIXME: Wrong choice.


def kill_me():
custom_print(">>> I am in device_serial_id.kill_me()", is_print=False)
custom_print("\n", is_get_time=False)
custom_print("Exiting...")
custom_print(
'>>> I am in device_serial_id.kill_me()', is_print=False)
custom_print('\n', is_get_time=False)
custom_print('Exiting...')
custom_print(
'Turn off USB debugging [and USB debugging (Security Settings)] if you\'re done.', 'cyan')
custom_input('Hit \"Enter\" key to continue....', 'cyan')
"Turn off USB debugging [and USB debugging (Security Settings)] if you're done.",
"cyan",
)
custom_input('Hit "Enter" key to continue....', "cyan")
quit()
Loading