Merge branch 'develop'
This commit is contained in:
commit
c94fbe5495
|
|
@ -65,8 +65,7 @@ def main():
|
||||||
'''
|
'''
|
||||||
main func to initalize dpt object
|
main func to initalize dpt object
|
||||||
'''
|
'''
|
||||||
p = argparse.ArgumentParser(
|
p = argparse.ArgumentParser(description="DPT Tools")
|
||||||
description="DPT Tools")
|
|
||||||
p.add_argument(
|
p.add_argument(
|
||||||
'--client-id', '-id',
|
'--client-id', '-id',
|
||||||
dest="dpt_id",
|
dest="dpt_id",
|
||||||
|
|
@ -107,8 +106,6 @@ def main():
|
||||||
"Make sure your id, key, and ip addresses are correct."
|
"Make sure your id, key, and ip addresses are correct."
|
||||||
)
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
dpt.client_id_fp = args.get('dpt_id', "")
|
|
||||||
dpt.key_fp = args.get('dpt_key', "")
|
|
||||||
|
|
||||||
interactive(dpt, diagnosis=args.get('diagnosis', False))
|
interactive(dpt, diagnosis=args.get('diagnosis', False))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
|
DDAT_MOUNT_PATH=/tmp/ddat
|
||||||
|
END_USER_UPDATER_PKG=${DDAT_MOUNT_PATH}/FwUpdater.pkg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# $1 : reboot=1, shutdown 0
|
||||||
|
local_reboot()
|
||||||
|
{
|
||||||
|
umount $DDAT_MOUNT_PATH
|
||||||
|
sync
|
||||||
|
sync
|
||||||
|
mount -o remount,ro /
|
||||||
|
if [ $1 -eq 1 ]
|
||||||
|
then
|
||||||
|
/sbin/reboot
|
||||||
|
else
|
||||||
|
/sbin/poweroff
|
||||||
|
fi
|
||||||
|
|
||||||
|
while [ 1 ]
|
||||||
|
do
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# End User Updater check
|
||||||
|
#########################
|
||||||
|
|
||||||
|
mount -t tmpfs tmpfs /tmp
|
||||||
|
mkdir ${DDAT_MOUNT_PATH}
|
||||||
|
mount /dev/mmcblk0p16 ${DDAT_MOUNT_PATH}
|
||||||
|
if [ -f ${END_USER_UPDATER_PKG} ]
|
||||||
|
then
|
||||||
|
rawdata --get_dump=sig_key > /tmp/sig.key
|
||||||
|
rawdata --get_dump=dec_key > /tmp/dec.key
|
||||||
|
start_eufwupdater.sh ${END_USER_UPDATER_PKG} /tmp /tmp/sig.key /tmp/dec.key
|
||||||
|
ret=$?
|
||||||
|
if [ $ret -eq 0 ]
|
||||||
|
then
|
||||||
|
# remove pkg, change normal boot and reboot
|
||||||
|
change_boot_mode.sh normal
|
||||||
|
rm -rf ${END_USER_UPDATER_PKG}
|
||||||
|
local_reboot 1
|
||||||
|
# elif [ $ret -eq 1 ]
|
||||||
|
# then
|
||||||
|
# # remain pkg, keep boot mode and shutdown
|
||||||
|
# local_reboot 0
|
||||||
|
else
|
||||||
|
# remove pkg, change normal boot and shutdown
|
||||||
|
change_boot_mode.sh normal
|
||||||
|
rm -rf ${END_USER_UPDATER_PKG}
|
||||||
|
local_reboot 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
umount ${DDAT_MOUNT_PATH}
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# Diag check
|
||||||
|
#########################
|
||||||
|
|
||||||
|
initctl start diag
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
@ -561,12 +561,72 @@ class DPT():
|
||||||
return self._get_api(
|
return self._get_api(
|
||||||
"/system/controls/pastlog", cookies=self.cookies, isfile=True)
|
"/system/controls/pastlog", cookies=self.cookies, isfile=True)
|
||||||
|
|
||||||
def authenticate(self, client_id_fp, key_fp, testmode=False):
|
def get_client_key_fps(self):
|
||||||
|
'''
|
||||||
|
return the stored client key file paths
|
||||||
|
'''
|
||||||
|
return self.client_id_fp, self.key_fp
|
||||||
|
|
||||||
|
def set_client_key_fps(self, client_id_fp, key_fp):
|
||||||
|
'''
|
||||||
|
store the client key file paths
|
||||||
|
'''
|
||||||
|
self.client_id_fp = client_id_fp
|
||||||
|
self.key_fp = key_fp
|
||||||
|
|
||||||
|
def auto_find_client_key_fps(self):
|
||||||
|
'''
|
||||||
|
automatically find the client key file paths
|
||||||
|
inspired from https://github.com/janten/dpt-rp1-py/pull/52
|
||||||
|
'''
|
||||||
|
default_client_fp, default_key_fp = self.get_client_key_fps()
|
||||||
|
if os.path.isfile(default_client_fp) and os.path.isfile(default_key_fp):
|
||||||
|
return default_client_fp, default_key_fp
|
||||||
|
dpa_path = "."
|
||||||
|
# MacOS
|
||||||
|
try:
|
||||||
|
home_path = os.path.expanduser("~")
|
||||||
|
except BaseException:
|
||||||
|
return default_client_fp, default_key_fp
|
||||||
|
tmp_dpa_path = "{}/Library/Application Support/".format(home_path)
|
||||||
|
tmp_dpa_path += "Sony Corporation/Digital Paper App"
|
||||||
|
if os.path.isdir(tmp_dpa_path):
|
||||||
|
dpa_path = tmp_dpa_path
|
||||||
|
# windows
|
||||||
|
tmp_dpa_path = "{}/AppData/Roaming/".format(home_path)
|
||||||
|
tmp_dpa_path += "Sony Corporation/Digital Paper App"
|
||||||
|
if os.path.isdir(tmp_dpa_path):
|
||||||
|
dpa_path = tmp_dpa_path
|
||||||
|
# Linux
|
||||||
|
tmp_dpa_path = "{}/.dpapp".format(home_path)
|
||||||
|
if os.path.isdir(tmp_dpa_path):
|
||||||
|
dpa_path = tmp_dpa_path
|
||||||
|
tmp_client_fp = "{}/deviceid.dat".format(dpa_path)
|
||||||
|
tmp_key_fp = "{}/privatekey.dat".format(dpa_path)
|
||||||
|
if os.path.isfile(tmp_client_fp) and os.path.isfile(tmp_key_fp):
|
||||||
|
default_client_fp = tmp_client_fp
|
||||||
|
default_key_fp = tmp_key_fp
|
||||||
|
return default_client_fp, default_key_fp
|
||||||
|
|
||||||
|
def reauthenticate(self):
|
||||||
|
'''
|
||||||
|
reauthentication (must done after reboot)
|
||||||
|
'''
|
||||||
|
return self.authenticate()
|
||||||
|
|
||||||
|
def authenticate(self, client_id_fp="", key_fp="", testmode=False):
|
||||||
|
'''
|
||||||
|
authenticate is necessary to send url request
|
||||||
|
'''
|
||||||
|
# find client_id_fp and key_fp optional
|
||||||
|
if not client_id_fp or not key_fp:
|
||||||
|
client_id_fp, key_fp = self.auto_find_client_key_fps()
|
||||||
if not os.path.isfile(client_id_fp) or not os.path.isfile(key_fp):
|
if not os.path.isfile(client_id_fp) or not os.path.isfile(key_fp):
|
||||||
print(
|
print(
|
||||||
"! Err: did not find {0} or {1}"
|
"! Err: did not find {0} or {1}"
|
||||||
.format(client_id_fp, key_fp))
|
.format(client_id_fp, key_fp))
|
||||||
return False
|
return False
|
||||||
|
self.set_client_key_fps(client_id_fp, key_fp)
|
||||||
|
|
||||||
with open(client_id_fp) as f:
|
with open(client_id_fp) as f:
|
||||||
client_id = f.read().strip()
|
client_id = f.read().strip()
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ def validate_required_files(dpt, purpose='diagnosis'):
|
||||||
]
|
]
|
||||||
elif purpose == 'eufwupdater':
|
elif purpose == 'eufwupdater':
|
||||||
requiredFiles = [
|
requiredFiles = [
|
||||||
'python_api/assets/start_eufwupdater.sh'
|
'python_api/assets/start_eufwupdater.sh',
|
||||||
|
'python_api/assets/updater_check.sh'
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
requiredFiles = [
|
requiredFiles = [
|
||||||
|
|
@ -125,7 +126,7 @@ def obtain_diagnosis_access(dpt):
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
dpt.err_print(str(e))
|
dpt.err_print(str(e))
|
||||||
return False
|
return False
|
||||||
if not dpt.authenticate(dpt.client_id_fp, dpt.key_fp):
|
if not dpt.reauthenticate():
|
||||||
dpt.err_print("Cannot reauthenticate after reboot")
|
dpt.err_print("Cannot reauthenticate after reboot")
|
||||||
dpt.err_print("Client id filepath: {}".format(dpt.client_id_fp))
|
dpt.err_print("Client id filepath: {}".format(dpt.client_id_fp))
|
||||||
dpt.err_print("Client key filepath: {}".format(dpt.key_fp))
|
dpt.err_print("Client key filepath: {}".format(dpt.key_fp))
|
||||||
|
|
@ -342,15 +343,27 @@ def diagnosis_patch_eufwupdater(dpt):
|
||||||
'''
|
'''
|
||||||
if not validate_required_files(dpt, purpose='eufwupdater'):
|
if not validate_required_files(dpt, purpose='eufwupdater'):
|
||||||
return False
|
return False
|
||||||
|
# patch start_eufwupdater.sh
|
||||||
bashfp = diagnosis_push_file(
|
bashfp = diagnosis_push_file(
|
||||||
dpt,
|
dpt,
|
||||||
localfp='python_api/assets/start_eufwupdater.sh',
|
localfp='python_api/assets/start_eufwupdater.sh',
|
||||||
folder='/usr/local/bin',
|
folder='/usr/local/bin',
|
||||||
overwrite=True)
|
overwrite=True)
|
||||||
if bashfp is None:
|
if bashfp is None:
|
||||||
dpt.err_print("Failed to patch!!")
|
dpt.err_print("Failed to patch start_eufwupdater.sh!!")
|
||||||
return False
|
return False
|
||||||
dpt.diagnosis_set_perm(bashfp, owner='1496.1496', perm='0775')
|
dpt.diagnosis_set_perm(bashfp, owner='1496.1496', perm='0775')
|
||||||
|
# patch updater_check.sh
|
||||||
|
bashfp = diagnosis_push_file(
|
||||||
|
dpt,
|
||||||
|
localfp='python_api/assets/updater_check.sh',
|
||||||
|
folder='/usr/local/bin',
|
||||||
|
overwrite=True)
|
||||||
|
if bashfp is None:
|
||||||
|
dpt.err_print("Failed to patch updater_check.sh!!")
|
||||||
|
return False
|
||||||
|
dpt.diagnosis_set_perm(bashfp, owner='1496.1496', perm='0775')
|
||||||
|
# success
|
||||||
dpt.info_print("Success!")
|
dpt.info_print("Success!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue