Created
December 21, 2021 01:34
-
-
Save SoftPoison/3b35c84807a718c0302b2cc027504981 to your computer and use it in GitHub Desktop.
Dumps a router's flash via the CFE serial console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
OFFSET = 0 | |
NUM_PAGES = 64 * 2048 | |
f = open('serial_dump.bin', 'wb') | |
io = serial.Serial('/dev/ttyUSB0', baudrate=115200) | |
io.read_until(b'Auto run second count down: 1') | |
io.write(b'f\n') | |
io.write(f'rn 0 {OFFSET} {NUM_PAGES}\n'.encode()) | |
for _ in range(OFFSET, NUM_PAGES): | |
io.read_until(b'------------------ block: ') | |
bn = int(io.read_until(b', ')[:-2]) | |
io.read_until(b'page: ') | |
pn = int(io.read_until(b' ')[:-1]) | |
io.read_until(b'\n') | |
print(f'Block {bn}, page {pn}') | |
page = bytearray(128*16) | |
for i in range(128): | |
io.read_until(b': ') | |
hex_data = io.read_until(b' ')[:-2].decode() | |
hex_data = bytearray.fromhex(hex_data.replace(' ', '')) | |
io.read_until(b'\n') | |
page[i*16:(i+1)*16] = hex_data | |
f.write(page) | |
f.flush() | |
for i in range(10): | |
io.readline() | |
io.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment