def scan_boot(self): """Step 1: scan boot block. Returns (True, x) if boot block has a valid dos type. Returns (x, True) if boot block is bootable Invalid checksum of the block is tolerated but remarked. """ # check boot block boot = BootBlock(self.blkdev) boot.read() if boot.valid: # dos type is valid self.boot = boot self.dos_type = boot.dos_type # give a warning if checksum is not correct if not boot.valid_chksum: self.log.msg(Log.INFO,"invalid boot block checksum",0) self.log.msg(Log.INFO,"dos type is '%s'" % DosType.get_dos_type_str(self.dos_type)) return (True, boot.valid_chksum) else: self.log.msg(Log.ERROR,"invalid boot block dos type",0) return (False, False)
def handle_blkdev(self, blkdev): n = len(self.opts) if n == 0: print("Usage: boot ( show [hex] [asm] | read <file> | write <file> | install [boot1x] | clear )") return 1 cmd = self.opts[0] # fetch boot blcok bb = BootBlock(blkdev, 0) bb.read() # boot show [hex] [asm] if cmd == 'show': bb.dump() if bb.valid and bb.boot_code != None: if 'hex' in self.opts: print_hex(bb.boot_code) if 'asm' in self.opts: dis = DisAsm() code = dis.disassemble(bb.boot_code) dis.dump(code) return 0 # boot read <file> elif cmd == 'read': if n > 1: if bb.valid: if bb.boot_code != None: f = open(self.opts[1], "wb") f.write(bb.boot_code) f.close() return 0 else: print("No Boot Code found!") return 2 else: print("Invalid Boot Block!") return 1 else: print("No file name!") return 1 # boot write <file> elif cmd == 'write': if n > 1: f = open(self.opts[1], "rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print("Boot Code invalid!") return 2 else: print("No file name!") return 1 # boot install [<name>] elif cmd == 'install': if n == 1: # default boot code name = "boot2x3x" else: name = self.opts[1] # boot code directory bc_dir = bb.get_boot_code_dir() if bc_dir == None: print("No boot code directory found!") return 1 path = os.path.join(bc_dir, name + ".bin") if not os.path.exists: print("Boot code '%s' not found!" % path) return 1 # read data f = open(path,"rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print("Boot Code invalid!") return 2 # boot clear elif cmd == 'clear': bb.set_boot_code(None) bb.write() return 0 # boot ? else: print("Unknown boot command!") return 1
def handle_blkdev(self, blkdev): n = len(self.opts) if n == 0: print "Usage: boot ( show [hex] [asm] | read <file> | write <file> | install [boot1x] | clear )" return 1 cmd = self.opts[0] # fetch boot blcok bb = BootBlock(blkdev, 0) bb.read() # boot show [hex] [asm] if cmd == 'show': bb.dump() if bb.valid and bb.boot_code != None: if 'hex' in self.opts: print_hex(bb.boot_code) if 'asm' in self.opts: dis = DisAsm() code = dis.disassemble(bb.boot_code) dis.dump(code) return 0 # boot read <file> elif cmd == 'read': if n > 1: if bb.valid: if bb.boot_code != None: f = open(self.opts[1], "wb") f.write(bb.boot_code) f.close() return 0 else: print "No Boot Code found!" return 2 else: print "Invalid Boot Block!" return 1 else: print "No file name!" return 1 # boot write <file> elif cmd == 'write': if n > 1: f = open(self.opts[1], "rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print "Boot Code invalid!" return 2 else: print "No file name!" return 1 # boot install [<name>] elif cmd == 'install': if n == 1: # default boot code name = "boot2x3x" else: name = self.opts[1] # boot code directory bc_dir = bb.get_boot_code_dir() if bc_dir == None: print "No boot code directory found!" return 1 path = os.path.join(bc_dir, name + ".bin") if not os.path.exists: print "Boot code '%s' not found!" % path return 1 # read data f = open(path, "rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print "Boot Code invalid!" return 2 # boot clear elif cmd == 'clear': bb.set_boot_code(None) bb.write() return 0 # boot ? else: print "Unknown boot command!" return 1
def handle_blkdev(self, blkdev): n = len(self.opts) if n == 0: print( "Usage: boot ( show [hex] [asm] | read <file> | write <file> | install [boot1x] | clear )" ) return 1 cmd = self.opts[0] # fetch boot blcok bb = BootBlock(blkdev, 0) bb.read() # boot show [hex] [asm] if cmd == "show": bb.dump() if bb.valid and bb.boot_code != None: if "hex" in self.opts: print_hex(bb.boot_code) if "asm" in self.opts: from amitools.vamos.machine import DisAsm dis = DisAsm.create() code = dis.disassemble_block(bb.boot_code) dis.dump_block(code) return 0 # boot read <file> elif cmd == "read": if n > 1: if bb.valid: if bb.boot_code != None: f = open(self.opts[1], "wb") f.write(bb.boot_code) f.close() return 0 else: print("No Boot Code found!") return 2 else: print("Invalid Boot Block!") return 1 else: print("No file name!") return 1 # boot write <file> elif cmd == "write": if n > 1: f = open(self.opts[1], "rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print("Boot Code invalid!") return 2 else: print("No file name!") return 1 # boot install [<name>] elif cmd == "install": if n == 1: # default boot code name = "boot2x3x" else: name = self.opts[1] # boot code directory bc_dir = bb.get_boot_code_dir() if bc_dir == None: print("No boot code directory found!") return 1 path = os.path.join(bc_dir, name + ".bin") if not os.path.exists: print("Boot code '%s' not found!" % path) return 1 # read data f = open(path, "rb") data = f.read() f.close() ok = bb.set_boot_code(data) if ok: bb.write() return 0 else: print("Boot Code invalid!") return 2 # boot clear elif cmd == "clear": bb.set_boot_code(None) bb.write() return 0 # boot ? else: print("Unknown boot command!") return 1