tools: refresh mem_* debug tools, blackify

pull/25/head
matejcik 5 years ago
parent 832c47a278
commit 2813522b05

@ -1,47 +1,49 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from trezorlib.debuglink import DebugLink from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport import enumerate_devices from trezorlib.transport import enumerate_devices
import sys import sys
# fmt: off
sectoraddrs = [0x8000000, 0x8004000, 0x8008000, 0x800c000, sectoraddrs = [0x8000000, 0x8004000, 0x8008000, 0x800c000,
0x8010000, 0x8020000, 0x8040000, 0x8060000, 0x8010000, 0x8020000, 0x8040000, 0x8060000,
0x8080000, 0x80a0000, 0x80c0000, 0x80f0000] 0x8080000, 0x80a0000, 0x80c0000, 0x80f0000]
sectorlens = [0x4000, 0x4000, 0x4000, 0x4000, sectorlens = [0x4000, 0x4000, 0x4000, 0x4000,
0x8000, 0x10000, 0x10000, 0x10000, 0x8000, 0x10000, 0x10000, 0x10000,
0x10000, 0x10000, 0x10000, 0x10000] 0x10000, 0x10000, 0x10000, 0x10000]
# fmt: on
def main(): def find_debug():
# List all debuggable TREZORs for device in enumerate_devices():
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] try:
debug_transport = device.find_debug()
# Check whether we found any debug = DebugLink(debug_transport, auto_interact=False)
if len(devices) == 0: debug.open()
print('No TREZOR found') return debug
return except Exception:
continue
else:
print("No suitable Trezor device found")
sys.exit(1)
# Use first connected device
transport = devices[0]
debug_transport = devices[0].find_debug()
# Creates object for manipulating TREZOR def main():
client = TrezorClient(transport) debug = find_debug()
debug = DebugLink(debug_transport)
sector = int(sys.argv[1]) sector = int(sys.argv[1])
f = open(sys.argv[2], "rb") f = open(sys.argv[2], "rb")
content = f.read(sectorlens[sector]) content = f.read(sectorlens[sector])
if (len(content) != sectorlens[sector]): if len(content) != sectorlens[sector]:
print("Not enough bytes in file") print("Not enough bytes in file")
return return
debug.flash_erase(sector) debug.flash_erase(sector)
step = 0x400 step = 0x400
for offset in range(0, sectorlens[sector], step): for offset in range(0, sectorlens[sector], step):
debug.memory_write(sectoraddrs[sector] + offset, content[offset:offset + step], flash=True) debug.memory_write(
client.close() sectoraddrs[sector] + offset, content[offset : offset + step], flash=True
)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

@ -1,6 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from trezorlib.debuglink import DebugLink from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport import enumerate_devices from trezorlib.transport import enumerate_devices
import sys import sys
@ -13,28 +12,28 @@ import sys
# be running a firmware that was built with debug link enabled # be running a firmware that was built with debug link enabled
def main(): def find_debug():
# List all debuggable TREZORs for device in enumerate_devices():
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] try:
debug_transport = device.find_debug()
# Check whether we found any debug = DebugLink(debug_transport, auto_interact=False)
if len(devices) == 0: debug.open()
print('No TREZOR found') return debug
return except Exception:
continue
else:
print("No suitable Trezor device found")
sys.exit(1)
# Use first connected device
transport = devices[0]
debug_transport = devices[0].find_debug()
# Creates object for manipulating TREZOR def main():
client = TrezorClient(transport) debug = find_debug()
debug = DebugLink(debug_transport)
arg1 = int(sys.argv[1], 16) arg1 = int(sys.argv[1], 16)
arg2 = int(sys.argv[2], 16) arg2 = int(sys.argv[2], 16)
step = 0x400 if arg2 >= 0x400 else arg2 step = 0x400 if arg2 >= 0x400 else arg2
f = open('memory.dat', 'wb') f = open("memory.dat", "wb")
for addr in range(arg1, arg1 + arg2, step): for addr in range(arg1, arg1 + arg2, step):
mem = debug.memory_read(addr, step) mem = debug.memory_read(addr, step)
@ -42,8 +41,6 @@ def main():
f.close() f.close()
client.close()
if __name__ == '__main__': if __name__ == "__main__":
main() main()

@ -1,30 +1,27 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from trezorlib.debuglink import DebugLink from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient
from trezorlib.transport import enumerate_devices from trezorlib.transport import enumerate_devices
import sys import sys
def main(): def find_debug():
# List all debuggable TREZORs for device in enumerate_devices():
devices = [device for device in enumerate_devices() if hasattr(device, 'find_debug')] try:
debug_transport = device.find_debug()
# Check whether we found any debug = DebugLink(debug_transport, auto_interact=False)
if len(devices) == 0: debug.open()
print('No TREZOR found') return debug
return except Exception:
continue
else:
print("No suitable Trezor device found")
sys.exit(1)
# Use first connected device
transport = devices[0]
debug_transport = devices[0].find_debug()
# Creates object for manipulating TREZOR
client = TrezorClient(transport)
debug = DebugLink(debug_transport)
def main():
debug = find_debug()
debug.memory_write(int(sys.argv[1], 16), bytes.fromhex(sys.argv[2]), flash=True) debug.memory_write(int(sys.argv[1], 16), bytes.fromhex(sys.argv[2]), flash=True)
client.close()
if __name__ == '__main__': if __name__ == "__main__":
main() main()

Loading…
Cancel
Save