Пример #1
0
 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
Пример #2
0
 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