summaryrefslogtreecommitdiffstats
path: root/Scripts
diff options
context:
space:
mode:
authorLudwig <ludwig@v>2021-02-06 12:16:34 +0100
committerLudwig <ludwig@v>2021-02-06 12:20:58 +0100
commit754b67bad806fe727be852f7886a8fd54c72580b (patch)
treeb22ae2c36b119a24c089e2eb4d742def10046ae5 /Scripts
parentChinese units Keys (diff)
downloadpsa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar.gz
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar.bz2
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar.lz
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar.xz
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.tar.zst
psa-nac-firmware-reverse-engineering-754b67bad806fe727be852f7886a8fd54c72580b.zip
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/decrypt_SWL.sh29
-rw-r--r--Scripts/decrypt_smime_file.sh29
-rw-r--r--Scripts/mount_ubifs_nac.sh49
-rw-r--r--Scripts/mount_ubifs_rcc.sh49
4 files changed, 114 insertions, 42 deletions
diff --git a/Scripts/decrypt_SWL.sh b/Scripts/decrypt_SWL.sh
index 6cd663c..de74de2 100644
--- a/Scripts/decrypt_SWL.sh
+++ b/Scripts/decrypt_SWL.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2020, Ludwig V. <https://github.com/ludwig-v>
+# Copyright 2020-2021, Ludwig V. <https://github.com/ludwig-v>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,6 +18,23 @@
DIRECTORY=$1
FIRMWARE_KEY=$2
+if ! [ -x "$(command -v openssl)" ]; then
+ echo 'Error: openssl is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v head)" ]; then
+ echo 'Error: head is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v grep)" ]; then
+ echo 'Error: grep is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v find)" ]; then
+ echo 'Error: find is not installed.' >&2
+ exit 1
+fi
+
if [[ -d $DIRECTORY ]]; then
find $DIRECTORY -type f -print0 | while read -d $'\0' FILE; do
DATA=$(head -2 $FILE | grep "smime." 2>&1)
@@ -30,7 +47,7 @@ if [[ -d $DIRECTORY ]]; then
else
mv $FILE.bak $FILE
echo "${FILE} has not been decrypted, the key is probably invalid !"
- echo "Stopping"
+ echo "Stopping" >&2
exit 1
fi
else
@@ -49,8 +66,8 @@ if [[ -d $DIRECTORY ]]; then
echo "${FILE} parts have been merged !"
fi
done
+ exit 0
else
- echo "${DIRECTORY} not found or not a directory !"
-fi
-
-exit 0 \ No newline at end of file
+ echo "${DIRECTORY} not found or not a directory !" >&2
+ exit 1
+fi \ No newline at end of file
diff --git a/Scripts/decrypt_smime_file.sh b/Scripts/decrypt_smime_file.sh
index f0b5d4f..a54cabd 100644
--- a/Scripts/decrypt_smime_file.sh
+++ b/Scripts/decrypt_smime_file.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2020, Ludwig V. <https://github.com/ludwig-v>
+# Copyright 2020-2021, Ludwig V. <https://github.com/ludwig-v>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,6 +18,23 @@
FILE=$1
FIRMWARE_KEY=$2
+if ! [ -x "$(command -v openssl)" ]; then
+ echo 'Error: openssl is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v head)" ]; then
+ echo 'Error: head is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v grep)" ]; then
+ echo 'Error: grep is not installed.' >&2
+ exit 1
+fi
+if ! [ -x "$(command -v find)" ]; then
+ echo 'Error: find is not installed.' >&2
+ exit 1
+fi
+
if [[ -f "$FILE" ]]; then
DATA=$(head -2 $FILE | grep "smime." 2>&1)
if [[ $DATA =~ '"smime.' ]]; then
@@ -29,14 +46,14 @@ if [[ -f "$FILE" ]]; then
else
mv $FILE.bak $FILE
echo "${FILE} has not been decrypted, the key is probably invalid !"
- echo "Stopping"
+ echo "Stopping" >&2
exit 1
fi
else
echo "${FILE} seems already decrypted !"
fi
+ exit 0
else
- echo "${FILE} not found !"
-fi
-
-exit 0 \ No newline at end of file
+ echo "${FILE} not found !" >&2
+ exit 1
+fi \ No newline at end of file
diff --git a/Scripts/mount_ubifs_nac.sh b/Scripts/mount_ubifs_nac.sh
index 2c504c7..d651d91 100644
--- a/Scripts/mount_ubifs_nac.sh
+++ b/Scripts/mount_ubifs_nac.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2020, Ludwig V. <https://github.com/ludwig-v>
+# Copyright 2020-2021, Ludwig V. <https://github.com/ludwig-v>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,20 +17,39 @@
UBIFS_IMAGE=$1
-mkdir -p /mnt/ubifs
-if grep -qs '/dev/ubi' /proc/mounts; then
- umount /mnt/ubifs
- ubidetach -p /dev/mtd0
- rmmod nandsim
+if ! [ -x "$(command -v ubiformat)" ]; then
+ echo 'Error: mtd-utils is not installed.' >&2
+ exit 1
fi
-modprobe ubi
-modprobe nandsim first_id_byte=0xec second_id_byte=0xd5 third_id_byte=0x51 fourth_id_byte=0xa6
-flash_erase /dev/mtd0 0 0
-ubiformat /dev/mtd0 -s 4096 -O 4096
-ubiattach -m 0 -d 0 -O 4096
-ubimkvol /dev/ubi0 -N NAC_UBIFS -s 1024MiB
-ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE
-mount /dev/ubi0_0 /mnt/ubifs
+if modinfo ubi | grep -wq "filename:"; then
+ if modinfo nandsim | grep -wq "filename:"; then
+ mkdir -p /mnt/ubifs
+ if lsmod | grep -wq "^nandsim"; then
+ umount /mnt/ubifs
+ ubidetach -p /dev/mtd0
+ rmmod nandsim
+ fi
-echo "${UBIFS_IMAGE} mounted on /mnt/ubifs" \ No newline at end of file
+ modprobe ubi
+ modprobe nandsim first_id_byte=0xec second_id_byte=0xd5 third_id_byte=0x51 fourth_id_byte=0xa6
+ flash_erase /dev/mtd0 0 0
+ ubiformat /dev/mtd0 -s 4096 -O 4096
+ ubiattach -m 0 -d 0 -O 4096
+ ubimkvol /dev/ubi0 -N NAC_UBIFS -s 1024MiB
+ ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE
+ mount /dev/ubi0_0 /mnt/ubifs
+
+ echo "${UBIFS_IMAGE} mounted on /mnt/ubifs"
+
+ exit 0
+ else
+ echo 'Error: nandsim kernel module is not installed.' >&2
+
+ exit 1
+ fi
+else
+ echo 'Error: ubi kernel module is not installed.' >&2
+
+ exit 1
+fi \ No newline at end of file
diff --git a/Scripts/mount_ubifs_rcc.sh b/Scripts/mount_ubifs_rcc.sh
index 57d41cc..1cd22ed 100644
--- a/Scripts/mount_ubifs_rcc.sh
+++ b/Scripts/mount_ubifs_rcc.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2020, Ludwig V. <https://github.com/ludwig-v>
+# Copyright 2020-2021, Ludwig V. <https://github.com/ludwig-v>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,20 +17,39 @@
UBIFS_IMAGE=$1
-mkdir -p /mnt/ubifs
-if grep -qs '/dev/ubi' /proc/mounts; then
- umount /mnt/ubifs
- ubidetach -p /dev/mtd0
- rmmod nandsim
+if ! [ -x "$(command -v ubiformat)" ]; then
+ echo 'Error: mtd-utils is not installed.' >&2
+ exit 1
fi
-modprobe ubi
-modprobe nandsim first_id_byte=0xec second_id_byte=0xd7 third_id_byte=0x00 fourth_id_byte=0x36
-flash_erase /dev/mtd0 0 0
-ubiformat /dev/mtd0 -s 4096 -O 4096
-ubiattach -m 0 -d 0 -O 4096
-ubimkvol /dev/ubi0 -N NAC_UBIFS -s 1024MiB
-ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE
-mount /dev/ubi0_0 /mnt/ubifs
+if modinfo ubi | grep -wq "filename:"; then
+ if modinfo nandsim | grep -wq "filename:"; then
+ mkdir -p /mnt/ubifs
+ if lsmod | grep -wq "^nandsim"; then
+ umount /mnt/ubifs
+ ubidetach -p /dev/mtd0
+ rmmod nandsim
+ fi
-echo "${UBIFS_IMAGE} mounted on /mnt/ubifs" \ No newline at end of file
+ modprobe ubi
+ modprobe nandsim first_id_byte=0xec second_id_byte=0xd7 third_id_byte=0x00 fourth_id_byte=0x36
+ flash_erase /dev/mtd0 0 0
+ ubiformat /dev/mtd0 -s 4096 -O 4096
+ ubiattach -m 0 -d 0 -O 4096
+ ubimkvol /dev/ubi0 -N RCCC_UBIFS -s 1024MiB
+ ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE
+ mount /dev/ubi0_0 /mnt/ubifs
+
+ echo "${UBIFS_IMAGE} mounted on /mnt/ubifs"
+
+ exit 0
+ else
+ echo 'Error: nandsim kernel module is not installed.' >&2
+
+ exit 1
+ fi
+else
+ echo 'Error: ubi kernel module is not installed.' >&2
+
+ exit 1
+fi \ No newline at end of file