File size: 1,570 Bytes
49d6718 |
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 51 52 53 54 55 56 57 58 59 60 61 62 |
import json5
class Config:
watchdog_address: int = 0x10007000
uart_base: int = 0x11002000
payload_address: int = 0x100A00
var_0: int = None
var_1: int = 0xA
payload: str
crash_method: int = 0
ptr_usbdl: int = None
ptr_da: int = None
def default(self, hw_code):
config = open("default_config.json5")
self.from_file(config, hw_code)
config.close()
return self
def from_file(self, config, hw_code):
hw_code = hex(hw_code)
config = json5.load(config)
if hw_code in config:
self.from_dict(config[hw_code])
else:
raise NotImplementedError("Can't find {} hw_code in config".format(hw_code))
return self
def from_dict(self, entry):
if "watchdog_address" in entry:
self.watchdog_address = entry["watchdog_address"]
if "uart_base" in entry:
self.uart_base = entry["uart_base"]
if "payload_address" in entry:
self.payload_address = entry["payload_address"]
if "var_0" in entry:
self.var_0 = entry["var_0"]
if "var_1" in entry:
self.var_1 = entry["var_1"]
if "crash_method" in entry:
self.crash_method = entry["crash_method"]
if "ptr_usbdl" in entry:
self.ptr_usbdl = entry["ptr_usbdl"]
if "ptr_da" in entry:
self.ptr_da = entry["ptr_da"]
self.payload = entry["payload"]
return self
|