-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathpartition_hashes
executable file
·50 lines (39 loc) · 1.52 KB
/
partition_hashes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# Copyright (C) 2024, Mark Qvist
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import sys
import RNS
import json
import hashlib
import subprocess
major_version = None
minor_version = None
target_version = None
target_file = os.path.join(sys.argv[1])
if sys.argv[1] == "from_device":
from_device = True
else:
from_device = False
if not from_device:
firmware_data = open(target_file, "rb").read()
calc_hash = hashlib.sha256(firmware_data[0:-32]).digest()
part_hash = firmware_data[-32:]
if calc_hash == part_hash:
print(RNS.hexrep(part_hash, delimit=False))
else:
try:
cmdresult = subprocess.run(["rnodeconf", sys.argv[2], "-L"], stdout=subprocess.PIPE).stdout.decode('utf-8')
part_hash = cmdresult.split("The actual firmware hash is: ")[1].replace("\n", "")
print(part_hash)
except Exception as e:
print("Could not get partition hash from device: "+str(e))