Q: brick into forever calculator
This commit is contained in:
parent
e7f42cf7f1
commit
78d5f2dc52
@ -8,9 +8,8 @@ import utime, ngu, re
|
||||
from utils import B2A, word_wrap
|
||||
from ux_q1 import ux_input_text
|
||||
|
||||
async def login_repl():
|
||||
from glob import dis, settings
|
||||
from pincodes import pa
|
||||
async def login_repl(allow_login=True):
|
||||
from glob import dis
|
||||
|
||||
NUM_LINES = 7 # 10 - title - 2 for prompt
|
||||
|
||||
@ -65,27 +64,31 @@ Example Commands:
|
||||
elif ln in ('help', 'cls', 'rand'):
|
||||
# no need for () for these commands
|
||||
ans = state[ln]()
|
||||
elif re_pin.match(ln) and len(ln) <= 13:
|
||||
# try login
|
||||
m = re_pin.match(ln)
|
||||
ln = m.group(1)+ '-' + m.group(2)
|
||||
print(ln)
|
||||
try:
|
||||
pa.setup(ln)
|
||||
ok = pa.login()
|
||||
if ok: return
|
||||
except RuntimeError as exc:
|
||||
# I'm a brick and other stuff can happen here
|
||||
# - especially AUTH_FAIL when pin is just wrong.
|
||||
if exc.args[0] == 'AUTH_FAIL':
|
||||
pa.attempts_left -= 1
|
||||
ans = '%-7d # %d tries remain' % (eval(ln), pa.attempts_left)
|
||||
else:
|
||||
ans = 'Error: ' + repr(exc.args)
|
||||
elif allow_login:
|
||||
# without this flag, PIN codes ignored
|
||||
if re_pin.match(ln) and (len(ln) <= 13):
|
||||
# try login
|
||||
m = re_pin.match(ln)
|
||||
ln = m.group(1)+ '-' + m.group(2)
|
||||
print(ln)
|
||||
from pincodes import pa
|
||||
try:
|
||||
pa.setup(ln)
|
||||
ok = pa.login()
|
||||
if ok: return
|
||||
except RuntimeError as exc:
|
||||
# I'm a brick and other stuff can happen here
|
||||
# - especially AUTH_FAIL when pin is just wrong.
|
||||
if exc.args[0] == 'AUTH_FAIL':
|
||||
pa.attempts_left -= 1
|
||||
ans = '%-7d # %d tries remain' % (eval(ln), pa.attempts_left)
|
||||
else:
|
||||
ans = 'Error: ' + repr(exc.args)
|
||||
|
||||
elif re_prefix.match(ln) and len(ln) <= 7:
|
||||
# show words
|
||||
ans = pa.prefix_words(ln[:-1].encode())
|
||||
elif re_prefix.match(ln) and len(ln) <= 7:
|
||||
# show words
|
||||
from pincodes import pa
|
||||
ans = pa.prefix_words(ln[:-1].encode())
|
||||
else:
|
||||
if any((b in ln) for b in blacklist):
|
||||
ans = None
|
||||
|
||||
@ -86,6 +86,19 @@ async def more_setup():
|
||||
from files import CardSlot
|
||||
CardSlot.setup()
|
||||
|
||||
# check for bricked system early
|
||||
import callgate
|
||||
if callgate.get_is_bricked():
|
||||
print("SE bricked")
|
||||
try:
|
||||
# regardless of settings.calc forever calculator after brickage
|
||||
if version.has_qwerty:
|
||||
from calc import login_repl
|
||||
await login_repl(allow_login=False)
|
||||
finally:
|
||||
# die right away if it's not going to work
|
||||
callgate.enter_dfu(3)
|
||||
|
||||
# This "pa" object holds some state shared w/ bootloader about the PIN
|
||||
try:
|
||||
from pincodes import pa
|
||||
|
||||
@ -134,13 +134,6 @@ class PinAttempt:
|
||||
assert ustruct.calcsize(PIN_ATTEMPT_FMT_V1) == PIN_ATTEMPT_SIZE_V1
|
||||
assert ustruct.calcsize(PIN_ATTEMPT_FMT_V2_ADDITIONS) == PIN_ATTEMPT_SIZE - PIN_ATTEMPT_SIZE_V1
|
||||
|
||||
# check for bricked system early
|
||||
import callgate
|
||||
if callgate.get_is_bricked():
|
||||
# die right away if it's not going to work
|
||||
print("SE bricked")
|
||||
callgate.enter_dfu(3)
|
||||
|
||||
def __repr__(self):
|
||||
return '<PinAttempt: fails/left=%d/%d tc_flag/arg=0x%x/0x%x>' % (
|
||||
self.num_fails, self.attempts_left,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user