Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exceptions #48

Open
p1r473 opened this issue May 31, 2021 · 1 comment
Open

Unhandled Exceptions #48

p1r473 opened this issue May 31, 2021 · 1 comment

Comments

@p1r473
Copy link

p1r473 commented May 31, 2021

Hi,
When the phone isn't plugged in and you try to run the script, it gives a Value Error
I believe you should try and catch ADB errors as an exception and display it nicely to the user, and ask if the phone is plugged in, if ADB is running, of USB Debugging is enabled, etc.

2021-05-31 10:06:24 BlackPearl android_otp_extractor.adb[39864] INFO Testing if your phone uses binary: 'toybox'
2021-05-31 10:06:24 BlackPearl android_otp_extractor.adb[39864] INFO Checking if adb already runs as root
Traceback (most recent call last):
  File "c:\python3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\python3\lib\site-packages\android_otp_extractor\__main__.py", line 3, in <module>
    main()
  File "c:\python3\lib\site-packages\android_otp_extractor\cli.py", line 53, in main
    adb = guess_adb_interface(args.data)
  File "c:\python3\lib\site-packages\android_otp_extractor\adb.py", line 136, in guess_adb_interface
    if '0' == test.adb_uid() and '0' == test.adb_gid():
  File "c:\python3\lib\site-packages\android_otp_extractor\adb.py", line 89, in adb_uid
    lines = self.run(f'{self.binary} id -u', prefix=b'id: ', root=False)
  File "c:\python3\lib\site-packages\android_otp_extractor\adb.py", line 71, in run
    raise ValueError(f'adb command failed: {lines}')
ValueError: adb command failed: [b'error: no devices/emulators found\r\n']

Similar error but on my Raspberry Pi

2021-05-31 10:42:19 Harbormaster android_otp_extractor.adb[25587] INFO Testing if your phone uses binary: 'toybox'
2021-05-31 10:42:19 Harbormaster android_otp_extractor.adb[25587] INFO Checking if adb already runs as root
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/__main__.py", line 3, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/cli.py", line 53, in main
    adb = guess_adb_interface(args.data)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/adb.py", line 136, in guess_adb_interface
    if '0' == test.adb_uid() and '0' == test.adb_gid():
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/adb.py", line 89, in adb_uid
    lines = self.run(f'{self.binary} id -u', prefix=b'id: ', root=False)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/adb.py", line 71, in run
    raise ValueError(f'adb command failed: {lines}')
ValueError: adb command failed: [b'error: device offline\n']
@p1r473 p1r473 changed the title Phone not plugged in error ADB Error Exception Jun 1, 2021
@p1r473 p1r473 changed the title ADB Error Exception Unhandled Exceptions Jun 14, 2021
@p1r473
Copy link
Author

p1r473 commented Jun 14, 2021

Some other unhandled exceptions from #46:

If you want to have a TryCatch Exception for entering the wrong master password:

2021-06-01 13:25:25 Debian10 android_otp_extractor.adb[1093] INFO Using command line utility binary: 'toybox'
2021-06-01 13:25:25 Debian10 android_otp_extractor.apps[1093] INFO Reading Authenticator Plus accounts
Enter the Authenticator Plus master password: 
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/__main__.py", line 3, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/cli.py", line 62, in main
    accounts = apps.read_accounts(adb, enabled_apps)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/apps.py", line 416, in read_accounts
    new = list(app.extractor(adb))
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/apps.py", line 393, in read_authenticator_plus_accounts
    cursor.execute('SELECT * FROM accounts;')
pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database

If you enter an invalid secret, you might want to have an exception:

2021-06-01 13:25:57 Debian10 android_otp_extractor.adb[1126] INFO Using command line utility binary: 'toybox'
2021-06-01 13:25:57 Debian10 android_otp_extractor.apps[1126] INFO Reading Authenticator Plus accounts
Enter the Authenticator Plus master password: 
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/__main__.py", line 3, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/cli.py", line 62, in main
    accounts = apps.read_accounts(adb, enabled_apps)
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/apps.py", line 416, in read_accounts
    new = list(app.extractor(adb))
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/apps.py", line 396, in read_authenticator_plus_accounts
    secret = lenient_base32_decode(row['secret'])
  File "/usr/local/lib/python3.7/dist-packages/android_otp_extractor/otp.py", line 13, in lenient_base32_decode
    return base64.b32decode(data)
  File "/usr/lib/python3.7/base64.py", line 231, in b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant