コード例 #1
0
    def run(self):
        SIZE = 0x8000
        WCMD = "\xA0"
        DUMP = "\x00\x00"
        addr2 = [
            '\x00', '\x20', '\x40', '\x60', '\x80', '\xa0', '\xc0', '\xe0'
        ]
        addr1 = [
            '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
            '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
            'x10', 'x11'
        ]
        RCMD = "\xA1"
        FOUT = self.filepath
        status = 0
        op = 0
        #Try to claim ftdi device
        try:
            FT232H.enable_FTDI_driver()
            eeprom = MPSSE(I2C, FOUR_HUNDRED_KHZ)
        except Exception as e:
            print("[*] I2C Operation Thread Initialization Error :" + str(e))
            self.terminate()
            exit(1)

        #Perform Operations
        try:
            #FT232H.enable_FTDI_driver()
            if (self.operation == "Read"):
                op = 1
                eeprom.Start()
                eeprom.Write(WCMD + DUMP)
                if (eeprom.GetAck() == ACK):
                    eeprom.Start()
                    eeprom.Write(RCMD)
                    if (eeprom.GetAck() == ACK):
                        data = eeprom.Read(SIZE)
                        eeprom.SendNacks()
                        eeprom.Read(1)
                eeprom.Stop()
                open(FOUT, "wb").write(data)
                print("[*] I2C EEPROM Dump Successful ")

            elif (self.operation == "Erase"):
                op = 2
                print("[*] I2C Erase Initializing")
                for a1 in addr1:
                    for a2 in addr2:
                        sleep(0.2)
                    eeprom.Start()
                    eeprom.Write(WCMD + a1 + a2)
                    eeprom.Write('\xff' * 32)
                    eeprom.SendNacks()
                    eeprom.Stop()
                print("[*] I2C EEPROM Erase Successful ")
            elif (self.operation == "Write"):
                op = 3
                #Write Op
                print("[*] Not Implemented ")

            eeprom.Close()
            status = 1

        except Exception as e:
            eeprom.Close()
            print("[*] I2C Operation Thread Error :" + str(e))
            self.terminate()

        self.emit(SIGNAL('I2c_operation_handler(int,int)'), status, op)
        print("[*] Terminating I2C Operation Thread ")
        self.terminate()